Bug 1424252 - [2.0] Enable text selection complementary to the HTML or native context menu. r=nechen

This commit is contained in:
Eugen Sawin 2018-01-19 16:31:15 +01:00
Родитель 536e7df90b
Коммит 9523035bec
1 изменённых файлов: 27 добавлений и 5 удалений

Просмотреть файл

@ -2691,6 +2691,10 @@ var NativeWindow = {
return this.defaultContext = Strings.browser.GetStringFromName("browser.menu.context.default");
},
get nonLinkContext() {
return "";
},
/* Gets menuitems for an arbitrary node
* Parameters:
* element - The element to look at. If this element has a contextmenu attribute, the
@ -2753,6 +2757,20 @@ var NativeWindow = {
return false;
},
// Returns true if there are any link-related context menu items
_shouldPreventDefault: function() {
for (let context in this.menus) {
if (context === this.nonLinkContext) {
continue;
}
let menu = this.menus[context];
if (menu.length > 0) {
return true;
}
}
return false;
},
/* Returns a label to be shown in a tabbed ui if there are multiple "contexts". For instance, if this
* is an image inside an <a> tag, we may have a "link" context and an "image" one.
*/
@ -2762,7 +2780,10 @@ var NativeWindow = {
try {
let uri = this.makeURI(this._getLinkURL(element));
return Strings.browser.GetStringFromName("browser.menu.context." + uri.scheme);
} catch(ex) { }
} catch(ex) {
// Fallback to the default
return this.defaultContext;
}
}
// Otherwise we try the nodeName
@ -2770,8 +2791,7 @@ var NativeWindow = {
return Strings.browser.GetStringFromName("browser.menu.context." + element.nodeName.toLowerCase());
} catch(ex) { }
// Fallback to the default
return this.defaultContext;
return this.nonLinkContext;
},
// Adds context menu items added through the add-on api
@ -2819,8 +2839,10 @@ var NativeWindow = {
if (this._shouldShow()) {
BrowserEventHandler._cancelTapHighlight();
// Consume / preventDefault the event, and show the contextmenu.
event.preventDefault();
if (this._shouldPreventDefault()) {
// Consume / preventDefault the event.
event.preventDefault();
}
this._innerShow(this._target, event.clientX, event.clientY);
this._target = null;