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