| 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..912ef376d424d86cd49e7fcbb477b08414e451d7
|
| --- /dev/null
|
| +++ b/ash/launcher/app_placeholder_view.cc
|
| @@ -0,0 +1,115 @@
|
| +// 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 animation_start_delay = 0;
|
| +
|
| +} // namespace
|
| +
|
| +AppPlaceholderView::AppPlaceholderView() {
|
| +}
|
| +
|
| +AppPlaceholderView::~AppPlaceholderView() {
|
| +}
|
| +
|
| +void AppPlaceholderView::ScheduleAnimation() {
|
| + // The two animation set should have the same size.
|
| + DCHECK_EQ(arraysize(kAnimationOpacity), arraysize(kAnimationScale));
|
| +
|
| + 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);
|
| +}
|
| +
|
| +void AppPlaceholderView::ViewHierarchyChanged(bool is_add,
|
| + View* parent,
|
| + View* child) {
|
| + if (is_add && child == this && !animation_delay_timer_.IsRunning()) {
|
| + animation_delay_timer_.Start(
|
| + FROM_HERE,
|
| + base::TimeDelta::FromMilliseconds(animation_start_delay),
|
| + this, &AppPlaceholderView::ScheduleAnimation);
|
| + animation_start_delay += kAnimationDurationInMs / 2;
|
| + }
|
| +}
|
| +
|
| +} // namespace internal
|
| +} // namespace ash
|
|
|