summaryrefslogtreecommitdiffstats
path: root/ash/launcher
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 20:52:15 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 20:52:15 +0000
commita160baecdd408a80a6861635a398011622f04718 (patch)
tree8fd64fc6a97cdb3a5900b3303edb70ba267bd28e /ash/launcher
parent1cd7a4bdffafd7c84f0846d9cce59c921ae8ac0e (diff)
downloadchromium_src-a160baecdd408a80a6861635a398011622f04718.zip
chromium_src-a160baecdd408a80a6861635a398011622f04718.tar.gz
chromium_src-a160baecdd408a80a6861635a398011622f04718.tar.bz2
Makes the tray not paint a background if the launcher is painting a
background. I refactored the animation class to allow both launcher and tray to share it. BUG=118357 TEST=visual test, see bug. R=sadrul@chromium.org Review URL: https://chromiumcodereview.appspot.com/9820002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/launcher')
-rw-r--r--ash/launcher/background_animator.cc57
-rw-r--r--ash/launcher/background_animator.h72
-rw-r--r--ash/launcher/launcher.cc32
-rw-r--r--ash/launcher/launcher.h31
4 files changed, 146 insertions, 46 deletions
diff --git a/ash/launcher/background_animator.cc b/ash/launcher/background_animator.cc
new file mode 100644
index 0000000..db1d8aa
--- /dev/null
+++ b/ash/launcher/background_animator.cc
@@ -0,0 +1,57 @@
+// 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/background_animator.h"
+
+
+namespace ash {
+namespace internal {
+
+namespace {
+
+// Duration of the background animation.
+const int kBackgroundDurationMS = 1000;
+
+}
+
+BackgroundAnimator::BackgroundAnimator(BackgroundAnimatorDelegate* delegate,
+ int min_alpha,
+ int max_alpha)
+ : delegate_(delegate),
+ min_alpha_(min_alpha),
+ max_alpha_(max_alpha),
+ ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)),
+ paints_background_(false),
+ alpha_(min_alpha) {
+ animation_.SetSlideDuration(kBackgroundDurationMS);
+}
+
+BackgroundAnimator::~BackgroundAnimator() {
+}
+
+void BackgroundAnimator::SetPaintsBackground(bool value, ChangeType type) {
+ if (paints_background_ == value)
+ return;
+ paints_background_ = value;
+ if (type == CHANGE_IMMEDIATE && !animation_.is_animating()) {
+ animation_.Reset(value ? 1.0f : 0.0f);
+ AnimationProgressed(&animation_);
+ return;
+ }
+ if (paints_background_)
+ animation_.Show();
+ else
+ animation_.Hide();
+}
+
+void BackgroundAnimator::AnimationProgressed(const ui::Animation* animation) {
+ int alpha = animation->CurrentValueBetween(min_alpha_, max_alpha_);
+ if (alpha_ == alpha)
+ return;
+ alpha_ = alpha;
+ delegate_->UpdateBackground(alpha_);
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/launcher/background_animator.h b/ash/launcher/background_animator.h
new file mode 100644
index 0000000..602c2aa
--- /dev/null
+++ b/ash/launcher/background_animator.h
@@ -0,0 +1,72 @@
+// 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.
+
+#ifndef ASH_LAUNCHER_BACKGROUND_ANIMATOR_H_
+#define ASH_LAUNCHER_BACKGROUND_ANIMATOR_H_
+#pragma once
+
+#include "ash/ash_export.h"
+#include "base/basictypes.h"
+#include "ui/base/animation/animation_delegate.h"
+#include "ui/base/animation/slide_animation.h"
+
+namespace ash {
+namespace internal {
+
+// Delegate is notified any time the background changes.
+class ASH_EXPORT BackgroundAnimatorDelegate {
+ public:
+ virtual void UpdateBackground(int alpha) = 0;
+
+ protected:
+ virtual ~BackgroundAnimatorDelegate() {}
+};
+
+// BackgroundAnimator is used by the launcher and system tray to animate the
+// background (alpha).
+class ASH_EXPORT BackgroundAnimator : public ui::AnimationDelegate {
+ public:
+ // How the background can be changed.
+ enum ChangeType {
+ CHANGE_ANIMATE,
+ CHANGE_IMMEDIATE
+ };
+
+ BackgroundAnimator(BackgroundAnimatorDelegate* delegate,
+ int min_alpha,
+ int max_alpha);
+ virtual ~BackgroundAnimator();
+
+ // Sets whether a background is rendered. Initial value is false. If |type|
+ // is |CHANGE_IMMEDIATE| and an animation is not in progress this notifies
+ // the delegate immediately (synchronously from this method).
+ void SetPaintsBackground(bool value, ChangeType type);
+
+ // Current alpha.
+ int alpha() const { return alpha_; }
+
+ // ui::AnimationDelegate overrides:
+ virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
+
+ private:
+ BackgroundAnimatorDelegate* delegate_;
+
+ const int min_alpha_;
+ const int max_alpha_;
+
+ ui::SlideAnimation animation_;
+
+ // Whether the background is painted.
+ bool paints_background_;
+
+ // Current alpha value of the background.
+ int alpha_;
+
+ DISALLOW_COPY_AND_ASSIGN(BackgroundAnimator);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_LAUNCHER_BACKGROUND_ANIMATOR_H_
diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc
index 6264bc3..2094fc5 100644
--- a/ash/launcher/launcher.cc
+++ b/ash/launcher/launcher.cc
@@ -26,9 +26,6 @@ namespace ash {
namespace {
-// Duration of the background animation.
-const int kBackgroundDurationMS = 1000;
-
// Delay before showing the launcher after the mouse enters the view.
const int kShowDelayMS = 300;
@@ -147,9 +144,8 @@ Launcher::Launcher(aura::Window* window_container)
window_container_(window_container),
delegate_view_(NULL),
launcher_view_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(background_animation_(this)),
- renders_background_(false),
- background_alpha_(0) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ background_animator_(this, 0, kBackgroundAlpha)) {
model_.reset(new LauncherModel);
if (Shell::GetInstance()->delegate()) {
delegate_.reset(
@@ -179,7 +175,6 @@ Launcher::Launcher(aura::Window* window_container)
widget_->SetContentsView(delegate_view_);
widget_->Show();
widget_->GetNativeView()->SetName("LauncherView");
- background_animation_.SetSlideDuration(kBackgroundDurationMS);
}
Launcher::~Launcher() {
@@ -190,19 +185,10 @@ void Launcher::SetFocusCycler(internal::FocusCycler* focus_cycler) {
focus_cycler->AddWidget(widget_.get());
}
-void Launcher::SetRendersBackground(bool value, BackgroundChangeSpeed speed) {
- if (renders_background_ == value)
- return;
- renders_background_ = value;
- if (speed == CHANGE_IMMEDIATE && !background_animation_.is_animating()) {
- background_animation_.Reset(value ? 1.0f : 0.0f);
- AnimationProgressed(&background_animation_);
- return;
- }
- if (renders_background_)
- background_animation_.Show();
- else
- background_animation_.Hide();
+void Launcher::SetPaintsBackground(
+ bool value,
+ internal::BackgroundAnimator::ChangeType change_type) {
+ background_animator_.SetPaintsBackground(value, change_type);
}
void Launcher::SetStatusWidth(int width) {
@@ -235,11 +221,7 @@ internal::LauncherView* Launcher::GetLauncherViewForTest() {
widget_->GetContentsView()->child_at(0));
}
-void Launcher::AnimationProgressed(const ui::Animation* animation) {
- int alpha = animation->CurrentValueBetween(0, kBackgroundAlpha);
- if (background_alpha_ == alpha)
- return;
- background_alpha_ = alpha;
+void Launcher::UpdateBackground(int alpha) {
if (alpha == 0) {
delegate_view_->set_background(NULL);
} else {
diff --git a/ash/launcher/launcher.h b/ash/launcher/launcher.h
index 1c5dad6..12a1790 100644
--- a/ash/launcher/launcher.h
+++ b/ash/launcher/launcher.h
@@ -6,11 +6,10 @@
#define ASH_LAUNCHER_LAUNCHER_H_
#pragma once
+#include "ash/launcher/background_animator.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "ash/ash_export.h"
-#include "ui/base/animation/animation_delegate.h"
-#include "ui/base/animation/slide_animation.h"
namespace aura {
class Window;
@@ -34,23 +33,19 @@ class LauncherView;
class LauncherDelegate;
class LauncherModel;
-class ASH_EXPORT Launcher : public ui::AnimationDelegate {
+class ASH_EXPORT Launcher : public internal::BackgroundAnimatorDelegate {
public:
- // How the background can be changed.
- enum BackgroundChangeSpeed {
- CHANGE_ANIMATE,
- CHANGE_IMMEDIATE
- };
-
explicit Launcher(aura::Window* window_container);
virtual ~Launcher();
// Sets the focus cycler. Also adds the launcher to the cycle.
void SetFocusCycler(internal::FocusCycler* focus_cycler);
- // Sets whether the launcher renders a background. Default is false, but is
- // set to true if a window overlaps the shelf.
- void SetRendersBackground(bool value, BackgroundChangeSpeed speed);
+ // Sets whether the launcher paints a background. Default is false, but is set
+ // to true if a window overlaps the shelf.
+ void SetPaintsBackground(
+ bool value,
+ internal::BackgroundAnimator::ChangeType change_type);
// Sets the width of the status area.
void SetStatusWidth(int width);
@@ -69,8 +64,8 @@ class ASH_EXPORT Launcher : public ui::AnimationDelegate {
aura::Window* window_container() { return window_container_; }
- // ui::AnimationDelegate overrides:
- virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
+ // BackgroundAnimatorDelegate overrides:
+ virtual void UpdateBackground(int alpha) OVERRIDE;
private:
class DelegateView;
@@ -91,13 +86,7 @@ class ASH_EXPORT Launcher : public ui::AnimationDelegate {
scoped_ptr<LauncherDelegate> delegate_;
// Used to animate the background.
- ui::SlideAnimation background_animation_;
-
- // Whether we render a background.
- bool renders_background_;
-
- // Current alpha value of the background.
- int background_alpha_;
+ internal::BackgroundAnimator background_animator_;
DISALLOW_COPY_AND_ASSIGN(Launcher);
};