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 13 matching lines...) Expand all Loading... |
24 * Return the filename component of a URL. | 24 * Return the filename component of a URL. |
25 * @param {string} url The URL to get the filename from. | 25 * @param {string} url The URL to get the filename from. |
26 * @return {string} The filename component. | 26 * @return {string} The filename component. |
27 */ | 27 */ |
28 function getFilenameFromURL(url) { | 28 function getFilenameFromURL(url) { |
29 var components = url.split(/\/|\\/); | 29 var components = url.split(/\/|\\/); |
30 return components[components.length - 1]; | 30 return components[components.length - 1]; |
31 } | 31 } |
32 | 32 |
33 /** | 33 /** |
| 34 * Called when navigation happens in the current tab. |
| 35 * @param {string} url The url to be opened in the current tab. |
| 36 */ |
| 37 function onNavigateInCurrentTab(url) { |
| 38 window.location.href = url; |
| 39 } |
| 40 |
| 41 /** |
| 42 * Called when navigation happens in the new tab. |
| 43 * @param {string} url The url to be opened in the new tab. |
| 44 */ |
| 45 function onNavigateInNewTab(url) { |
| 46 // Prefer the tabs API because it guarantees we can just open a new tab. |
| 47 // window.open doesn't have this guarantee. |
| 48 if (chrome.tabs) |
| 49 chrome.tabs.create({ url: url}); |
| 50 else |
| 51 window.open(url); |
| 52 } |
| 53 |
| 54 /** |
34 * The minimum number of pixels to offset the toolbar by from the bottom and | 55 * The minimum number of pixels to offset the toolbar by from the bottom and |
35 * right side of the screen. | 56 * right side of the screen. |
36 */ | 57 */ |
37 PDFViewer.MIN_TOOLBAR_OFFSET = 15; | 58 PDFViewer.MIN_TOOLBAR_OFFSET = 15; |
38 | 59 |
39 /** | 60 /** |
40 * Creates a new PDFViewer. There should only be one of these objects per | 61 * Creates a new PDFViewer. There should only be one of these objects per |
41 * document. | 62 * document. |
42 * @constructor | 63 * @constructor |
43 * @param {Object} streamDetails The stream object which points to the data | 64 * @param {Object} streamDetails The stream object which points to the data |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // the zoom. onZoomChange() is called before setZoomComplete() callback | 170 // the zoom. onZoomChange() is called before setZoomComplete() callback |
150 // when we initiate the zoom. | 171 // when we initiate the zoom. |
151 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) | 172 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) |
152 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | 173 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); |
153 }.bind(this)); | 174 }.bind(this)); |
154 } | 175 } |
155 | 176 |
156 // Parse open pdf parameters. | 177 // Parse open pdf parameters. |
157 this.paramsParser_ = new OpenPDFParamsParser(); | 178 this.paramsParser_ = new OpenPDFParamsParser(); |
158 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, | 179 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, |
159 this.viewport_, this.paramsParser_); | 180 this.viewport_, this.paramsParser_, onNavigateInCurrentTab, |
| 181 onNavigateInNewTab); |
160 } | 182 } |
161 | 183 |
162 PDFViewer.prototype = { | 184 PDFViewer.prototype = { |
163 /** | 185 /** |
164 * @private | 186 * @private |
165 * Handle key events. These may come from the user directly or via the | 187 * Handle key events. These may come from the user directly or via the |
166 * scripting API. | 188 * scripting API. |
167 * @param {KeyboardEvent} e the event to handle. | 189 * @param {KeyboardEvent} e the event to handle. |
168 */ | 190 */ |
169 handleKeyEvent_: function(e) { | 191 handleKeyEvent_: function(e) { |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 * Each bookmark is an Object containing a: | 716 * Each bookmark is an Object containing a: |
695 * - title | 717 * - title |
696 * - page (optional) | 718 * - page (optional) |
697 * - array of children (themselves bookmarks) | 719 * - array of children (themselves bookmarks) |
698 * @type {Array} the top-level bookmarks of the PDF. | 720 * @type {Array} the top-level bookmarks of the PDF. |
699 */ | 721 */ |
700 get bookmarks() { | 722 get bookmarks() { |
701 return this.bookmarks_; | 723 return this.bookmarks_; |
702 } | 724 } |
703 }; | 725 }; |
OLD | NEW |