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

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

Issue 2358553002: PDF: Use KeyboardEvent.code instead of keyCode.
Patch Set: Created 4 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
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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { 277 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
278 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1); 278 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
279 // Since we do the movement of the page. 279 // Since we do the movement of the page.
280 e.preventDefault(); 280 e.preventDefault();
281 } else if (fromScriptingAPI) { 281 } else if (fromScriptingAPI) {
282 position.y += this.viewport.size.height; 282 position.y += this.viewport.size.height;
283 this.viewport.position = position; 283 this.viewport.position = position;
284 } 284 }
285 }.bind(this); 285 }.bind(this);
286 286
287 switch (e.keyCode) { 287 switch (e.code) {
288 case 9: // Tab key. 288 case 'Tab':
289 this.toolbarManager_.showToolbarsForKeyboardNavigation(); 289 this.toolbarManager_.showToolbarsForKeyboardNavigation();
290 return; 290 return;
291 case 27: // Escape key. 291 case 'Escape':
292 if (!this.isPrintPreview_) { 292 if (!this.isPrintPreview_) {
293 this.toolbarManager_.hideSingleToolbarLayer(); 293 this.toolbarManager_.hideSingleToolbarLayer();
294 return; 294 return;
295 } 295 }
296 break; // Ensure escape falls through to the print-preview handler. 296 break; // Ensure escape falls through to the print-preview handler.
297 case 32: // Space key. 297 case 'Space':
298 if (e.shiftKey) 298 if (e.shiftKey)
299 pageUpHandler(); 299 pageUpHandler();
300 else 300 else
301 pageDownHandler(); 301 pageDownHandler();
302 return; 302 return;
303 case 33: // Page up key. 303 case 'PageUp':
304 pageUpHandler(); 304 pageUpHandler();
305 return; 305 return;
306 case 34: // Page down key. 306 case 'PageDown':
307 pageDownHandler(); 307 pageDownHandler();
308 return; 308 return;
309 case 37: // Left arrow key. 309 case 'ArrowLeft':
310 if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) { 310 if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) {
311 // Go to the previous page if there are no horizontal scrollbars and 311 // Go to the previous page if there are no horizontal scrollbars and
312 // no form field is focused. 312 // no form field is focused.
313 if (!(this.viewport_.documentHasScrollbars().horizontal || 313 if (!(this.viewport_.documentHasScrollbars().horizontal ||
314 this.isFormFieldFocused_)) { 314 this.isFormFieldFocused_)) {
315 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); 315 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
316 // Since we do the movement of the page. 316 // Since we do the movement of the page.
317 e.preventDefault(); 317 e.preventDefault();
318 } else if (fromScriptingAPI) { 318 } else if (fromScriptingAPI) {
319 position.x -= Viewport.SCROLL_INCREMENT; 319 position.x -= Viewport.SCROLL_INCREMENT;
320 this.viewport.position = position; 320 this.viewport.position = position;
321 } 321 }
322 } 322 }
323 return; 323 return;
324 case 38: // Up arrow key. 324 case 'ArrowUp':
325 if (fromScriptingAPI) { 325 if (fromScriptingAPI) {
326 position.y -= Viewport.SCROLL_INCREMENT; 326 position.y -= Viewport.SCROLL_INCREMENT;
327 this.viewport.position = position; 327 this.viewport.position = position;
328 } 328 }
329 return; 329 return;
330 case 39: // Right arrow key. 330 case 'ArrowRight':
331 if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) { 331 if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) {
332 // Go to the next page if there are no horizontal scrollbars and no 332 // Go to the next page if there are no horizontal scrollbars and no
333 // form field is focused. 333 // form field is focused.
334 if (!(this.viewport_.documentHasScrollbars().horizontal || 334 if (!(this.viewport_.documentHasScrollbars().horizontal ||
335 this.isFormFieldFocused_)) { 335 this.isFormFieldFocused_)) {
336 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1); 336 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
337 // Since we do the movement of the page. 337 // Since we do the movement of the page.
338 e.preventDefault(); 338 e.preventDefault();
339 } else if (fromScriptingAPI) { 339 } else if (fromScriptingAPI) {
340 position.x += Viewport.SCROLL_INCREMENT; 340 position.x += Viewport.SCROLL_INCREMENT;
341 this.viewport.position = position; 341 this.viewport.position = position;
342 } 342 }
343 } 343 }
344 return; 344 return;
345 case 40: // Down arrow key. 345 case 'ArrowDown':
346 if (fromScriptingAPI) { 346 if (fromScriptingAPI) {
347 position.y += Viewport.SCROLL_INCREMENT; 347 position.y += Viewport.SCROLL_INCREMENT;
348 this.viewport.position = position; 348 this.viewport.position = position;
349 } 349 }
350 return; 350 return;
351 case 65: // 'a' key. 351 case 'KeyA':
352 if (e.ctrlKey || e.metaKey) { 352 if (e.ctrlKey || e.metaKey) {
353 this.plugin_.postMessage({ 353 this.plugin_.postMessage({
354 type: 'selectAll' 354 type: 'selectAll'
355 }); 355 });
356 // Since we do selection ourselves. 356 // Since we do selection ourselves.
357 e.preventDefault(); 357 e.preventDefault();
358 } 358 }
359 return; 359 return;
360 case 71: // 'g' key. 360 case 'KeyG':
361 if (this.toolbar_ && (e.ctrlKey || e.metaKey) && e.altKey) { 361 if (this.toolbar_ && (e.ctrlKey || e.metaKey) && e.altKey) {
362 this.toolbarManager_.showToolbars(); 362 this.toolbarManager_.showToolbars();
363 this.toolbar_.selectPageNumber(); 363 this.toolbar_.selectPageNumber();
364 } 364 }
365 return; 365 return;
366 case 219: // Left bracket key. 366 case 'BracketLeft':
367 if (e.ctrlKey) 367 if (e.ctrlKey)
368 this.rotateCounterClockwise_(); 368 this.rotateCounterClockwise_();
369 return; 369 return;
370 case 220: // Backslash key. 370 case 'Backslash':
371 if (e.ctrlKey) 371 if (e.ctrlKey)
372 this.zoomToolbar_.fitToggleFromHotKey(); 372 this.zoomToolbar_.fitToggleFromHotKey();
373 return; 373 return;
374 case 221: // Right bracket key. 374 case 'BracketRight':
375 if (e.ctrlKey) 375 if (e.ctrlKey)
376 this.rotateClockwise_(); 376 this.rotateClockwise_();
377 return; 377 return;
378 } 378 }
379 379
380 // Give print preview a chance to handle the key event. 380 // Give print preview a chance to handle the key event.
381 if (!fromScriptingAPI && this.isPrintPreview_) { 381 if (!fromScriptingAPI && this.isPrintPreview_) {
382 this.sendScriptingMessage_({ 382 this.sendScriptingMessage_({
383 type: 'sendKeyEvent', 383 type: 'sendKeyEvent',
384 keyEvent: SerializeKeyEvent(e) 384 keyEvent: SerializeKeyEvent(e)
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 * Each bookmark is an Object containing a: 859 * Each bookmark is an Object containing a:
860 * - title 860 * - title
861 * - page (optional) 861 * - page (optional)
862 * - array of children (themselves bookmarks) 862 * - array of children (themselves bookmarks)
863 * @type {Array} the top-level bookmarks of the PDF. 863 * @type {Array} the top-level bookmarks of the PDF.
864 */ 864 */
865 get bookmarks() { 865 get bookmarks() {
866 return this.bookmarks_; 866 return this.bookmarks_;
867 } 867 }
868 }; 868 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698