| 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 22 matching lines...) Expand all Loading... |
| 33 try { | 33 try { |
| 34 return decodeURIComponent(filename); | 34 return decodeURIComponent(filename); |
| 35 } catch (e) { | 35 } catch (e) { |
| 36 if (e instanceof URIError) | 36 if (e instanceof URIError) |
| 37 return filename; | 37 return filename; |
| 38 throw e; | 38 throw e; |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Called when navigation happens in the current tab. | |
| 44 * @param {boolean} isInTab Indicates if the PDF viewer is displayed in a tab. | |
| 45 * @param {boolean} isSourceFileUrl Indicates if the navigation source is a | |
| 46 * file:// URL. | |
| 47 * @param {string} url The url to be opened in the current tab. | |
| 48 */ | |
| 49 function onNavigateInCurrentTab(isInTab, isSourceFileUrl, url) { | |
| 50 // When the PDFviewer is inside a browser tab, prefer the tabs API because | |
| 51 // it can navigate from one file:// URL to another. | |
| 52 if (chrome.tabs && isInTab && isSourceFileUrl) | |
| 53 chrome.tabs.update({url: url}); | |
| 54 else | |
| 55 window.location.href = url; | |
| 56 } | |
| 57 | |
| 58 /** | |
| 59 * Called when navigation happens in the new tab. | |
| 60 * @param {string} url The url to be opened in the new tab. | |
| 61 * @param {boolean} active Indicates if the new tab should be the active tab. | |
| 62 */ | |
| 63 function onNavigateInNewTab(url, active) { | |
| 64 // Prefer the tabs API because it guarantees we can just open a new tab. | |
| 65 // window.open doesn't have this guarantee. | |
| 66 if (chrome.tabs) | |
| 67 chrome.tabs.create({url: url, active: active}); | |
| 68 else | |
| 69 window.open(url); | |
| 70 } | |
| 71 | |
| 72 /** | |
| 73 * Whether keydown events should currently be ignored. Events are ignored when | 43 * Whether keydown events should currently be ignored. Events are ignored when |
| 74 * an editable element has focus, to allow for proper editing controls. | 44 * an editable element has focus, to allow for proper editing controls. |
| 75 * @param {HTMLElement} activeElement The currently selected DOM node. | 45 * @param {HTMLElement} activeElement The currently selected DOM node. |
| 76 * @return {boolean} True if keydown events should be ignored. | 46 * @return {boolean} True if keydown events should be ignored. |
| 77 */ | 47 */ |
| 78 function shouldIgnoreKeyEvents(activeElement) { | 48 function shouldIgnoreKeyEvents(activeElement) { |
| 79 while (activeElement.shadowRoot != null && | 49 while (activeElement.shadowRoot != null && |
| 80 activeElement.shadowRoot.activeElement != null) { | 50 activeElement.shadowRoot.activeElement != null) { |
| 81 activeElement = activeElement.shadowRoot.activeElement; | 51 activeElement = activeElement.shadowRoot.activeElement; |
| 82 } | 52 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 this.browserApi_.addZoomEventListener( | 223 this.browserApi_.addZoomEventListener( |
| 254 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); | 224 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); |
| 255 | 225 |
| 256 // Setup the keyboard event listener. | 226 // Setup the keyboard event listener. |
| 257 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); | 227 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); |
| 258 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this)); | 228 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this)); |
| 259 document.addEventListener('mouseout', this.handleMouseEvent_.bind(this)); | 229 document.addEventListener('mouseout', this.handleMouseEvent_.bind(this)); |
| 260 | 230 |
| 261 var isInTab = this.browserApi_.getStreamInfo().tabId != -1; | 231 var isInTab = this.browserApi_.getStreamInfo().tabId != -1; |
| 262 var isSourceFileUrl = this.originalUrl_.indexOf('file://') == 0; | 232 var isSourceFileUrl = this.originalUrl_.indexOf('file://') == 0; |
| 263 this.navigator_ = new Navigator(this.originalUrl_, | 233 this.navigator_ = new Navigator( |
| 264 this.viewport_, this.paramsParser_, | 234 this.originalUrl_, this.viewport_, this.paramsParser_, |
| 265 onNavigateInCurrentTab.bind(undefined, | 235 new NavigatorDelegate(isInTab, isSourceFileUrl)); |
| 266 isInTab, | |
| 267 isSourceFileUrl), | |
| 268 onNavigateInNewTab); | |
| 269 this.viewportScroller_ = | 236 this.viewportScroller_ = |
| 270 new ViewportScroller(this.viewport_, this.plugin_, window); | 237 new ViewportScroller(this.viewport_, this.plugin_, window); |
| 271 | 238 |
| 272 // Request translated strings. | 239 // Request translated strings. |
| 273 chrome.resourcesPrivate.getStrings('pdf', this.handleStrings_.bind(this)); | 240 chrome.resourcesPrivate.getStrings('pdf', this.handleStrings_.bind(this)); |
| 274 } | 241 } |
| 275 | 242 |
| 276 PDFViewer.prototype = { | 243 PDFViewer.prototype = { |
| 277 /** | 244 /** |
| 278 * @private | 245 * @private |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 * Each bookmark is an Object containing a: | 855 * Each bookmark is an Object containing a: |
| 889 * - title | 856 * - title |
| 890 * - page (optional) | 857 * - page (optional) |
| 891 * - array of children (themselves bookmarks) | 858 * - array of children (themselves bookmarks) |
| 892 * @type {Array} the top-level bookmarks of the PDF. | 859 * @type {Array} the top-level bookmarks of the PDF. |
| 893 */ | 860 */ |
| 894 get bookmarks() { | 861 get bookmarks() { |
| 895 return this.bookmarks_; | 862 return this.bookmarks_; |
| 896 } | 863 } |
| 897 }; | 864 }; |
| OLD | NEW |