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

Side by Side 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, 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 | « no previous file | pdf/out_of_process_instance.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 * @return {number} Width of a scrollbar in pixels 8 * @return {number} Width of a scrollbar in pixels
9 */ 9 */
10 function getScrollbarWidth() { 10 function getScrollbarWidth() {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // when we initiate the zoom. 146 // when we initiate the zoom.
147 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) 147 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
148 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); 148 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
149 }.bind(this)); 149 }.bind(this));
150 } 150 }
151 151
152 // Parse open pdf parameters. 152 // Parse open pdf parameters.
153 this.paramsParser_ = new OpenPDFParamsParser(); 153 this.paramsParser_ = new OpenPDFParamsParser();
154 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, 154 this.navigator_ = new Navigator(this.streamDetails_.originalUrl,
155 this.viewport_, this.paramsParser_); 155 this.viewport_, this.paramsParser_);
156 this.isSelecting_ = false;
157 this.mousemoveCallback_ = null;
158
156 } 159 }
157 160
158 PDFViewer.prototype = { 161 PDFViewer.prototype = {
159 /** 162 /**
160 * @private 163 * @private
161 * Handle key events. These may come from the user directly or via the 164 * Handle key events. These may come from the user directly or via the
162 * scripting API. 165 * scripting API.
163 * @param {KeyboardEvent} e the event to handle. 166 * @param {KeyboardEvent} e the event to handle.
164 */ 167 */
165 handleKeyEvent_: function(e) { 168 handleKeyEvent_: function(e) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 if (!this.isPrintPreview_) 431 if (!this.isPrintPreview_)
429 this.progressBar_.style.visibility = 'visible'; 432 this.progressBar_.style.visibility = 'visible';
430 this.errorScreen_.text = message.data.loadFailedString; 433 this.errorScreen_.text = message.data.loadFailedString;
431 break; 434 break;
432 case 'cancelStreamUrl': 435 case 'cancelStreamUrl':
433 chrome.mimeHandlerPrivate.abortStream(); 436 chrome.mimeHandlerPrivate.abortStream();
434 break; 437 break;
435 case 'bookmarks': 438 case 'bookmarks':
436 this.bookmarks_ = message.data.bookmarks; 439 this.bookmarks_ = message.data.bookmarks;
437 break; 440 break;
441 case 'setIsSelecting': {
Sam McNally 2015/01/28 02:43:51 Match the other cases: no {}.
Deepak 2015/01/28 11:59:26 Done.
442 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
443 break;
Sam McNally 2015/01/28 02:43:51 2 space indent.
Deepak 2015/01/28 11:59:26 Done.
444 this.isSelecting_ = message.data.isSelecting;
445 if (this.isSelecting_) {
446 this.mousemoveCallback_ = this.selectionDragListener_.bind(this);
447 this.plugin_.addEventListener('mousemove',
448 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.
449 } else {
450 this.plugin_.removeEventListener('mousemove',
451 this.mousemoveCallback_, false);
452 }
453 }
454 break;
438 } 455 }
439 }, 456 },
440 457
441 /** 458 /**
459 * @private
460 * Helper function that check weather point is in inside rect or not.
461 * @param {Object} point The point that need to be checked.
462 * @param {Object} rect The rect with top left point and bottom right point.
463 * @return {boolean} returns true if point is inside rect else returns false.
464 */
465 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.
466 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.
467 var x2 = Math.max(rect.x1, rect.x2);
468 var y1 = Math.min(rect.y1, rect.y2);
469 var y2 = Math.max(rect.y1, rect.y2);
470 return ((x1 <= point.x && point.x <= x2) &&
471 (y1 <= point.y && point.y <= y2));
472 },
473
474 /**
475 * @private
476 * Handles mousemove events. Scrolls page when mouse move happen reacting to
477 * the direction scroll.
478 * @param {Object} event The mouse move event.
479 */
480 selectionDragListener_: function(event) {
481 var position = this.viewport_.position;
482 var viewportRect = {
483 x1: position.x / this.viewport_.zoom,
484 y1: position.y / this.viewport_.zoom,
485 x2: (position.x + this.viewport_.size.width) / this.viewport_.zoom,
486 y2: (position.y + this.viewport_.size.height) / this.viewport_.zoom
487 };
488 var point = {
489 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.
490 y: event.pageY / this.viewport_.zoom
491 };
492 var isPointInside = this.isPointInsideRect_(point, viewportRect);
493 if (isPointInside)
494 return;
495
496 if (this.viewport_.documentHasScrollbars().vertical) {
497 if (point.y < viewportRect.y1 && viewportRect.y1 > 0) {
498 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
499 } else if ((point.y > viewportRect.y2) &&
500 (event.pageY < (this.viewport_.documentDimensions_.height *
501 this.viewport_.zoom))) {
502 position.y += (Viewport.SCROLL_INCREMENT / this.viewport_.zoom);
503 }
504 }
505 if (this.viewport_.documentHasScrollbars().horizontal) {
506 if (point.x < viewportRect.x1 && viewportRect.x1 > 0) {
507 position.x -= (Viewport.SCROLL_INCREMENT / this.viewport_.zoom);
508 } else if ((point.x > viewportRect.x2) &&
509 (event.pageX < this.viewport_.documentDimensions_.width *
510 this.viewport_.zoom)) {
511 position.x += (Viewport.SCROLL_INCREMENT / this.viewport_.zoom);
512 }
513 }
514 this.viewport_.position = position;
515 },
516
517 /**
442 * @private 518 * @private
443 * A callback that's called before the zoom changes. Notify the plugin to stop 519 * A callback that's called before the zoom changes. Notify the plugin to stop
444 * reacting to scroll events while zoom is taking place to avoid flickering. 520 * reacting to scroll events while zoom is taking place to avoid flickering.
445 */ 521 */
446 beforeZoom_: function() { 522 beforeZoom_: function() {
447 this.plugin_.postMessage({ 523 this.plugin_.postMessage({
448 type: 'stopScrolling' 524 type: 'stopScrolling'
449 }); 525 });
450 }, 526 },
451 527
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 this.streamDetails_.tabId != -1); 741 this.streamDetails_.tabId != -1);
666 }, 742 },
667 743
668 /** 744 /**
669 * @type {Viewport} the viewport of the PDF viewer. 745 * @type {Viewport} the viewport of the PDF viewer.
670 */ 746 */
671 get viewport() { 747 get viewport() {
672 return this.viewport_; 748 return this.viewport_;
673 } 749 }
674 }; 750 };
OLDNEW
« 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