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

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

Issue 2304443002: ash: Move ShelfWidget ownership to WmShelf and refactor access to it (Closed)
Patch Set: review comments Created 4 years, 3 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/common/shelf/shelf_delegate.h" 5 #include "ash/common/shelf/shelf_delegate.h"
6 #include "ash/common/shelf/shelf_item_delegate.h" 6 #include "ash/common/shelf/shelf_item_delegate.h"
7 #include "ash/common/shelf/shelf_layout_manager.h" 7 #include "ash/common/shelf/shelf_layout_manager.h"
8 #include "ash/common/shelf/shelf_locking_manager.h" 8 #include "ash/common/shelf/shelf_locking_manager.h"
9 #include "ash/common/shelf/shelf_model.h" 9 #include "ash/common/shelf/shelf_model.h"
10 #include "ash/common/shelf/shelf_widget.h" 10 #include "ash/common/shelf/shelf_widget.h"
11 #include "ash/common/shelf/wm_shelf.h" 11 #include "ash/common/shelf/wm_shelf.h"
12 #include "ash/common/shelf/wm_shelf_observer.h" 12 #include "ash/common/shelf/wm_shelf_observer.h"
13 #include "ash/common/shell_window_ids.h"
13 #include "ash/common/wm_lookup.h" 14 #include "ash/common/wm_lookup.h"
14 #include "ash/common/wm_root_window_controller.h" 15 #include "ash/common/wm_root_window_controller.h"
15 #include "ash/common/wm_shell.h" 16 #include "ash/common/wm_shell.h"
16 #include "ash/common/wm_window.h" 17 #include "ash/common/wm_window.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "ui/gfx/geometry/rect.h" 19 #include "ui/gfx/geometry/rect.h"
19 20
20 namespace ash { 21 namespace ash {
21 22
22 // static 23 // static
23 WmShelf* WmShelf::ForWindow(WmWindow* window) { 24 WmShelf* WmShelf::ForWindow(WmWindow* window) {
24 return window->GetRootWindowController()->GetShelf(); 25 return window->GetRootWindowController()->GetShelf();
25 } 26 }
26 27
27 void WmShelf::SetShelfLayoutManager(ShelfLayoutManager* manager) { 28 void WmShelf::CreateShelfWidget(WmWindow* root) {
29 DCHECK(!shelf_widget_);
30 WmWindow* shelf_container =
31 root->GetChildByShellWindowId(kShellWindowId_ShelfContainer);
32 shelf_widget_.reset(new ShelfWidget(shelf_container, this));
33
28 DCHECK(!shelf_layout_manager_); 34 DCHECK(!shelf_layout_manager_);
29 DCHECK(manager); 35 shelf_layout_manager_ = shelf_widget_->shelf_layout_manager();
30 shelf_layout_manager_ = manager;
31 shelf_layout_manager_->AddObserver(this); 36 shelf_layout_manager_->AddObserver(this);
32 DCHECK(manager->shelf_widget()); 37
33 shelf_widget_ = manager->shelf_widget(); 38 // Must occur after |shelf_widget_| is constructed because the system tray
39 // constructors call back into WmShelf::shelf_widget().
40 DCHECK(!shelf_widget_->status_area_widget());
41 WmWindow* status_container =
42 root->GetChildByShellWindowId(kShellWindowId_StatusContainer);
43 shelf_widget_->CreateStatusAreaWidget(status_container);
44 }
45
46 void WmShelf::ShutdownShelfWidget() {
47 if (shelf_widget_)
48 shelf_widget_->Shutdown();
49 }
50
51 void WmShelf::DestroyShelfWidget() {
52 shelf_widget_.reset();
34 } 53 }
35 54
36 void WmShelf::InitializeShelf() { 55 void WmShelf::InitializeShelf() {
37 DCHECK(shelf_layout_manager_); 56 DCHECK(shelf_layout_manager_);
38 DCHECK(shelf_widget_); 57 DCHECK(shelf_widget_);
39 DCHECK(!shelf_view_); 58 DCHECK(!shelf_view_);
40 shelf_view_ = shelf_widget_->CreateShelfView(); 59 shelf_view_ = shelf_widget_->CreateShelfView();
41 shelf_locking_manager_.reset(new ShelfLockingManager(this)); 60 shelf_locking_manager_.reset(new ShelfLockingManager(this));
42 // When the shelf is created the alignment is unlocked. Chrome will update the 61 // When the shelf is created the alignment is unlocked. Chrome will update the
43 // alignment later from preferences. 62 // alignment later from preferences.
44 alignment_ = SHELF_ALIGNMENT_BOTTOM; 63 alignment_ = SHELF_ALIGNMENT_BOTTOM;
45 // NOTE: The delegate may access WmShelf. 64 // NOTE: The delegate may access WmShelf.
46 WmShell::Get()->shelf_delegate()->OnShelfCreated(this); 65 WmShell::Get()->shelf_delegate()->OnShelfCreated(this);
47 } 66 }
48 67
49 void WmShelf::ShutdownShelf() { 68 void WmShelf::ShutdownShelf() {
50 DCHECK(shelf_view_); 69 DCHECK(shelf_view_);
51 shelf_locking_manager_.reset(); 70 shelf_locking_manager_.reset();
52 shelf_view_ = nullptr; 71 shelf_view_ = nullptr;
53 WmShell::Get()->shelf_delegate()->OnShelfDestroyed(this); 72 WmShell::Get()->shelf_delegate()->OnShelfDestroyed(this);
54 } 73 }
55 74
56 bool WmShelf::IsShelfInitialized() const { 75 bool WmShelf::IsShelfInitialized() const {
57 return !!shelf_view_; 76 return !!shelf_view_;
58 } 77 }
59 78
60 WmWindow* WmShelf::GetWindow() { 79 WmWindow* WmShelf::GetWindow() {
61 // Use |shelf_layout_manager_| to access ShelfWidget because it is set before 80 return WmLookup::Get()->GetWindowForWidget(shelf_widget_.get());
62 // before the Shelf instance is available.
63 return WmLookup::Get()->GetWindowForWidget(
64 shelf_layout_manager_->shelf_widget());
65 } 81 }
66 82
67 void WmShelf::SetAlignment(ShelfAlignment alignment) { 83 void WmShelf::SetAlignment(ShelfAlignment alignment) {
68 DCHECK(shelf_layout_manager_); 84 DCHECK(shelf_layout_manager_);
69 DCHECK(shelf_locking_manager_); 85 DCHECK(shelf_locking_manager_);
70 86
71 if (alignment_ == alignment) 87 if (alignment_ == alignment)
72 return; 88 return;
73 89
74 if (shelf_locking_manager_->is_locked() && 90 if (shelf_locking_manager_->is_locked() &&
75 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { 91 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) {
76 shelf_locking_manager_->set_stored_alignment(alignment); 92 shelf_locking_manager_->set_stored_alignment(alignment);
77 return; 93 return;
78 } 94 }
79 95
80 alignment_ = alignment; 96 alignment_ = alignment;
81 // The ShelfWidget notifies the ShelfView of the alignment change. 97 // The ShelfWidget notifies the ShelfView of the alignment change.
82 shelf_layout_manager_->shelf_widget()->OnShelfAlignmentChanged(); 98 shelf_widget_->OnShelfAlignmentChanged();
83 WmShell::Get()->shelf_delegate()->OnShelfAlignmentChanged(this); 99 WmShell::Get()->shelf_delegate()->OnShelfAlignmentChanged(this);
84 WmShell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); 100 WmShell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow());
85 // ShelfLayoutManager will resize the shelf. 101 // ShelfLayoutManager will resize the shelf.
86 } 102 }
87 103
88 bool WmShelf::IsHorizontalAlignment() const { 104 bool WmShelf::IsHorizontalAlignment() const {
89 switch (alignment_) { 105 switch (alignment_) {
90 case SHELF_ALIGNMENT_BOTTOM: 106 case SHELF_ALIGNMENT_BOTTOM:
91 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 107 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
92 return true; 108 return true;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 148
133 ShelfAutoHideState WmShelf::GetAutoHideState() const { 149 ShelfAutoHideState WmShelf::GetAutoHideState() const {
134 return shelf_layout_manager_->auto_hide_state(); 150 return shelf_layout_manager_->auto_hide_state();
135 } 151 }
136 152
137 void WmShelf::UpdateAutoHideState() { 153 void WmShelf::UpdateAutoHideState() {
138 shelf_layout_manager_->UpdateAutoHideState(); 154 shelf_layout_manager_->UpdateAutoHideState();
139 } 155 }
140 156
141 ShelfBackgroundType WmShelf::GetBackgroundType() const { 157 ShelfBackgroundType WmShelf::GetBackgroundType() const {
142 return shelf_layout_manager_->shelf_widget()->GetBackgroundType(); 158 return shelf_widget_->GetBackgroundType();
143 } 159 }
144 160
145 WmDimmerView* WmShelf::CreateDimmerView(bool disable_animations_for_test) { 161 WmDimmerView* WmShelf::CreateDimmerView(bool disable_animations_for_test) {
146 return nullptr; 162 return nullptr;
147 } 163 }
148 164
149 bool WmShelf::IsDimmed() const { 165 bool WmShelf::IsDimmed() const {
150 return shelf_layout_manager_->shelf_widget()->GetDimsShelf(); 166 return shelf_widget_->GetDimsShelf();
151 } 167 }
152 168
153 bool WmShelf::IsVisible() const { 169 bool WmShelf::IsVisible() const {
154 return shelf_widget_->IsShelfVisible(); 170 return shelf_widget_->IsShelfVisible();
155 } 171 }
156 172
157 void WmShelf::UpdateVisibilityState() { 173 void WmShelf::UpdateVisibilityState() {
158 if (shelf_layout_manager_) 174 if (shelf_layout_manager_)
159 shelf_layout_manager_->UpdateVisibilityState(); 175 shelf_layout_manager_->UpdateVisibilityState();
160 } 176 }
161 177
162 ShelfVisibilityState WmShelf::GetVisibilityState() const { 178 ShelfVisibilityState WmShelf::GetVisibilityState() const {
163 return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state() 179 return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state()
164 : SHELF_HIDDEN; 180 : SHELF_HIDDEN;
165 } 181 }
166 182
167 gfx::Rect WmShelf::GetIdealBounds() { 183 gfx::Rect WmShelf::GetIdealBounds() {
168 return shelf_layout_manager_->GetIdealBounds(); 184 return shelf_layout_manager_->GetIdealBounds();
169 } 185 }
170 186
171 gfx::Rect WmShelf::GetUserWorkAreaBounds() const { 187 gfx::Rect WmShelf::GetUserWorkAreaBounds() const {
172 return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds() 188 return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds()
173 : gfx::Rect(); 189 : gfx::Rect();
174 } 190 }
175 191
176 void WmShelf::UpdateIconPositionForPanel(WmWindow* panel) { 192 void WmShelf::UpdateIconPositionForPanel(WmWindow* panel) {
177 shelf_layout_manager_->shelf_widget()->UpdateIconPositionForPanel(panel); 193 shelf_widget_->UpdateIconPositionForPanel(panel);
178 } 194 }
179 195
180 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { 196 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) {
181 if (!shelf_layout_manager_) 197 if (!shelf_widget_)
182 return gfx::Rect(); 198 return gfx::Rect();
183 return shelf_layout_manager_->shelf_widget() 199 return shelf_widget_->GetScreenBoundsOfItemIconForWindow(window);
184 ->GetScreenBoundsOfItemIconForWindow(window);
185 } 200 }
186 201
187 // static 202 // static
188 void WmShelf::LaunchShelfItem(int item_index) { 203 void WmShelf::LaunchShelfItem(int item_index) {
189 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); 204 ShelfModel* shelf_model = WmShell::Get()->shelf_model();
190 const ShelfItems& items = shelf_model->items(); 205 const ShelfItems& items = shelf_model->items();
191 int item_count = shelf_model->item_count(); 206 int item_count = shelf_model->item_count();
192 int indexes_left = item_index >= 0 ? item_index : item_count; 207 int indexes_left = item_index >= 0 ? item_index : item_count;
193 int found_index = -1; 208 int found_index = -1;
194 209
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 252
238 void WmShelf::RemoveObserver(WmShelfObserver* observer) { 253 void WmShelf::RemoveObserver(WmShelfObserver* observer) {
239 observers_.RemoveObserver(observer); 254 observers_.RemoveObserver(observer);
240 } 255 }
241 256
242 void WmShelf::NotifyShelfIconPositionsChanged() { 257 void WmShelf::NotifyShelfIconPositionsChanged() {
243 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged()); 258 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged());
244 } 259 }
245 260
246 StatusAreaWidget* WmShelf::GetStatusAreaWidget() const { 261 StatusAreaWidget* WmShelf::GetStatusAreaWidget() const {
247 return shelf_layout_manager_->shelf_widget()->status_area_widget(); 262 return shelf_widget_->status_area_widget();
248 } 263 }
249 264
250 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { 265 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) {
251 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); 266 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds);
252 } 267 }
253 268
254 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { 269 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() {
255 return shelf_locking_manager_.get(); 270 return shelf_locking_manager_.get();
256 } 271 }
257 272
(...skipping 23 matching lines...) Expand all
281 296
282 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, 297 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type,
283 BackgroundAnimatorChangeType change_type) { 298 BackgroundAnimatorChangeType change_type) {
284 if (background_type == GetBackgroundType()) 299 if (background_type == GetBackgroundType())
285 return; 300 return;
286 FOR_EACH_OBSERVER(WmShelfObserver, observers_, 301 FOR_EACH_OBSERVER(WmShelfObserver, observers_,
287 OnBackgroundTypeChanged(background_type, change_type)); 302 OnBackgroundTypeChanged(background_type, change_type));
288 } 303 }
289 304
290 } // namespace ash 305 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/wm_shelf.h ('k') | ash/mus/accelerators/accelerator_controller_delegate_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698