| OLD | NEW |
| 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 import android.view.InputDevice; |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 return 2; | 42 return 2; |
| 43 } else if (context.getPackageManager().hasSystemFeature( | 43 } else if (context.getPackageManager().hasSystemFeature( |
| 44 PackageManager.FEATURE_TOUCHSCREEN)) { | 44 PackageManager.FEATURE_TOUCHSCREEN)) { |
| 45 return 1; | 45 return 1; |
| 46 } else { | 46 } else { |
| 47 return 0; | 47 return 0; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * @return the pointer-types supported by the device, as the union (bitwise
OR) of PointerType | 52 * @return an array of two ints: result[0] represents the pointer-types and
result[1] represents |
| 53 * bits in result[0] | 53 * the hover-types supported by the device, where each int is the un
ion (bitwise OR) of |
| 54 * the hover-types supported by the device, as the union (bitwise OR
) of HoverType bits | 54 * corresponding type (PointerType/HoverType) bits. |
| 55 * in result[1]. | |
| 56 */ | 55 */ |
| 57 @CalledByNative | 56 @CalledByNative |
| 58 private static int[] availablePointerAndHoverTypes(Context context) { | 57 private static int[] availablePointerAndHoverTypes(Context context) { |
| 59 int[] result = new int[2]; | 58 int[] result = new int[2]; |
| 60 result[0] = result[1] = 0; | 59 result[0] = result[1] = 0; |
| 61 | 60 |
| 62 for (int deviceId : InputDevice.getDeviceIds()) { | 61 for (int deviceId : InputDevice.getDeviceIds()) { |
| 63 InputDevice inputDevice = InputDevice.getDevice(deviceId); | 62 InputDevice inputDevice = InputDevice.getDevice(deviceId); |
| 64 if (inputDevice == null) continue; | 63 if (inputDevice == null) continue; |
| 65 | 64 |
| 66 int sources = inputDevice.getSources(); | 65 int sources = inputDevice.getSources(); |
| 67 | 66 |
| 68 if (hasSource(sources, InputDevice.SOURCE_MOUSE) | 67 if (hasSource(sources, InputDevice.SOURCE_MOUSE) |
| 69 || hasSource(sources, InputDevice.SOURCE_STYLUS) | 68 || hasSource(sources, InputDevice.SOURCE_STYLUS) |
| 70 || hasSource(sources, InputDevice.SOURCE_TOUCHPAD) | 69 || hasSource(sources, InputDevice.SOURCE_TOUCHPAD) |
| 71 || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) { | 70 || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) { |
| 72 result[0] |= PointerType.FINE; | 71 result[0] |= PointerType.FINE; |
| 73 } else if (hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) { | 72 } else if (hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) { |
| 74 result[0] |= PointerType.COARSE; | 73 result[0] |= PointerType.COARSE; |
| 75 } | 74 } |
| 76 | 75 |
| 77 if (hasSource(sources, InputDevice.SOURCE_MOUSE) | 76 if (hasSource(sources, InputDevice.SOURCE_MOUSE) |
| 78 || hasSource(sources, InputDevice.SOURCE_TOUCHPAD) | 77 || hasSource(sources, InputDevice.SOURCE_TOUCHPAD) |
| 79 || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) { | 78 || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) { |
| 80 result[1] |= HoverType.HOVER; | 79 result[1] |= HoverType.HOVER; |
| 81 } else if (hasSource(sources, InputDevice.SOURCE_STYLUS) | 80 } else if (hasSource(sources, InputDevice.SOURCE_STYLUS) |
| 82 || hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) { | 81 || hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) { |
| 83 result[1] |= HoverType.ON_DEMAND; | 82 result[1] |= HoverType.NONE; |
| 84 } | 83 } |
| 85 | 84 |
| 86 // Remaining InputDevice sources: SOURCE_DPAD, SOURCE_GAMEPAD, SOURC
E_JOYSTICK, | 85 // Remaining InputDevice sources: SOURCE_DPAD, SOURCE_GAMEPAD, SOURC
E_JOYSTICK, |
| 87 // SOURCE_KEYBOARD, SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN | 86 // SOURCE_KEYBOARD, SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN |
| 88 } | 87 } |
| 89 | 88 |
| 90 if (result[0] == 0) result[0] = PointerType.NONE; | 89 if (result[0] == 0) result[0] = PointerType.NONE; |
| 91 if (result[1] == 0) result[1] = HoverType.NONE; | 90 if (result[1] == 0) result[1] = HoverType.NONE; |
| 92 | 91 |
| 93 return result; | 92 return result; |
| 94 } | 93 } |
| 95 | 94 |
| 96 private static boolean hasSource(int sources, int inputDeviceSource) { | 95 private static boolean hasSource(int sources, int inputDeviceSource) { |
| 97 return (sources & inputDeviceSource) == inputDeviceSource; | 96 return (sources & inputDeviceSource) == inputDeviceSource; |
| 98 } | 97 } |
| 99 } | 98 } |
| OLD | NEW |