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/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/launcher/launcher_button_host.h" | 10 #include "ash/launcher/launcher_button_host.h" |
11 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
12 #include "grit/ash_resources.h" | 12 #include "grit/ash_resources.h" |
13 #include "skia/ext/image_operations.h" | 13 #include "skia/ext/image_operations.h" |
14 #include "ui/base/accessibility/accessible_view_state.h" | 14 #include "ui/base/accessibility/accessible_view_state.h" |
15 #include "ui/base/animation/animation_delegate.h" | |
16 #include "ui/base/animation/throb_animation.h" | |
17 #include "ui/base/events/event_constants.h" | 15 #include "ui/base/events/event_constants.h" |
18 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
20 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 19 #include "ui/gfx/animation/animation_delegate.h" |
| 20 #include "ui/gfx/animation/throb_animation.h" |
21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
23 #include "ui/gfx/image/image_skia_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
24 #include "ui/gfx/skbitmap_operations.h" | 24 #include "ui/gfx/skbitmap_operations.h" |
25 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Size of the bar. This is along the opposite axis of the shelf. For example, | 29 // Size of the bar. This is along the opposite axis of the shelf. For example, |
30 // if the shelf is aligned horizontally then this is the height of the bar. | 30 // if the shelf is aligned horizontally then this is the height of the bar. |
31 const int kBarSize = 3; | 31 const int kBarSize = 3; |
32 const int kBarSpacing = 5; | 32 const int kBarSpacing = 5; |
33 const int kIconSize = 32; | 33 const int kIconSize = 32; |
34 const int kHopSpacing = 2; | 34 const int kHopSpacing = 2; |
35 const int kIconPad = 8; | 35 const int kIconPad = 8; |
36 const int kAlternateIconPad = 5; | 36 const int kAlternateIconPad = 5; |
37 const int kHopUpMS = 0; | 37 const int kHopUpMS = 0; |
38 const int kHopDownMS = 200; | 38 const int kHopDownMS = 200; |
39 const int kAttentionThrobDurationMS = 800; | 39 const int kAttentionThrobDurationMS = 800; |
40 | 40 |
41 bool ShouldHop(int state) { | 41 bool ShouldHop(int state) { |
42 return state & ash::internal::LauncherButton::STATE_HOVERED || | 42 return state & ash::internal::LauncherButton::STATE_HOVERED || |
43 state & ash::internal::LauncherButton::STATE_ACTIVE || | 43 state & ash::internal::LauncherButton::STATE_ACTIVE || |
44 state & ash::internal::LauncherButton::STATE_FOCUSED; | 44 state & ash::internal::LauncherButton::STATE_FOCUSED; |
45 } | 45 } |
46 | 46 |
47 // Simple AnimationDelegate that owns a single ThrobAnimation instance to | 47 // Simple AnimationDelegate that owns a single ThrobAnimation instance to |
48 // keep all Draw Attention animations in sync. | 48 // keep all Draw Attention animations in sync. |
49 class LauncherButtonAnimation : public ui::AnimationDelegate { | 49 class LauncherButtonAnimation : public gfx::AnimationDelegate { |
50 public: | 50 public: |
51 class Observer { | 51 class Observer { |
52 public: | 52 public: |
53 virtual void AnimationProgressed() = 0; | 53 virtual void AnimationProgressed() = 0; |
54 | 54 |
55 protected: | 55 protected: |
56 virtual ~Observer() {} | 56 virtual ~Observer() {} |
57 }; | 57 }; |
58 | 58 |
59 static LauncherButtonAnimation* GetInstance() { | 59 static LauncherButtonAnimation* GetInstance() { |
(...skipping 16 matching lines...) Expand all Loading... |
76 } | 76 } |
77 | 77 |
78 double GetAnimation() { | 78 double GetAnimation() { |
79 return GetThrobAnimation().GetCurrentValue(); | 79 return GetThrobAnimation().GetCurrentValue(); |
80 } | 80 } |
81 | 81 |
82 private: | 82 private: |
83 LauncherButtonAnimation() | 83 LauncherButtonAnimation() |
84 : animation_(this) { | 84 : animation_(this) { |
85 animation_.SetThrobDuration(kAttentionThrobDurationMS); | 85 animation_.SetThrobDuration(kAttentionThrobDurationMS); |
86 animation_.SetTweenType(ui::Tween::SMOOTH_IN_OUT); | 86 animation_.SetTweenType(gfx::Tween::SMOOTH_IN_OUT); |
87 } | 87 } |
88 | 88 |
89 virtual ~LauncherButtonAnimation() { | 89 virtual ~LauncherButtonAnimation() { |
90 } | 90 } |
91 | 91 |
92 ui::ThrobAnimation& GetThrobAnimation() { | 92 gfx::ThrobAnimation& GetThrobAnimation() { |
93 if (!animation_.is_animating()) { | 93 if (!animation_.is_animating()) { |
94 animation_.Reset(); | 94 animation_.Reset(); |
95 animation_.StartThrobbing(-1 /*throb indefinitely*/); | 95 animation_.StartThrobbing(-1 /*throb indefinitely*/); |
96 } | 96 } |
97 return animation_; | 97 return animation_; |
98 } | 98 } |
99 | 99 |
100 // ui::AnimationDelegate | 100 // gfx::AnimationDelegate |
101 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { | 101 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE { |
102 if (animation != &animation_) | 102 if (animation != &animation_) |
103 return; | 103 return; |
104 if (!animation_.is_animating()) | 104 if (!animation_.is_animating()) |
105 return; | 105 return; |
106 FOR_EACH_OBSERVER(Observer, observers_, AnimationProgressed()); | 106 FOR_EACH_OBSERVER(Observer, observers_, AnimationProgressed()); |
107 } | 107 } |
108 | 108 |
109 ui::ThrobAnimation animation_; | 109 gfx::ThrobAnimation animation_; |
110 ObserverList<Observer> observers_; | 110 ObserverList<Observer> observers_; |
111 | 111 |
112 DISALLOW_COPY_AND_ASSIGN(LauncherButtonAnimation); | 112 DISALLOW_COPY_AND_ASSIGN(LauncherButtonAnimation); |
113 }; | 113 }; |
114 | 114 |
115 } // namespace | 115 } // namespace |
116 | 116 |
117 namespace ash { | 117 namespace ash { |
118 namespace internal { | 118 namespace internal { |
119 | 119 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 bar_->ShowAttention(true); | 312 bar_->ShowAttention(true); |
313 } | 313 } |
314 } | 314 } |
315 | 315 |
316 void LauncherButton::ClearState(State state) { | 316 void LauncherButton::ClearState(State state) { |
317 if (state_ & state) { | 317 if (state_ & state) { |
318 if (!ash::switches::UseAlternateShelfLayout() && | 318 if (!ash::switches::UseAlternateShelfLayout() && |
319 (!ShouldHop(state) || ShouldHop(state_))) { | 319 (!ShouldHop(state) || ShouldHop(state_))) { |
320 ui::ScopedLayerAnimationSettings scoped_setter( | 320 ui::ScopedLayerAnimationSettings scoped_setter( |
321 icon_view_->layer()->GetAnimator()); | 321 icon_view_->layer()->GetAnimator()); |
322 scoped_setter.SetTweenType(ui::Tween::LINEAR); | 322 scoped_setter.SetTweenType(gfx::Tween::LINEAR); |
323 scoped_setter.SetTransitionDuration( | 323 scoped_setter.SetTransitionDuration( |
324 base::TimeDelta::FromMilliseconds(kHopDownMS)); | 324 base::TimeDelta::FromMilliseconds(kHopDownMS)); |
325 } | 325 } |
326 state_ &= ~state; | 326 state_ &= ~state; |
327 Layout(); | 327 Layout(); |
328 if (state & STATE_ATTENTION) | 328 if (state & STATE_ATTENTION) |
329 bar_->ShowAttention(false); | 329 bar_->ShowAttention(false); |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 views::ImageView::CENTER, | 573 views::ImageView::CENTER, |
574 views::ImageView::LEADING)); | 574 views::ImageView::LEADING)); |
575 bar_->SchedulePaint(); | 575 bar_->SchedulePaint(); |
576 } | 576 } |
577 | 577 |
578 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 578 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); |
579 } | 579 } |
580 | 580 |
581 } // namespace internal | 581 } // namespace internal |
582 } // namespace ash | 582 } // namespace ash |
OLD | NEW |