Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 // when we initiate the zoom. | 150 // when we initiate the zoom. |
| 151 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) | 151 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) |
| 152 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | 152 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); |
| 153 }.bind(this)); | 153 }.bind(this)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Parse open pdf parameters. | 156 // Parse open pdf parameters. |
| 157 this.paramsParser_ = new OpenPDFParamsParser(); | 157 this.paramsParser_ = new OpenPDFParamsParser(); |
| 158 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, | 158 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, |
| 159 this.viewport_, this.paramsParser_); | 159 this.viewport_, this.paramsParser_); |
| 160 this.isSelecting_ = false; | |
| 161 this.mousemoveCallback_ = null; | |
| 162 this.timerId_ = null; | |
| 163 this.dragDirection_; | |
| 160 } | 164 } |
| 161 | 165 |
| 162 PDFViewer.prototype = { | 166 PDFViewer.prototype = { |
| 163 /** | 167 /** |
| 164 * @private | 168 * @private |
| 165 * Handle key events. These may come from the user directly or via the | 169 * Handle key events. These may come from the user directly or via the |
| 166 * scripting API. | 170 * scripting API. |
| 167 * @param {KeyboardEvent} e the event to handle. | 171 * @param {KeyboardEvent} e the event to handle. |
| 168 */ | 172 */ |
| 169 handleKeyEvent_: function(e) { | 173 handleKeyEvent_: function(e) { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 if (!this.isPrintPreview_) | 447 if (!this.isPrintPreview_) |
| 444 this.progressBar_.style.visibility = 'visible'; | 448 this.progressBar_.style.visibility = 'visible'; |
| 445 this.errorScreen_.text = message.data.loadFailedString; | 449 this.errorScreen_.text = message.data.loadFailedString; |
| 446 break; | 450 break; |
| 447 case 'cancelStreamUrl': | 451 case 'cancelStreamUrl': |
| 448 chrome.mimeHandlerPrivate.abortStream(); | 452 chrome.mimeHandlerPrivate.abortStream(); |
| 449 break; | 453 break; |
| 450 case 'bookmarks': | 454 case 'bookmarks': |
| 451 this.bookmarks_ = message.data.bookmarks; | 455 this.bookmarks_ = message.data.bookmarks; |
| 452 break; | 456 break; |
| 457 case 'setIsSelecting': | |
| 458 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.
| |
| 459 if (this.isSelecting_) { | |
| 460 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.
| |
| 461 this.plugin_.addEventListener('mousemove', | |
| 462 this.mousemoveCallback_, false); | |
| 463 } else { | |
| 464 this.plugin_.removeEventListener('mousemove', | |
|
Sam McNally
2015/02/04 02:56:02
Ditto.
Deepak
2015/02/04 13:50:54
Done.
| |
| 465 this.mousemoveCallback_, false); | |
| 466 this.clearTimer_(); | |
| 467 } | |
| 468 break; | |
| 453 } | 469 } |
| 454 }, | 470 }, |
| 455 | 471 |
| 472 /** | |
| 473 * @private | |
| 474 * Clear the timer if it is active and reset timerId. | |
| 475 */ | |
| 476 clearTimer_: function() { | |
| 477 if (this.timerId_) { | |
| 478 window.clearTimeout(this.timerId_); | |
|
Sam McNally
2015/02/04 02:56:01
Use clearInterval here.
Deepak
2015/02/04 13:50:54
Done.
| |
| 479 this.timerId_ = null; | |
| 480 } | |
| 481 }, | |
| 482 | |
| 483 /** | |
| 484 * @private | |
| 485 * Handles scrolling in the page when we drag mouse out of the viewport and | |
| 486 * does not move mouse, Then no mouse move event came so we are scrolling | |
| 487 * based on timer in drag direction. | |
| 488 */ | |
| 489 dragScrollPage_: function() { | |
| 490 this.clearTimer_(); | |
| 491 var position = this.viewport_.position; | |
| 492 switch (this.dragDirection_) { | |
| 493 case 'up': | |
| 494 position.y -= ((Viewport.SCROLL_INCREMENT) / this.viewport_.zoom); | |
| 495 break; | |
| 496 case 'down': | |
| 497 position.y += ((Viewport.SCROLL_INCREMENT) / this.viewport_.zoom); | |
| 498 break; | |
| 499 case 'left': | |
| 500 position.x -= ((Viewport.SCROLL_INCREMENT) / this.viewport_.zoom); | |
| 501 break; | |
| 502 case 'right': | |
| 503 position.x += ((Viewport.SCROLL_INCREMENT) / this.viewport_.zoom); | |
| 504 break; | |
| 505 } | |
| 506 this.viewport_.position = position; | |
| 507 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.
| |
| 508 }, | |
| 509 | |
| 510 /** | |
| 511 * @private | |
| 512 * Handles mousemove events. Scrolls page when mouse move happen reacting to | |
| 513 * the direction of scroll. | |
| 514 * @param {Object} event The mouse move event. | |
| 515 */ | |
| 516 selectionDragListener_: function(event) { | |
| 517 var position = this.viewport_.position; | |
| 518 var viewportRect = { | |
| 519 x1: position.x / this.viewport_.zoom, | |
| 520 y1: position.y / this.viewport_.zoom, | |
| 521 x2: (position.x + this.viewport_.size.width) / this.viewport_.zoom, | |
| 522 y2: (position.y + this.viewport_.size.height) / this.viewport_.zoom | |
| 523 }; | |
| 524 var point = { | |
| 525 x: event.pageX / this.viewport_.zoom, | |
| 526 y: event.pageY / this.viewport_.zoom | |
| 527 }; | |
| 528 | |
| 529 if ((point.x >= viewportRect.x1 && point.x <= viewportRect.x2) && | |
| 530 (point.y >= viewportRect.y1 && point.y <= viewportRect.y2)) { | |
| 531 this.clearTimer_(); | |
| 532 return; | |
| 533 } | |
| 534 | |
| 535 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.
| |
| 536 if (point.y < viewportRect.y1 && viewportRect.y1 > 0) { | |
| 537 this.dragDirection_ = 'up'; | |
| 538 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.
| |
| 539 } else if ((point.y > viewportRect.y2) && | |
| 540 (event.pageY < (this.viewport_.documentDimensions_.height * | |
| 541 this.viewport_.zoom))) { | |
| 542 this.dragDirection_ = 'down'; | |
| 543 this.dragScrollPage_(); | |
| 544 } | |
| 545 } | |
| 546 if (this.viewport_.documentHasScrollbars().horizontal) { | |
| 547 if (point.x < viewportRect.x1 && viewportRect.x1 > 0) { | |
| 548 this.dragDirection_ = 'left'; | |
| 549 this.dragScrollPage_(); | |
| 550 } else if ((point.x > viewportRect.x2) && | |
| 551 (event.pageX < this.viewport_.documentDimensions_.width * | |
| 552 this.viewport_.zoom)) { | |
| 553 this.dragDirection_ = 'right'; | |
| 554 this.dragScrollPage_(); | |
| 555 } | |
| 556 } | |
| 557 }, | |
| 558 | |
| 456 /** | 559 /** |
| 457 * @private | 560 * @private |
| 458 * A callback that's called before the zoom changes. Notify the plugin to stop | 561 * A callback that's called before the zoom changes. Notify the plugin to stop |
| 459 * reacting to scroll events while zoom is taking place to avoid flickering. | 562 * reacting to scroll events while zoom is taking place to avoid flickering. |
| 460 */ | 563 */ |
| 461 beforeZoom_: function() { | 564 beforeZoom_: function() { |
| 462 this.plugin_.postMessage({ | 565 this.plugin_.postMessage({ |
| 463 type: 'stopScrolling' | 566 type: 'stopScrolling' |
| 464 }); | 567 }); |
| 465 }, | 568 }, |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 * Each bookmark is an Object containing a: | 797 * Each bookmark is an Object containing a: |
| 695 * - title | 798 * - title |
| 696 * - page (optional) | 799 * - page (optional) |
| 697 * - array of children (themselves bookmarks) | 800 * - array of children (themselves bookmarks) |
| 698 * @type {Array} the top-level bookmarks of the PDF. | 801 * @type {Array} the top-level bookmarks of the PDF. |
| 699 */ | 802 */ |
| 700 get bookmarks() { | 803 get bookmarks() { |
| 701 return this.bookmarks_; | 804 return this.bookmarks_; |
| 702 } | 805 } |
| 703 }; | 806 }; |
| OLD | NEW |