Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1347)

Unified Diff: ui/android/java/src/org/chromium/ui/base/TouchDevice.java

Issue 696713002: Pointer/hover media query support: platform-dependent changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/android/BUILD.gn ('k') | ui/android/ui_android.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/java/src/org/chromium/ui/base/TouchDevice.java
diff --git a/ui/android/java/src/org/chromium/ui/base/TouchDevice.java b/ui/android/java/src/org/chromium/ui/base/TouchDevice.java
index 6801655c25e727c4e4654999450e26f046e59a04..38edf900d88a94c61cd1b1edf1fafb550f842950 100644
--- a/ui/android/java/src/org/chromium/ui/base/TouchDevice.java
+++ b/ui/android/java/src/org/chromium/ui/base/TouchDevice.java
@@ -6,12 +6,13 @@ package org.chromium.ui.base;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.view.InputDevice;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
/**
- * Simple proxy to let us query the touch device from C++
+ * Simple proxy for querying input device properties from C++.
*/
@JNINamespace("ui")
public class TouchDevice {
@@ -22,16 +23,14 @@ public class TouchDevice {
private TouchDevice() { }
/**
- * Returns the number of supported touch points.
- *
* @return Maximum supported touch points.
*/
@CalledByNative
private static int maxTouchPoints(Context context) {
- // Android only tells us if the device belongs to a "Touchscreen Class"
- // which only guarantees a minimum number of touch points. Be
- // conservative and return the minimum, checking membership from the
- // highest class down.
+ // Android only tells us if the device belongs to a "Touchscreen Class" which only
+ // guarantees a minimum number of touch points. Be conservative and return the minimum,
+ // checking membership from the highest class down.
+
if (context.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND)) {
return 5;
@@ -48,4 +47,65 @@ public class TouchDevice {
return 0;
}
}
+
+ /**
+ * @return the pointer-types supported by the device, as the union (bitwise OR) of PointerType
+ * bits.
+ */
+ @CalledByNative
+ private static int availablePointerTypes(Context context) {
+ int pointerTypesVal = 0;
+
+ for (int deviceId : InputDevice.getDeviceIds()) {
+ int sources = InputDevice.getDevice(deviceId).getSources();
+
+ if (hasSource(sources, InputDevice.SOURCE_MOUSE)
+ || hasSource(sources, InputDevice.SOURCE_STYLUS)
+ || hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
+ || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
+ pointerTypesVal |= PointerType.FINE;
+ } else if (hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
+ pointerTypesVal |= PointerType.COARSE;
+ } else {
+ // The remaining InputDevice sources:
+ // SOURCE_DPAD, SOURCE_GAMEPAD, SOURCE_JOYSTICK, SOURCE_KEYBOARD,
+ // SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN
+ pointerTypesVal |= PointerType.NONE;
+ }
+ }
+
+ return pointerTypesVal;
+ }
+
+ /**
+ * @return the hover-types supported by the device, as the union (bitwise OR) of HoverType bits.
+ */
+ @CalledByNative
+ private static int availableHoverTypes(Context context) {
+ int hoverTypesVal = 0;
+
+ for (int deviceId : InputDevice.getDeviceIds()) {
+ int sources = InputDevice.getDevice(deviceId).getSources();
+
+ if (hasSource(sources, InputDevice.SOURCE_MOUSE)
+ || hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
+ || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
+ hoverTypesVal |= HoverType.HOVER;
+ } else if (hasSource(sources, InputDevice.SOURCE_STYLUS)
+ || hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
+ hoverTypesVal |= HoverType.ON_DEMAND;
+ } else {
+ // The remaining InputDevice sources:
+ // SOURCE_DPAD, SOURCE_GAMEPAD, SOURCE_JOYSTICK,
+ // SOURCE_KEYBOARD, SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN
+ hoverTypesVal |= HoverType.NONE;
+ }
+ }
+
+ return hoverTypesVal;
+ }
+
+ private static boolean hasSource(int sources, int inputDeviceSource) {
+ return (sources & inputDeviceSource) == inputDeviceSource;
+ }
}
« no previous file with comments | « ui/android/BUILD.gn ('k') | ui/android/ui_android.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698