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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/toolbar/KeyboardNavigationListener.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.toolbar;
6
7 import android.view.KeyEvent;
8 import android.view.View;
9 import android.view.View.OnKeyListener;
10
11 /**
12 * This is an abstract class to override keyboard navigation behavior for views.
13 */
14 abstract class KeyboardNavigationListener implements OnKeyListener {
15
16 public KeyboardNavigationListener() {
17 super();
18 }
19
20 @Override
21 public boolean onKey(View v, int keyCode, KeyEvent event) {
22 if (keyCode == KeyEvent.KEYCODE_TAB && event.getAction() == KeyEvent.ACT ION_DOWN) {
23 if (event.hasNoModifiers()) {
24 View forward = getNextFocusForward();
25 if (forward != null) return forward.requestFocus();
26 } else if (event.isShiftPressed()) {
27 View backward = getNextFocusBackward();
28 if (backward != null) return backward.requestFocus();
29 }
30 } else if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == Key Event.ACTION_UP) {
31 return handleEnterKeyPress();
32 }
33 return false;
34 }
35
36 /**
37 * Get the view to be focused on a TAB click. If you return null, the defaul t key event
38 * processing will occur instead of attempting to focus.
39 * @return The view to gain focus.
40 */
41 public View getNextFocusForward() {
42 return null;
43 }
44
45 /**
46 * Get the view to be focused on a Shift + TAB click. If you return null, th e default key event
47 * processing will occur instead of attempting to focus.
48 * @return The view to gain focus.
49 */
50 public View getNextFocusBackward() {
51 return null;
52 }
53
54 /**
55 * Allows the extending class to special case the enter key press handling.
56 * @return Whether the enter key was handled
57 */
58 protected boolean handleEnterKeyPress() {
59 return false;
60 }
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698