| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 PDFViewer.prototype = { | 158 PDFViewer.prototype = { |
| 159 /** | 159 /** |
| 160 * @private | 160 * @private |
| 161 * Handle key events. These may come from the user directly or via the | 161 * Handle key events. These may come from the user directly or via the |
| 162 * scripting API. | 162 * scripting API. |
| 163 * @param {KeyboardEvent} e the event to handle. | 163 * @param {KeyboardEvent} e the event to handle. |
| 164 */ | 164 */ |
| 165 handleKeyEvent_: function(e) { | 165 handleKeyEvent_: function(e) { |
| 166 var position = this.viewport_.position; | 166 var position = this.viewport_.position; |
| 167 // Certain scroll events may be sent from outside of the extension. | 167 // Certain scroll events may be sent from outside of the extension. |
| 168 var fromScriptingAPI = e.type == 'scriptingKeypress'; | 168 var fromScriptingAPI = e.fromScriptingAPI; |
| 169 | 169 |
| 170 var pageUpHandler = function() { | 170 var pageUpHandler = function() { |
| 171 // Go to the previous page if we are fit-to-page. | 171 // Go to the previous page if we are fit-to-page. |
| 172 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { | 172 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { |
| 173 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); | 173 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); |
| 174 // Since we do the movement of the page. | 174 // Since we do the movement of the page. |
| 175 e.preventDefault(); | 175 e.preventDefault(); |
| 176 } else if (fromScriptingAPI) { | 176 } else if (fromScriptingAPI) { |
| 177 position.y -= this.viewport.size.height; | 177 position.y -= this.viewport.size.height; |
| 178 this.viewport.position = position; | 178 this.viewport.position = position; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 263 } |
| 264 return; | 264 return; |
| 265 case 221: // right bracket. | 265 case 221: // right bracket. |
| 266 if (e.ctrlKey) { | 266 if (e.ctrlKey) { |
| 267 this.plugin_.postMessage({ | 267 this.plugin_.postMessage({ |
| 268 type: 'rotateClockwise' | 268 type: 'rotateClockwise' |
| 269 }); | 269 }); |
| 270 } | 270 } |
| 271 return; | 271 return; |
| 272 } | 272 } |
| 273 |
| 274 // Give print preview a chance to handle the key event. |
| 275 if (!fromScriptingAPI && this.isPrintPreview_) { |
| 276 this.sendScriptingMessage_({ |
| 277 type: 'sendKeyEvent', |
| 278 keyEvent: SerializeKeyEvent(e) |
| 279 }); |
| 280 } |
| 273 }, | 281 }, |
| 274 | 282 |
| 275 /** | 283 /** |
| 276 * @private | 284 * @private |
| 277 * Notify the plugin to print. | 285 * Notify the plugin to print. |
| 278 */ | 286 */ |
| 279 print_: function() { | 287 print_: function() { |
| 280 this.plugin_.postMessage({ | 288 this.plugin_.postMessage({ |
| 281 type: 'print' | 289 type: 'print' |
| 282 }); | 290 }); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 type: 'resetPrintPreviewMode', | 638 type: 'resetPrintPreviewMode', |
| 631 url: message.data.url, | 639 url: message.data.url, |
| 632 grayscale: message.data.grayscale, | 640 grayscale: message.data.grayscale, |
| 633 // If the PDF isn't modifiable we send 0 as the page count so that no | 641 // If the PDF isn't modifiable we send 0 as the page count so that no |
| 634 // blank placeholder pages get appended to the PDF. | 642 // blank placeholder pages get appended to the PDF. |
| 635 pageCount: (message.data.modifiable ? | 643 pageCount: (message.data.modifiable ? |
| 636 message.data.pageNumbers.length : 0) | 644 message.data.pageNumbers.length : 0) |
| 637 }); | 645 }); |
| 638 return true; | 646 return true; |
| 639 case 'sendKeyEvent': | 647 case 'sendKeyEvent': |
| 640 var e = document.createEvent('Event'); | 648 this.handleKeyEvent_(DeserializeKeyEvent(message.data.keyEvent)); |
| 641 e.initEvent('scriptingKeypress'); | |
| 642 e.keyCode = message.data.keyCode; | |
| 643 this.handleKeyEvent_(e); | |
| 644 return true; | 649 return true; |
| 645 } | 650 } |
| 646 | 651 |
| 647 return false; | 652 return false; |
| 648 }, | 653 }, |
| 649 | 654 |
| 650 /** | 655 /** |
| 651 * @private | 656 * @private |
| 652 * Send a scripting message outside the extension (typically to | 657 * Send a scripting message outside the extension (typically to |
| 653 * PDFScriptingAPI in a page containing the extension). | 658 * PDFScriptingAPI in a page containing the extension). |
| (...skipping 26 matching lines...) Expand all Loading... |
| 680 * Each bookmark is an Object containing a: | 685 * Each bookmark is an Object containing a: |
| 681 * - title | 686 * - title |
| 682 * - page (optional) | 687 * - page (optional) |
| 683 * - array of children (themselves bookmarks) | 688 * - array of children (themselves bookmarks) |
| 684 * @type {Array} the top-level bookmarks of the PDF. | 689 * @type {Array} the top-level bookmarks of the PDF. |
| 685 */ | 690 */ |
| 686 get bookmarks() { | 691 get bookmarks() { |
| 687 return this.bookmarks_; | 692 return this.bookmarks_; |
| 688 } | 693 } |
| 689 }; | 694 }; |
| OLD | NEW |