OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/win/win_util.h" | 8 #include "base/win/win_util.h" |
9 | 9 |
10 namespace ui { | 10 namespace ui { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 bool IsTouchDevicePresent() { | 14 bool IsTouchDevicePresent() { |
15 int value = GetSystemMetrics(SM_DIGITIZER); | 15 int value = GetSystemMetrics(SM_DIGITIZER); |
16 return (value & NID_READY) && | 16 return (value & NID_READY) && |
17 ((value & NID_INTEGRATED_TOUCH) || (value & NID_EXTERNAL_TOUCH)); | 17 ((value & NID_INTEGRATED_TOUCH) || (value & NID_EXTERNAL_TOUCH)); |
18 } | 18 } |
19 | 19 |
| 20 } // namespace |
| 21 |
20 // The following method logic is as follow : | 22 // The following method logic is as follow : |
21 // - On versions prior to Windows 8 it will always return POINTER_TYPE_FINE | 23 // - On versions prior to Windows 8 it will always return POINTER_TYPE_FINE |
22 // and/or POINTER_TYPE_COARSE (if the device has a touch screen). | 24 // and/or POINTER_TYPE_COARSE (if the device has a touch screen). |
23 // - If the device is a detachable/convertible win8/10 device and the keyboard/ | 25 // - If the device is a detachable/convertible win8/10 device and the keyboard/ |
24 // trackpad is detached/flipped it will always return POINTER_TYPE_COARSE. | 26 // trackpad is detached/flipped it will always return POINTER_TYPE_COARSE. |
25 // It does not cover the case where an external mouse/keyboard is connected | 27 // It does not cover the case where an external mouse/keyboard is connected |
26 // while the device is used as a tablet. This is because Windows doesn't provide | 28 // while the device is used as a tablet. This is because Windows doesn't provide |
27 // us a reliable way to detect keyboard/mouse presence with | 29 // us a reliable way to detect keyboard/mouse presence with |
28 // GetSystemMetrics(SM_MOUSEPRESENT). | 30 // GetSystemMetrics(SM_MOUSEPRESENT). |
29 // - If the device doesn't have a touch screen it will return POINTER_TYPE_FINE. | 31 // - If the device doesn't have a touch screen it will return POINTER_TYPE_FINE. |
(...skipping 28 matching lines...) Expand all Loading... |
58 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0) { | 60 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0) { |
59 available_hover_types = HOVER_TYPE_HOVER; | 61 available_hover_types = HOVER_TYPE_HOVER; |
60 if (IsTouchDevicePresent()) | 62 if (IsTouchDevicePresent()) |
61 available_hover_types |= HOVER_TYPE_NONE; | 63 available_hover_types |= HOVER_TYPE_NONE; |
62 } else | 64 } else |
63 available_hover_types = HOVER_TYPE_NONE; | 65 available_hover_types = HOVER_TYPE_NONE; |
64 | 66 |
65 return available_hover_types; | 67 return available_hover_types; |
66 } | 68 } |
67 | 69 |
68 } // namespace | |
69 | |
70 TouchScreensAvailability GetTouchScreensAvailability() { | 70 TouchScreensAvailability GetTouchScreensAvailability() { |
71 if (!IsTouchDevicePresent()) | 71 if (!IsTouchDevicePresent()) |
72 return TouchScreensAvailability::NONE; | 72 return TouchScreensAvailability::NONE; |
73 | 73 |
74 return TouchScreensAvailability::ENABLED; | 74 return TouchScreensAvailability::ENABLED; |
75 } | 75 } |
76 | 76 |
77 int MaxTouchPoints() { | 77 int MaxTouchPoints() { |
78 if (!IsTouchDevicePresent()) | 78 if (!IsTouchDevicePresent()) |
79 return 0; | 79 return 0; |
(...skipping 10 matching lines...) Expand all Loading... |
90 return POINTER_TYPE_NONE; | 90 return POINTER_TYPE_NONE; |
91 } | 91 } |
92 | 92 |
93 HoverType GetPrimaryHoverType(int available_hover_types) { | 93 HoverType GetPrimaryHoverType(int available_hover_types) { |
94 if (available_hover_types & HOVER_TYPE_HOVER) | 94 if (available_hover_types & HOVER_TYPE_HOVER) |
95 return HOVER_TYPE_HOVER; | 95 return HOVER_TYPE_HOVER; |
96 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); | 96 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); |
97 return HOVER_TYPE_NONE; | 97 return HOVER_TYPE_NONE; |
98 } | 98 } |
99 | 99 |
100 bool return_available_pointer_and_hover_types_for_testing = false; | |
101 int available_pointer_types_for_testing = POINTER_TYPE_NONE; | |
102 int available_hover_types_for_testing = HOVER_TYPE_NONE; | |
103 | |
104 void SetAvailablePointerAndHoverTypesForTesting(int available_pointer_types, | |
105 int available_hover_types) { | |
106 return_available_pointer_and_hover_types_for_testing = true; | |
107 available_pointer_types_for_testing = available_pointer_types; | |
108 available_hover_types_for_testing = available_hover_types; | |
109 } | |
110 | |
111 std::pair<int, int> GetAvailablePointerAndHoverTypes() { | |
112 if (return_available_pointer_and_hover_types_for_testing) | |
113 return std::make_pair(available_pointer_types_for_testing, | |
114 available_hover_types_for_testing); | |
115 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes()); | |
116 } | |
117 | |
118 } // namespace ui | 100 } // namespace ui |
OLD | NEW |