summaryrefslogtreecommitdiffstats
path: root/ash/system/tray
diff options
context:
space:
mode:
authorjonross@chromium.org <jonross@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-09 18:21:37 +0000
committerjonross@chromium.org <jonross@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-09 18:21:37 +0000
commitf2eb09cd51c6c3dec830abd6613c0df130b7c08f (patch)
treeeaf2ceeb35aad532a279533431dc73a7dd57b965 /ash/system/tray
parent5ad9f1557bd7cfac8a900e693400707760bb3fad (diff)
downloadchromium_src-f2eb09cd51c6c3dec830abd6613c0df130b7c08f.zip
chromium_src-f2eb09cd51c6c3dec830abd6613c0df130b7c08f.tar.gz
chromium_src-f2eb09cd51c6c3dec830abd6613c0df130b7c08f.tar.bz2
Animate the OverviewButtonTray
Take the animations from TrayItemView and port them to TrayBackgroundView so that the outer trays also animate their visibility. TEST=OverviewButtonTray TEST=SystemTrayTest TEST=WebNotificationTrayTest BUG=363714 Review URL: https://codereview.chromium.org/251193004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/system/tray')
-rw-r--r--ash/system/tray/tray_background_view.cc81
-rw-r--r--ash/system/tray/tray_background_view.h24
2 files changed, 96 insertions, 9 deletions
diff --git a/ash/system/tray/tray_background_view.cc b/ash/system/tray/tray_background_view.cc
index fc24c14..2ece371 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"
@@ -37,7 +42,15 @@ const int kTrayBackgroundAlpha = 100;
const int kTrayBackgroundHoverAlpha = 150;
const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244);
-const int kAnimationDurationForPopupMS = 200;
+const int kAnimationDurationForPopupMs = 200;
+
+// Duration of opacity animation for visibility changes.
+const int kAnimationDurationForVisibilityMs = 250;
+
+// When becoming visible delay the animation so that StatusAreaWidgetDelegate
+// can animate sibling views out of the position to be occuped by the
+// TrayBackgroundView.
+const int kShowAnimationDelayMs = 100;
} // namespace
@@ -307,6 +320,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 +335,53 @@ void TrayBackgroundView::Initialize() {
SetTrayBorder();
}
+void TrayBackgroundView::SetVisible(bool visible) {
+ if (visible == this->visible())
+ return;
+
+ if (visible) {
+ // The alignment of the shelf can change while the TrayBackgroundView is
+ // hidden. Reset the offscreen transform so that the animation to becoming
+ // visible reflects the current layout.
+ HideTransformation();
+ // SetVisible(false) is defered until the animation for hiding is done.
+ // Otherwise the view is immediately hidden and the animation does not
+ // render.
+ views::View::SetVisible(visible);
+ }
+
+ layer()->GetAnimator()->StopAnimating();
+ ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
+ animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
+ kAnimationDurationForVisibilityMs));
+ animation.SetPreemptionStrategy(
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
+
+ if (visible) {
+ animation.SetTweenType(gfx::Tween::EASE_OUT);
+ // Show is delayed so as to allow time for other children of
+ // StatusAreaWidget to begin animating to their new positions.
+ layer()->GetAnimator()->SchedulePauseForProperties(
+ base::TimeDelta::FromMilliseconds(kShowAnimationDelayMs),
+ ui::LayerAnimationElement::OPACITY |
+ ui::LayerAnimationElement::TRANSFORM);
+ // layer()->SetVisible(true) is handled by views::View::SetVisible(true) so
+ // we do not need to apply that change while becoming visible.
+ layer()->SetOpacity(1.0f);
+ gfx::Transform transform;
+ transform.Translate(0.0f, 0.0f);
+ layer()->SetTransform(transform);
+ } else {
+ // Listen only to the hide animation. As we cannot turn off visibility
+ // until the animation is over.
+ animation.AddObserver(this);
+ animation.SetTweenType(gfx::Tween::EASE_IN);
+ layer()->SetOpacity(0.0f);
+ layer()->SetVisible(false);
+ HideTransformation();
+ }
+}
+
const char* TrayBackgroundView::GetClassName() const {
return kViewClassName;
}
@@ -420,6 +483,20 @@ void TrayBackgroundView::SetTrayBorder() {
top_edge, left_edge, bottom_edge, right_edge));
}
+void TrayBackgroundView::OnImplicitAnimationsCompleted() {
+ 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(
@@ -430,7 +507,7 @@ void TrayBackgroundView::InitializeBubbleAnimations(
wm::ANIMATE_HIDE);
wm::SetWindowVisibilityAnimationDuration(
bubble_widget->GetNativeWindow(),
- base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS));
+ base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMs));
}
aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const {
diff --git a/ash/system/tray/tray_background_view.h b/ash/system/tray/tray_background_view.h
index 365e63a..ce3c163 100644
--- a/ash/system/tray/tray_background_view.h
+++ b/ash/system/tray/tray_background_view.h
@@ -9,6 +9,7 @@
#include "ash/shelf/background_animator.h"
#include "ash/shelf/shelf_types.h"
#include "ash/system/tray/actionable_view.h"
+#include "ui/compositor/layer_animation_observer.h"
#include "ui/views/bubble/tray_bubble_view.h"
namespace ash {
@@ -18,12 +19,13 @@ class TrayEventFilter;
class TrayBackground;
// Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray,
-// LogoutButtonTray.
+// LogoutButtonTray, OverviewButtonTray.
// This class handles setting and animating the background when the Launcher
// his shown/hidden. It also inherits from ActionableView so that the tray
// items can override PerformAction when clicked on.
class ASH_EXPORT TrayBackgroundView : public ActionableView,
- public BackgroundAnimatorDelegate {
+ public BackgroundAnimatorDelegate,
+ public ui::ImplicitAnimationObserver {
public:
static const char kViewClassName[];
@@ -38,11 +40,11 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
void set_size(const gfx::Size& size) { size_ = size; }
- // Overridden from views::View.
+ // views::View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
protected:
- // Overridden from views::View.
+ // views::View:
virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
virtual void ChildVisibilityChanged(View* child) OVERRIDE;
virtual void ViewHierarchyChanged(
@@ -63,7 +65,8 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// Called after the tray has been added to the widget containing it.
virtual void Initialize();
- // Overridden from views::View.
+ // views::View:
+ virtual void SetVisible(bool visible) OVERRIDE;
virtual const char* GetClassName() const OVERRIDE;
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
@@ -71,11 +74,11 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
- // Overridden from ActionableView.
+ // ActionableView:
virtual bool PerformAction(const ui::Event& event) OVERRIDE;
virtual gfx::Rect GetFocusBounds() OVERRIDE;
- // Overridden from BackgroundAnimatorDelegate.
+ // BackgroundAnimatorDelegate:
virtual void UpdateBackground(int alpha) OVERRIDE;
// Called whenever the shelf alignment changes.
@@ -152,6 +155,13 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// Sets the border based on the position of the view.
void SetTrayBorder();
+ // ui::ImplicitAnimationObserver:
+ virtual void OnImplicitAnimationsCompleted() OVERRIDE;
+
+ // Applies transformations to the |layer()| to animate the view when
+ // SetVisible(false) is called.
+ void HideTransformation();
+
// Unowned pointer to parent widget.
StatusAreaWidget* status_area_widget_;