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

Side by Side Diff: chrome/browser/resources/chromeos/keyboard/keyboard_utils.js

Issue 2944703004: Run clang-format on .js files in c/b/r/chromeos (Closed)
Patch Set: Created 3 years, 6 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 /** 5 /**
6 * Namespace for keyboard utility functions. 6 * Namespace for keyboard utility functions.
7 */ 7 */
8 var keyboard = {}; 8 var keyboard = {};
9 9
10 /** 10 /**
(...skipping 10 matching lines...) Expand all
21 */ 21 */
22 var keyboardHostOrigin; 22 var keyboardHostOrigin;
23 23
24 /** 24 /**
25 * Handles the initial messaging posted from webview, where this script is 25 * Handles the initial messaging posted from webview, where this script is
26 * injected. 26 * injected.
27 * @param {Event} event Message event posted from webview. 27 * @param {Event} event Message event posted from webview.
28 * @private 28 * @private
29 */ 29 */
30 keyboard.onInitMessage_ = function(event) { 30 keyboard.onInitMessage_ = function(event) {
31 if (event.data == 'initialMessage' && 31 if (event.data == 'initialMessage' && event.origin == 'chrome://oobe') {
32 event.origin == 'chrome://oobe') {
33 keyboardHostWindow = event.source; 32 keyboardHostWindow = event.source;
34 keyboardHostOrigin = event.origin; 33 keyboardHostOrigin = event.origin;
35 } 34 }
36 }; 35 };
37 36
38 /** 37 /**
39 * Handles the actual focus advancing by raising tab/shift-tab key events 38 * Handles the actual focus advancing by raising tab/shift-tab key events
40 * on C++ side. 39 * on C++ side.
41 * @param {boolean} reverse true if focus is moving backward, otherwise forward. 40 * @param {boolean} reverse true if focus is moving backward, otherwise forward.
42 */ 41 */
43 keyboard.onAdvanceFocus = function(reverse) { 42 keyboard.onAdvanceFocus = function(reverse) {
44 chrome.send('raiseTabKeyEvent', [reverse]); 43 chrome.send('raiseTabKeyEvent', [reverse]);
45 }; 44 };
46 45
47 /** 46 /**
48 * Swallows keypress and keyup events of arrow keys. 47 * Swallows keypress and keyup events of arrow keys.
49 * @param {!Event} event Raised event. 48 * @param {!Event} event Raised event.
50 * @private 49 * @private
51 */ 50 */
52 keyboard.onKeyIgnore_ = function(event) { 51 keyboard.onKeyIgnore_ = function(event) {
53 event = /** @type {!KeyboardEvent} */(event); 52 event = /** @type {!KeyboardEvent} */ (event);
54 53
55 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) 54 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey)
56 return; 55 return;
57 56
58 if (event.key == 'ArrowLeft' || 57 if (event.key == 'ArrowLeft' || event.key == 'ArrowRight' ||
59 event.key == 'ArrowRight' || 58 event.key == 'ArrowUp' || event.key == 'ArrowDown') {
60 event.key == 'ArrowUp' ||
61 event.key == 'ArrowDown') {
62 event.stopPropagation(); 59 event.stopPropagation();
63 event.preventDefault(); 60 event.preventDefault();
64 } 61 }
65 }; 62 };
66 63
67 /** 64 /**
68 * Handles arrow key events, depending on if self is a content script. 65 * Handles arrow key events, depending on if self is a content script.
69 * @param {!Event} event Raised event. 66 * @param {!Event} event Raised event.
70 * @private 67 * @private
71 */ 68 */
72 keyboard.onKeyDown_ = function(event) { 69 keyboard.onKeyDown_ = function(event) {
73 event = /** @type {!KeyboardEvent} */(event); 70 event = /** @type {!KeyboardEvent} */ (event);
74 71
75 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) 72 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey)
76 return; 73 return;
77 74
78 // This file also gets embedded inside of the CfM/hotrod enrollment webview. 75 // This file also gets embedded inside of the CfM/hotrod enrollment webview.
79 // Events will bubble down into the webview, which means that the event 76 // Events will bubble down into the webview, which means that the event
80 // handler from the webui will steal the events meant for the webview. So we 77 // handler from the webui will steal the events meant for the webview. So we
81 // have to disable the webui handler if the active element is the webview. 78 // have to disable the webui handler if the active element is the webview.
82 // 79 //
83 // $ is defined differently depending on how this file gets executed; we have 80 // $ is defined differently depending on how this file gets executed; we have
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (event.key == 'ArrowLeft' || event.key == 'ArrowUp' || 120 if (event.key == 'ArrowLeft' || event.key == 'ArrowUp' ||
124 event.key == 'ArrowRight' || event.key == 'ArrowDown') 121 event.key == 'ArrowRight' || event.key == 'ArrowDown')
125 event.stopPropagation(); 122 event.stopPropagation();
126 }; 123 };
127 124
128 /** 125 /**
129 * Initializes event handling for arrow keys driven focus flow. 126 * Initializes event handling for arrow keys driven focus flow.
130 * @param {boolean} injected true if script runs as an injected content script. 127 * @param {boolean} injected true if script runs as an injected content script.
131 */ 128 */
132 keyboard.initializeKeyboardFlow = function(injected) { 129 keyboard.initializeKeyboardFlow = function(injected) {
133 document.addEventListener('keydown', 130 document.addEventListener('keydown', keyboard.onKeyDown_, true);
134 keyboard.onKeyDown_, true); 131 document.addEventListener('keypress', keyboard.onKeyIgnore_, true);
135 document.addEventListener('keypress', 132 document.addEventListener('keyup', keyboard.onKeyIgnore_, true);
136 keyboard.onKeyIgnore_, true);
137 document.addEventListener('keyup',
138 keyboard.onKeyIgnore_, true);
139 if (injected) 133 if (injected)
140 window.addEventListener('message', keyboard.onInitMessage_); 134 window.addEventListener('message', keyboard.onInitMessage_);
141 }; 135 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/first_run/step.js ('k') | chrome/browser/resources/chromeos/keyboard_overlay.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698