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

Side by Side Diff: ash/launcher/app_list_button.cc

Issue 10829268: chromeos: Sync animation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit_tests crash + rebase Created 8 years, 4 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 | « ash/launcher/app_list_button.h ('k') | ash/launcher/launcher_button.h » ('j') | 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/launcher/app_list_button.h" 5 #include "ash/launcher/app_list_button.h"
6 6
7 #include <vector>
8
7 #include "ash/launcher/launcher_button_host.h" 9 #include "ash/launcher/launcher_button_host.h"
10 #include "ash/launcher/launcher_types.h"
11 #include "grit/ash_strings.h"
12 #include "grit/ui_resources.h"
8 #include "ui/base/accessibility/accessible_view_state.h" 13 #include "ui/base/accessibility/accessible_view_state.h"
9 #include "ui/base/animation/animation_delegate.h" 14 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/base/animation/throb_animation.h"
11 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/compositor/layer.h" 16 #include "ui/compositor/layer.h"
13 #include "ui/compositor/layer_animation_element.h" 17 #include "ui/compositor/layer_animation_element.h"
14 #include "ui/compositor/layer_animation_observer.h"
15 #include "ui/compositor/layer_animation_sequence.h" 18 #include "ui/compositor/layer_animation_sequence.h"
16 #include "ui/compositor/scoped_layer_animation_settings.h" 19 #include "ui/compositor/scoped_layer_animation_settings.h"
17 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/shadow_value.h"
20 #include "ui/gfx/skbitmap_operations.h"
21 #include "ui/gfx/transform_util.h" 20 #include "ui/gfx/transform_util.h"
22 #include "ui/views/controls/image_view.h"
23 21
24 namespace ash { 22 namespace ash {
23 namespace internal {
25 24
26 namespace internal { 25 namespace {
26
27 const int kAnimationDurationInMs = 600;
28 const float kAnimationOpacity[] = { 0.4f, 0.8f, 0.4f };
29 const float kAnimationScale[] = { 0.8f, 1.0f, 0.8f };
30
31 } // namespace
27 32
28 AppListButton::AppListButton(views::ButtonListener* listener, 33 AppListButton::AppListButton(views::ButtonListener* listener,
29 LauncherButtonHost* host) 34 LauncherButtonHost* host)
30 : views::ImageButton(listener), 35 : views::ImageButton(listener),
31 host_(host) {} 36 host_(host) {
37 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
38 SetImage(
39 views::CustomButton::BS_NORMAL,
40 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToImageSkia());
41 SetImage(
42 views::CustomButton::BS_HOT,
43 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT).
44 ToImageSkia());
45 SetImage(
46 views::CustomButton::BS_PUSHED,
47 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED).
48 ToImageSkia());
49 SetAccessibleName(l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE));
50 SetSize(gfx::Size(kLauncherPreferredSize, kLauncherPreferredSize));
51 }
32 52
33 AppListButton::~AppListButton() { 53 AppListButton::~AppListButton() {
34 } 54 }
35 55
56 void AppListButton::StartLoadingAnimation() {
57 // The two animation set should have the same size.
58 DCHECK_EQ(arraysize(kAnimationOpacity), arraysize(kAnimationScale));
59
60 layer()->GetAnimator()->StopAnimating();
61
62 scoped_ptr<ui::LayerAnimationSequence> opacity_sequence(
63 new ui::LayerAnimationSequence());
64 scoped_ptr<ui::LayerAnimationSequence> transform_sequence(
65 new ui::LayerAnimationSequence());
66
67 // The animations loop infinitely.
68 opacity_sequence->set_is_cyclic(true);
69 transform_sequence->set_is_cyclic(true);
70
71 for (size_t i = 0; i < arraysize(kAnimationOpacity); ++i) {
72 opacity_sequence->AddElement(
73 ui::LayerAnimationElement::CreateOpacityElement(
74 kAnimationOpacity[i],
75 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)));
76 transform_sequence->AddElement(
77 ui::LayerAnimationElement::CreateTransformElement(
78 ui::GetScaleTransform(GetLocalBounds().CenterPoint(),
79 kAnimationScale[i]),
80 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)));
81 }
82
83 ui::LayerAnimationElement::AnimatableProperties opacity_properties;
84 opacity_properties.insert(ui::LayerAnimationElement::OPACITY);
85 opacity_sequence->AddElement(
86 ui::LayerAnimationElement::CreatePauseElement(
87 opacity_properties,
88 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)));
89
90 ui::LayerAnimationElement::AnimatableProperties transform_properties;
91 transform_properties.insert(ui::LayerAnimationElement::TRANSFORM);
92 transform_sequence->AddElement(
93 ui::LayerAnimationElement::CreatePauseElement(
94 transform_properties,
95 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)));
96
97 std::vector<ui::LayerAnimationSequence*> animations;
98 // LayerAnimator::ScheduleTogether takes ownership of the sequences.
99 animations.push_back(opacity_sequence.release());
100 animations.push_back(transform_sequence.release());
101 layer()->GetAnimator()->ScheduleTogether(animations);
102 }
103
104 void AppListButton::StopLoadingAnimation() {
105 layer()->GetAnimator()->StopAnimating();
106
107 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
108 settings.SetTransitionDuration(
109 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs));
110 layer()->SetOpacity(1.0f);
111 layer()->SetTransform(ui::Transform());
112 }
113
36 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { 114 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) {
37 ImageButton::OnMousePressed(event); 115 ImageButton::OnMousePressed(event);
38 host_->PointerPressedOnButton(this, LauncherButtonHost::MOUSE, event); 116 host_->PointerPressedOnButton(this, LauncherButtonHost::MOUSE, event);
39 return true; 117 return true;
40 } 118 }
41 119
42 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { 120 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) {
43 ImageButton::OnMouseReleased(event); 121 ImageButton::OnMouseReleased(event);
44 host_->PointerReleasedOnButton(this, LauncherButtonHost::MOUSE, false); 122 host_->PointerReleasedOnButton(this, LauncherButtonHost::MOUSE, false);
45 } 123 }
(...skipping 24 matching lines...) Expand all
70 host_->MouseExitedButton(this); 148 host_->MouseExitedButton(this);
71 } 149 }
72 150
73 void AppListButton::GetAccessibleState(ui::AccessibleViewState* state) { 151 void AppListButton::GetAccessibleState(ui::AccessibleViewState* state) {
74 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; 152 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
75 state->name = host_->GetAccessibleName(this); 153 state->name = host_->GetAccessibleName(this);
76 } 154 }
77 155
78 } // namespace internal 156 } // namespace internal
79 } // namespace ash 157 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/app_list_button.h ('k') | ash/launcher/launcher_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698