Bug 1364896 - Part 4 - Add a popupshowing listener to the entire document instead of individual elements. r=nhnt11
MozReview-Commit-ID: Fypw3TSziyk
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -8224,81 +8224,35 @@ var RestoreLastSessionObserver = {
function restoreLastSession() {
SessionStore.restoreLastSession();
}
/* Observes context menus and adjusts their size for better
* usability when opened via a touch screen. */
var ContextMenuTouchModeObserver = {
- get _searchBarContextMenu() {
- let searchbar = document.getElementById("searchbar");
- let textBox = document.getAnonymousElementByAttribute(searchbar,
- "anonid", "searchbar-textbox");
- let inputBox = document.getAnonymousElementByAttribute(textBox,
- "anonid", "textbox-input-box");
- let menu = document.getAnonymousElementByAttribute(inputBox,
- "anonid", "input-box-contextmenu");
- return menu;
- },
-
- get _urlBarContextMenu() {
- let urlbar = document.getElementById("urlbar");
- let textBox = document.getAnonymousElementByAttribute(urlbar,
- "anonid", "textbox-input-box");
- let menu = document.getAnonymousElementByAttribute(textBox,
- "anonid", "input-box-contextmenu");
- return menu;
- },
-
- _addListener(el) {
- el.addEventListener("popupshowing", this);
- },
-
- _removeListener(el) {
- el.removeEventListener("popupshowing", this);
- },
-
init() {
- // Start observing different context menus for popupshowing.
-
- // The main popup set, which contains several context menus,
- // e.g. the page content area context menu.
- this._addListener(document.getElementById("mainPopupSet"));
-
- // The navigation context menu of the back and forward button.
- this._addListener(document.getElementById("back-button"));
- this._addListener(document.getElementById("forward-button"));
-
- // The search bar context menu.
- this._addListener(this._searchBarContextMenu);
-
- // The url bar context menu.
- this._addListener(this._urlBarContextMenu);
+ window.addEventListener("popupshowing", this, true);
},
handleEvent(event) {
- let target = event.target;
+ let target = event.originalTarget;
if (target.localName != "menupopup") {
return;
}
if (event.mozInputSource == MouseEvent.MOZ_SOURCE_TOUCH) {
target.setAttribute("touchmode", "true");
} else {
target.removeAttribute("touchmode");
}
},
uninit() {
- this._removeListener(document.getElementById("mainPopupSet"));
- this._removeListener(document.getElementById("back-button"));
- this._removeListener(document.getElementById("forward-button"));
- this._removeListener(this._searchBarContextMenu);
- this._removeListener(this._urlBarContextMenu);
+ window.removeEventListener("popupshowing", this, true);
},
};
var TabContextMenu = {
contextTab: null,
_updateToggleMuteMenuItem(aTab, aConditionFn) {
["muted", "soundplaying"].forEach(attr => {
if (!aConditionFn || aConditionFn(attr)) {