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

Side by Side Diff: ash/system/palette/palette_utils.cc

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

Powered by Google App Engine
This is Rietveld 408576698