Merge pull request #5921 from electron/webview-show-definition-for-selection

Add showDefinitionForSelection to webContents/webview
This commit is contained in:
Kevin Sawicki 2016-06-08 10:40:10 -07:00
commit f4c1cd11a0
13 changed files with 25 additions and 33 deletions

View file

@ -1094,6 +1094,14 @@ void WebContents::StopFindInPage(content::StopFindAction action) {
web_contents()->StopFinding(action);
}
void WebContents::ShowDefinitionForSelection() {
#if defined(OS_MACOSX)
const auto view = web_contents()->GetRenderWidgetHostView();
if (view)
view->ShowDefinitionForSelection();
#endif
}
void WebContents::Focus() {
web_contents()->Focus();
}
@ -1289,6 +1297,8 @@ 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)

View file

@ -116,6 +116,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void ReplaceMisspelling(const base::string16& word);
uint32_t FindInPage(mate::Arguments* args);
void StopFindInPage(content::StopFindAction action);
void ShowDefinitionForSelection();
// Focus.
void Focus();

View file

@ -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<NativeImage> 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

View file

@ -169,10 +169,6 @@ class Window : public mate::TrackableObject<Window>,
void UnhookAllWindowMessages();
#endif
#if defined(OS_MACOSX)
void ShowDefinitionForSelection();
#endif
#if defined(TOOLKIT_VIEWS)
void SetIcon(mate::Handle<NativeImage> icon);
#endif

View file

@ -334,10 +334,6 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
kBGRA_8888_SkColorType);
}
void NativeWindow::ShowDefinitionForSelection() {
NOTIMPLEMENTED();
}
void NativeWindow::SetAutoHideMenuBar(bool auto_hide) {
}

View file

@ -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();

View file

@ -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;

View file

@ -933,15 +933,6 @@ void NativeWindowMac::SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) {
}
void NativeWindowMac::ShowDefinitionForSelection() {
if (!web_contents())
return;
auto rwhv = web_contents()->GetRenderWidgetHostView();
if (!rwhv)
return;
rwhv->ShowDefinitionForSelection();
}
void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible) {
SetCollectionBehavior(visible, NSWindowCollectionBehaviorCanJoinAllSpaces);
}

View file

@ -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_

View file

@ -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:

View file

@ -490,6 +490,10 @@ Sends an input `event` to the page.
See [webContents.sendInputEvent](web-contents.md##webcontentssendinputeventevent)
for detailed description of `event` object.
### `<webview>.showDefinitionForSelection()` _OS X_
Shows pop-up dictionary that searches the selected word on the page.
### `<webview>.getWebContents()`
Returns the [WebContents](web-contents.md) associated with this `webview`.

View file

@ -151,6 +151,9 @@ Object.assign(BrowserWindow.prototype, {
},
inspectServiceWorker () {
return this.webContents.inspectServiceWorker()
},
showDefinitionForSelection () {
return this.webContents.showDefinitionForSelection()
}
})

View file

@ -379,7 +379,8 @@ var registerWebViewElement = function () {
'downloadURL',
'inspectServiceWorker',
'print',
'printToPDF'
'printToPDF',
'showDefinitionForSelection'
]
nonblockMethods = [
'insertCSS',