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

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

Issue 2053113002: Replaced BackgroundAnimator with ShelfBackgroundAnimator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added PaletteTray to the Shelf background animations. 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 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/aura/wm_shelf_aura.h" 7 #include "ash/aura/wm_shelf_aura.h"
8 #include "ash/aura/wm_window_aura.h" 8 #include "ash/aura/wm_window_aura.h"
9 #include "ash/common/ash_switches.h" 9 #include "ash/common/ash_switches.h"
10 #include "ash/common/focus_cycler.h" 10 #include "ash/common/focus_cycler.h"
11 #include "ash/common/material_design/material_design_controller.h" 11 #include "ash/common/material_design/material_design_controller.h"
12 #include "ash/common/session/session_state_delegate.h" 12 #include "ash/common/session/session_state_delegate.h"
13 #include "ash/common/shelf/shelf_background_animator_observer.h"
13 #include "ash/common/shelf/shelf_constants.h" 14 #include "ash/common/shelf/shelf_constants.h"
14 #include "ash/common/shelf/shelf_delegate.h" 15 #include "ash/common/shelf/shelf_delegate.h"
15 #include "ash/common/shelf/shelf_model.h" 16 #include "ash/common/shelf/shelf_model.h"
17 #include "ash/common/shelf/wm_shelf.h"
16 #include "ash/common/shelf/wm_shelf_util.h" 18 #include "ash/common/shelf/wm_shelf_util.h"
17 #include "ash/common/shell_window_ids.h" 19 #include "ash/common/shell_window_ids.h"
18 #include "ash/common/system/tray/system_tray_delegate.h" 20 #include "ash/common/system/tray/system_tray_delegate.h"
19 #include "ash/common/wm_root_window_controller.h" 21 #include "ash/common/wm_root_window_controller.h"
20 #include "ash/common/wm_shell.h" 22 #include "ash/common/wm_shell.h"
21 #include "ash/shelf/shelf_layout_manager.h" 23 #include "ash/shelf/shelf_layout_manager.h"
22 #include "ash/shelf/shelf_util.h" 24 #include "ash/shelf/shelf_util.h"
23 #include "ash/shelf/shelf_view.h" 25 #include "ash/shelf/shelf_view.h"
24 #include "ash/shell.h" 26 #include "ash/shell.h"
25 #include "ash/wm/status_area_layout_manager.h" 27 #include "ash/wm/status_area_layout_manager.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 void SetHovered(bool hovered); 74 void SetHovered(bool hovered);
73 75
74 // Force the dimmer to be undimmed. 76 // Force the dimmer to be undimmed.
75 void ForceUndimming(bool force); 77 void ForceUndimming(bool force);
76 78
77 // views::WidgetDelegate overrides: 79 // views::WidgetDelegate overrides:
78 views::Widget* GetWidget() override { return View::GetWidget(); } 80 views::Widget* GetWidget() override { return View::GetWidget(); }
79 const views::Widget* GetWidget() const override { return View::GetWidget(); } 81 const views::Widget* GetWidget() const override { return View::GetWidget(); }
80 82
81 // BackgroundAnimatorDelegate overrides: 83 // BackgroundAnimatorDelegate overrides:
82 void UpdateBackground(int alpha) override { 84 void UpdateBackground(BackgroundAnimator* animator, int alpha) override {
83 alpha_ = alpha; 85 alpha_ = alpha;
84 SchedulePaint(); 86 SchedulePaint();
85 } 87 }
86 88
89 void BackgroundAnimationEnded(BackgroundAnimator* animator) override {}
90
87 // views::View overrides: 91 // views::View overrides:
88 void OnPaintBackground(gfx::Canvas* canvas) override; 92 void OnPaintBackground(gfx::Canvas* canvas) override;
89 93
90 // A function to test the current alpha used. 94 // A function to test the current alpha used.
91 int get_dimming_alpha_for_test() { return alpha_; } 95 int get_dimming_alpha_for_test() { return alpha_; }
92 96
93 private: 97 private:
94 // This class monitors mouse events to see if it is on top of the shelf. 98 // This class monitors mouse events to see if it is on top of the shelf.
95 class DimmerEventFilter : public ui::EventHandler { 99 class DimmerEventFilter : public ui::EventHandler {
96 public: 100 public:
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 293
290 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); 294 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter);
291 }; 295 };
292 296
293 } // namespace 297 } // namespace
294 298
295 // The contents view of the Shelf. This view contains ShelfView and 299 // The contents view of the Shelf. This view contains ShelfView and
296 // sizes it to the width of the shelf minus the size of the status area. 300 // sizes it to the width of the shelf minus the size of the status area.
297 class ShelfWidget::DelegateView : public views::WidgetDelegate, 301 class ShelfWidget::DelegateView : public views::WidgetDelegate,
298 public views::AccessiblePaneView, 302 public views::AccessiblePaneView,
299 public BackgroundAnimatorDelegate, 303 public aura::WindowObserver,
300 public aura::WindowObserver { 304 public ShelfBackgroundAnimatorObserver {
301 public: 305 public:
302 explicit DelegateView(ShelfWidget* shelf); 306 explicit DelegateView(ShelfWidget* shelf);
303 ~DelegateView() override; 307 ~DelegateView() override;
304 308
305 void set_focus_cycler(FocusCycler* focus_cycler) { 309 void set_focus_cycler(FocusCycler* focus_cycler) {
306 focus_cycler_ = focus_cycler; 310 focus_cycler_ = focus_cycler;
307 } 311 }
308 FocusCycler* focus_cycler() { return focus_cycler_; } 312 FocusCycler* focus_cycler() { return focus_cycler_; }
309 313
310 ui::Layer* opaque_background() { return &opaque_background_; } 314 ui::Layer* opaque_background() { return &opaque_background_; }
(...skipping 19 matching lines...) Expand all
330 334
331 // aura::WindowObserver overrides: 335 // aura::WindowObserver overrides:
332 // This will be called when the shelf itself changes its absolute position. 336 // This will be called when the shelf itself changes its absolute position.
333 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs 337 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs
334 // to be repositioned. The difference to the OnBoundsChanged call above is 338 // to be repositioned. The difference to the OnBoundsChanged call above is
335 // that this gets also triggered when the shelf only moves. 339 // that this gets also triggered when the shelf only moves.
336 void OnWindowBoundsChanged(aura::Window* window, 340 void OnWindowBoundsChanged(aura::Window* window,
337 const gfx::Rect& old_bounds, 341 const gfx::Rect& old_bounds,
338 const gfx::Rect& new_bounds) override; 342 const gfx::Rect& new_bounds) override;
339 343
340 // BackgroundAnimatorDelegate overrides: 344 // ShelfBackgroundAnimatorObserver:
341 void UpdateBackground(int alpha) override; 345 void UpdateShelfOpaqueBackground(int alpha) override;
346 void UpdateShelfAssetBackground(int alpha) override;
342 347
343 // Force the shelf to be presented in an undimmed state. 348 // Force the shelf to be presented in an undimmed state.
344 void ForceUndimming(bool force); 349 void ForceUndimming(bool force);
345 350
346 // A function to test the current alpha used by the dimming bar. If there is 351 // A function to test the current alpha used by the dimming bar. If there is
347 // no dimmer active, the function will return -1. 352 // no dimmer active, the function will return -1.
348 int GetDimmingAlphaForTest(); 353 int GetDimmingAlphaForTest();
349 354
350 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if 355 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if
351 // the dimmer is inactive. 356 // the dimmer is inactive.
352 gfx::Rect GetDimmerBoundsForTest(); 357 gfx::Rect GetDimmerBoundsForTest();
353 358
354 // Disable dimming animations for running tests. This needs to be called 359 // Disable dimming animations for running tests. This needs to be called
355 // prior to the creation of of the |dimmer_|. 360 // prior to the creation of of the |dimmer_|.
356 void disable_dimming_animations_for_test() { 361 void disable_dimming_animations_for_test() {
357 disable_dimming_animations_for_test_ = true; 362 disable_dimming_animations_for_test_ = true;
358 } 363 }
359 364
360 private: 365 private:
361 ShelfWidget* shelf_; 366 ShelfWidget* shelf_;
362 std::unique_ptr<views::Widget> dimmer_; 367 std::unique_ptr<views::Widget> dimmer_;
363 FocusCycler* focus_cycler_; 368 FocusCycler* focus_cycler_;
364 int alpha_; 369 int asset_background_alpha_;
370 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551).
365 // A black background layer which is shown when a maximized window is visible. 371 // A black background layer which is shown when a maximized window is visible.
366 ui::Layer opaque_background_; 372 ui::Layer opaque_background_;
367 // A black foreground layer which is shown while transitioning between users. 373 // A black foreground layer which is shown while transitioning between users.
368 // Note: Since the back- and foreground layers have different functions they 374 // Note: Since the back- and foreground layers have different functions they
369 // can be used simultaneously - so no repurposing possible. 375 // can be used simultaneously - so no repurposing possible.
370 ui::Layer opaque_foreground_; 376 ui::Layer opaque_foreground_;
371 377
372 // The view which does the dimming. 378 // The view which does the dimming.
373 DimmerView* dimmer_view_; 379 DimmerView* dimmer_view_;
374 380
375 // True if dimming animations should be turned off. 381 // True if dimming animations should be turned off.
376 bool disable_dimming_animations_for_test_; 382 bool disable_dimming_animations_for_test_;
377 383
378 DISALLOW_COPY_AND_ASSIGN(DelegateView); 384 DISALLOW_COPY_AND_ASSIGN(DelegateView);
379 }; 385 };
380 386
381 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) 387 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf)
382 : shelf_(shelf), 388 : shelf_(shelf),
383 focus_cycler_(NULL), 389 focus_cycler_(NULL),
384 alpha_(0), 390 asset_background_alpha_(0),
385 opaque_background_(ui::LAYER_SOLID_COLOR), 391 opaque_background_(ui::LAYER_SOLID_COLOR),
386 opaque_foreground_(ui::LAYER_SOLID_COLOR), 392 opaque_foreground_(ui::LAYER_SOLID_COLOR),
387 dimmer_view_(NULL), 393 dimmer_view_(NULL),
388 disable_dimming_animations_for_test_(false) { 394 disable_dimming_animations_for_test_(false) {
389 SetLayoutManager(new views::FillLayout()); 395 SetLayoutManager(new views::FillLayout());
390 set_allow_deactivate_on_esc(true); 396 set_allow_deactivate_on_esc(true);
391 opaque_background_.SetColor(SK_ColorBLACK); 397 opaque_background_.SetColor(SK_ColorBLACK);
392 opaque_background_.SetBounds(GetLocalBounds()); 398 opaque_background_.SetBounds(GetLocalBounds());
393 opaque_background_.SetOpacity(0.0f); 399 opaque_background_.SetOpacity(0.0f);
394 opaque_foreground_.SetColor(SK_ColorBLACK); 400 opaque_foreground_.SetColor(SK_ColorBLACK);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return dimmer_.get() && dimmer_->IsVisible(); 443 return dimmer_.get() && dimmer_->IsVisible();
438 } 444 }
439 445
440 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { 446 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) {
441 layer->Add(&opaque_background_); 447 layer->Add(&opaque_background_);
442 layer->Add(&opaque_foreground_); 448 layer->Add(&opaque_foreground_);
443 ReorderLayers(); 449 ReorderLayers();
444 } 450 }
445 451
446 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { 452 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
447 if (MaterialDesignController::IsShelfMaterial()) { 453 if (MaterialDesignController::IsShelfMaterial())
448 canvas->FillRect(bounds(), SkColorSetA(kShelfBaseColor, alpha_)); 454 return;
449 } else { 455
450 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 456 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
451 gfx::ImageSkia shelf_background = 457 gfx::ImageSkia shelf_background =
452 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); 458 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
453 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); 459 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment());
454 if (!horizontal) { 460 if (!horizontal) {
455 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( 461 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
456 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT 462 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT
457 ? SkBitmapOperations::ROTATION_90_CW 463 ? SkBitmapOperations::ROTATION_90_CW
458 : SkBitmapOperations::ROTATION_270_CW); 464 : SkBitmapOperations::ROTATION_270_CW);
465 }
466 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds());
467 SkPaint paint;
468 paint.setAlpha(asset_background_alpha_);
469 canvas->DrawImageInt(
470 shelf_background, 0, 0, shelf_background.width(),
471 shelf_background.height(),
472 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0)
473 ? dock_bounds.width()
474 : 0,
475 0, horizontal ? width() - dock_bounds.width() : width(), height(), false,
476 paint);
477 if (horizontal && dock_bounds.width() > 0) {
478 // The part of the shelf background that is in the corner below the docked
479 // windows close to the work area is an arched gradient that blends
480 // vertically oriented docked background and horizontal shelf.
481 gfx::ImageSkia shelf_corner = *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER);
482 if (dock_bounds.x() == 0) {
483 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage(
484 shelf_corner, SkBitmapOperations::ROTATION_90_CW);
459 } 485 }
460 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds());
461 SkPaint paint;
462 paint.setAlpha(alpha_);
463 canvas->DrawImageInt( 486 canvas->DrawImageInt(
464 shelf_background, 0, 0, shelf_background.width(), 487 shelf_corner, 0, 0, shelf_corner.width(), shelf_corner.height(),
465 shelf_background.height(), 488 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(),
466 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) 489 0, height(), height(), false, paint);
467 ? dock_bounds.width() 490 // The part of the shelf background that is just below the docked windows
468 : 0, 491 // is drawn using the last (lowest) 1-pixel tall strip of the image asset.
469 0, horizontal ? width() - dock_bounds.width() : width(), height(), 492 // This avoids showing the border 3D shadow between the shelf and the
470 false, paint); 493 // dock.
471 if (horizontal && dock_bounds.width() > 0) { 494 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1,
472 // The part of the shelf background that is in the corner below the docked 495 shelf_background.width(), 1,
473 // windows close to the work area is an arched gradient that blends 496 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0,
474 // vertically oriented docked background and horizontal shelf. 497 0, dock_bounds.width() - height(), height(), false,
475 gfx::ImageSkia shelf_corner = 498 paint);
476 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER);
477 if (dock_bounds.x() == 0) {
478 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage(
479 shelf_corner, SkBitmapOperations::ROTATION_90_CW);
480 }
481 canvas->DrawImageInt(shelf_corner, 0, 0, shelf_corner.width(),
482 shelf_corner.height(),
483 dock_bounds.x() > 0 ? dock_bounds.x()
484 : dock_bounds.width() - height(),
485 0, height(), height(), false, paint);
486 // The part of the shelf background that is just below the docked windows
487 // is drawn using the last (lowest) 1-pixel tall strip of the image asset.
488 // This avoids showing the border 3D shadow between the shelf and the
489 // dock.
490 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1,
491 shelf_background.width(), 1,
492 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0,
493 0, dock_bounds.width() - height(), height(), false,
494 paint);
495 }
496 gfx::Rect black_rect =
497 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment(
498 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels),
499 gfx::Rect(0, 0, kNumBlackPixels, height()),
500 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()));
501 canvas->FillRect(black_rect, SK_ColorBLACK);
502 } 499 }
500 gfx::Rect black_rect =
501 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment(
502 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels),
503 gfx::Rect(0, 0, kNumBlackPixels, height()),
504 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()));
505 canvas->FillRect(black_rect, SK_ColorBLACK);
503 } 506 }
504 507
505 bool ShelfWidget::DelegateView::CanActivate() const { 508 bool ShelfWidget::DelegateView::CanActivate() const {
506 // Allow to activate as fallback. 509 // Allow to activate as fallback.
507 if (shelf_->activating_as_fallback_) 510 if (shelf_->activating_as_fallback_)
508 return true; 511 return true;
509 // Allow to activate from the focus cycler. 512 // Allow to activate from the focus cycler.
510 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) 513 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget())
511 return true; 514 return true;
512 // Disallow activating in other cases, especially when using mouse. 515 // Disallow activating in other cases, especially when using mouse.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 return dimmer_view_->get_dimming_alpha_for_test(); 549 return dimmer_view_->get_dimming_alpha_for_test();
547 return -1; 550 return -1;
548 } 551 }
549 552
550 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { 553 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() {
551 if (GetDimmed()) 554 if (GetDimmed())
552 return dimmer_view_->GetBoundsInScreen(); 555 return dimmer_view_->GetBoundsInScreen();
553 return gfx::Rect(); 556 return gfx::Rect();
554 } 557 }
555 558
556 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { 559 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) {
557 alpha_ = alpha; 560 const float kMaxAlpha = 255.0f;
561 opaque_background_.SetOpacity(alpha / kMaxAlpha);
562 }
563
564 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) {
565 asset_background_alpha_ = alpha;
558 SchedulePaint(); 566 SchedulePaint();
559 } 567 }
560 568
561 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, 569 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container,
562 WmWindow* wm_status_container, 570 WmWindow* wm_status_container,
563 WmShelfAura* wm_shelf_aura, 571 WmShelfAura* wm_shelf_aura,
564 WorkspaceController* workspace_controller) 572 WorkspaceController* workspace_controller)
565 : delegate_view_(new DelegateView(this)), 573 : wm_shelf_aura_(wm_shelf_aura),
566 background_animator_(delegate_view_, 574 delegate_view_(new DelegateView(this)),
567 0, 575 background_animator_(SHELF_BACKGROUND_DEFAULT),
568 GetShelfConstant(SHELF_BACKGROUND_ALPHA)),
569 activating_as_fallback_(false) { 576 activating_as_fallback_(false) {
577 static_cast<WmShelf*>(wm_shelf_aura_)->AddObserver(&background_animator_);
James Cook 2016/07/27 00:30:39 Could the background animator take a WmShelf as a
bruthig 2016/07/27 17:05:45 I've added a WmShelf param to ShelfBackgroundAnima
578 background_animator_.AddObserver(delegate_view_);
579
570 views::Widget::InitParams params( 580 views::Widget::InitParams params(
571 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 581 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
572 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 582 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
573 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 583 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
574 params.delegate = delegate_view_; 584 params.delegate = delegate_view_;
575 wm_shelf_container->GetRootWindowController() 585 wm_shelf_container->GetRootWindowController()
576 ->ConfigureWidgetInitParamsForContainer( 586 ->ConfigureWidgetInitParamsForContainer(
577 this, wm_shelf_container->GetShellWindowId(), &params); 587 this, wm_shelf_container->GetShellWindowId(), &params);
578 Init(params); 588 Init(params);
579 589
580 // The shelf should not take focus when initially shown. 590 // The shelf should not take focus when initially shown.
581 set_focus_on_creation(false); 591 set_focus_on_creation(false);
582 SetContentsView(delegate_view_); 592 SetContentsView(delegate_view_);
583 delegate_view_->SetParentLayer(GetLayer()); 593 delegate_view_->SetParentLayer(GetLayer());
584 594
585 shelf_layout_manager_ = new ShelfLayoutManager(this); 595 shelf_layout_manager_ = new ShelfLayoutManager(this);
586 shelf_layout_manager_->AddObserver(this); 596 shelf_layout_manager_->AddObserver(this);
587 aura::Window* shelf_container = 597 aura::Window* shelf_container =
588 WmWindowAura::GetAuraWindow(wm_shelf_container); 598 WmWindowAura::GetAuraWindow(wm_shelf_container);
589 shelf_container->SetLayoutManager(shelf_layout_manager_); 599 shelf_container->SetLayoutManager(shelf_layout_manager_);
590 shelf_layout_manager_->set_workspace_controller(workspace_controller); 600 shelf_layout_manager_->set_workspace_controller(workspace_controller);
591 workspace_controller->SetShelf(shelf_layout_manager_); 601 workspace_controller->SetShelf(shelf_layout_manager_);
592 wm_shelf_aura->SetShelfLayoutManager(shelf_layout_manager_); 602 background_animator_.PaintBackground(
603 shelf_layout_manager_->GetShelfBackgroundType(),
604 BACKGROUND_CHANGE_IMMEDIATE);
605 wm_shelf_aura_->SetShelfLayoutManager(shelf_layout_manager_);
593 606
594 // TODO(jamescook): Move ownership to RootWindowController. 607 // TODO(jamescook): Move ownership to RootWindowController.
595 status_area_widget_ = 608 status_area_widget_ =
596 new StatusAreaWidget(wm_status_container, wm_shelf_aura); 609 new StatusAreaWidget(wm_status_container, wm_shelf_aura_);
597 status_area_widget_->CreateTrayViews(); 610 status_area_widget_->CreateTrayViews();
598 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) 611 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted())
599 status_area_widget_->Show(); 612 status_area_widget_->Show();
600 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); 613 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_);
614 background_animator_.AddObserver(status_area_widget_);
601 615
602 aura::Window* status_container = 616 aura::Window* status_container =
603 WmWindowAura::GetAuraWindow(wm_status_container); 617 WmWindowAura::GetAuraWindow(wm_status_container);
604 status_container->SetLayoutManager( 618 status_container->SetLayoutManager(
605 new StatusAreaLayoutManager(status_container, this)); 619 new StatusAreaLayoutManager(status_container, this));
606 620
607 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( 621 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>(
608 new ShelfWindowTargeter(shelf_container, shelf_layout_manager_))); 622 new ShelfWindowTargeter(shelf_container, shelf_layout_manager_)));
609 status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( 623 status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>(
610 new ShelfWindowTargeter(status_container, shelf_layout_manager_))); 624 new ShelfWindowTargeter(status_container, shelf_layout_manager_)));
611 625
612 views::Widget::AddObserver(this); 626 views::Widget::AddObserver(this);
613 } 627 }
614 628
615 ShelfWidget::~ShelfWidget() { 629 ShelfWidget::~ShelfWidget() {
616 // Must call Shutdown() before destruction. 630 // Must call Shutdown() before destruction.
617 DCHECK(!status_area_widget_); 631 DCHECK(!status_area_widget_);
618 WmShell::Get()->focus_cycler()->RemoveWidget(this); 632 WmShell::Get()->focus_cycler()->RemoveWidget(this);
619 SetFocusCycler(nullptr); 633 SetFocusCycler(nullptr);
620 RemoveObserver(this); 634 RemoveObserver(this);
635 background_animator_.RemoveObserver(delegate_view_);
636 if (shelf_)
637 background_animator_.RemoveObserver(shelf_.get());
638 static_cast<WmShelf*>(wm_shelf_aura_)->RemoveObserver(&background_animator_);
621 } 639 }
622 640
623 void ShelfWidget::SetPaintsBackground( 641 void ShelfWidget::SetPaintsBackground(
624 ShelfBackgroundType background_type, 642 ShelfBackgroundType background_type,
625 BackgroundAnimatorChangeType change_type) { 643 BackgroundAnimatorChangeType change_type) {
626 ui::Layer* opaque_background = delegate_view_->opaque_background(); 644 background_animator_.PaintBackground(background_type, change_type);
627 float target_opacity =
628 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f;
629 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation;
630 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) {
631 opaque_background_animation.reset(
632 new ui::ScopedLayerAnimationSettings(opaque_background->GetAnimator()));
633 opaque_background_animation->SetTransitionDuration(
634 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs));
635 }
636 opaque_background->SetOpacity(target_opacity);
637
638 // TODO(mukai): use ui::Layer on both opaque_background and normal background
639 // retire background_animator_ at all. It would be simpler.
640 // See also DockedBackgroundWidget::SetPaintsBackground.
641 background_animator_.SetPaintsBackground(
642 background_type != SHELF_BACKGROUND_DEFAULT, change_type);
643 } 645 }
644 646
645 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { 647 ShelfBackgroundType ShelfWidget::GetBackgroundType() const {
646 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) 648 return background_animator_.target_background_type();
647 return SHELF_BACKGROUND_MAXIMIZED;
648 if (background_animator_.paints_background())
649 return SHELF_BACKGROUND_OVERLAP;
650
651 return SHELF_BACKGROUND_DEFAULT;
652 } 649 }
653 650
654 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { 651 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) {
655 if (IsShelfHiddenBehindBlackBar() == hide) 652 if (IsShelfHiddenBehindBlackBar() == hide)
656 return; 653 return;
657 654
658 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); 655 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground();
659 float target_opacity = hide ? 1.0f : 0.0f; 656 float target_opacity = hide ? 1.0f : 0.0f;
660 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; 657 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation;
661 opaque_foreground_animation.reset( 658 opaque_foreground_animation.reset(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 // status area background, app list button and overflow button. 712 // status area background, app list button and overflow button.
716 if (shelf_) 713 if (shelf_)
717 shelf_->SchedulePaint(); 714 shelf_->SchedulePaint();
718 status_area_widget_->SchedulePaint(); 715 status_area_widget_->SchedulePaint();
719 } 716 }
720 717
721 bool ShelfWidget::GetDimsShelf() const { 718 bool ShelfWidget::GetDimsShelf() const {
722 return delegate_view_->GetDimmed(); 719 return delegate_view_->GetDimmed();
723 } 720 }
724 721
725 void ShelfWidget::CreateShelf(WmShelfAura* wm_shelf_aura) { 722 void ShelfWidget::CreateShelf() {
726 DCHECK(!shelf_); 723 DCHECK(!shelf_);
727 724
728 shelf_.reset(new Shelf(WmShell::Get()->shelf_model(), wm_shelf_aura, this)); 725 shelf_.reset(new Shelf(WmShell::Get()->shelf_model(), wm_shelf_aura_, this));
726 background_animator_.AddObserver(shelf_.get());
729 // Must be initialized before the delegate is notified because the delegate 727 // Must be initialized before the delegate is notified because the delegate
730 // may try to access the WmShelf. 728 // may try to access the WmShelf.
731 wm_shelf_aura->SetShelf(shelf_.get()); 729 wm_shelf_aura_->SetShelf(shelf_.get());
732 WmShell::Get()->shelf_delegate()->OnShelfCreated(shelf_.get()); 730 WmShell::Get()->shelf_delegate()->OnShelfCreated(shelf_.get());
733 731
734 SetFocusCycler(WmShell::Get()->focus_cycler()); 732 SetFocusCycler(WmShell::Get()->focus_cycler());
735 } 733 }
736 734
737 void ShelfWidget::PostCreateShelf() { 735 void ShelfWidget::PostCreateShelf() {
738 shelf_->SetVisible( 736 shelf_->SetVisible(
739 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()); 737 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted());
740 shelf_layout_manager_->LayoutShelf(); 738 shelf_layout_manager_->LayoutShelf();
741 shelf_layout_manager_->UpdateAutoHideState(); 739 shelf_layout_manager_->UpdateAutoHideState();
(...skipping 21 matching lines...) Expand all
763 761
764 void ShelfWidget::Shutdown() { 762 void ShelfWidget::Shutdown() {
765 // Shutting down the status area widget may cause some widgets (e.g. bubbles) 763 // Shutting down the status area widget may cause some widgets (e.g. bubbles)
766 // to close, so uninstall the ShelfLayoutManager event filters first. Don't 764 // to close, so uninstall the ShelfLayoutManager event filters first. Don't
767 // reset the pointer until later because other widgets (e.g. app list) may 765 // reset the pointer until later because other widgets (e.g. app list) may
768 // access it later in shutdown. 766 // access it later in shutdown.
769 if (shelf_layout_manager_) 767 if (shelf_layout_manager_)
770 shelf_layout_manager_->PrepareForShutdown(); 768 shelf_layout_manager_->PrepareForShutdown();
771 769
772 if (status_area_widget_) { 770 if (status_area_widget_) {
771 background_animator_.RemoveObserver(status_area_widget_);
773 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); 772 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_);
774 status_area_widget_->Shutdown(); 773 status_area_widget_->Shutdown();
775 status_area_widget_ = nullptr; 774 status_area_widget_ = nullptr;
776 } 775 }
777 } 776 }
778 777
779 void ShelfWidget::ForceUndimming(bool force) { 778 void ShelfWidget::ForceUndimming(bool force) {
780 delegate_view_->ForceUndimming(force); 779 delegate_view_->ForceUndimming(force);
781 } 780 }
782 781
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); 816 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event);
818 } 817 }
819 818
820 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { 819 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) {
821 Widget::OnGestureEvent(event); 820 Widget::OnGestureEvent(event);
822 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) 821 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_)
823 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); 822 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event);
824 } 823 }
825 824
826 } // namespace ash 825 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698