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

Unified Diff: ash/launcher/app_placeholder_view.cc

Issue 10829268: chromeos: Sync animation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wrap up + 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 side-by-side diff with in-line comments
Download patch
Index: ash/launcher/app_placeholder_view.cc
diff --git a/ash/launcher/app_placeholder_view.cc b/ash/launcher/app_placeholder_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c3367ec6fe48e5d8beeb2309e58da7c5c1d5aec0
--- /dev/null
+++ b/ash/launcher/app_placeholder_view.cc
@@ -0,0 +1,108 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/launcher/app_placeholder_view.h"
+
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "ui/compositor/layer.h"
+#include "ui/compositor/layer_animator.h"
+#include "ui/compositor/layer_animation_element.h"
+#include "ui/compositor/layer_animation_sequence.h"
+#include "ui/compositor/scoped_layer_animation_settings.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/transform_util.h"
+
+namespace ash {
+namespace internal {
+
+namespace {
+
+const int kIconSize = 28;
+const SkColor kIconColor = SkColorSetARGB(204, 255, 255, 255);
+
+const int kAnimationDurationInMs = 600;
+const float kAnimationOpacity[] = { 0.4f, 0.8f, 0.4f };
+const float kAnimationScale[] = { 0.8f, 1.0f, 0.8f };
+
+// Delay in milliseconds to start pulse animation.
+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.
+
+} // namespace
+
+AppPlaceholderView::AppPlaceholderView() {
+ animation_delay_timer_.Start(
+ FROM_HERE,
+ base::TimeDelta::FromMilliseconds(g_animation_start_delay),
+ this, &AppPlaceholderView::ScheduleAnimation);
+ 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.
+}
+
+AppPlaceholderView::~AppPlaceholderView() {
+}
+
+void AppPlaceholderView::ScheduleAnimation() {
+ // The two animation set should have the same size.
+ DCHECK(arraysize(kAnimationOpacity) == arraysize(kAnimationScale));
sky 2012/08/14 20:02:34 DCHECK_EQ
xiyuan 2012/08/15 18:23:27 Done.
+
+ ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
+ settings.SetTransitionDuration(
+ base::TimeDelta::FromMilliseconds(kAnimationDurationInMs));
+ layer()->SetOpacity(kAnimationOpacity[0]);
+ layer()->SetTransform(
+ ui::GetScaleTransform(GetLocalBounds().CenterPoint(),
+ kAnimationScale[0]));
+
+ scoped_ptr<ui::LayerAnimationSequence> opacity_sequence(
+ new ui::LayerAnimationSequence());
+ scoped_ptr<ui::LayerAnimationSequence> transform_sequence(
+ new ui::LayerAnimationSequence());
+
+ // The animations loop infinitely.
+ opacity_sequence->set_is_cyclic(true);
+ transform_sequence->set_is_cyclic(true);
+
+ for (size_t i = 0; i < arraysize(kAnimationOpacity); ++i) {
+ opacity_sequence->AddElement(
+ ui::LayerAnimationElement::CreateOpacityElement(
+ kAnimationOpacity[i],
+ base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)));
+ transform_sequence->AddElement(
+ ui::LayerAnimationElement::CreateTransformElement(
+ ui::GetScaleTransform(GetLocalBounds().CenterPoint(),
+ kAnimationScale[i]),
+ base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)));
+ }
+
+ ui::LayerAnimationElement::AnimatableProperties opacity_properties;
+ opacity_properties.insert(ui::LayerAnimationElement::OPACITY);
+ opacity_sequence->AddElement(
+ ui::LayerAnimationElement::CreatePauseElement(
+ opacity_properties,
+ base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)));
+
+ ui::LayerAnimationElement::AnimatableProperties transform_properties;
+ transform_properties.insert(ui::LayerAnimationElement::TRANSFORM);
+ transform_sequence->AddElement(
+ ui::LayerAnimationElement::CreatePauseElement(
+ transform_properties,
+ base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)));
+
+ std::vector<ui::LayerAnimationSequence*> animations;
+ // LayerAnimator::ScheduleTogether takes ownership of the sequences.
+ animations.push_back(opacity_sequence.release());
+ animations.push_back(transform_sequence.release());
+ layer()->GetAnimator()->ScheduleTogether(animations);
+}
+
+void AppPlaceholderView::OnPaint(gfx::Canvas* canvas) {
+ gfx::Rect rect(GetContentsBounds());
+ rect = rect.Center(gfx::Size(kIconSize, kIconSize));
+
+ canvas->FillRect(rect, kIconColor);
+}
+
+} // namespace internal
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698