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

Side by Side Diff: ash/shelf/shelf_widget.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 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();
180 if (Shell::Get()->session_controller()->IsActiveUserSessionStarted()) 187 // NOTE: Container may be hidden depending on login/display state.
181 status_area_widget_->Show(); 188 status_area_widget_->Show();
182 Shell::Get()->focus_cycler()->AddWidget(status_area_widget_); 189 Shell::Get()->focus_cycler()->AddWidget(status_area_widget_);
183 background_animator_.AddObserver(status_area_widget_); 190 background_animator_.AddObserver(status_area_widget_);
184 status_container->aura_window()->SetLayoutManager( 191 status_container->aura_window()->SetLayoutManager(
185 new StatusAreaLayoutManager(this)); 192 new StatusAreaLayoutManager(this));
186 } 193 }
187 194
188 void ShelfWidget::SetPaintsBackground(ShelfBackgroundType background_type, 195 void ShelfWidget::SetPaintsBackground(ShelfBackgroundType background_type,
189 AnimationChangeType change_type) { 196 AnimationChangeType change_type) {
190 background_animator_.PaintBackground(background_type, change_type); 197 background_animator_.PaintBackground(background_type, change_type);
191 } 198 }
(...skipping 22 matching lines...) Expand all
214 bool ShelfWidget::IsShelfHiddenBehindBlackBar() const { 221 bool ShelfWidget::IsShelfHiddenBehindBlackBar() const {
215 return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f; 222 return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f;
216 } 223 }
217 224
218 void ShelfWidget::OnShelfAlignmentChanged() { 225 void ShelfWidget::OnShelfAlignmentChanged() {
219 shelf_view_->OnShelfAlignmentChanged(); 226 shelf_view_->OnShelfAlignmentChanged();
220 status_area_widget_->UpdateAfterShelfAlignmentChange(); 227 status_area_widget_->UpdateAfterShelfAlignmentChange();
221 delegate_view_->SchedulePaint(); 228 delegate_view_->SchedulePaint();
222 } 229 }
223 230
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() { 231 void ShelfWidget::PostCreateShelf() {
233 SetFocusCycler(Shell::Get()->focus_cycler()); 232 SetFocusCycler(Shell::Get()->focus_cycler());
234 233
235 // Ensure the newly created |shelf_| gets current values. 234 // Ensure the newly created |shelf_| gets current values.
236 background_animator_.NotifyObserver(this); 235 background_animator_.NotifyObserver(this);
237 236
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(); 237 shelf_layout_manager_->LayoutShelf();
250 shelf_layout_manager_->UpdateAutoHideState(); 238 shelf_layout_manager_->UpdateAutoHideState();
251 Show(); 239 Show();
252 } 240 }
253 241
254 bool ShelfWidget::IsShelfVisible() const {
255 return shelf_view_ && shelf_view_->visible();
256 }
257
258 bool ShelfWidget::IsShowingAppList() const { 242 bool ShelfWidget::IsShowingAppList() const {
259 return GetAppListButton() && GetAppListButton()->is_showing_app_list(); 243 return GetAppListButton() && GetAppListButton()->is_showing_app_list();
260 } 244 }
261 245
262 bool ShelfWidget::IsShowingContextMenu() const { 246 bool ShelfWidget::IsShowingContextMenu() const {
263 return shelf_view_ && shelf_view_->IsShowingMenu(); 247 return shelf_view_->IsShowingMenu();
264 } 248 }
265 249
266 bool ShelfWidget::IsShowingOverflowBubble() const { 250 bool ShelfWidget::IsShowingOverflowBubble() const {
267 return shelf_view_ && shelf_view_->IsShowingOverflowBubble(); 251 return shelf_view_->IsShowingOverflowBubble();
268 } 252 }
269 253
270 void ShelfWidget::SetFocusCycler(FocusCycler* focus_cycler) { 254 void ShelfWidget::SetFocusCycler(FocusCycler* focus_cycler) {
271 delegate_view_->set_focus_cycler(focus_cycler); 255 delegate_view_->set_focus_cycler(focus_cycler);
272 if (focus_cycler) 256 if (focus_cycler)
273 focus_cycler->AddWidget(this); 257 focus_cycler->AddWidget(this);
274 } 258 }
275 259
276 FocusCycler* ShelfWidget::GetFocusCycler() { 260 FocusCycler* ShelfWidget::GetFocusCycler() {
277 return delegate_view_->focus_cycler(); 261 return delegate_view_->focus_cycler();
(...skipping 13 matching lines...) Expand all
291 status_area_widget_->Shutdown(); 275 status_area_widget_->Shutdown();
292 status_area_widget_ = nullptr; 276 status_area_widget_ = nullptr;
293 } 277 }
294 278
295 CloseNow(); 279 CloseNow();
296 } 280 }
297 281
298 void ShelfWidget::UpdateIconPositionForPanel(WmWindow* panel) { 282 void ShelfWidget::UpdateIconPositionForPanel(WmWindow* panel) {
299 ShelfID id = 283 ShelfID id =
300 ShelfID::Deserialize(panel->aura_window()->GetProperty(kShelfIDKey)); 284 ShelfID::Deserialize(panel->aura_window()->GetProperty(kShelfIDKey));
301 if (!shelf_view_ || id.IsNull()) 285 if (id.IsNull())
302 return; 286 return;
303 287
304 WmWindow* shelf_window = WmWindow::Get(this->GetNativeWindow()); 288 WmWindow* shelf_window = WmWindow::Get(this->GetNativeWindow());
305 shelf_view_->UpdatePanelIconPosition( 289 shelf_view_->UpdatePanelIconPosition(
306 id, shelf_window->ConvertRectFromScreen(panel->GetBoundsInScreen()) 290 id, shelf_window->ConvertRectFromScreen(panel->GetBoundsInScreen())
307 .CenterPoint()); 291 .CenterPoint());
308 } 292 }
309 293
310 gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { 294 gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow(WmWindow* window) {
311 ShelfID id = 295 ShelfID id =
312 ShelfID::Deserialize(window->aura_window()->GetProperty(kShelfIDKey)); 296 ShelfID::Deserialize(window->aura_window()->GetProperty(kShelfIDKey));
313 // Window animations can be triggered during session restore before the shelf 297 if (id.IsNull())
314 // view is created. In that case, return default empty bounds.
315 if (!shelf_view_ || id.IsNull())
316 return gfx::Rect(); 298 return gfx::Rect();
317 299
318 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); 300 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id));
319 gfx::Point screen_origin; 301 gfx::Point screen_origin;
320 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); 302 views::View::ConvertPointToScreen(shelf_view_, &screen_origin);
321 return gfx::Rect(screen_origin.x() + bounds.x(), 303 return gfx::Rect(screen_origin.x() + bounds.x(),
322 screen_origin.y() + bounds.y(), bounds.width(), 304 screen_origin.y() + bounds.y(), bounds.width(),
323 bounds.height()); 305 bounds.height());
324 } 306 }
325 307
326 AppListButton* ShelfWidget::GetAppListButton() const { 308 AppListButton* ShelfWidget::GetAppListButton() const {
327 return shelf_view_ ? shelf_view_->GetAppListButton() : nullptr; 309 return shelf_view_->GetAppListButton();
328 } 310 }
329 311
330 app_list::ApplicationDragAndDropHost* 312 app_list::ApplicationDragAndDropHost*
331 ShelfWidget::GetDragAndDropHostForAppList() { 313 ShelfWidget::GetDragAndDropHostForAppList() {
332 return shelf_view_; 314 return shelf_view_;
333 } 315 }
334 316
335 void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget, 317 void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget,
336 bool active) { 318 bool active) {
337 activating_as_fallback_ = false; 319 activating_as_fallback_ = false;
338 if (active) 320 if (active)
339 delegate_view_->SetPaneFocusAndFocusDefault(); 321 delegate_view_->SetPaneFocusAndFocusDefault();
340 else 322 else
341 delegate_view_->GetFocusManager()->ClearFocus(); 323 delegate_view_->GetFocusManager()->ClearFocus();
342 } 324 }
343 325
344 void ShelfWidget::UpdateShelfItemBackground(SkColor color) { 326 void ShelfWidget::UpdateShelfItemBackground(SkColor color) {
345 if (shelf_view_) 327 shelf_view_->UpdateShelfItemBackground(color);
346 shelf_view_->UpdateShelfItemBackground(color);
347 } 328 }
348 329
349 void ShelfWidget::WillDeleteShelfLayoutManager() { 330 void ShelfWidget::WillDeleteShelfLayoutManager() {
350 shelf_layout_manager_->RemoveObserver(this); 331 shelf_layout_manager_->RemoveObserver(this);
351 shelf_layout_manager_ = nullptr; 332 shelf_layout_manager_ = nullptr;
352 } 333 }
353 334
354 } // namespace ash 335 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698