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

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: Changes for scrolling based on Timer when no mouse move event comes. Created 5 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 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 fb4d3ee53a3d7d19b7c918089fcc09b3de7097a1..ea49e24f09a761203e665d860a3f7998c8baa80d 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -157,6 +157,10 @@ function PDFViewer(streamDetails) {
this.paramsParser_ = new OpenPDFParamsParser();
this.navigator_ = new Navigator(this.streamDetails_.originalUrl,
this.viewport_, this.paramsParser_);
+ this.isSelecting_ = false;
+ this.mousemoveCallback_ = null;
+ this.timerId_ = null;
+ this.dragDirection_;
}
PDFViewer.prototype = {
@@ -450,6 +454,105 @@ PDFViewer.prototype = {
case 'bookmarks':
this.bookmarks_ = message.data.bookmarks;
break;
+ case 'setIsSelecting':
+ this.isSelecting_ = message.data.isSelecting;
Sam McNally 2015/02/04 02:56:01 this.isSelecting_ isn't used anywhere else. Remove
Deepak 2015/02/04 13:50:54 Done.
+ if (this.isSelecting_) {
+ this.mousemoveCallback_ = this.selectionDragListener_.bind(this);
Sam McNally 2015/02/04 02:56:01 2 space indent. Also, only set mousemoveCallback_
Deepak 2015/02/04 13:50:54 Done.
+ this.plugin_.addEventListener('mousemove',
+ this.mousemoveCallback_, false);
+ } else {
+ this.plugin_.removeEventListener('mousemove',
Sam McNally 2015/02/04 02:56:02 Ditto.
Deepak 2015/02/04 13:50:54 Done.
+ this.mousemoveCallback_, false);
+ this.clearTimer_();
+ }
+ break;
+ }
+ },
+
+ /**
+ * @private
+ * Clear the timer if it is active and reset timerId.
+ */
+ clearTimer_: function() {
+ if (this.timerId_) {
+ window.clearTimeout(this.timerId_);
Sam McNally 2015/02/04 02:56:01 Use clearInterval here.
Deepak 2015/02/04 13:50:54 Done.
+ this.timerId_ = null;
+ }
+ },
+
+ /**
+ * @private
+ * Handles scrolling in the page when we drag mouse out of the viewport and
+ * does not move mouse, Then no mouse move event came so we are scrolling
+ * based on timer in drag direction.
+ */
+ dragScrollPage_: function() {
+ this.clearTimer_();
+ var position = this.viewport_.position;
+ switch (this.dragDirection_) {
+ case 'up':
+ position.y -= ((Viewport.SCROLL_INCREMENT) / this.viewport_.zoom);
+ break;
+ case 'down':
+ position.y += ((Viewport.SCROLL_INCREMENT) / this.viewport_.zoom);
+ break;
+ case 'left':
+ position.x -= ((Viewport.SCROLL_INCREMENT) / this.viewport_.zoom);
+ break;
+ case 'right':
+ position.x += ((Viewport.SCROLL_INCREMENT) / this.viewport_.zoom);
+ break;
+ }
+ this.viewport_.position = position;
+ this.timerId_ = window.setTimeout(this.dragScrollPage_.bind(this), 50);
Sam McNally 2015/02/04 02:56:01 Remove.
Deepak 2015/02/04 13:50:54 Done.
+ },
+
+ /**
+ * @private
+ * Handles mousemove events. Scrolls page when mouse move happen reacting to
+ * the direction of scroll.
+ * @param {Object} event The mouse move event.
+ */
+ selectionDragListener_: function(event) {
+ var position = this.viewport_.position;
+ 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.clearTimer_();
+ return;
+ }
+
+ if (this.viewport_.documentHasScrollbars().vertical) {
Sam McNally 2015/02/04 02:56:01 This won't work for diagonal scrolls. Instead, cal
Deepak 2015/02/04 13:50:54 Done.
+ if (point.y < viewportRect.y1 && viewportRect.y1 > 0) {
+ this.dragDirection_ = 'up';
+ this.dragScrollPage_();
Sam McNally 2015/02/04 02:56:01 Instead of calling dragScrollPage_ here, after cal
Deepak 2015/02/04 13:50:54 Done.
+ } else if ((point.y > viewportRect.y2) &&
+ (event.pageY < (this.viewport_.documentDimensions_.height *
+ this.viewport_.zoom))) {
+ this.dragDirection_ = 'down';
+ this.dragScrollPage_();
+ }
+ }
+ if (this.viewport_.documentHasScrollbars().horizontal) {
+ if (point.x < viewportRect.x1 && viewportRect.x1 > 0) {
+ this.dragDirection_ = 'left';
+ this.dragScrollPage_();
+ } else if ((point.x > viewportRect.x2) &&
+ (event.pageX < this.viewport_.documentDimensions_.width *
+ this.viewport_.zoom)) {
+ this.dragDirection_ = 'right';
+ this.dragScrollPage_();
+ }
}
},
« 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