Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebd47751 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Support fallback action if unhandled key event"

parents 069fa7b3 d6b1098e
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.util.EventLog;
import android.util.Log;
import android.util.Slog;
import android.util.TypedValue;
import android.view.KeyCharacterMap.FallbackAction;
import android.view.View.AttachInfo;
import android.view.View.MeasureSpec;
import android.view.accessibility.AccessibilityEvent;
@@ -323,6 +324,8 @@ public final class ViewRootImpl implements ViewParent,

    private final int mDensity;

    final KeyCharacterMap.FallbackAction mFallbackAction = new KeyCharacterMap.FallbackAction();

    /**
     * Consistency verifier for debugging purposes.
     */
@@ -4383,6 +4386,31 @@ public final class ViewRootImpl implements ViewParent,
        mHandler.sendMessage(msg);
    }

    public void dispatchUnhandledKey(KeyEvent event) {
        if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
            final KeyCharacterMap kcm = event.getKeyCharacterMap();
            final int keyCode = event.getKeyCode();
            final int metaState = event.getMetaState();

            KeyEvent fallbackEvent = null;
            synchronized (mFallbackAction) {
                // Check for fallback actions specified by the key character map.
                if (kcm.getFallbackAction(keyCode, metaState, mFallbackAction)) {
                    int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
                    fallbackEvent = KeyEvent.obtain(
                            event.getDownTime(), event.getEventTime(),
                            event.getAction(), mFallbackAction.keyCode,
                            event.getRepeatCount(), mFallbackAction.metaState,
                            event.getDeviceId(), event.getScanCode(),
                            flags, event.getSource(), null);
                }
            }
            if (fallbackEvent != null) {
                dispatchKey(fallbackEvent);
            }
        }
    }

    public void dispatchAppVisibility(boolean visible) {
        Message msg = mHandler.obtainMessage(MSG_DISPATCH_APP_VISIBILITY);
        msg.arg1 = visible ? 1 : 0;
+5 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Message;
import android.view.KeyEvent;
import android.view.ViewRootImpl;

public class WebViewClient {

@@ -273,6 +274,10 @@ public class WebViewClient {
     * @param event The key event.
     */
    public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
        ViewRootImpl root = view.getViewRootImpl();
        if (root != null) {
            root.dispatchUnhandledKey(event);
        }
    }

    /**