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

Side by Side Diff: ui/base/touch/touch_device_win.cc

Issue 2301073002: Optimization: avoid making 4 JNI calls to get touch device attributes. (Closed)
Patch Set: Fix windows compile issues Created 4 years, 3 months 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/base/touch/touch_device_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/win/windows_version.h" 7 #include "base/win/windows_version.h"
8 #include <windows.h> 8 #include <windows.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
22 TouchScreensAvailability GetTouchScreensAvailability() {
23 if (!IsTouchDevicePresent())
24 return TouchScreensAvailability::NONE;
25
26 return TouchScreensAvailability::ENABLED;
27 }
28
29 int MaxTouchPoints() {
30 if (!IsTouchDevicePresent())
31 return 0;
32
33 return GetSystemMetrics(SM_MAXIMUMTOUCHES);
34 }
35
36 int GetAvailablePointerTypes() { 20 int GetAvailablePointerTypes() {
37 int available_pointer_types = 0; 21 int available_pointer_types = 0;
38 if (IsTouchDevicePresent()) 22 if (IsTouchDevicePresent())
39 available_pointer_types |= POINTER_TYPE_COARSE; 23 available_pointer_types |= POINTER_TYPE_COARSE;
40 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0 && 24 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0 &&
41 GetSystemMetrics(SM_CMOUSEBUTTONS) > 0) 25 GetSystemMetrics(SM_CMOUSEBUTTONS) > 0)
42 available_pointer_types |= POINTER_TYPE_FINE; 26 available_pointer_types |= POINTER_TYPE_FINE;
43 27
44 if (available_pointer_types == 0) 28 if (available_pointer_types == 0)
45 available_pointer_types = POINTER_TYPE_NONE; 29 available_pointer_types = POINTER_TYPE_NONE;
46 30
47 return available_pointer_types; 31 return available_pointer_types;
48 } 32 }
49 33
50 PointerType GetPrimaryPointerType() {
51 int available_pointer_types = GetAvailablePointerTypes();
52 if (available_pointer_types & POINTER_TYPE_FINE)
53 return POINTER_TYPE_FINE;
54 if (available_pointer_types & POINTER_TYPE_COARSE)
55 return POINTER_TYPE_COARSE;
56 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE);
57 return POINTER_TYPE_NONE;
58 }
59
60 int GetAvailableHoverTypes() { 34 int GetAvailableHoverTypes() {
61 int available_hover_types = 0; 35 int available_hover_types = 0;
62 if (IsTouchDevicePresent()) 36 if (IsTouchDevicePresent())
63 available_hover_types |= HOVER_TYPE_ON_DEMAND; 37 available_hover_types |= HOVER_TYPE_ON_DEMAND;
64 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0) 38 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0)
65 available_hover_types |= HOVER_TYPE_HOVER; 39 available_hover_types |= HOVER_TYPE_HOVER;
66 40
67 if (available_hover_types == 0) 41 if (available_hover_types == 0)
68 available_hover_types = HOVER_TYPE_NONE; 42 available_hover_types = HOVER_TYPE_NONE;
69 43
70 return available_hover_types; 44 return available_hover_types;
71 } 45 }
72 46
73 HoverType GetPrimaryHoverType() { 47 } // namespace
74 int available_hover_types = GetAvailableHoverTypes(); 48
49 TouchScreensAvailability GetTouchScreensAvailability() {
50 if (!IsTouchDevicePresent())
51 return TouchScreensAvailability::NONE;
52
53 return TouchScreensAvailability::ENABLED;
54 }
55
56 int MaxTouchPoints() {
57 if (!IsTouchDevicePresent())
58 return 0;
59
60 return GetSystemMetrics(SM_MAXIMUMTOUCHES);
61 }
62
63 PointerType GetPrimaryPointerType(int available_pointer_types) {
64 if (available_pointer_types & POINTER_TYPE_FINE)
65 return POINTER_TYPE_FINE;
66 if (available_pointer_types & POINTER_TYPE_COARSE)
67 return POINTER_TYPE_COARSE;
68 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE);
69 return POINTER_TYPE_NONE;
70 }
71
72 HoverType GetPrimaryHoverType(int available_hover_types) {
75 if (available_hover_types & HOVER_TYPE_HOVER) 73 if (available_hover_types & HOVER_TYPE_HOVER)
76 return HOVER_TYPE_HOVER; 74 return HOVER_TYPE_HOVER;
77 if (available_hover_types & HOVER_TYPE_ON_DEMAND) 75 if (available_hover_types & HOVER_TYPE_ON_DEMAND)
78 return HOVER_TYPE_ON_DEMAND; 76 return HOVER_TYPE_ON_DEMAND;
79 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); 77 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE);
80 return HOVER_TYPE_NONE; 78 return HOVER_TYPE_NONE;
81 } 79 }
82 80
81 std::pair<int, int> GetAvailablePointerAndHoverTypes() {
82 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes());
83 }
84
83 } // namespace ui 85 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/touch/touch_device_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698