Chromium Code Reviews| Index: ui/base/touch/touch_device_linux.cc |
| diff --git a/ui/base/touch/touch_device_linux.cc b/ui/base/touch/touch_device_linux.cc |
| index 3ebf53c3a2fda51106671eeaa8e86a7a1fd3ff4d..b555a3cdfb683899295eac4791406f1149664a42 100644 |
| --- a/ui/base/touch/touch_device_linux.cc |
| +++ b/ui/base/touch/touch_device_linux.cc |
| @@ -15,23 +15,37 @@ bool IsTouchDevicePresent() { |
| return !InputDeviceManager::GetInstance()->GetTouchscreenDevices().empty(); |
| } |
| -// TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634 |
| +bool isMouseOrTouchpadPresent() { |
| + InputDeviceManager* input_manager = InputDeviceManager::GetInstance(); |
| + for (const ui::InputDevice& device : input_manager->GetTouchpadDevices()) { |
| + if (device.enabled) |
| + return true; |
| + } |
| + // We didn't find a touchpad then let's look if there is a mouse connected. |
| + for (const ui::InputDevice& device : input_manager->GetMouseDevices()) { |
| + if (device.enabled) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| int GetAvailablePointerTypes() { |
| - // Assume a mouse is there |
| - int available_pointer_types = POINTER_TYPE_FINE; |
| + int available_pointer_types = 0; |
| + if (isMouseOrTouchpadPresent()) |
| + available_pointer_types |= POINTER_TYPE_FINE; |
| + |
| if (IsTouchDevicePresent()) |
| available_pointer_types |= POINTER_TYPE_COARSE; |
| + if (available_pointer_types == 0) |
| + available_pointer_types = POINTER_TYPE_NONE; |
| + |
| DCHECK(available_pointer_types); |
| return available_pointer_types; |
| } |
| -// TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634 |
| int GetAvailableHoverTypes() { |
| - int available_hover_types = HOVER_TYPE_HOVER; |
| - if (IsTouchDevicePresent()) |
| - available_hover_types |= HOVER_TYPE_NONE; |
| - return available_hover_types; |
| + return isMouseOrTouchpadPresent() ? HOVER_TYPE_HOVER : HOVER_TYPE_NONE; |
|
mustaq
2017/04/24 17:58:04
For mouse+touch case, the return value should be H
|
| } |
| } // namespace |
| @@ -56,7 +70,21 @@ int MaxTouchPoints() { |
| return max_touch; |
| } |
| +bool return_available_pointer_and_hover_types_for_testing = false; |
|
mustaq
2017/04/24 17:58:04
This code duplication with touch_device_win.cc loo
|
| +int available_pointer_types_for_testing = POINTER_TYPE_NONE; |
| +int available_hover_types_for_testing = HOVER_TYPE_NONE; |
| + |
| +void SetAvailablePointerAndHoverTypesForTesting(int available_pointer_types, |
| + int available_hover_types) { |
| + return_available_pointer_and_hover_types_for_testing = true; |
| + available_pointer_types_for_testing = available_pointer_types; |
| + available_hover_types_for_testing = available_hover_types; |
| +} |
| + |
| std::pair<int, int> GetAvailablePointerAndHoverTypes() { |
| + if (return_available_pointer_and_hover_types_for_testing) |
| + return std::make_pair(available_pointer_types_for_testing, |
| + available_hover_types_for_testing); |
| return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes()); |
| } |