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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 this.zoomToolbar_ = $('zoom-toolbar'); | 184 this.zoomToolbar_ = $('zoom-toolbar'); |
185 this.zoomToolbar_.addEventListener('fit-to-width', | 185 this.zoomToolbar_.addEventListener('fit-to-width', |
186 this.viewport_.fitToWidth.bind(this.viewport_)); | 186 this.viewport_.fitToWidth.bind(this.viewport_)); |
187 this.zoomToolbar_.addEventListener('fit-to-page', | 187 this.zoomToolbar_.addEventListener('fit-to-page', |
188 this.fitToPage_.bind(this)); | 188 this.fitToPage_.bind(this)); |
189 this.zoomToolbar_.addEventListener('zoom-in', | 189 this.zoomToolbar_.addEventListener('zoom-in', |
190 this.viewport_.zoomIn.bind(this.viewport_)); | 190 this.viewport_.zoomIn.bind(this.viewport_)); |
191 this.zoomToolbar_.addEventListener('zoom-out', | 191 this.zoomToolbar_.addEventListener('zoom-out', |
192 this.viewport_.zoomOut.bind(this.viewport_)); | 192 this.viewport_.zoomOut.bind(this.viewport_)); |
193 | 193 |
| 194 this.gestureDetector_ = new GestureDetector(this.plugin_); |
| 195 this.gestureDetector_.addEventListener( |
| 196 'pinchstart', this.viewport_.pinchZoomStart.bind(this.viewport_)); |
| 197 this.sentPinchEvent_ = false; |
| 198 this.gestureDetector_.addEventListener( |
| 199 'pinchupdate', this.onPinchUpdate_.bind(this)); |
| 200 this.gestureDetector_.addEventListener( |
| 201 'pinchend', this.onPinchEnd_.bind(this)); |
| 202 |
194 if (toolbarEnabled) { | 203 if (toolbarEnabled) { |
195 this.toolbar_ = $('toolbar'); | 204 this.toolbar_ = $('toolbar'); |
196 this.toolbar_.hidden = false; | 205 this.toolbar_.hidden = false; |
197 this.toolbar_.addEventListener('save', this.save_.bind(this)); | 206 this.toolbar_.addEventListener('save', this.save_.bind(this)); |
198 this.toolbar_.addEventListener('print', this.print_.bind(this)); | 207 this.toolbar_.addEventListener('print', this.print_.bind(this)); |
199 this.toolbar_.addEventListener('rotate-right', | 208 this.toolbar_.addEventListener('rotate-right', |
200 this.rotateClockwise_.bind(this)); | 209 this.rotateClockwise_.bind(this)); |
201 // Must attach to mouseup on the plugin element, since it eats mousedown | 210 // Must attach to mouseup on the plugin element, since it eats mousedown |
202 // and click events. | 211 // and click events. |
203 this.plugin_.addEventListener('mouseup', | 212 this.plugin_.addEventListener('mouseup', |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 661 |
653 /** | 662 /** |
654 * @private | 663 * @private |
655 * A callback that's called before the zoom changes. Notify the plugin to stop | 664 * A callback that's called before the zoom changes. Notify the plugin to stop |
656 * reacting to scroll events while zoom is taking place to avoid flickering. | 665 * reacting to scroll events while zoom is taking place to avoid flickering. |
657 */ | 666 */ |
658 beforeZoom_: function() { | 667 beforeZoom_: function() { |
659 this.plugin_.postMessage({ | 668 this.plugin_.postMessage({ |
660 type: 'stopScrolling' | 669 type: 'stopScrolling' |
661 }); | 670 }); |
| 671 |
| 672 if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) { |
| 673 var position = this.viewport_.position; |
| 674 var zoom = this.viewport_.zoom; |
| 675 var pinchPhase = this.viewport_.pinchPhase; |
| 676 this.plugin_.postMessage({ |
| 677 type: 'viewport', |
| 678 zoom: zoom, |
| 679 xOffset: position.x, |
| 680 yOffset: position.y, |
| 681 pinchPhase: pinchPhase |
| 682 }); |
| 683 } |
662 }, | 684 }, |
663 | 685 |
664 /** | 686 /** |
665 * @private | 687 * @private |
666 * A callback that's called after the zoom changes. Notify the plugin of the | 688 * A callback that's called after the zoom changes. Notify the plugin of the |
667 * zoom change and to continue reacting to scroll events. | 689 * zoom change and to continue reacting to scroll events. |
668 */ | 690 */ |
669 afterZoom_: function() { | 691 afterZoom_: function() { |
670 var position = this.viewport_.position; | 692 var position = this.viewport_.position; |
671 var zoom = this.viewport_.zoom; | 693 var zoom = this.viewport_.zoom; |
| 694 var pinchVector = this.viewport_.pinchPanVector || {x: 0, y: 0}; |
| 695 var pinchCenter = this.viewport_.pinchCenter || {x: 0, y: 0}; |
| 696 var pinchPhase = this.viewport_.pinchPhase; |
| 697 |
672 this.plugin_.postMessage({ | 698 this.plugin_.postMessage({ |
673 type: 'viewport', | 699 type: 'viewport', |
674 zoom: zoom, | 700 zoom: zoom, |
675 xOffset: position.x, | 701 xOffset: position.x, |
676 yOffset: position.y | 702 yOffset: position.y, |
| 703 pinchPhase: pinchPhase, |
| 704 pinchX: pinchCenter.x, |
| 705 pinchY: pinchCenter.y, |
| 706 pinchVectorX: pinchVector.x, |
| 707 pinchVectorY: pinchVector.y |
677 }); | 708 }); |
678 this.zoomManager_.onPdfZoomChange(); | 709 this.zoomManager_.onPdfZoomChange(); |
679 }, | 710 }, |
680 | 711 |
681 /** | 712 /** |
682 * @private | 713 * @private |
| 714 * A callback that's called when an update to a pinch zoom is detected. |
| 715 * @param {!Object} e the pinch event. |
| 716 */ |
| 717 onPinchUpdate_: function(e) { |
| 718 // Throttle number of pinch events to one per frame. |
| 719 if (!this.sentPinchEvent_) { |
| 720 this.sentPinchEvent_ = true; |
| 721 window.requestAnimationFrame(function() { |
| 722 this.sentPinchEvent_ = false; |
| 723 this.viewport_.pinchZoom(e); |
| 724 }.bind(this)); |
| 725 } |
| 726 }, |
| 727 |
| 728 /** |
| 729 * @private |
| 730 * A callback that's called when the end of a pinch zoom is detected. |
| 731 * @param {!Object} e the pinch event. |
| 732 */ |
| 733 onPinchEnd_: function(e) { |
| 734 // Using rAF for pinch end prevents pinch updates scheduled by rAF getting |
| 735 // sent after the pinch end. |
| 736 window.requestAnimationFrame(function() { |
| 737 this.viewport_.pinchZoomEnd(e); |
| 738 }.bind(this)); |
| 739 }, |
| 740 |
| 741 /** |
| 742 * @private |
683 * A callback that's called after the viewport changes. | 743 * A callback that's called after the viewport changes. |
684 */ | 744 */ |
685 viewportChanged_: function() { | 745 viewportChanged_: function() { |
686 if (!this.documentDimensions_) | 746 if (!this.documentDimensions_) |
687 return; | 747 return; |
688 | 748 |
689 // Offset the toolbar position so that it doesn't move if scrollbars appear. | 749 // Offset the toolbar position so that it doesn't move if scrollbars appear. |
690 var hasScrollbars = this.viewport_.documentHasScrollbars(); | 750 var hasScrollbars = this.viewport_.documentHasScrollbars(); |
691 var scrollbarWidth = this.viewport_.scrollbarWidth; | 751 var scrollbarWidth = this.viewport_.scrollbarWidth; |
692 var verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0; | 752 var verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 * Each bookmark is an Object containing a: | 919 * Each bookmark is an Object containing a: |
860 * - title | 920 * - title |
861 * - page (optional) | 921 * - page (optional) |
862 * - array of children (themselves bookmarks) | 922 * - array of children (themselves bookmarks) |
863 * @type {Array} the top-level bookmarks of the PDF. | 923 * @type {Array} the top-level bookmarks of the PDF. |
864 */ | 924 */ |
865 get bookmarks() { | 925 get bookmarks() { |
866 return this.bookmarks_; | 926 return this.bookmarks_; |
867 } | 927 } |
868 }; | 928 }; |
OLD | NEW |