Bug 1476221 - Keep the bounding client rect of the 'FormAssist:AutoCompleteResults' message relative to the visual viewport. r=mstange a=pascalc
authorBotond Ballo <botond@mozilla.com>
Thu, 20 Sep 2018 19:31:54 +0000
changeset 490136 52c77c08b8a50b158a75d4b4948babb42350c0ae
parent 490135 2658fb7e9e994e9a581399e445a640ec7449d956
child 490137 3fa0c4d514c91c625d0a6f8c2cae2b3c7157b712
push id9915
push userebalazs@mozilla.com
push dateMon, 01 Oct 2018 13:10:22 +0000
treeherdermozilla-beta@f76a129ff2f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, pascalc
bugs1476221
milestone63.0
Bug 1476221 - Keep the bounding client rect of the 'FormAssist:AutoCompleteResults' message relative to the visual viewport. r=mstange a=pascalc Depends on D6090 Differential Revision: https://phabricator.services.mozilla.com/D6091
mobile/android/modules/FormAssistant.jsm
--- a/mobile/android/modules/FormAssistant.jsm
+++ b/mobile/android/modules/FormAssistant.jsm
@@ -373,18 +373,26 @@ var FormAssistant = {
       // adjust client coordinates' origin to be top left of iframe viewport
       let rect = frame.frameElement.getBoundingClientRect();
       let left = frame.getComputedStyle(frame.frameElement).borderLeftWidth;
       let top = frame.getComputedStyle(frame.frameElement).borderTopWidth;
       scrollX += rect.left + parseInt(left);
       scrollY += rect.top + parseInt(top);
     }
 
+    // The rect computed above is relative to the origin of the viewport frame,
+    // i.e. the layout viewport origin, but the consumer of the
+    // FormAssist::AutoCompleteResult messaage expects a rect relative to
+    // the visual viewport origin, so translate between the two.
+    let offsetX = {}, offsetY = {};
+    aElement.ownerGlobal.windowUtils
+        .getVisualViewportOffsetRelativeToLayoutViewport(offsetX, offsetY);
+
     return {
-      x: r.left + scrollX,
-      y: r.top + scrollY,
+      x: r.left + scrollX - offsetX.value,
+      y: r.top + scrollY - offsetY.value,
       w: r.width,
       h: r.height,
     };
   },
 };
 
 FormAssistant.init();