зеркало из https://github.com/mozilla/gecko-dev.git
Bug 855471 - Transfer focus to the LayerView when receiving a gamepad panning-related event. r=mfinkle
This commit is contained in:
Родитель
dc20788173
Коммит
66275a333e
|
@ -9,9 +9,11 @@ import org.mozilla.gecko.db.BrowserContract.Combined;
|
|||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.gfx.BitmapUtils;
|
||||
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
||||
import org.mozilla.gecko.gfx.LayerView;
|
||||
import org.mozilla.gecko.util.FloatUtils;
|
||||
import org.mozilla.gecko.util.UiAsyncTask;
|
||||
import org.mozilla.gecko.util.GamepadUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.util.UiAsyncTask;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -439,6 +441,19 @@ abstract public class BrowserApp extends GeckoApp
|
|||
mMainLayout.addView(actionBar, 2);
|
||||
|
||||
((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideTabsTouchListener());
|
||||
((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() {
|
||||
@Override
|
||||
public boolean onInterceptMotionEvent(View view, MotionEvent event) {
|
||||
// If we get a gamepad panning MotionEvent while the focus is not on the layerview,
|
||||
// put the focus on the layerview and carry on
|
||||
LayerView layerView = mLayerView;
|
||||
if (layerView != null && !layerView.hasFocus() && GamepadUtils.isPanningControl(event)) {
|
||||
layerView.requestFocus();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mBrowserToolbar = new BrowserToolbar(this);
|
||||
mBrowserToolbar.from(actionBar);
|
||||
|
|
|
@ -2469,6 +2469,7 @@ abstract public class GeckoApp
|
|||
|
||||
public static class MainLayout extends RelativeLayout {
|
||||
private TouchEventInterceptor mTouchEventInterceptor;
|
||||
private MotionEventInterceptor mMotionEventInterceptor;
|
||||
|
||||
public MainLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
@ -2478,6 +2479,10 @@ abstract public class GeckoApp
|
|||
mTouchEventInterceptor = interceptor;
|
||||
}
|
||||
|
||||
public void setMotionEventInterceptor(MotionEventInterceptor interceptor) {
|
||||
mMotionEventInterceptor = interceptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||
if (mTouchEventInterceptor != null && mTouchEventInterceptor.onInterceptTouchEvent(this, event)) {
|
||||
|
@ -2494,6 +2499,14 @@ abstract public class GeckoApp
|
|||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
if (mMotionEventInterceptor != null && mMotionEventInterceptor.onInterceptMotionEvent(this, event)) {
|
||||
return true;
|
||||
}
|
||||
return super.onGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrawingCacheEnabled(boolean enabled) {
|
||||
// Instead of setting drawing cache in the view itself, we simply
|
||||
|
|
|
@ -120,6 +120,7 @@ FENNEC_JAVA_FILES = \
|
|||
MenuItemDefault.java \
|
||||
MenuPanel.java \
|
||||
MenuPopup.java \
|
||||
MotionEventInterceptor.java \
|
||||
MultiChoicePreference.java \
|
||||
NotificationClient.java \
|
||||
NotificationHandler.java \
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public interface MotionEventInterceptor {
|
||||
public boolean onInterceptMotionEvent(View view, MotionEvent event);
|
||||
}
|
|
@ -8,6 +8,7 @@ package org.mozilla.gecko.util;
|
|||
import android.os.Build;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
@ -38,6 +39,13 @@ public final class GamepadUtils {
|
|||
return (isGamepadKey(event) && (event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_B));
|
||||
}
|
||||
|
||||
public static boolean isPanningControl(MotionEvent event) {
|
||||
if (Build.VERSION.SDK_INT >= 12) {
|
||||
return (event.getSource() & InputDevice.SOURCE_CLASS_MASK) == InputDevice.SOURCE_CLASS_JOYSTICK;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static View.OnKeyListener getClickDispatcher() {
|
||||
if (sClickDispatcher == null) {
|
||||
sClickDispatcher = new View.OnKeyListener() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче