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

Side by Side Diff: telemetry/telemetry/internal/actions/scroll.js

Issue 2162963002: [polymer] Merge of master into polymer10-migration (Closed) Base URL: git@github.com:catapult-project/catapult.git@polymer10-migration
Patch Set: Merge polymer10-migration int polymer10-merge Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 the ScrollAction object, which scrolls a page 5 // This file provides the ScrollAction object, which scrolls a page
6 // to the bottom or for a specified distance: 6 // to the bottom or for a specified distance:
7 // 1. var action = new __ScrollAction(callback, opt_distance_func) 7 // 1. var action = new __ScrollAction(callback, opt_distance_func)
8 // 2. action.start(scroll_options) 8 // 2. action.start(scroll_options)
9 'use strict'; 9 'use strict';
10 10
(...skipping 14 matching lines...) Expand all
25 this.top_start_ratio_ = 0.5; 25 this.top_start_ratio_ = 0.5;
26 this.direction_ = 'down'; 26 this.direction_ = 'down';
27 this.speed_ = 800; 27 this.speed_ = 800;
28 this.gesture_source_type_ = chrome.gpuBenchmarking.DEFAULT_INPUT; 28 this.gesture_source_type_ = chrome.gpuBenchmarking.DEFAULT_INPUT;
29 } 29 }
30 } 30 }
31 31
32 function supportedByBrowser() { 32 function supportedByBrowser() {
33 return !!(window.chrome && 33 return !!(window.chrome &&
34 chrome.gpuBenchmarking && 34 chrome.gpuBenchmarking &&
35 chrome.gpuBenchmarking.smoothScrollBy); 35 chrome.gpuBenchmarking.smoothScrollBy &&
36 chrome.gpuBenchmarking.visualViewportHeight &&
37 chrome.gpuBenchmarking.visualViewportWidth);
36 } 38 }
37 39
38 // This class scrolls a page from the top to the bottom once. 40 // This class scrolls a page from the top to the bottom once.
39 // 41 //
40 // The page is scrolled down by a single scroll gesture. 42 // The page is scrolled down by a single scroll gesture.
41 function ScrollAction(opt_callback, opt_distance_func) { 43 function ScrollAction(opt_callback, opt_distance_func) {
42 var self = this; 44 var self = this;
43 45
44 this.beginMeasuringHook = function() {}; 46 this.beginMeasuringHook = function() {};
45 this.endMeasuringHook = function() {}; 47 this.endMeasuringHook = function() {};
46 48
47 this.callback_ = opt_callback; 49 this.callback_ = opt_callback;
48 this.distance_func_ = opt_distance_func; 50 this.distance_func_ = opt_distance_func;
49 } 51 }
50 52
51 ScrollAction.prototype.getScrollDistanceDown_ = function() { 53 ScrollAction.prototype.getScrollDistanceDown_ = function() {
52 var clientHeight; 54 var clientHeight;
53 // clientHeight is "special" for the body element. 55 // clientHeight is "special" for the body element.
54 if (this.element_ == document.body) 56 if (this.element_ == document.body)
55 clientHeight = window.innerHeight; 57 clientHeight = __GestureCommon_GetWindowHeight();
56 else 58 else
57 clientHeight = this.element_.clientHeight; 59 clientHeight = this.element_.clientHeight;
58 60
59 return this.element_.scrollHeight - 61 return this.element_.scrollHeight -
60 this.element_.scrollTop - 62 this.element_.scrollTop -
61 clientHeight; 63 clientHeight;
62 }; 64 };
63 65
64 ScrollAction.prototype.getScrollDistanceUp_ = function() { 66 ScrollAction.prototype.getScrollDistanceUp_ = function() {
65 return this.element_.scrollTop; 67 return this.element_.scrollTop;
66 }; 68 };
67 69
68 ScrollAction.prototype.getScrollDistanceRight_ = function() { 70 ScrollAction.prototype.getScrollDistanceRight_ = function() {
69 var clientWidth; 71 var clientWidth;
70 // clientWidth is "special" for the body element. 72 // clientWidth is "special" for the body element.
71 if (this.element_ == document.body) 73 if (this.element_ == document.body)
72 clientWidth = window.innerWidth; 74 clientWidth = __GestureCommon_GetWindowWidth();
73 else 75 else
74 clientWidth = this.element_.clientWidth; 76 clientWidth = this.element_.clientWidth;
75 77
76 return this.element_.scrollWidth - this.element_.scrollLeft - clientWidth; 78 return this.element_.scrollWidth - this.element_.scrollLeft - clientWidth;
77 }; 79 };
78 80
79 ScrollAction.prototype.getScrollDistanceLeft_ = function() { 81 ScrollAction.prototype.getScrollDistanceLeft_ = function() {
80 return this.element_.scrollLeft; 82 return this.element_.scrollLeft;
81 }; 83 };
82 84
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 119
118 ScrollAction.prototype.startGesture_ = function() { 120 ScrollAction.prototype.startGesture_ = function() {
119 this.beginMeasuringHook(); 121 this.beginMeasuringHook();
120 122
121 var max_scroll_length_pixels = (MAX_SCROLL_LENGTH_TIME_MS / 1000) * 123 var max_scroll_length_pixels = (MAX_SCROLL_LENGTH_TIME_MS / 1000) *
122 this.options_.speed_; 124 this.options_.speed_;
123 var distance = Math.min(max_scroll_length_pixels, 125 var distance = Math.min(max_scroll_length_pixels,
124 this.getScrollDistance_()); 126 this.getScrollDistance_());
125 127
126 var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_); 128 var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_);
127 // TODO(bccheng): workaround crbug/599656
128 // Use device-independent pixel value for the x and y positions
129 var start_left = 129 var start_left =
130 rect.left + (rect.width / window.devicePixelRatio) * 130 rect.left + rect.width * this.options_.left_start_ratio_;
131 this.options_.left_start_ratio_;
132 var start_top = 131 var start_top =
133 rect.top + (rect.height / window.devicePixelRatio) * 132 rect.top + rect.height * this.options_.top_start_ratio_;
134 this.options_.top_start_ratio_;
135 chrome.gpuBenchmarking.smoothScrollBy( 133 chrome.gpuBenchmarking.smoothScrollBy(
136 distance, this.onGestureComplete_.bind(this), start_left, start_top, 134 distance, this.onGestureComplete_.bind(this), start_left, start_top,
137 this.options_.gesture_source_type_, this.options_.direction_, 135 this.options_.gesture_source_type_, this.options_.direction_,
138 this.options_.speed_); 136 this.options_.speed_);
139 }; 137 };
140 138
141 ScrollAction.prototype.onGestureComplete_ = function() { 139 ScrollAction.prototype.onGestureComplete_ = function() {
142 this.endMeasuringHook(); 140 this.endMeasuringHook();
143 141
144 // We're done. 142 // We're done.
145 if (this.callback_) 143 if (this.callback_)
146 this.callback_(); 144 this.callback_();
147 }; 145 };
148 146
149 window.__ScrollAction = ScrollAction; 147 window.__ScrollAction = ScrollAction;
150 window.__ScrollAction_SupportedByBrowser = supportedByBrowser; 148 window.__ScrollAction_SupportedByBrowser = supportedByBrowser;
151 })(); 149 })();
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/actions/repeatable_scroll_unittest.py ('k') | telemetry/telemetry/internal/actions/scroll.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698