Bug 1543940 - Rely on chromeEventHandler for toolboxContextMenu events r=ochameau
☠☠ backed out by 6986b4b5c3db ☠ ☠
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 08 May 2019 15:13:32 +0000
changeset 473077 7fe9661e8510f9bf0430573aaceb7ed478e472b2
parent 473076 3bf1f379d77e758092f84df765e8c8726b0f3b98
child 473078 b1e6e932873c26533fe57f4d87e4c99f45f4097b
push id113065
push useropoprus@mozilla.com
push dateThu, 09 May 2019 03:46:59 +0000
treeherdermozilla-inbound@34a824c75b7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1543940
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543940 - Rely on chromeEventHandler for toolboxContextMenu events r=ochameau Using chromeEventHandler will allow us to catch events fired from any frame. By default when DevTools are in a type=chrome frame, events also bubble across frames. With type=content this is no longer the case. Differential Revision: https://phabricator.services.mozilla.com/D27693
devtools/client/framework/toolbox.js
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -170,16 +170,17 @@ function Toolbox(target, selectedTool, h
   this._onPickerStarting = this._onPickerStarting.bind(this);
   this._onPickerStarted = this._onPickerStarted.bind(this);
   this._onPickerStopped = this._onPickerStopped.bind(this);
   this._onPickerCanceled = this._onPickerCanceled.bind(this);
   this._onInspectObject = this._onInspectObject.bind(this);
   this._onNewSelectedNodeFront = this._onNewSelectedNodeFront.bind(this);
   this._onToolSelected = this._onToolSelected.bind(this);
   this._onTargetClosed = this._onTargetClosed.bind(this);
+  this._onContextMenu = this._onContextMenu.bind(this);
   this.updateToolboxButtonsVisibility = this.updateToolboxButtonsVisibility.bind(this);
   this.updateToolboxButtons = this.updateToolboxButtons.bind(this);
   this.selectTool = this.selectTool.bind(this);
   this._pingTelemetrySelectTool = this._pingTelemetrySelectTool.bind(this);
   this.toggleSplitConsole = this.toggleSplitConsole.bind(this);
   this.toggleOptions = this.toggleOptions.bind(this);
   this.togglePaintFlashing = this.togglePaintFlashing.bind(this);
   this.toggleDragging = this.toggleDragging.bind(this);
@@ -505,31 +506,16 @@ Toolbox.prototype = {
       this.isReady = true;
 
       const framesPromise = this._listFrames();
 
       Services.prefs.addObserver("devtools.cache.disabled", this._applyCacheSettings);
       Services.prefs.addObserver("devtools.serviceWorkers.testing.enabled",
                                  this._applyServiceWorkersTestingSettings);
 
-      // Register listener for handling context menus in standard
-      // input elements: <input> and <textarea>.
-      // There is also support for custom input elements using
-      // .devtools-input class (e.g. CodeMirror instances).
-      this.doc.addEventListener("contextmenu", (e) => {
-        if (e.originalTarget.closest("input[type=text]") ||
-            e.originalTarget.closest("input[type=search]") ||
-            e.originalTarget.closest("input:not([type])") ||
-            e.originalTarget.closest(".devtools-input") ||
-            e.originalTarget.closest("textarea")) {
-          e.stopPropagation();
-          e.preventDefault();
-          this.openTextBoxContextMenu(e.screenX, e.screenY);
-        }
-      });
       // Get the DOM element to mount the ToolboxController to.
       this._componentMount = this.doc.getElementById("toolbox-toolbar-mount");
 
       this._mountReactComponent();
       this._buildDockOptions();
       this._buildTabs();
       this._applyCacheSettings();
       this._applyServiceWorkersTestingSettings();
@@ -643,31 +629,33 @@ Toolbox.prototype = {
     }
 
     // Add shortcuts and window-host-shortcuts that use the ChromeEventHandler as target.
     this._addShortcuts();
     this._addWindowHostShortcuts();
 
     this._chromeEventHandler.addEventListener("keypress", this._splitConsoleOnKeypress);
     this._chromeEventHandler.addEventListener("focus", this._onFocus, true);
+    this._chromeEventHandler.addEventListener("contextmenu", this._onContextMenu);
   },
 
   _removeChromeEventHandlerEvents: function() {
     if (!this._chromeEventHandler) {
       return;
     }
 
     // Remove shortcuts and window-host-shortcuts that use the ChromeEventHandler as
     // target.
     this._removeShortcuts();
     this._removeWindowHostShortcuts();
 
     this._chromeEventHandler.removeEventListener("keypress",
       this._splitConsoleOnKeypress);
     this._chromeEventHandler.removeEventListener("focus", this._onFocus, true);
+    this._chromeEventHandler.removeEventListener("contextmenu", this._onContextMenu);
 
     this._chromeEventHandler = null;
   },
 
   _addShortcuts: function() {
     // Create shortcuts instance for the toolbox
     if (!this.shortcuts) {
       this.shortcuts = new KeyShortcuts({
@@ -789,16 +777,31 @@ Toolbox.prototype = {
 
   _removeWindowHostShortcuts: function() {
     if (this._windowHostShortcuts) {
       this._windowHostShortcuts.destroy();
       this._windowHostShortcuts = null;
     }
   },
 
+  _onContextMenu: function(e) {
+    // Handle context menu events in standard input elements: <input> and <textarea>.
+    // Also support for custom input elements using .devtools-input class
+    // (e.g. CodeMirror instances).
+    if (e.originalTarget.closest("input[type=text]") ||
+        e.originalTarget.closest("input[type=search]") ||
+        e.originalTarget.closest("input:not([type])") ||
+        e.originalTarget.closest(".devtools-input") ||
+        e.originalTarget.closest("textarea")) {
+      e.stopPropagation();
+      e.preventDefault();
+      this.openTextBoxContextMenu(e.screenX, e.screenY);
+    }
+  },
+
   _getDebugTargetData: function() {
     const url = new URL(this.win.location);
     const searchParams = new this.win.URLSearchParams(url.search);
 
     const targetType = searchParams.get("type") || DEBUG_TARGET_TYPES.TAB;
 
     const remoteId = searchParams.get("remoteId");
     const runtimeInfo = remoteClientManager.getRuntimeInfoByRemoteId(remoteId);