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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/KeyboardShortcuts.java

Issue 1276703003: Handle UI operations through gamepad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 package org.chromium.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import android.view.KeyEvent; 7 import android.view.KeyEvent;
8 8
9 import org.chromium.base.annotations.SuppressFBWarnings; 9 import org.chromium.base.annotations.SuppressFBWarnings;
10 import org.chromium.chrome.R; 10 import org.chromium.chrome.R;
(...skipping 16 matching lines...) Expand all
27 private static final int SHIFT = 1 << 29; 27 private static final int SHIFT = 1 << 29;
28 28
29 private KeyboardShortcuts() {} 29 private KeyboardShortcuts() {}
30 30
31 private static int getMetaState(KeyEvent event) { 31 private static int getMetaState(KeyEvent event) {
32 return (event.isCtrlPressed() ? CTRL : 0) 32 return (event.isCtrlPressed() ? CTRL : 0)
33 | (event.isAltPressed() ? ALT : 0) 33 | (event.isAltPressed() ? ALT : 0)
34 | (event.isShiftPressed() ? SHIFT : 0); 34 | (event.isShiftPressed() ? SHIFT : 0);
35 } 35 }
36 36
37 private static boolean isGamepadAPIActive(KeyEvent event, ChromeActivity act ivity) {
jdduke (slow) 2015/08/07 18:19:30 I don't think we need the KeyEvent arg here, do we
38 if (activity.getCurrentContentViewCore() != null) {
39 return activity.getCurrentContentViewCore().isGamepadAccessed();
40 }
41 return false;
42 }
43
37 /** 44 /**
38 * This should be called from the Activity's dispatchKeyEvent() to handle ke yboard shortcuts. 45 * This should be called from the Activity's dispatchKeyEvent() to handle ke yboard shortcuts.
39 * 46 *
40 * Note: dispatchKeyEvent() is called before the active view or web page get s a chance to handle 47 * Note: dispatchKeyEvent() is called before the active view or web page get s a chance to handle
41 * the key event. So the keys handled here cannot be overridden by any view or web page. 48 * the key event. So the keys handled here cannot be overridden by any view or web page.
42 * 49 *
43 * @param event The KeyEvent to handle. 50 * @param event The KeyEvent to handle.
44 * @param activity The ChromeActivity in which the key was pressed. 51 * @param activity The ChromeActivity in which the key was pressed.
45 * @param uiInitialized Whether the UI has been initialized. If this is fals e, most keys will 52 * @param uiInitialized Whether the UI has been initialized. If this is fals e, most keys will
46 * not be handled. 53 * not be handled.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 * Ctrl+Tab, Ctrl+3). 108 * Ctrl+Tab, Ctrl+3).
102 * @return Whether the key event was handled. 109 * @return Whether the key event was handled.
103 */ 110 */
104 public static boolean onKeyDown(KeyEvent event, ChromeActivity activity, 111 public static boolean onKeyDown(KeyEvent event, ChromeActivity activity,
105 boolean isCurrentTabVisible, boolean tabSwitchingEnabled) { 112 boolean isCurrentTabVisible, boolean tabSwitchingEnabled) {
106 int keyCode = event.getKeyCode(); 113 int keyCode = event.getKeyCode();
107 if (event.getRepeatCount() != 0 || KeyEvent.isModifierKey(keyCode)) retu rn false; 114 if (event.getRepeatCount() != 0 || KeyEvent.isModifierKey(keyCode)) retu rn false;
108 if (!event.isCtrlPressed() && !event.isAltPressed() 115 if (!event.isCtrlPressed() && !event.isAltPressed()
109 && keyCode != KeyEvent.KEYCODE_F3 116 && keyCode != KeyEvent.KEYCODE_F3
110 && keyCode != KeyEvent.KEYCODE_F5 117 && keyCode != KeyEvent.KEYCODE_F5
111 && keyCode != KeyEvent.KEYCODE_FORWARD) { 118 && keyCode != KeyEvent.KEYCODE_FORWARD
119 && !(KeyEvent.isGamepadButton(keyCode) && !isGamepadAPIActive(ev ent, activity))) {
jdduke (slow) 2015/08/07 18:19:30 This big if statement is getting pretty meaty, hmm
112 return false; 120 return false;
113 } 121 }
114 122
115 TabModel curModel = activity.getCurrentTabModel(); 123 TabModel curModel = activity.getCurrentTabModel();
116 int count = curModel.getCount(); 124 int count = curModel.getCount();
117 125
118 int metaState = getMetaState(event); 126 int metaState = getMetaState(event);
119 int keyCodeAndMeta = keyCode | metaState; 127 int keyCodeAndMeta = keyCode | metaState;
120 128
121 switch (keyCodeAndMeta) { 129 switch (keyCodeAndMeta) {
(...skipping 17 matching lines...) Expand all
139 if (currentTab != null && isCurrentTabVisible) { 147 if (currentTab != null && isCurrentTabVisible) {
140 currentTab.loadUrl(new LoadUrlParams(url, PageTransition.AUT O_BOOKMARK)); 148 currentTab.loadUrl(new LoadUrlParams(url, PageTransition.AUT O_BOOKMARK));
141 } else { 149 } else {
142 TabCreator tabCreator = activity.getCurrentTabCreator(); 150 TabCreator tabCreator = activity.getCurrentTabCreator();
143 if (tabCreator != null) { 151 if (tabCreator != null) {
144 tabCreator.launchUrl(url, TabLaunchType.FROM_KEYBOARD); 152 tabCreator.launchUrl(url, TabLaunchType.FROM_KEYBOARD);
145 } 153 }
146 } 154 }
147 return true; 155 return true;
148 case ALT | KeyEvent.KEYCODE_F: 156 case ALT | KeyEvent.KEYCODE_F:
157 case KeyEvent.KEYCODE_BUTTON_Y:
149 activity.onMenuOrKeyboardAction(R.id.show_menu, false); 158 activity.onMenuOrKeyboardAction(R.id.show_menu, false);
150 return true; 159 return true;
151 } 160 }
152 161
153 if (isCurrentTabVisible) { 162 if (isCurrentTabVisible) {
154 if (tabSwitchingEnabled && (metaState == CTRL || metaState == ALT)) { 163 if (tabSwitchingEnabled && (metaState == CTRL || metaState == ALT)) {
155 int numCode = keyCode - KeyEvent.KEYCODE_0; 164 int numCode = keyCode - KeyEvent.KEYCODE_0;
156 if (numCode > 0 && numCode <= Math.min(count, 8)) { 165 if (numCode > 0 && numCode <= Math.min(count, 8)) {
157 // Ctrl+1 to Ctrl+8: select tab by index 166 // Ctrl+1 to Ctrl+8: select tab by index
158 TabModelUtils.setIndex(curModel, numCode - 1); 167 TabModelUtils.setIndex(curModel, numCode - 1);
159 return true; 168 return true;
160 } else if (numCode == 9 && count != 0) { 169 } else if (numCode == 9 && count != 0) {
161 // Ctrl+9: select last tab 170 // Ctrl+9: select last tab
162 TabModelUtils.setIndex(curModel, count - 1); 171 TabModelUtils.setIndex(curModel, count - 1);
163 return true; 172 return true;
164 } 173 }
165 } 174 }
166 175
167 switch (keyCodeAndMeta) { 176 switch (keyCodeAndMeta) {
168 case CTRL | KeyEvent.KEYCODE_TAB: 177 case CTRL | KeyEvent.KEYCODE_TAB:
169 case CTRL | KeyEvent.KEYCODE_PAGE_DOWN: 178 case CTRL | KeyEvent.KEYCODE_PAGE_DOWN:
179 case KeyEvent.KEYCODE_BUTTON_R1:
170 if (tabSwitchingEnabled && count > 1) { 180 if (tabSwitchingEnabled && count > 1) {
171 TabModelUtils.setIndex(curModel, (curModel.index() + 1) % count); 181 TabModelUtils.setIndex(curModel, (curModel.index() + 1) % count);
172 } 182 }
173 return true; 183 return true;
174 case CTRL | SHIFT | KeyEvent.KEYCODE_TAB: 184 case CTRL | SHIFT | KeyEvent.KEYCODE_TAB:
175 case CTRL | KeyEvent.KEYCODE_PAGE_UP: 185 case CTRL | KeyEvent.KEYCODE_PAGE_UP:
186 case KeyEvent.KEYCODE_BUTTON_L1:
176 if (tabSwitchingEnabled && count > 1) { 187 if (tabSwitchingEnabled && count > 1) {
177 TabModelUtils.setIndex(curModel, (curModel.index() + cou nt - 1) % count); 188 TabModelUtils.setIndex(curModel, (curModel.index() + cou nt - 1) % count);
178 } 189 }
179 return true; 190 return true;
180 case CTRL | KeyEvent.KEYCODE_W: 191 case CTRL | KeyEvent.KEYCODE_W:
181 case CTRL | KeyEvent.KEYCODE_F4: 192 case CTRL | KeyEvent.KEYCODE_F4:
193 case KeyEvent.KEYCODE_BUTTON_B:
182 TabModelUtils.closeCurrentTab(curModel); 194 TabModelUtils.closeCurrentTab(curModel);
183 return true; 195 return true;
184 case CTRL | KeyEvent.KEYCODE_F: 196 case CTRL | KeyEvent.KEYCODE_F:
185 case CTRL | KeyEvent.KEYCODE_G: 197 case CTRL | KeyEvent.KEYCODE_G:
186 case CTRL | SHIFT | KeyEvent.KEYCODE_G: 198 case CTRL | SHIFT | KeyEvent.KEYCODE_G:
187 case KeyEvent.KEYCODE_F3: 199 case KeyEvent.KEYCODE_F3:
188 case SHIFT | KeyEvent.KEYCODE_F3: 200 case SHIFT | KeyEvent.KEYCODE_F3:
189 activity.onMenuOrKeyboardAction(R.id.find_in_page_id, false) ; 201 activity.onMenuOrKeyboardAction(R.id.find_in_page_id, false) ;
190 return true; 202 return true;
191 case CTRL | KeyEvent.KEYCODE_L: 203 case CTRL | KeyEvent.KEYCODE_L:
192 case ALT | KeyEvent.KEYCODE_D: 204 case ALT | KeyEvent.KEYCODE_D:
205 case KeyEvent.KEYCODE_BUTTON_X:
193 activity.onMenuOrKeyboardAction(R.id.focus_url_bar, false); 206 activity.onMenuOrKeyboardAction(R.id.focus_url_bar, false);
194 return true; 207 return true;
195 case KeyEvent.KEYCODE_BOOKMARK: 208 case KeyEvent.KEYCODE_BOOKMARK:
196 case CTRL | KeyEvent.KEYCODE_D: 209 case CTRL | KeyEvent.KEYCODE_D:
197 activity.onMenuOrKeyboardAction(R.id.bookmark_this_page_id, false); 210 activity.onMenuOrKeyboardAction(R.id.bookmark_this_page_id, false);
198 return true; 211 return true;
199 case CTRL | KeyEvent.KEYCODE_P: 212 case CTRL | KeyEvent.KEYCODE_P:
200 activity.onMenuOrKeyboardAction(R.id.print_id, false); 213 activity.onMenuOrKeyboardAction(R.id.print_id, false);
201 return true; 214 return true;
202 case CTRL | KeyEvent.KEYCODE_PLUS: 215 case CTRL | KeyEvent.KEYCODE_PLUS:
(...skipping 17 matching lines...) Expand all
220 case KeyEvent.KEYCODE_F5: 233 case KeyEvent.KEYCODE_F5:
221 Tab tab = activity.getActivityTab(); 234 Tab tab = activity.getActivityTab();
222 if (tab != null) tab.reload(); 235 if (tab != null) tab.reload();
223 return true; 236 return true;
224 case ALT | KeyEvent.KEYCODE_DPAD_LEFT: 237 case ALT | KeyEvent.KEYCODE_DPAD_LEFT:
225 tab = activity.getActivityTab(); 238 tab = activity.getActivityTab();
226 if (tab != null && tab.canGoBack()) tab.goBack(); 239 if (tab != null && tab.canGoBack()) tab.goBack();
227 return true; 240 return true;
228 case ALT | KeyEvent.KEYCODE_DPAD_RIGHT: 241 case ALT | KeyEvent.KEYCODE_DPAD_RIGHT:
229 case KeyEvent.KEYCODE_FORWARD: 242 case KeyEvent.KEYCODE_FORWARD:
243 case KeyEvent.KEYCODE_BUTTON_START:
230 tab = activity.getActivityTab(); 244 tab = activity.getActivityTab();
231 if (tab != null && tab.canGoForward()) tab.goForward(); 245 if (tab != null && tab.canGoForward()) tab.goForward();
232 return true; 246 return true;
233 case CTRL | SHIFT | KeyEvent.KEYCODE_SLASH: // i.e. Ctrl+? 247 case CTRL | SHIFT | KeyEvent.KEYCODE_SLASH: // i.e. Ctrl+?
234 activity.onMenuOrKeyboardAction(R.id.help_id, false); 248 activity.onMenuOrKeyboardAction(R.id.help_id, false);
235 return true; 249 return true;
236 } 250 }
237 } 251 }
238 252
239 return false; 253 return false;
240 } 254 }
241 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698