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; | |
dpapad
2016/11/09 01:12:26
Nit:
var pinchVector = this.viewport_.pinchPanVect
Kevin McNee - google account
2016/11/09 16:36:09
Done.
| |
695 var pinchCenter = this.viewport_.pinchCenter; | |
696 var pinchPhase = this.viewport_.pinchPhase; | |
697 | |
698 if (!pinchVector) | |
699 pinchVector = {x: 0, y: 0}; | |
700 if (!pinchCenter) | |
701 pinchCenter = {x: 0, y: 0}; | |
672 this.plugin_.postMessage({ | 702 this.plugin_.postMessage({ |
673 type: 'viewport', | 703 type: 'viewport', |
674 zoom: zoom, | 704 zoom: zoom, |
675 xOffset: position.x, | 705 xOffset: position.x, |
676 yOffset: position.y | 706 yOffset: position.y, |
707 pinchPhase: pinchPhase, | |
708 pinchX: pinchCenter.x, | |
709 pinchY: pinchCenter.y, | |
710 pinchVectorX: pinchVector.x, | |
711 pinchVectorY: pinchVector.y | |
677 }); | 712 }); |
678 this.zoomManager_.onPdfZoomChange(); | 713 this.zoomManager_.onPdfZoomChange(); |
679 }, | 714 }, |
680 | 715 |
681 /** | 716 /** |
682 * @private | 717 * @private |
718 * A callback that's called when an update to a pinch zoom is detected. | |
719 * @param {!Object} e the pinch event. | |
720 */ | |
721 onPinchUpdate_: function(e) { | |
722 // Throttle number of pinch events to one per frame. | |
723 if (!this.sentPinchEvent_) { | |
724 this.sentPinchEvent_ = true; | |
725 window.requestAnimationFrame(function() { | |
726 this.sentPinchEvent_ = false; | |
727 this.viewport_.pinchZoom(e); | |
728 }.bind(this)); | |
729 } | |
730 }, | |
731 | |
732 /** | |
733 * @private | |
734 * A callback that's called when the end of a pinch zoom is detected. | |
735 * @param {!Object} e the pinch event. | |
736 */ | |
737 onPinchEnd_: function(e) { | |
738 // Using rAF for pinch end prevents pinch updates scheduled by rAF getting | |
739 // sent after the pinch end. | |
740 window.requestAnimationFrame(function() { | |
741 this.viewport_.pinchZoomEnd(e); | |
742 }.bind(this)); | |
743 }, | |
744 | |
745 /** | |
746 * @private | |
683 * A callback that's called after the viewport changes. | 747 * A callback that's called after the viewport changes. |
684 */ | 748 */ |
685 viewportChanged_: function() { | 749 viewportChanged_: function() { |
686 if (!this.documentDimensions_) | 750 if (!this.documentDimensions_) |
687 return; | 751 return; |
688 | 752 |
689 // Offset the toolbar position so that it doesn't move if scrollbars appear. | 753 // Offset the toolbar position so that it doesn't move if scrollbars appear. |
690 var hasScrollbars = this.viewport_.documentHasScrollbars(); | 754 var hasScrollbars = this.viewport_.documentHasScrollbars(); |
691 var scrollbarWidth = this.viewport_.scrollbarWidth; | 755 var scrollbarWidth = this.viewport_.scrollbarWidth; |
692 var verticalScrollbarWidth = hasScrollbars.vertical ? scrollbarWidth : 0; | 756 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: | 923 * Each bookmark is an Object containing a: |
860 * - title | 924 * - title |
861 * - page (optional) | 925 * - page (optional) |
862 * - array of children (themselves bookmarks) | 926 * - array of children (themselves bookmarks) |
863 * @type {Array} the top-level bookmarks of the PDF. | 927 * @type {Array} the top-level bookmarks of the PDF. |
864 */ | 928 */ |
865 get bookmarks() { | 929 get bookmarks() { |
866 return this.bookmarks_; | 930 return this.bookmarks_; |
867 } | 931 } |
868 }; | 932 }; |
OLD | NEW |