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

Unified Diff: chrome/browser/resources/pdf/pdf.js

Issue 814573004: Fix for Multipage selection by dragging mouse in OOP case in PDF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing nit. Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pdf/out_of_process_instance.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/pdf/pdf.js
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
index 9123627f884ba66f0a30883269619f4c3e9d8b41..755025d9bda7b04f0c83add2c640575376dcf66f 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -58,6 +58,19 @@ function onNavigateInNewTab(url) {
PDFViewer.MIN_TOOLBAR_OFFSET = 15;
/**
+ * The timer interval for drag scroll when we have selection and mouse is
Sam McNally 2015/02/06 03:43:06 The period of time to wait between updating the vi
Deepak 2015/02/06 08:33:42 Done.
+ * dragged out of the viewport. The callback function will get called after
+ * this interval till timer get cleared.
+ */
+PDFViewer.DRAG_TIMER_INTERVAL = 100;
+
+/**
+ * The maximum scroll velocity when we have selection and drag mouse out of
Sam McNally 2015/02/06 03:43:07 The maximum drag scroll velocity.
Deepak 2015/02/06 08:33:43 Done.
+ * viewport.
+ */
+PDFViewer.MAX_SCROLL_VELOCITY = 100;
+
+/**
* Creates a new PDFViewer. There should only be one of these objects per
* document.
* @constructor
@@ -193,6 +206,9 @@ function PDFViewer(streamDetails) {
this.navigator_ = new Navigator(this.streamDetails_.originalUrl,
this.viewport_, this.paramsParser_, onNavigateInCurrentTab,
onNavigateInNewTab);
+ this.mousemoveCallback_ = null;
+ this.timerId_ = null;
+ this.scrollVelocity_ = null;
}
PDFViewer.prototype = {
@@ -519,7 +535,106 @@ PDFViewer.prototype = {
if (this.isMaterial_)
this.bookmarksPane.bookmarks = message.data.bookmarks;
break;
+ case 'setIsSelecting':
+ if (message.data.isSelecting && !this.mousemoveCallback_) {
+ this.mousemoveCallback_ = this.selectionDragListener_.bind(this);
Sam McNally 2015/02/06 03:43:07 I meant only do this once and then reuse the same
Deepak 2015/02/06 08:33:43 Done.
+ this.plugin_.addEventListener('mousemove',
Sam McNally 2015/02/06 03:43:07 Break after the (.
Deepak 2015/02/06 08:33:43 ok, I will run clang format for this.
+ this.mousemoveCallback_, false);
+ } else {
+ this.clearTimerInterval_();
+ if (this.mousemoveCallback_) {
+ this.plugin_.removeEventListener('mousemove',
Sam McNally 2015/02/06 03:43:07 Ditto.
Deepak 2015/02/06 08:33:43 Done.
+ this.mousemoveCallback_, false);
+ this.mousemoveCallback_ = null;
Sam McNally 2015/02/06 03:43:07 Delete.
Deepak 2015/02/06 08:33:43 Done.
+ }
+ }
+ break;
+ }
+ },
+
+ /**
+ * @private
+ * Start the timer to call dragScrollPage_ function at regular interval till
Sam McNally 2015/02/06 03:43:07 until the timer is stopped.
Deepak 2015/02/06 08:33:43 Done.
+ * timer get cleared.
+ */
+ setTimerInterval_: function() {
Sam McNally 2015/02/06 03:43:07 startDragScrollTimer_
Deepak 2015/02/06 08:33:43 Done.
+ this.timerId_ =
+ window.setInterval(this.dragScrollPage_.bind(this),
+ PDFViewer.DRAG_TIMER_INTERVAL);
+ },
+
+ /**
+ * @private
+ * Clear the timer if it is active and reset timerId_.
Sam McNally 2015/02/06 03:43:06 Stops the drag scroll timer if it is active.
Deepak 2015/02/06 08:33:43 Done.
+ */
+ clearTimerInterval_: function() {
Sam McNally 2015/02/06 03:43:07 stopDragScrollTimer_
Deepak 2015/02/06 08:33:43 Done.
+ if (this.timerId_ !== null) {
+ window.clearInterval(this.timerId_);
+ this.timerId_ = null;
+ }
+ },
+
+ /**
+ * @private
+ * Handles scrolling in the page when we drag mouse out of the viewport and
Sam McNally 2015/02/06 03:43:07 Scrolls the viewport by the current scroll velocit
Deepak 2015/02/06 08:33:43 Done.
+ * does not get mousemove event.
+ */
+ dragScrollPage_: function() {
+ var position = this.viewport_.position;
+ position.y += this.scrollVelocity_.y;
+ position.x += this.scrollVelocity_.x;
+ this.viewport_.position = position;
+ },
+
+ /**
+ * @private
+ * Calculate velocity of scroll in the x and y direction when we drag mouse
Sam McNally 2015/02/06 03:43:07 Calculate the velocity to scroll while dragging us
Deepak 2015/02/06 08:33:43 Done.
+ * out of the viewport and does not move mouse. The scroll velocity depends
+ * upon mouse pointer distance from the viewport.
+ * @return {Object} Object with x and y direction scroll velocity.
+ */
+ calculateVelocity_: function(event) {
+ var x = Math.min(Math.max(-event.offsetX, event.offsetX -
Sam McNally 2015/02/06 03:43:07 Please clang-format this.
Deepak 2015/02/06 08:33:43 Done.
+ this.plugin_.offsetWidth, 0), PDFViewer.MAX_SCROLL_VELOCITY) *
+ Math.sign(event.offsetX);
+ var y = Math.min(Math.max(-event.offsetY, event.offsetY -
+ this.plugin_.offsetHeight, 0), PDFViewer.MAX_SCROLL_VELOCITY) *
+ Math.sign(event.offsetY);
+ return {x: x, y: y};
+ },
+
+ /**
+ * @private
+ * Handles mousemove events. Scrolls page when mouse move happen reacting to
Sam McNally 2015/02/06 03:43:07 This doesn't do any scrolling itself. It just upda
Deepak 2015/02/06 08:33:43 Done.
+ * the direction of scroll. When mouse move event does not come then we are
+ * scrolling based on timer.
+ * @param {Object} event The mousemove event.
+ */
+ selectionDragListener_: function(event) {
+ var position = this.viewport_.position;
Sam McNally 2015/02/06 03:43:06 These bounds checks aren't necessary. Remove them.
Deepak 2015/02/06 08:33:42 Done.
+ var viewportRect = {
+ x1: position.x / this.viewport_.zoom,
+ y1: position.y / this.viewport_.zoom,
+ x2: (position.x + this.viewport_.size.width) / this.viewport_.zoom,
+ y2: (position.y + this.viewport_.size.height) / this.viewport_.zoom
+ };
+ var point = {
+ x: event.pageX / this.viewport_.zoom,
+ y: event.pageY / this.viewport_.zoom
+ };
+
+ if ((point.x >= viewportRect.x1 && point.x <= viewportRect.x2) &&
+ (point.y >= viewportRect.y1 && point.y <= viewportRect.y2)) {
+ this.clearTimerInterval_();
+ return;
+ }
+ this.scrollVelocity_ = this.calculateVelocity_(event);
+ if ((this.scrollVelocity_.x != 0 || this.scrollVelocity_.y != 0) &&
+ !this.timerId_) {
+ this.setTimerInterval_();
Sam McNally 2015/02/06 03:43:07 Please make setTimerInterval_ idempotent and simpl
Deepak 2015/02/06 08:33:43 Done.
}
+ if (!this.scrollVelocity_.x && !this.scrollVelocity_.y)
+ this.clearTimerInterval_();
},
raymes 2015/02/06 03:11:07 Can we move all this stuff into a new class in a s
Deepak 2015/02/06 08:33:43 ya, sure , I will definitely move this code in sep
/**
« no previous file with comments | « no previous file | pdf/out_of_process_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698