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

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

Issue 2827803002: Make Interaction Media Features MQ dynamic on Linux. (Closed)
Patch Set: Patch for landing, added the mojo bits Created 3 years, 7 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.h ('k') | ui/base/touch/touch_device_util.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 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
32 } // namespace
33
19 int GetAvailablePointerTypes() { 34 int GetAvailablePointerTypes() {
20 // Assume a mouse is there 35 int available_pointer_types = 0;
21 int available_pointer_types = POINTER_TYPE_FINE; 36 if (isMouseOrTouchpadPresent())
37 available_pointer_types |= POINTER_TYPE_FINE;
38
22 if (IsTouchDevicePresent()) 39 if (IsTouchDevicePresent())
23 available_pointer_types |= POINTER_TYPE_COARSE; 40 available_pointer_types |= POINTER_TYPE_COARSE;
24 41
42 if (available_pointer_types == 0)
43 available_pointer_types = POINTER_TYPE_NONE;
44
25 DCHECK(available_pointer_types); 45 DCHECK(available_pointer_types);
26 return available_pointer_types; 46 return available_pointer_types;
27 } 47 }
28 48
29 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634
30 int GetAvailableHoverTypes() { 49 int GetAvailableHoverTypes() {
31 int available_hover_types = HOVER_TYPE_HOVER; 50 int available_hover_types = HOVER_TYPE_NONE;
32 if (IsTouchDevicePresent()) 51 if (isMouseOrTouchpadPresent())
33 available_hover_types |= HOVER_TYPE_NONE; 52 available_hover_types |= HOVER_TYPE_HOVER;
34 return available_hover_types; 53 return available_hover_types;
35 } 54 }
36 55
37 } // namespace
38
39 TouchScreensAvailability GetTouchScreensAvailability() { 56 TouchScreensAvailability GetTouchScreensAvailability() {
40 if (!IsTouchDevicePresent()) 57 if (!IsTouchDevicePresent())
41 return TouchScreensAvailability::NONE; 58 return TouchScreensAvailability::NONE;
42 59
43 return InputDeviceManager::GetInstance()->AreTouchscreensEnabled() 60 return InputDeviceManager::GetInstance()->AreTouchscreensEnabled()
44 ? TouchScreensAvailability::ENABLED 61 ? TouchScreensAvailability::ENABLED
45 : TouchScreensAvailability::DISABLED; 62 : TouchScreensAvailability::DISABLED;
46 } 63 }
47 64
48 int MaxTouchPoints() { 65 int MaxTouchPoints() {
49 int max_touch = 0; 66 int max_touch = 0;
50 const std::vector<ui::TouchscreenDevice>& touchscreen_devices = 67 const std::vector<ui::TouchscreenDevice>& touchscreen_devices =
51 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices(); 68 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices();
52 for (const ui::TouchscreenDevice& device : touchscreen_devices) { 69 for (const ui::TouchscreenDevice& device : touchscreen_devices) {
53 if (device.touch_points > max_touch) 70 if (device.touch_points > max_touch)
54 max_touch = device.touch_points; 71 max_touch = device.touch_points;
55 } 72 }
56 return max_touch; 73 return max_touch;
57 } 74 }
58 75
59 std::pair<int, int> GetAvailablePointerAndHoverTypes() {
60 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes());
61 }
62
63 PointerType GetPrimaryPointerType(int available_pointer_types) { 76 PointerType GetPrimaryPointerType(int available_pointer_types) {
64 if (available_pointer_types & POINTER_TYPE_FINE) 77 if (available_pointer_types & POINTER_TYPE_FINE)
65 return POINTER_TYPE_FINE; 78 return POINTER_TYPE_FINE;
66 if (available_pointer_types & POINTER_TYPE_COARSE) 79 if (available_pointer_types & POINTER_TYPE_COARSE)
67 return POINTER_TYPE_COARSE; 80 return POINTER_TYPE_COARSE;
68 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE); 81 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE);
69 return POINTER_TYPE_NONE; 82 return POINTER_TYPE_NONE;
70 } 83 }
71 84
72 HoverType GetPrimaryHoverType(int available_hover_types) { 85 HoverType GetPrimaryHoverType(int available_hover_types) {
73 if (available_hover_types & HOVER_TYPE_HOVER) 86 if (available_hover_types & HOVER_TYPE_HOVER)
74 return HOVER_TYPE_HOVER; 87 return HOVER_TYPE_HOVER;
75 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); 88 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE);
76 return HOVER_TYPE_NONE; 89 return HOVER_TYPE_NONE;
77 } 90 }
78 91
79 } // namespace ui 92 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/touch/touch_device.h ('k') | ui/base/touch/touch_device_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698