summaryrefslogtreecommitdiffstats
path: root/ui/aura_shell
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 18:52:17 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 18:52:17 +0000
commit080287469804ce94aaf94c87e957fd27315dcf49 (patch)
treeb428654e910fd93bc720246da6eb747fd4a59dd4 /ui/aura_shell
parenteb13aa23e3d5e820fd4f3ff39633b99b30d4b352 (diff)
downloadchromium_src-080287469804ce94aaf94c87e957fd27315dcf49.zip
chromium_src-080287469804ce94aaf94c87e957fd27315dcf49.tar.gz
chromium_src-080287469804ce94aaf94c87e957fd27315dcf49.tar.bz2
Tweaks to the launcher favicon painting code. Current code resulted in
a lot of flickering as we waited for the favicon for sites. We would transition to globe, then to real favicon. New code delays for 500ms, then fades out current icon. BUG=none TEST=none R=ben@chromium.org Review URL: http://codereview.chromium.org/8967003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114834 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura_shell')
-rw-r--r--ui/aura_shell/launcher/launcher_model.cc5
-rw-r--r--ui/aura_shell/launcher/launcher_model.h4
-rw-r--r--ui/aura_shell/launcher/launcher_model_observer.h4
-rw-r--r--ui/aura_shell/launcher/launcher_model_unittest.cc2
-rw-r--r--ui/aura_shell/launcher/launcher_view.cc7
-rw-r--r--ui/aura_shell/launcher/launcher_view.h1
-rw-r--r--ui/aura_shell/launcher/tabbed_launcher_button.cc54
-rw-r--r--ui/aura_shell/launcher/tabbed_launcher_button.h38
-rw-r--r--ui/aura_shell/workspace_controller.h1
9 files changed, 114 insertions, 2 deletions
diff --git a/ui/aura_shell/launcher/launcher_model.cc b/ui/aura_shell/launcher/launcher_model.cc
index d65023b..1380a12 100644
--- a/ui/aura_shell/launcher/launcher_model.cc
+++ b/ui/aura_shell/launcher/launcher_model.cc
@@ -56,6 +56,11 @@ void LauncherModel::SetAppImage(int index, const SkBitmap& image) {
LauncherItemImagesChanged(index));
}
+void LauncherModel::SetPendingUpdate(int index) {
+ FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
+ LauncherItemImagesWillChange(index));
+}
+
int LauncherModel::ItemIndexByWindow(aura::Window* window) {
LauncherItems::const_iterator i = ItemByWindow(window);
return i == items_.end() ? -1 : static_cast<int>((i - items_.begin()));
diff --git a/ui/aura_shell/launcher/launcher_model.h b/ui/aura_shell/launcher/launcher_model.h
index 1e8c19a..2771950 100644
--- a/ui/aura_shell/launcher/launcher_model.h
+++ b/ui/aura_shell/launcher/launcher_model.h
@@ -40,6 +40,10 @@ class AURA_SHELL_EXPORT LauncherModel {
void SetTabbedImages(int index, const LauncherTabbedImages& images);
void SetAppImage(int index, const SkBitmap& image);
+ // Sends LauncherItemImagesWillChange() to the observers. Used when the images
+ // are going to change for an item, but not for a while.
+ void SetPendingUpdate(int index);
+
// Returns the index of the item with the specified window.
int ItemIndexByWindow(aura::Window* window);
diff --git a/ui/aura_shell/launcher/launcher_model_observer.h b/ui/aura_shell/launcher/launcher_model_observer.h
index 0388aa0..a477872 100644
--- a/ui/aura_shell/launcher/launcher_model_observer.h
+++ b/ui/aura_shell/launcher/launcher_model_observer.h
@@ -26,6 +26,10 @@ class AURA_SHELL_EXPORT LauncherModelObserver {
// Invoked when the images of an item change.
virtual void LauncherItemImagesChanged(int index) = 0;
+ // Signals that LauncherItemImagesChanged() is going to be sent in the
+ // near future.
+ virtual void LauncherItemImagesWillChange(int index) = 0;
+
protected:
virtual ~LauncherModelObserver() {}
};
diff --git a/ui/aura_shell/launcher/launcher_model_unittest.cc b/ui/aura_shell/launcher/launcher_model_unittest.cc
index d8ab3ba..1cc95f3 100644
--- a/ui/aura_shell/launcher/launcher_model_unittest.cc
+++ b/ui/aura_shell/launcher/launcher_model_unittest.cc
@@ -47,6 +47,8 @@ class TestLauncherModelObserver : public LauncherModelObserver {
virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE {
moved_count_++;
}
+ virtual void LauncherItemImagesWillChange(int index) OVERRIDE {
+ }
private:
void AddToResult(const std::string& format, int count, std::string* result) {
diff --git a/ui/aura_shell/launcher/launcher_view.cc b/ui/aura_shell/launcher/launcher_view.cc
index 68a8ed8..eb71ef2 100644
--- a/ui/aura_shell/launcher/launcher_view.cc
+++ b/ui/aura_shell/launcher/launcher_view.cc
@@ -539,6 +539,13 @@ void LauncherView::LauncherItemMoved(int start_index, int target_index) {
AnimateToIdealBounds();
}
+void LauncherView::LauncherItemImagesWillChange(int index) {
+ const LauncherItem& item(model_->items()[index]);
+ views::View* view = view_model_->view_at(index);
+ if (item.type == TYPE_TABBED)
+ static_cast<TabbedLauncherButton*>(view)->PrepareForImageChange();
+}
+
void LauncherView::MousePressedOnButton(views::View* view,
const views::MouseEvent& event) {
if (view_model_->GetIndexOfView(view) == -1 || view_model_->view_size() <= 1)
diff --git a/ui/aura_shell/launcher/launcher_view.h b/ui/aura_shell/launcher/launcher_view.h
index 8461921..cfff1b2 100644
--- a/ui/aura_shell/launcher/launcher_view.h
+++ b/ui/aura_shell/launcher/launcher_view.h
@@ -96,6 +96,7 @@ class LauncherView : public views::WidgetDelegateView,
virtual void LauncherItemRemoved(int model_index) OVERRIDE;
virtual void LauncherItemImagesChanged(int model_index) OVERRIDE;
virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE;
+ virtual void LauncherItemImagesWillChange(int index) OVERRIDE;
// Overridden from LauncherButtonHost:
virtual void MousePressedOnButton(views::View* view,
diff --git a/ui/aura_shell/launcher/tabbed_launcher_button.cc b/ui/aura_shell/launcher/tabbed_launcher_button.cc
index aac9205..404030f 100644
--- a/ui/aura_shell/launcher/tabbed_launcher_button.cc
+++ b/ui/aura_shell/launcher/tabbed_launcher_button.cc
@@ -8,6 +8,7 @@
#include "grit/ui_resources.h"
#include "ui/aura_shell/launcher/launcher_button_host.h"
+#include "ui/base/animation/multi_animation.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image.h"
@@ -31,6 +32,28 @@ const int kBgLeftInset = 30;
const int kBgBottomInset = 12;
const int kBgRightInset = 8;
+TabbedLauncherButton::AnimationDelegateImpl::AnimationDelegateImpl(
+ TabbedLauncherButton* host)
+ : host_(host) {
+}
+
+TabbedLauncherButton::AnimationDelegateImpl::~AnimationDelegateImpl() {
+}
+
+void TabbedLauncherButton::AnimationDelegateImpl::AnimationEnded(
+ const ui::Animation* animation) {
+ AnimationProgressed(animation);
+ // Hide the image when the animation is done. We'll show it again the next
+ // time SetImages is invoked.
+ host_->show_image_ = false;
+}
+
+void TabbedLauncherButton::AnimationDelegateImpl::AnimationProgressed(
+ const ui::Animation* animation) {
+ if (host_->animation_->current_part_index() == 1)
+ host_->SchedulePaint();
+}
+
// static
TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_1_ = NULL;
TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_2_ = NULL;
@@ -39,7 +62,9 @@ TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_3_ = NULL;
TabbedLauncherButton::TabbedLauncherButton(views::ButtonListener* listener,
LauncherButtonHost* host)
: views::ImageButton(listener),
- host_(host) {
+ host_(host),
+ ALLOW_THIS_IN_INITIALIZER_LIST(animation_delegate_(this)),
+ show_image_(true) {
if (!bg_image_1_) {
bg_image_1_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_1,
IDR_AURA_LAUNCHER_TABBED_BROWSER_1_PUSHED,
@@ -58,7 +83,23 @@ TabbedLauncherButton::TabbedLauncherButton(views::ButtonListener* listener,
TabbedLauncherButton::~TabbedLauncherButton() {
}
+void TabbedLauncherButton::PrepareForImageChange() {
+ if (!show_image_ || (animation_.get() && animation_->is_animating()))
+ return;
+
+ // Pause for 500ms, then ease out for 200ms.
+ ui::MultiAnimation::Parts animation_parts;
+ animation_parts.push_back(ui::MultiAnimation::Part(500, ui::Tween::ZERO));
+ animation_parts.push_back(ui::MultiAnimation::Part(200, ui::Tween::EASE_OUT));
+ animation_.reset(new ui::MultiAnimation(animation_parts));
+ animation_->set_continuous(false);
+ animation_->set_delegate(&animation_delegate_);
+ animation_->Start();
+}
+
void TabbedLauncherButton::SetImages(const LauncherTabbedImages& images) {
+ animation_.reset();
+ show_image_ = true;
images_ = images;
ImageSet* set;
if (images_.size() <= 1)
@@ -70,20 +111,29 @@ void TabbedLauncherButton::SetImages(const LauncherTabbedImages& images) {
SetImage(BS_NORMAL, set->normal_image);
SetImage(BS_HOT, set->hot_image);
SetImage(BS_PUSHED, set->pushed_image);
+ SchedulePaint();
}
void TabbedLauncherButton::OnPaint(gfx::Canvas* canvas) {
ImageButton::OnPaint(canvas);
- if (images_.empty())
+ if (images_.empty() || images_[0].image.empty() || !show_image_)
return;
+ bool save_layer = (animation_.get() && animation_->is_animating() &&
+ animation_->current_part_index() == 1);
+ if (save_layer)
+ canvas->SaveLayerAlpha(animation_->CurrentValueBetween(255, 0));
+
// Only show the first icon.
// TODO(sky): if we settle on just 1 icon, then we should simplify surrounding
// code (don't use a vector of images).
int x = (width() - images_[0].image.width()) / 2;
int y = (height() - images_[0].image.height()) / 2 + 1;
canvas->DrawBitmapInt(images_[0].image, x, y);
+
+ if (save_layer)
+ canvas->Restore();
}
bool TabbedLauncherButton::OnMousePressed(const views::MouseEvent& event) {
diff --git a/ui/aura_shell/launcher/tabbed_launcher_button.h b/ui/aura_shell/launcher/tabbed_launcher_button.h
index a945074..589c28a 100644
--- a/ui/aura_shell/launcher/tabbed_launcher_button.h
+++ b/ui/aura_shell/launcher/tabbed_launcher_button.h
@@ -6,9 +6,16 @@
#define UI_AURA_SHELL_LAUNCHER_TABBED_LAUNCHER_BUTTON_H_
#pragma once
+#include "base/memory/scoped_ptr.h"
+#include "base/timer.h"
#include "ui/aura_shell/launcher/launcher_types.h"
+#include "ui/base/animation/animation_delegate.h"
#include "ui/views/controls/button/image_button.h"
+namespace ui {
+class MultiAnimation;
+}
+
namespace aura_shell {
namespace internal {
@@ -21,6 +28,9 @@ class TabbedLauncherButton : public views::ImageButton {
LauncherButtonHost* host);
virtual ~TabbedLauncherButton();
+ // Notification that the images are about to change. Kicks off an animation.
+ void PrepareForImageChange();
+
// Sets the images to display for this entry.
void SetImages(const LauncherTabbedImages& images);
@@ -33,6 +43,24 @@ class TabbedLauncherButton : public views::ImageButton {
virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE;
private:
+ // Used as the delegate for |animation_|. TabbedLauncherButton doesn't
+ // directly implement AnimationDelegate as one of it's superclasses already
+ // does.
+ class AnimationDelegateImpl : public ui::AnimationDelegate {
+ public:
+ explicit AnimationDelegateImpl(TabbedLauncherButton* host);
+ virtual ~AnimationDelegateImpl();
+
+ // ui::AnimationDelegateImpl overrides:
+ virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
+ virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
+
+ private:
+ TabbedLauncherButton* host_;
+
+ DISALLOW_COPY_AND_ASSIGN(AnimationDelegateImpl);
+ };
+
struct ImageSet {
SkBitmap* normal_image;
SkBitmap* pushed_image;
@@ -47,6 +75,16 @@ class TabbedLauncherButton : public views::ImageButton {
LauncherButtonHost* host_;
+ // Delegate of |animation_|.
+ AnimationDelegateImpl animation_delegate_;
+
+ // Used to animate image.
+ scoped_ptr<ui::MultiAnimation> animation_;
+
+ // Should |images_| be shown? This is set to false soon after
+ // PrepareForImageChange() is invoked without a following call to SetImages().
+ bool show_image_;
+
// Background images. Which one is chosen depends upon how many images are
// provided.
static ImageSet* bg_image_1_;
diff --git a/ui/aura_shell/workspace_controller.h b/ui/aura_shell/workspace_controller.h
index fd9e311..e1404da 100644
--- a/ui/aura_shell/workspace_controller.h
+++ b/ui/aura_shell/workspace_controller.h
@@ -70,6 +70,7 @@ class AURA_SHELL_EXPORT WorkspaceController :
virtual void LauncherItemRemoved(int index) OVERRIDE;
virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE;
virtual void LauncherItemImagesChanged(int index) OVERRIDE;
+ virtual void LauncherItemImagesWillChange(int index) OVERRIDE {}
private:
scoped_ptr<WorkspaceManager> workspace_manager_;