Index: base/android/java/src/org/chromium/base/BaseChromiumApplication.java |
diff --git a/base/android/java/src/org/chromium/base/BaseChromiumApplication.java b/base/android/java/src/org/chromium/base/BaseChromiumApplication.java |
index 8ec4afa6637fc90138ba1eec32f7dca47864198b..d7c7b05ea58d88808aef44d10e798448e74ec0ca 100644 |
--- a/base/android/java/src/org/chromium/base/BaseChromiumApplication.java |
+++ b/base/android/java/src/org/chromium/base/BaseChromiumApplication.java |
@@ -8,6 +8,7 @@ import android.app.Activity; |
import android.app.Application; |
import android.content.Context; |
import android.os.Bundle; |
+import android.view.KeyEvent; |
import android.view.Window; |
import java.lang.reflect.InvocationHandler; |
@@ -37,6 +38,9 @@ public class BaseChromiumApplication extends Application { |
/** |
* Intercepts calls to an existing Window.Callback. Most invocations are passed on directly |
* to the composed Window.Callback but enables intercepting/manipulating others. |
+ * |
+ * This is used to relay window focus changes throughout the app and remedy a bug in the |
+ * appcompat library. |
*/ |
private class WindowCallbackProxy implements InvocationHandler { |
private final Window.Callback mCallback; |
@@ -53,6 +57,9 @@ public class BaseChromiumApplication extends Application { |
&& args[0] instanceof Boolean) { |
onWindowFocusChanged((boolean) args[0]); |
return null; |
+ } else if (method.getName().equals("dispatchKeyEvent") && args.length == 1 |
+ && args[0] instanceof KeyEvent) { |
+ return dispatchKeyEvent((KeyEvent) args[0]); |
} else { |
try { |
return method.invoke(mCallback, args); |
@@ -78,6 +85,15 @@ public class BaseChromiumApplication extends Application { |
listener.onWindowFocusChanged(mActivity, hasFocus); |
} |
} |
+ |
+ public boolean dispatchKeyEvent(KeyEvent event) { |
+ // TODO(aurimas): remove this once AppCompatDelegateImpl no longer steals |
+ // KEYCODE_MENU. (see b/20529185) |
+ if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && mActivity.dispatchKeyEvent(event)) { |
+ return true; |
+ } |
+ return mCallback.dispatchKeyEvent(event); |
+ } |
} |
@Override |
public void onCreate() { |