| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 function onNavigateInNewTab(url) { | 45 function onNavigateInNewTab(url) { |
| 46 // Prefer the tabs API because it guarantees we can just open a new tab. | 46 // Prefer the tabs API because it guarantees we can just open a new tab. |
| 47 // window.open doesn't have this guarantee. | 47 // window.open doesn't have this guarantee. |
| 48 if (chrome.tabs) | 48 if (chrome.tabs) |
| 49 chrome.tabs.create({ url: url}); | 49 chrome.tabs.create({ url: url}); |
| 50 else | 50 else |
| 51 window.open(url); | 51 window.open(url); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * Whether keydown events should currently be ignored. Events are ignored when |
| 56 * an editable element has focus, to allow for proper editing controls. |
| 57 * @param {HTMLElement} activeElement The currently selected DOM node. |
| 58 * @return {boolean} True if keydown events should be ignored. |
| 59 */ |
| 60 function shouldIgnoreKeyEvents(activeElement) { |
| 61 while (activeElement.shadowRoot != null) |
| 62 activeElement = activeElement.shadowRoot.activeElement; |
| 63 |
| 64 return (activeElement.isContentEditable || |
| 65 activeElement.tagName == 'INPUT' || |
| 66 activeElement.tagName == 'TEXTAREA'); |
| 67 } |
| 68 |
| 69 /** |
| 55 * The minimum number of pixels to offset the toolbar by from the bottom and | 70 * The minimum number of pixels to offset the toolbar by from the bottom and |
| 56 * right side of the screen. | 71 * right side of the screen. |
| 57 */ | 72 */ |
| 58 PDFViewer.MIN_TOOLBAR_OFFSET = 15; | 73 PDFViewer.MIN_TOOLBAR_OFFSET = 15; |
| 59 | 74 |
| 60 /** | 75 /** |
| 61 * Creates a new PDFViewer. There should only be one of these objects per | 76 * Creates a new PDFViewer. There should only be one of these objects per |
| 62 * document. | 77 * document. |
| 63 * @constructor | 78 * @constructor |
| 64 * @param {!BrowserApi} browserApi An object providing an API to the browser. | 79 * @param {!BrowserApi} browserApi An object providing an API to the browser. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 * @private | 214 * @private |
| 200 * Handle key events. These may come from the user directly or via the | 215 * Handle key events. These may come from the user directly or via the |
| 201 * scripting API. | 216 * scripting API. |
| 202 * @param {KeyboardEvent} e the event to handle. | 217 * @param {KeyboardEvent} e the event to handle. |
| 203 */ | 218 */ |
| 204 handleKeyEvent_: function(e) { | 219 handleKeyEvent_: function(e) { |
| 205 var position = this.viewport_.position; | 220 var position = this.viewport_.position; |
| 206 // Certain scroll events may be sent from outside of the extension. | 221 // Certain scroll events may be sent from outside of the extension. |
| 207 var fromScriptingAPI = e.fromScriptingAPI; | 222 var fromScriptingAPI = e.fromScriptingAPI; |
| 208 | 223 |
| 224 if (shouldIgnoreKeyEvents(document.activeElement) || e.defaultPrevented) |
| 225 return; |
| 226 |
| 209 var pageUpHandler = function() { | 227 var pageUpHandler = function() { |
| 210 // Go to the previous page if we are fit-to-page. | 228 // Go to the previous page if we are fit-to-page. |
| 211 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { | 229 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { |
| 212 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); | 230 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); |
| 213 // Since we do the movement of the page. | 231 // Since we do the movement of the page. |
| 214 e.preventDefault(); | 232 e.preventDefault(); |
| 215 } else if (fromScriptingAPI) { | 233 } else if (fromScriptingAPI) { |
| 216 position.y -= this.viewport.size.height; | 234 position.y -= this.viewport.size.height; |
| 217 this.viewport.position = position; | 235 this.viewport.position = position; |
| 218 } | 236 } |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 // Hide the toolbar if it doesn't fit in the viewport. | 634 // Hide the toolbar if it doesn't fit in the viewport. |
| 617 if (this.toolbar_.offsetLeft < 0 || this.toolbar_.offsetTop < 0) | 635 if (this.toolbar_.offsetLeft < 0 || this.toolbar_.offsetTop < 0) |
| 618 this.toolbar_.style.visibility = 'hidden'; | 636 this.toolbar_.style.visibility = 'hidden'; |
| 619 else | 637 else |
| 620 this.toolbar_.style.visibility = 'visible'; | 638 this.toolbar_.style.visibility = 'visible'; |
| 621 } | 639 } |
| 622 | 640 |
| 623 // Update the page indicator. | 641 // Update the page indicator. |
| 624 var visiblePage = this.viewport_.getMostVisiblePage(); | 642 var visiblePage = this.viewport_.getMostVisiblePage(); |
| 625 if (this.isMaterial_) { | 643 if (this.isMaterial_) { |
| 626 this.materialToolbar_.pageIndex = visiblePage; | 644 this.materialToolbar_.pageNo = visiblePage + 1; |
| 627 } else { | 645 } else { |
| 628 this.pageIndicator_.index = visiblePage; | 646 this.pageIndicator_.index = visiblePage; |
| 629 if (this.documentDimensions_.pageDimensions.length > 1 && | 647 if (this.documentDimensions_.pageDimensions.length > 1 && |
| 630 hasScrollbars.vertical) { | 648 hasScrollbars.vertical) { |
| 631 this.pageIndicator_.style.visibility = 'visible'; | 649 this.pageIndicator_.style.visibility = 'visible'; |
| 632 } else { | 650 } else { |
| 633 this.pageIndicator_.style.visibility = 'hidden'; | 651 this.pageIndicator_.style.visibility = 'hidden'; |
| 634 } | 652 } |
| 635 } | 653 } |
| 636 | 654 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 * Each bookmark is an Object containing a: | 775 * Each bookmark is an Object containing a: |
| 758 * - title | 776 * - title |
| 759 * - page (optional) | 777 * - page (optional) |
| 760 * - array of children (themselves bookmarks) | 778 * - array of children (themselves bookmarks) |
| 761 * @type {Array} the top-level bookmarks of the PDF. | 779 * @type {Array} the top-level bookmarks of the PDF. |
| 762 */ | 780 */ |
| 763 get bookmarks() { | 781 get bookmarks() { |
| 764 return this.bookmarks_; | 782 return this.bookmarks_; |
| 765 } | 783 } |
| 766 }; | 784 }; |
| OLD | NEW |