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.gesture_detector_ = new GestureDetector(this.plugin_); | |
dpapad
2016/10/31 23:02:23
Nit: s/gesture_detector/gestureDetector
Kevin McNee - google account
2016/11/07 23:08:27
Done.
| |
195 | |
196 this.gesture_detector_.addEventListener( | |
197 'pinchstart', this.viewport_.pinchZoomStart.bind(this.viewport_)); | |
198 | |
199 // Throttle number of pinch events to one per frame. | |
200 this.sentPinchEvent_ = false; | |
201 | |
dpapad
2016/10/31 23:02:23
The PDFViwer constructor is a huge function. Perha
Kevin McNee - google account
2016/11/07 23:08:27
Done.
| |
202 this.gesture_detector_.addEventListener('pinchupdate', function(ev) { | |
203 if (!this.sentPinchEvent_) { | |
204 this.sentPinchEvent_ = true; | |
205 window.requestAnimationFrame(function() { | |
206 this.sentPinchEvent_ = false; | |
207 this.viewport_.pinchZoom(ev); | |
208 }.bind(this)); | |
209 } | |
210 }.bind(this)); | |
211 | |
212 this.gesture_detector_.addEventListener('pinchend', function(ev) { | |
213 // Using rAF for pinch end prevents pinch updates scheduled by rAF getting | |
214 // sent after the pinch end. | |
215 window.requestAnimationFrame(function() { | |
216 this.viewport_.pinchZoomEnd(ev); | |
217 }.bind(this)); | |
218 }.bind(this)); | |
219 | |
194 if (toolbarEnabled) { | 220 if (toolbarEnabled) { |
195 this.toolbar_ = $('toolbar'); | 221 this.toolbar_ = $('toolbar'); |
196 this.toolbar_.hidden = false; | 222 this.toolbar_.hidden = false; |
197 this.toolbar_.addEventListener('save', this.save_.bind(this)); | 223 this.toolbar_.addEventListener('save', this.save_.bind(this)); |
198 this.toolbar_.addEventListener('print', this.print_.bind(this)); | 224 this.toolbar_.addEventListener('print', this.print_.bind(this)); |
199 this.toolbar_.addEventListener('rotate-right', | 225 this.toolbar_.addEventListener('rotate-right', |
200 this.rotateClockwise_.bind(this)); | 226 this.rotateClockwise_.bind(this)); |
201 // Must attach to mouseup on the plugin element, since it eats mousedown | 227 // Must attach to mouseup on the plugin element, since it eats mousedown |
202 // and click events. | 228 // and click events. |
203 this.plugin_.addEventListener('mouseup', | 229 this.plugin_.addEventListener('mouseup', |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 | 678 |
653 /** | 679 /** |
654 * @private | 680 * @private |
655 * A callback that's called before the zoom changes. Notify the plugin to stop | 681 * 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. | 682 * reacting to scroll events while zoom is taking place to avoid flickering. |
657 */ | 683 */ |
658 beforeZoom_: function() { | 684 beforeZoom_: function() { |
659 this.plugin_.postMessage({ | 685 this.plugin_.postMessage({ |
660 type: 'stopScrolling' | 686 type: 'stopScrolling' |
661 }); | 687 }); |
688 | |
689 if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) { | |
690 var position = this.viewport_.position; | |
691 var zoom = this.viewport_.zoom; | |
692 var pinchPhase = this.viewport_.pinchPhase; | |
693 this.plugin_.postMessage({ | |
694 type: 'viewport', | |
695 zoom: zoom, | |
696 xOffset: position.x, | |
697 yOffset: position.y, | |
698 pinchPhase: pinchPhase | |
699 }); | |
700 } | |
662 }, | 701 }, |
663 | 702 |
664 /** | 703 /** |
665 * @private | 704 * @private |
666 * A callback that's called after the zoom changes. Notify the plugin of the | 705 * A callback that's called after the zoom changes. Notify the plugin of the |
667 * zoom change and to continue reacting to scroll events. | 706 * zoom change and to continue reacting to scroll events. |
668 */ | 707 */ |
669 afterZoom_: function() { | 708 afterZoom_: function() { |
670 var position = this.viewport_.position; | 709 var position = this.viewport_.position; |
671 var zoom = this.viewport_.zoom; | 710 var zoom = this.viewport_.zoom; |
711 var pinchVector = this.viewport_.pinchPanVector; | |
712 var pinchCenter = this.viewport_.pinchCenter; | |
713 var pinchPhase = this.viewport_.pinchPhase; | |
714 | |
715 if (!pinchVector) | |
716 pinchVector = {x: 0, y: 0}; | |
717 if (!pinchCenter) | |
718 pinchCenter = {x: 0, y: 0}; | |
672 this.plugin_.postMessage({ | 719 this.plugin_.postMessage({ |
673 type: 'viewport', | 720 type: 'viewport', |
674 zoom: zoom, | 721 zoom: zoom, |
675 xOffset: position.x, | 722 xOffset: position.x, |
676 yOffset: position.y | 723 yOffset: position.y, |
724 pinchPhase: pinchPhase, | |
725 pinchX: pinchCenter.x, | |
726 pinchY: pinchCenter.y, | |
727 pinchVectorX: pinchVector.x, | |
728 pinchVectorY: pinchVector.y | |
677 }); | 729 }); |
678 this.zoomManager_.onPdfZoomChange(); | 730 this.zoomManager_.onPdfZoomChange(); |
679 }, | 731 }, |
680 | 732 |
681 /** | 733 /** |
682 * @private | 734 * @private |
683 * A callback that's called after the viewport changes. | 735 * A callback that's called after the viewport changes. |
684 */ | 736 */ |
685 viewportChanged_: function() { | 737 viewportChanged_: function() { |
686 if (!this.documentDimensions_) | 738 if (!this.documentDimensions_) |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 * Each bookmark is an Object containing a: | 911 * Each bookmark is an Object containing a: |
860 * - title | 912 * - title |
861 * - page (optional) | 913 * - page (optional) |
862 * - array of children (themselves bookmarks) | 914 * - array of children (themselves bookmarks) |
863 * @type {Array} the top-level bookmarks of the PDF. | 915 * @type {Array} the top-level bookmarks of the PDF. |
864 */ | 916 */ |
865 get bookmarks() { | 917 get bookmarks() { |
866 return this.bookmarks_; | 918 return this.bookmarks_; |
867 } | 919 } |
868 }; | 920 }; |
OLD | NEW |