| 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/system/palette/palette_utils.h" | 5 #include "ash/system/palette/palette_utils.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/palette_delegate.h" |
| 8 #include "ash/shelf/wm_shelf.h" | 9 #include "ash/shelf/wm_shelf.h" |
| 10 #include "ash/shell.h" |
| 9 #include "ash/shell_port.h" | 11 #include "ash/shell_port.h" |
| 10 #include "ash/system/palette/palette_tray.h" | 12 #include "ash/system/palette/palette_tray.h" |
| 11 #include "ash/system/status_area_widget.h" | 13 #include "ash/system/status_area_widget.h" |
| 12 #include "ash/wm_window.h" | 14 #include "ash/wm_window.h" |
| 13 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "ui/display/display.h" |
| 14 #include "ui/events/devices/input_device_manager.h" | 17 #include "ui/events/devices/input_device_manager.h" |
| 15 #include "ui/events/devices/touchscreen_device.h" | 18 #include "ui/events/devices/touchscreen_device.h" |
| 16 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
| 17 | 20 |
| 18 namespace ash { | 21 namespace ash { |
| 19 namespace palette_utils { | 22 namespace palette_utils { |
| 20 | 23 |
| 21 bool HasStylusInput() { | 24 bool HasStylusInput() { |
| 22 // Allow the user to force enable or disable by passing a switch. If both are | 25 // Allow the user to force enable or disable by passing a switch. If both are |
| 23 // present, enabling takes precedence over disabling. | 26 // present, enabling takes precedence over disabling. |
| 24 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 27 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 25 switches::kAshForceEnablePalette)) { | 28 switches::kAshForceEnableStylusTools)) { |
| 26 return true; | 29 return true; |
| 27 } | 30 } |
| 28 | 31 |
| 29 // Check to see if the hardware reports it is stylus capable. | 32 // Check to see if the hardware reports it is stylus capable. |
| 30 for (const ui::TouchscreenDevice& device : | 33 for (const ui::TouchscreenDevice& device : |
| 31 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices()) { | 34 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices()) { |
| 32 if (device.is_stylus && | 35 if (device.is_stylus && |
| 33 device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) { | 36 device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) { |
| 34 return true; | 37 return true; |
| 35 } | 38 } |
| 36 } | 39 } |
| 37 | 40 |
| 38 return false; | 41 return false; |
| 39 } | 42 } |
| 40 | 43 |
| 41 bool IsPaletteEnabledOnEveryDisplay() { | 44 bool IsPaletteEnabledOnEveryDisplay() { |
| 42 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 45 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 43 switches::kAshEnablePaletteOnAllDisplays); | 46 switches::kAshEnablePaletteOnAllDisplays); |
| 44 } | 47 } |
| 45 | 48 |
| 49 bool ShouldShowPalette() { |
| 50 return HasStylusInput() && |
| 51 (display::Display::HasInternalDisplay() || |
| 52 IsPaletteEnabledOnEveryDisplay()) && |
| 53 Shell::Get()->palette_delegate() && |
| 54 Shell::Get()->palette_delegate()->ShouldShowPalette(); |
| 55 } |
| 56 |
| 46 bool PaletteContainsPointInScreen(const gfx::Point& point) { | 57 bool PaletteContainsPointInScreen(const gfx::Point& point) { |
| 47 for (WmWindow* window : ShellPort::Get()->GetAllRootWindows()) { | 58 for (WmWindow* window : ShellPort::Get()->GetAllRootWindows()) { |
| 48 PaletteTray* palette_tray = | 59 PaletteTray* palette_tray = |
| 49 WmShelf::ForWindow(window)->GetStatusAreaWidget()->palette_tray(); | 60 WmShelf::ForWindow(window)->GetStatusAreaWidget()->palette_tray(); |
| 50 if (palette_tray && palette_tray->ContainsPointInScreen(point)) | 61 if (palette_tray && palette_tray->ContainsPointInScreen(point)) |
| 51 return true; | 62 return true; |
| 52 } | 63 } |
| 53 | 64 |
| 54 return false; | 65 return false; |
| 55 } | 66 } |
| 56 | 67 |
| 57 } // namespace palette_utils | 68 } // namespace palette_utils |
| 58 } // namespace ash | 69 } // namespace ash |
| OLD | NEW |