summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/pdf/viewport_scroller.js
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/resources/pdf/viewport_scroller.js')
-rw-r--r--chromium/chrome/browser/resources/pdf/viewport_scroller.js83
1 files changed, 42 insertions, 41 deletions
diff --git a/chromium/chrome/browser/resources/pdf/viewport_scroller.js b/chromium/chrome/browser/resources/pdf/viewport_scroller.js
index bb8c187d478..ca16c9cf7d2 100644
--- a/chromium/chrome/browser/resources/pdf/viewport_scroller.js
+++ b/chromium/chrome/browser/resources/pdf/viewport_scroller.js
@@ -5,75 +5,61 @@
'use strict';
/**
- * The period of time in milliseconds to wait between updating the viewport
- * position by the scroll velocity.
- *
- * @private
- */
-ViewportScroller.DRAG_TIMER_INTERVAL_MS_ = 100;
-
-/**
- * The maximum drag scroll distance per DRAG_TIMER_INTERVAL in pixels.
- *
- * @private
- */
-ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_ = 100;
-
-/**
* Creates a new ViewportScroller.
* A ViewportScroller scrolls the page in response to drag selection with the
* mouse.
*
- * @param {Object} viewport The viewport info of the page.
- * @param {Object} plugin The PDF plugin element.
- * @param {Object} window The window containing the viewer.
- * @constructor
*/
-function ViewportScroller(viewport, plugin, window) {
- this.viewport_ = viewport;
- this.plugin_ = plugin;
- this.window_ = window;
- this.mousemoveCallback_ = null;
- this.timerId_ = null;
- this.scrollVelocity_ = null;
- this.lastFrameTime_ = 0;
-}
+class ViewportScroller {
+ /**
+ * @param {Object} viewport The viewport info of the page.
+ * @param {Object} plugin The PDF plugin element.
+ * @param {Object} window The window containing the viewer.
+ */
+ constructor(viewport, plugin, window) {
+ this.viewport_ = viewport;
+ this.plugin_ = plugin;
+ this.window_ = window;
+ this.mousemoveCallback_ = null;
+ this.timerId_ = null;
+ this.scrollVelocity_ = null;
+ this.lastFrameTime_ = 0;
+ }
-ViewportScroller.prototype = {
/**
* Start scrolling the page by |scrollVelocity_| every
* |DRAG_TIMER_INTERVAL_MS_|.
*
* @private
*/
- startDragScrollTimer_: function() {
+ startDragScrollTimer_() {
if (this.timerId_ === null) {
this.timerId_ = this.window_.setInterval(
this.dragScrollPage_.bind(this),
ViewportScroller.DRAG_TIMER_INTERVAL_MS_);
this.lastFrameTime_ = Date.now();
}
- },
+ }
/**
* Stops the drag scroll timer if it is active.
*
* @private
*/
- stopDragScrollTimer_: function() {
+ stopDragScrollTimer_() {
if (this.timerId_ !== null) {
this.window_.clearInterval(this.timerId_);
this.timerId_ = null;
this.lastFrameTime_ = 0;
}
- },
+ }
/**
* Scrolls the viewport by the current scroll velocity.
*
* @private
*/
- dragScrollPage_: function() {
+ dragScrollPage_() {
const position = this.viewport_.position;
const currentFrameTime = Date.now();
const timeAdjustment = (currentFrameTime - this.lastFrameTime_) /
@@ -82,7 +68,7 @@ ViewportScroller.prototype = {
position.x += (this.scrollVelocity_.x * timeAdjustment);
this.viewport_.position = position;
this.lastFrameTime_ = currentFrameTime;
- },
+ }
/**
* Calculate the velocity to scroll while dragging using the distance of the
@@ -92,7 +78,7 @@ ViewportScroller.prototype = {
* @return {Object} Object with x and y direction scroll velocity.
* @private
*/
- calculateVelocity_: function(event) {
+ calculateVelocity_(event) {
const x =
Math.min(
Math.max(
@@ -106,7 +92,7 @@ ViewportScroller.prototype = {
ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_) *
Math.sign(event.offsetY);
return {x: x, y: y};
- },
+ }
/**
* Handles mousemove events. It updates the scroll velocity and starts and
@@ -115,14 +101,14 @@ ViewportScroller.prototype = {
* @param {Object} event The mousemove event.
* @private
*/
- onMousemove_: function(event) {
+ onMousemove_(event) {
this.scrollVelocity_ = this.calculateVelocity_(event);
if (!this.scrollVelocity_.x && !this.scrollVelocity_.y) {
this.stopDragScrollTimer_();
} else if (!this.timerId_) {
this.startDragScrollTimer_();
}
- },
+ }
/**
* Sets whether to scroll the viewport when the mouse is outside the
@@ -130,7 +116,7 @@ ViewportScroller.prototype = {
*
* @param {boolean} isSelecting Represents selection status.
*/
- setEnableScrolling: function(isSelecting) {
+ setEnableScrolling(isSelecting) {
if (isSelecting) {
if (!this.mousemoveCallback_) {
this.mousemoveCallback_ = this.onMousemove_.bind(this);
@@ -145,4 +131,19 @@ ViewportScroller.prototype = {
}
}
}
-};
+}
+
+/**
+ * The period of time in milliseconds to wait between updating the viewport
+ * position by the scroll velocity.
+ *
+ * @private
+ */
+ViewportScroller.DRAG_TIMER_INTERVAL_MS_ = 100;
+
+/**
+ * The maximum drag scroll distance per DRAG_TIMER_INTERVAL in pixels.
+ *
+ * @private
+ */
+ViewportScroller.MAX_DRAG_SCROLL_DISTANCE_ = 100;