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

Side by Side Diff: ui/base/touch/touch_device_linux.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_android.cc ('k') | ui/base/touch/touch_device_win.cc » ('j') | 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) 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
19 int GetAvailablePointerTypes() {
20 // Assume a mouse is there
21 int available_pointer_types = POINTER_TYPE_FINE;
22 if (IsTouchDevicePresent())
23 available_pointer_types |= POINTER_TYPE_COARSE;
24
25 DCHECK(available_pointer_types);
26 return available_pointer_types;
27 }
28
29 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634
30 int GetAvailableHoverTypes() {
31 // Assume a mouse is there
32 int available_hover_types = HOVER_TYPE_HOVER;
33 if (IsTouchDevicePresent())
34 available_hover_types |= HOVER_TYPE_ON_DEMAND;
35
36 DCHECK(available_hover_types);
37 return available_hover_types;
38 }
39
18 } // namespace 40 } // namespace
19 41
20 TouchScreensAvailability GetTouchScreensAvailability() { 42 TouchScreensAvailability GetTouchScreensAvailability() {
21 if (!IsTouchDevicePresent()) 43 if (!IsTouchDevicePresent())
22 return TouchScreensAvailability::NONE; 44 return TouchScreensAvailability::NONE;
23 45
24 return InputDeviceManager::GetInstance()->AreTouchscreensEnabled() 46 return InputDeviceManager::GetInstance()->AreTouchscreensEnabled()
25 ? TouchScreensAvailability::ENABLED 47 ? TouchScreensAvailability::ENABLED
26 : TouchScreensAvailability::DISABLED; 48 : TouchScreensAvailability::DISABLED;
27 } 49 }
28 50
29 int MaxTouchPoints() { 51 int MaxTouchPoints() {
30 int max_touch = 0; 52 int max_touch = 0;
31 const std::vector<ui::TouchscreenDevice>& touchscreen_devices = 53 const std::vector<ui::TouchscreenDevice>& touchscreen_devices =
32 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices(); 54 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices();
33 for (const ui::TouchscreenDevice& device : touchscreen_devices) { 55 for (const ui::TouchscreenDevice& device : touchscreen_devices) {
34 if (device.touch_points > max_touch) 56 if (device.touch_points > max_touch)
35 max_touch = device.touch_points; 57 max_touch = device.touch_points;
36 } 58 }
37 return max_touch; 59 return max_touch;
38 } 60 }
39 61
40 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634 62 std::pair<int, int> GetAvailablePointerAndHoverTypes() {
41 int GetAvailablePointerTypes() { 63 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes());
42 // Assume a mouse is there
43 int available_pointer_types = POINTER_TYPE_FINE;
44 if (IsTouchDevicePresent())
45 available_pointer_types |= POINTER_TYPE_COARSE;
46
47 DCHECK(available_pointer_types);
48 return available_pointer_types;
49 } 64 }
50 65
51 PointerType GetPrimaryPointerType() { 66 PointerType GetPrimaryPointerType(int available_pointer_types) {
52 int available_pointer_types = GetAvailablePointerTypes();
53 if (available_pointer_types & POINTER_TYPE_FINE) 67 if (available_pointer_types & POINTER_TYPE_FINE)
54 return POINTER_TYPE_FINE; 68 return POINTER_TYPE_FINE;
55 if (available_pointer_types & POINTER_TYPE_COARSE) 69 if (available_pointer_types & POINTER_TYPE_COARSE)
56 return POINTER_TYPE_COARSE; 70 return POINTER_TYPE_COARSE;
57 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE); 71 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE);
58 return POINTER_TYPE_NONE; 72 return POINTER_TYPE_NONE;
59 } 73 }
60 74
61 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634 75 HoverType GetPrimaryHoverType(int available_hover_types) {
62 int GetAvailableHoverTypes() {
63 // Assume a mouse is there
64 int available_hover_types = HOVER_TYPE_HOVER;
65 if (IsTouchDevicePresent())
66 available_hover_types |= HOVER_TYPE_ON_DEMAND;
67
68 DCHECK(available_hover_types);
69 return available_hover_types;
70 }
71
72 HoverType GetPrimaryHoverType() {
73 int available_hover_types = GetAvailableHoverTypes();
74 if (available_hover_types & HOVER_TYPE_HOVER) 76 if (available_hover_types & HOVER_TYPE_HOVER)
75 return HOVER_TYPE_HOVER; 77 return HOVER_TYPE_HOVER;
76 if (available_hover_types & HOVER_TYPE_ON_DEMAND) 78 if (available_hover_types & HOVER_TYPE_ON_DEMAND)
77 return HOVER_TYPE_ON_DEMAND; 79 return HOVER_TYPE_ON_DEMAND;
78 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); 80 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE);
79 return HOVER_TYPE_NONE; 81 return HOVER_TYPE_NONE;
80 } 82 }
81 83
82 } // namespace ui 84 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/touch/touch_device_android.cc ('k') | ui/base/touch/touch_device_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698