Index: ash/shelf/shelf_widget.cc |
diff --git a/ash/shelf/shelf_widget.cc b/ash/shelf/shelf_widget.cc |
index 9c6ea09e47ceb3b30eb83bbfe3b3e5b31d49cc67..b89ab13880a524e8edccf693a1705b06e47607e4 100644 |
--- a/ash/shelf/shelf_widget.cc |
+++ b/ash/shelf/shelf_widget.cc |
@@ -9,6 +9,7 @@ |
#include "ash/aura/wm_window_aura.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_model.h" |
#include "ash/common/shelf/wm_shelf_util.h" |
@@ -80,11 +81,14 @@ class DimmerView : public views::View, |
const views::Widget* GetWidget() const override { return View::GetWidget(); } |
// BackgroundAnimatorDelegate overrides: |
- void UpdateBackground(int alpha) override { |
+ void UpdateBackground(BackgroundAnimator* animator, int alpha) override { |
alpha_ = alpha; |
SchedulePaint(); |
} |
+ void BackgroundAnimationEnded(BackgroundAnimator* animator, |
+ bool successful) override {} |
+ |
// views::View overrides: |
void OnPaintBackground(gfx::Canvas* canvas) override; |
@@ -302,8 +306,8 @@ class ShelfWindowTargeter : public ::wm::EasyResizeWindowTargeter, |
// 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 BackgroundAnimatorDelegate, |
- public aura::WindowObserver { |
+ public aura::WindowObserver, |
+ public ShelfBackgroundAnimatorObserver { |
public: |
explicit DelegateView(ShelfWidget* shelf); |
~DelegateView() override; |
@@ -343,8 +347,9 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate, |
const gfx::Rect& old_bounds, |
const gfx::Rect& new_bounds) override; |
- // BackgroundAnimatorDelegate overrides: |
- void UpdateBackground(int alpha) override; |
+ // ShelfBackgroundAnimatorObserver: |
+ void UpdateShelfOpaqueBackground(int alpha) override; |
+ void UpdateShelfAssetBackground(int alpha) override; |
// Force the shelf to be presented in an undimmed state. |
void ForceUndimming(bool force); |
@@ -367,7 +372,8 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate, |
ShelfWidget* shelf_; |
std::unique_ptr<views::Widget> dimmer_; |
FocusCycler* focus_cycler_; |
- int alpha_; |
+ int asset_background_alpha_; |
James Cook
2016/06/14 17:50:02
Hooray for more explicit variable names!
|
+ // TODO(bruthig): Remove opaque_background_. |
James Cook
2016/06/14 17:50:02
Please file a bug for this and reference it here.
bruthig
2016/07/26 19:50:03
Done.
|
// 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. |
@@ -387,7 +393,7 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate, |
ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) |
: shelf_(shelf), |
focus_cycler_(NULL), |
- alpha_(0), |
+ asset_background_alpha_(0), |
opaque_background_(ui::LAYER_SOLID_COLOR), |
opaque_foreground_(ui::LAYER_SOLID_COLOR), |
dimmer_view_(NULL), |
@@ -450,9 +456,7 @@ void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { |
} |
void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
- if (MaterialDesignController::IsShelfMaterial()) { |
- canvas->FillRect(bounds(), SkColorSetA(kShelfBaseColor, alpha_)); |
- } else { |
+ if (!MaterialDesignController::IsShelfMaterial()) { |
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
gfx::ImageSkia shelf_background = |
*rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); |
@@ -465,7 +469,7 @@ void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
} |
const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); |
SkPaint paint; |
- paint.setAlpha(alpha_); |
+ paint.setAlpha(asset_background_alpha_); |
canvas->DrawImageInt( |
shelf_background, 0, 0, shelf_background.width(), |
shelf_background.height(), |
@@ -560,8 +564,13 @@ gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { |
return gfx::Rect(); |
} |
-void ShelfWidget::DelegateView::UpdateBackground(int alpha) { |
- alpha_ = alpha; |
+void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { |
+ const double kMaxAlpha = 255.0; |
James Cook
2016/06/14 17:50:02
could be a float
bruthig
2016/07/26 19:50:03
Done.
|
+ opaque_background_.SetOpacity(alpha / kMaxAlpha); |
+} |
+ |
+void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { |
+ asset_background_alpha_ = alpha; |
SchedulePaint(); |
} |
@@ -569,8 +578,6 @@ ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, |
WmWindow* wm_status_container, |
WorkspaceController* workspace_controller) |
: delegate_view_(new DelegateView(this)), |
- background_animator_( |
- delegate_view_, 0, GetShelfConstant(SHELF_BACKGROUND_ALPHA)), |
activating_as_fallback_(false) { |
views::Widget::InitParams params( |
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
@@ -595,6 +602,8 @@ ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, |
shelf_layout_manager_->set_workspace_controller(workspace_controller); |
workspace_controller->SetShelf(shelf_layout_manager_); |
+ background_animator_.AddObserver(delegate_view_); |
James Cook
2016/06/14 17:50:02
Does this need to be done here, or could it happen
bruthig
2016/07/26 19:50:03
Done.
|
+ |
status_area_widget_ = new StatusAreaWidget(wm_status_container, this); |
status_area_widget_->CreateTrayViews(); |
if (Shell::GetInstance()->session_state_delegate()-> |
@@ -602,6 +611,7 @@ ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, |
status_area_widget_->Show(); |
} |
Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); |
+ background_animator_.AddObserver(status_area_widget_); |
aura::Window* status_container = |
WmWindowAura::GetAuraWindow(wm_status_container); |
@@ -613,6 +623,11 @@ ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, |
status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
new ShelfWindowTargeter(status_container, shelf_layout_manager_))); |
+ // Forcefully paint the background after all observers have been added so they |
+ // paint properly the first time. |
+ background_animator_.PaintBackground(SHELF_BACKGROUND_DEFAULT, |
+ BACKGROUND_CHANGE_IMMEDIATE); |
+ |
views::Widget::AddObserver(this); |
} |
@@ -627,32 +642,11 @@ ShelfWidget::~ShelfWidget() { |
void ShelfWidget::SetPaintsBackground( |
ShelfBackgroundType background_type, |
BackgroundAnimatorChangeType 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); |
+ background_animator_.PaintBackground(background_type, change_type); |
} |
ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
- 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; |
+ return background_animator_.target_background_type(); |
} |
void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { |
@@ -735,6 +729,10 @@ void ShelfWidget::CreateShelf(WmShelfAura* wm_shelf_aura) { |
// Must be initialized before the delegate is notified because the delegate |
// may try to access the WmShelf. |
wm_shelf_aura->SetShelf(shelf_.get()); |
+ // TODO(bruthig): Is this the best/right place to attach the |
+ // |background_animator_|? Does |background_animator_| need to be removed as |
+ // an observer? |
+ wm_shelf_aura->AddObserver(&background_animator_); |
James Cook
2016/06/14 17:50:02
Given that the items being animated are built in t
bruthig
2016/07/26 19:50:03
Done.
|
delegate->OnShelfCreated(shelf_.get()); |
SetFocusCycler(shell->focus_cycler()); |
@@ -778,6 +776,7 @@ void ShelfWidget::Shutdown() { |
if (status_area_widget_) { |
Shell::GetInstance()->focus_cycler()->RemoveWidget(status_area_widget_); |
+ background_animator_.RemoveObserver(status_area_widget_); |
status_area_widget_->Shutdown(); |
status_area_widget_ = nullptr; |
} |