Bug 1405031 - Add middle-click and click modifiers to browserAction r=robwu
and pageActions. Before this change, browserActions and pageActions did not trigger onClick events when middle-clicked, and no information on the button or any modifiers were passed in the onClick event. With this change, middle clicking triggers an event, and a clickData object is passed in the onClick event, with the button and a list of modifiers. Differential Revision: https://phabricator.services.mozilla.com/D41492
This commit is contained in:
@@ -200,6 +200,8 @@ this.browserAction = class extends ExtensionAPI {
|
||||
node.onmousedown = event => this.handleEvent(event);
|
||||
node.onmouseover = event => this.handleEvent(event);
|
||||
node.onmouseout = event => this.handleEvent(event);
|
||||
node.onkeypress = event => this.handleEvent(event);
|
||||
node.onmouseup = event => this.handleMouseUp(event);
|
||||
|
||||
this.updateButton(node, this.globals, true);
|
||||
},
|
||||
@@ -280,7 +282,7 @@ this.browserAction = class extends ExtensionAPI {
|
||||
*/
|
||||
async triggerAction(window) {
|
||||
let popup = ViewPopup.for(this.extension, window);
|
||||
if (popup) {
|
||||
if (!this.pendingPopup && popup) {
|
||||
popup.closePopup();
|
||||
return;
|
||||
}
|
||||
@@ -307,10 +309,27 @@ this.browserAction = class extends ExtensionAPI {
|
||||
widget.node.dispatchEvent(event);
|
||||
} else {
|
||||
this.tabManager.addActiveTabPermission(tab);
|
||||
this.lastClickInfo = { button: 0, modifiers: [] };
|
||||
this.emit("click");
|
||||
}
|
||||
}
|
||||
|
||||
handleMouseUp(event) {
|
||||
let window = event.target.ownerGlobal;
|
||||
|
||||
this.lastClickInfo = {
|
||||
button: event.button,
|
||||
modifiers: clickModifiersFromEvent(event),
|
||||
};
|
||||
|
||||
if (event.button === 1) {
|
||||
let { gBrowser } = window;
|
||||
if (this.getProperty(gBrowser.selectedTab, "enabled")) {
|
||||
this.emit("click", gBrowser.selectedBrowser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleEvent(event) {
|
||||
let button = event.target;
|
||||
let window = button.ownerGlobal;
|
||||
@@ -412,6 +431,15 @@ this.browserAction = class extends ExtensionAPI {
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case "keypress":
|
||||
if (event.key === " " || event.key === "Enter") {
|
||||
this.lastClickInfo = {
|
||||
button: 0,
|
||||
modifiers: clickModifiersFromEvent(event),
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -760,7 +788,10 @@ this.browserAction = class extends ExtensionAPI {
|
||||
register: fire => {
|
||||
let listener = (event, browser) => {
|
||||
context.withPendingBrowser(browser, () =>
|
||||
fire.sync(tabManager.convert(tabTracker.activeTab))
|
||||
fire.sync(
|
||||
tabManager.convert(tabTracker.activeTab),
|
||||
browserAction.lastClickInfo
|
||||
)
|
||||
);
|
||||
};
|
||||
browserAction.on("click", listener);
|
||||
|
||||
Reference in New Issue
Block a user