Chromium Code Reviews| Index: ash/system/tray/tray_background_view.cc |
| diff --git a/ash/system/tray/tray_background_view.cc b/ash/system/tray/tray_background_view.cc |
| index fc24c14932af7c4673e9a46c1d195ce8701d965a..7574664bd5f8c5248a15cbf0c7a720a821d466b2 100644 |
| --- a/ash/system/tray/tray_background_view.cc |
| +++ b/ash/system/tray/tray_background_view.cc |
| @@ -22,12 +22,17 @@ |
| #include "ui/aura/window.h" |
| #include "ui/aura/window_event_dispatcher.h" |
| #include "ui/base/resource/resource_bundle.h" |
| +#include "ui/compositor/layer.h" |
| +#include "ui/compositor/layer_animation_element.h" |
| +#include "ui/compositor/scoped_layer_animation_settings.h" |
| +#include "ui/gfx/animation/tween.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/image/image_skia.h" |
| #include "ui/gfx/image/image_skia_operations.h" |
| #include "ui/gfx/rect.h" |
| #include "ui/gfx/screen.h" |
| #include "ui/gfx/skia_util.h" |
| +#include "ui/gfx/transform.h" |
| #include "ui/views/background.h" |
| #include "ui/views/layout/box_layout.h" |
| @@ -38,6 +43,8 @@ const int kTrayBackgroundHoverAlpha = 150; |
| const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244); |
| const int kAnimationDurationForPopupMS = 200; |
| +const int kAnimationDurationForVisibility = 250; |
|
flackr
2014/05/06 15:42:11
Does this need to match the status area widget dur
jonross
2014/05/07 13:52:36
They currently match in the spec. However the spec
|
| +const int kShowAnimationDelay = 100; |
| } // namespace |
| @@ -307,6 +314,9 @@ TrayBackgroundView::TrayBackgroundView(StatusAreaWidget* status_area_widget) |
| tray_container_ = new TrayContainer(shelf_alignment_); |
| SetContents(tray_container_); |
| tray_event_filter_.reset(new TrayEventFilter); |
| + |
| + SetPaintToLayer(true); |
| + SetFillsBoundsOpaquely(false); |
| } |
| TrayBackgroundView::~TrayBackgroundView() { |
| @@ -319,6 +329,45 @@ void TrayBackgroundView::Initialize() { |
| SetTrayBorder(); |
| } |
| +void TrayBackgroundView::SetVisible(bool visible) { |
| + if (visible == this->visible()) |
| + return; |
| + |
| + if (!this->visible()) { |
| + // A translation transform was applied when becoming hidden. However the |
| + // alignment of the shelf can change. Reset the offscreen transform so that |
| + // the animation to becoming visible reflects the changed layout. |
| + HideTransformation(); |
|
flackr
2014/05/06 15:42:11
Given visible != this->visible(), if !this->visibl
jonross
2014/05/07 13:52:36
Done.
|
| + } |
| + |
| + if (visible) |
| + views::View::SetVisible(visible); |
|
flackr
2014/05/06 15:42:11
Comment that SetVisible(false) is deferred until a
jonross
2014/05/07 13:52:36
Done.
|
| + |
| + layer()->GetAnimator()->StopAnimating(); |
| + ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); |
| + animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| + kAnimationDurationForVisibility)); |
| + animation.SetPreemptionStrategy( |
| + ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| + animation.AddObserver(this); |
| + |
| + if (visible) { |
| + animation.SetTweenType(gfx::Tween::EASE_OUT); |
| + layer()->GetAnimator()->SchedulePauseForProperties( |
|
flackr
2014/05/06 15:42:11
Why is the show delayed? Add comment as to why.
jonross
2014/05/07 13:52:36
Done.
|
| + base::TimeDelta::FromMilliseconds(kShowAnimationDelay), |
| + ui::LayerAnimationElement::OPACITY | |
| + ui::LayerAnimationElement::TRANSFORM); |
| + layer()->SetOpacity(1.0f); |
| + gfx::Transform transform; |
| + transform.Translate(0.0f, 0.0f); |
| + layer()->SetTransform(transform); |
| + } else { |
| + animation.SetTweenType(gfx::Tween::EASE_IN); |
| + layer()->SetOpacity(0.0f); |
|
flackr
2014/05/06 15:42:11
Perhaps also layer()->SetVisible(false);
jonross
2014/05/07 13:52:36
Done.
|
| + HideTransformation(); |
| + } |
| +} |
| + |
| const char* TrayBackgroundView::GetClassName() const { |
| return kViewClassName; |
| } |
| @@ -420,6 +469,21 @@ void TrayBackgroundView::SetTrayBorder() { |
| top_edge, left_edge, bottom_edge, right_edge)); |
| } |
| +void TrayBackgroundView::OnImplicitAnimationsCompleted() { |
| + if (layer()->opacity() == 0.0f) |
|
flackr
2014/05/06 15:42:11
It might be more robust to compare the layer's vis
jonross
2014/05/07 13:52:36
Moved the listener to only be added for the !visib
|
| + views::View::SetVisible(false); |
| +} |
| + |
| +void TrayBackgroundView::HideTransformation() { |
| + gfx::Transform transform; |
| + if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM || |
| + shelf_alignment_ == SHELF_ALIGNMENT_TOP) |
| + transform.Translate(width(), 0.0f); |
| + else |
| + transform.Translate(0.0f, height()); |
| + layer()->SetTransform(transform); |
| +} |
| + |
| void TrayBackgroundView::InitializeBubbleAnimations( |
| views::Widget* bubble_widget) { |
| wm::SetWindowVisibilityAnimationType( |