Bug 1009351 - Add link text to mozbrowser context menu data. r=smaug

This commit is contained in:
"Kan-Ru Chen (陳侃如)" 2014-06-14 15:16:26 +08:00
parent ada0098088
commit dc42453d34
2 changed files with 8 additions and 1 deletions

View File

@ -13,6 +13,8 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/BrowserElementPromptService.jsm");
let kLongestReturnedString = 128;
// Event whitelisted for bubbling.
let whitelistedEvents = [
Ci.nsIDOMKeyEvent.DOM_VK_ESCAPE, // Back button.
@ -695,7 +697,8 @@ BrowserElementChild.prototype = {
_getSystemCtxMenuData: function(elem) {
if ((elem instanceof Ci.nsIDOMHTMLAnchorElement && elem.href) ||
(elem instanceof Ci.nsIDOMHTMLAreaElement && elem.href)) {
return {uri: elem.href};
return {uri: elem.href,
text: elem.textContent.substring(0, kLongestReturnedString)};
}
if (elem instanceof Ci.nsIImageLoadingContent && elem.currentURI) {
return {uri: elem.currentURI.spec};

View File

@ -25,6 +25,10 @@ function checkInnerContextMenu() {
sendContextMenuTo('#inner-link', function onContextMenu(detail) {
is(detail.systemTargets.length, 1, 'Includes anchor data');
is(detail.contextmenu.items.length, 2, 'Inner clicks trigger correct menu');
var target = detail.systemTargets[0];
is(target.nodeName, 'A', 'Reports correct nodeName');
is(target.data.uri, 'foo.html', 'Reports correct uri');
is(target.data.text, 'Menu 1', 'Reports correct link text');
checkCustomContextMenu();
});