Bug 465284: Open link in new tab [r=mark.finkle]

This commit is contained in:
Ben Combee 2009-10-23 12:02:40 -04:00
Родитель e041a0bc56
Коммит 0c4b89027a
3 изменённых файлов: 45 добавлений и 6 удалений

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

@ -406,9 +406,10 @@ InputHandler.EventInfo.prototype = {
* customClicker will be notified. The customClicker must support the following * customClicker will be notified. The customClicker must support the following
* interface: * interface:
* *
* singleClick(cx, cy) * singleClick(cx, cy, modifiers)
* Signals a single (as opposed to double) click occured at client * Signals a single (as opposed to double) click occured at client
* coordinates cx, cy * coordinates cx, cy. Specify optional modifiers to include
* shift-keys with click.
* *
* doubleClick(cx1, cy1, cx2, cy2) * doubleClick(cx1, cy1, cx2, cy2)
* Signals a doubleclick occured, with the first click at client coordinates * Signals a doubleclick occured, with the first click at client coordinates
@ -689,7 +690,14 @@ MouseModule.prototype = {
let ev = this._downUpEvents[1].event; let ev = this._downUpEvents[1].event;
this._cleanClickBuffer(2); this._cleanClickBuffer(2);
this._clicker.singleClick(ev.clientX, ev.clientY);
// borrowed from nsIDOMNSEvent.idl
let modifiers =
(ev.altKey ? Ci.nsIDOMNSEvent.ALT_MASK : 0) |
(ev.ctrlKey ? Ci.nsIDOMNSEvent.CONTROL_MASK : 0) |
(ev.shiftKey ? Ci.nsIDOMNSEvent.SHIFT_MASK : 0) |
(ev.metaKey ? Ci.nsIDOMNSEvent.META_MASK : 0);
this._clicker.singleClick(ev.clientX, ev.clientY, modifiers);
}, },
/** /**

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

@ -85,6 +85,28 @@ let Util = {
aFunc(); aFunc();
} }
}, Ci.nsIThread.DISPATCH_NORMAL); }, Ci.nsIThread.DISPATCH_NORMAL);
},
getHrefForElement: function getHrefForElement(target) {
// XXX: This is kind of a hack to work around a Gecko bug (see bug 266932)
// We're going to walk up the DOM looking for a parent link node.
// This shouldn't be necessary, but we're matching the existing behaviour for left click
let link = null;
while (target) {
if (target instanceof HTMLAnchorElement ||
target instanceof HTMLAreaElement ||
target instanceof HTMLLinkElement) {
if (target.hasAttribute("href"))
link = target;
}
target = target.parentNode;
}
if (link && link.hasAttribute("href"))
return link.href;
else
return null;
} }
}; };

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

@ -1524,9 +1524,18 @@ ContentCustomClicker.prototype = {
mouseUp: function mouseUp(cX, cY) { mouseUp: function mouseUp(cX, cY) {
}, },
singleClick: function singleClick(cX, cY) { singleClick: function singleClick(cX, cY, modifiers) {
this._dispatchMouseEvent("mousedown", cX, cY); if (modifiers == 0) {
this._dispatchMouseEvent("mouseup", cX, cY); this._dispatchMouseEvent("mousedown", cX, cY);
this._dispatchMouseEvent("mouseup", cX, cY);
}
else if (modifiers == Ci.nsIDOMNSEvent.CONTROL_MASK) {
let [elementX, elementY] = Browser.transformClientToBrowser(cX, cY);
let element = Browser.elementFromPoint(elementX, elementY);
let uri = Util.getHrefForElement(element);
if (uri)
Browser.addTab(uri, false);
}
}, },
doubleClick: function doubleClick(cX1, cY1, cX2, cY2) { doubleClick: function doubleClick(cX1, cY1, cX2, cY2) {