OLD | NEW |
---|---|
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/launcher/launcher_button.h" | 5 #include "ash/launcher/launcher_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/launcher/launcher_button_host.h" | 9 #include "ash/launcher/launcher_button_host.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
11 #include "ui/base/accessibility/accessible_view_state.h" | 11 #include "ui/base/accessibility/accessible_view_state.h" |
12 #include "ui/base/animation/animation_delegate.h" | |
13 #include "ui/base/animation/throb_animation.h" | |
12 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/compositor/layer.h" | 15 #include "ui/compositor/layer.h" |
14 #include "ui/compositor/scoped_layer_animation_settings.h" | 16 #include "ui/compositor/scoped_layer_animation_settings.h" |
15 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
17 #include "ui/gfx/skbitmap_operations.h" | 19 #include "ui/gfx/skbitmap_operations.h" |
18 #include "ui/views/controls/image_view.h" | 20 #include "ui/views/controls/image_view.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 const int kBarHeight = 3; | 23 const int kBarHeight = 3; |
22 const int kBarSpacing = 5; | 24 const int kBarSpacing = 5; |
23 const int kIconHeight = 32; | 25 const int kIconHeight = 32; |
24 const int kIconWidth = 48; | 26 const int kIconWidth = 48; |
25 const int kHopSpacing = 2; | 27 const int kHopSpacing = 2; |
26 const int kActiveBarColor = 0xe6ffffff; | 28 const int kActiveBarColor = 0xe6ffffff; |
27 const int kInactiveBarColor = 0x80ffffff; | 29 const int kInactiveBarColor = 0x80ffffff; |
28 const int kHopUpMS = 200; | 30 const int kHopUpMS = 200; |
29 const int kHopDownMS = 200; | 31 const int kHopDownMS = 200; |
30 | 32 const int kAttentionThrobDurationMS = 2000; |
31 // Used to allow Mouse...() messages to go to the parent view. | |
32 class MouseIgnoredImageView : public views::ImageView { | |
33 public: | |
34 bool HitTest(const gfx::Point& l) const OVERRIDE { | |
35 return false; | |
36 } | |
37 }; | |
38 | 33 |
39 bool ShouldHop(int state) { | 34 bool ShouldHop(int state) { |
40 return state & ash::internal::LauncherButton::STATE_HOVERED || | 35 return state & ash::internal::LauncherButton::STATE_HOVERED || |
41 state & ash::internal::LauncherButton::STATE_ACTIVE; | 36 state & ash::internal::LauncherButton::STATE_ACTIVE; |
42 } | 37 } |
43 | 38 |
44 } // namespace | 39 } // namespace |
45 | 40 |
46 namespace ash { | 41 namespace ash { |
47 | 42 |
48 namespace internal { | 43 namespace internal { |
49 | 44 |
45 class LauncherButton::BarView : public views::ImageView, | |
46 public ui::AnimationDelegate { | |
47 public: | |
48 BarView() : animation_(new ui::ThrobAnimation(this)) { | |
sky
2012/05/18 16:38:30
ALLOW_THIS_IN_INITIALIAZER_LIST
| |
49 animation_->SetThrobDuration(kAttentionThrobDurationMS); | |
50 animation_->SetTweenType(ui::Tween::SMOOTH_IN_OUT); | |
51 } | |
52 | |
53 // View overrides. | |
54 bool HitTest(const gfx::Point& l) const OVERRIDE { | |
55 // Allow Mouse...() messages to go to the parent view. | |
56 return false; | |
57 } | |
58 | |
59 void OnPaint(gfx::Canvas* canvas) { | |
sky
2012/05/18 16:38:30
virtual OVERRIDE
| |
60 if (animation_->is_animating()) { | |
61 int alpha = animation_->CurrentValueBetween(0, 255); | |
62 canvas->SaveLayerAlpha(alpha); | |
63 views::ImageView::OnPaint(canvas); | |
64 canvas->Restore(); | |
65 } else { | |
66 views::ImageView::OnPaint(canvas); | |
67 } | |
68 } | |
69 | |
70 // ui::AnimationDelegate overrides. | |
71 void AnimationProgressed(const ui::Animation* animation) { | |
sky
2012/05/18 16:38:30
virtual OVERRIDE
| |
72 SchedulePaint(); | |
73 } | |
74 | |
75 void ShowAttention(bool show) { | |
76 if (show) | |
77 animation_->StartThrobbing(-1); | |
78 else | |
79 animation_->Reset(); | |
80 } | |
81 | |
82 private: | |
83 scoped_ptr<ui::ThrobAnimation> animation_; | |
sky
2012/05/18 16:38:30
Since you create this in the constructor, no need
| |
84 }; | |
sky
2012/05/18 16:38:30
DISALLOW_...
| |
85 | |
50 LauncherButton::IconView::IconView() : icon_size_(kIconHeight) { | 86 LauncherButton::IconView::IconView() : icon_size_(kIconHeight) { |
51 } | 87 } |
52 | 88 |
53 LauncherButton::IconView::~IconView() { | 89 LauncherButton::IconView::~IconView() { |
54 } | 90 } |
55 | 91 |
56 bool LauncherButton::IconView::HitTest(const gfx::Point& l) const { | 92 bool LauncherButton::IconView::HitTest(const gfx::Point& l) const { |
57 return false; | 93 return false; |
58 } | 94 } |
59 | 95 |
60 LauncherButton* LauncherButton::Create(views::ButtonListener* listener, | 96 LauncherButton* LauncherButton::Create(views::ButtonListener* listener, |
61 LauncherButtonHost* host) { | 97 LauncherButtonHost* host) { |
62 LauncherButton* button = new LauncherButton(listener, host); | 98 LauncherButton* button = new LauncherButton(listener, host); |
63 button->Init(); | 99 button->Init(); |
64 return button; | 100 return button; |
65 } | 101 } |
66 | 102 |
67 LauncherButton::LauncherButton(views::ButtonListener* listener, | 103 LauncherButton::LauncherButton(views::ButtonListener* listener, |
68 LauncherButtonHost* host) | 104 LauncherButtonHost* host) |
69 : CustomButton(listener), | 105 : CustomButton(listener), |
70 host_(host), | 106 host_(host), |
71 icon_view_(NULL), | 107 icon_view_(NULL), |
72 bar_(new MouseIgnoredImageView), | 108 bar_(new BarView), |
73 state_(STATE_NORMAL) { | 109 state_(STATE_NORMAL) { |
74 set_accessibility_focusable(true); | 110 set_accessibility_focusable(true); |
75 bar_->SetHorizontalAlignment(views::ImageView::CENTER); | 111 bar_->SetHorizontalAlignment(views::ImageView::CENTER); |
76 bar_->SetVerticalAlignment(views::ImageView::TRAILING); | 112 bar_->SetVerticalAlignment(views::ImageView::TRAILING); |
77 AddChildView(bar_); | 113 AddChildView(bar_); |
78 } | 114 } |
79 | 115 |
80 LauncherButton::~LauncherButton() { | 116 LauncherButton::~LauncherButton() { |
81 } | 117 } |
82 | 118 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 ui::ScopedLayerAnimationSettings scoped_setter( | 181 ui::ScopedLayerAnimationSettings scoped_setter( |
146 icon_view_->layer()->GetAnimator()); | 182 icon_view_->layer()->GetAnimator()); |
147 scoped_setter.SetTransitionDuration( | 183 scoped_setter.SetTransitionDuration( |
148 base::TimeDelta::FromMilliseconds(kHopUpMS)); | 184 base::TimeDelta::FromMilliseconds(kHopUpMS)); |
149 state_ |= state; | 185 state_ |= state; |
150 UpdateState(); | 186 UpdateState(); |
151 } else { | 187 } else { |
152 state_ |= state; | 188 state_ |= state; |
153 UpdateState(); | 189 UpdateState(); |
154 } | 190 } |
191 if (state & STATE_ATTENTION) | |
192 bar_->ShowAttention(true); | |
155 } | 193 } |
156 } | 194 } |
157 | 195 |
158 void LauncherButton::ClearState(State state) { | 196 void LauncherButton::ClearState(State state) { |
159 if (state_ & state) { | 197 if (state_ & state) { |
160 if (!ShouldHop(state) || ShouldHop(state_)) { | 198 if (!ShouldHop(state) || ShouldHop(state_)) { |
161 ui::ScopedLayerAnimationSettings scoped_setter( | 199 ui::ScopedLayerAnimationSettings scoped_setter( |
162 icon_view_->layer()->GetAnimator()); | 200 icon_view_->layer()->GetAnimator()); |
163 scoped_setter.SetTweenType(ui::Tween::LINEAR); | 201 scoped_setter.SetTweenType(ui::Tween::LINEAR); |
164 scoped_setter.SetTransitionDuration( | 202 scoped_setter.SetTransitionDuration( |
165 base::TimeDelta::FromMilliseconds(kHopDownMS)); | 203 base::TimeDelta::FromMilliseconds(kHopDownMS)); |
166 state_ &= ~state; | 204 state_ &= ~state; |
167 UpdateState(); | 205 UpdateState(); |
168 } else { | 206 } else { |
169 state_ &= ~state; | 207 state_ &= ~state; |
170 UpdateState(); | 208 UpdateState(); |
171 } | 209 } |
210 if (state & STATE_ATTENTION) | |
211 bar_->ShowAttention(false); | |
172 } | 212 } |
173 } | 213 } |
174 | 214 |
175 gfx::Rect LauncherButton::GetIconBounds() const { | 215 gfx::Rect LauncherButton::GetIconBounds() const { |
176 return icon_view_->bounds(); | 216 return icon_view_->bounds(); |
177 } | 217 } |
178 | 218 |
179 bool LauncherButton::OnMousePressed(const views::MouseEvent& event) { | 219 bool LauncherButton::OnMousePressed(const views::MouseEvent& event) { |
180 CustomButton::OnMousePressed(event); | 220 CustomButton::OnMousePressed(event); |
181 host_->MousePressedOnButton(this, event); | 221 host_->MousePressedOnButton(this, event); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 } | 290 } |
251 | 291 |
252 void LauncherButton::UpdateState() { | 292 void LauncherButton::UpdateState() { |
253 if (state_ == STATE_NORMAL) { | 293 if (state_ == STATE_NORMAL) { |
254 bar_->SetVisible(false); | 294 bar_->SetVisible(false); |
255 } else { | 295 } else { |
256 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 296 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
257 int bar_id; | 297 int bar_id; |
258 bar_->SetVisible(true); | 298 bar_->SetVisible(true); |
259 | 299 |
260 if (state_ & STATE_HOVERED) | 300 if (state_ & STATE_ACTIVE || state_ & STATE_ATTENTION) |
301 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE; | |
302 else if (state_ & STATE_HOVERED) | |
261 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_HOVER; | 303 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_HOVER; |
262 else if (state_ & STATE_ACTIVE) | |
263 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE; | |
264 else | 304 else |
265 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_RUNNING; | 305 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_RUNNING; |
266 | 306 |
267 bar_->SetImage(rb.GetImageNamed(bar_id).ToSkBitmap()); | 307 bar_->SetImage(rb.GetImageNamed(bar_id).ToSkBitmap()); |
268 } | 308 } |
269 | 309 |
270 Layout(); | 310 Layout(); |
271 SchedulePaint(); | 311 SchedulePaint(); |
272 } | 312 } |
273 } // namespace internal | 313 } // namespace internal |
274 } // namespace ash | 314 } // namespace ash |
OLD | NEW |