Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Unified Diff: telemetry/telemetry/internal/actions/gesture_common.js

Issue 2617503002: [telemetry] Let ScrollToElement callers pass root (Closed)
Patch Set: disable on android Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a9d5b6a3acd75d9668f028b384d2eb13c3e01385..ec76ebaedb258ba8a7a2db3eec455dd3baee7273 100644
--- a/telemetry/telemetry/internal/actions/gesture_common.js
+++ b/telemetry/telemetry/internal/actions/gesture_common.js
@@ -50,37 +50,24 @@
return getPageScaleFactor() * chrome.gpuBenchmarking.visualViewportWidth();
}
+ function clamp(min, value, max) {
+ return Math.min(Math.max(min, value), max);
+ }
+
function getBoundingVisibleRect(el) {
// Get the element bounding rect.
var rect = getBoundingRect(el);
- // Then clip the rect to the screen size.
- if (rect.top < 0) {
- rect.height += rect.top;
- rect.top = 0;
- if (rect.height < 0) {
- rect.height = 0; // The whole of the element is out of screen.
- }
- }
- if (rect.left < 0) {
- rect.width += rect.left;
- rect.left = 0;
- if (rect.width < 0) {
- rect.width = 0; // The whole of the element is out of screen.
- }
- }
-
+ // Get the window dimensions.
var windowHeight = getWindowHeight();
var windowWidth = getWindowWidth();
- var outsideHeight = (rect.top + rect.height) - windowHeight;
- var outsideWidth = (rect.left + rect.width) - windowWidth;
- if (outsideHeight > 0) {
- rect.height -= outsideHeight;
- }
- if (outsideWidth > 0) {
- rect.width -= outsideWidth;
- }
+ // Then clip the rect to the screen size.
+ rect.top = clamp(0, rect.top, windowHeight);
+ rect.left = clamp(0, rect.left, windowWidth);
+ rect.height = clamp(0, rect.height, windowHeight - rect.top);
+ rect.width = clamp(0, rect.width, windowWidth - rect.left);
+
return rect;
}

Powered by Google App Engine
This is Rietveld 408576698