summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
Diffstat (limited to 'ash')
-rw-r--r--ash/system/status_area_widget_delegate.cc35
-rw-r--r--ash/system/tray/tray_background_view.cc81
-rw-r--r--ash/system/tray/tray_background_view.h24
3 files changed, 131 insertions, 9 deletions
diff --git a/ash/system/status_area_widget_delegate.cc b/ash/system/status_area_widget_delegate.cc
index babe66d..cfdae47 100644
--- a/ash/system/status_area_widget_delegate.cc
+++ b/ash/system/status_area_widget_delegate.cc
@@ -10,15 +10,43 @@
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/system/tray/tray_constants.h"
+#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/compositor/layer.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.h"
#include "ui/views/accessible_pane_view.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/widget/widget.h"
+namespace {
+
+const int kAnimationDurationMs = 250;
+
+class StatusAreaWidgetDelegateAnimationSettings
+ : public ui::ScopedLayerAnimationSettings {
+ public:
+ explicit StatusAreaWidgetDelegateAnimationSettings(ui::Layer* layer)
+ : ui::ScopedLayerAnimationSettings(layer->GetAnimator()) {
+ SetTransitionDuration(
+ base::TimeDelta::FromMilliseconds(kAnimationDurationMs));
+ SetPreemptionStrategy(
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
+ SetTweenType(gfx::Tween::EASE_IN_OUT);
+ }
+
+ virtual ~StatusAreaWidgetDelegateAnimationSettings() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(StatusAreaWidgetDelegateAnimationSettings);
+};
+
+} // namespace
+
namespace ash {
StatusAreaWidgetDelegate::StatusAreaWidgetDelegate()
@@ -27,6 +55,8 @@ StatusAreaWidgetDelegate::StatusAreaWidgetDelegate()
// Allow the launcher to surrender the focus to another window upon
// navigation completion by the user.
set_allow_deactivate_on_esc(true);
+ SetPaintToLayer(true);
+ SetFillsBoundsOpaquely(false);
}
StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() {
@@ -117,12 +147,17 @@ void StatusAreaWidgetDelegate::UpdateLayout() {
layout->AddView(child);
}
}
+
+ layer()->GetAnimator()->StopAnimating();
+ StatusAreaWidgetDelegateAnimationSettings settings(layer());
+
Layout();
UpdateWidgetSize();
}
void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) {
// Need to resize the window when trays or items are added/removed.
+ StatusAreaWidgetDelegateAnimationSettings settings(layer());
UpdateWidgetSize();
}
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_;