Bug 1131695 - Ensure that mouse and touch events sent via BrowserElementParent to the child are offsetted correctly. r=fabrice
☠☠ backed out by dc2d6f67c231 ☠ ☠
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 13 Feb 2015 14:33:09 -0500
changeset 256244 13af514d6aea7bded99cf71fe219ba2621a9b263
parent 256243 6823625f20424fdeb060cc24607c1efb6fb3b8c3
child 256245 c5b1c517ad63bc99922dfe96a18ab0b964d350c0
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs1131695
milestone38.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 1131695 - Ensure that mouse and touch events sent via BrowserElementParent to the child are offsetted correctly. r=fabrice
dom/browser-element/BrowserElementParent.js
dom/interfaces/base/nsITabParent.idl
dom/ipc/TabParent.cpp
--- a/dom/browser-element/BrowserElementParent.js
+++ b/dom/browser-element/BrowserElementParent.js
@@ -533,17 +533,34 @@ BrowserElementParent.prototype = {
     if (!this._isAlive()) {
       throw Components.Exception("Dead content process",
                                  Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
     }
 
     return this._frameLoader.visible;
   },
 
+  getChildProcessOffset: function() {
+    let offset = { x: 0, y: 0 };
+    let tabParent = this._frameLoader.tabParent;
+    if (tabParent) {
+      let offsetX = {};
+      let offsetY = {};
+      tabParent.getChildProcessOffset(offsetX, offsetY);
+      offset.x = offsetX.value;
+      offset.y = offsetY.value;
+    }
+    return offset;
+  },
+
   sendMouseEvent: defineNoReturnMethod(function(type, x, y, button, clickCount, modifiers) {
+    let offset = this.getChildProcessOffset();
+    x += offset.x;
+    y += offset.y;
+
     this._sendAsyncMsg("send-mouse-event", {
       "type": type,
       "x": x,
       "y": y,
       "button": button,
       "clickCount": clickCount,
       "modifiers": modifiers
     });
@@ -561,16 +578,23 @@ BrowserElementParent.prototype = {
                                  touchesY,
                                  radiisX,
                                  radiisY,
                                  rotationAngles,
                                  forces,
                                  count,
                                  modifiers);
     } else {
+      let offset = this.getChildProcessOffset();
+      for (var i = 0; i < touchesX.length; i++) {
+        touchesX[i] += offset.x;
+      }
+      for (var i = 0; i < touchesY.length; i++) {
+        touchesY[i] += offset.y;
+      }
       this._sendAsyncMsg("send-touch-event", {
         "type": type,
         "identifiers": identifiers,
         "touchesX": touchesX,
         "touchesY": touchesY,
         "radiisX": radiisX,
         "radiisY": radiisY,
         "rotationAngles": rotationAngles,
--- a/dom/interfaces/base/nsITabParent.idl
+++ b/dom/interfaces/base/nsITabParent.idl
@@ -1,27 +1,29 @@
 /* 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/. */
 
 
 #include "domstubs.idl"
 
-[scriptable, uuid(30361a5b-a3b8-4dbc-b464-e08761abb123)]
+[scriptable, uuid(b19038ba-0d75-40d2-be35-742e26d33bf9)]
 interface nsITabParent : nsISupports
 {
   void injectTouchEvent(in AString aType,
                         [array, size_is(count)] in uint32_t aIdentifiers,
                         [array, size_is(count)] in int32_t aXs,
                         [array, size_is(count)] in int32_t aYs,
                         [array, size_is(count)] in uint32_t aRxs,
                         [array, size_is(count)] in uint32_t aRys,
                         [array, size_is(count)] in float aRotationAngles,
                         [array, size_is(count)] in float aForces,
                         in uint32_t count,
                         in long aModifiers);
 
+  void getChildProcessOffset(out int32_t aCssX, out int32_t aCssY);
+
   readonly attribute boolean useAsyncPanZoom;
 
   void setIsDocShellActive(in bool aIsActive);
 
   readonly attribute uint64_t tabId;
 };
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -1817,16 +1817,28 @@ TabParent::RecvEnableDisableCommands(con
     remoteBrowser->EnableDisableCommands(aAction,
                                          aEnabledCommands.Length(), enabledCommands,
                                          aDisabledCommands.Length(), disabledCommands);
   }
 
   return true;
 }
 
+NS_IMETHODIMP
+TabParent::GetChildProcessOffset(int32_t* aOutCssX, int32_t* aOutCssY)
+{
+  NS_ENSURE_ARG(aOutCssX);
+  NS_ENSURE_ARG(aOutCssY);
+  CSSPoint offset = LayoutDevicePoint(LayoutDeviceIntPoint::FromUntyped(GetChildProcessOffset()))
+      * GetLayoutDeviceToCSSScale();
+  *aOutCssX = offset.x;
+  *aOutCssY = offset.y;
+  return NS_OK;
+}
+
 nsIntPoint
 TabParent::GetChildProcessOffset()
 {
   // The "toplevel widget" in child processes is always at position
   // 0,0.  Map the event coordinates to match that.
 
   nsIntPoint offset(0, 0);
   nsRefPtr<nsFrameLoader> frameLoader = GetFrameLoader();