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 animation_start_delay = 0; |
| 32 |
| 33 } // namespace |
| 34 |
| 35 AppPlaceholderView::AppPlaceholderView() { |
| 36 } |
| 37 |
| 38 AppPlaceholderView::~AppPlaceholderView() { |
| 39 } |
| 40 |
| 41 void AppPlaceholderView::ScheduleAnimation() { |
| 42 // The two animation set should have the same size. |
| 43 DCHECK_EQ(arraysize(kAnimationOpacity), arraysize(kAnimationScale)); |
| 44 |
| 45 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| 46 settings.SetTransitionDuration( |
| 47 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)); |
| 48 layer()->SetOpacity(kAnimationOpacity[0]); |
| 49 layer()->SetTransform( |
| 50 ui::GetScaleTransform(GetLocalBounds().CenterPoint(), |
| 51 kAnimationScale[0])); |
| 52 |
| 53 scoped_ptr<ui::LayerAnimationSequence> opacity_sequence( |
| 54 new ui::LayerAnimationSequence()); |
| 55 scoped_ptr<ui::LayerAnimationSequence> transform_sequence( |
| 56 new ui::LayerAnimationSequence()); |
| 57 |
| 58 // The animations loop infinitely. |
| 59 opacity_sequence->set_is_cyclic(true); |
| 60 transform_sequence->set_is_cyclic(true); |
| 61 |
| 62 for (size_t i = 0; i < arraysize(kAnimationOpacity); ++i) { |
| 63 opacity_sequence->AddElement( |
| 64 ui::LayerAnimationElement::CreateOpacityElement( |
| 65 kAnimationOpacity[i], |
| 66 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); |
| 67 transform_sequence->AddElement( |
| 68 ui::LayerAnimationElement::CreateTransformElement( |
| 69 ui::GetScaleTransform(GetLocalBounds().CenterPoint(), |
| 70 kAnimationScale[i]), |
| 71 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); |
| 72 } |
| 73 |
| 74 ui::LayerAnimationElement::AnimatableProperties opacity_properties; |
| 75 opacity_properties.insert(ui::LayerAnimationElement::OPACITY); |
| 76 opacity_sequence->AddElement( |
| 77 ui::LayerAnimationElement::CreatePauseElement( |
| 78 opacity_properties, |
| 79 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); |
| 80 |
| 81 ui::LayerAnimationElement::AnimatableProperties transform_properties; |
| 82 transform_properties.insert(ui::LayerAnimationElement::TRANSFORM); |
| 83 transform_sequence->AddElement( |
| 84 ui::LayerAnimationElement::CreatePauseElement( |
| 85 transform_properties, |
| 86 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); |
| 87 |
| 88 std::vector<ui::LayerAnimationSequence*> animations; |
| 89 // LayerAnimator::ScheduleTogether takes ownership of the sequences. |
| 90 animations.push_back(opacity_sequence.release()); |
| 91 animations.push_back(transform_sequence.release()); |
| 92 layer()->GetAnimator()->ScheduleTogether(animations); |
| 93 } |
| 94 |
| 95 void AppPlaceholderView::OnPaint(gfx::Canvas* canvas) { |
| 96 gfx::Rect rect(GetContentsBounds()); |
| 97 rect = rect.Center(gfx::Size(kIconSize, kIconSize)); |
| 98 |
| 99 canvas->FillRect(rect, kIconColor); |
| 100 } |
| 101 |
| 102 void AppPlaceholderView::ViewHierarchyChanged(bool is_add, |
| 103 View* parent, |
| 104 View* child) { |
| 105 if (is_add && child == this && !animation_delay_timer_.IsRunning()) { |
| 106 animation_delay_timer_.Start( |
| 107 FROM_HERE, |
| 108 base::TimeDelta::FromMilliseconds(animation_start_delay), |
| 109 this, &AppPlaceholderView::ScheduleAnimation); |
| 110 animation_start_delay += kAnimationDurationInMs / 2; |
| 111 } |
| 112 } |
| 113 |
| 114 } // namespace internal |
| 115 } // namespace ash |
OLD | NEW |