Chromium Code Reviews| Index: chrome/browser/resources/pdf/pdf.js |
| diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js |
| index 007d3dca37ad967d7be2be9803a3b4eb05813e6f..410b58a79644e05bfc84eafc5a8b6856f344aa9f 100644 |
| --- a/chrome/browser/resources/pdf/pdf.js |
| +++ b/chrome/browser/resources/pdf/pdf.js |
| @@ -153,6 +153,9 @@ function PDFViewer(streamDetails) { |
| this.paramsParser_ = new OpenPDFParamsParser(); |
| this.navigator_ = new Navigator(this.streamDetails_.originalUrl, |
| this.viewport_, this.paramsParser_); |
| + this.isSelecting_ = false; |
| + this.mousemoveCallback_ = null; |
| + |
| } |
| PDFViewer.prototype = { |
| @@ -435,7 +438,80 @@ PDFViewer.prototype = { |
| case 'bookmarks': |
| this.bookmarks_ = message.data.bookmarks; |
| break; |
| + case 'setIsSelecting': { |
|
Sam McNally
2015/01/28 02:43:51
Match the other cases: no {}.
Deepak
2015/01/28 11:59:26
Done.
|
| + if (message.data.isSelecting == this.isSelecting_) |
|
raymes
2015/01/28 03:33:08
Does this ever happen?
Deepak
2015/01/28 11:59:26
This is not needed as we are sending message when
|
| + break; |
|
Sam McNally
2015/01/28 02:43:51
2 space indent.
Deepak
2015/01/28 11:59:26
Done.
|
| + this.isSelecting_ = message.data.isSelecting; |
| + if (this.isSelecting_) { |
| + this.mousemoveCallback_ = this.selectionDragListener_.bind(this); |
| + this.plugin_.addEventListener('mousemove', |
| + this.mousemoveCallback_, false); |
|
Sam McNally
2015/01/28 02:43:51
Line up with the opening ( or break before 'mousem
Deepak
2015/01/28 11:59:26
If I bring this.mousemoveCallback_ to start of '('
Sam McNally
2015/02/04 02:56:01
See code formatting > function arguments.
|
| + } else { |
| + this.plugin_.removeEventListener('mousemove', |
| + this.mousemoveCallback_, false); |
| + } |
| + } |
| + break; |
| + } |
| + }, |
| + |
| + /** |
| + * @private |
| + * Helper function that check weather point is in inside rect or not. |
| + * @param {Object} point The point that need to be checked. |
| + * @param {Object} rect The rect with top left point and bottom right point. |
| + * @return {boolean} returns true if point is inside rect else returns false. |
| + */ |
| + isPointInsideRect_: function(point, rect) { |
|
Sam McNally
2015/01/28 02:43:51
This doesn't need to be a method.
Deepak
2015/01/28 11:59:26
Done.
|
| + var x1 = Math.min(rect.x1, rect.x2); |
|
Sam McNally
2015/01/28 02:43:51
Why are these here?
Deepak
2015/01/28 11:59:26
Done.
|
| + var x2 = Math.max(rect.x1, rect.x2); |
| + var y1 = Math.min(rect.y1, rect.y2); |
| + var y2 = Math.max(rect.y1, rect.y2); |
| + return ((x1 <= point.x && point.x <= x2) && |
| + (y1 <= point.y && point.y <= y2)); |
| + }, |
| + |
| + /** |
| + * @private |
| + * Handles mousemove events. Scrolls page when mouse move happen reacting to |
| + * the direction 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, |
|
Sam McNally
2015/01/28 02:43:51
Check whether screenX or screenY is between 0 and
Deepak
2015/01/28 11:59:26
Done.
|
| + y: event.pageY / this.viewport_.zoom |
| + }; |
| + var isPointInside = this.isPointInsideRect_(point, viewportRect); |
| + if (isPointInside) |
| + return; |
| + |
| + if (this.viewport_.documentHasScrollbars().vertical) { |
| + if (point.y < viewportRect.y1 && viewportRect.y1 > 0) { |
| + position.y -= (Viewport.SCROLL_INCREMENT / this.viewport_.zoom); |
|
Sam McNally
2015/01/28 02:43:51
This will only scroll when the mouse moves, and al
Deepak
2015/01/28 11:59:26
yes, Currently it is scrolling when their is mouse
|
| + } else if ((point.y > viewportRect.y2) && |
| + (event.pageY < (this.viewport_.documentDimensions_.height * |
| + this.viewport_.zoom))) { |
| + position.y += (Viewport.SCROLL_INCREMENT / this.viewport_.zoom); |
| + } |
| + } |
| + if (this.viewport_.documentHasScrollbars().horizontal) { |
| + if (point.x < viewportRect.x1 && viewportRect.x1 > 0) { |
| + position.x -= (Viewport.SCROLL_INCREMENT / this.viewport_.zoom); |
| + } else if ((point.x > viewportRect.x2) && |
| + (event.pageX < this.viewport_.documentDimensions_.width * |
| + this.viewport_.zoom)) { |
| + position.x += (Viewport.SCROLL_INCREMENT / this.viewport_.zoom); |
| + } |
| } |
| + this.viewport_.position = position; |
| }, |
| /** |