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.hammertime_.on('pinch', function(ev) { | |
| 241 if(!this.didPinch_) { | |
| 242 this.didPinch_ = true; | |
| 243 window.requestAnimationFrame(function() { | |
| 244 this.didPinch_ = false; | |
| 245 this.pinchZoom(ev); | |
| 246 }.bind(this)); | |
| 247 } | |
| 248 }.bind(this.viewport_)); | |
| 249 | |
| 250 this.hammertime_.on('pinchend', function(ev) { | |
| 251 if(!this.didPinchEnd_) { | |
| 252 this.didPinchEnd_ = true; | |
| 253 window.requestAnimationFrame(function() { | |
|
bokan
2016/05/12 14:57:57
I don't think we need to rAF the PinchEnd event.
| |
| 254 this.didPinchEnd_ = false; | |
| 255 this.pinchZoomEnd(ev); | |
| 256 }.bind(this)); | |
| 257 } | |
| 258 }.bind(this.viewport_)); | |
| 259 | |
| 220 if (toolbarEnabled) { | 260 if (toolbarEnabled) { |
| 221 this.toolbar_ = $('toolbar'); | 261 this.toolbar_ = $('toolbar'); |
| 222 this.toolbar_.hidden = false; | 262 this.toolbar_.hidden = false; |
| 223 this.toolbar_.addEventListener('save', this.save_.bind(this)); | 263 this.toolbar_.addEventListener('save', this.save_.bind(this)); |
| 224 this.toolbar_.addEventListener('print', this.print_.bind(this)); | 264 this.toolbar_.addEventListener('print', this.print_.bind(this)); |
| 225 this.toolbar_.addEventListener('rotate-right', | 265 this.toolbar_.addEventListener('rotate-right', |
| 226 this.rotateClockwise_.bind(this)); | 266 this.rotateClockwise_.bind(this)); |
| 227 // Must attach to mouseup on the plugin element, since it eats mousedown | 267 // Must attach to mouseup on the plugin element, since it eats mousedown |
| 228 // and click events. | 268 // and click events. |
| 229 this.plugin_.addEventListener('mouseup', | 269 this.plugin_.addEventListener('mouseup', |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 680 }, | 720 }, |
| 681 | 721 |
| 682 /** | 722 /** |
| 683 * @private | 723 * @private |
| 684 * A callback that's called after the zoom changes. Notify the plugin of the | 724 * A callback that's called after the zoom changes. Notify the plugin of the |
| 685 * zoom change and to continue reacting to scroll events. | 725 * zoom change and to continue reacting to scroll events. |
| 686 */ | 726 */ |
| 687 afterZoom_: function() { | 727 afterZoom_: function() { |
| 688 var position = this.viewport_.position; | 728 var position = this.viewport_.position; |
| 689 var zoom = this.viewport_.zoom; | 729 var zoom = this.viewport_.zoom; |
| 730 var pinchVector = this.viewport_.pinchPanVector_; | |
| 731 var pinchCenter = this.viewport_.pinchCenter_; | |
| 732 var doRender = this.viewport.doRender_; | |
| 733 | |
| 734 if (!pinchVector) | |
| 735 pinchVector = {x: 0, y: 0}; | |
| 736 if (!pinchCenter) | |
| 737 pinchCenter = {x: 0, y: 0}; | |
| 690 this.plugin_.postMessage({ | 738 this.plugin_.postMessage({ |
| 691 type: 'viewport', | 739 type: 'viewport', |
| 692 zoom: zoom, | 740 zoom: zoom, |
| 693 xOffset: position.x, | 741 xOffset: position.x, |
| 694 yOffset: position.y | 742 yOffset: position.y, |
| 743 render: doRender, // Render or not | |
|
bokan
2016/05/12 14:57:57
I think a better name here would be needsReraster
| |
| 744 px: pinchCenter.x, | |
| 745 py: pinchCenter.y, | |
| 746 pinchVectorX: pinchVector.x, | |
| 747 pinchVectorY: pinchVector.y | |
| 695 }); | 748 }); |
| 696 this.zoomManager_.onPdfZoomChange(); | 749 this.zoomManager_.onPdfZoomChange(); |
| 697 }, | 750 }, |
| 698 | 751 |
| 699 /** | 752 /** |
| 700 * @private | 753 * @private |
| 701 * A callback that's called after the viewport changes. | 754 * A callback that's called after the viewport changes. |
| 702 */ | 755 */ |
| 703 viewportChanged_: function() { | 756 viewportChanged_: function() { |
| 704 if (!this.documentDimensions_) | 757 if (!this.documentDimensions_) |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 * Each bookmark is an Object containing a: | 931 * Each bookmark is an Object containing a: |
| 879 * - title | 932 * - title |
| 880 * - page (optional) | 933 * - page (optional) |
| 881 * - array of children (themselves bookmarks) | 934 * - array of children (themselves bookmarks) |
| 882 * @type {Array} the top-level bookmarks of the PDF. | 935 * @type {Array} the top-level bookmarks of the PDF. |
| 883 */ | 936 */ |
| 884 get bookmarks() { | 937 get bookmarks() { |
| 885 return this.bookmarks_; | 938 return this.bookmarks_; |
| 886 } | 939 } |
| 887 }; | 940 }; |
| OLD | NEW |