OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 // from top to bottom: | 6 // from top to bottom: |
7 // 1. var action = new __ScrollAction(callback) | 7 // 1. var action = new __ScrollAction(callback) |
8 // 2. action.start(element_to_scroll) | 8 // 2. action.start(element_to_scroll) |
9 'use strict'; | 9 'use strict'; |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 return rect; | 67 return rect; |
68 }; | 68 }; |
69 | 69 |
70 SmoothScrollDownGesture.prototype.start = function(distance, callback) { | 70 SmoothScrollDownGesture.prototype.start = function(distance, callback) { |
71 this.callback_ = callback; | 71 this.callback_ = callback; |
72 if (window.chrome && | 72 if (window.chrome && |
73 chrome.gpuBenchmarking && | 73 chrome.gpuBenchmarking && |
74 chrome.gpuBenchmarking.smoothScrollBy) { | 74 chrome.gpuBenchmarking.smoothScrollBy) { |
75 var rect = getBoundingVisibleRect(this.element_); | 75 var rect = getBoundingVisibleRect(this.element_); |
76 chrome.gpuBenchmarking.smoothScrollBy(distance, function() { | 76 var scrolled = chrome.gpuBenchmarking.smoothScrollBy( |
77 callback(); | 77 distance, function() { |
78 }, rect.left + rect.width / 2, rect.top + rect.height / 2); | 78 callback(); |
| 79 }, |
| 80 rect.left + rect.width / 2, rect.top + rect.height / 2); |
| 81 if (!scrolled) |
| 82 console.log('Unable to start smooth scrolling'); |
79 return; | 83 return; |
80 } | 84 } |
81 | 85 |
82 var SCROLL_DELTA = 100; | 86 var SCROLL_DELTA = 100; |
83 this.element_.scrollTop += SCROLL_DELTA; | 87 this.element_.scrollTop += SCROLL_DELTA; |
84 requestAnimationFrame(callback); | 88 requestAnimationFrame(callback); |
85 }; | 89 }; |
86 | 90 |
87 // This class scrolls a page from the top to the bottom once. | 91 // This class scrolls a page from the top to the bottom once. |
88 // | 92 // |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 this.endMeasuringHook(); | 156 this.endMeasuringHook(); |
153 | 157 |
154 // We're done. | 158 // We're done. |
155 if (this.callback_) | 159 if (this.callback_) |
156 this.callback_(); | 160 this.callback_(); |
157 }; | 161 }; |
158 | 162 |
159 window.__ScrollAction = ScrollAction; | 163 window.__ScrollAction = ScrollAction; |
160 window.__ScrollAction_GetBoundingVisibleRect = getBoundingVisibleRect; | 164 window.__ScrollAction_GetBoundingVisibleRect = getBoundingVisibleRect; |
161 })(); | 165 })(); |
OLD | NEW |