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 10827420: Revert 152221 - chromeos: Sync animation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
9 #include "ash/launcher/launcher_button_host.h" 7 #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"
13 #include "ui/base/accessibility/accessible_view_state.h" 8 #include "ui/base/accessibility/accessible_view_state.h"
14 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/animation/animation_delegate.h"
10 #include "ui/base/animation/throb_animation.h"
15 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/compositor/layer.h" 12 #include "ui/compositor/layer.h"
17 #include "ui/compositor/layer_animation_element.h" 13 #include "ui/compositor/layer_animation_element.h"
14 #include "ui/compositor/layer_animation_observer.h"
18 #include "ui/compositor/layer_animation_sequence.h" 15 #include "ui/compositor/layer_animation_sequence.h"
19 #include "ui/compositor/scoped_layer_animation_settings.h" 16 #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"
20 #include "ui/gfx/transform_util.h" 21 #include "ui/gfx/transform_util.h"
22 #include "ui/views/controls/image_view.h"
21 23
22 namespace ash { 24 namespace ash {
25
23 namespace internal { 26 namespace internal {
24 27
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
32
33 AppListButton::AppListButton(views::ButtonListener* listener, 28 AppListButton::AppListButton(views::ButtonListener* listener,
34 LauncherButtonHost* host) 29 LauncherButtonHost* host)
35 : views::ImageButton(listener), 30 : views::ImageButton(listener),
36 host_(host) { 31 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 }
52 32
53 AppListButton::~AppListButton() { 33 AppListButton::~AppListButton() {
54 } 34 }
55 35
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
114 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { 36 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) {
115 ImageButton::OnMousePressed(event); 37 ImageButton::OnMousePressed(event);
116 host_->PointerPressedOnButton(this, LauncherButtonHost::MOUSE, event); 38 host_->PointerPressedOnButton(this, LauncherButtonHost::MOUSE, event);
117 return true; 39 return true;
118 } 40 }
119 41
120 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { 42 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) {
121 ImageButton::OnMouseReleased(event); 43 ImageButton::OnMouseReleased(event);
122 host_->PointerReleasedOnButton(this, LauncherButtonHost::MOUSE, false); 44 host_->PointerReleasedOnButton(this, LauncherButtonHost::MOUSE, false);
123 } 45 }
(...skipping 24 matching lines...) Expand all
148 host_->MouseExitedButton(this); 70 host_->MouseExitedButton(this);
149 } 71 }
150 72
151 void AppListButton::GetAccessibleState(ui::AccessibleViewState* state) { 73 void AppListButton::GetAccessibleState(ui::AccessibleViewState* state) {
152 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; 74 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
153 state->name = host_->GetAccessibleName(this); 75 state->name = host_->GetAccessibleName(this);
154 } 76 }
155 77
156 } // namespace internal 78 } // namespace internal
157 } // namespace ash 79 } // 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