OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "ui/base/touch/touch_device.h" | 5 #include "ui/base/touch/touch_device.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/events/devices/input_device_manager.h" | 8 #include "ui/events/devices/input_device_manager.h" |
9 | 9 |
10 namespace ui { | 10 namespace ui { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 bool IsTouchDevicePresent() { | 14 bool IsTouchDevicePresent() { |
15 return !InputDeviceManager::GetInstance()->GetTouchscreenDevices().empty(); | 15 return !InputDeviceManager::GetInstance()->GetTouchscreenDevices().empty(); |
16 } | 16 } |
17 | 17 |
18 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634 | 18 bool isMouseOrTouchpadPresent() { |
19 InputDeviceManager* input_manager = InputDeviceManager::GetInstance(); | |
20 for (const ui::InputDevice& device : input_manager->GetTouchpadDevices()) { | |
21 if (device.enabled) | |
22 return true; | |
23 } | |
24 // We didn't find a touchpad then let's look if there is a mouse connected. | |
25 for (const ui::InputDevice& device : input_manager->GetMouseDevices()) { | |
26 if (device.enabled) | |
27 return true; | |
28 } | |
29 return false; | |
30 } | |
31 | |
19 int GetAvailablePointerTypes() { | 32 int GetAvailablePointerTypes() { |
20 // Assume a mouse is there | 33 int available_pointer_types = 0; |
21 int available_pointer_types = POINTER_TYPE_FINE; | 34 if (isMouseOrTouchpadPresent()) |
35 available_pointer_types |= POINTER_TYPE_FINE; | |
36 | |
22 if (IsTouchDevicePresent()) | 37 if (IsTouchDevicePresent()) |
23 available_pointer_types |= POINTER_TYPE_COARSE; | 38 available_pointer_types |= POINTER_TYPE_COARSE; |
24 | 39 |
40 if (available_pointer_types == 0) | |
41 available_pointer_types = POINTER_TYPE_NONE; | |
42 | |
25 DCHECK(available_pointer_types); | 43 DCHECK(available_pointer_types); |
26 return available_pointer_types; | 44 return available_pointer_types; |
27 } | 45 } |
28 | 46 |
29 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634 | |
30 int GetAvailableHoverTypes() { | 47 int GetAvailableHoverTypes() { |
31 int available_hover_types = HOVER_TYPE_HOVER; | 48 return isMouseOrTouchpadPresent() ? HOVER_TYPE_HOVER : HOVER_TYPE_NONE; |
mustaq
2017/04/24 17:58:04
For mouse+touch case, the return value should be H
| |
32 if (IsTouchDevicePresent()) | |
33 available_hover_types |= HOVER_TYPE_NONE; | |
34 return available_hover_types; | |
35 } | 49 } |
36 | 50 |
37 } // namespace | 51 } // namespace |
38 | 52 |
39 TouchScreensAvailability GetTouchScreensAvailability() { | 53 TouchScreensAvailability GetTouchScreensAvailability() { |
40 if (!IsTouchDevicePresent()) | 54 if (!IsTouchDevicePresent()) |
41 return TouchScreensAvailability::NONE; | 55 return TouchScreensAvailability::NONE; |
42 | 56 |
43 return InputDeviceManager::GetInstance()->AreTouchscreensEnabled() | 57 return InputDeviceManager::GetInstance()->AreTouchscreensEnabled() |
44 ? TouchScreensAvailability::ENABLED | 58 ? TouchScreensAvailability::ENABLED |
45 : TouchScreensAvailability::DISABLED; | 59 : TouchScreensAvailability::DISABLED; |
46 } | 60 } |
47 | 61 |
48 int MaxTouchPoints() { | 62 int MaxTouchPoints() { |
49 int max_touch = 0; | 63 int max_touch = 0; |
50 const std::vector<ui::TouchscreenDevice>& touchscreen_devices = | 64 const std::vector<ui::TouchscreenDevice>& touchscreen_devices = |
51 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices(); | 65 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices(); |
52 for (const ui::TouchscreenDevice& device : touchscreen_devices) { | 66 for (const ui::TouchscreenDevice& device : touchscreen_devices) { |
53 if (device.touch_points > max_touch) | 67 if (device.touch_points > max_touch) |
54 max_touch = device.touch_points; | 68 max_touch = device.touch_points; |
55 } | 69 } |
56 return max_touch; | 70 return max_touch; |
57 } | 71 } |
58 | 72 |
73 bool return_available_pointer_and_hover_types_for_testing = false; | |
mustaq
2017/04/24 17:58:04
This code duplication with touch_device_win.cc loo
| |
74 int available_pointer_types_for_testing = POINTER_TYPE_NONE; | |
75 int available_hover_types_for_testing = HOVER_TYPE_NONE; | |
76 | |
77 void SetAvailablePointerAndHoverTypesForTesting(int available_pointer_types, | |
78 int available_hover_types) { | |
79 return_available_pointer_and_hover_types_for_testing = true; | |
80 available_pointer_types_for_testing = available_pointer_types; | |
81 available_hover_types_for_testing = available_hover_types; | |
82 } | |
83 | |
59 std::pair<int, int> GetAvailablePointerAndHoverTypes() { | 84 std::pair<int, int> GetAvailablePointerAndHoverTypes() { |
85 if (return_available_pointer_and_hover_types_for_testing) | |
86 return std::make_pair(available_pointer_types_for_testing, | |
87 available_hover_types_for_testing); | |
60 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes()); | 88 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes()); |
61 } | 89 } |
62 | 90 |
63 PointerType GetPrimaryPointerType(int available_pointer_types) { | 91 PointerType GetPrimaryPointerType(int available_pointer_types) { |
64 if (available_pointer_types & POINTER_TYPE_FINE) | 92 if (available_pointer_types & POINTER_TYPE_FINE) |
65 return POINTER_TYPE_FINE; | 93 return POINTER_TYPE_FINE; |
66 if (available_pointer_types & POINTER_TYPE_COARSE) | 94 if (available_pointer_types & POINTER_TYPE_COARSE) |
67 return POINTER_TYPE_COARSE; | 95 return POINTER_TYPE_COARSE; |
68 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE); | 96 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE); |
69 return POINTER_TYPE_NONE; | 97 return POINTER_TYPE_NONE; |
70 } | 98 } |
71 | 99 |
72 HoverType GetPrimaryHoverType(int available_hover_types) { | 100 HoverType GetPrimaryHoverType(int available_hover_types) { |
73 if (available_hover_types & HOVER_TYPE_HOVER) | 101 if (available_hover_types & HOVER_TYPE_HOVER) |
74 return HOVER_TYPE_HOVER; | 102 return HOVER_TYPE_HOVER; |
75 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); | 103 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); |
76 return HOVER_TYPE_NONE; | 104 return HOVER_TYPE_NONE; |
77 } | 105 } |
78 | 106 |
79 } // namespace ui | 107 } // namespace ui |
OLD | NEW |