mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-04 15:51:37 +00:00
Bug 714789 - Don't show "Open in new tab" for non-openable links [r=mfinkle]
This commit is contained in:
parent
c59241f100
commit
ca09bf547d
@ -62,6 +62,8 @@ XPCOMUtils.defineLazyServiceGetter(this, "DOMUtils",
|
|||||||
|
|
||||||
const kStateActive = 0x00000001; // :active pseudoclass for elements
|
const kStateActive = 0x00000001; // :active pseudoclass for elements
|
||||||
|
|
||||||
|
const kXLinkNamespace = "http://www.w3.org/1999/xlink";
|
||||||
|
|
||||||
// TODO: Take into account ppi in these units?
|
// TODO: Take into account ppi in these units?
|
||||||
|
|
||||||
// The ratio of velocity that is retained every ms.
|
// The ratio of velocity that is retained every ms.
|
||||||
@ -922,19 +924,18 @@ var NativeWindow = {
|
|||||||
contextmenus: {
|
contextmenus: {
|
||||||
items: {}, // a list of context menu items that we may show
|
items: {}, // a list of context menu items that we may show
|
||||||
textContext: null, // saved selector for text input areas
|
textContext: null, // saved selector for text input areas
|
||||||
linkContext: null, // saved selector for links
|
|
||||||
_contextId: 0, // id to assign to new context menu items if they are added
|
_contextId: 0, // id to assign to new context menu items if they are added
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
this.textContext = this.SelectorContext("input[type='text'],input[type='password'],textarea");
|
this.textContext = this.SelectorContext("input[type='text'],input[type='password'],textarea");
|
||||||
this.linkContext = this.SelectorContext("a:not([href='']),area:not([href='']),link");
|
|
||||||
this.imageContext = this.SelectorContext("img");
|
this.imageContext = this.SelectorContext("img");
|
||||||
|
|
||||||
Services.obs.addObserver(this, "Gesture:LongPress", false);
|
Services.obs.addObserver(this, "Gesture:LongPress", false);
|
||||||
|
|
||||||
// TODO: These should eventually move into more appropriate classes
|
// TODO: These should eventually move into more appropriate classes
|
||||||
this.add(Strings.browser.GetStringFromName("contextmenu.openInNewTab"),
|
this.add(Strings.browser.GetStringFromName("contextmenu.openInNewTab"),
|
||||||
this.linkContext,
|
this.linkOpenableContext,
|
||||||
function(aTarget) {
|
function(aTarget) {
|
||||||
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
|
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
|
||||||
BrowserApp.addTab(url, { selected: false, parentId: BrowserApp.selectedTab.id });
|
BrowserApp.addTab(url, { selected: false, parentId: BrowserApp.selectedTab.id });
|
||||||
@ -1007,6 +1008,32 @@ var NativeWindow = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
linkOpenableContext: {
|
||||||
|
matches: function linkOpenableContextMatches(aElement) {
|
||||||
|
if (aElement.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
||||||
|
((aElement instanceof Ci.nsIDOMHTMLAnchorElement && aElement.href) ||
|
||||||
|
(aElement instanceof Ci.nsIDOMHTMLAreaElement && aElement.href) ||
|
||||||
|
aElement instanceof Ci.nsIDOMHTMLLinkElement ||
|
||||||
|
aElement.getAttributeNS(kXLinkNamespace, "type") == "simple")) {
|
||||||
|
let uri;
|
||||||
|
try {
|
||||||
|
let url = NativeWindow.contextmenus._getLinkURL(aElement);
|
||||||
|
uri = Services.io.newURI(url, null, null);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let scheme = uri.scheme;
|
||||||
|
if (!scheme)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
let dontOpen = /^(mailto|javascript|news|snews)$/;
|
||||||
|
return (scheme && !dontOpen.test(scheme));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_sendToContent: function(aX, aY) {
|
_sendToContent: function(aX, aY) {
|
||||||
// initially we look for nearby clickable elements. If we don't find one we fall back to using whatever this click was on
|
// initially we look for nearby clickable elements. If we don't find one we fall back to using whatever this click was on
|
||||||
let rootElement = ElementTouchHelper.elementFromPoint(BrowserApp.selectedBrowser.contentWindow, aX, aY);
|
let rootElement = ElementTouchHelper.elementFromPoint(BrowserApp.selectedBrowser.contentWindow, aX, aY);
|
||||||
@ -1029,7 +1056,7 @@ var NativeWindow = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.linkContext.matches(element) || this.textContext.matches(element))
|
if (this.linkOpenableContext.matches(element) || this.textContext.matches(element))
|
||||||
break;
|
break;
|
||||||
element = element.parentNode;
|
element = element.parentNode;
|
||||||
}
|
}
|
||||||
@ -1124,7 +1151,7 @@ var NativeWindow = {
|
|||||||
throw "Empty href";
|
throw "Empty href";
|
||||||
}
|
}
|
||||||
|
|
||||||
return Util.makeURLAbsolute(aLink.baseURI, href);
|
return this.makeURLAbsolute(aLink.baseURI, href);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user