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 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 // We add Hammer.js in order to handle touch events like pinch-zoom. | |
| 195 this.hammertime_ = new Hammer($('plugin')); | |
| 196 | |
| 197 // We must preventDefault if there is a two finger touch. By doing so browser | |
|
bokan
2016/10/17 22:20:15
Please replace "browser zoom" with "native pinch-z
Kevin McNee - google account
2016/10/24 21:11:47
Done.
| |
| 198 // zoom does not interfere with our way of handling the event. | |
| 199 this.plugin_.addEventListener('touchstart', function(e) { | |
| 200 if (e.touches.length >= 2) { | |
| 201 e.preventDefault(); | |
| 202 this.hammertime_.get('pinch').set({enable: true}); | |
| 203 } | |
| 204 }.bind(this)); | |
| 205 | |
| 206 this.plugin_.addEventListener('touchend', function(e) { | |
| 207 this.hammertime_.get('pinch').set({enable: false}); | |
| 208 }.bind(this)); | |
| 209 | |
| 210 this.hammertime_.on('pinchstart', | |
| 211 this.viewport_.pinchZoomStart.bind(this.viewport_)); | |
| 212 | |
| 213 // Throttle number of pinch events to one per frame. | |
| 214 this.sentPinchEvent_ = false; | |
| 215 | |
| 216 this.hammertime_.on('pinch', function(ev) { | |
| 217 if (!this.sentPinchEvent_) { | |
| 218 this.sentPinchEvent_ = true; | |
| 219 window.requestAnimationFrame(function() { | |
| 220 this.sentPinchEvent_ = false; | |
| 221 this.viewport_.pinchZoom(ev); | |
| 222 }.bind(this)); | |
| 223 } | |
| 224 }.bind(this)); | |
| 225 | |
| 226 this.hammertime_.on('pinchend', function(ev) { | |
| 227 // Using rAF for pinch end prevents pinch updates scheduled by rAF getting | |
| 228 // sent after the pinch end. | |
| 229 window.requestAnimationFrame(function() { | |
| 230 this.viewport_.pinchZoomEnd(ev); | |
| 231 }.bind(this)); | |
| 232 }.bind(this)); | |
| 233 | |
| 194 if (toolbarEnabled) { | 234 if (toolbarEnabled) { |
| 195 this.toolbar_ = $('toolbar'); | 235 this.toolbar_ = $('toolbar'); |
| 196 this.toolbar_.hidden = false; | 236 this.toolbar_.hidden = false; |
| 197 this.toolbar_.addEventListener('save', this.save_.bind(this)); | 237 this.toolbar_.addEventListener('save', this.save_.bind(this)); |
| 198 this.toolbar_.addEventListener('print', this.print_.bind(this)); | 238 this.toolbar_.addEventListener('print', this.print_.bind(this)); |
| 199 this.toolbar_.addEventListener('rotate-right', | 239 this.toolbar_.addEventListener('rotate-right', |
| 200 this.rotateClockwise_.bind(this)); | 240 this.rotateClockwise_.bind(this)); |
| 201 // Must attach to mouseup on the plugin element, since it eats mousedown | 241 // Must attach to mouseup on the plugin element, since it eats mousedown |
| 202 // and click events. | 242 // and click events. |
| 203 this.plugin_.addEventListener('mouseup', | 243 this.plugin_.addEventListener('mouseup', |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 | 692 |
| 653 /** | 693 /** |
| 654 * @private | 694 * @private |
| 655 * A callback that's called before the zoom changes. Notify the plugin to stop | 695 * 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. | 696 * reacting to scroll events while zoom is taking place to avoid flickering. |
| 657 */ | 697 */ |
| 658 beforeZoom_: function() { | 698 beforeZoom_: function() { |
| 659 this.plugin_.postMessage({ | 699 this.plugin_.postMessage({ |
| 660 type: 'stopScrolling' | 700 type: 'stopScrolling' |
| 661 }); | 701 }); |
| 702 | |
| 703 if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) { | |
| 704 var position = this.viewport_.position; | |
| 705 var zoom = this.viewport_.zoom; | |
| 706 var pinchPhase = this.viewport_.pinchPhase; | |
| 707 this.plugin_.postMessage({ | |
| 708 type: 'viewport', | |
| 709 zoom: zoom, | |
| 710 xOffset: position.x, | |
| 711 yOffset: position.y, | |
| 712 pinchPhase: pinchPhase | |
| 713 }); | |
| 714 } | |
| 662 }, | 715 }, |
| 663 | 716 |
| 664 /** | 717 /** |
| 665 * @private | 718 * @private |
| 666 * A callback that's called after the zoom changes. Notify the plugin of the | 719 * A callback that's called after the zoom changes. Notify the plugin of the |
| 667 * zoom change and to continue reacting to scroll events. | 720 * zoom change and to continue reacting to scroll events. |
| 668 */ | 721 */ |
| 669 afterZoom_: function() { | 722 afterZoom_: function() { |
| 670 var position = this.viewport_.position; | 723 var position = this.viewport_.position; |
| 671 var zoom = this.viewport_.zoom; | 724 var zoom = this.viewport_.zoom; |
| 725 var pinchVector = this.viewport_.pinchPanVector; | |
| 726 var pinchCenter = this.viewport_.pinchCenter; | |
| 727 var pinchPhase = this.viewport_.pinchPhase; | |
| 728 | |
| 729 if (!pinchVector) | |
| 730 pinchVector = {x: 0, y: 0}; | |
| 731 if (!pinchCenter) | |
| 732 pinchCenter = {x: 0, y: 0}; | |
| 672 this.plugin_.postMessage({ | 733 this.plugin_.postMessage({ |
| 673 type: 'viewport', | 734 type: 'viewport', |
| 674 zoom: zoom, | 735 zoom: zoom, |
| 675 xOffset: position.x, | 736 xOffset: position.x, |
| 676 yOffset: position.y | 737 yOffset: position.y, |
| 738 pinchPhase: pinchPhase, | |
| 739 pinchX: pinchCenter.x, | |
| 740 pinchY: pinchCenter.y, | |
| 741 pinchVectorX: pinchVector.x, | |
| 742 pinchVectorY: pinchVector.y | |
| 677 }); | 743 }); |
| 678 this.zoomManager_.onPdfZoomChange(); | 744 this.zoomManager_.onPdfZoomChange(); |
| 679 }, | 745 }, |
| 680 | 746 |
| 681 /** | 747 /** |
| 682 * @private | 748 * @private |
| 683 * A callback that's called after the viewport changes. | 749 * A callback that's called after the viewport changes. |
| 684 */ | 750 */ |
| 685 viewportChanged_: function() { | 751 viewportChanged_: function() { |
| 686 if (!this.documentDimensions_) | 752 if (!this.documentDimensions_) |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 859 * Each bookmark is an Object containing a: | 925 * Each bookmark is an Object containing a: |
| 860 * - title | 926 * - title |
| 861 * - page (optional) | 927 * - page (optional) |
| 862 * - array of children (themselves bookmarks) | 928 * - array of children (themselves bookmarks) |
| 863 * @type {Array} the top-level bookmarks of the PDF. | 929 * @type {Array} the top-level bookmarks of the PDF. |
| 864 */ | 930 */ |
| 865 get bookmarks() { | 931 get bookmarks() { |
| 866 return this.bookmarks_; | 932 return this.bookmarks_; |
| 867 } | 933 } |
| 868 }; | 934 }; |
| OLD | NEW |