OLD | NEW |
---|---|
(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/launcher/app_placeholder_view.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "ui/compositor/layer.h" | |
11 #include "ui/compositor/layer_animator.h" | |
12 #include "ui/compositor/layer_animation_element.h" | |
13 #include "ui/compositor/layer_animation_sequence.h" | |
14 #include "ui/compositor/scoped_layer_animation_settings.h" | |
15 #include "ui/gfx/canvas.h" | |
16 #include "ui/gfx/transform_util.h" | |
17 | |
18 namespace ash { | |
19 namespace internal { | |
20 | |
21 namespace { | |
22 | |
23 const int kIconSize = 28; | |
24 const SkColor kIconColor = SkColorSetARGB(204, 255, 255, 255); | |
25 | |
26 const int kAnimationDurationInMs = 600; | |
27 const float kAnimationOpacity[] = { 0.4f, 0.8f, 0.4f }; | |
28 const float kAnimationScale[] = { 0.8f, 1.0f, 0.8f }; | |
29 | |
30 // Delay in milliseconds to start pulse animation. | |
31 int g_animation_start_delay = 0; | |
sky
2012/08/14 20:02:34
This isn't really a global, I think it should be a
xiyuan
2012/08/15 18:23:27
Done.
| |
32 | |
33 } // namespace | |
34 | |
35 AppPlaceholderView::AppPlaceholderView() { | |
36 animation_delay_timer_.Start( | |
37 FROM_HERE, | |
38 base::TimeDelta::FromMilliseconds(g_animation_start_delay), | |
39 this, &AppPlaceholderView::ScheduleAnimation); | |
40 g_animation_start_delay += kAnimationDurationInMs / 2; | |
sky
2012/08/14 20:02:34
This seems arbitrary. Shouldn't it be based on whe
xiyuan
2012/08/15 18:23:27
Done.
| |
41 } | |
42 | |
43 AppPlaceholderView::~AppPlaceholderView() { | |
44 } | |
45 | |
46 void AppPlaceholderView::ScheduleAnimation() { | |
47 // The two animation set should have the same size. | |
48 DCHECK(arraysize(kAnimationOpacity) == arraysize(kAnimationScale)); | |
sky
2012/08/14 20:02:34
DCHECK_EQ
xiyuan
2012/08/15 18:23:27
Done.
| |
49 | |
50 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); | |
51 settings.SetTransitionDuration( | |
52 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)); | |
53 layer()->SetOpacity(kAnimationOpacity[0]); | |
54 layer()->SetTransform( | |
55 ui::GetScaleTransform(GetLocalBounds().CenterPoint(), | |
56 kAnimationScale[0])); | |
57 | |
58 scoped_ptr<ui::LayerAnimationSequence> opacity_sequence( | |
59 new ui::LayerAnimationSequence()); | |
60 scoped_ptr<ui::LayerAnimationSequence> transform_sequence( | |
61 new ui::LayerAnimationSequence()); | |
62 | |
63 // The animations loop infinitely. | |
64 opacity_sequence->set_is_cyclic(true); | |
65 transform_sequence->set_is_cyclic(true); | |
66 | |
67 for (size_t i = 0; i < arraysize(kAnimationOpacity); ++i) { | |
68 opacity_sequence->AddElement( | |
69 ui::LayerAnimationElement::CreateOpacityElement( | |
70 kAnimationOpacity[i], | |
71 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); | |
72 transform_sequence->AddElement( | |
73 ui::LayerAnimationElement::CreateTransformElement( | |
74 ui::GetScaleTransform(GetLocalBounds().CenterPoint(), | |
75 kAnimationScale[i]), | |
76 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); | |
77 } | |
78 | |
79 ui::LayerAnimationElement::AnimatableProperties opacity_properties; | |
80 opacity_properties.insert(ui::LayerAnimationElement::OPACITY); | |
81 opacity_sequence->AddElement( | |
82 ui::LayerAnimationElement::CreatePauseElement( | |
83 opacity_properties, | |
84 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); | |
85 | |
86 ui::LayerAnimationElement::AnimatableProperties transform_properties; | |
87 transform_properties.insert(ui::LayerAnimationElement::TRANSFORM); | |
88 transform_sequence->AddElement( | |
89 ui::LayerAnimationElement::CreatePauseElement( | |
90 transform_properties, | |
91 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); | |
92 | |
93 std::vector<ui::LayerAnimationSequence*> animations; | |
94 // LayerAnimator::ScheduleTogether takes ownership of the sequences. | |
95 animations.push_back(opacity_sequence.release()); | |
96 animations.push_back(transform_sequence.release()); | |
97 layer()->GetAnimator()->ScheduleTogether(animations); | |
98 } | |
99 | |
100 void AppPlaceholderView::OnPaint(gfx::Canvas* canvas) { | |
101 gfx::Rect rect(GetContentsBounds()); | |
102 rect = rect.Center(gfx::Size(kIconSize, kIconSize)); | |
103 | |
104 canvas->FillRect(rect, kIconColor); | |
105 } | |
106 | |
107 } // namespace internal | |
108 } // namespace ash | |
OLD | NEW |