Bug 976772 - [e10s] Make sure context menu appears at the right place, even in a subframe (r=felipe)
authorBill McCloskey <wmccloskey@mozilla.com>
Fri, 28 Feb 2014 16:58:52 -0800
changeset 171701 e4139eb421ffa24df5cff747ba54ab2882139a47
parent 171700 27a719294f4b455ba89bc2b83199675ae32f5efe
child 171702 9a822b2b8810f4ce5c48b039ec3b7a24cbe2c56b
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersfelipe
bugs976772
milestone30.0a1
Bug 976772 - [e10s] Make sure context menu appears at the right place, even in a subframe (r=felipe)
browser/base/content/tabbrowser.xml
toolkit/content/widgets/browser.xml
toolkit/content/widgets/remote-browser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -2991,20 +2991,19 @@
               if (titleChanged && !tab.selected && !tab.hasAttribute("busy"))
                 tab.setAttribute("titlechanged", "true");
               break;
             }
             case "contextmenu": {
               gContextMenuContentData = { event: aMessage.objects.event,
                                           browser: browser };
               let popup = browser.ownerDocument.getElementById("contentAreaContextMenu");
-              popup.openPopup(browser, "overlap",
-                              gContextMenuContentData.event.clientX,
-                              gContextMenuContentData.event.clientY,
-                              true, false, null);
+              let event = gContextMenuContentData.event;
+              let pos = browser.mapScreenCoordinatesFromContent(event.screenX, event.screenY);
+              popup.openPopupAtScreen(pos.x, pos.y, true);
               break;
             }
             case "DOMWebNotificationClicked": {
               let tab = this._getTabForBrowser(browser);
               if (!tab)
                 return;
               this.selectedTab = tab;
               window.focus();
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -1172,16 +1172,35 @@
                 break;
               }
             }
           }
         ]]>
         </body>
       </method>
 
+      <!--
+        For out-of-process code, event.screen[XY] is relative to the
+        left/top of the content view. For in-process code,
+        event.screen[XY] is relative to the left/top of the screen. We
+        use this method to map screen coordinates received from a
+        (possibly out-of-process) <browser> element to coordinates
+        that are relative to the screen. This code handles the
+        in-process case, where we return the coordinates unchanged.
+      -->
+      <method name="mapScreenCoordinatesFromContent">
+        <parameter name="aScreenX"/>
+        <parameter name="aScreenY"/>
+        <body>
+        <![CDATA[
+          return { x: aScreenX, y: aScreenY };
+        ]]>
+        </body>
+      </method>
+
       <method name="swapDocShells">
         <parameter name="aOtherBrowser"/>
         <body>
         <![CDATA[
           // We need to swap fields that are tied to our docshell or related to
           // the loaded page
           // Fields which are built as a result of notifactions (pageshow/hide,
           // DOMLinkAdded/Removed, onStateChange) should not be swapped here,
--- a/toolkit/content/widgets/remote-browser.xml
+++ b/toolkit/content/widgets/remote-browser.xml
@@ -232,13 +232,34 @@
               Cu.import("resource://gre/modules/SelectParentHelper.jsm");
               let dropdown = document.getElementById(this.getAttribute("selectpopup"));
               SelectParentHelper.hide(dropdown);
             }
           }
         ]]></body>
       </method>
 
+      <!--
+        For out-of-process code, event.screen[XY] is relative to the
+        left/top of the content view. For in-process code,
+        event.screen[XY] is relative to the left/top of the screen. We
+        use this method to map screen coordinates received from a
+        (possibly out-of-process) <browser> element to coordinates
+        that are relative to the screen. This code handles the
+        out-of-process case, where we need to translate by the screen
+        position of the <browser> element.
+      -->
+      <method name="mapScreenCoordinatesFromContent">
+        <parameter name="aScreenX"/>
+        <parameter name="aScreenY"/>
+        <body>
+        <![CDATA[
+          return { x: aScreenX + this.boxObject.screenX,
+                   y: aScreenY + this.boxObject.screenY };
+        ]]>
+        </body>
+      </method>
+
     </implementation>
 
   </binding>
 
 </bindings>