Bug 1364896 - Part 4 - Add a popupshowing listener to the entire document instead of individual elements. r=nhnt11

MozReview-Commit-ID: Fypw3TSziyk
This commit is contained in:
Johann Hofmann
2017-06-27 23:05:10 +02:00
parent 56bb768096
commit 24de9bfeca

View File

@@ -8229,54 +8229,12 @@ function 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;
}
@@ -8289,11 +8247,7 @@ var ContextMenuTouchModeObserver = {
},
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);
},
};