| Index: ash/shelf/shelf_widget.cc
|
| diff --git a/ash/shelf/shelf_widget.cc b/ash/shelf/shelf_widget.cc
|
| index d93dc6c9b77886853acf27975e2ecc3da7d47d77..0b986a38b947c47dc1f83a0c9218f75998244855 100644
|
| --- a/ash/shelf/shelf_widget.cc
|
| +++ b/ash/shelf/shelf_widget.cc
|
| @@ -10,11 +10,9 @@
|
| #include "ash/common/focus_cycler.h"
|
| #include "ash/common/material_design/material_design_controller.h"
|
| #include "ash/common/session/session_state_delegate.h"
|
| -#include "ash/common/shelf/shelf_background_animator_observer.h"
|
| #include "ash/common/shelf/shelf_constants.h"
|
| #include "ash/common/shelf/shelf_delegate.h"
|
| #include "ash/common/shelf/shelf_model.h"
|
| -#include "ash/common/shelf/wm_shelf.h"
|
| #include "ash/common/shelf/wm_shelf_util.h"
|
| #include "ash/common/shell_window_ids.h"
|
| #include "ash/common/system/status_area_widget.h"
|
| @@ -83,12 +81,10 @@
|
| const views::Widget* GetWidget() const override { return View::GetWidget(); }
|
|
|
| // BackgroundAnimatorDelegate overrides:
|
| - void UpdateBackground(BackgroundAnimator* animator, int alpha) override {
|
| + void UpdateBackground(int alpha) override {
|
| alpha_ = alpha;
|
| SchedulePaint();
|
| }
|
| -
|
| - void BackgroundAnimationEnded(BackgroundAnimator* animator) override {}
|
|
|
| // views::View overrides:
|
| void OnPaintBackground(gfx::Canvas* canvas) override;
|
| @@ -302,8 +298,8 @@
|
| // sizes it to the width of the shelf minus the size of the status area.
|
| class ShelfWidget::DelegateView : public views::WidgetDelegate,
|
| public views::AccessiblePaneView,
|
| - public aura::WindowObserver,
|
| - public ShelfBackgroundAnimatorObserver {
|
| + public BackgroundAnimatorDelegate,
|
| + public aura::WindowObserver {
|
| public:
|
| explicit DelegateView(ShelfWidget* shelf);
|
| ~DelegateView() override;
|
| @@ -343,9 +339,8 @@
|
| const gfx::Rect& old_bounds,
|
| const gfx::Rect& new_bounds) override;
|
|
|
| - // ShelfBackgroundAnimatorObserver:
|
| - void UpdateShelfOpaqueBackground(int alpha) override;
|
| - void UpdateShelfAssetBackground(int alpha) override;
|
| + // BackgroundAnimatorDelegate overrides:
|
| + void UpdateBackground(int alpha) override;
|
|
|
| // Force the shelf to be presented in an undimmed state.
|
| void ForceUndimming(bool force);
|
| @@ -368,8 +363,7 @@
|
| ShelfWidget* shelf_;
|
| std::unique_ptr<views::Widget> dimmer_;
|
| FocusCycler* focus_cycler_;
|
| - int asset_background_alpha_;
|
| - // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551).
|
| + int alpha_;
|
| // A black background layer which is shown when a maximized window is visible.
|
| ui::Layer opaque_background_;
|
| // A black foreground layer which is shown while transitioning between users.
|
| @@ -389,7 +383,7 @@
|
| ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf)
|
| : shelf_(shelf),
|
| focus_cycler_(NULL),
|
| - asset_background_alpha_(0),
|
| + alpha_(0),
|
| opaque_background_(ui::LAYER_SOLID_COLOR),
|
| opaque_foreground_(ui::LAYER_SOLID_COLOR),
|
| dimmer_view_(NULL),
|
| @@ -452,59 +446,62 @@
|
| }
|
|
|
| void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
|
| - if (MaterialDesignController::IsShelfMaterial())
|
| - return;
|
| -
|
| - ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
|
| - gfx::ImageSkia shelf_background =
|
| - *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
|
| - const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment());
|
| - if (!horizontal) {
|
| - shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
|
| - shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT
|
| - ? SkBitmapOperations::ROTATION_90_CW
|
| - : SkBitmapOperations::ROTATION_270_CW);
|
| - }
|
| - const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds());
|
| - SkPaint paint;
|
| - paint.setAlpha(asset_background_alpha_);
|
| - canvas->DrawImageInt(
|
| - shelf_background, 0, 0, shelf_background.width(),
|
| - shelf_background.height(),
|
| - (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0)
|
| - ? dock_bounds.width()
|
| - : 0,
|
| - 0, horizontal ? width() - dock_bounds.width() : width(), height(), false,
|
| - paint);
|
| - if (horizontal && dock_bounds.width() > 0) {
|
| - // The part of the shelf background that is in the corner below the docked
|
| - // windows close to the work area is an arched gradient that blends
|
| - // vertically oriented docked background and horizontal shelf.
|
| - gfx::ImageSkia shelf_corner = *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER);
|
| - if (dock_bounds.x() == 0) {
|
| - shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage(
|
| - shelf_corner, SkBitmapOperations::ROTATION_90_CW);
|
| + if (MaterialDesignController::IsShelfMaterial()) {
|
| + canvas->FillRect(bounds(), SkColorSetA(kShelfBaseColor, alpha_));
|
| + } else {
|
| + ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
|
| + gfx::ImageSkia shelf_background =
|
| + *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
|
| + const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment());
|
| + if (!horizontal) {
|
| + shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
|
| + shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT
|
| + ? SkBitmapOperations::ROTATION_90_CW
|
| + : SkBitmapOperations::ROTATION_270_CW);
|
| }
|
| + const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds());
|
| + SkPaint paint;
|
| + paint.setAlpha(alpha_);
|
| canvas->DrawImageInt(
|
| - shelf_corner, 0, 0, shelf_corner.width(), shelf_corner.height(),
|
| - dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(),
|
| - 0, height(), height(), false, paint);
|
| - // The part of the shelf background that is just below the docked windows
|
| - // is drawn using the last (lowest) 1-pixel tall strip of the image asset.
|
| - // This avoids showing the border 3D shadow between the shelf and the
|
| - // dock.
|
| - canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1,
|
| - shelf_background.width(), 1,
|
| - dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0,
|
| - 0, dock_bounds.width() - height(), height(), false,
|
| - paint);
|
| - }
|
| - gfx::Rect black_rect =
|
| - shelf_->shelf_layout_manager()->SelectValueForShelfAlignment(
|
| - gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels),
|
| - gfx::Rect(0, 0, kNumBlackPixels, height()),
|
| - gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()));
|
| - canvas->FillRect(black_rect, SK_ColorBLACK);
|
| + shelf_background, 0, 0, shelf_background.width(),
|
| + shelf_background.height(),
|
| + (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0)
|
| + ? dock_bounds.width()
|
| + : 0,
|
| + 0, horizontal ? width() - dock_bounds.width() : width(), height(),
|
| + false, paint);
|
| + if (horizontal && dock_bounds.width() > 0) {
|
| + // The part of the shelf background that is in the corner below the docked
|
| + // windows close to the work area is an arched gradient that blends
|
| + // vertically oriented docked background and horizontal shelf.
|
| + gfx::ImageSkia shelf_corner =
|
| + *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER);
|
| + if (dock_bounds.x() == 0) {
|
| + shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage(
|
| + shelf_corner, SkBitmapOperations::ROTATION_90_CW);
|
| + }
|
| + canvas->DrawImageInt(shelf_corner, 0, 0, shelf_corner.width(),
|
| + shelf_corner.height(),
|
| + dock_bounds.x() > 0 ? dock_bounds.x()
|
| + : dock_bounds.width() - height(),
|
| + 0, height(), height(), false, paint);
|
| + // The part of the shelf background that is just below the docked windows
|
| + // is drawn using the last (lowest) 1-pixel tall strip of the image asset.
|
| + // This avoids showing the border 3D shadow between the shelf and the
|
| + // dock.
|
| + canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1,
|
| + shelf_background.width(), 1,
|
| + dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0,
|
| + 0, dock_bounds.width() - height(), height(), false,
|
| + paint);
|
| + }
|
| + gfx::Rect black_rect =
|
| + shelf_->shelf_layout_manager()->SelectValueForShelfAlignment(
|
| + gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels),
|
| + gfx::Rect(0, 0, kNumBlackPixels, height()),
|
| + gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()));
|
| + canvas->FillRect(black_rect, SK_ColorBLACK);
|
| + }
|
| }
|
|
|
| bool ShelfWidget::DelegateView::CanActivate() const {
|
| @@ -558,13 +555,8 @@
|
| return gfx::Rect();
|
| }
|
|
|
| -void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) {
|
| - const float kMaxAlpha = 255.0f;
|
| - opaque_background_.SetOpacity(alpha / kMaxAlpha);
|
| -}
|
| -
|
| -void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) {
|
| - asset_background_alpha_ = alpha;
|
| +void ShelfWidget::DelegateView::UpdateBackground(int alpha) {
|
| + alpha_ = alpha;
|
| SchedulePaint();
|
| }
|
|
|
| @@ -572,12 +564,11 @@
|
| WmWindow* wm_status_container,
|
| WmShelfAura* wm_shelf_aura,
|
| WorkspaceController* workspace_controller)
|
| - : wm_shelf_aura_(wm_shelf_aura),
|
| - delegate_view_(new DelegateView(this)),
|
| - background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_aura_),
|
| + : delegate_view_(new DelegateView(this)),
|
| + background_animator_(delegate_view_,
|
| + 0,
|
| + GetShelfConstant(SHELF_BACKGROUND_ALPHA)),
|
| activating_as_fallback_(false) {
|
| - background_animator_.AddObserver(delegate_view_);
|
| -
|
| views::Widget::InitParams params(
|
| views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
|
| params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
|
| @@ -600,19 +591,15 @@
|
| shelf_container->SetLayoutManager(shelf_layout_manager_);
|
| shelf_layout_manager_->set_workspace_controller(workspace_controller);
|
| workspace_controller->SetShelf(shelf_layout_manager_);
|
| - background_animator_.PaintBackground(
|
| - shelf_layout_manager_->GetShelfBackgroundType(),
|
| - BACKGROUND_CHANGE_IMMEDIATE);
|
| - wm_shelf_aura_->SetShelfLayoutManager(shelf_layout_manager_);
|
| + wm_shelf_aura->SetShelfLayoutManager(shelf_layout_manager_);
|
|
|
| // TODO(jamescook): Move ownership to RootWindowController.
|
| status_area_widget_ =
|
| - new StatusAreaWidget(wm_status_container, wm_shelf_aura_);
|
| + new StatusAreaWidget(wm_status_container, wm_shelf_aura);
|
| status_area_widget_->CreateTrayViews();
|
| if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted())
|
| status_area_widget_->Show();
|
| WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_);
|
| - background_animator_.AddObserver(status_area_widget_);
|
|
|
| aura::Window* status_container =
|
| WmWindowAura::GetAuraWindow(wm_status_container);
|
| @@ -633,17 +620,37 @@
|
| WmShell::Get()->focus_cycler()->RemoveWidget(this);
|
| SetFocusCycler(nullptr);
|
| RemoveObserver(this);
|
| - background_animator_.RemoveObserver(delegate_view_);
|
| }
|
|
|
| void ShelfWidget::SetPaintsBackground(
|
| ShelfBackgroundType background_type,
|
| BackgroundAnimatorChangeType change_type) {
|
| - background_animator_.PaintBackground(background_type, change_type);
|
| + ui::Layer* opaque_background = delegate_view_->opaque_background();
|
| + float target_opacity =
|
| + (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f;
|
| + std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation;
|
| + if (change_type != BACKGROUND_CHANGE_IMMEDIATE) {
|
| + opaque_background_animation.reset(
|
| + new ui::ScopedLayerAnimationSettings(opaque_background->GetAnimator()));
|
| + opaque_background_animation->SetTransitionDuration(
|
| + base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs));
|
| + }
|
| + opaque_background->SetOpacity(target_opacity);
|
| +
|
| + // TODO(mukai): use ui::Layer on both opaque_background and normal background
|
| + // retire background_animator_ at all. It would be simpler.
|
| + // See also DockedBackgroundWidget::SetPaintsBackground.
|
| + background_animator_.SetPaintsBackground(
|
| + background_type != SHELF_BACKGROUND_DEFAULT, change_type);
|
| }
|
|
|
| ShelfBackgroundType ShelfWidget::GetBackgroundType() const {
|
| - return background_animator_.target_background_type();
|
| + if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f)
|
| + return SHELF_BACKGROUND_MAXIMIZED;
|
| + if (background_animator_.paints_background())
|
| + return SHELF_BACKGROUND_OVERLAP;
|
| +
|
| + return SHELF_BACKGROUND_DEFAULT;
|
| }
|
|
|
| void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) {
|
| @@ -717,14 +724,13 @@
|
| return delegate_view_->GetDimmed();
|
| }
|
|
|
| -void ShelfWidget::CreateShelf() {
|
| +void ShelfWidget::CreateShelf(WmShelfAura* wm_shelf_aura) {
|
| DCHECK(!shelf_);
|
|
|
| - shelf_.reset(new Shelf(WmShell::Get()->shelf_model(), wm_shelf_aura_, this,
|
| - &background_animator_));
|
| + shelf_.reset(new Shelf(WmShell::Get()->shelf_model(), wm_shelf_aura, this));
|
| // Must be initialized before the delegate is notified because the delegate
|
| // may try to access the WmShelf.
|
| - wm_shelf_aura_->SetShelf(shelf_.get());
|
| + wm_shelf_aura->SetShelf(shelf_.get());
|
| WmShell::Get()->shelf_delegate()->OnShelfCreated(shelf_.get());
|
|
|
| SetFocusCycler(WmShell::Get()->focus_cycler());
|
| @@ -766,7 +772,6 @@
|
| shelf_layout_manager_->PrepareForShutdown();
|
|
|
| if (status_area_widget_) {
|
| - background_animator_.RemoveObserver(status_area_widget_);
|
| WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_);
|
| status_area_widget_->Shutdown();
|
| status_area_widget_ = nullptr;
|
|
|