Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1544517 - Add a pref that controls conversion of mouse events to …
Browse files Browse the repository at this point in the history
…touch events. r=geckoview-reviewers,rbarker

For TV devices, it is useful to have mouse events automatically
interpreted as touch events. On other devices, such as more desktop-like
Android devices, we want to treat mouse events as mouse events. This patch
makes this behaviour controllable by a pref, but keeps the existing default
behaviour of treating mouse events as touch events.

Differential Revision: https://phabricator.services.mozilla.com/D29188
  • Loading branch information
staktrace committed Apr 30, 2019
1 parent f954d7c commit 9f0bd91
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@

package org.mozilla.geckoview;

import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.mozglue.JNIObject;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.ThreadUtils;

import android.app.UiModeManager;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.SystemClock;
import android.support.annotation.NonNull;
Expand All @@ -31,6 +36,8 @@ public class PanZoomController {
private static final int EVENT_SOURCE_SCROLL = 0;
private static final int EVENT_SOURCE_MOTION = 1;
private static final int EVENT_SOURCE_MOUSE = 2;
private static final String PREF_MOUSE_AS_TOUCH = "ui.android.mouse_as_touch";
private static boolean sTreatMouseAsTouch = true;

private final GeckoSession mSession;
private final Rect mTempRect = new Rect();
Expand Down Expand Up @@ -228,6 +235,30 @@ private boolean handleMouseEvent(final MotionEvent event) {
protected PanZoomController(final GeckoSession session) {
mSession = session;
enableEventQueue();
initMouseAsTouch();
}

private static void initMouseAsTouch() {
PrefsHelper.PrefHandler prefHandler = new PrefsHelper.PrefHandlerBase() {
@Override
public void prefValue(final String pref, final int value) {
if (!PREF_MOUSE_AS_TOUCH.equals(pref)) {
return;
}
if (value == 0) {
sTreatMouseAsTouch = false;
} else if (value == 1) {
sTreatMouseAsTouch = true;
} else if (value == 2) {
Context c = GeckoAppShell.getApplicationContext();
UiModeManager m = (UiModeManager)c.getSystemService(Context.UI_MODE_SERVICE);
// on TV devices, treat mouse as touch. everywhere else, don't
sTreatMouseAsTouch = (m.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION);
}
}
};
PrefsHelper.addObserver(new String[] { PREF_MOUSE_AS_TOUCH }, prefHandler);
PrefsHelper.getPref(PREF_MOUSE_AS_TOUCH, prefHandler);
}

/**
Expand Down Expand Up @@ -261,6 +292,10 @@ public float getScrollFactor() {
*/
public boolean onTouchEvent(final @NonNull MotionEvent event) {
ThreadUtils.assertOnUiThread();

if (!sTreatMouseAsTouch && event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
return handleMouseEvent(event);
}
return handleMotionEvent(event);
}

Expand Down
2 changes: 2 additions & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ pref("browser.sessionhistory.max_total_viewers", -1);

pref("ui.use_native_colors", true);
pref("ui.click_hold_context_menus", false);
// 0 = false, 1 = true, 2 = autodetect.
pref("ui.android.mouse_as_touch", 1);

// Pop up context menu on mouseup instead of mousedown, if that's the OS default.
// Note: ignored on Windows (context menus always use mouseup)
Expand Down

0 comments on commit 9f0bd91

Please sign in to comment.