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

Side by Side Diff: ash/system/tray/system_tray.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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/tray/system_tray.h" 5 #include "ash/system/tray/system_tray.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell/panel_window.h" 8 #include "ash/shell/panel_window.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/system/tray/tray_constants.h" 10 #include "ash/system/tray/tray_constants.h"
(...skipping 10 matching lines...) Expand all
21 #include "grit/ash_strings.h" 21 #include "grit/ash_strings.h"
22 #include "third_party/skia/include/core/SkCanvas.h" 22 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkColor.h" 23 #include "third_party/skia/include/core/SkColor.h"
24 #include "third_party/skia/include/core/SkPaint.h" 24 #include "third_party/skia/include/core/SkPaint.h"
25 #include "third_party/skia/include/core/SkPath.h" 25 #include "third_party/skia/include/core/SkPath.h"
26 #include "ui/aura/root_window.h" 26 #include "ui/aura/root_window.h"
27 #include "ui/base/events.h" 27 #include "ui/base/events.h"
28 #include "ui/base/accessibility/accessible_view_state.h" 28 #include "ui/base/accessibility/accessible_view_state.h"
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/gfx/canvas.h" 30 #include "ui/gfx/canvas.h"
31 #include "ui/gfx/compositor/layer.h"
31 #include "ui/gfx/skia_util.h" 32 #include "ui/gfx/skia_util.h"
32 #include "ui/views/border.h" 33 #include "ui/views/border.h"
33 #include "ui/views/bubble/bubble_delegate.h" 34 #include "ui/views/bubble/bubble_delegate.h"
34 #include "ui/views/controls/label.h" 35 #include "ui/views/controls/label.h"
35 #include "ui/views/layout/fill_layout.h" 36 #include "ui/views/layout/fill_layout.h"
36 #include "ui/views/layout/box_layout.h" 37 #include "ui/views/layout/box_layout.h"
37 #include "ui/views/view.h" 38 #include "ui/views/view.h"
38 #include "ui/views/widget/widget.h" 39 #include "ui/views/widget/widget.h"
39 40
40 namespace ash { 41 namespace ash {
41 42
42 namespace { 43 namespace {
43 44
44 const int kPaddingFromRightEdgeOfScreen = 15; 45 const int kPaddingFromRightEdgeOfScreen = 15;
45 const int kPaddingFromBottomOfScreen = 10; 46 const int kPaddingFromBottomOfScreen = 10;
46 47
47 const int kAnimationDurationForPopupMS = 200; 48 const int kAnimationDurationForPopupMS = 200;
49 const int kTrayItemAnimationDurationMS = 200;
48 50
49 const int kArrowHeight = 10; 51 const int kArrowHeight = 10;
50 const int kArrowWidth = 20; 52 const int kArrowWidth = 20;
51 const int kArrowPaddingFromRight = 20; 53 const int kArrowPaddingFromRight = 20;
52 54
53 const int kShadowOffset = 3; 55 const int kShadowOffset = 3;
54 const int kShadowHeight = 3; 56 const int kShadowHeight = 3;
55 57
56 const int kLeftPadding = 4; 58 const int kLeftPadding = 4;
57 const int kBottomLineHeight = 1; 59 const int kBottomLineHeight = 1;
58 60
59 const int kTrayIconHeight = 29; 61 const int kTrayIconHeight = 29;
60 62
61 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); 63 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0);
62 64
63 const SkColor kTrayBackgroundAlpha = 100; 65 const SkColor kTrayBackgroundAlpha = 100;
64 const SkColor kTrayBackgroundHoverAlpha = 150; 66 const SkColor kTrayBackgroundHoverAlpha = 150;
65 67
66 // Container for items in the tray. It makes sure the widget is updated 68 // Container for items in the tray. It makes sure the widget is updated
67 // correctly when the visibility/size of the tray item changes. 69 // correctly when the visibility/size of the tray item changes.
68 // TODO: setup animation. 70 class TrayItemContainer : public views::View,
69 class TrayItemContainer : public views::View { 71 public ui::AnimationDelegate {
70 public: 72 public:
71 explicit TrayItemContainer(views::View* view) : child_(view) { 73 explicit TrayItemContainer(views::View* view)
74 : child_(view),
75 processing_(false) {
72 AddChildView(child_); 76 AddChildView(child_);
73 SetVisible(child_->visible()); 77 SetVisible(child_->visible());
78
79 child_->SetPaintToLayer(true);
80 child_->SetFillsBoundsOpaquely(false);
74 } 81 }
75 82
76 virtual ~TrayItemContainer() {} 83 virtual ~TrayItemContainer() {}
77 84
78 private: 85 private:
79 // Makes sure the widget relayouts after the size/visibility of the view 86 // Makes sure the widget relayouts after the size/visibility of the view
80 // changes. 87 // changes.
81 void ApplyChange() { 88 void ApplyChange() {
82 // Forcing the widget to the new size is sufficient. The positing is taken 89 // Forcing the widget to the new size is sufficient. The positioning is
83 // care of by the layout manager (ShelfLayoutManager). 90 // taken care of by the layout manager (ShelfLayoutManager).
84 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize()); 91 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize());
85 } 92 }
86 93
87 // Overridden from views::View. 94 // Overridden from views::View.
88 virtual void Layout() { 95 virtual void Layout() {
89 child_->SetBoundsRect(gfx::Rect(size())); 96 child_->SetBoundsRect(gfx::Rect(size()));
90 } 97 }
91 98
92 virtual gfx::Size GetPreferredSize() OVERRIDE { 99 virtual gfx::Size GetPreferredSize() OVERRIDE {
100 if (!animation_.get() || !animation_->is_animating())
101 return child_->GetPreferredSize();
93 gfx::Size size = child_->GetPreferredSize(); 102 gfx::Size size = child_->GetPreferredSize();
103 size.set_width(std::max(1,
104 static_cast<int>(size.width() * animation_->GetCurrentValue())));
94 size.set_height(kTrayIconHeight); 105 size.set_height(kTrayIconHeight);
95 return size; 106 return size;
96 } 107 }
97 108
98 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { 109 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE {
99 ApplyChange(); 110 ApplyChange();
100 } 111 }
101 112
102 virtual void ChildVisibilityChanged(views::View* child) OVERRIDE { 113 virtual void ChildVisibilityChanged(views::View* child) OVERRIDE {
103 if (visible() == child_->visible()) 114 if (processing_)
104 return; 115 return;
105 SetVisible(child_->visible()); 116 processing_ = true;
117 if (!animation_.get()) {
118 animation_.reset(new ui::SlideAnimation(this));
119 animation_->SetSlideDuration(kTrayItemAnimationDurationMS);
120 animation_->SetTweenType(ui::Tween::LINEAR);
121 }
122
123 if (!child_->visible()) {
124 // child_ is hiding. To animate nicely, it is necessary to redisplay the
125 // child view during animation.
126 child_->SetVisible(true);
sadrul 2012/04/02 20:41:12 This is a bit hacky. This can cause a bug if the i
127 animation_->Hide();
128 AnimationProgressed(animation_.get());
129 } else {
130 SetVisible(true);
131 animation_->Show();
132 AnimationProgressed(animation_.get());
133 }
134 processing_ = false;
135 }
136
137 // Overridden from ui::AnimationDelegate.
138 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE {
139 ui::Transform transform;
140 transform.SetScale(animation->GetCurrentValue(),
141 animation->GetCurrentValue());
142 transform.ConcatTranslate(0, animation->CurrentValueBetween(
143 static_cast<double>(height()) / 2, 0.));
144 child_->layer()->SetTransform(transform);
106 ApplyChange(); 145 ApplyChange();
107 } 146 }
108 147
148 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE {
149 processing_ = true;
150 if (animation->GetCurrentValue() < 0.1) {
151 child_->SetVisible(false);
152 SetVisible(false);
153 } else {
154 child_->SetVisible(true);
155 SetVisible(true);
156 }
157 processing_ = false;
158 }
159
160 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE {
161 AnimationEnded(animation);
162 }
163
109 views::View* child_; 164 views::View* child_;
165 bool processing_;
166 scoped_ptr<ui::SlideAnimation> animation_;
110 167
111 DISALLOW_COPY_AND_ASSIGN(TrayItemContainer); 168 DISALLOW_COPY_AND_ASSIGN(TrayItemContainer);
112 }; 169 };
113 170
114 // A view with some special behaviour for tray items in the popup: 171 // A view with some special behaviour for tray items in the popup:
115 // - changes background color on hover. 172 // - changes background color on hover.
116 // - TODO: accessibility 173 // - TODO: accessibility
117 class TrayPopupItemContainer : public views::View { 174 class TrayPopupItemContainer : public views::View {
118 public: 175 public:
119 explicit TrayPopupItemContainer(views::View* view) : hover_(false) { 176 explicit TrayPopupItemContainer(views::View* view) : hover_(false) {
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 popup_->Hide(); 717 popup_->Hide();
661 } 718 }
662 } 719 }
663 return base::EVENT_CONTINUE; 720 return base::EVENT_CONTINUE;
664 } 721 }
665 722
666 void SystemTray::DidProcessEvent(const base::NativeEvent& event) { 723 void SystemTray::DidProcessEvent(const base::NativeEvent& event) {
667 } 724 }
668 725
669 } // namespace ash 726 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698