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 // Setup hammer.js touch event listener. | |
bokan
2016/04/21 02:24:00
Comments should describe "why", not "what". In thi
alessandroa
2016/04/21 20:39:39
Done.
| |
221 this.hammertime_ = new Hammer($('plugin')); | |
222 | |
223 // We must preventDefault if there are is a two fingers touch. | |
bokan
2016/04/21 02:24:00
"are is" -> "is"
"fingers" -> "finger"
Same as ab
alessandroa
2016/04/21 20:39:39
Acknowledged.
| |
224 this.plugin_.addEventListener('touchstart', function(e) { | |
225 if (e.touches.length >= 2) { | |
226 e.preventDefault(); | |
227 this.hammertime_.get('pinch').set({enable: true}); | |
228 } else | |
bokan
2016/04/21 02:24:00
Else block should also have curly braces {} (if on
alessandroa
2016/04/21 20:39:39
Acknowledged.
| |
229 this.hammertime_.get('pinch').set({enable: false}); | |
230 }.bind(this)); | |
231 | |
232 this.plugin_.addEventListener('touchend', function(e) { | |
233 if (e.touches.length >= 2) | |
234 this.hammertime_.get('pinch').set({enable: true}); | |
bokan
2016/04/21 02:24:00
I think you only need the "enable: false" branch i
alessandroa
2016/04/21 20:39:39
Done.
| |
235 else | |
236 this.hammertime_.get('pinch').set({enable: false}); | |
237 }.bind(this)); | |
238 | |
239 this.hammertime_.on('pinchstart', function(ev) { | |
240 window.requestAnimationFrame(function() { | |
241 this.pinchZoomStart(ev); | |
242 }.bind(this)); | |
243 }.bind(this.viewport_)); | |
244 | |
245 this.hammertime_.on('pinch', function(ev) { | |
246 window.requestAnimationFrame(function() { | |
247 this.pinchZoom(ev); | |
bokan
2016/04/21 02:24:00
The way these are set up, if "pinch" is called 5 t
alessandroa
2016/04/21 20:39:39
Acknowledged.
| |
248 }.bind(this)); | |
249 }.bind(this.viewport_)); | |
250 | |
251 this.hammertime_.on('pinchend', function(ev) { | |
252 window.requestAnimationFrame(function() { | |
253 this.pinchZoomEnd(ev); | |
254 }.bind(this)); | |
255 }.bind(this.viewport_)); | |
256 | |
220 if (toolbarEnabled) { | 257 if (toolbarEnabled) { |
221 this.toolbar_ = $('toolbar'); | 258 this.toolbar_ = $('toolbar'); |
222 this.toolbar_.hidden = false; | 259 this.toolbar_.hidden = false; |
223 this.toolbar_.addEventListener('save', this.save_.bind(this)); | 260 this.toolbar_.addEventListener('save', this.save_.bind(this)); |
224 this.toolbar_.addEventListener('print', this.print_.bind(this)); | 261 this.toolbar_.addEventListener('print', this.print_.bind(this)); |
225 this.toolbar_.addEventListener('rotate-right', | 262 this.toolbar_.addEventListener('rotate-right', |
226 this.rotateClockwise_.bind(this)); | 263 this.rotateClockwise_.bind(this)); |
227 // Must attach to mouseup on the plugin element, since it eats mousedown | 264 // Must attach to mouseup on the plugin element, since it eats mousedown |
228 // and click events. | 265 // and click events. |
229 this.plugin_.addEventListener('mouseup', | 266 this.plugin_.addEventListener('mouseup', |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 | 480 |
444 fitToPage_: function() { | 481 fitToPage_: function() { |
445 this.viewport_.fitToPage(); | 482 this.viewport_.fitToPage(); |
446 this.toolbarManager_.forceHideTopToolbar(); | 483 this.toolbarManager_.forceHideTopToolbar(); |
447 }, | 484 }, |
448 | 485 |
449 /** | 486 /** |
450 * @private | 487 * @private |
451 * Notify the plugin to print. | 488 * Notify the plugin to print. |
452 */ | 489 */ |
453 print_: function() { | 490 print_: function() { this.plugin_.postMessage({type: 'print'}); }, |
bokan
2016/04/21 02:24:00
Undo the whitespace change (makes going back in ti
alessandroa
2016/04/21 20:39:39
Done.
| |
454 this.plugin_.postMessage({ | |
455 type: 'print' | |
456 }); | |
457 }, | |
458 | 491 |
459 /** | 492 /** |
460 * @private | 493 * @private |
461 * Notify the plugin to save. | 494 * Notify the plugin to save. |
462 */ | 495 */ |
463 save_: function() { | 496 save_: function() { this.plugin_.postMessage({type: 'save'}); }, |
464 this.plugin_.postMessage({ | |
465 type: 'save' | |
466 }); | |
467 }, | |
468 | 497 |
469 /** | 498 /** |
470 * Fetches the page number corresponding to the given named destination from | 499 * Fetches the page number corresponding to the given named destination from |
471 * the plugin. | 500 * the plugin. |
472 * @param {string} name The namedDestination to fetch page number from plugin. | 501 * @param {string} name The namedDestination to fetch page number from plugin. |
473 */ | 502 */ |
474 getNamedDestination_: function(name) { | 503 getNamedDestination_: function(name) { |
475 this.plugin_.postMessage({ | 504 this.plugin_.postMessage({ |
476 type: 'getNamedDestination', | 505 type: 'getNamedDestination', |
477 namedDestination: name | 506 namedDestination: name |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 }, | 709 }, |
681 | 710 |
682 /** | 711 /** |
683 * @private | 712 * @private |
684 * A callback that's called after the zoom changes. Notify the plugin of the | 713 * A callback that's called after the zoom changes. Notify the plugin of the |
685 * zoom change and to continue reacting to scroll events. | 714 * zoom change and to continue reacting to scroll events. |
686 */ | 715 */ |
687 afterZoom_: function() { | 716 afterZoom_: function() { |
688 var position = this.viewport_.position; | 717 var position = this.viewport_.position; |
689 var zoom = this.viewport_.zoom; | 718 var zoom = this.viewport_.zoom; |
719 var pinchVector = this.viewport_.pinchPanVector_; | |
720 var pinchCenter = this.viewport_.pinchCenter_; | |
721 var doRender = true; | |
722 if (!this.viewport_.doRender_) | |
bokan
2016/04/21 15:22:06
This can just be doRender = this.viewport_.doRende
alessandroa
2016/04/21 20:39:39
Acknowledged.
| |
723 doRender = false; | |
wjmaclean
2016/04/21 14:11:01
I don't understand ... isn't this the equivalent o
alessandroa
2016/04/21 20:39:39
I changed from 1 and 0 to true and false and I for
| |
724 | |
725 if (!pinchVector) | |
726 pinchVector = {x: 0, y: 0}; | |
727 if (!pinchCenter) | |
728 pinchCenter = {x: 0, y: 0}; | |
690 this.plugin_.postMessage({ | 729 this.plugin_.postMessage({ |
691 type: 'viewport', | 730 type: 'viewport', |
692 zoom: zoom, | 731 zoom: zoom, |
693 xOffset: position.x, | 732 xOffset: position.x, |
694 yOffset: position.y | 733 yOffset: position.y, |
734 render: doRender, // Render or not | |
735 px: pinchCenter.x, | |
736 py: pinchCenter.y, | |
737 pinchVectorX: pinchVector.x, | |
738 pinchVectorY: pinchVector.y | |
695 }); | 739 }); |
696 this.zoomManager_.onPdfZoomChange(); | 740 this.zoomManager_.onPdfZoomChange(); |
697 }, | 741 }, |
698 | 742 |
699 /** | 743 /** |
700 * @private | 744 * @private |
701 * A callback that's called after the viewport changes. | 745 * A callback that's called after the viewport changes. |
702 */ | 746 */ |
703 viewportChanged_: function() { | 747 viewportChanged_: function() { |
704 if (!this.documentDimensions_) | 748 if (!this.documentDimensions_) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
863 targetOrigin = '*'; | 907 targetOrigin = '*'; |
864 else | 908 else |
865 targetOrigin = this.originalUrl_; | 909 targetOrigin = this.originalUrl_; |
866 this.parentWindow_.postMessage(message, targetOrigin); | 910 this.parentWindow_.postMessage(message, targetOrigin); |
867 } | 911 } |
868 }, | 912 }, |
869 | 913 |
870 /** | 914 /** |
871 * @type {Viewport} the viewport of the PDF viewer. | 915 * @type {Viewport} the viewport of the PDF viewer. |
872 */ | 916 */ |
873 get viewport() { | 917 get viewport() { return this.viewport_; }, |
bokan
2016/04/21 02:24:00
Ditto on whitespace here and below
alessandroa
2016/04/21 20:39:39
Sorry .. ctrl + f screwed this up :)
| |
874 return this.viewport_; | |
875 }, | |
876 | 918 |
877 /** | 919 /** |
878 * Each bookmark is an Object containing a: | 920 * Each bookmark is an Object containing a: |
879 * - title | 921 * - title |
880 * - page (optional) | 922 * - page (optional) |
881 * - array of children (themselves bookmarks) | 923 * - array of children (themselves bookmarks) |
882 * @type {Array} the top-level bookmarks of the PDF. | 924 * @type {Array} the top-level bookmarks of the PDF. |
883 */ | 925 */ |
884 get bookmarks() { | 926 get bookmarks() { return this.bookmarks_; } |
885 return this.bookmarks_; | |
886 } | |
887 }; | 927 }; |
OLD | NEW |