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

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

Issue 2532443002: [telemetry] Bullet proof scroll.js (Closed)
Patch Set: fix for comments Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/internal/actions/scroll.js
diff --git a/telemetry/telemetry/internal/actions/scroll.js b/telemetry/telemetry/internal/actions/scroll.js
index 2cc565011e1aa0ce134354410ec8e45d716fe2d9..7c72c88e8575d28c6e792f6f2021e6366343e230 100644
--- a/telemetry/telemetry/internal/actions/scroll.js
+++ b/telemetry/telemetry/internal/actions/scroll.js
@@ -14,15 +14,15 @@
function ScrollGestureOptions(opt_options) {
if (opt_options) {
this.element_ = opt_options.element;
- this.left_start_ratio_ = opt_options.left_start_ratio;
- this.top_start_ratio_ = opt_options.top_start_ratio;
+ this.leftStartRatio_ = opt_options.left_start_ratio;
+ this.topStartRatio_ = opt_options.top_start_ratio;
this.direction_ = opt_options.direction;
this.speed_ = opt_options.speed;
this.gesture_source_type_ = opt_options.gesture_source_type;
} else {
this.element_ = document.scrollingElement || document.body;
- this.left_start_ratio_ = 0.5;
- this.top_start_ratio_ = 0.5;
+ this.leftStartRatio_ = 0.5;
+ this.topStartRatio_ = 0.5;
this.direction_ = 'down';
this.speed_ = 800;
this.gesture_source_type_ = chrome.gpuBenchmarking.DEFAULT_INPUT;
@@ -40,20 +40,20 @@
// This class scrolls a page from the top to the bottom once.
//
// The page is scrolled down by a single scroll gesture.
- function ScrollAction(opt_callback, opt_distance_func) {
+ function ScrollAction(opt_callback, opt_distanceFunc) {
var self = this;
this.beginMeasuringHook = function() {};
this.endMeasuringHook = function() {};
this.callback_ = opt_callback;
- this.distance_func_ = opt_distance_func;
+ this.distance_func_ = opt_distanceFunc;
}
ScrollAction.prototype.getScrollDistanceDown_ = function() {
var clientHeight;
// clientHeight is "special" for the body element.
- if (this.element_ == document.body)
+ if (this.element_ === document.body)
clientHeight = __GestureCommon_GetWindowHeight();
else
clientHeight = this.element_.clientHeight;
@@ -70,7 +70,7 @@
ScrollAction.prototype.getScrollDistanceRight_ = function() {
var clientWidth;
// clientWidth is "special" for the body element.
- if (this.element_ == document.body)
+ if (this.element_ === document.body)
clientWidth = __GestureCommon_GetWindowWidth();
else
clientWidth = this.element_.clientWidth;
@@ -86,24 +86,24 @@
if (this.distance_func_)
return this.distance_func_();
- if (this.options_.direction_ == 'down') {
+ if (this.options_.direction_ === 'down') {
return this.getScrollDistanceDown_();
- } else if (this.options_.direction_ == 'up') {
+ } else if (this.options_.direction_ === 'up') {
return this.getScrollDistanceUp_();
- } else if (this.options_.direction_ == 'right') {
+ } else if (this.options_.direction_ === 'right') {
return this.getScrollDistanceRight_();
- } else if (this.options_.direction_ == 'left') {
+ } else if (this.options_.direction_ === 'left') {
return this.getScrollDistanceLeft_();
- } else if (this.options_.direction_ == 'upleft') {
+ } else if (this.options_.direction_ === 'upleft') {
return Math.min(this.getScrollDistanceUp_(),
this.getScrollDistanceLeft_());
- } else if (this.options_.direction_ == 'upright') {
+ } else if (this.options_.direction_ === 'upright') {
return Math.min(this.getScrollDistanceUp_(),
this.getScrollDistanceRight_());
- } else if (this.options_.direction_ == 'downleft') {
+ } else if (this.options_.direction_ === 'downleft') {
return Math.min(this.getScrollDistanceDown_(),
this.getScrollDistanceLeft_());
- } else if (this.options_.direction_ == 'downright') {
+ } else if (this.options_.direction_ === 'downright') {
return Math.min(this.getScrollDistanceDown_(),
this.getScrollDistanceRight_());
}
@@ -114,26 +114,30 @@
// Assign this.element_ here instead of constructor, because the constructor
// ensures this method will be called after the document is loaded.
this.element_ = this.options_.element_;
+
+ // Calculate scroll point.
+ var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_);
+ this.startLeft = rect.left + rect.width * this.options_.leftStartRatio_;
+ this.startTop = rect.top + rect.height * this.options_.topStartRatio_;
+
+ if (rect.width === 0 || rect.height === 0) {
+ throw new Error('Scroll element has zero height and/or width.');
Sami 2016/11/24 14:47:35 "... or is outside the viewport"
+ }
+
requestAnimationFrame(this.startGesture_.bind(this));
};
ScrollAction.prototype.startGesture_ = function() {
this.beginMeasuringHook();
- var max_scroll_length_pixels = (MAX_SCROLL_LENGTH_TIME_MS / 1000) *
+ var maxScrollLengthPixels = (MAX_SCROLL_LENGTH_TIME_MS / 1000) *
this.options_.speed_;
- var distance = Math.min(max_scroll_length_pixels,
- this.getScrollDistance_());
+ var distance = Math.min(maxScrollLengthPixels, this.getScrollDistance_());
- var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_);
- var start_left =
- rect.left + rect.width * this.options_.left_start_ratio_;
- var start_top =
- rect.top + rect.height * this.options_.top_start_ratio_;
- chrome.gpuBenchmarking.smoothScrollBy(
- distance, this.onGestureComplete_.bind(this), start_left, start_top,
- this.options_.gesture_source_type_, this.options_.direction_,
- this.options_.speed_);
+ chrome.gpuBenchmarking.smoothScrollBy(
+ distance, this.onGestureComplete_.bind(this),
+ this.startLeft, this.startTop, this.options_.gesture_source_type_,
+ this.options_.direction_, this.options_.speed_);
};
ScrollAction.prototype.onGestureComplete_ = function() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698