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

Side by Side Diff: ash/aura/wm_shelf_aura.cc

Issue 2247503002: mash: Create and show a shelf in mash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup. Created 4 years, 4 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/aura/wm_shelf_aura.h" 5 #include "ash/aura/wm_shelf_aura.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/shelf/wm_shelf_observer.h"
9 #include "ash/common/wm_window.h"
10 #include "ash/shelf/dimmer_view.h" 8 #include "ash/shelf/dimmer_view.h"
11 #include "ash/shelf/shelf.h"
12 #include "ash/shelf/shelf_bezel_event_handler.h" 9 #include "ash/shelf/shelf_bezel_event_handler.h"
13 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
14 #include "ash/shell.h" 11 #include "ash/shell.h"
15 #include "ui/views/widget/widget.h"
16 12
17 namespace ash { 13 namespace ash {
18 14
19 // WmShelfAura::AutoHideEventHandler ------------------------------------------- 15 // WmShelfAura::AutoHideEventHandler -------------------------------------------
20 16
21 // Forwards mouse and gesture events to ShelfLayoutManager for auto-hide. 17 // Forwards mouse and gesture events to ShelfLayoutManager for auto-hide.
22 // TODO(mash): Add similar event handling support for mash. 18 // TODO(mash): Add similar event handling support for mash.
23 class WmShelfAura::AutoHideEventHandler : public ui::EventHandler { 19 class WmShelfAura::AutoHideEventHandler : public ui::EventHandler {
24 public: 20 public:
25 explicit AutoHideEventHandler(ShelfLayoutManager* shelf_layout_manager) 21 explicit AutoHideEventHandler(ShelfLayoutManager* shelf_layout_manager)
(...skipping 18 matching lines...) Expand all
44 ShelfLayoutManager* shelf_layout_manager_; 40 ShelfLayoutManager* shelf_layout_manager_;
45 DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler); 41 DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler);
46 }; 42 };
47 43
48 // WmShelfAura ----------------------------------------------------------------- 44 // WmShelfAura -----------------------------------------------------------------
49 45
50 WmShelfAura::WmShelfAura() {} 46 WmShelfAura::WmShelfAura() {}
51 47
52 WmShelfAura::~WmShelfAura() {} 48 WmShelfAura::~WmShelfAura() {}
53 49
54 void WmShelfAura::SetShelfLayoutManager(
55 ShelfLayoutManager* shelf_layout_manager) {
56 DCHECK(!shelf_layout_manager_);
57 shelf_layout_manager_ = shelf_layout_manager;
58 shelf_layout_manager_->AddObserver(this);
59 bezel_event_handler_.reset(new ShelfBezelEventHandler(this));
60 }
61
62 void WmShelfAura::SetShelf(Shelf* shelf) {
63 DCHECK(!shelf_);
64 shelf_ = shelf;
65 shelf_->AddIconObserver(this);
66 }
67
68 void WmShelfAura::Shutdown() {
69 if (shelf_) {
70 shelf_->RemoveIconObserver(this);
71 shelf_ = nullptr;
72 }
73
74 ResetShelfLayoutManager();
75 }
76
77 // static
78 Shelf* WmShelfAura::GetShelf(WmShelf* shelf) {
79 return static_cast<WmShelfAura*>(shelf)->shelf_;
80 }
81
82 void WmShelfAura::ResetShelfLayoutManager() {
83 if (!shelf_layout_manager_)
84 return;
85 // Clear event handlers that might otherwise forward events during shutdown.
86 auto_hide_event_handler_.reset();
87 bezel_event_handler_.reset();
88 shelf_layout_manager_->RemoveObserver(this);
89 shelf_layout_manager_ = nullptr;
90 }
91
92 WmWindow* WmShelfAura::GetWindow() {
93 // Use |shelf_layout_manager_| to access ShelfWidget because it is set
94 // before |shelf_| is available.
95 return WmWindowAura::Get(
96 shelf_layout_manager_->shelf_widget()->GetNativeView());
97 }
98
99 ShelfAlignment WmShelfAura::GetAlignment() const {
100 // Can be called before |shelf_| is set when initializing a secondary monitor.
101 return shelf_ ? shelf_->alignment() : SHELF_ALIGNMENT_BOTTOM_LOCKED;
102 }
103
104 void WmShelfAura::SetAlignment(ShelfAlignment alignment) {
105 shelf_->SetAlignment(alignment);
106 }
107
108 ShelfAutoHideBehavior WmShelfAura::GetAutoHideBehavior() const {
109 return shelf_->auto_hide_behavior();
110 }
111
112 void WmShelfAura::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) {
113 shelf_->SetAutoHideBehavior(behavior);
114 }
115
116 ShelfAutoHideState WmShelfAura::GetAutoHideState() const {
117 return shelf_layout_manager_->auto_hide_state();
118 }
119
120 void WmShelfAura::UpdateAutoHideState() {
121 shelf_layout_manager_->UpdateAutoHideState();
122 }
123
124 ShelfBackgroundType WmShelfAura::GetBackgroundType() const {
125 return shelf_layout_manager_->shelf_widget()->GetBackgroundType();
126 }
127
128 WmDimmerView* WmShelfAura::CreateDimmerView(bool disable_animations_for_test) { 50 WmDimmerView* WmShelfAura::CreateDimmerView(bool disable_animations_for_test) {
129 return DimmerView::Create(this, disable_animations_for_test); 51 return DimmerView::Create(this, disable_animations_for_test);
130 } 52 }
131 53
132 bool WmShelfAura::IsDimmed() const { 54 void WmShelfAura::SetShelfLayoutManager(ShelfLayoutManager* manager) {
James Cook 2016/08/16 23:21:35 I suspect this only needs to be called once to set
msw 2016/08/17 01:09:01 Done. (I wrote ClearShelfLayoutManager, but then d
133 return shelf_layout_manager_->shelf_widget()->GetDimsShelf(); 55 if (shelf_layout_manager()) {
134 } 56 // Clear event handlers that might forward events to the destroyed instance.
57 auto_hide_event_handler_.reset();
58 bezel_event_handler_.reset();
59 }
135 60
136 void WmShelfAura::SchedulePaint() { 61 WmShelf::SetShelfLayoutManager(manager);
137 // Can be called during shutdown if the overflow bubble is visible.
138 if (shelf_)
139 shelf_->SchedulePaint();
140 }
141 62
142 bool WmShelfAura::IsVisible() const { 63 if (manager)
143 return shelf_->IsVisible(); 64 bezel_event_handler_.reset(new ShelfBezelEventHandler(this));
James Cook 2016/08/16 23:21:34 Do you need to reconstruct the auto_hide_event_fil
msw 2016/08/17 01:09:01 I don't think so; that's created on WillChangeVisi
144 }
145
146 void WmShelfAura::UpdateVisibilityState() {
147 if (shelf_layout_manager_)
148 shelf_layout_manager_->UpdateVisibilityState();
149 }
150
151 ShelfVisibilityState WmShelfAura::GetVisibilityState() const {
152 return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state()
153 : SHELF_HIDDEN;
154 }
155
156 gfx::Rect WmShelfAura::GetIdealBounds() {
157 return shelf_layout_manager_->GetIdealBounds();
158 }
159
160 gfx::Rect WmShelfAura::GetUserWorkAreaBounds() const {
161 return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds()
162 : gfx::Rect();
163 }
164
165 void WmShelfAura::UpdateIconPositionForWindow(WmWindow* window) {
166 shelf_->UpdateIconPositionForWindow(window);
167 }
168
169 gfx::Rect WmShelfAura::GetScreenBoundsOfItemIconForWindow(WmWindow* window) {
170 return shelf_->GetScreenBoundsOfItemIconForWindow(window);
171 }
172
173 bool WmShelfAura::ProcessGestureEvent(const ui::GestureEvent& event) {
174 // Can be called at login screen.
175 if (!shelf_layout_manager_)
176 return false;
177 return shelf_layout_manager_->ProcessGestureEvent(event);
178 }
179
180 void WmShelfAura::AddObserver(WmShelfObserver* observer) {
181 observers_.AddObserver(observer);
182 }
183
184 void WmShelfAura::RemoveObserver(WmShelfObserver* observer) {
185 observers_.RemoveObserver(observer);
186 }
187
188 void WmShelfAura::SetKeyboardBoundsForTesting(const gfx::Rect& bounds) {
189 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds);
190 }
191
192 ShelfLockingManager* WmShelfAura::GetShelfLockingManagerForTesting() {
193 return shelf_->shelf_locking_manager_for_testing();
194 }
195
196 ShelfView* WmShelfAura::GetShelfViewForTesting() {
197 return shelf_->shelf_view_for_testing();
198 }
199
200 void WmShelfAura::WillDeleteShelfLayoutManager() {
201 ResetShelfLayoutManager();
202 }
203
204 void WmShelfAura::OnBackgroundUpdated(
205 ShelfBackgroundType background_type,
206 BackgroundAnimatorChangeType change_type) {
207 if (background_type == GetBackgroundType())
208 return;
209 FOR_EACH_OBSERVER(WmShelfObserver, observers_,
210 OnBackgroundTypeChanged(background_type, change_type));
211 } 65 }
212 66
213 void WmShelfAura::WillChangeVisibilityState(ShelfVisibilityState new_state) { 67 void WmShelfAura::WillChangeVisibilityState(ShelfVisibilityState new_state) {
214 FOR_EACH_OBSERVER(WmShelfObserver, observers_, 68 WmShelf::WillChangeVisibilityState(new_state);
215 WillChangeVisibilityState(new_state));
216
217 if (new_state != SHELF_AUTO_HIDE) { 69 if (new_state != SHELF_AUTO_HIDE) {
218 auto_hide_event_handler_.reset(); 70 auto_hide_event_handler_.reset();
219 } else if (!auto_hide_event_handler_) { 71 } else if (!auto_hide_event_handler_) {
220 auto_hide_event_handler_.reset( 72 auto_hide_event_handler_.reset(
221 new AutoHideEventHandler(shelf_layout_manager_)); 73 new AutoHideEventHandler(shelf_layout_manager()));
222 } 74 }
223 } 75 }
224 76
225 void WmShelfAura::OnAutoHideStateChanged(ShelfAutoHideState new_state) {
226 FOR_EACH_OBSERVER(WmShelfObserver, observers_,
227 OnAutoHideStateChanged(new_state));
228 }
229
230 void WmShelfAura::OnShelfIconPositionsChanged() {
231 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged());
232 }
233
234 } // namespace ash 77 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698