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
3 // found in the LICENSE file.
5 #include "ui/base/touch/touch_device.h"
6 #include "base/logging.h"
7 #include "base/win/windows_version.h"
12 bool IsTouchDevicePresent() {
13 int value
= GetSystemMetrics(SM_DIGITIZER
);
14 return (value
& NID_READY
) &&
15 ((value
& NID_INTEGRATED_TOUCH
) || (value
& NID_EXTERNAL_TOUCH
));
18 int MaxTouchPoints() {
19 if (!IsTouchDevicePresent())
22 return GetSystemMetrics(SM_MAXIMUMTOUCHES
);
25 int GetAvailablePointerTypes() {
26 int available_pointer_types
= 0;
27 if (IsTouchDevicePresent())
28 available_pointer_types
|= POINTER_TYPE_COARSE
;
29 if (GetSystemMetrics(SM_MOUSEPRESENT
) != 0 &&
30 GetSystemMetrics(SM_CMOUSEBUTTONS
) > 0)
31 available_pointer_types
|= POINTER_TYPE_FINE
;
33 if (available_pointer_types
== 0)
34 available_pointer_types
= POINTER_TYPE_NONE
;
36 return available_pointer_types
;
39 PointerType
GetPrimaryPointerType() {
40 int available_pointer_types
= GetAvailablePointerTypes();
41 if (available_pointer_types
& POINTER_TYPE_FINE
)
42 return POINTER_TYPE_FINE
;
43 if (available_pointer_types
& POINTER_TYPE_COARSE
)
44 return POINTER_TYPE_COARSE
;
45 DCHECK_EQ(available_pointer_types
, POINTER_TYPE_NONE
);
46 return POINTER_TYPE_NONE
;
49 int GetAvailableHoverTypes() {
50 int available_hover_types
= 0;
51 if (IsTouchDevicePresent())
52 available_hover_types
|= HOVER_TYPE_ON_DEMAND
;
53 if (GetSystemMetrics(SM_MOUSEPRESENT
) != 0)
54 available_hover_types
|= HOVER_TYPE_HOVER
;
56 if (available_hover_types
== 0)
57 available_hover_types
= HOVER_TYPE_NONE
;
59 return available_hover_types
;
62 HoverType
GetPrimaryHoverType() {
63 int available_hover_types
= GetAvailableHoverTypes();
64 if (available_hover_types
& HOVER_TYPE_HOVER
)
65 return HOVER_TYPE_HOVER
;
66 if (available_hover_types
& HOVER_TYPE_ON_DEMAND
)
67 return HOVER_TYPE_ON_DEMAND
;
68 DCHECK_EQ(available_hover_types
, HOVER_TYPE_NONE
);
69 return HOVER_TYPE_NONE
;