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

Unified Diff: chrome/browser/ui/views/location_bar/location_bar_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: 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/location_bar_view.cc
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 df73e4c8b9699a93eb0a1de6b608df224339c5f2..702d67d88b61a56209cf93a8039d84674f375ca3 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -11,6 +11,7 @@
#include "base/i18n/rtl.h"
#include "base/prefs/pref_service.h"
#include "base/stl_util.h"
+#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -39,6 +40,7 @@
#include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/toolbar/origin_chip_info.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
@@ -78,6 +80,7 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/theme_provider.h"
#include "ui/events/event.h"
+#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/image/image.h"
@@ -220,6 +223,7 @@ LocationBarView::LocationBarView(Browser* browser,
show_focus_rect_(false),
template_url_service_(NULL),
animation_offset_(0),
+ animated_host_label_(NULL),
weak_ptr_factory_(this) {
edit_bookmarks_enabled_.Init(
prefs::kEditBookmarksEnabled, profile->GetPrefs(),
@@ -317,6 +321,10 @@ void LocationBarView::Init() {
ime_inline_autocomplete_view_->SetVisible(false);
AddChildView(ime_inline_autocomplete_view_);
+ animated_host_label_ = new views::Label(base::string16(), font_list);
+ animated_host_label_->SetVisible(false);
+ AddChildView(animated_host_label_);
+
origin_chip_view_ = new OriginChipView(this, profile(), font_list);
origin_chip_view_->Init();
origin_chip_view_->SetFocusable(false);
@@ -423,6 +431,14 @@ void LocationBarView::Init() {
search_button_->SetVisible(false);
AddChildView(search_button_);
+ show_url_animation_.reset(new gfx::SlideAnimation(this));
+ show_url_animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN);
+ show_url_animation_->SetSlideDuration(200);
+
+ hide_url_animation_.reset(new gfx::SlideAnimation(this));
+ hide_url_animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN);
+ hide_url_animation_->SetSlideDuration(200);
+
content::Source<Profile> profile_source = content::Source<Profile>(profile());
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED,
@@ -706,6 +722,7 @@ void LocationBarView::Layout() {
if (!IsInitialized())
return;
+ animated_host_label_->SetVisible(false);
origin_chip_view_->SetVisible(origin_chip_view_->ShouldShow());
selected_keyword_view_->SetVisible(false);
location_icon_view_->SetVisible(false);
@@ -721,6 +738,47 @@ void LocationBarView::Layout() {
LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE,
item_padding);
+ // Show and position the animated host label used in the show and hide URL
+ // animations.
+ if (show_url_animation_->is_animating() ||
+ hide_url_animation_->is_animating()) {
+ const GURL url = GetWebContents()->GetURL();
+ const base::string16 host =
+ OriginChip::LabelFromURLForProfile(url, profile());
+ animated_host_label_->SetText(host);
+
+ const base::string16 formatted_url = GetToolbarModel()->GetFormattedURL();
+
+ // Split the formatted URL on the host name in order to determine the size
+ // of the text leading up to it.
+ std::vector<base::string16> substrings;
+ base::SplitStringUsingSubstr(formatted_url, host, &substrings);
Peter Kasting 2014/03/21 21:22:10 Does this do the right thing for, say, an intranet
Justin Donnelly 2014/03/24 22:59:37 Good point. There are other issues like a hostname
+ const base::string16 text_leading_host = substrings[0];
+
+ gfx::FontList font_list = origin_chip_view_->GetFontList();
+ int w = std::numeric_limits<int>::max();
+ int h = font_list.GetHeight();
+ gfx::Canvas::SizeStringInt(text_leading_host, font_list, &w, &h, 0, 0);
Peter Kasting 2014/03/21 21:22:10 Do you just want GetStringWidth() here?
Justin Donnelly 2014/03/24 22:59:37 Oh, cool, didn't see that method. Done.
+
+ const int position_of_host_name_in_chip =
+ origin_chip_view_->LabelPosition();
+ const int postition_of_host_name_in_url = position_of_host_name_in_chip + w;
+
+ int host_label_x = position_of_host_name_in_chip;
+ if (show_url_animation_->is_animating()) {
+ host_label_x = show_url_animation_->
+ CurrentValueBetween(position_of_host_name_in_chip,
+ postition_of_host_name_in_url);
+ } else if (hide_url_animation_->is_animating()) {
+ host_label_x = hide_url_animation_->
+ CurrentValueBetween(postition_of_host_name_in_url,
+ position_of_host_name_in_chip);
+ }
+ animated_host_label_->SetBounds(host_label_x, 0,
+ animated_host_label_->GetPreferredSize().width(), height());
Peter Kasting 2014/03/21 21:22:10 Nit: All lines of args should begin at the same ho
Justin Donnelly 2014/03/24 22:59:37 Done.
+ animated_host_label_->SetVisible(true);
+ }
+
const int origin_chip_width = origin_chip_view_->visible() ?
origin_chip_view_->GetPreferredSize().width() : 0;
origin_chip_view_->SetBounds(0, 0, origin_chip_width, height());
@@ -1099,6 +1157,49 @@ void LocationBarView::OnSetFocus() {
GetFocusManager()->SetFocusedView(this);
}
+void LocationBarView::ShowURL() {
+ omnibox_view_->SetVisible(false);
+ omnibox_view_->ShowURL();
+ show_url_animation_->Show();
+}
+
+void LocationBarView::OnShowURLAnimationEnded() {
+ animated_host_label_->SetVisible(false);
+ omnibox_view_->SetVisible(true);
+ omnibox_view_->FadeIn();
+ omnibox_view_->SetFocus();
+}
+
+void LocationBarView::HideURLAndShowOriginChip() {
+ omnibox_view_->SetVisible(false);
+ hide_url_animation_->Show();
+}
+
+void LocationBarView::OnHideURLAnimationEnded() {
+ animated_host_label_->SetVisible(false);
+ omnibox_view_->HideURL();
+ omnibox_view_->SetVisible(true);
+ origin_chip_view_->FadeIn();
+}
+
+void LocationBarView::AnimationProgressed(const gfx::Animation* animation) {
+ if (animation == show_url_animation_.get() ||
+ animation == hide_url_animation_.get()) {
+ Layout();
+ SchedulePaint();
+ }
+}
+
+void LocationBarView::AnimationEnded(const gfx::Animation* animation) {
+ if (animation == show_url_animation_.get()) {
+ show_url_animation_->Reset();
+ OnShowURLAnimationEnded();
+ } else if (animation == hide_url_animation_.get()) {
+ hide_url_animation_->Reset();
+ OnHideURLAnimationEnded();
+ }
+}
+
InstantController* LocationBarView::GetInstant() {
return delegate_->GetInstant();
}

Powered by Google App Engine
This is Rietveld 408576698