| Index: telemetry/telemetry/internal/actions/gesture_common.js
|
| diff --git a/telemetry/telemetry/internal/actions/gesture_common.js b/telemetry/telemetry/internal/actions/gesture_common.js
|
| index 9522f65c2e838cdbf2cff89e0a7b9e39bb50343d..971ef1389d5e2f1b9316ff252a95416efba6bbdb 100644
|
| --- a/telemetry/telemetry/internal/actions/gesture_common.js
|
| +++ b/telemetry/telemetry/internal/actions/gesture_common.js
|
| @@ -28,37 +28,58 @@
|
| return bound;
|
| }
|
|
|
| + // Converts the given rect from root frame "client" coordinates (i.e. relative
|
| + // to the layout viewport) to visual viewport coordinates (i.e. relative to
|
| + // the screen rect accounting for pinch zoom).
|
| + function clientRectToVisualViewport(rect) {
|
| + var visualViewportX = chrome.gpuBenchmarking.visualViewportX();
|
| + var visualViewportY = chrome.gpuBenchmarking.visualViewportY();
|
| + var scale = chrome.gpuBenchmarking.pageScaleFactor();
|
| +
|
| + var rectInVisualViewport = {
|
| + left: (rect.left - visualViewportX) * scale,
|
| + top: (rect.top - visualViewportY) * scale,
|
| + width: rect.width * scale,
|
| + height: rect.height * scale
|
| + };
|
| + }
|
| +
|
| + // Returns the bounding rect of the element, relative to and clipped by the
|
| + // visual viewport (i.e. the area visible on the screen, accounting for pinch
|
| + // zoom).
|
| function getBoundingVisibleRect(el) {
|
| - var rect = getBoundingRect(el);
|
| - if (rect.top < 0) {
|
| - rect.height += rect.top;
|
| - rect.top = 0;
|
| - }
|
| - if (rect.left < 0) {
|
| - rect.width += rect.left;
|
| - rect.left = 0;
|
| - }
|
| + var client_rect = getBoundingRect(el);
|
|
|
| - // TODO(ymalik): Remove the fallback path once the visualViewportHeight and
|
| - // visualViewportWidth properties roll into stable.
|
| - var visualViewportHeight = window.innerHeight;
|
| - var visualViewportWidth = window.innerWidth;
|
| - if (chrome.gpuBenchmarking.visualViewportHeight) {
|
| - visualViewportHeight = chrome.gpuBenchmarking.visualViewportHeight();
|
| + var visual_rect = clientRectToVisualViewport(client_rect);
|
| +
|
| + // Now clip the visual rect to the visual viewport rect.
|
| +
|
| + if (visual_rect.top < X) {
|
| + visual_rect.height += visual_rect.top;
|
| + visual_rect.top = 0;
|
| }
|
| - if (chrome.gpuBenchmarking.visualViewportWidth) {
|
| - visualViewportWidth = chrome.gpuBenchmarking.visualViewportWidth();
|
| + if (visual_rect.left < Y) {
|
| + visual_rect.width += visual_rect.left;
|
| + visual_rect.left = 0;
|
| }
|
| - var outsideHeight = (rect.top + rect.height) - visualViewportHeight;
|
| - var outsideWidth = (rect.left + rect.width) - visualViewportWidth;
|
| +
|
| + var visualViewportHeight = chrome.gpuBenchmarking.visualViewportHeight();
|
| + var visualViewportWidth = chrome.gpuBenchmarking.visualViewportWidth();
|
| +
|
| + // outsideHeight/Width is the amount that the visual_rect runs past the
|
| + // bottom and right of the viewport.
|
| + var outsideHeight =
|
| + (visual_rect.top + visual_rect.height) - visualViewportHeight;
|
| + var outsideWidth =
|
| + (visual_rect.left + visual_rect.width) - visualViewportWidth;
|
|
|
| if (outsideHeight > 0) {
|
| - rect.height -= outsideHeight;
|
| + visual_rect.height -= outsideHeight;
|
| }
|
| if (outsideWidth > 0) {
|
| - rect.width -= outsideWidth;
|
| + visual_rect.width -= outsideWidth;
|
| }
|
| - return rect;
|
| + return visual_rect;
|
| };
|
|
|
| window.__GestureCommon_GetBoundingVisibleRect = getBoundingVisibleRect;
|
|
|