diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-29 20:12:09 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-29 20:12:09 +0000 |
commit | 628e913f71a21b37943bf707764e382f3bda9d53 (patch) | |
tree | 395e4c61b55be903a686f245a436c7d3c2c238c5 /chrome/browser/ui | |
parent | c99436e285f7f5275793e5fe4c1b1a9f7da9ed0d (diff) | |
download | chromium_src-628e913f71a21b37943bf707764e382f3bda9d53.zip chromium_src-628e913f71a21b37943bf707764e382f3bda9d53.tar.gz chromium_src-628e913f71a21b37943bf707764e382f3bda9d53.tar.bz2 |
Upstream omnibox icon fade-in animation
BUG=b/6750053
TEST=Slow down animations in about:instant, type into omnibox, observe fade animation
R=alicet@chromium.org
TBR=sky@chromium.org for OWNERS
Review URL: https://chromiumcodereview.appspot.com/10694032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
5 files changed, 134 insertions, 1 deletions
diff --git a/chrome/browser/ui/search/search_delegate.h b/chrome/browser/ui/search/search_delegate.h index e8f30c7..21c9eb2 100644 --- a/chrome/browser/ui/search/search_delegate.h +++ b/chrome/browser/ui/search/search_delegate.h @@ -40,7 +40,7 @@ class SearchDelegate : public SearchModelObserver { // tab's model. void OnTabDeactivated(TabContents* contents); - // When a tab is dettached, this class no longer observes changes to the + // When a tab is detached, this class no longer observes changes to the // tab's model. void OnTabDetached(TabContents* contents); diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc index 5731485..903a5d2 100644 --- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc +++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc @@ -62,6 +62,10 @@ void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { image_->SetImage(image_skia); } +void IconLabelBubbleView::SetLabelBackgroundColor(SkColor color) { + label_->SetBackgroundColor(color); +} + void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { background_painter_.Paint(canvas, size()); } diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h index 55f03f1..efc4277 100644 --- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h +++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h @@ -41,6 +41,11 @@ class IconLabelBubbleView : public views::View { is_extension_icon_ = is_extension_icon; } + // Sets the label's text background color to |color|. Needed for correct + // sub-pixel text rendering. + void SetLabelBackgroundColor(SkColor color); + + // views::View overrides: virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual gfx::Size GetPreferredSize() OVERRIDE; virtual void Layout() OVERRIDE; diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 00e8a41..7fbcb2d 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -31,6 +31,7 @@ #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" #include "chrome/browser/ui/search/search.h" #include "chrome/browser/ui/search/search_model.h" +#include "chrome/browser/ui/search/search_types.h" #include "chrome/browser/ui/search/search_ui.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/view_ids.h" @@ -48,6 +49,7 @@ #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" #include "chrome/browser/ui/views/omnibox/omnibox_views.h" +#include "chrome/browser/ui/webui/instant_ui.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension_switch_utils.h" @@ -80,6 +82,11 @@ #include "chrome/browser/ui/views/first_run_bubble.h" #endif +#if defined(USE_AURA) +#include "ui/compositor/layer.h" +#include "ui/compositor/scoped_layer_animation_settings.h" +#endif + using content::WebContents; using views::View; @@ -133,6 +140,20 @@ static const int kSelectedKeywordBackgroundImages[] = { IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_R, }; +#if defined(USE_AURA) +LocationBarView::FadeAnimationObserver::FadeAnimationObserver( + LocationBarView* location_bar_view) + : location_bar_view_(location_bar_view) { +} + +LocationBarView::FadeAnimationObserver::~FadeAnimationObserver() { +} + +void LocationBarView::FadeAnimationObserver::OnImplicitAnimationsCompleted() { + location_bar_view_->CleanupFadeAnimation(); +} +#endif // USE_AURA + // LocationBarView ----------------------------------------------------------- LocationBarView::LocationBarView(Profile* profile, @@ -178,11 +199,17 @@ LocationBarView::LocationBarView(Profile* profile, edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, profile_->GetPrefs(), this); + + if (search_model_) + search_model_->AddObserver(this); } LocationBarView::~LocationBarView() { if (template_url_service_) template_url_service_->RemoveObserver(this); + + if (search_model_) + search_model_->RemoveObserver(this); } void LocationBarView::Init(views::View* popup_parent_view) { @@ -349,9 +376,22 @@ void LocationBarView::SetAnimationOffset(int offset) { animation_offset_ = offset; } +void LocationBarView::ModeChanged(const chrome::search::Mode& mode) { +#if defined(USE_AURA) + if (mode.is_search() && mode.animate) { + // Fade in so the icons don't pop. + StartFadeAnimation(); + } else { + // Cancel any pending animations; switch to the final state immediately. + StopFadeAnimation(); + } +#endif +} + void LocationBarView::Update(const WebContents* tab_for_state_restoring) { bool star_enabled = star_view_ && !model_->input_in_progress() && edit_bookmarks_enabled_.GetValue(); + command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); if (star_view_) star_view_->SetVisible(star_enabled); @@ -1382,3 +1422,44 @@ bool LocationBarView::HasValidSuggestText() const { return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && !suggested_text_view_->text().empty(); } + +#if defined(USE_AURA) +void LocationBarView::StartFadeAnimation() { + // We do an opacity animation on this view, so it needs a layer. + SetPaintToLayer(true); + layer()->SetFillsBoundsOpaquely(false); + + // Sub-pixel text rendering doesn't work properly on top of non-opaque + // layers, so disable it by setting a transparent background color on the + // bubble labels. + const SkColor kTransparentWhite = SkColorSetARGB(128, 255, 255, 255); + ev_bubble_view_->SetLabelBackgroundColor(kTransparentWhite); + selected_keyword_view_->SetLabelBackgroundColor(kTransparentWhite); + + // Fade in opacity from 0 to 1. + layer()->SetOpacity(0.f); + ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); + fade_animation_observer_.reset(new FadeAnimationObserver(this)); + settings.AddObserver(fade_animation_observer_.get()); + settings.SetTransitionDuration( + base::TimeDelta::FromMilliseconds( + 200 * InstantUI::GetSlowAnimationScaleFactor())); + settings.SetTweenType(ui::Tween::LINEAR); + layer()->SetOpacity(1.f); +} + +void LocationBarView::StopFadeAnimation() { + if (!layer()) + return; + // Stop all animations. + layer()->GetAnimator()->StopAnimating(); +} + +void LocationBarView::CleanupFadeAnimation() { + // Since we're no longer animating we don't need our layer. + SetPaintToLayer(false); + // Bubble labels don't need a transparent background anymore. + ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); + selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); +} +#endif // USE_AURA diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index d6b11ac..b4cd8cc 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -15,6 +15,7 @@ #include "chrome/browser/search_engines/template_url_service_observer.h" #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" +#include "chrome/browser/ui/search/search_model_observer.h" #include "chrome/browser/ui/toolbar/toolbar_model.h" #include "chrome/browser/ui/views/dropdown_bar_host.h" #include "chrome/browser/ui/views/dropdown_bar_host_delegate.h" @@ -26,6 +27,10 @@ #include "ui/views/controls/native/native_view_host.h" #include "ui/views/drag_controller.h" +#if defined(USE_AURA) +#include "ui/compositor/layer_animation_observer.h" +#endif + class ActionBoxButtonView; class ChromeToMobileView; class CommandUpdater; @@ -71,6 +76,7 @@ class LocationBarView : public LocationBar, public views::DragController, public OmniboxEditController, public DropdownBarHostDelegate, + public chrome::search::SearchModelObserver, public TemplateURLServiceObserver, public content::NotificationObserver { public: @@ -81,6 +87,9 @@ class LocationBarView : public LocationBar, virtual void SetFocusAndSelection(bool select_all) OVERRIDE; virtual void SetAnimationOffset(int offset) OVERRIDE; + // chrome::search::SearchModelObserver: + virtual void ModeChanged(const chrome::search::Mode& mode) OVERRIDE; + // Returns the offset used while animating. int animation_offset() const { return animation_offset_; } @@ -351,6 +360,24 @@ class LocationBarView : public LocationBar, friend class PageActionWithBadgeView; typedef std::vector<PageActionWithBadgeView*> PageActionViews; +#if defined(USE_AURA) + // Observer that informs the LocationBarView when the animation is done. + class FadeAnimationObserver : public ui::ImplicitAnimationObserver { + public: + explicit FadeAnimationObserver(LocationBarView* location_bar_view); + virtual ~FadeAnimationObserver(); + + // ui::ImplicitAnimationObserver overrides: + virtual void OnImplicitAnimationsCompleted() OVERRIDE; + + private: + // The location bar view being animated. Not owned. + LocationBarView* location_bar_view_; + + DISALLOW_COPY_AND_ASSIGN(FadeAnimationObserver); + }; +#endif // USE_AURA + // Returns the amount of horizontal space (in pixels) out of // |location_bar_width| that is not taken up by the actual text in // location_entry_. @@ -396,6 +423,17 @@ class LocationBarView : public LocationBar, void PaintActionBoxBackground(gfx::Canvas* canvas, const gfx::Rect& content_rect); +#if defined(USE_AURA) + // Fade in the location bar view so the icons come in gradually. + void StartFadeAnimation(); + + // Stops the fade animation, if it is playing. Otherwise does nothing. + void StopFadeAnimation(); + + // Cleans up layers used for the animation. + void CleanupFadeAnimation(); +#endif + // The Autocomplete Edit field. scoped_ptr<OmniboxView> location_entry_; @@ -501,6 +539,11 @@ class LocationBarView : public LocationBar, // LocationBarContainer. views::View* view_to_focus_; +#if defined(USE_AURA) + // Observer for a fade-in animation. + scoped_ptr<FadeAnimationObserver> fade_animation_observer_; +#endif + DISALLOW_IMPLICIT_CONSTRUCTORS(LocationBarView); }; |