| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/common/system/chromeos/palette/palette_utils.h" | 5 #include "ash/common/system/chromeos/palette/palette_utils.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
| 8 #include "ash/common/shelf/wm_shelf.h" | 8 #include "ash/common/shelf/wm_shelf.h" |
| 9 #include "ash/common/system/chromeos/palette/palette_tray.h" | 9 #include "ash/common/system/chromeos/palette/palette_tray.h" |
| 10 #include "ash/common/system/status_area_widget.h" | 10 #include "ash/common/system/status_area_widget.h" |
| 11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 12 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/sys_info.h" |
| 14 #include "ui/events/devices/input_device_manager.h" | 15 #include "ui/events/devices/input_device_manager.h" |
| 15 #include "ui/events/devices/touchscreen_device.h" | 16 #include "ui/events/devices/touchscreen_device.h" |
| 16 #include "ui/gfx/geometry/point.h" | 17 #include "ui/gfx/geometry/point.h" |
| 17 | 18 |
| 18 namespace ash { | 19 namespace ash { |
| 19 namespace palette_utils { | 20 namespace palette_utils { |
| 20 | 21 |
| 22 namespace { |
| 23 // Pyro firmware currently reports it has a stylus but it does not. |
| 24 // TODO(jdufault): Remove this once firmware is fixed. See b/36367810. |
| 25 const char* kBlacklistedDevices[] = {"pyro"}; |
| 26 |
| 27 bool IsBlacklisted(const std::string& name) { |
| 28 return std::find(std::begin(kBlacklistedDevices), |
| 29 std::end(kBlacklistedDevices), |
| 30 name) != std::end(kBlacklistedDevices); |
| 31 } |
| 32 } // namespace |
| 33 |
| 21 bool HasStylusInput() { | 34 bool HasStylusInput() { |
| 22 // Allow the user to force-enable by passing a switch. | 35 // Allow the user to force enable or disable by passing a switch. If both are |
| 36 // present, enabling takes precedence over disabling. |
| 23 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 37 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 24 switches::kAshForceEnablePalette)) { | 38 switches::kAshForceEnablePalette)) { |
| 25 return true; | 39 return true; |
| 26 } | 40 } |
| 27 | 41 |
| 42 // Disable stylus for any blacklisted devices. |
| 43 if (IsBlacklisted(base::SysInfo::GetLsbReleaseBoard())) |
| 44 return false; |
| 45 |
| 46 // Check to see if the hardware reports it is stylus capable. |
| 28 for (const ui::TouchscreenDevice& device : | 47 for (const ui::TouchscreenDevice& device : |
| 29 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices()) { | 48 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices()) { |
| 30 if (device.is_stylus && | 49 if (device.is_stylus && |
| 31 device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) { | 50 device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) { |
| 32 return true; | 51 return true; |
| 33 } | 52 } |
| 34 } | 53 } |
| 35 | 54 |
| 36 return false; | 55 return false; |
| 37 } | 56 } |
| 38 | 57 |
| 39 bool IsPaletteEnabledOnEveryDisplay() { | 58 bool IsPaletteEnabledOnEveryDisplay() { |
| 40 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 59 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 41 switches::kAshEnablePaletteOnAllDisplays); | 60 switches::kAshEnablePaletteOnAllDisplays); |
| 42 } | 61 } |
| 43 | 62 |
| 44 bool PaletteContainsPointInScreen(const gfx::Point& point) { | 63 bool PaletteContainsPointInScreen(const gfx::Point& point) { |
| 45 for (WmWindow* window : WmShell::Get()->GetAllRootWindows()) { | 64 for (WmWindow* window : WmShell::Get()->GetAllRootWindows()) { |
| 46 PaletteTray* palette_tray = | 65 PaletteTray* palette_tray = |
| 47 WmShelf::ForWindow(window)->GetStatusAreaWidget()->palette_tray(); | 66 WmShelf::ForWindow(window)->GetStatusAreaWidget()->palette_tray(); |
| 48 if (palette_tray && palette_tray->ContainsPointInScreen(point)) | 67 if (palette_tray && palette_tray->ContainsPointInScreen(point)) |
| 49 return true; | 68 return true; |
| 50 } | 69 } |
| 51 | 70 |
| 52 return false; | 71 return false; |
| 53 } | 72 } |
| 54 | 73 |
| 55 } // namespace palette_utils | 74 } // namespace palette_utils |
| 56 } // namespace ash | 75 } // namespace ash |
| OLD | NEW |