Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1111)

Unified Diff: ash/system/tray/tray_background_view.cc

Issue 251193004: Animate the OverviewButtonTray (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a29a2ded0368a3549990122fb0ede3c4aeb812ac 100644
--- a/ash/system/tray/tray_background_view.cc
+++ b/ash/system/tray/tray_background_view.cc
@@ -38,7 +38,10 @@ const int kTrayBackgroundHoverAlpha = 150;
const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244);
const int kAnimationDurationForPopupMS = 200;
+const int kAnimationDurationForVisibility = 200;
+// Animations can be disabled for tests.
+bool animations_enabled = true;
flackr 2014/04/29 14:18:22 nit: newline before end of namespace.
jonross 2014/04/30 14:09:31 Done.
} // namespace
using views::TrayBubbleView;
@@ -307,6 +310,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 +325,48 @@ void TrayBackgroundView::Initialize() {
SetTrayBorder();
}
+void TrayBackgroundView::SetVisible(bool set_visible) {
+ if (!GetWidget() || !animations_enabled) {
+ views::View::SetVisible(set_visible);
+ return;
+ }
+
+ if (!animation_) {
+ animation_.reset(new gfx::SlideAnimation(this));
+ animation_->SetSlideDuration(kAnimationDurationForVisibility);
+ animation_->SetTweenType(gfx::Tween::LINEAR);
+ animation_->Reset(visible() ? 1.0 : 0.0);
+ }
+
+ if (!set_visible) {
+ animation_->Hide();
+ AnimationProgressed(animation_.get());
flackr 2014/04/29 14:18:22 Isn't AnimationProgressed supposed to be called au
+ } else {
+ animation_->Show();
+ AnimationProgressed(animation_.get());
+ views::View::SetVisible(true);
+ }
+}
+
+gfx::Size TrayBackgroundView::GetPreferredSize() {
+ gfx::Size size = views::View::GetPreferredSize();
+ if (!animation_.get() || !animation_->is_animating())
+ return size;
+ if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM ||
+ shelf_alignment_ == SHELF_ALIGNMENT_TOP) {
+ size.set_width(std::max(1,
+ static_cast<int>(size.width() * animation_->GetCurrentValue())));
+ } else {
+ size.set_height(std::max(1,
+ static_cast<int>(size.height() * animation_->GetCurrentValue())));
+ }
+ return size;
+}
+
+int TrayBackgroundView::GetHeightForWidth(int width) {
+ return GetPreferredSize().height();
+}
+
const char* TrayBackgroundView::GetClassName() const {
return kViewClassName;
}
@@ -420,6 +468,35 @@ void TrayBackgroundView::SetTrayBorder() {
top_edge, left_edge, bottom_edge, right_edge));
}
+void TrayBackgroundView::DisableAnimationsForTest() {
+ animations_enabled = false;
flackr 2014/04/29 14:18:22 I realize this pattern is copied from elsewhere, b
+}
+
+void TrayBackgroundView::AnimationProgressed(const gfx::Animation* animation) {
+ gfx::Transform transform;
+ if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM ||
+ shelf_alignment_ == SHELF_ALIGNMENT_TOP) {
+ transform.Translate(0, animation->CurrentValueBetween(
+ static_cast<double>(height()) / 2, 0.));
flackr 2014/04/29 14:18:22 nit: The static_cast is unnecessary for this sort
+ } else {
+ transform.Translate(animation->CurrentValueBetween(
+ static_cast<double>(width() / 2), 0.), 0);
flackr 2014/04/29 14:18:22 ditto.
+ }
+ transform.Scale(animation->GetCurrentValue(),
+ animation->GetCurrentValue());
+ layer()->SetTransform(transform);
flackr 2014/04/29 14:18:22 The animation is done as a layer transform? Would
+ PreferredSizeChanged();
+}
+
+void TrayBackgroundView::AnimationEnded(const gfx::Animation* animation) {
+ if (animation->GetCurrentValue() < 0.1)
+ views::View::SetVisible(false);
+}
+
+void TrayBackgroundView::AnimationCanceled(const gfx::Animation* animation) {
+ AnimationEnded(animation);
flackr 2014/04/29 14:18:22 Isn't this not guaranteed to give the correct resu
+}
+
void TrayBackgroundView::InitializeBubbleAnimations(
views::Widget* bubble_widget) {
wm::SetWindowVisibilityAnimationType(
« no previous file with comments | « ash/system/tray/tray_background_view.h ('k') | ash/system/web_notification/web_notification_tray_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698