Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
| 6 | 6 |
| 7 import android.graphics.Rect; | 7 import android.graphics.Rect; |
| 8 import android.os.Handler; | 8 import android.os.Handler; |
| 9 import android.os.Looper; | 9 import android.os.Looper; |
| 10 import android.os.Message; | 10 import android.os.Message; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 View containerView) { | 31 View containerView) { |
| 32 mContentsClient = contentsClient; | 32 mContentsClient = contentsClient; |
| 33 mContainerView = containerView; | 33 mContainerView = containerView; |
| 34 } | 34 } |
| 35 | 35 |
| 36 @Override | 36 @Override |
| 37 public void onLoadProgressChanged(int progress) { | 37 public void onLoadProgressChanged(int progress) { |
| 38 mContentsClient.onProgressChanged(progress); | 38 mContentsClient.onProgressChanged(progress); |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Converts a KeyEvent into the corresponding View.FOCUS_XXX integer type, i ff the key | |
| 42 // event is a key down action, and is a DPAD_XXX key code. | |
| 43 static int getViewDirectionFromKeyEvent(KeyEvent event) { | |
|
dmazzoni
2013/10/22 06:47:55
Would it be too verbose to say getViewFocusDirecti
joth
2013/10/22 22:02:41
Good suggestion, however in the end I reverted thi
| |
| 44 if (event.getAction() == KeyEvent.ACTION_DOWN) { | |
| 45 switch (event.getKeyCode()) { | |
| 46 case KeyEvent.KEYCODE_DPAD_DOWN: | |
| 47 return View.FOCUS_DOWN; | |
| 48 case KeyEvent.KEYCODE_DPAD_UP: | |
| 49 return View.FOCUS_UP; | |
| 50 case KeyEvent.KEYCODE_DPAD_LEFT: | |
| 51 return View.FOCUS_LEFT; | |
| 52 case KeyEvent.KEYCODE_DPAD_RIGHT: | |
| 53 return View.FOCUS_RIGHT; | |
| 54 } | |
| 55 } | |
| 56 return 0; | |
|
sgurun-gerrit only
2013/10/22 17:18:00
0 is a special number, i.e. View.FOCUSABLES_ALL, b
joth
2013/10/22 22:02:41
FOCUSABLES_ALL is used with addFocusables(), thes
| |
| 57 } | |
| 58 | |
| 41 @Override | 59 @Override |
| 42 public void handleKeyboardEvent(KeyEvent event) { | 60 public void handleKeyboardEvent(KeyEvent event) { |
| 43 if (event.getAction() == KeyEvent.ACTION_DOWN) { | 61 int direction = getViewDirectionFromKeyEvent(event); |
| 44 int direction; | 62 if (direction != 0 && tryToMoveFocus(direction)) return; |
| 45 switch (event.getKeyCode()) { | 63 |
| 46 case KeyEvent.KEYCODE_DPAD_DOWN: | |
| 47 direction = View.FOCUS_DOWN; | |
| 48 break; | |
| 49 case KeyEvent.KEYCODE_DPAD_UP: | |
| 50 direction = View.FOCUS_UP; | |
| 51 break; | |
| 52 case KeyEvent.KEYCODE_DPAD_LEFT: | |
| 53 direction = View.FOCUS_LEFT; | |
| 54 break; | |
| 55 case KeyEvent.KEYCODE_DPAD_RIGHT: | |
| 56 direction = View.FOCUS_RIGHT; | |
| 57 break; | |
| 58 default: | |
| 59 direction = 0; | |
| 60 break; | |
| 61 } | |
| 62 if (direction != 0 && tryToMoveFocus(direction)) return; | |
| 63 } | |
| 64 mContentsClient.onUnhandledKeyEvent(event); | 64 mContentsClient.onUnhandledKeyEvent(event); |
| 65 } | 65 } |
| 66 | 66 |
| 67 @Override | 67 @Override |
| 68 public boolean takeFocus(boolean reverse) { | 68 public boolean takeFocus(boolean reverse) { |
| 69 int direction = | 69 int direction = |
| 70 (reverse == (mContainerView.getLayoutDirection() == View.LAYOUT_DIRE CTION_RTL)) ? | 70 (reverse == (mContainerView.getLayoutDirection() == View.LAYOUT_DIRE CTION_RTL)) ? |
| 71 View.FOCUS_RIGHT : View.FOCUS_LEFT; | 71 View.FOCUS_RIGHT : View.FOCUS_LEFT; |
| 72 if (tryToMoveFocus(direction)) return true; | 72 if (tryToMoveFocus(direction)) return true; |
| 73 direction = reverse ? View.FOCUS_UP : View.FOCUS_DOWN; | 73 direction = reverse ? View.FOCUS_UP : View.FOCUS_DOWN; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 @Override | 181 @Override |
| 182 public boolean addNewContents(boolean isDialog, boolean isUserGesture) { | 182 public boolean addNewContents(boolean isDialog, boolean isUserGesture) { |
| 183 return mContentsClient.onCreateWindow(isDialog, isUserGesture); | 183 return mContentsClient.onCreateWindow(isDialog, isUserGesture); |
| 184 } | 184 } |
| 185 | 185 |
| 186 @Override | 186 @Override |
| 187 public void activateContents() { | 187 public void activateContents() { |
| 188 mContentsClient.onRequestFocus(); | 188 mContentsClient.onRequestFocus(); |
| 189 } | 189 } |
| 190 } | 190 } |
| OLD | NEW |