Bug 1455462 - Part 3. Use zoom value when showing popup menu. r?jdescottes draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Fri, 11 May 2018 09:08:09 +0900
changeset 793949 65e2d48158344298ac071d29cdacfc295dd77a4d
parent 793948 2d18435b9043a4fdb2f1408c764f315d82ad5f26
child 793950 a88106da7ebaa84ec8a645b8e95dd32991e82871
push id109539
push userbmo:mantaroh@gmail.com
push dateFri, 11 May 2018 02:09:26 +0000
reviewersjdescottes
bugs1455462
milestone62.0a1
Bug 1455462 - Part 3. Use zoom value when showing popup menu. r?jdescottes The openPopupAtScreen() use the zoomed css coordinate value as position value, devtools's caller of this function use css pixel value without zoom. So position of popup will missaligned if zooming out/in the devtool panel. MozReview-Commit-ID: 4vvEssO41bO
devtools/client/framework/components/ToolboxTabs.js
devtools/client/framework/components/ToolboxToolbar.js
devtools/client/framework/menu.js
devtools/client/framework/toolbox.js
devtools/client/shared/components/tabs/TabBar.js
--- a/devtools/client/framework/components/ToolboxTabs.js
+++ b/devtools/client/framework/components/ToolboxTabs.js
@@ -215,17 +215,17 @@ class ToolboxTabs extends Component {
           }
         });
 
         let rect = target.getBoundingClientRect();
         let screenX = target.ownerDocument.defaultView.mozInnerScreenX;
         let screenY = target.ownerDocument.defaultView.mozInnerScreenY;
 
         // Display the popup below the button.
-        menu.popup(rect.left + screenX, rect.bottom + screenY, toolbox);
+        menu.popupWithZoom(rect.left + screenX, rect.bottom + screenY, toolbox);
         return menu;
       },
     });
   }
 
   /**
    * Render all of the tabs, based on the panel definitions and builds out
    * a toolbox tab for each of them. Will render the chevron button if the
--- a/devtools/client/framework/components/ToolboxToolbar.js
+++ b/devtools/client/framework/components/ToolboxToolbar.js
@@ -429,10 +429,10 @@ function showMeatballMenu(
     },
   }));
 
   const rect = menuButton.getBoundingClientRect();
   const screenX = menuButton.ownerDocument.defaultView.mozInnerScreenX;
   const screenY = menuButton.ownerDocument.defaultView.mozInnerScreenY;
 
   // Display the popup below the button.
-  menu.popup(rect.left + screenX, rect.bottom + screenY, toolbox);
+  menu.popupWithZoom(rect.left + screenX, rect.bottom + screenY, toolbox);
 }
--- a/devtools/client/framework/menu.js
+++ b/devtools/client/framework/menu.js
@@ -1,16 +1,17 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+const Services = require("Services");
 const EventEmitter = require("devtools/shared/event-emitter");
 
 /**
  * A partial implementation of the Menu API provided by electron:
  * https://github.com/electron/electron/blob/master/docs/api/menu.md.
  *
  * Extra features:
  *  - Emits an 'open' and 'close' event when the menu is opened/closed
@@ -46,16 +47,34 @@ Menu.prototype.append = function(menuIte
  * @param {int} pos
  * @param {MenuItem} menuItem
  */
 Menu.prototype.insert = function(pos, menuItem) {
   throw Error("Not implemented");
 };
 
 /**
+ * Show the Menu with anchor element's coordinate.
+ * For example, In the case of zoom in/out the devtool panel, we should multiply
+ * element's position to zoom value.
+ * If you know the screen coodinate of display position, you should use Menu.pop().
+ *
+ * @param {int} x
+ * @param {int} y
+ * @param Toolbox toolbox
+ */
+Menu.prototype.popupWithZoom = function(x, y, toolbox) {
+  let zoom = parseFloat(Services.prefs.getCharPref("devtools.toolbox.zoomValue"));
+  if (!zoom || isNaN(zoom)) {
+    zoom = 1.0;
+  }
+  this.popup(x * zoom, y * zoom, toolbox);
+};
+
+/**
  * Show the Menu at a specified location on the screen
  *
  * Missing features:
  *   - browserWindow - BrowserWindow (optional) - Default is null.
  *   - positioningItem Number - (optional) OS X
  *
  * @param {int} screenX
  * @param {int} screenY
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -2275,17 +2275,17 @@ Toolbox.prototype = {
     // Show a drop down menu with frames.
     // XXX Missing menu API for specifying target (anchor)
     // and relative position to it. See also:
     // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Method/openPopup
     // https://bugzilla.mozilla.org/show_bug.cgi?id=1274551
     let rect = target.getBoundingClientRect();
     let screenX = target.ownerDocument.defaultView.mozInnerScreenX;
     let screenY = target.ownerDocument.defaultView.mozInnerScreenY;
-    menu.popup(rect.left + screenX, rect.bottom + screenY, this);
+    menu.popupWithZoom(rect.left + screenX, rect.bottom + screenY, this);
 
     return menu;
   },
 
   /**
    * Handle keyDown event on 'frames' button to show available frames
    */
   handleKeyDownOnFramesButton: function(event) {
--- a/devtools/client/shared/components/tabs/TabBar.js
+++ b/devtools/client/shared/components/tabs/TabBar.js
@@ -234,18 +234,18 @@ class Tabbar extends Component {
     // Show a drop down menu with frames.
     // XXX Missing menu API for specifying target (anchor)
     // and relative position to it. See also:
     // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Method/openPopup
     // https://bugzilla.mozilla.org/show_bug.cgi?id=1274551
     let rect = target.getBoundingClientRect();
     let screenX = target.ownerDocument.defaultView.mozInnerScreenX;
     let screenY = target.ownerDocument.defaultView.mozInnerScreenY;
-    menu.popup(rect.left + screenX, rect.bottom + screenY,
-      { doc: this.props.menuDocument });
+    menu.popupWithZoom(rect.left + screenX, rect.bottom + screenY,
+                       { doc: this.props.menuDocument });
 
     return menu;
   }
 
   // Rendering
 
   renderTab(tab) {
     if (typeof tab.panel === "function") {