From 4f0a52628e33c5e65d42d5d31d82e54810c73ffa Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 2 Jun 2016 10:12:38 -0700 Subject: [PATCH 1/8] Add showDefinitionForSelection to webContents/webview --- atom/browser/api/atom_api_web_contents.cc | 11 +++++++++++ atom/browser/api/atom_api_web_contents.h | 1 + lib/renderer/web-view/web-view.js | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index c33b9f1d9bd9..59cdf746ab15 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1094,6 +1094,16 @@ void WebContents::StopFindInPage(content::StopFindAction action) { web_contents()->StopFinding(action); } +void WebContents::ShowDefinitionForSelection() { +#if defined(OS_WIN) + const auto view = web_contents()->GetRenderWidgetHostView(); + if (view) + view->ShowDefinitionForSelection(); +#else + NOTIMPLEMENTED(); +#endif +} + void WebContents::Focus() { web_contents()->Focus(); } @@ -1289,6 +1299,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("_printToPDF", &WebContents::PrintToPDF) .SetMethod("addWorkSpace", &WebContents::AddWorkSpace) .SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace) + .SetMethod("showDefinitionForSelection", &WebContents::ShowDefinitionForSelection) .SetProperty("id", &WebContents::ID) .SetProperty("session", &WebContents::Session) .SetProperty("hostWebContents", &WebContents::HostWebContents) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index dfaac8791fb4..f8e6710a5c58 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -116,6 +116,7 @@ class WebContents : public mate::TrackableObject, void ReplaceMisspelling(const base::string16& word); uint32_t FindInPage(mate::Arguments* args); void StopFindInPage(content::StopFindAction action); + void ShowDefinitionForSelection(); // Focus. void Focus(); diff --git a/lib/renderer/web-view/web-view.js b/lib/renderer/web-view/web-view.js index e9d300aabbcb..82ed62dd3a5d 100644 --- a/lib/renderer/web-view/web-view.js +++ b/lib/renderer/web-view/web-view.js @@ -379,7 +379,8 @@ var registerWebViewElement = function () { 'downloadURL', 'inspectServiceWorker', 'print', - 'printToPDF' + 'printToPDF', + 'showDefinitionForSelection' ] nonblockMethods = [ 'insertCSS', From ce19c2c0adf305516fd40136ed0f5165bbd2e91f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 13:09:54 -0700 Subject: [PATCH 2/8] Document webContents.showDefinitionForSelection --- docs/api/browser-window.md | 2 +- docs/api/web-contents.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index c133a49beda0..8b850b5c4388 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -885,7 +885,7 @@ The `flags` is an array that can include following `String`s: ### `win.showDefinitionForSelection()` _OS X_ -Shows pop-up dictionary that searches the selected word on the page. +Same as `webContents.showDefinitionForSelection()`. ### `win.setIcon(icon)` _Windows_ _Linux_ diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index b9ff9d7c4863..60c736e0041c 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -957,6 +957,10 @@ win.webContents.on('did-finish-load', () => { }); ``` +### `webContents.showDefinitionForSelection()` _OS X_ + +Shows pop-up dictionary that searches the selected word on the page. + ## Instance Properties `WebContents` objects also have the following properties: From 6360a5cae43257d587c1c77bf37a96a9ed282cfa Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 13:12:24 -0700 Subject: [PATCH 3/8] Add deprecation TODO for BrowserWindow.showDefinitionForSelection --- atom/browser/native_window_mac.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 2b88b180694d..995031a6f536 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -934,6 +934,8 @@ void NativeWindowMac::SetOverlayIcon(const gfx::Image& overlay, } void NativeWindowMac::ShowDefinitionForSelection() { + // TODO(kevinsawicki): Deprecate and remove this method in 2.0 in favor of + // calling it directly on webContents. if (!web_contents()) return; auto rwhv = web_contents()->GetRenderWidgetHostView(); From 8c520cf158baacb9740dd4606f5367116e0bbb1f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 13:13:49 -0700 Subject: [PATCH 4/8] :art: --- atom/browser/api/atom_api_web_contents.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 59cdf746ab15..f05b70c50f49 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1299,7 +1299,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("_printToPDF", &WebContents::PrintToPDF) .SetMethod("addWorkSpace", &WebContents::AddWorkSpace) .SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace) - .SetMethod("showDefinitionForSelection", &WebContents::ShowDefinitionForSelection) + .SetMethod("showDefinitionForSelection", + &WebContents::ShowDefinitionForSelection) .SetProperty("id", &WebContents::ID) .SetProperty("session", &WebContents::Session) .SetProperty("hostWebContents", &WebContents::HostWebContents) From c66299bf6603b89a8b44af0e06437e43c284c41c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 13:17:41 -0700 Subject: [PATCH 5/8] Document webview.showDefinitionForSelection --- docs/api/web-view-tag.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 1c9edcecaa75..c210bd8b9cb0 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -490,6 +490,10 @@ Sends an input `event` to the page. See [webContents.sendInputEvent](web-contents.md##webcontentssendinputeventevent) for detailed description of `event` object. +### `.showDefinitionForSelection()` _OS X_ + +Shows pop-up dictionary that searches the selected word on the page. + ### `.getWebContents()` Returns the [WebContents](web-contents.md) associated with this `webview`. From 6337e93e6dc1b9d511839cd8526c6a34c36f9b16 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 13:20:06 -0700 Subject: [PATCH 6/8] Check for Mac in if block --- atom/browser/api/atom_api_web_contents.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index f05b70c50f49..b0927ee57298 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1095,7 +1095,7 @@ void WebContents::StopFindInPage(content::StopFindAction action) { } void WebContents::ShowDefinitionForSelection() { -#if defined(OS_WIN) +#if defined(OS_MACOSX) const auto view = web_contents()->GetRenderWidgetHostView(); if (view) view->ShowDefinitionForSelection(); From 70996c79ba82529cfcf8ef625964737538b42973 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 8 Jun 2016 10:19:28 -0700 Subject: [PATCH 7/8] Add showDefinitionForSelection webContents proxy method --- atom/browser/api/atom_api_window.cc | 10 ---------- atom/browser/api/atom_api_window.h | 4 ---- atom/browser/native_window.cc | 4 ---- atom/browser/native_window.h | 3 --- atom/browser/native_window_mac.h | 1 - atom/browser/native_window_mac.mm | 11 ----------- lib/browser/api/browser-window.js | 3 +++ 7 files changed, 3 insertions(+), 33 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index ac3c510193ed..c95a43340418 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -623,12 +623,6 @@ void Window::UnhookAllWindowMessages() { } #endif -#if defined(OS_MACOSX) -void Window::ShowDefinitionForSelection() { - window_->ShowDefinitionForSelection(); -} -#endif - #if defined(TOOLKIT_VIEWS) void Window::SetIcon(mate::Handle icon) { #if defined(OS_WIN) @@ -760,10 +754,6 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("unhookWindowMessage", &Window::UnhookWindowMessage) .SetMethod("unhookAllWindowMessages", &Window::UnhookAllWindowMessages) #endif -#if defined(OS_MACOSX) - .SetMethod("showDefinitionForSelection", - &Window::ShowDefinitionForSelection) -#endif #if defined(TOOLKIT_VIEWS) .SetMethod("setIcon", &Window::SetIcon) #endif diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index e698eaaf78cc..23ab162261ff 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -169,10 +169,6 @@ class Window : public mate::TrackableObject, void UnhookAllWindowMessages(); #endif -#if defined(OS_MACOSX) - void ShowDefinitionForSelection(); -#endif - #if defined(TOOLKIT_VIEWS) void SetIcon(mate::Handle icon); #endif diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 46c3250a94a6..b50de48dc54b 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -334,10 +334,6 @@ void NativeWindow::CapturePage(const gfx::Rect& rect, kBGRA_8888_SkColorType); } -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 a12663a1aa5a..c7d099fcadf2 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -179,9 +179,6 @@ class NativeWindow : public base::SupportsUserData, virtual void CapturePage(const gfx::Rect& rect, const CapturePageCallback& callback); - // 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 52ebcbcb9c51..27857239e8c8 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -83,7 +83,6 @@ class NativeWindowMac : public NativeWindow { void SetProgressBar(double progress) override; void SetOverlayIcon(const gfx::Image& overlay, const std::string& description) override; - void ShowDefinitionForSelection() override; void SetVisibleOnAllWorkspaces(bool visible) override; bool IsVisibleOnAllWorkspaces() override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 995031a6f536..73aa3017eb3f 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -933,17 +933,6 @@ void NativeWindowMac::SetOverlayIcon(const gfx::Image& overlay, const std::string& description) { } -void NativeWindowMac::ShowDefinitionForSelection() { - // TODO(kevinsawicki): Deprecate and remove this method in 2.0 in favor of - // calling it directly on webContents. - if (!web_contents()) - return; - auto rwhv = web_contents()->GetRenderWidgetHostView(); - if (!rwhv) - return; - rwhv->ShowDefinitionForSelection(); -} - void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible) { SetCollectionBehavior(visible, NSWindowCollectionBehaviorCanJoinAllSpaces); } diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index ec61229368d1..6ac31e737b8c 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -151,6 +151,9 @@ Object.assign(BrowserWindow.prototype, { }, inspectServiceWorker () { return this.webContents.inspectServiceWorker() + }, + showDefinitionForSelection () { + return this.webContents.showDefinitionForSelection() } }) From 7250c461bef33feb5dfa56bc06dd3ff62c889af2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 8 Jun 2016 10:21:28 -0700 Subject: [PATCH 8/8] Remove NOTIMPLEMENTED() call --- atom/browser/api/atom_api_web_contents.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index b0927ee57298..6a18f0967b53 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1099,8 +1099,6 @@ void WebContents::ShowDefinitionForSelection() { const auto view = web_contents()->GetRenderWidgetHostView(); if (view) view->ShowDefinitionForSelection(); -#else - NOTIMPLEMENTED(); #endif }