OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_PALETTE_BUTTON_TRAY_H_ | |
6 #define ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_PALETTE_BUTTON_TRAY_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 | |
11 #include "ash/ash_export.h" | |
12 #include "ash/common/palette_delegate.h" | |
13 #include "ash/common/session/session_state_observer.h" | |
14 #include "ash/common/shell_observer.h" | |
15 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" | |
16 #include "ash/common/system/tray/tray_background_view.h" | |
17 #include "base/macros.h" | |
18 #include "base/memory/weak_ptr.h" | |
19 #include "ui/events/devices/input_device_event_observer.h" | |
20 | |
21 namespace gfx { | |
22 class Point; | |
23 } | |
24 | |
25 namespace views { | |
26 class ImageView; | |
27 class Widget; | |
28 } | |
29 | |
30 namespace ash { | |
31 | |
32 class TrayBubbleWrapper; | |
33 class PaletteToolManager; | |
34 | |
35 // The PaletteTray shows the palette in the bottom area of the screen. This | |
36 // class also controls the lifetime for all of the tools available in the | |
37 // palette. | |
38 class ASH_EXPORT PaletteTray : public TrayBackgroundView, | |
39 public SessionStateObserver, | |
40 public ShellObserver, | |
41 public PaletteToolManager::Delegate, | |
42 public ui::InputDeviceEventObserver, | |
43 public views::TrayBubbleView::Delegate { | |
44 public: | |
45 explicit PaletteTray(WmShelf* wm_shelf); | |
46 ~PaletteTray() override; | |
47 | |
48 // ActionableView: | |
49 bool PerformAction(const ui::Event& event) override; | |
50 | |
51 // SessionStateObserver: | |
52 void SessionStateChanged(session_manager::SessionState state) override; | |
53 | |
54 // ShellObserver: | |
55 void OnLockStateChanged(bool locked) override; | |
56 | |
57 // TrayBackgroundView: | |
58 void ClickedOutsideBubble() override; | |
59 base::string16 GetAccessibleNameForTray() override; | |
60 void HideBubbleWithView(const views::TrayBubbleView* bubble_view) override; | |
61 void SetShelfAlignment(ShelfAlignment alignment) override; | |
62 void AnchorUpdated() override; | |
63 void Initialize() override; | |
64 | |
65 // PaletteToolManager::Delegate: | |
66 void HidePalette() override; | |
67 void HidePaletteImmediately() override; | |
68 void RecordPaletteOptionsUsage(PaletteTrayOptions option) override; | |
69 void RecordPaletteModeCancellation(PaletteModeCancelType type) override; | |
70 | |
71 // Returns true if the shelf should not autohide. | |
72 bool ShouldBlockShelfAutoHide() const; | |
73 | |
74 // Opens up the palette if it is not already open. Returns true if the palette | |
75 // was opened. | |
76 bool ShowPalette(); | |
77 | |
78 // Returns true if the palette tray contains the given point. This is useful | |
79 // for determining if an event should be propagated through to the palette. | |
80 bool ContainsPointInScreen(const gfx::Point& point); | |
81 | |
82 private: | |
83 // ui::InputDeviceObserver: | |
84 void OnTouchscreenDeviceConfigurationChanged() override; | |
85 void OnStylusStateChanged(ui::StylusState stylus_state) override; | |
86 | |
87 // views::TrayBubbleView::Delegate: | |
88 void BubbleViewDestroyed() override; | |
89 void OnMouseEnteredView() override; | |
90 void OnMouseExitedView() override; | |
91 base::string16 GetAccessibleNameForBubble() override; | |
92 void OnBeforeBubbleWidgetInit( | |
93 views::Widget* anchor_widget, | |
94 views::Widget* bubble_widget, | |
95 views::Widget::InitParams* params) const override; | |
96 void HideBubble(const views::TrayBubbleView* bubble_view) override; | |
97 | |
98 // PaletteToolManager::Delegate: | |
99 void OnActiveToolChanged() override; | |
100 WmWindow* GetWindow() override; | |
101 | |
102 // Updates the tray icon from the palette tool manager. | |
103 void UpdateTrayIcon(); | |
104 | |
105 // Sets the icon to visible if the palette can be used. | |
106 void UpdateIconVisibility(); | |
107 | |
108 // Called when the palette enabled pref has changed. | |
109 void OnPaletteEnabledPrefChanged(bool enabled); | |
110 | |
111 std::unique_ptr<PaletteToolManager> palette_tool_manager_; | |
112 std::unique_ptr<TrayBubbleWrapper> bubble_; | |
113 | |
114 // Manages the callback OnPaletteEnabledPrefChanged callback registered to | |
115 // the PaletteDelegate instance. | |
116 std::unique_ptr<PaletteDelegate::EnableListenerSubscription> | |
117 palette_enabled_subscription_; | |
118 | |
119 // Weak pointer, will be parented by TrayContainer for its lifetime. | |
120 views::ImageView* icon_; | |
121 | |
122 // The shelf auto-hide state is checked during the tray constructor, so we | |
123 // have to use a helper variable instead of just checking if we have a tray | |
124 // instance. | |
125 bool should_block_shelf_auto_hide_ = false; | |
126 | |
127 // Cached palette enabled/disabled pref value. | |
128 bool is_palette_enabled_ = true; | |
129 | |
130 // Used to indicate whether the palette bubble is automatically opened by a | |
131 // stylus eject event. | |
132 bool is_bubble_auto_opened_ = false; | |
133 | |
134 // Number of actions in pen palette bubble. | |
135 int num_actions_in_bubble_ = 0; | |
136 | |
137 base::WeakPtrFactory<PaletteTray> weak_factory_; | |
138 | |
139 DISALLOW_COPY_AND_ASSIGN(PaletteTray); | |
140 }; | |
141 | |
142 } // namespace ash | |
143 | |
144 #endif // ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_PALETTE_BUTTON_TRAY_H_ | |
OLD | NEW |