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 | |
| 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', function(ev) { | |
| 211 this.pinchZoomStart(ev); | |
| 212 }.bind(this.viewport_)); | |
| 213 | |
| 214 this.hammertime_.on('pinch', function(ev) { | |
| 215 if(!this.didPinch_) { | |
|
Kevin McNee - google account
2016/10/06 21:53:17
Style: missing space
Kevin McNee - google account
2016/10/13 18:19:23
Done.
| |
| 216 this.didPinch_ = true; | |
|
Kevin McNee - google account
2016/10/07 19:08:49
There are several places where we access viewport'
Kevin McNee - google account
2016/10/13 18:19:23
Done.
| |
| 217 window.requestAnimationFrame(function() { | |
| 218 this.didPinch_ = false; | |
| 219 this.pinchZoom(ev); | |
| 220 }.bind(this)); | |
| 221 } | |
| 222 }.bind(this.viewport_)); | |
|
Kevin McNee - google account
2016/10/07 19:08:49
I'm not really a fan of these kind of binds. It ma
Kevin McNee - google account
2016/10/13 18:19:23
Done.
| |
| 223 | |
| 224 this.hammertime_.on('pinchend', function(ev) { | |
| 225 if(!this.didPinchEnd_) { | |
|
Kevin McNee - google account
2016/10/06 21:53:17
Style: missing space
Kevin McNee - google account
2016/10/13 18:19:23
Done.
| |
| 226 this.didPinchEnd_ = true; | |
| 227 window.requestAnimationFrame(function() { | |
|
Kevin McNee - google account
2016/10/06 21:53:17
Comment from previous review:
bokan: I don't think
Kevin McNee - google account
2016/10/07 19:08:49
The method that this calls, pinchZoomEnd, does a f
bokan
2016/10/07 19:16:03
It's been a while since I've looked at this. I thi
Kevin McNee - google account
2016/10/07 19:38:11
Oh, I see. I'll double check, but assuming the eve
Kevin McNee - google account
2016/10/13 18:04:02
It looks like this was preventing a race where a p
| |
| 228 this.didPinchEnd_ = false; | |
| 229 this.pinchZoomEnd(ev); | |
| 230 }.bind(this)); | |
| 231 } | |
| 232 }.bind(this.viewport_)); | |
| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 }, | 702 }, |
| 663 | 703 |
| 664 /** | 704 /** |
| 665 * @private | 705 * @private |
| 666 * A callback that's called after the zoom changes. Notify the plugin of the | 706 * A callback that's called after the zoom changes. Notify the plugin of the |
| 667 * zoom change and to continue reacting to scroll events. | 707 * zoom change and to continue reacting to scroll events. |
| 668 */ | 708 */ |
| 669 afterZoom_: function() { | 709 afterZoom_: function() { |
| 670 var position = this.viewport_.position; | 710 var position = this.viewport_.position; |
| 671 var zoom = this.viewport_.zoom; | 711 var zoom = this.viewport_.zoom; |
| 712 var pinchVector = this.viewport_.pinchPanVector_; | |
| 713 var pinchCenter = this.viewport_.pinchCenter_; | |
| 714 var doRender = this.viewport.doRender_; | |
|
Kevin McNee - google account
2016/10/07 19:08:49
Consistent use of viewport / viewport_
Kevin McNee - google account
2016/10/13 18:19:23
Done.
| |
| 715 | |
| 716 if (!pinchVector) | |
| 717 pinchVector = {x: 0, y: 0}; | |
| 718 if (!pinchCenter) | |
| 719 pinchCenter = {x: 0, y: 0}; | |
| 672 this.plugin_.postMessage({ | 720 this.plugin_.postMessage({ |
| 673 type: 'viewport', | 721 type: 'viewport', |
| 674 zoom: zoom, | 722 zoom: zoom, |
| 675 xOffset: position.x, | 723 xOffset: position.x, |
| 676 yOffset: position.y | 724 yOffset: position.y, |
| 725 render: doRender, // Render or not | |
|
Kevin McNee - google account
2016/10/06 21:53:17
Comment from previous review:
bokan: I think a bet
wjmaclean
2016/10/07 12:30:21
Agreed, needsReraster is better.
Nit: update comm
Kevin McNee - google account
2016/10/13 18:19:23
Done.
| |
| 726 px: pinchCenter.x, | |
| 727 py: pinchCenter.y, | |
| 728 pinchVectorX: pinchVector.x, | |
| 729 pinchVectorY: pinchVector.y | |
| 677 }); | 730 }); |
| 678 this.zoomManager_.onPdfZoomChange(); | 731 this.zoomManager_.onPdfZoomChange(); |
| 679 }, | 732 }, |
| 680 | 733 |
| 681 /** | 734 /** |
| 682 * @private | 735 * @private |
| 683 * A callback that's called after the viewport changes. | 736 * A callback that's called after the viewport changes. |
| 684 */ | 737 */ |
| 685 viewportChanged_: function() { | 738 viewportChanged_: function() { |
| 686 if (!this.documentDimensions_) | 739 if (!this.documentDimensions_) |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 859 * Each bookmark is an Object containing a: | 912 * Each bookmark is an Object containing a: |
| 860 * - title | 913 * - title |
| 861 * - page (optional) | 914 * - page (optional) |
| 862 * - array of children (themselves bookmarks) | 915 * - array of children (themselves bookmarks) |
| 863 * @type {Array} the top-level bookmarks of the PDF. | 916 * @type {Array} the top-level bookmarks of the PDF. |
| 864 */ | 917 */ |
| 865 get bookmarks() { | 918 get bookmarks() { |
| 866 return this.bookmarks_; | 919 return this.bookmarks_; |
| 867 } | 920 } |
| 868 }; | 921 }; |
| OLD | NEW |