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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 }.bind(this)); | 169 }.bind(this)); |
| 170 | 170 |
| 171 document.body.addEventListener('change-page', function(e) { | 171 document.body.addEventListener('change-page', function(e) { |
| 172 this.viewport_.goToPage(e.detail.page); | 172 this.viewport_.goToPage(e.detail.page); |
| 173 }.bind(this)); | 173 }.bind(this)); |
| 174 | 174 |
| 175 this.uiManager_ = new UiManager(window, this.materialToolbar_, | 175 this.uiManager_ = new UiManager(window, this.materialToolbar_, |
| 176 [this.bookmarksPane_]); | 176 [this.bookmarksPane_]); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Set up the zoom API. | |
| 180 if (this.shouldManageZoom_()) { | |
| 181 chrome.tabs.setZoomSettings(this.streamDetails_.tabId, | |
| 182 {mode: 'manual', scope: 'per-tab'}, function() { | |
| 183 this.zoomManager_ = | |
| 184 new ZoomManager(this.viewport_, this.setZoom_.bind(this)); | |
| 185 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { | |
| 186 if (zoomChangeInfo.tabId != this.streamDetails_.tabId) | |
| 187 return; | |
|
raymes
2015/04/09 03:40:01
Do you think we should pass in the zoom id? Then w
Sam McNally
2015/04/09 08:24:40
I'd prefer to avoid ZoomManager needing to know ab
| |
| 188 this.zoomManager_.onBrowserZoomChange(zoomChangeInfo.newZoomFactor); | |
| 189 }.bind(this)); | |
| 190 }.bind(this)); | |
| 191 } | |
| 192 | |
| 179 // Setup the keyboard event listener. | 193 // Setup the keyboard event listener. |
| 180 document.onkeydown = this.handleKeyEvent_.bind(this); | 194 document.onkeydown = this.handleKeyEvent_.bind(this); |
| 181 | 195 |
| 182 // Set up the zoom API. | |
| 183 if (this.shouldManageZoom_()) { | |
| 184 chrome.tabs.setZoomSettings(this.streamDetails_.tabId, | |
| 185 {mode: 'manual', scope: 'per-tab'}, | |
| 186 this.afterZoom_.bind(this)); | |
| 187 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { | |
| 188 if (zoomChangeInfo.tabId != this.streamDetails_.tabId) | |
| 189 return; | |
| 190 // If the zoom level is close enough to the current zoom level, don't | |
| 191 // change it. This avoids us getting into an infinite loop of zoom changes | |
| 192 // due to floating point error. | |
| 193 var MIN_ZOOM_DELTA = 0.01; | |
| 194 var zoomDelta = Math.abs(this.viewport_.zoom - | |
| 195 zoomChangeInfo.newZoomFactor); | |
| 196 // We should not change zoom level when we are responsible for initiating | |
| 197 // the zoom. onZoomChange() is called before setZoomComplete() callback | |
| 198 // when we initiate the zoom. | |
| 199 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) | |
| 200 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | |
| 201 }.bind(this)); | |
| 202 } | |
| 203 | |
| 204 // Parse open pdf parameters. | 196 // Parse open pdf parameters. |
| 205 this.paramsParser_ = | 197 this.paramsParser_ = |
| 206 new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); | 198 new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); |
| 207 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, | 199 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, |
| 208 this.viewport_, this.paramsParser_, | 200 this.viewport_, this.paramsParser_, |
| 209 onNavigateInCurrentTab, onNavigateInNewTab); | 201 onNavigateInCurrentTab, onNavigateInNewTab); |
| 210 this.viewportScroller_ = | 202 this.viewportScroller_ = |
| 211 new ViewportScroller(this.viewport_, this.plugin_, window); | 203 new ViewportScroller(this.viewport_, this.plugin_, window); |
| 212 } | 204 } |
| 213 | 205 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 if (this.passwordScreen_.active) | 473 if (this.passwordScreen_.active) |
| 482 this.passwordScreen_.accept(); | 474 this.passwordScreen_.accept(); |
| 483 | 475 |
| 484 if (this.isMaterial_) { | 476 if (this.isMaterial_) { |
| 485 this.materialToolbar_.docLength = | 477 this.materialToolbar_.docLength = |
| 486 this.documentDimensions_.pageDimensions.length; | 478 this.documentDimensions_.pageDimensions.length; |
| 487 } else { | 479 } else { |
| 488 this.pageIndicator_.initialFadeIn(); | 480 this.pageIndicator_.initialFadeIn(); |
| 489 this.toolbar_.initialFadeIn(); | 481 this.toolbar_.initialFadeIn(); |
| 490 } | 482 } |
| 491 | |
| 492 break; | 483 break; |
| 493 case 'email': | 484 case 'email': |
| 494 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + | 485 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + |
| 495 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + | 486 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + |
| 496 '&body=' + message.data.body; | 487 '&body=' + message.data.body; |
| 497 window.location.href = href; | 488 window.location.href = href; |
| 498 break; | 489 break; |
| 499 case 'getAccessibilityJSONReply': | 490 case 'getAccessibilityJSONReply': |
| 500 this.sendScriptingMessage_(message.data); | 491 this.sendScriptingMessage_(message.data); |
| 501 break; | 492 break; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 /** | 565 /** |
| 575 * @private | 566 * @private |
| 576 * A callback that's called after the zoom changes. Notify the plugin of the | 567 * A callback that's called after the zoom changes. Notify the plugin of the |
| 577 * zoom change and to continue reacting to scroll events. | 568 * zoom change and to continue reacting to scroll events. |
| 578 */ | 569 */ |
| 579 afterZoom_: function() { | 570 afterZoom_: function() { |
| 580 var position = this.viewport_.position; | 571 var position = this.viewport_.position; |
| 581 var zoom = this.viewport_.zoom; | 572 var zoom = this.viewport_.zoom; |
| 582 if (this.isMaterial_) | 573 if (this.isMaterial_) |
| 583 this.zoomSelector_.zoomValue = 100 * zoom; | 574 this.zoomSelector_.zoomValue = 100 * zoom; |
| 584 if (this.shouldManageZoom_() && !this.setZoomInProgress_) { | |
| 585 this.setZoomInProgress_ = true; | |
| 586 chrome.tabs.setZoom(this.streamDetails_.tabId, zoom, | |
| 587 this.setZoomComplete_.bind(this, zoom)); | |
| 588 } | |
| 589 this.plugin_.postMessage({ | 575 this.plugin_.postMessage({ |
| 590 type: 'viewport', | 576 type: 'viewport', |
| 591 zoom: zoom, | 577 zoom: zoom, |
| 592 xOffset: position.x, | 578 xOffset: position.x, |
| 593 yOffset: position.y | 579 yOffset: position.y |
| 594 }); | 580 }); |
| 581 if (this.zoomManager_) | |
| 582 this.zoomManager_.onPdfZoomChange(); | |
| 583 }, | |
| 584 | |
| 585 setZoom_: function(zoom) { | |
| 586 return new Promise(function(resolve, reject) { | |
| 587 chrome.tabs.setZoom(this.streamDetails_.tabId, zoom, resolve); | |
|
raymes
2015/04/09 03:40:01
Why don't you pass in the function that sets the z
Sam McNally
2015/04/09 08:24:40
I'd prefer ZoomManager to use a nice interface ins
| |
| 588 }.bind(this)); | |
| 595 }, | 589 }, |
| 596 | 590 |
| 597 /** | 591 /** |
| 598 * @private | |
| 599 * A callback that's called after chrome.tabs.setZoom is complete. This will | |
| 600 * call chrome.tabs.setZoom again if the zoom level has changed since it was | |
| 601 * last called. | |
| 602 * @param {number} lastZoom the zoom level that chrome.tabs.setZoom was called | |
| 603 * with. | |
| 604 */ | |
| 605 setZoomComplete_: function(lastZoom) { | |
| 606 var zoom = this.viewport_.zoom; | |
| 607 if (zoom !== lastZoom) { | |
| 608 chrome.tabs.setZoom(this.streamDetails_.tabId, zoom, | |
| 609 this.setZoomComplete_.bind(this, zoom)); | |
| 610 } else { | |
| 611 this.setZoomInProgress_ = false; | |
| 612 } | |
| 613 }, | |
| 614 | |
| 615 /** | |
| 616 * @private | 592 * @private |
| 617 * A callback that's called after the viewport changes. | 593 * A callback that's called after the viewport changes. |
| 618 */ | 594 */ |
| 619 viewportChanged_: function() { | 595 viewportChanged_: function() { |
| 620 if (!this.documentDimensions_) | 596 if (!this.documentDimensions_) |
| 621 return; | 597 return; |
| 622 | 598 |
| 623 // Update the buttons selected. | 599 // Update the buttons selected. |
| 624 if (!this.isMaterial_) { | 600 if (!this.isMaterial_) { |
| 625 $('fit-to-page-button').classList.remove('polymer-selected'); | 601 $('fit-to-page-button').classList.remove('polymer-selected'); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 802 * Each bookmark is an Object containing a: | 778 * Each bookmark is an Object containing a: |
| 803 * - title | 779 * - title |
| 804 * - page (optional) | 780 * - page (optional) |
| 805 * - array of children (themselves bookmarks) | 781 * - array of children (themselves bookmarks) |
| 806 * @type {Array} the top-level bookmarks of the PDF. | 782 * @type {Array} the top-level bookmarks of the PDF. |
| 807 */ | 783 */ |
| 808 get bookmarks() { | 784 get bookmarks() { |
| 809 return this.bookmarks_; | 785 return this.bookmarks_; |
| 810 } | 786 } |
| 811 }; | 787 }; |
| OLD | NEW |