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

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

Issue 2889673002: chromeos: Refactor shelf to create ShelfView earlier in startup (Closed)
Patch Set: Move ShelfView to initializer list 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/shelf_widget.h" 5 #include "ash/shelf/shelf_widget.h"
6 6
7 #include "ash/animation/animation_change_type.h" 7 #include "ash/animation/animation_change_type.h"
8 #include "ash/focus_cycler.h" 8 #include "ash/focus_cycler.h"
9 #include "ash/public/cpp/window_properties.h" 9 #include "ash/public/cpp/window_properties.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 120
121 void ShelfWidget::DelegateView::UpdateShelfBackground(SkColor color) { 121 void ShelfWidget::DelegateView::UpdateShelfBackground(SkColor color) {
122 opaque_background_.SetColor(color); 122 opaque_background_.SetColor(color);
123 } 123 }
124 124
125 ShelfWidget::ShelfWidget(WmWindow* shelf_container, WmShelf* wm_shelf) 125 ShelfWidget::ShelfWidget(WmWindow* shelf_container, WmShelf* wm_shelf)
126 : wm_shelf_(wm_shelf), 126 : wm_shelf_(wm_shelf),
127 status_area_widget_(nullptr), 127 status_area_widget_(nullptr),
128 delegate_view_(new DelegateView(this)), 128 delegate_view_(new DelegateView(this)),
129 shelf_view_(nullptr), 129 shelf_view_(new ShelfView(Shell::Get()->shelf_model(), wm_shelf_, this)),
130 background_animator_(SHELF_BACKGROUND_DEFAULT, 130 background_animator_(SHELF_BACKGROUND_DEFAULT,
131 wm_shelf_, 131 wm_shelf_,
132 Shell::Get()->wallpaper_controller()), 132 Shell::Get()->wallpaper_controller()),
133 activating_as_fallback_(false) { 133 activating_as_fallback_(false) {
134 DCHECK(shelf_container);
134 DCHECK(wm_shelf_); 135 DCHECK(wm_shelf_);
135 background_animator_.AddObserver(this);
136 background_animator_.AddObserver(delegate_view_);
137 136
138 views::Widget::InitParams params( 137 views::Widget::InitParams params(
139 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 138 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
140 params.name = "ShelfWidget"; 139 params.name = "ShelfWidget";
141 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 140 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
142 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 141 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
143 params.delegate = delegate_view_; 142 params.delegate = delegate_view_;
144 shelf_container->GetRootWindowController() 143 shelf_container->GetRootWindowController()
145 ->ConfigureWidgetInitParamsForContainer( 144 ->ConfigureWidgetInitParamsForContainer(
146 this, shelf_container->aura_window()->id(), &params); 145 this, shelf_container->aura_window()->id(), &params);
147 Init(params); 146 Init(params);
148 147
149 // The shelf should not take focus when initially shown. 148 // The shelf should not take focus when initially shown.
150 set_focus_on_creation(false); 149 set_focus_on_creation(false);
151 SetContentsView(delegate_view_); 150 SetContentsView(delegate_view_);
152 delegate_view_->SetParentLayer(GetLayer()); 151 delegate_view_->SetParentLayer(GetLayer());
153 152
153 // The shelf view observes the shelf model and creates icons as items are
154 // added to the model.
155 shelf_view_->Init();
156 GetContentsView()->AddChildView(shelf_view_);
157
154 shelf_layout_manager_ = new ShelfLayoutManager(this, wm_shelf_); 158 shelf_layout_manager_ = new ShelfLayoutManager(this, wm_shelf_);
155 shelf_layout_manager_->AddObserver(this); 159 shelf_layout_manager_->AddObserver(this);
156 shelf_container->aura_window()->SetLayoutManager(shelf_layout_manager_); 160 shelf_container->aura_window()->SetLayoutManager(shelf_layout_manager_);
157 background_animator_.PaintBackground( 161 background_animator_.PaintBackground(
158 shelf_layout_manager_->GetShelfBackgroundType(), 162 shelf_layout_manager_->GetShelfBackgroundType(),
159 AnimationChangeType::IMMEDIATE); 163 AnimationChangeType::IMMEDIATE);
160 164
161 views::Widget::AddObserver(this); 165 views::Widget::AddObserver(this);
166
167 // Calls back into |this| and depends on |shelf_view_|.
168 background_animator_.AddObserver(this);
169 background_animator_.AddObserver(delegate_view_);
162 } 170 }
163 171
164 ShelfWidget::~ShelfWidget() { 172 ShelfWidget::~ShelfWidget() {
165 // Must call Shutdown() before destruction. 173 // Must call Shutdown() before destruction.
166 DCHECK(!status_area_widget_); 174 DCHECK(!status_area_widget_);
175 background_animator_.RemoveObserver(delegate_view_);
176 background_animator_.RemoveObserver(this);
167 Shell::Get()->focus_cycler()->RemoveWidget(this); 177 Shell::Get()->focus_cycler()->RemoveWidget(this);
168 SetFocusCycler(nullptr); 178 SetFocusCycler(nullptr);
169 RemoveObserver(this); 179 RemoveObserver(this);
170 background_animator_.RemoveObserver(delegate_view_);
171 background_animator_.RemoveObserver(this);
172 } 180 }
173 181
174 void ShelfWidget::CreateStatusAreaWidget(WmWindow* status_container) { 182 void ShelfWidget::CreateStatusAreaWidget(WmWindow* status_container) {
175 DCHECK(status_container); 183 DCHECK(status_container);
176 DCHECK(!status_area_widget_); 184 DCHECK(!status_area_widget_);
177 // TODO(jamescook): Move ownership to RootWindowController.
178 status_area_widget_ = new StatusAreaWidget(status_container, wm_shelf_); 185 status_area_widget_ = new StatusAreaWidget(status_container, wm_shelf_);
179 status_area_widget_->CreateTrayViews(); 186 status_area_widget_->CreateTrayViews();
187 // TODO(jamescook): Is the session check needed?
msw 2017/05/16 22:42:00 nit: address now? (so many TODOs!)
James Cook 2017/05/17 16:16:12 Ah, you never would have noticed if I hadn't added
180 if (Shell::Get()->session_controller()->IsActiveUserSessionStarted()) 188 if (Shell::Get()->session_controller()->IsActiveUserSessionStarted())
181 status_area_widget_->Show(); 189 status_area_widget_->Show();
182 Shell::Get()->focus_cycler()->AddWidget(status_area_widget_); 190 Shell::Get()->focus_cycler()->AddWidget(status_area_widget_);
183 background_animator_.AddObserver(status_area_widget_); 191 background_animator_.AddObserver(status_area_widget_);
184 status_container->aura_window()->SetLayoutManager( 192 status_container->aura_window()->SetLayoutManager(
185 new StatusAreaLayoutManager(this)); 193 new StatusAreaLayoutManager(this));
186 } 194 }
187 195
188 void ShelfWidget::SetPaintsBackground(ShelfBackgroundType background_type, 196 void ShelfWidget::SetPaintsBackground(ShelfBackgroundType background_type,
189 AnimationChangeType change_type) { 197 AnimationChangeType change_type) {
(...skipping 24 matching lines...) Expand all
214 bool ShelfWidget::IsShelfHiddenBehindBlackBar() const { 222 bool ShelfWidget::IsShelfHiddenBehindBlackBar() const {
215 return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f; 223 return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f;
216 } 224 }
217 225
218 void ShelfWidget::OnShelfAlignmentChanged() { 226 void ShelfWidget::OnShelfAlignmentChanged() {
219 shelf_view_->OnShelfAlignmentChanged(); 227 shelf_view_->OnShelfAlignmentChanged();
220 status_area_widget_->UpdateAfterShelfAlignmentChange(); 228 status_area_widget_->UpdateAfterShelfAlignmentChange();
221 delegate_view_->SchedulePaint(); 229 delegate_view_->SchedulePaint();
222 } 230 }
223 231
224 ShelfView* ShelfWidget::CreateShelfView() {
225 DCHECK(!shelf_view_);
226 shelf_view_ = new ShelfView(Shell::Get()->shelf_model(), wm_shelf_, this);
227 shelf_view_->Init();
228 GetContentsView()->AddChildView(shelf_view_);
229 return shelf_view_;
230 }
231
232 void ShelfWidget::PostCreateShelf() { 232 void ShelfWidget::PostCreateShelf() {
233 SetFocusCycler(Shell::Get()->focus_cycler()); 233 SetFocusCycler(Shell::Get()->focus_cycler());
234 234
235 // Ensure the newly created |shelf_| gets current values. 235 // Ensure the newly created |shelf_| gets current values.
236 background_animator_.NotifyObserver(this); 236 background_animator_.NotifyObserver(this);
237 237
238 // TODO(jamescook): The IsActiveUserSessionStarted() check may not be needed
239 // because the shelf is only created after the first user session is active.
240 // The ShelfView seems to always be visible after login. At the lock screen
241 // the shelf is hidden because its container is hidden. During auto-hide it is
242 // hidden because ShelfWidget is transparent. Some of the ShelfView visibility
243 // code could be simplified. http://crbug.com/674773
244 // TODO(jdufualt|jamescook): Remove CHECK and shelf_view_->SetVisible call in
245 // m60 or beyond (see above TODO).
246 CHECK(Shell::Get()->session_controller()->IsActiveUserSessionStarted());
247 shelf_view_->SetVisible(
248 Shell::Get()->session_controller()->IsActiveUserSessionStarted());
249 shelf_layout_manager_->LayoutShelf(); 238 shelf_layout_manager_->LayoutShelf();
250 shelf_layout_manager_->UpdateAutoHideState(); 239 shelf_layout_manager_->UpdateAutoHideState();
251 Show(); 240 Show();
252 } 241 }
253 242
254 bool ShelfWidget::IsShelfVisible() const { 243 bool ShelfWidget::IsShelfVisible() const {
msw 2017/05/16 22:42:00 nit: remove? this will always return true now, rig
James Cook 2017/05/17 16:16:12 Good catch! Removed.
255 return shelf_view_ && shelf_view_->visible(); 244 return shelf_view_->visible();
256 } 245 }
257 246
258 bool ShelfWidget::IsShowingAppList() const { 247 bool ShelfWidget::IsShowingAppList() const {
259 return GetAppListButton() && GetAppListButton()->is_showing_app_list(); 248 return GetAppListButton() && GetAppListButton()->is_showing_app_list();
260 } 249 }
261 250
262 bool ShelfWidget::IsShowingContextMenu() const { 251 bool ShelfWidget::IsShowingContextMenu() const {
263 return shelf_view_ && shelf_view_->IsShowingMenu(); 252 return shelf_view_->IsShowingMenu();
264 } 253 }
265 254
266 bool ShelfWidget::IsShowingOverflowBubble() const { 255 bool ShelfWidget::IsShowingOverflowBubble() const {
267 return shelf_view_ && shelf_view_->IsShowingOverflowBubble(); 256 return shelf_view_->IsShowingOverflowBubble();
268 } 257 }
269 258
270 void ShelfWidget::SetFocusCycler(FocusCycler* focus_cycler) { 259 void ShelfWidget::SetFocusCycler(FocusCycler* focus_cycler) {
271 delegate_view_->set_focus_cycler(focus_cycler); 260 delegate_view_->set_focus_cycler(focus_cycler);
272 if (focus_cycler) 261 if (focus_cycler)
273 focus_cycler->AddWidget(this); 262 focus_cycler->AddWidget(this);
274 } 263 }
275 264
276 FocusCycler* ShelfWidget::GetFocusCycler() { 265 FocusCycler* ShelfWidget::GetFocusCycler() {
277 return delegate_view_->focus_cycler(); 266 return delegate_view_->focus_cycler();
(...skipping 13 matching lines...) Expand all
291 status_area_widget_->Shutdown(); 280 status_area_widget_->Shutdown();
292 status_area_widget_ = nullptr; 281 status_area_widget_ = nullptr;
293 } 282 }
294 283
295 CloseNow(); 284 CloseNow();
296 } 285 }
297 286
298 void ShelfWidget::UpdateIconPositionForPanel(WmWindow* panel) { 287 void ShelfWidget::UpdateIconPositionForPanel(WmWindow* panel) {
299 ShelfID id = 288 ShelfID id =
300 ShelfID::Deserialize(panel->aura_window()->GetProperty(kShelfIDKey)); 289 ShelfID::Deserialize(panel->aura_window()->GetProperty(kShelfIDKey));
301 if (!shelf_view_ || id.IsNull()) 290 if (id.IsNull())
302 return; 291 return;
303 292
304 WmWindow* shelf_window = WmWindow::Get(this->GetNativeWindow()); 293 WmWindow* shelf_window = WmWindow::Get(this->GetNativeWindow());
305 shelf_view_->UpdatePanelIconPosition( 294 shelf_view_->UpdatePanelIconPosition(
306 id, shelf_window->ConvertRectFromScreen(panel->GetBoundsInScreen()) 295 id, shelf_window->ConvertRectFromScreen(panel->GetBoundsInScreen())
307 .CenterPoint()); 296 .CenterPoint());
308 } 297 }
309 298
310 gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { 299 gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow(WmWindow* window) {
311 ShelfID id = 300 ShelfID id =
312 ShelfID::Deserialize(window->aura_window()->GetProperty(kShelfIDKey)); 301 ShelfID::Deserialize(window->aura_window()->GetProperty(kShelfIDKey));
313 // Window animations can be triggered during session restore before the shelf 302 if (id.IsNull())
314 // view is created. In that case, return default empty bounds.
315 if (!shelf_view_ || id.IsNull())
316 return gfx::Rect(); 303 return gfx::Rect();
317 304
318 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); 305 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id));
319 gfx::Point screen_origin; 306 gfx::Point screen_origin;
320 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); 307 views::View::ConvertPointToScreen(shelf_view_, &screen_origin);
321 return gfx::Rect(screen_origin.x() + bounds.x(), 308 return gfx::Rect(screen_origin.x() + bounds.x(),
322 screen_origin.y() + bounds.y(), bounds.width(), 309 screen_origin.y() + bounds.y(), bounds.width(),
323 bounds.height()); 310 bounds.height());
324 } 311 }
325 312
326 AppListButton* ShelfWidget::GetAppListButton() const { 313 AppListButton* ShelfWidget::GetAppListButton() const {
327 return shelf_view_ ? shelf_view_->GetAppListButton() : nullptr; 314 return shelf_view_->GetAppListButton();
328 } 315 }
329 316
330 app_list::ApplicationDragAndDropHost* 317 app_list::ApplicationDragAndDropHost*
331 ShelfWidget::GetDragAndDropHostForAppList() { 318 ShelfWidget::GetDragAndDropHostForAppList() {
332 return shelf_view_; 319 return shelf_view_;
333 } 320 }
334 321
335 void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget, 322 void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget,
336 bool active) { 323 bool active) {
337 activating_as_fallback_ = false; 324 activating_as_fallback_ = false;
338 if (active) 325 if (active)
339 delegate_view_->SetPaneFocusAndFocusDefault(); 326 delegate_view_->SetPaneFocusAndFocusDefault();
340 else 327 else
341 delegate_view_->GetFocusManager()->ClearFocus(); 328 delegate_view_->GetFocusManager()->ClearFocus();
342 } 329 }
343 330
344 void ShelfWidget::UpdateShelfItemBackground(SkColor color) { 331 void ShelfWidget::UpdateShelfItemBackground(SkColor color) {
345 if (shelf_view_) 332 shelf_view_->UpdateShelfItemBackground(color);
346 shelf_view_->UpdateShelfItemBackground(color);
347 } 333 }
348 334
349 void ShelfWidget::WillDeleteShelfLayoutManager() { 335 void ShelfWidget::WillDeleteShelfLayoutManager() {
350 shelf_layout_manager_->RemoveObserver(this); 336 shelf_layout_manager_->RemoveObserver(this);
351 shelf_layout_manager_ = nullptr; 337 shelf_layout_manager_ = nullptr;
352 } 338 }
353 339
354 } // namespace ash 340 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698