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

Side by Side Diff: ash/shelf/wm_shelf.cc

Issue 2889673002: chromeos: Refactor shelf to create ShelfView earlier in startup (Closed)
Patch Set: rebase Created 3 years, 7 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/shelf/wm_shelf.h" 5 #include "ash/shelf/wm_shelf.h"
6 6
7 #include "ash/public/cpp/config.h" 7 #include "ash/public/cpp/config.h"
8 #include "ash/public/cpp/shelf_item_delegate.h" 8 #include "ash/public/cpp/shelf_item_delegate.h"
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
11 #include "ash/session/session_controller.h" 11 #include "ash/session/session_controller.h"
12 #include "ash/shelf/shelf_bezel_event_handler.h" 12 #include "ash/shelf/shelf_bezel_event_handler.h"
13 #include "ash/shelf/shelf_controller.h" 13 #include "ash/shelf/shelf_controller.h"
14 #include "ash/shelf/shelf_layout_manager.h" 14 #include "ash/shelf/shelf_layout_manager.h"
15 #include "ash/shelf/shelf_locking_manager.h"
16 #include "ash/shelf/shelf_model.h" 15 #include "ash/shelf/shelf_model.h"
17 #include "ash/shelf/shelf_widget.h" 16 #include "ash/shelf/shelf_widget.h"
18 #include "ash/shelf/wm_shelf_observer.h" 17 #include "ash/shelf/wm_shelf_observer.h"
19 #include "ash/shell.h" 18 #include "ash/shell.h"
20 #include "ash/wm_window.h" 19 #include "ash/wm_window.h"
21 #include "base/logging.h" 20 #include "base/logging.h"
22 #include "base/memory/ptr_util.h" 21 #include "base/memory/ptr_util.h"
23 #include "ui/display/types/display_constants.h" 22 #include "ui/display/types/display_constants.h"
24 #include "ui/gfx/geometry/rect.h" 23 #include "ui/gfx/geometry/rect.h"
25 24
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 event, static_cast<aura::Window*>(event->target())); 56 event, static_cast<aura::Window*>(event->target()));
58 } 57 }
59 58
60 private: 59 private:
61 ShelfLayoutManager* shelf_layout_manager_; 60 ShelfLayoutManager* shelf_layout_manager_;
62 DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler); 61 DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler);
63 }; 62 };
64 63
65 // WmShelf --------------------------------------------------------------------- 64 // WmShelf ---------------------------------------------------------------------
66 65
67 WmShelf::WmShelf() {} 66 WmShelf::WmShelf() : shelf_locking_manager_(this) {
67 // TODO: ShelfBezelEventHandler needs to work with mus too.
68 // http://crbug.com/636647
69 if (Shell::GetAshConfig() != Config::MASH)
70 bezel_event_handler_ = base::MakeUnique<ShelfBezelEventHandler>(this);
71 }
68 72
69 WmShelf::~WmShelf() {} 73 WmShelf::~WmShelf() {}
70 74
71 // static 75 // static
72 WmShelf* WmShelf::ForWindow(WmWindow* window) { 76 WmShelf* WmShelf::ForWindow(WmWindow* window) {
73 return window->GetRootWindowController()->GetShelf(); 77 return window->GetRootWindowController()->GetShelf();
74 } 78 }
75 79
76 // static 80 // static
77 bool WmShelf::CanChangeShelfAlignment() { 81 bool WmShelf::CanChangeShelfAlignment() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 DCHECK(!shelf_layout_manager_); 114 DCHECK(!shelf_layout_manager_);
111 shelf_layout_manager_ = shelf_widget_->shelf_layout_manager(); 115 shelf_layout_manager_ = shelf_widget_->shelf_layout_manager();
112 shelf_layout_manager_->AddObserver(this); 116 shelf_layout_manager_->AddObserver(this);
113 117
114 // Must occur after |shelf_widget_| is constructed because the system tray 118 // Must occur after |shelf_widget_| is constructed because the system tray
115 // constructors call back into WmShelf::shelf_widget(). 119 // constructors call back into WmShelf::shelf_widget().
116 DCHECK(!shelf_widget_->status_area_widget()); 120 DCHECK(!shelf_widget_->status_area_widget());
117 WmWindow* status_container = 121 WmWindow* status_container =
118 root->GetChildByShellWindowId(kShellWindowId_StatusContainer); 122 root->GetChildByShellWindowId(kShellWindowId_StatusContainer);
119 shelf_widget_->CreateStatusAreaWidget(status_container); 123 shelf_widget_->CreateStatusAreaWidget(status_container);
120
121 // TODO: ShelfBezelEventHandler needs to work with mus too.
122 // http://crbug.com/636647
123 if (Shell::GetAshConfig() != Config::MASH)
124 bezel_event_handler_ = base::MakeUnique<ShelfBezelEventHandler>(this);
125 } 124 }
126 125
127 void WmShelf::ShutdownShelfWidget() { 126 void WmShelf::ShutdownShelfWidget() {
128 if (shelf_widget_) 127 if (shelf_widget_)
129 shelf_widget_->Shutdown(); 128 shelf_widget_->Shutdown();
130 } 129 }
131 130
132 void WmShelf::DestroyShelfWidget() { 131 void WmShelf::DestroyShelfWidget() {
133 shelf_widget_.reset(); 132 shelf_widget_.reset();
134 } 133 }
135 134
136 void WmShelf::CreateShelfView() { 135 void WmShelf::NotifyShelfInitialized() {
137 DCHECK(shelf_layout_manager_); 136 DCHECK(shelf_layout_manager_);
138 DCHECK(shelf_widget_); 137 DCHECK(shelf_widget_);
139 DCHECK(!shelf_view_); 138 Shell::Get()->shelf_controller()->NotifyShelfInitialized(this);
140 shelf_view_ = shelf_widget_->CreateShelfView();
141 shelf_locking_manager_.reset(new ShelfLockingManager(this));
142 Shell::Get()->shelf_controller()->NotifyShelfCreated(this);
143 }
144
145 void WmShelf::ShutdownShelf() {
146 DCHECK(shelf_view_);
147 shelf_locking_manager_.reset();
148 shelf_view_ = nullptr;
149 }
150
151 bool WmShelf::IsShelfInitialized() const {
152 return !!shelf_view_;
153 } 139 }
154 140
155 WmWindow* WmShelf::GetWindow() { 141 WmWindow* WmShelf::GetWindow() {
156 return WmWindow::Get(shelf_widget_->GetNativeWindow()); 142 return WmWindow::Get(shelf_widget_->GetNativeWindow());
157 } 143 }
158 144
159 void WmShelf::SetAlignment(ShelfAlignment alignment) { 145 void WmShelf::SetAlignment(ShelfAlignment alignment) {
160 DCHECK(shelf_layout_manager_); 146 DCHECK(shelf_layout_manager_);
161 DCHECK(shelf_locking_manager_);
162 147
163 if (alignment_ == alignment) 148 if (alignment_ == alignment)
164 return; 149 return;
165 150
166 if (shelf_locking_manager_->is_locked() && 151 if (shelf_locking_manager_.is_locked() &&
167 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { 152 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) {
168 shelf_locking_manager_->set_stored_alignment(alignment); 153 shelf_locking_manager_.set_stored_alignment(alignment);
169 return; 154 return;
170 } 155 }
171 156
172 alignment_ = alignment; 157 alignment_ = alignment;
173 // The ShelfWidget notifies the ShelfView of the alignment change. 158 // The ShelfWidget notifies the ShelfView of the alignment change.
174 shelf_widget_->OnShelfAlignmentChanged(); 159 shelf_widget_->OnShelfAlignmentChanged();
175 shelf_layout_manager_->LayoutShelf(); 160 shelf_layout_manager_->LayoutShelf();
176 Shell::Get()->shelf_controller()->NotifyShelfAlignmentChanged(this); 161 Shell::Get()->shelf_controller()->NotifyShelfAlignmentChanged(this);
177 Shell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); 162 Shell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow());
178 } 163 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 212 }
228 213
229 void WmShelf::UpdateAutoHideState() { 214 void WmShelf::UpdateAutoHideState() {
230 shelf_layout_manager_->UpdateAutoHideState(); 215 shelf_layout_manager_->UpdateAutoHideState();
231 } 216 }
232 217
233 ShelfBackgroundType WmShelf::GetBackgroundType() const { 218 ShelfBackgroundType WmShelf::GetBackgroundType() const {
234 return shelf_widget_->GetBackgroundType(); 219 return shelf_widget_->GetBackgroundType();
235 } 220 }
236 221
237 bool WmShelf::IsVisible() const {
238 return shelf_widget_->IsShelfVisible();
239 }
240
241 void WmShelf::UpdateVisibilityState() { 222 void WmShelf::UpdateVisibilityState() {
242 if (shelf_layout_manager_) 223 if (shelf_layout_manager_)
243 shelf_layout_manager_->UpdateVisibilityState(); 224 shelf_layout_manager_->UpdateVisibilityState();
244 } 225 }
245 226
246 ShelfVisibilityState WmShelf::GetVisibilityState() const { 227 ShelfVisibilityState WmShelf::GetVisibilityState() const {
247 return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state() 228 return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state()
248 : SHELF_HIDDEN; 229 : SHELF_HIDDEN;
249 } 230 }
250 231
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 307
327 StatusAreaWidget* WmShelf::GetStatusAreaWidget() const { 308 StatusAreaWidget* WmShelf::GetStatusAreaWidget() const {
328 return shelf_widget_->status_area_widget(); 309 return shelf_widget_->status_area_widget();
329 } 310 }
330 311
331 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { 312 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) {
332 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); 313 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds);
333 } 314 }
334 315
335 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { 316 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() {
336 return shelf_locking_manager_.get(); 317 return &shelf_locking_manager_;
337 } 318 }
338 319
339 ShelfView* WmShelf::GetShelfViewForTesting() { 320 ShelfView* WmShelf::GetShelfViewForTesting() {
340 return shelf_view_; 321 return shelf_widget_->shelf_view_for_testing();
341 } 322 }
342 323
343 void WmShelf::WillDeleteShelfLayoutManager() { 324 void WmShelf::WillDeleteShelfLayoutManager() {
344 if (Shell::GetAshConfig() == Config::MASH) { 325 if (Shell::GetAshConfig() == Config::MASH) {
345 // TODO(sky): this should be removed once Shell is used everywhere. 326 // TODO(sky): this should be removed once Shell is used everywhere.
346 ShutdownShelfWidget(); 327 ShutdownShelfWidget();
347 } 328 }
348 329
349 // Clear event handlers that might forward events to the destroyed instance. 330 // Clear event handlers that might forward events to the destroyed instance.
350 auto_hide_event_handler_.reset(); 331 auto_hide_event_handler_.reset();
(...skipping 23 matching lines...) Expand all
374 355
375 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, 356 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type,
376 AnimationChangeType change_type) { 357 AnimationChangeType change_type) {
377 if (background_type == GetBackgroundType()) 358 if (background_type == GetBackgroundType())
378 return; 359 return;
379 for (auto& observer : observers_) 360 for (auto& observer : observers_)
380 observer.OnBackgroundTypeChanged(background_type, change_type); 361 observer.OnBackgroundTypeChanged(background_type, change_type);
381 } 362 }
382 363
383 } // namespace ash 364 } // namespace ash
OLDNEW
« ash/shelf/shelf_widget_unittest.cc ('K') | « ash/shelf/wm_shelf.h ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698