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

Side by Side Diff: chrome/browser/resources/pdf/viewport_scroller.js

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/pdf/viewport.js ('k') | chrome/browser/resources/pdf/zoom_manager.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @private 8 * @private
9 * The period of time in milliseconds to wait between updating the viewport 9 * The period of time in milliseconds to wait between updating the viewport
10 * position by the scroll velocity. 10 * position by the scroll velocity.
(...skipping 25 matching lines...) Expand all
36 } 36 }
37 37
38 ViewportScroller.prototype = { 38 ViewportScroller.prototype = {
39 /** 39 /**
40 * @private 40 * @private
41 * Start scrolling the page by |scrollVelocity_| every 41 * Start scrolling the page by |scrollVelocity_| every
42 * |DRAG_TIMER_INTERVAL_MS_|. 42 * |DRAG_TIMER_INTERVAL_MS_|.
43 */ 43 */
44 startDragScrollTimer_: function() { 44 startDragScrollTimer_: function() {
45 if (this.timerId_ === null) { 45 if (this.timerId_ === null) {
46 this.timerId_ = 46 this.timerId_ = this.window_.setInterval(
47 this.window_.setInterval(this.dragScrollPage_.bind(this), 47 this.dragScrollPage_.bind(this),
48 ViewportScroller.DRAG_TIMER_INTERVAL_MS_); 48 ViewportScroller.DRAG_TIMER_INTERVAL_MS_);
49 this.lastFrameTime_ = Date.now(); 49 this.lastFrameTime_ = Date.now();
50 } 50 }
51 }, 51 },
52 52
53 /** 53 /**
54 * @private 54 * @private
55 * Stops the drag scroll timer if it is active. 55 * Stops the drag scroll timer if it is active.
56 */ 56 */
57 stopDragScrollTimer_: function() { 57 stopDragScrollTimer_: function() {
58 if (this.timerId_ !== null) { 58 if (this.timerId_ !== null) {
59 this.window_.clearInterval(this.timerId_); 59 this.window_.clearInterval(this.timerId_);
60 this.timerId_ = null; 60 this.timerId_ = null;
61 this.lastFrameTime_ = 0; 61 this.lastFrameTime_ = 0;
62 } 62 }
63 }, 63 },
64 64
65 /** 65 /**
66 * @private 66 * @private
67 * Scrolls the viewport by the current scroll velocity. 67 * Scrolls the viewport by the current scroll velocity.
68 */ 68 */
69 dragScrollPage_: function() { 69 dragScrollPage_: function() {
70 var position = this.viewport_.position; 70 var position = this.viewport_.position;
71 var currentFrameTime = Date.now(); 71 var currentFrameTime = Date.now();
72 var timeAdjustment = (currentFrameTime - this.lastFrameTime_) / 72 var timeAdjustment = (currentFrameTime - this.lastFrameTime_) /
73 ViewportScroller.DRAG_TIMER_INTERVAL_MS_; 73 ViewportScroller.DRAG_TIMER_INTERVAL_MS_;
74 position.y += (this.scrollVelocity_.y * timeAdjustment); 74 position.y += (this.scrollVelocity_.y * timeAdjustment);
75 position.x += (this.scrollVelocity_.x * timeAdjustment); 75 position.x += (this.scrollVelocity_.x * timeAdjustment);
76 this.viewport_.position = position; 76 this.viewport_.position = position;
77 this.lastFrameTime_ = currentFrameTime; 77 this.lastFrameTime_ = currentFrameTime;
78 }, 78 },
79 79
80 /** 80 /**
81 * @private 81 * @private
82 * Calculate the velocity to scroll while dragging using the distance of the 82 * Calculate the velocity to scroll while dragging using the distance of the
83 * cursor outside the viewport. 83 * cursor outside the viewport.
84 * @param {Object} event The mousemove event. 84 * @param {Object} event The mousemove event.
85 * @return {Object} Object with x and y direction scroll velocity. 85 * @return {Object} Object with x and y direction scroll velocity.
86 */ 86 */
87 calculateVelocity_: function(event) { 87 calculateVelocity_: function(event) {
88 var x = Math.min(Math.max(-event.offsetX, 88 var x =
89 event.offsetX - this.plugin_.offsetWidth, 0), 89 Math.min(
90 ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) * 90 Math.max(
91 Math.sign(event.offsetX); 91 -event.offsetX, event.offsetX - this.plugin_.offsetWidth, 0),
92 var y = Math.min(Math.max(-event.offsetY, 92 ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) *
93 event.offsetY - this.plugin_.offsetHeight, 0), 93 Math.sign(event.offsetX);
94 ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) * 94 var y =
95 Math.sign(event.offsetY); 95 Math.min(
96 return { 96 Math.max(
97 x: x, 97 -event.offsetY, event.offsetY - this.plugin_.offsetHeight, 0),
98 y: y 98 ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) *
99 }; 99 Math.sign(event.offsetY);
100 return {x: x, y: y};
100 }, 101 },
101 102
102 /** 103 /**
103 * @private 104 * @private
104 * Handles mousemove events. It updates the scroll velocity and starts and 105 * Handles mousemove events. It updates the scroll velocity and starts and
105 * stops timer based on scroll velocity. 106 * stops timer based on scroll velocity.
106 * @param {Object} event The mousemove event. 107 * @param {Object} event The mousemove event.
107 */ 108 */
108 onMousemove_: function(event) { 109 onMousemove_: function(event) {
109 this.scrollVelocity_ = this.calculateVelocity_(event); 110 this.scrollVelocity_ = this.calculateVelocity_(event);
110 if (!this.scrollVelocity_.x && !this.scrollVelocity_.y) 111 if (!this.scrollVelocity_.x && !this.scrollVelocity_.y)
111 this.stopDragScrollTimer_(); 112 this.stopDragScrollTimer_();
112 else if (!this.timerId_) 113 else if (!this.timerId_)
113 this.startDragScrollTimer_(); 114 this.startDragScrollTimer_();
114 }, 115 },
115 116
116 /** 117 /**
117 * Sets whether to scroll the viewport when the mouse is outside the 118 * Sets whether to scroll the viewport when the mouse is outside the
118 * viewport. 119 * viewport.
119 * @param {boolean} isSelecting Represents selection status. 120 * @param {boolean} isSelecting Represents selection status.
120 */ 121 */
121 setEnableScrolling: function(isSelecting) { 122 setEnableScrolling: function(isSelecting) {
122 if (isSelecting) { 123 if (isSelecting) {
123 if (!this.mousemoveCallback_) 124 if (!this.mousemoveCallback_)
124 this.mousemoveCallback_ = this.onMousemove_.bind(this); 125 this.mousemoveCallback_ = this.onMousemove_.bind(this);
125 this.plugin_.addEventListener('mousemove', this.mousemoveCallback_, 126 this.plugin_.addEventListener(
126 false); 127 'mousemove', this.mousemoveCallback_, false);
127 } else { 128 } else {
128 this.stopDragScrollTimer_(); 129 this.stopDragScrollTimer_();
129 if (this.mousemoveCallback_) { 130 if (this.mousemoveCallback_) {
130 this.plugin_.removeEventListener('mousemove', this.mousemoveCallback_, 131 this.plugin_.removeEventListener(
131 false); 132 'mousemove', this.mousemoveCallback_, false);
132 } 133 }
133 } 134 }
134 } 135 }
135 }; 136 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/viewport.js ('k') | chrome/browser/resources/pdf/zoom_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698