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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 this.zoomToolbar_ = $('zoom-toolbar'); | 210 this.zoomToolbar_ = $('zoom-toolbar'); |
| 211 this.zoomToolbar_.addEventListener('fit-to-width', | 211 this.zoomToolbar_.addEventListener('fit-to-width', |
| 212 this.viewport_.fitToWidth.bind(this.viewport_)); | 212 this.viewport_.fitToWidth.bind(this.viewport_)); |
| 213 this.zoomToolbar_.addEventListener('fit-to-page', | 213 this.zoomToolbar_.addEventListener('fit-to-page', |
| 214 this.fitToPage_.bind(this)); | 214 this.fitToPage_.bind(this)); |
| 215 this.zoomToolbar_.addEventListener('zoom-in', | 215 this.zoomToolbar_.addEventListener('zoom-in', |
| 216 this.viewport_.zoomIn.bind(this.viewport_)); | 216 this.viewport_.zoomIn.bind(this.viewport_)); |
| 217 this.zoomToolbar_.addEventListener('zoom-out', | 217 this.zoomToolbar_.addEventListener('zoom-out', |
| 218 this.viewport_.zoomOut.bind(this.viewport_)); | 218 this.viewport_.zoomOut.bind(this.viewport_)); |
| 219 | 219 |
| 220 // We add Hammer.js in order to handle touch events like pinch-zoom. | |
| 221 this.hammertime_ = new Hammer($('plugin')); | |
| 222 | |
| 223 // We must preventDefault if there is a two finger touch. By doing so browser | |
| 224 // zoom does not interfere with our way of handling the event. | |
| 225 this.plugin_.addEventListener('touchstart', function(e) { | |
| 226 if (e.touches.length >= 2) { | |
| 227 e.preventDefault(); | |
| 228 this.hammertime_.get('pinch').set({enable: true}); | |
| 229 } | |
| 230 }.bind(this)); | |
| 231 | |
| 232 this.plugin_.addEventListener('touchend', function(e) { | |
| 233 this.hammertime_.get('pinch').set({enable: false}); | |
| 234 }.bind(this)); | |
| 235 | |
| 236 this.hammertime_.on('pinchstart', function(ev) { | |
| 237 this.pinchZoomStart(ev); | |
| 238 }.bind(this.viewport_)); | |
| 239 | |
| 240 this.didPinch_ = false; | |
| 241 this.didPinchEnd_ = false; | |
|
bokan
2016/04/22 15:45:35
These should be on this.viewport_ since you bind y
alessandroa
2016/04/22 18:59:02
That's true! Ups :)
| |
| 242 | |
| 243 this.hammertime_.on('pinch', function(ev) { | |
| 244 if(!this.didPinch_) { | |
| 245 this.didPinch_ = true; | |
| 246 window.requestAnimationFrame(function() { | |
| 247 this.didPinch_ = false; | |
| 248 this.pinchZoom(ev); | |
| 249 }.bind(this)); | |
| 250 } | |
| 251 }.bind(this.viewport_)); | |
| 252 | |
| 253 this.hammertime_.on('pinchend', function(ev) { | |
| 254 if(!this.didPinchEnd_) { | |
| 255 window.requestAnimationFrame(function() { | |
| 256 this.didPinchEnd_ = false; | |
| 257 this.pinchZoomEnd(ev); | |
| 258 }.bind(this)); | |
| 259 } | |
| 260 }.bind(this.viewport_)); | |
| 261 | |
| 220 if (toolbarEnabled) { | 262 if (toolbarEnabled) { |
| 221 this.toolbar_ = $('toolbar'); | 263 this.toolbar_ = $('toolbar'); |
| 222 this.toolbar_.hidden = false; | 264 this.toolbar_.hidden = false; |
| 223 this.toolbar_.addEventListener('save', this.save_.bind(this)); | 265 this.toolbar_.addEventListener('save', this.save_.bind(this)); |
| 224 this.toolbar_.addEventListener('print', this.print_.bind(this)); | 266 this.toolbar_.addEventListener('print', this.print_.bind(this)); |
| 225 this.toolbar_.addEventListener('rotate-right', | 267 this.toolbar_.addEventListener('rotate-right', |
| 226 this.rotateClockwise_.bind(this)); | 268 this.rotateClockwise_.bind(this)); |
| 227 // Must attach to mouseup on the plugin element, since it eats mousedown | 269 // Must attach to mouseup on the plugin element, since it eats mousedown |
| 228 // and click events. | 270 // and click events. |
| 229 this.plugin_.addEventListener('mouseup', | 271 this.plugin_.addEventListener('mouseup', |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 680 }, | 722 }, |
| 681 | 723 |
| 682 /** | 724 /** |
| 683 * @private | 725 * @private |
| 684 * A callback that's called after the zoom changes. Notify the plugin of the | 726 * A callback that's called after the zoom changes. Notify the plugin of the |
| 685 * zoom change and to continue reacting to scroll events. | 727 * zoom change and to continue reacting to scroll events. |
| 686 */ | 728 */ |
| 687 afterZoom_: function() { | 729 afterZoom_: function() { |
| 688 var position = this.viewport_.position; | 730 var position = this.viewport_.position; |
| 689 var zoom = this.viewport_.zoom; | 731 var zoom = this.viewport_.zoom; |
| 732 var pinchVector = this.viewport_.pinchPanVector_; | |
| 733 var pinchCenter = this.viewport_.pinchCenter_; | |
| 734 var doRender = this.viewport.doRender_; | |
| 735 | |
| 736 if (!pinchVector) | |
| 737 pinchVector = {x: 0, y: 0}; | |
| 738 if (!pinchCenter) | |
| 739 pinchCenter = {x: 0, y: 0}; | |
| 690 this.plugin_.postMessage({ | 740 this.plugin_.postMessage({ |
| 691 type: 'viewport', | 741 type: 'viewport', |
| 692 zoom: zoom, | 742 zoom: zoom, |
| 693 xOffset: position.x, | 743 xOffset: position.x, |
| 694 yOffset: position.y | 744 yOffset: position.y, |
| 745 render: doRender, // Render or not | |
| 746 px: pinchCenter.x, | |
| 747 py: pinchCenter.y, | |
| 748 pinchVectorX: pinchVector.x, | |
| 749 pinchVectorY: pinchVector.y | |
| 695 }); | 750 }); |
| 696 this.zoomManager_.onPdfZoomChange(); | 751 this.zoomManager_.onPdfZoomChange(); |
| 697 }, | 752 }, |
| 698 | 753 |
| 699 /** | 754 /** |
| 700 * @private | 755 * @private |
| 701 * A callback that's called after the viewport changes. | 756 * A callback that's called after the viewport changes. |
| 702 */ | 757 */ |
| 703 viewportChanged_: function() { | 758 viewportChanged_: function() { |
| 704 if (!this.documentDimensions_) | 759 if (!this.documentDimensions_) |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 * Each bookmark is an Object containing a: | 933 * Each bookmark is an Object containing a: |
| 879 * - title | 934 * - title |
| 880 * - page (optional) | 935 * - page (optional) |
| 881 * - array of children (themselves bookmarks) | 936 * - array of children (themselves bookmarks) |
| 882 * @type {Array} the top-level bookmarks of the PDF. | 937 * @type {Array} the top-level bookmarks of the PDF. |
| 883 */ | 938 */ |
| 884 get bookmarks() { | 939 get bookmarks() { |
| 885 return this.bookmarks_; | 940 return this.bookmarks_; |
| 886 } | 941 } |
| 887 }; | 942 }; |
| OLD | NEW |