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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/android/BUILD.gn ('k') | ui/android/ui_android.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.ui.base; 5 package org.chromium.ui.base;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.pm.PackageManager; 8 import android.content.pm.PackageManager;
9 import android.view.InputDevice;
9 10
10 import org.chromium.base.CalledByNative; 11 import org.chromium.base.CalledByNative;
11 import org.chromium.base.JNINamespace; 12 import org.chromium.base.JNINamespace;
12 13
13 /** 14 /**
14 * Simple proxy to let us query the touch device from C++ 15 * Simple proxy for querying input device properties from C++.
15 */ 16 */
16 @JNINamespace("ui") 17 @JNINamespace("ui")
17 public class TouchDevice { 18 public class TouchDevice {
18 19
19 /** 20 /**
20 * Static methods only so make constructor private. 21 * Static methods only so make constructor private.
21 */ 22 */
22 private TouchDevice() { } 23 private TouchDevice() { }
23 24
24 /** 25 /**
25 * Returns the number of supported touch points.
26 *
27 * @return Maximum supported touch points. 26 * @return Maximum supported touch points.
28 */ 27 */
29 @CalledByNative 28 @CalledByNative
30 private static int maxTouchPoints(Context context) { 29 private static int maxTouchPoints(Context context) {
31 // Android only tells us if the device belongs to a "Touchscreen Class" 30 // Android only tells us if the device belongs to a "Touchscreen Class" which only
32 // which only guarantees a minimum number of touch points. Be 31 // guarantees a minimum number of touch points. Be conservative and retu rn the minimum,
33 // conservative and return the minimum, checking membership from the 32 // checking membership from the highest class down.
34 // highest class down. 33
35 if (context.getPackageManager().hasSystemFeature( 34 if (context.getPackageManager().hasSystemFeature(
36 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND)) { 35 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND)) {
37 return 5; 36 return 5;
38 } else if (context.getPackageManager().hasSystemFeature( 37 } else if (context.getPackageManager().hasSystemFeature(
39 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)) { 38 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)) {
40 return 2; 39 return 2;
41 } else if (context.getPackageManager().hasSystemFeature( 40 } else if (context.getPackageManager().hasSystemFeature(
42 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) { 41 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
43 return 2; 42 return 2;
44 } else if (context.getPackageManager().hasSystemFeature( 43 } else if (context.getPackageManager().hasSystemFeature(
45 PackageManager.FEATURE_TOUCHSCREEN)) { 44 PackageManager.FEATURE_TOUCHSCREEN)) {
46 return 1; 45 return 1;
47 } else { 46 } else {
48 return 0; 47 return 0;
49 } 48 }
50 } 49 }
50
51 /**
52 * @return the pointer-types supported by the device, as the union (bitwise OR) of PointerType
53 * bits.
54 */
55 @CalledByNative
56 private static int availablePointerTypes(Context context) {
57 int pointerTypesVal = 0;
58
59 for (int deviceId : InputDevice.getDeviceIds()) {
60 int sources = InputDevice.getDevice(deviceId).getSources();
61
62 if (hasSource(sources, InputDevice.SOURCE_MOUSE)
63 || hasSource(sources, InputDevice.SOURCE_STYLUS)
64 || hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
65 || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
66 pointerTypesVal |= PointerType.FINE;
67 } else if (hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
68 pointerTypesVal |= PointerType.COARSE;
69 } else {
70 // The remaining InputDevice sources:
71 // SOURCE_DPAD, SOURCE_GAMEPAD, SOURCE_JOYSTICK, SOURCE_KEYBOARD ,
72 // SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN
73 pointerTypesVal |= PointerType.NONE;
74 }
75 }
76
77 return pointerTypesVal;
78 }
79
80 /**
81 * @return the hover-types supported by the device, as the union (bitwise OR ) of HoverType bits.
82 */
83 @CalledByNative
84 private static int availableHoverTypes(Context context) {
85 int hoverTypesVal = 0;
86
87 for (int deviceId : InputDevice.getDeviceIds()) {
88 int sources = InputDevice.getDevice(deviceId).getSources();
89
90 if (hasSource(sources, InputDevice.SOURCE_MOUSE)
91 || hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
92 || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
93 hoverTypesVal |= HoverType.HOVER;
94 } else if (hasSource(sources, InputDevice.SOURCE_STYLUS)
95 || hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
96 hoverTypesVal |= HoverType.ON_DEMAND;
97 } else {
98 // The remaining InputDevice sources:
99 // SOURCE_DPAD, SOURCE_GAMEPAD, SOURCE_JOYSTICK,
100 // SOURCE_KEYBOARD, SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN
101 hoverTypesVal |= HoverType.NONE;
102 }
103 }
104
105 return hoverTypesVal;
106 }
107
108 private static boolean hasSource(int sources, int inputDeviceSource) {
109 return (sources & inputDeviceSource) == inputDeviceSource;
110 }
51 } 111 }
OLDNEW
« 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