diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 126344aec718..9ecb445b3d71 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -422,6 +422,12 @@ bool Window::IsMenuBarVisible() { return window_->IsMenuBarVisible(); } +#if defined(OS_MACOSX) +void Window::ShowDefinitionForSelection() { + window_->ShowDefinitionForSelection(); +} +#endif + mate::Handle Window::GetWebContents(v8::Isolate* isolate) const { return WebContents::CreateFrom(isolate, window_->GetWebContents()); } @@ -491,6 +497,10 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide) .SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility) .SetMethod("isMenuBarVisible", &Window::IsMenuBarVisible) +#if defined(OS_MACOSX) + .SetMethod( + "showDefinitionForSelection", &Window::ShowDefinitionForSelection) +#endif .SetMethod("_getWebContents", &Window::GetWebContents) .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 3b123de7160d..494519d28f2d 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -123,6 +123,10 @@ class Window : public mate::EventEmitter, void SetMenuBarVisibility(bool visible); bool IsMenuBarVisible(); +#if defined(OS_MACOSX) + void ShowDefinitionForSelection(); +#endif + // APIs for WebContents. mate::Handle GetWebContents(v8::Isolate* isolate) const; mate::Handle GetDevToolsWebContents(v8::Isolate* isolate) const; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 8e1a1e237ae4..5248f6bda816 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -247,6 +247,10 @@ void NativeWindow::Print(bool silent, bool print_background) { PrintNow(silent, print_background); } +void NativeWindow::ShowDefinitionForSelection() { + NOTIMPLEMENTED(); +} + void NativeWindow::SetAutoHideMenuBar(bool auto_hide) { } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 4c9f84bd0c39..06f7163862b5 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -161,6 +161,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // Print current page. virtual void Print(bool silent, bool print_background); + // Show popup dictionary. + virtual void ShowDefinitionForSelection(); + // Toggle the menu bar. virtual void SetAutoHideMenuBar(bool auto_hide); virtual bool IsMenuBarAutoHide(); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 2a34fe415154..8567cccebf76 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -7,6 +7,9 @@ #import +#include +#include + #include "base/mac/scoped_nsobject.h" #include "base/memory/scoped_ptr.h" #include "atom/browser/native_window.h" @@ -68,6 +71,7 @@ class NativeWindowMac : public NativeWindow { virtual bool HasModalDialog() OVERRIDE; virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; virtual void SetProgressBar(double progress) OVERRIDE; + virtual void ShowDefinitionForSelection() OVERRIDE; // Returns true if |point| in local Cocoa coordinate system falls within // the draggable region. diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 17e361f78925..5c66f3b41262 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -642,6 +642,14 @@ void NativeWindowMac::SetProgressBar(double progress) { [dock_tile display]; } +void NativeWindowMac::ShowDefinitionForSelection() { + content::WebContents* web_contents = GetWebContents(); + content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); + if (!rwhv) + return; + rwhv->ShowDefinitionForSelection(); +} + bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const { if (!draggable_region_) return false; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index fc0459b1faa9..2275756571b4 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -530,6 +530,11 @@ On Linux platform, only supports Unity desktop environment, you need to specify the `*.desktop` file name to `desktopName` field in `package.json`. By default, it will assume `app.getName().desktop`. +### BrowserWindow.showDefinitionForSelection() + +Show pop-up dictionary that searches the selected word on the page. +This API is available only on Mac OS. + ### BrowserWindow.setAutoHideMenuBar(hide) * `hide` Boolean