Commit ec330505 authored by kalman@chromium.org's avatar kalman@chromium.org

Animation the script badges on views.


BUG=133141

Review URL: https://chromiumcodereview.appspot.com/10699033

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145991 0039d316-1c4b-4281-b951-d872f2087c98
parent 6e72b337
......@@ -45,7 +45,11 @@ PageActionImageView::PageActionImageView(LocationBarView* owner,
ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)),
current_tab_id_(-1),
preview_enabled_(false),
popup_(NULL) {
popup_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_(
page_action->GetIconAnimation(
owner->GetTabContents()->extension_tab_helper()->tab_id()),
this)) {
const Extension* extension = owner_->profile()->GetExtensionService()->
GetExtensionById(page_action->extension_id(), false);
DCHECK(extension);
......@@ -202,11 +206,10 @@ void PageActionImageView::OnImageLoaded(const gfx::Image& image,
page_action_icons_[page_action_->default_icon_path()] = *bitmap;
}
// During object construction (before the parent has been set) we are already
// in a UpdatePageActions call, so we don't need to start another one (and
// doing so causes crash described in http://crbug.com/57333).
if (parent())
owner_->UpdatePageActions();
// During object construction owner_ will be NULL.
TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL;
if (tab_contents)
UpdateVisibility(tab_contents->web_contents(), current_url_);
}
bool PageActionImageView::AcceleratorPressed(
......@@ -262,8 +265,14 @@ void PageActionImageView::UpdateVisibility(WebContents* contents,
icon = iter->second;
}
}
if (!icon.isNull())
if (!icon.isNull()) {
const ExtensionAction::IconAnimation* icon_animation =
scoped_icon_animation_observer_.icon_animation();
if (icon_animation)
icon = icon_animation->Apply(icon);
SetImage(icon);
}
SetVisible(true);
}
......@@ -284,6 +293,13 @@ void PageActionImageView::Observe(int type,
owner_->UpdatePageActions();
}
void PageActionImageView::OnIconChanged(
const ExtensionAction::IconAnimation& animation) {
TabContents* tab_contents = owner_->GetTabContents();
if (tab_contents)
UpdateVisibility(tab_contents->web_contents(), current_url_);
}
void PageActionImageView::ShowPopupWithURL(const GURL& popup_url) {
bool popup_showing = popup_ != NULL;
......
......@@ -12,10 +12,10 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/image_loading_tracker.h"
#include "chrome/browser/ui/views/extensions/extension_popup.h"
#include "chrome/common/extensions/extension_action.h"
#include "ui/views/controls/image_view.h"
class Browser;
class ExtensionAction;
class LocationBarView;
namespace content {
......@@ -30,7 +30,8 @@ class MenuRunner;
class PageActionImageView : public views::ImageView,
public ImageLoadingTracker::Observer,
public views::Widget::Observer,
public content::NotificationObserver {
public content::NotificationObserver,
public ExtensionAction::IconAnimation::Observer {
public:
PageActionImageView(LocationBarView* owner,
ExtensionAction* page_action,
......@@ -79,6 +80,10 @@ class PageActionImageView : public views::ImageView,
void ExecuteAction(int button);
private:
// Overridden from ExtensionAction::IconAnimation::Observer.
virtual void OnIconChanged(
const ExtensionAction::IconAnimation& animation) OVERRIDE;
// Shows the popup, with the given URL.
void ShowPopupWithURL(const GURL& popup_url);
......@@ -127,6 +132,10 @@ class PageActionImageView : public views::ImageView,
scoped_ptr<views::MenuRunner> menu_runner_;
// Fade-in animation for the icon with observer scoped to this.
ExtensionAction::IconAnimation::ScopedObserver
scoped_icon_animation_observer_;
DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment