| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file provides common functionality for synthetic gesture actions. | 5 // This file provides common functionality for synthetic gesture actions. |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 (function() { | 8 (function() { |
| 9 | 9 |
| 10 // Make sure functions are injected only once. | 10 // Make sure functions are injected only once. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // Zoom-independent window height. See crbug.com/627123 for more details. | 43 // Zoom-independent window height. See crbug.com/627123 for more details. |
| 44 function getWindowHeight() { | 44 function getWindowHeight() { |
| 45 return getPageScaleFactor() * chrome.gpuBenchmarking.visualViewportHeight(); | 45 return getPageScaleFactor() * chrome.gpuBenchmarking.visualViewportHeight(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Zoom-independent window width. See crbug.com/627123 for more details. | 48 // Zoom-independent window width. See crbug.com/627123 for more details. |
| 49 function getWindowWidth() { | 49 function getWindowWidth() { |
| 50 return getPageScaleFactor() * chrome.gpuBenchmarking.visualViewportWidth(); | 50 return getPageScaleFactor() * chrome.gpuBenchmarking.visualViewportWidth(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 function clamp(min, value, max) { |
| 54 return Math.min(Math.max(min, value), max); |
| 55 } |
| 56 |
| 53 function getBoundingVisibleRect(el) { | 57 function getBoundingVisibleRect(el) { |
| 54 // Get the element bounding rect. | 58 // Get the element bounding rect. |
| 55 var rect = getBoundingRect(el); | 59 var rect = getBoundingRect(el); |
| 56 | 60 |
| 57 // Then clip the rect to the screen size. | 61 // Get the window dimensions. |
| 58 if (rect.top < 0) { | |
| 59 rect.height += rect.top; | |
| 60 rect.top = 0; | |
| 61 if (rect.height < 0) { | |
| 62 rect.height = 0; // The whole of the element is out of screen. | |
| 63 } | |
| 64 } | |
| 65 if (rect.left < 0) { | |
| 66 rect.width += rect.left; | |
| 67 rect.left = 0; | |
| 68 if (rect.width < 0) { | |
| 69 rect.width = 0; // The whole of the element is out of screen. | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 var windowHeight = getWindowHeight(); | 62 var windowHeight = getWindowHeight(); |
| 74 var windowWidth = getWindowWidth(); | 63 var windowWidth = getWindowWidth(); |
| 75 var outsideHeight = (rect.top + rect.height) - windowHeight; | |
| 76 var outsideWidth = (rect.left + rect.width) - windowWidth; | |
| 77 | 64 |
| 78 if (outsideHeight > 0) { | 65 // Then clip the rect to the screen size. |
| 79 rect.height -= outsideHeight; | 66 rect.top = clamp(0, rect.top, windowHeight); |
| 80 } | 67 rect.left = clamp(0, rect.left, windowWidth); |
| 81 if (outsideWidth > 0) { | 68 rect.height = clamp(0, rect.height, windowHeight - rect.top); |
| 82 rect.width -= outsideWidth; | 69 rect.width = clamp(0, rect.width, windowWidth - rect.left); |
| 83 } | 70 |
| 84 return rect; | 71 return rect; |
| 85 } | 72 } |
| 86 | 73 |
| 87 window.__GestureCommon_GetBoundingVisibleRect = getBoundingVisibleRect; | 74 window.__GestureCommon_GetBoundingVisibleRect = getBoundingVisibleRect; |
| 88 window.__GestureCommon_GetWindowHeight = getWindowHeight; | 75 window.__GestureCommon_GetWindowHeight = getWindowHeight; |
| 89 window.__GestureCommon_GetWindowWidth = getWindowWidth; | 76 window.__GestureCommon_GetWindowWidth = getWindowWidth; |
| 90 })(); | 77 })(); |
| OLD | NEW |