Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_enabled.h" | 5 #include "ui/base/touch/touch_enabled.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ui/base/touch/touch_device.h" | 9 #include "ui/base/touch/touch_device.h" |
| 10 #include "ui/base/ui_base_switches.h" | 10 #include "ui/base/ui_base_switches.h" |
| 11 #include "ui/events/base_event_utils.h" | 11 #include "ui/events/base_event_utils.h" |
| 12 #include "ui/events/event_switches.h" | 12 #include "ui/events/event_switches.h" |
| 13 | 13 |
| 14 namespace ui { | 14 namespace ui { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 enum class TouchEventsStatus { | 18 enum class TouchEventsStatus { |
| 19 AUTO, | 19 AUTO, |
| 20 DISABLED, | 20 DISABLED, |
| 21 ENABLED, | 21 ENABLED, |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 TouchEventsStatus ComputeTouchFlagStatus() { | 24 TouchEventsStatus ComputeTouchAPIFlagStatus() { |
| 25 auto* command_line = base::CommandLine::ForCurrentProcess(); | 25 auto* command_line = base::CommandLine::ForCurrentProcess(); |
| 26 const std::string touch_enabled_switch = | 26 const std::string touch_enabled_switch = |
| 27 command_line->HasSwitch(switches::kTouchEvents) ? | 27 command_line->HasSwitch(switches::kTouchEvents) ? |
| 28 command_line->GetSwitchValueASCII(switches::kTouchEvents) : | 28 command_line->GetSwitchValueASCII(switches::kTouchEvents) : |
| 29 switches::kTouchEventsAuto; | 29 switches::kTouchEventsAuto; |
| 30 | 30 |
| 31 if (touch_enabled_switch.empty() || | 31 if (touch_enabled_switch.empty() || |
| 32 touch_enabled_switch == switches::kTouchEventsEnabled) { | 32 touch_enabled_switch == switches::kTouchEventsEnabled) { |
| 33 return TouchEventsStatus::ENABLED; | 33 return TouchEventsStatus::ENABLED; |
| 34 } | 34 } |
| 35 | 35 |
| 36 if (touch_enabled_switch == switches::kTouchEventsAuto) | 36 if (touch_enabled_switch == switches::kTouchEventsAuto) |
| 37 return TouchEventsStatus::AUTO; | 37 return TouchEventsStatus::AUTO; |
| 38 | 38 |
| 39 DLOG_IF(ERROR, touch_enabled_switch != switches::kTouchEventsDisabled) << | 39 DLOG_IF(ERROR, touch_enabled_switch != switches::kTouchEventsDisabled) << |
| 40 "Invalid --touch-events option: " << touch_enabled_switch; | 40 "Invalid --touch-events option: " << touch_enabled_switch; |
| 41 return TouchEventsStatus::DISABLED; | 41 return TouchEventsStatus::DISABLED; |
| 42 } | 42 } |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 bool AreTouchEventsEnabled() { | 46 bool IsTouchAPIEnabled() { |
| 47 static TouchEventsStatus touch_flag_status = ComputeTouchFlagStatus(); | 47 static TouchEventsStatus touch_flag_status = ComputeTouchAPIFlagStatus(); |
| 48 | 48 |
| 49 // The #touch-events flag is used to force and simulate the presence or | 49 // The #touch-events flag is used to force and simulate the presence or |
| 50 // absence of touch devices. Only if the flag is set to AUTO, we need to check | 50 // absence of touch devices. Only if the flag is set to AUTO, we need to check |
| 51 // for the actual availability of touch devices. | 51 // for the actual availability of touch devices. |
| 52 if (touch_flag_status == TouchEventsStatus::AUTO) | 52 if (touch_flag_status == TouchEventsStatus::AUTO) |
| 53 return GetTouchScreensAvailability() == TouchScreensAvailability::ENABLED; | 53 return GetTouchScreensAvailability() == TouchScreensAvailability::ENABLED; |
|
mustaq
2016/11/03 18:10:49
IsTouchAPIEnabled() shouldn't depend on touch scre
| |
| 54 | 54 |
| 55 return touch_flag_status == TouchEventsStatus::ENABLED; | 55 return touch_flag_status == TouchEventsStatus::ENABLED; |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace ui | 58 } // namespace ui |
| 59 | |
| OLD | NEW |