mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 828254 - Add context menu item to query default search provider using selection. r=mleibovic
This commit is contained in:
parent
343917fd58
commit
401241c946
@ -396,6 +396,15 @@ var SelectionHandler = {
|
||||
this._closeSelection();
|
||||
},
|
||||
|
||||
searchSelection: function sh_searchSelection() {
|
||||
let selectedText = this._getSelectedText();
|
||||
if (selectedText.length) {
|
||||
let req = Services.search.defaultEngine.getSubmission(selectedText);
|
||||
BrowserApp.selectOrOpenTab(req.uri.spec);
|
||||
}
|
||||
this._closeSelection();
|
||||
},
|
||||
|
||||
/*
|
||||
* Called if for any reason we fail during the selection
|
||||
* process. Cancels the selection.
|
||||
|
@ -2065,6 +2065,8 @@ var NativeWindow = {
|
||||
this.menuitems = [];
|
||||
let menuitemsSet = false;
|
||||
|
||||
Services.obs.notifyObservers(null, "before-build-contextmenu", "");
|
||||
|
||||
// now walk up the tree and for each node look for any context menu items that apply
|
||||
let element = target;
|
||||
this._nativeItemsSeparator = 0;
|
||||
@ -5962,6 +5964,9 @@ var IndexedDB = {
|
||||
};
|
||||
|
||||
var ClipboardHelper = {
|
||||
// Recorded so search with option can be removed/replaced when default engine changed.
|
||||
_searchMenuItem: -1,
|
||||
|
||||
init: function() {
|
||||
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.copy"), ClipboardHelper.getCopyContext(false), ClipboardHelper.copy.bind(ClipboardHelper));
|
||||
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.copyAll"), ClipboardHelper.getCopyContext(true), ClipboardHelper.copy.bind(ClipboardHelper));
|
||||
@ -5970,6 +5975,26 @@ var ClipboardHelper = {
|
||||
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.share"), ClipboardHelper.shareContext, ClipboardHelper.share.bind(ClipboardHelper));
|
||||
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.paste"), ClipboardHelper.pasteContext, ClipboardHelper.paste.bind(ClipboardHelper));
|
||||
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.changeInputMethod"), NativeWindow.contextmenus.textContext, ClipboardHelper.inputMethod.bind(ClipboardHelper));
|
||||
|
||||
// We add this contextmenu item right before the menu is built to avoid having to initialise the search service early.
|
||||
Services.obs.addObserver(this, "before-build-contextmenu", false);
|
||||
},
|
||||
|
||||
uninit: function ch_uninit() {
|
||||
Services.obs.removeObserver(this, "before-build-contextmenu");
|
||||
},
|
||||
|
||||
observe: function observe(aSubject, aTopic) {
|
||||
if (aTopic == "ContextMenu:Open") {
|
||||
this._setSearchMenuItem();
|
||||
}
|
||||
},
|
||||
|
||||
_setSearchMenuItem: function setSearchMenuItem() {
|
||||
if (this._searchMenuItem) {
|
||||
NativeWindow.contextmenus.remove(this._searchMenuItem);
|
||||
}
|
||||
this._searchMenuItem = NativeWindow.contextmenus.add(Strings.browser.formatStringFromName("contextmenu.search", [Services.search.defaultEngine.name], 1), ClipboardHelper.searchWithContext, ClipboardHelper.searchWith.bind(ClipboardHelper));
|
||||
},
|
||||
|
||||
get clipboardHelper() {
|
||||
@ -6006,6 +6031,10 @@ var ClipboardHelper = {
|
||||
SelectionHandler.selectAll(aElement, aX, aY);
|
||||
},
|
||||
|
||||
searchWith: function(aElement) {
|
||||
SelectionHandler.searchSelection(aElement);
|
||||
},
|
||||
|
||||
share: function() {
|
||||
SelectionHandler.shareSelection();
|
||||
},
|
||||
@ -6075,6 +6104,12 @@ var ClipboardHelper = {
|
||||
}
|
||||
},
|
||||
|
||||
searchWithContext: {
|
||||
matches: function searchWithContextMatches(aElement, aX, aY) {
|
||||
return SelectionHandler.shouldShowContextMenu(aX, aY);
|
||||
}
|
||||
},
|
||||
|
||||
pasteContext: {
|
||||
matches: function(aElement) {
|
||||
if (NativeWindow.contextmenus.textContext.matches(aElement)) {
|
||||
|
@ -165,6 +165,7 @@ contextmenu.changeInputMethod=Select Input Method
|
||||
contextmenu.fullScreen=Full Screen
|
||||
contextmenu.copyImageLocation=Copy Image Location
|
||||
contextmenu.shareImage=Share Image
|
||||
contextmenu.search=%S Search
|
||||
contextmenu.saveImage=Save Image
|
||||
contextmenu.setWallpaper=Set as Wallpaper
|
||||
contextmenu.addSearchEngine=Add Search Engine
|
||||
|
Loading…
Reference in New Issue
Block a user