]> khamidou — GitHub mirrors - electron.git/commitdiff
Add BrowserWindow.showDefinitionForSelection()
authorHajime Morrita <omo@dodgson.org>
Thu, 18 Dec 2014 23:40:35 +0000 (15:40 -0800)
committerHajime Morrita <omo@dodgson.org>
Fri, 19 Dec 2014 00:45:45 +0000 (16:45 -0800)
This API shows the system-provided pop-up dictionary.
Some Mac apps including Chrome have "Look Up in in Dictionary" context
menu item. This API can be used to implement it.

atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
docs/api/browser-window.md

index 126344aec7186db6d677493a2546dcf9addb3f0b..9ecb445b3d71bd5a5df2399477bd2810bf2338e6 100644 (file)
@@ -422,6 +422,12 @@ bool Window::IsMenuBarVisible() {
   return window_->IsMenuBarVisible();
 }
 
+#if defined(OS_MACOSX)
+void Window::ShowDefinitionForSelection() {
+  window_->ShowDefinitionForSelection();
+}
+#endif
+
 mate::Handle<WebContents> 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);
 }
index 3b123de7160df8c5b921ca3a74dd21acc6b70f67..494519d28f2ddd86295b2475f8f2f223241adfb6 100644 (file)
@@ -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<WebContents> GetWebContents(v8::Isolate* isolate) const;
   mate::Handle<WebContents> GetDevToolsWebContents(v8::Isolate* isolate) const;
index 8e1a1e237ae47dd8e5c09eb097a5d218c3f155c6..5248f6bda816b7ac29c96b53f8d09c375a8b4642 100644 (file)
@@ -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) {
 }
 
index 4c9f84bd0c39627407d3f864b6b451d803978a58..06f7163862b5668e7663747b09ed46430dfe70fd 100644 (file)
@@ -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();
index 2a34fe415154c25e497b7b8f64d08245371a370c..8567cccebf7674e24f58235506cd7df48073824e 100644 (file)
@@ -7,6 +7,9 @@
 
 #import <Cocoa/Cocoa.h>
 
+#include <string>
+#include <vector>
+
 #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.
index 17e361f7892525467b2daad99dbe3098767c1e26..5c66f3b41262b07dd739e193a974ff93f422803f 100644 (file)
@@ -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;
index fc0459b1faa99e034eb388b46e3dc01a65985650..2275756571b4f65189c0dbc663104bfb61c2c424 100644 (file)
@@ -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