Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(793)

Side by Side Diff: chrome/browser/resources/pdf/pdf.js

Issue 1359613002: PDF: Prevent left/right arrow shortcuts when a PDF text field is focused. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/pdf/pdf_extension_test.cc ('k') | chrome/test/data/pdf/page_change_test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 * Creates a new PDFViewer. There should only be one of these objects per 108 * Creates a new PDFViewer. There should only be one of these objects per
109 * document. 109 * document.
110 * @constructor 110 * @constructor
111 * @param {!BrowserApi} browserApi An object providing an API to the browser. 111 * @param {!BrowserApi} browserApi An object providing an API to the browser.
112 */ 112 */
113 function PDFViewer(browserApi) { 113 function PDFViewer(browserApi) {
114 this.browserApi_ = browserApi; 114 this.browserApi_ = browserApi;
115 this.loadState_ = LoadState.LOADING; 115 this.loadState_ = LoadState.LOADING;
116 this.parentWindow_ = null; 116 this.parentWindow_ = null;
117 this.parentOrigin_ = null; 117 this.parentOrigin_ = null;
118 this.pluginFormFieldFocus_ = false;
raymes 2015/09/22 04:35:25 nit: maybe just: isFormFieldFocused_
tsergeant 2015/09/22 04:55:28 Done.
118 119
119 this.delayedScriptingMessages_ = []; 120 this.delayedScriptingMessages_ = [];
120 121
121 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf( 122 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf(
122 'chrome://print') == 0; 123 'chrome://print') == 0;
123 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html'; 124 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html';
124 125
125 // The sizer element is placed behind the plugin element to cause scrollbars 126 // The sizer element is placed behind the plugin element to cause scrollbars
126 // to be displayed in the window. It is sized according to the document size 127 // to be displayed in the window. It is sized according to the document size
127 // of the pdf and zoom level. 128 // of the pdf and zoom level.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 pageDownHandler(); 319 pageDownHandler();
319 return; 320 return;
320 case 33: // Page up key. 321 case 33: // Page up key.
321 pageUpHandler(); 322 pageUpHandler();
322 return; 323 return;
323 case 34: // Page down key. 324 case 34: // Page down key.
324 pageDownHandler(); 325 pageDownHandler();
325 return; 326 return;
326 case 37: // Left arrow key. 327 case 37: // Left arrow key.
327 if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) { 328 if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) {
328 // Go to the previous page if there are no horizontal scrollbars. 329 // Go to the previous page if there are no horizontal scrollbars and
329 if (!this.viewport_.documentHasScrollbars().horizontal) { 330 // no form field is focused.
331 if (!(this.viewport_.documentHasScrollbars().horizontal ||
332 this.pluginFormFieldFocus_)) {
330 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); 333 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
331 // Since we do the movement of the page. 334 // Since we do the movement of the page.
332 e.preventDefault(); 335 e.preventDefault();
333 } else if (fromScriptingAPI) { 336 } else if (fromScriptingAPI) {
334 position.x -= Viewport.SCROLL_INCREMENT; 337 position.x -= Viewport.SCROLL_INCREMENT;
335 this.viewport.position = position; 338 this.viewport.position = position;
336 } 339 }
337 } 340 }
338 return; 341 return;
339 case 38: // Up arrow key. 342 case 38: // Up arrow key.
340 if (fromScriptingAPI) { 343 if (fromScriptingAPI) {
341 position.y -= Viewport.SCROLL_INCREMENT; 344 position.y -= Viewport.SCROLL_INCREMENT;
342 this.viewport.position = position; 345 this.viewport.position = position;
343 } 346 }
344 return; 347 return;
345 case 39: // Right arrow key. 348 case 39: // Right arrow key.
346 if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) { 349 if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) {
347 // Go to the next page if there are no horizontal scrollbars. 350 // Go to the next page if there are no horizontal scrollbars and no
348 if (!this.viewport_.documentHasScrollbars().horizontal) { 351 // form field is focused.
352 if (!(this.viewport_.documentHasScrollbars().horizontal ||
353 this.pluginFormFieldFocus_)) {
349 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1); 354 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
350 // Since we do the movement of the page. 355 // Since we do the movement of the page.
351 e.preventDefault(); 356 e.preventDefault();
352 } else if (fromScriptingAPI) { 357 } else if (fromScriptingAPI) {
353 position.x += Viewport.SCROLL_INCREMENT; 358 position.x += Viewport.SCROLL_INCREMENT;
354 this.viewport.position = position; 359 this.viewport.position = position;
355 } 360 }
356 } 361 }
357 return; 362 return;
358 case 40: // Down arrow key. 363 case 40: // Down arrow key.
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 this.materialToolbar_.bookmarks = this.bookmarks; 665 this.materialToolbar_.bookmarks = this.bookmarks;
661 } 666 }
662 break; 667 break;
663 case 'setIsSelecting': 668 case 'setIsSelecting':
664 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); 669 this.viewportScroller_.setEnableScrolling(message.data.isSelecting);
665 break; 670 break;
666 case 'getNamedDestinationReply': 671 case 'getNamedDestinationReply':
667 this.paramsParser_.onNamedDestinationReceived( 672 this.paramsParser_.onNamedDestinationReceived(
668 message.data.pageNumber); 673 message.data.pageNumber);
669 break; 674 break;
675 case 'formFocusChange':
676 this.pluginFormFieldFocus_ = message.data.focused;
677 break;
670 } 678 }
671 }, 679 },
672 680
673 /** 681 /**
674 * @private 682 * @private
675 * A callback that's called before the zoom changes. Notify the plugin to stop 683 * A callback that's called before the zoom changes. Notify the plugin to stop
676 * reacting to scroll events while zoom is taking place to avoid flickering. 684 * reacting to scroll events while zoom is taking place to avoid flickering.
677 */ 685 */
678 beforeZoom_: function() { 686 beforeZoom_: function() {
679 this.plugin_.postMessage({ 687 this.plugin_.postMessage({
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 * Each bookmark is an Object containing a: 911 * Each bookmark is an Object containing a:
904 * - title 912 * - title
905 * - page (optional) 913 * - page (optional)
906 * - array of children (themselves bookmarks) 914 * - array of children (themselves bookmarks)
907 * @type {Array} the top-level bookmarks of the PDF. 915 * @type {Array} the top-level bookmarks of the PDF.
908 */ 916 */
909 get bookmarks() { 917 get bookmarks() {
910 return this.bookmarks_; 918 return this.bookmarks_;
911 } 919 }
912 }; 920 };
OLDNEW
« no previous file with comments | « chrome/browser/pdf/pdf_extension_test.cc ('k') | chrome/test/data/pdf/page_change_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698