Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: chrome/browser/ui/views/location_bar/origin_chip_view.cc

Issue 200783003: [OriginChip] Add animations for the hiding and showing of the chip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/location_bar/origin_chip_view.cc
diff --git a/chrome/browser/ui/views/location_bar/origin_chip_view.cc b/chrome/browser/ui/views/location_bar/origin_chip_view.cc
index 09e385370cdcfe2b1cf547423b3fd39b5407bdf6..1da7a95a39f380f93964d6561eb521953cb43341 100644
--- a/chrome/browser/ui/views/location_bar/origin_chip_view.cc
+++ b/chrome/browser/ui/views/location_bar/origin_chip_view.cc
@@ -25,8 +25,6 @@
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/manifest_handlers/icons_handler.h"
-#include "content/public/browser/navigation_controller.h"
-#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
@@ -37,6 +35,8 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/theme_provider.h"
+#include "ui/gfx/animation/slide_animation.h"
+#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h"
@@ -143,16 +143,7 @@ OriginChipView::OriginChipView(LocationBarView* location_bar_view,
sb_service->ui_manager()->AddObserver(this);
SetFontList(font_list);
-}
-OriginChipView::~OriginChipView() {
- scoped_refptr<SafeBrowsingService> sb_service =
- g_browser_process->safe_browsing_service();
- if (sb_service.get() && sb_service->ui_manager())
- sb_service->ui_manager()->RemoveObserver(this);
-}
-
-void OriginChipView::Init() {
image()->EnableCanvasFlippingForRTLUI(false);
// TODO(gbillock): Would be nice to just use stock LabelButton stuff here.
@@ -164,6 +155,17 @@ void OriginChipView::Init() {
host_label_ = new views::Label(base::string16(), GetFontList());
AddChildView(host_label_);
+
+ fade_in_animation_.reset(new gfx::SlideAnimation(this));
+ fade_in_animation_->SetTweenType(gfx::Tween::LINEAR);
+ fade_in_animation_->SetSlideDuration(300);
+}
+
+OriginChipView::~OriginChipView() {
+ scoped_refptr<SafeBrowsingService> sb_service =
+ g_browser_process->safe_browsing_service();
+ if (sb_service.get() && sb_service->ui_manager())
+ sb_service->ui_manager()->RemoveObserver(this);
}
bool OriginChipView::ShouldShow() {
@@ -280,6 +282,24 @@ void OriginChipView::OnChanged() {
// arrows are pointing to the right spot. Only needed for some edge cases.
}
+void OriginChipView::FadeIn() {
+ fade_in_animation_->Show();
+}
+
+void OriginChipView::AnimationProgressed(const gfx::Animation* animation) {
+ if (animation == fade_in_animation_.get())
+ SchedulePaint();
+ else
+ views::LabelButton::AnimationProgressed(animation);
+}
+
+void OriginChipView::AnimationEnded(const gfx::Animation* animation) {
+ if (animation == fade_in_animation_.get())
+ fade_in_animation_->Reset();
+ else
+ views::LabelButton::AnimationEnded(animation);
+}
+
gfx::Size OriginChipView::GetPreferredSize() {
gfx::Size label_size = host_label_->GetPreferredSize();
gfx::Size icon_size = location_icon_view_->GetPreferredSize();
@@ -312,6 +332,17 @@ void OriginChipView::Layout() {
height() - 2 * LocationBarView::kNormalEdgeThickness);
}
+void OriginChipView::OnPaintBorder(gfx::Canvas* canvas) {
+ if (fade_in_animation_->is_animating()) {
+ canvas->SaveLayerAlpha(static_cast<uint8>(
+ fade_in_animation_->CurrentValueBetween(0, 255)));
+ views::LabelButton::OnPaintBorder(canvas);
+ canvas->Restore();
+ } else {
+ views::LabelButton::OnPaintBorder(canvas);
+ }
+}
+
int OriginChipView::ElideDomainTarget(int target_max_width) {
base::string16 host =
OriginChip::LabelFromURLForProfile(url_displayed_, profile_);
@@ -350,7 +381,7 @@ void OriginChipView::ButtonPressed(views::Button* sender,
UMA_HISTOGRAM_COUNTS("OriginChip.Pressed", 1);
content::RecordAction(base::UserMetricsAction("OriginChipPress"));
- location_bar_view_->GetOmniboxView()->ShowURL();
+ location_bar_view_->ShowURL();
}
// Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will

Powered by Google App Engine
This is Rietveld 408576698