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

Side by Side Diff: ash/system/tray/tray_item_view.cc

Issue 9969068: ash: Animate changes in the uber tray. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/system/tray/tray_item_view.h ('k') | ash/system/tray_accessibility.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/system/tray/tray_item_view.h"
6
7 #include "ui/base/animation/slide_animation.h"
8 #include "ui/gfx/compositor/layer.h"
9 #include "ui/views/controls/image_view.h"
10 #include "ui/views/controls/label.h"
11 #include "ui/views/layout/fill_layout.h"
12 #include "ui/views/widget/widget.h"
13
14 namespace {
15 const int kTrayIconHeight = 29;
16 const int kTrayItemAnimationDurationMS = 200;
17 }
18
19 namespace ash {
20 namespace internal {
21
22 TrayItemView::TrayItemView()
23 : label_(NULL),
24 image_view_(NULL) {
25 SetPaintToLayer(true);
26 SetFillsBoundsOpaquely(false);
27 SetLayoutManager(new views::FillLayout);
28 }
29
30 TrayItemView::~TrayItemView() {}
31
32 void TrayItemView::CreateLabel() {
33 label_ = new views::Label;
34 AddChildView(label_);
35 }
36
37 void TrayItemView::CreateImageView() {
38 image_view_ = new views::ImageView;
39 AddChildView(image_view_);
40 }
41
42 void TrayItemView::SetVisible(bool set_visible) {
43 if (!GetWidget()) {
44 views::View::SetVisible(set_visible);
45 return;
46 }
47
48 if (!animation_.get()) {
49 animation_.reset(new ui::SlideAnimation(this));
50 animation_->SetSlideDuration(GetAnimationDurationMS());
51 animation_->SetTweenType(ui::Tween::LINEAR);
52 animation_->Reset(visible() ? 1.0 : 0.0);
53 }
54
55 if (!set_visible) {
56 animation_->Hide();
57 AnimationProgressed(animation_.get());
58 } else {
59 animation_->Show();
60 AnimationProgressed(animation_.get());
61 views::View::SetVisible(true);
62 }
63 }
64
65 void TrayItemView::ApplyChange() {
66 // Forcing the widget to the new size is sufficient. The positioning is
67 // taken care of by the layout manager (ShelfLayoutManager).
68 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize());
69 }
70
71 gfx::Size TrayItemView::DesiredSize() {
72 return views::View::GetPreferredSize();
73 }
74
75 int TrayItemView::GetAnimationDurationMS() {
76 return kTrayItemAnimationDurationMS;
77 }
78
79 void TrayItemView::PreferredSizeChanged() {
80 views::View::PreferredSizeChanged();
81 ApplyChange();
82 }
83
84 gfx::Size TrayItemView::GetPreferredSize() {
85 gfx::Size size = DesiredSize();
86 size.set_height(kTrayIconHeight);
87 if (!animation_.get() || !animation_->is_animating())
88 return size;
89 size.set_width(std::max(1,
90 static_cast<int>(size.width() * animation_->GetCurrentValue())));
91 return size;
92 }
93
94 void TrayItemView::AnimationProgressed(const ui::Animation* animation) {
95 ui::Transform transform;
96 transform.SetScale(animation->GetCurrentValue(),
97 animation->GetCurrentValue());
98 transform.ConcatTranslate(0, animation->CurrentValueBetween(
99 static_cast<double>(height()) / 2, 0.));
100 layer()->SetTransform(transform);
101 ApplyChange();
102 }
103
104 void TrayItemView::AnimationEnded(const ui::Animation* animation) {
105 if (animation->GetCurrentValue() < 0.1)
106 views::View::SetVisible(false);
107 }
108
109 void TrayItemView::AnimationCanceled(const ui::Animation* animation) {
110 AnimationEnded(animation);
111 }
112
113 } // namespace internal
114 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_item_view.h ('k') | ash/system/tray_accessibility.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698