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

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, 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 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 window.open(url); 51 window.open(url);
52 } 52 }
53 53
54 /** 54 /**
55 * The minimum number of pixels to offset the toolbar by from the bottom and 55 * The minimum number of pixels to offset the toolbar by from the bottom and
56 * right side of the screen. 56 * right side of the screen.
57 */ 57 */
58 PDFViewer.MIN_TOOLBAR_OFFSET = 15; 58 PDFViewer.MIN_TOOLBAR_OFFSET = 15;
59 59
60 /** 60 /**
61 * 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.
62 * dragged out of the viewport. The callback function will get called after
63 * this interval till timer get cleared.
64 */
65 PDFViewer.DRAG_TIMER_INTERVAL = 100;
66
67 /**
68 * 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.
69 * viewport.
70 */
71 PDFViewer.MAX_SCROLL_VELOCITY = 100;
72
73 /**
61 * Creates a new PDFViewer. There should only be one of these objects per 74 * Creates a new PDFViewer. There should only be one of these objects per
62 * document. 75 * document.
63 * @constructor 76 * @constructor
64 * @param {Object} streamDetails The stream object which points to the data 77 * @param {Object} streamDetails The stream object which points to the data
65 * contained in the PDF. 78 * contained in the PDF.
66 */ 79 */
67 function PDFViewer(streamDetails) { 80 function PDFViewer(streamDetails) {
68 this.streamDetails_ = streamDetails; 81 this.streamDetails_ = streamDetails;
69 this.loaded_ = false; 82 this.loaded_ = false;
70 this.parentWindow_ = null; 83 this.parentWindow_ = null;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) 199 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
187 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); 200 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
188 }.bind(this)); 201 }.bind(this));
189 } 202 }
190 203
191 // Parse open pdf parameters. 204 // Parse open pdf parameters.
192 this.paramsParser_ = new OpenPDFParamsParser(); 205 this.paramsParser_ = new OpenPDFParamsParser();
193 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, 206 this.navigator_ = new Navigator(this.streamDetails_.originalUrl,
194 this.viewport_, this.paramsParser_, onNavigateInCurrentTab, 207 this.viewport_, this.paramsParser_, onNavigateInCurrentTab,
195 onNavigateInNewTab); 208 onNavigateInNewTab);
209 this.mousemoveCallback_ = null;
210 this.timerId_ = null;
211 this.scrollVelocity_ = null;
196 } 212 }
197 213
198 PDFViewer.prototype = { 214 PDFViewer.prototype = {
199 /** 215 /**
200 * @private 216 * @private
201 * Handle key events. These may come from the user directly or via the 217 * Handle key events. These may come from the user directly or via the
202 * scripting API. 218 * scripting API.
203 * @param {KeyboardEvent} e the event to handle. 219 * @param {KeyboardEvent} e the event to handle.
204 */ 220 */
205 handleKeyEvent_: function(e) { 221 handleKeyEvent_: function(e) {
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 this.errorScreen_.text = message.data.loadFailedString; 528 this.errorScreen_.text = message.data.loadFailedString;
513 break; 529 break;
514 case 'cancelStreamUrl': 530 case 'cancelStreamUrl':
515 chrome.mimeHandlerPrivate.abortStream(); 531 chrome.mimeHandlerPrivate.abortStream();
516 break; 532 break;
517 case 'bookmarks': 533 case 'bookmarks':
518 this.bookmarks_ = message.data.bookmarks; 534 this.bookmarks_ = message.data.bookmarks;
519 if (this.isMaterial_) 535 if (this.isMaterial_)
520 this.bookmarksPane.bookmarks = message.data.bookmarks; 536 this.bookmarksPane.bookmarks = message.data.bookmarks;
521 break; 537 break;
538 case 'setIsSelecting':
539 if (message.data.isSelecting && !this.mousemoveCallback_) {
540 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.
541 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.
542 this.mousemoveCallback_, false);
543 } else {
544 this.clearTimerInterval_();
545 if (this.mousemoveCallback_) {
546 this.plugin_.removeEventListener('mousemove',
Sam McNally 2015/02/06 03:43:07 Ditto.
Deepak 2015/02/06 08:33:43 Done.
547 this.mousemoveCallback_, false);
548 this.mousemoveCallback_ = null;
Sam McNally 2015/02/06 03:43:07 Delete.
Deepak 2015/02/06 08:33:43 Done.
549 }
550 }
551 break;
522 } 552 }
523 }, 553 },
524 554
525 /** 555 /**
556 * @private
557 * 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.
558 * timer get cleared.
559 */
560 setTimerInterval_: function() {
Sam McNally 2015/02/06 03:43:07 startDragScrollTimer_
Deepak 2015/02/06 08:33:43 Done.
561 this.timerId_ =
562 window.setInterval(this.dragScrollPage_.bind(this),
563 PDFViewer.DRAG_TIMER_INTERVAL);
564 },
565
566 /**
567 * @private
568 * 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.
569 */
570 clearTimerInterval_: function() {
Sam McNally 2015/02/06 03:43:07 stopDragScrollTimer_
Deepak 2015/02/06 08:33:43 Done.
571 if (this.timerId_ !== null) {
572 window.clearInterval(this.timerId_);
573 this.timerId_ = null;
574 }
575 },
576
577 /**
578 * @private
579 * 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.
580 * does not get mousemove event.
581 */
582 dragScrollPage_: function() {
583 var position = this.viewport_.position;
584 position.y += this.scrollVelocity_.y;
585 position.x += this.scrollVelocity_.x;
586 this.viewport_.position = position;
587 },
588
589 /**
590 * @private
591 * 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.
592 * out of the viewport and does not move mouse. The scroll velocity depends
593 * upon mouse pointer distance from the viewport.
594 * @return {Object} Object with x and y direction scroll velocity.
595 */
596 calculateVelocity_: function(event) {
597 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.
598 this.plugin_.offsetWidth, 0), PDFViewer.MAX_SCROLL_VELOCITY) *
599 Math.sign(event.offsetX);
600 var y = Math.min(Math.max(-event.offsetY, event.offsetY -
601 this.plugin_.offsetHeight, 0), PDFViewer.MAX_SCROLL_VELOCITY) *
602 Math.sign(event.offsetY);
603 return {x: x, y: y};
604 },
605
606 /**
607 * @private
608 * 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.
609 * the direction of scroll. When mouse move event does not come then we are
610 * scrolling based on timer.
611 * @param {Object} event The mousemove event.
612 */
613 selectionDragListener_: function(event) {
614 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.
615 var viewportRect = {
616 x1: position.x / this.viewport_.zoom,
617 y1: position.y / this.viewport_.zoom,
618 x2: (position.x + this.viewport_.size.width) / this.viewport_.zoom,
619 y2: (position.y + this.viewport_.size.height) / this.viewport_.zoom
620 };
621 var point = {
622 x: event.pageX / this.viewport_.zoom,
623 y: event.pageY / this.viewport_.zoom
624 };
625
626 if ((point.x >= viewportRect.x1 && point.x <= viewportRect.x2) &&
627 (point.y >= viewportRect.y1 && point.y <= viewportRect.y2)) {
628 this.clearTimerInterval_();
629 return;
630 }
631 this.scrollVelocity_ = this.calculateVelocity_(event);
632 if ((this.scrollVelocity_.x != 0 || this.scrollVelocity_.y != 0) &&
633 !this.timerId_) {
634 this.setTimerInterval_();
Sam McNally 2015/02/06 03:43:07 Please make setTimerInterval_ idempotent and simpl
Deepak 2015/02/06 08:33:43 Done.
635 }
636 if (!this.scrollVelocity_.x && !this.scrollVelocity_.y)
637 this.clearTimerInterval_();
638 },
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
639
640 /**
526 * @private 641 * @private
527 * A callback that's called before the zoom changes. Notify the plugin to stop 642 * A callback that's called before the zoom changes. Notify the plugin to stop
528 * reacting to scroll events while zoom is taking place to avoid flickering. 643 * reacting to scroll events while zoom is taking place to avoid flickering.
529 */ 644 */
530 beforeZoom_: function() { 645 beforeZoom_: function() {
531 this.plugin_.postMessage({ 646 this.plugin_.postMessage({
532 type: 'stopScrolling' 647 type: 'stopScrolling'
533 }); 648 });
534 }, 649 },
535 650
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 * Each bookmark is an Object containing a: 870 * Each bookmark is an Object containing a:
756 * - title 871 * - title
757 * - page (optional) 872 * - page (optional)
758 * - array of children (themselves bookmarks) 873 * - array of children (themselves bookmarks)
759 * @type {Array} the top-level bookmarks of the PDF. 874 * @type {Array} the top-level bookmarks of the PDF.
760 */ 875 */
761 get bookmarks() { 876 get bookmarks() {
762 return this.bookmarks_; 877 return this.bookmarks_;
763 } 878 }
764 }; 879 };
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