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

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 731423002: Remove OriginChip code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 28 matching lines...) Expand all
39 #include "chrome/browser/ui/tabs/tab_strip_model.h" 39 #include "chrome/browser/ui/tabs/tab_strip_model.h"
40 #include "chrome/browser/ui/view_ids.h" 40 #include "chrome/browser/ui/view_ids.h"
41 #include "chrome/browser/ui/views/browser_dialogs.h" 41 #include "chrome/browser/ui/views/browser_dialogs.h"
42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
44 #include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h" 44 #include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h"
45 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 45 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
46 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" 46 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h"
47 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 47 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
48 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" 48 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h"
49 #include "chrome/browser/ui/views/location_bar/origin_chip_view.h"
50 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 49 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
51 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 50 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
52 #include "chrome/browser/ui/views/location_bar/search_button.h" 51 #include "chrome/browser/ui/views/location_bar/search_button.h"
53 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 52 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
54 #include "chrome/browser/ui/views/location_bar/star_view.h" 53 #include "chrome/browser/ui/views/location_bar/star_view.h"
55 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" 54 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
56 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 55 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
57 #include "chrome/browser/ui/views/location_bar/zoom_view.h" 56 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
58 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" 57 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
59 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" 58 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 94
96 #if !defined(OS_CHROMEOS) 95 #if !defined(OS_CHROMEOS)
97 #include "chrome/browser/ui/views/first_run_bubble.h" 96 #include "chrome/browser/ui/views/first_run_bubble.h"
98 #endif 97 #endif
99 98
100 using content::WebContents; 99 using content::WebContents;
101 using views::View; 100 using views::View;
102 101
103 namespace { 102 namespace {
104 103
105 const gfx::Tween::Type kShowTweenType = gfx::Tween::LINEAR_OUT_SLOW_IN;
106 const gfx::Tween::Type kHideTweenType = gfx::Tween::FAST_OUT_LINEAR_IN;
107
108 // The search button images are made to look as if they overlay the normal edge 104 // The search button images are made to look as if they overlay the normal edge
109 // images, but to align things, the search button needs to be inset horizontally 105 // images, but to align things, the search button needs to be inset horizontally
110 // by 1 px. 106 // by 1 px.
111 const int kSearchButtonInset = 1; 107 const int kSearchButtonInset = 1;
112 108
113 int GetEditLeadingInternalSpace() { 109 int GetEditLeadingInternalSpace() {
114 // The textfield has 1 px of whitespace before the text in the RTL case only. 110 // The textfield has 1 px of whitespace before the text in the RTL case only.
115 return base::i18n::IsRTL() ? 1 : 0; 111 return base::i18n::IsRTL() ? 1 : 0;
116 } 112 }
117 113
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 LocationBarView::LocationBarView(Browser* browser, 149 LocationBarView::LocationBarView(Browser* browser,
154 Profile* profile, 150 Profile* profile,
155 CommandUpdater* command_updater, 151 CommandUpdater* command_updater,
156 Delegate* delegate, 152 Delegate* delegate,
157 bool is_popup_mode) 153 bool is_popup_mode)
158 : LocationBar(profile), 154 : LocationBar(profile),
159 OmniboxEditController(command_updater), 155 OmniboxEditController(command_updater),
160 browser_(browser), 156 browser_(browser),
161 omnibox_view_(NULL), 157 omnibox_view_(NULL),
162 delegate_(delegate), 158 delegate_(delegate),
163 origin_chip_view_(NULL),
164 location_icon_view_(NULL), 159 location_icon_view_(NULL),
165 ev_bubble_view_(NULL), 160 ev_bubble_view_(NULL),
166 ime_inline_autocomplete_view_(NULL), 161 ime_inline_autocomplete_view_(NULL),
167 selected_keyword_view_(NULL), 162 selected_keyword_view_(NULL),
168 suggested_text_view_(NULL), 163 suggested_text_view_(NULL),
169 keyword_hint_view_(NULL), 164 keyword_hint_view_(NULL),
170 mic_search_view_(NULL), 165 mic_search_view_(NULL),
171 zoom_view_(NULL), 166 zoom_view_(NULL),
172 generated_credit_card_view_(NULL), 167 generated_credit_card_view_(NULL),
173 open_pdf_in_reader_view_(NULL), 168 open_pdf_in_reader_view_(NULL),
174 manage_passwords_icon_view_(NULL), 169 manage_passwords_icon_view_(NULL),
175 translate_icon_view_(NULL), 170 translate_icon_view_(NULL),
176 star_view_(NULL), 171 star_view_(NULL),
177 search_button_(NULL), 172 search_button_(NULL),
178 is_popup_mode_(is_popup_mode), 173 is_popup_mode_(is_popup_mode),
179 show_focus_rect_(false), 174 show_focus_rect_(false),
180 template_url_service_(NULL), 175 template_url_service_(NULL),
181 dropdown_animation_offset_(0), 176 dropdown_animation_offset_(0),
182 starting_omnibox_offset_(0),
183 current_omnibox_offset_(0),
184 starting_omnibox_leading_inset_(0), 177 starting_omnibox_leading_inset_(0),
185 current_omnibox_leading_inset_(0), 178 current_omnibox_leading_inset_(0) {
186 current_omnibox_width_(0),
187 ending_omnibox_width_(0) {
188 edit_bookmarks_enabled_.Init( 179 edit_bookmarks_enabled_.Init(
189 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 180 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
190 base::Bind(&LocationBarView::Update, base::Unretained(this), 181 base::Bind(&LocationBarView::Update, base::Unretained(this),
191 static_cast<content::WebContents*>(NULL))); 182 static_cast<content::WebContents*>(NULL)));
192 183
193 if (browser_) 184 if (browser_)
194 browser_->search_model()->AddObserver(this); 185 browser_->search_model()->AddObserver(this);
195 } 186 }
196 187
197 LocationBarView::~LocationBarView() { 188 LocationBarView::~LocationBarView() {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); 258 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false);
268 ime_inline_autocomplete_view_->set_background( 259 ime_inline_autocomplete_view_->set_background(
269 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( 260 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
270 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); 261 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)));
271 ime_inline_autocomplete_view_->SetEnabledColor( 262 ime_inline_autocomplete_view_->SetEnabledColor(
272 GetNativeTheme()->GetSystemColor( 263 GetNativeTheme()->GetSystemColor(
273 ui::NativeTheme::kColorId_TextfieldSelectionColor)); 264 ui::NativeTheme::kColorId_TextfieldSelectionColor));
274 ime_inline_autocomplete_view_->SetVisible(false); 265 ime_inline_autocomplete_view_->SetVisible(false);
275 AddChildView(ime_inline_autocomplete_view_); 266 AddChildView(ime_inline_autocomplete_view_);
276 267
277 origin_chip_view_ = new OriginChipView(this, profile(), font_list);
278 origin_chip_view_->SetFocusable(false);
279 origin_chip_view_->set_drag_controller(this);
280 AddChildView(origin_chip_view_);
281
282 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); 268 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT);
283 selected_keyword_view_ = new SelectedKeywordView( 269 selected_keyword_view_ = new SelectedKeywordView(
284 bubble_font_list, text_color, background_color, profile()); 270 bubble_font_list, text_color, background_color, profile());
285 AddChildView(selected_keyword_view_); 271 AddChildView(selected_keyword_view_);
286 272
287 suggested_text_view_ = new views::Label(base::string16(), font_list); 273 suggested_text_view_ = new views::Label(base::string16(), font_list);
288 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 274 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
289 suggested_text_view_->SetAutoColorReadabilityEnabled(false); 275 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
290 suggested_text_view_->SetEnabledColor(GetColor( 276 suggested_text_view_->SetEnabledColor(GetColor(
291 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); 277 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 AddChildView(translate_icon_view_); 325 AddChildView(translate_icon_view_);
340 326
341 star_view_ = new StarView(command_updater()); 327 star_view_ = new StarView(command_updater());
342 star_view_->SetVisible(false); 328 star_view_->SetVisible(false);
343 AddChildView(star_view_); 329 AddChildView(star_view_);
344 330
345 search_button_ = new SearchButton(this); 331 search_button_ = new SearchButton(this);
346 search_button_->SetVisible(false); 332 search_button_->SetVisible(false);
347 AddChildView(search_button_); 333 AddChildView(search_button_);
348 334
349 show_url_animation_.reset(new gfx::SlideAnimation(this));
350 show_url_animation_->SetTweenType(kShowTweenType);
351 show_url_animation_->SetSlideDuration(200);
352
353 hide_url_animation_.reset(new gfx::SlideAnimation(this));
354 hide_url_animation_->SetTweenType(kHideTweenType);
355 hide_url_animation_->SetSlideDuration(175);
356
357 // Initialize the location entry. We do this to avoid a black flash which is 335 // Initialize the location entry. We do this to avoid a black flash which is
358 // visible when the location entry has just been initialized. 336 // visible when the location entry has just been initialized.
359 Update(NULL); 337 Update(NULL);
360 } 338 }
361 339
362 bool LocationBarView::IsInitialized() const { 340 bool LocationBarView::IsInitialized() const {
363 return omnibox_view_ != NULL; 341 return omnibox_view_ != NULL;
364 } 342 }
365 343
366 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, 344 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 if (star_view_) 442 if (star_view_)
465 star_view_->SetToggled(on); 443 star_view_->SetToggled(on);
466 } 444 }
467 445
468 void LocationBarView::SetTranslateIconToggled(bool on) { 446 void LocationBarView::SetTranslateIconToggled(bool on) {
469 translate_icon_view_->SetToggled(on); 447 translate_icon_view_->SetToggled(on);
470 } 448 }
471 449
472 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { 450 gfx::Point LocationBarView::GetOmniboxViewOrigin() const {
473 gfx::Point origin(omnibox_view_->bounds().origin()); 451 gfx::Point origin(omnibox_view_->bounds().origin());
474 origin.set_x(GetMirroredXInView(origin.x() - current_omnibox_offset_)); 452 origin.set_x(GetMirroredXInView(origin.x()));
475 views::View::ConvertPointToScreen(this, &origin); 453 views::View::ConvertPointToScreen(this, &origin);
476 return origin; 454 return origin;
477 } 455 }
478 456
479 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { 457 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) {
480 ime_inline_autocomplete_view_->SetText(text); 458 ime_inline_autocomplete_view_->SetText(text);
481 ime_inline_autocomplete_view_->SetVisible(!text.empty()); 459 ime_inline_autocomplete_view_->SetVisible(!text.empty());
482 } 460 }
483 461
484 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { 462 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // Compute minimum height. 556 // Compute minimum height.
579 gfx::Size min_size(border_painter_->GetMinimumSize()); 557 gfx::Size min_size(border_painter_->GetMinimumSize());
580 if (!IsInitialized()) 558 if (!IsInitialized())
581 return min_size; 559 return min_size;
582 gfx::Size search_button_min_size(search_button_->GetMinimumSize()); 560 gfx::Size search_button_min_size(search_button_->GetMinimumSize());
583 min_size.SetToMax(search_button_min_size); 561 min_size.SetToMax(search_button_min_size);
584 562
585 // Compute width of omnibox-leading content. 563 // Compute width of omnibox-leading content.
586 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); 564 const int horizontal_edge_thickness = GetHorizontalEdgeThickness();
587 int leading_width = horizontal_edge_thickness; 565 int leading_width = horizontal_edge_thickness;
588 // TODO(pkasting): Make the origin chip min width sane, and make the chip
589 // handle being shrunken down more gracefully; then uncomment this.
590 /*if (GetToolbarModel()->ShouldShowOriginChip())
591 leading_width += origin_chip_view_->GetMinimumSize().width();*/
592 if (ShouldShowKeywordBubble()) { 566 if (ShouldShowKeywordBubble()) {
593 // The selected keyword view can collapse completely. 567 // The selected keyword view can collapse completely.
594 } else if (ShouldShowEVBubble()) { 568 } else if (ShouldShowEVBubble()) {
595 leading_width += kBubblePadding + 569 leading_width += kBubblePadding +
596 ev_bubble_view_->GetMinimumSizeForLabelText( 570 ev_bubble_view_->GetMinimumSizeForLabelText(
597 GetToolbarModel()->GetEVCertName()).width(); 571 GetToolbarModel()->GetEVCertName()).width();
598 } else if (!origin_chip_view_->visible()) { 572 } else {
599 leading_width += 573 leading_width +=
600 kItemPadding + location_icon_view_->GetMinimumSize().width(); 574 kItemPadding + location_icon_view_->GetMinimumSize().width();
601 } 575 }
602 576
603 // Compute width of omnibox-trailing content. 577 // Compute width of omnibox-trailing content.
604 int trailing_width = search_button_->visible() ? 578 int trailing_width = search_button_->visible() ?
605 (search_button_->GetMinimumSize().width() + kSearchButtonInset) : 579 (search_button_->GetMinimumSize().width() + kSearchButtonInset) :
606 horizontal_edge_thickness; 580 horizontal_edge_thickness;
607 trailing_width += IncrementalMinimumWidth(star_view_) + 581 trailing_width += IncrementalMinimumWidth(star_view_) +
608 IncrementalMinimumWidth(translate_icon_view_) + 582 IncrementalMinimumWidth(translate_icon_view_) +
(...skipping 11 matching lines...) Expand all
620 594
621 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + 595 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() +
622 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width); 596 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width);
623 return min_size; 597 return min_size;
624 } 598 }
625 599
626 void LocationBarView::Layout() { 600 void LocationBarView::Layout() {
627 if (!IsInitialized()) 601 if (!IsInitialized())
628 return; 602 return;
629 603
630 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip());
631 selected_keyword_view_->SetVisible(false); 604 selected_keyword_view_->SetVisible(false);
632 location_icon_view_->SetVisible(false); 605 location_icon_view_->SetVisible(false);
633 ev_bubble_view_->SetVisible(false); 606 ev_bubble_view_->SetVisible(false);
634 keyword_hint_view_->SetVisible(false); 607 keyword_hint_view_->SetVisible(false);
635 608
636 LocationBarLayout leading_decorations( 609 LocationBarLayout leading_decorations(
637 LocationBarLayout::LEFT_EDGE, 610 LocationBarLayout::LEFT_EDGE,
638 kItemPadding - omnibox_view_->GetInsets().left() - 611 kItemPadding - omnibox_view_->GetInsets().left() -
639 GetEditLeadingInternalSpace()); 612 GetEditLeadingInternalSpace());
640 LocationBarLayout trailing_decorations( 613 LocationBarLayout trailing_decorations(
641 LocationBarLayout::RIGHT_EDGE, 614 LocationBarLayout::RIGHT_EDGE,
642 kItemPadding - omnibox_view_->GetInsets().right()); 615 kItemPadding - omnibox_view_->GetInsets().right());
643 616
644 const int origin_chip_preferred_width =
645 origin_chip_view_->GetPreferredSize().width();
646 const int origin_chip_width =
647 origin_chip_view_->visible() ? origin_chip_preferred_width : 0;
648 // Always give the origin chip view its desired size and lay it out, even when
649 // it's not visible, so we can calculate the correct animation values below
650 // when switching to tabs that have the origin chip hidden.
651 origin_chip_view_->SetBounds(0, 0, origin_chip_preferred_width, height());
652 origin_chip_view_->Layout();
653
654 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; 617 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding;
655 const base::string16 keyword(omnibox_view_->model()->keyword()); 618 const base::string16 keyword(omnibox_view_->model()->keyword());
656 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 619 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want
657 // to position our child views in this case, because other things may be 620 // to position our child views in this case, because other things may be
658 // positioned relative to them (e.g. the "bookmark added" bubble if the user 621 // positioned relative to them (e.g. the "bookmark added" bubble if the user
659 // hits ctrl-d). 622 // hits ctrl-d).
660 const int location_height = GetInternalHeight(false); 623 const int location_height = GetInternalHeight(false);
661 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); 624 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0);
662 if (ShouldShowKeywordBubble()) { 625 if (ShouldShowKeywordBubble()) {
663 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0, 626 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0,
(...skipping 16 matching lines...) Expand all
680 selected_keyword_view_->set_is_extension_icon(false); 643 selected_keyword_view_->set_is_extension_icon(false);
681 } 644 }
682 } 645 }
683 } else if (ShouldShowEVBubble()) { 646 } else if (ShouldShowEVBubble()) {
684 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); 647 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName());
685 // The largest fraction of the omnibox that can be taken by the EV bubble. 648 // The largest fraction of the omnibox that can be taken by the EV bubble.
686 const double kMaxBubbleFraction = 0.5; 649 const double kMaxBubbleFraction = 0.5;
687 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, 650 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false,
688 kMaxBubbleFraction, kBubblePadding, 651 kMaxBubbleFraction, kBubblePadding,
689 kItemPadding, ev_bubble_view_); 652 kItemPadding, ev_bubble_view_);
690 } else if (!origin_chip_view_->visible()) { 653 } else {
691 leading_decorations.AddDecoration( 654 leading_decorations.AddDecoration(
692 vertical_edge_thickness(), location_height, 655 vertical_edge_thickness(), location_height,
693 location_icon_view_); 656 location_icon_view_);
694 } 657 }
695 658
696 if (star_view_->visible()) { 659 if (star_view_->visible()) {
697 trailing_decorations.AddDecoration( 660 trailing_decorations.AddDecoration(
698 vertical_edge_thickness(), location_height, star_view_); 661 vertical_edge_thickness(), location_height, star_view_);
699 } 662 }
700 if (translate_icon_view_->visible()) { 663 if (translate_icon_view_->visible()) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 !omnibox_view_->IsImeComposing()) { 708 !omnibox_view_->IsImeComposing()) {
746 trailing_decorations.AddDecoration(vertical_edge_thickness(), 709 trailing_decorations.AddDecoration(vertical_edge_thickness(),
747 location_height, true, 0, kItemPadding, 710 location_height, true, 0, kItemPadding,
748 kItemPadding, keyword_hint_view_); 711 kItemPadding, keyword_hint_view_);
749 if (keyword_hint_view_->keyword() != keyword) 712 if (keyword_hint_view_->keyword() != keyword)
750 keyword_hint_view_->SetKeyword(keyword); 713 keyword_hint_view_->SetKeyword(keyword);
751 } 714 }
752 715
753 // Perform layout. 716 // Perform layout.
754 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); 717 const int horizontal_edge_thickness = GetHorizontalEdgeThickness();
755 int full_width = width() - horizontal_edge_thickness - origin_chip_width; 718 int full_width = width() - horizontal_edge_thickness;
756 719
757 const gfx::Size search_button_size(search_button_->GetPreferredSize()); 720 const gfx::Size search_button_size(search_button_->GetPreferredSize());
758 const int search_button_reserved_width = 721 const int search_button_reserved_width =
759 search_button_size.width() + kSearchButtonInset; 722 search_button_size.width() + kSearchButtonInset;
760 full_width -= search_button_->visible() ? 723 full_width -= search_button_->visible() ?
761 search_button_reserved_width : horizontal_edge_thickness; 724 search_button_reserved_width : horizontal_edge_thickness;
762 int entry_width = full_width; 725 int entry_width = full_width;
763 leading_decorations.LayoutPass1(&entry_width); 726 leading_decorations.LayoutPass1(&entry_width);
764 trailing_decorations.LayoutPass1(&entry_width); 727 trailing_decorations.LayoutPass1(&entry_width);
765 leading_decorations.LayoutPass2(&entry_width); 728 leading_decorations.LayoutPass2(&entry_width);
766 trailing_decorations.LayoutPass2(&entry_width); 729 trailing_decorations.LayoutPass2(&entry_width);
767 730
768 int location_needed_width = omnibox_view_->GetTextWidth(); 731 int location_needed_width = omnibox_view_->GetTextWidth();
769 int available_width = entry_width - location_needed_width; 732 int available_width = entry_width - location_needed_width;
770 // The bounds must be wide enough for all the decorations to fit. 733 // The bounds must be wide enough for all the decorations to fit.
771 gfx::Rect location_bounds( 734 gfx::Rect location_bounds(
772 origin_chip_width + horizontal_edge_thickness, vertical_edge_thickness(), 735 horizontal_edge_thickness, vertical_edge_thickness(),
773 std::max(full_width, full_width - entry_width), location_height); 736 std::max(full_width, full_width - entry_width), location_height);
774 leading_decorations.LayoutPass3(&location_bounds, &available_width); 737 leading_decorations.LayoutPass3(&location_bounds, &available_width);
775 trailing_decorations.LayoutPass3(&location_bounds, &available_width); 738 trailing_decorations.LayoutPass3(&location_bounds, &available_width);
776 739
777 // Calculate the animation parameters (see comments on these members in the
778 // header). We have to do this in Layout, after |origin_chip_view_| is laid
779 // out, because that may affect the host label offset in the origin chip.
780 const base::string16& chip_text(origin_chip_view_->host_label_text());
781 // If the chip is clicked, the omnibox text will become the toolbar model's
782 // formatted URL. We can't ask the omnibox for its current text, because
783 // while the chip is visible the current text is empty.
784 size_t prefix_end = 0;
785 const base::string16& omnibox_text(
786 GetToolbarModel()->GetFormattedURL(&prefix_end));
787 // Do a case-insensitive search to better match cases like
788 // "Settings" <-> "chrome://settings". Skip any pre-hostname text.
789 size_t chip_text_offset = std::search(
790 omnibox_text.begin() + prefix_end, omnibox_text.end(),
791 chip_text.begin(), chip_text.end(),
792 base::CaseInsensitiveCompare<base::char16>()) - omnibox_text.begin();
793 // If we couldn't find the chip text, try checking whether the omnibox text
794 // starts with it, as is true for e.g. file: URLs.
795 if ((chip_text_offset >= omnibox_text.length()) &&
796 StartsWith(omnibox_text, chip_text, true))
797 chip_text_offset = 0;
798 const gfx::FontList& font_list = omnibox_view_->GetFontList();
799 const int chip_text_width = gfx::GetStringWidth(chip_text, font_list);
800 const int old_starting_offset = starting_omnibox_offset_;
801 const int old_starting_leading_inset = starting_omnibox_leading_inset_;
802 const int old_ending_width = ending_omnibox_width_;
803 starting_omnibox_offset_ = current_omnibox_offset_ = 0;
804 starting_omnibox_leading_inset_ = current_omnibox_leading_inset_ = 0;
805 ending_omnibox_width_ = gfx::GetStringWidth(omnibox_text, font_list);
806 if (chip_text_offset < omnibox_text.length()) {
807 if (base::i18n::IsRTL())
808 chip_text_offset += chip_text.length();
809 base::string16 extra_omnibox_text(base::i18n::IsRTL() ?
810 omnibox_text.substr(chip_text_offset) :
811 omnibox_text.substr(0, chip_text_offset));
812 starting_omnibox_leading_inset_ =
813 gfx::GetStringWidth(extra_omnibox_text, font_list);
814 starting_omnibox_offset_ = origin_chip_view_->HostLabelOffset() -
815 starting_omnibox_leading_inset_;
816 current_omnibox_width_ = chip_text_width;
817 } else {
818 // If the chip text wasn't found in the omnibox text, then instead of
819 // starting the show animation clipped to the "hostname", we'll start with
820 // the entire omnibox text visible, clipped to the remaining chip width, and
821 // only animate any necessary expansion of that width, without moving the
822 // omnibox bounds.
823 current_omnibox_width_ = origin_chip_view_->WidthFromStartOfLabels();
824 }
825
826 // End the animations immediately if the parameters have changed.
827 if ((starting_omnibox_offset_ != old_starting_offset) ||
828 (starting_omnibox_leading_inset_ != old_starting_leading_inset) ||
829 (ending_omnibox_width_ != old_ending_width))
830 EndOriginChipAnimations(true);
831
832 // Also end the animations immediately if there's nothing to animate (but do
833 // allow the chip to fade back in).
834 const ui::NativeTheme* native_theme = GetNativeTheme();
835 const SkColor ending_selection_text_color = native_theme->GetSystemColor(
836 ui::NativeTheme::kColorId_TextfieldSelectionColor);
837 const SkColor ending_selection_background_color =
838 native_theme->GetSystemColor(
839 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused);
840 if ((starting_omnibox_offset_ == 0) &&
841 (starting_omnibox_leading_inset_ == 0) &&
842 (ending_omnibox_width_ == chip_text_width) &&
843 (hide_url_animation_->is_animating() ||
844 ((ending_selection_text_color ==
845 origin_chip_view_->pressed_text_color()) &&
846 (ending_selection_background_color ==
847 origin_chip_view_->pressed_background_color()))))
848 EndOriginChipAnimations(false);
849
850 if (show_url_animation_->is_animating()) {
851 omnibox_view_->SetSelectionTextColor(gfx::Tween::ColorValueBetween(
852 show_url_animation_->GetCurrentValue(),
853 origin_chip_view_->pressed_text_color(),
854 ending_selection_text_color));
855 omnibox_view_->SetSelectionBackgroundColor(gfx::Tween::ColorValueBetween(
856 show_url_animation_->GetCurrentValue(),
857 origin_chip_view_->pressed_background_color(),
858 ending_selection_background_color));
859 current_omnibox_offset_ =
860 show_url_animation_->CurrentValueBetween(starting_omnibox_offset_, 0);
861 current_omnibox_leading_inset_ = show_url_animation_->CurrentValueBetween(
862 starting_omnibox_leading_inset_, 0);
863 current_omnibox_width_ = show_url_animation_->CurrentValueBetween(
864 chip_text_width, ending_omnibox_width_);
865 } else if (hide_url_animation_->is_animating()) {
866 current_omnibox_offset_ =
867 hide_url_animation_->CurrentValueBetween(0, starting_omnibox_offset_);
868 current_omnibox_leading_inset_ = hide_url_animation_->CurrentValueBetween(
869 0, starting_omnibox_leading_inset_);
870 current_omnibox_width_ = hide_url_animation_->CurrentValueBetween(
871 ending_omnibox_width_, chip_text_width);
872 }
873 // Contract |available_width| as necessary, but never expand it. This way,
874 // we'll never draw suggested text at first and then have it disappear
875 // midway through the animation.
876 if (current_omnibox_offset_ > 0)
877 available_width -= current_omnibox_offset_;
878 location_bounds.Inset(current_omnibox_offset_, 0, 0, 0);
879
880 // Layout out the suggested text view right aligned to the location 740 // Layout out the suggested text view right aligned to the location
881 // entry. Only show the suggested text if we can fit the text from one 741 // entry. Only show the suggested text if we can fit the text from one
882 // character before the end of the selection to the end of the text and the 742 // character before the end of the selection to the end of the text and the
883 // suggested text. If we can't it means either the suggested text is too big, 743 // suggested text. If we can't it means either the suggested text is too big,
884 // or the user has scrolled. 744 // or the user has scrolled.
885 745
886 // TODO(sky): We could potentially adjust this to take into account suggested 746 // TODO(sky): We could potentially adjust this to take into account suggested
887 // text to force using minimum size if necessary, but currently the chance of 747 // text to force using minimum size if necessary, but currently the chance of
888 // showing keyword hints and suggested text is minimal and we're not confident 748 // showing keyword hints and suggested text is minimal and we're not confident
889 // this is the right approach for suggested text. 749 // this is the right approach for suggested text.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 845
986 if (contents) 846 if (contents)
987 omnibox_view_->OnTabChanged(contents); 847 omnibox_view_->OnTabChanged(contents);
988 else 848 else
989 omnibox_view_->Update(); 849 omnibox_view_->Update();
990 850
991 OnChanged(); // NOTE: Calls Layout(). 851 OnChanged(); // NOTE: Calls Layout().
992 } 852 }
993 853
994 void LocationBarView::ShowURL() { 854 void LocationBarView::ShowURL() {
995 // Start the animation before calling ShowURL(), since the latter eventually
996 // calls back to Layout(), and if the animation is not marked as "running",
997 // we'll draw the omnibox in its final position briefly until the first
998 // animation callback reaches us.
999 if (chrome::ShouldDisplayOriginChip()) {
1000 // If we're currently hiding, reverse the hide by swapping to the show
1001 // animation, offset so that the text is in the same position.
1002 if (hide_url_animation_->is_animating()) {
1003 const double show_value = GetValueForAnimation(false);
1004 hide_url_animation_->Reset();
1005 show_url_animation_->Show();
1006 // This must be done after calling Show() and is not equivalent to
1007 // calling Reset(n) before Show(); Reset() would have caused the entire
1008 // animation curve (and time) to run between this value and the final
1009 // value, whereas Show() + SetCurrentValue() skips the animation forward
1010 // to the supplied value.
1011 show_url_animation_->SetCurrentValue(show_value);
1012 } else {
1013 show_url_animation_->Show();
1014 }
1015 }
1016 omnibox_view_->ShowURL(); 855 omnibox_view_->ShowURL();
1017 } 856 }
1018 857
1019 void LocationBarView::EndOriginChipAnimations(bool cancel_fade) {
1020 show_url_animation_->End();
1021 hide_url_animation_->End();
1022 if (cancel_fade)
1023 origin_chip_view_->CancelFade();
1024 }
1025
1026 ToolbarModel* LocationBarView::GetToolbarModel() { 858 ToolbarModel* LocationBarView::GetToolbarModel() {
1027 return delegate_->GetToolbarModel(); 859 return delegate_->GetToolbarModel();
1028 } 860 }
1029 861
1030 WebContents* LocationBarView::GetWebContents() { 862 WebContents* LocationBarView::GetWebContents() {
1031 return delegate_->GetWebContents(); 863 return delegate_->GetWebContents();
1032 } 864 }
1033 865
1034 //////////////////////////////////////////////////////////////////////////////// 866 ////////////////////////////////////////////////////////////////////////////////
1035 // LocationBarView, private: 867 // LocationBarView, private:
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 return suggested_text_view_->visible() && 1014 return suggested_text_view_->visible() &&
1183 !suggested_text_view_->size().IsEmpty(); 1015 !suggested_text_view_->size().IsEmpty();
1184 } 1016 }
1185 1017
1186 bool LocationBarView::ShouldShowKeywordBubble() const { 1018 bool LocationBarView::ShouldShowKeywordBubble() const {
1187 return !omnibox_view_->model()->keyword().empty() && 1019 return !omnibox_view_->model()->keyword().empty() &&
1188 !omnibox_view_->model()->is_keyword_hint(); 1020 !omnibox_view_->model()->is_keyword_hint();
1189 } 1021 }
1190 1022
1191 bool LocationBarView::ShouldShowEVBubble() const { 1023 bool LocationBarView::ShouldShowEVBubble() const {
1192 return !chrome::ShouldDisplayOriginChip() && 1024 return
1193 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); 1025 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE);
1194 } 1026 }
1195 1027
1196 double LocationBarView::GetValueForAnimation(bool hide) const {
1197 int calculated_offset;
1198 const gfx::Tween::Type tween_type = hide ? kHideTweenType : kShowTweenType;
1199 int start_offset = starting_omnibox_offset_, end_offset = 0;
1200 if (hide)
1201 std::swap(start_offset, end_offset);
1202 const int desired_offset = abs(current_omnibox_offset_);
1203 // Binary-search the value space (0 <= value <= 1) to find the appropriate
1204 // position. We only bother to iterate to within 1/64 of the desired value,
1205 // because the longer of the two animations will only run for twelve frames
1206 // anyway (200 ms * 60 Hz), so at this point we'll have a maximum error of
1207 // less than a fifth of an animation frame, which the user isn't going to
1208 // notice.
1209 //
1210 // We have to use this method because Tween::CalculateValue() is not
1211 // necessarily easily invertible. Luckily, this only runs when the user
1212 // reverses the animation (rare), and the limit on how many iterations we'll
1213 // do ensures the cost is unnoticeable.
1214 double value = 0.5;
1215 double step = value / 2;
1216 do {
1217 calculated_offset = abs(gfx::Tween::IntValueBetween(
1218 gfx::Tween::CalculateValue(tween_type, value), start_offset,
1219 end_offset));
1220 if (calculated_offset < desired_offset)
1221 value += step;
1222 else if (calculated_offset > desired_offset)
1223 value -= step;
1224 step /= 2;
1225 } while ((calculated_offset != desired_offset) && (step >= (1.0 / 64)));
1226 return value;
1227 }
1228
1229 void LocationBarView::ResetShowAnimationAndColors() {
1230 show_url_animation_->Reset();
1231 omnibox_view_->UseDefaultSelectionTextColor();
1232 omnibox_view_->UseDefaultSelectionBackgroundColor();
1233 }
1234
1235 //////////////////////////////////////////////////////////////////////////////// 1028 ////////////////////////////////////////////////////////////////////////////////
1236 // LocationBarView, private LocationBar implementation: 1029 // LocationBarView, private LocationBar implementation:
1237 1030
1238 void LocationBarView::ShowFirstRunBubble() { 1031 void LocationBarView::ShowFirstRunBubble() {
1239 // Wait until search engines have loaded to show the first run bubble. 1032 // Wait until search engines have loaded to show the first run bubble.
1240 TemplateURLService* url_service = 1033 TemplateURLService* url_service =
1241 TemplateURLServiceFactory::GetForProfile(profile()); 1034 TemplateURLServiceFactory::GetForProfile(profile());
1242 if (!url_service->loaded()) { 1035 if (!url_service->loaded()) {
1243 template_url_service_ = url_service; 1036 template_url_service_ = url_service;
1244 template_url_service_->AddObserver(this); 1037 template_url_service_->AddObserver(this);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 SchedulePaint(); 1115 SchedulePaint();
1323 } 1116 }
1324 1117
1325 void LocationBarView::UpdateGeneratedCreditCardView() { 1118 void LocationBarView::UpdateGeneratedCreditCardView() {
1326 generated_credit_card_view_->Update(); 1119 generated_credit_card_view_->Update();
1327 Layout(); 1120 Layout();
1328 SchedulePaint(); 1121 SchedulePaint();
1329 } 1122 }
1330 1123
1331 void LocationBarView::SaveStateToContents(WebContents* contents) { 1124 void LocationBarView::SaveStateToContents(WebContents* contents) {
1332 // If we're about to switch tabs, complete any current animations, so that if
1333 // the user is in the midst of hiding the URL, when he returns to this tab,
1334 // the URL will be hidden rather than shown.
1335 // NOTE: This must be called before SaveStateToTab().
1336 EndOriginChipAnimations(true);
1337 omnibox_view_->SaveStateToTab(contents); 1125 omnibox_view_->SaveStateToTab(contents);
1338 } 1126 }
1339 1127
1340 const OmniboxView* LocationBarView::GetOmniboxView() const { 1128 const OmniboxView* LocationBarView::GetOmniboxView() const {
1341 return omnibox_view_; 1129 return omnibox_view_;
1342 } 1130 }
1343 1131
1344 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { 1132 LocationBarTesting* LocationBarView::GetLocationBarForTesting() {
1345 return this; 1133 return this;
1346 } 1134 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); 1234 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
1447 } 1235 }
1448 1236
1449 // The border itself will be drawn in PaintChildren() since it includes an 1237 // The border itself will be drawn in PaintChildren() since it includes an
1450 // inner shadow which should be drawn over the contents. 1238 // inner shadow which should be drawn over the contents.
1451 } 1239 }
1452 1240
1453 void LocationBarView::PaintChildren(gfx::Canvas* canvas, 1241 void LocationBarView::PaintChildren(gfx::Canvas* canvas,
1454 const views::CullSet& cull_set) { 1242 const views::CullSet& cull_set) {
1455 // Paint all the children except for the omnibox itself, which may need to be 1243 // Paint all the children except for the omnibox itself, which may need to be
1456 // clipped if it's animating in, and the origin chip and the search button, 1244 // clipped if it's animating in, and the search button, which will be painted
1457 // which will be painted after the border. 1245 // after the border.
1458 for (int i = 0, count = child_count(); i < count; ++i) { 1246 for (int i = 0, count = child_count(); i < count; ++i) {
1459 views::View* child = child_at(i); 1247 views::View* child = child_at(i);
1460 if (!child->layer() && (child != omnibox_view_) && 1248 if (!child->layer() && (child != omnibox_view_) &&
1461 (child != origin_chip_view_) && (child != search_button_)) 1249 (child != search_button_))
1462 child->Paint(canvas, cull_set); 1250 child->Paint(canvas, cull_set);
1463 } 1251 }
1464 1252
1465 { 1253 {
1466 gfx::ScopedCanvas scoped_canvas(canvas); 1254 gfx::ScopedCanvas scoped_canvas(canvas);
1467 if (show_url_animation_->is_animating() ||
1468 hide_url_animation_->is_animating()) {
1469 gfx::Rect clip_rect(omnibox_view_->bounds());
1470 clip_rect.Inset(current_omnibox_leading_inset_, 0, 0, 0);
1471 clip_rect.set_width(current_omnibox_width_);
1472 clip_rect.set_x(GetMirroredXForRect(clip_rect));
1473 canvas->ClipRect(clip_rect);
1474 }
1475 omnibox_view_->Paint(canvas, cull_set); 1255 omnibox_view_->Paint(canvas, cull_set);
1476 } 1256 }
1477 1257
1478 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need 1258 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need
1479 // the focus rect to appear on top of children we paint here rather than 1259 // the focus rect to appear on top of children we paint here rather than
1480 // OnPaint(). 1260 // OnPaint().
1481 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. 1261 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color.
1482 if (show_focus_rect_ && HasFocus()) 1262 if (show_focus_rect_ && HasFocus())
1483 canvas->DrawFocusRect(omnibox_view_->bounds()); 1263 canvas->DrawFocusRect(omnibox_view_->bounds());
1484 1264
1485 // Maximized popup windows don't draw the horizontal edges. We implement this 1265 // Maximized popup windows don't draw the horizontal edges. We implement this
1486 // by simply expanding the paint area outside the view by the edge thickness. 1266 // by simply expanding the paint area outside the view by the edge thickness.
1487 gfx::Rect border_rect(GetContentsBounds()); 1267 gfx::Rect border_rect(GetContentsBounds());
1488 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) 1268 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0))
1489 border_rect.Inset(-kPopupEdgeThickness, 0); 1269 border_rect.Inset(-kPopupEdgeThickness, 0);
1490 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect); 1270 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect);
1491 1271
1492 // The origin chip and the search button must be painted after the border so 1272 // The search button must be painted after the border so that the border
1493 // that the border shadow is not drawn over them. 1273 // shadow is not drawn over them.
1494 origin_chip_view_->Paint(canvas, cull_set);
1495 search_button_->Paint(canvas, cull_set); 1274 search_button_->Paint(canvas, cull_set);
1496 } 1275 }
1497 1276
1498 //////////////////////////////////////////////////////////////////////////////// 1277 ////////////////////////////////////////////////////////////////////////////////
1499 // LocationBarView, private views::ButtonListener implementation: 1278 // LocationBarView, private views::ButtonListener implementation:
1500 1279
1501 void LocationBarView::ButtonPressed(views::Button* sender, 1280 void LocationBarView::ButtonPressed(views::Button* sender,
1502 const ui::Event& event) { 1281 const ui::Event& event) {
1503 if (sender == mic_search_view_) { 1282 if (sender == mic_search_view_) {
1504 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); 1283 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT);
(...skipping 22 matching lines...) Expand all
1527 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), 1306 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(),
1528 web_contents->GetTitle(), 1307 web_contents->GetTitle(),
1529 favicon, 1308 favicon,
1530 NULL, 1309 NULL,
1531 data, 1310 data,
1532 sender->GetWidget()); 1311 sender->GetWidget());
1533 } 1312 }
1534 1313
1535 int LocationBarView::GetDragOperationsForView(views::View* sender, 1314 int LocationBarView::GetDragOperationsForView(views::View* sender,
1536 const gfx::Point& p) { 1315 const gfx::Point& p) {
1537 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_) || 1316 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_));
1538 (sender == origin_chip_view_));
1539 WebContents* web_contents = delegate_->GetWebContents(); 1317 WebContents* web_contents = delegate_->GetWebContents();
1540 return (web_contents && web_contents->GetURL().is_valid() && 1318 return (web_contents && web_contents->GetURL().is_valid() &&
1541 (!GetOmniboxView()->IsEditingOrEmpty() || 1319 (!GetOmniboxView()->IsEditingOrEmpty())) ?
1542 sender == origin_chip_view_)) ?
1543 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : 1320 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) :
1544 ui::DragDropTypes::DRAG_NONE; 1321 ui::DragDropTypes::DRAG_NONE;
1545 } 1322 }
1546 1323
1547 bool LocationBarView::CanStartDragForView(View* sender, 1324 bool LocationBarView::CanStartDragForView(View* sender,
1548 const gfx::Point& press_pt, 1325 const gfx::Point& press_pt,
1549 const gfx::Point& p) { 1326 const gfx::Point& p) {
1550 return true; 1327 return true;
1551 } 1328 }
1552 1329
(...skipping 10 matching lines...) Expand all
1563 chrome::GetDisplaySearchButtonConditions(); 1340 chrome::GetDisplaySearchButtonConditions();
1564 bool meets_conditions = 1341 bool meets_conditions =
1565 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) || 1342 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) ||
1566 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && 1343 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) &&
1567 (toolbar_model->WouldPerformSearchTermReplacement(true) || 1344 (toolbar_model->WouldPerformSearchTermReplacement(true) ||
1568 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && 1345 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) &&
1569 toolbar_model->input_in_progress()))); 1346 toolbar_model->input_in_progress())));
1570 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); 1347 search_button_->SetVisible(!is_popup_mode_ && meets_conditions);
1571 search_button_->UpdateIcon(icon_id == IDR_OMNIBOX_SEARCH); 1348 search_button_->UpdateIcon(icon_id == IDR_OMNIBOX_SEARCH);
1572 1349
1573 origin_chip_view_->OnChanged();
1574
1575 Layout(); 1350 Layout();
1576 SchedulePaint(); 1351 SchedulePaint();
1577 } 1352 }
1578 1353
1579 void LocationBarView::OnSetFocus() { 1354 void LocationBarView::OnSetFocus() {
1580 GetFocusManager()->SetFocusedView(this); 1355 GetFocusManager()->SetFocusedView(this);
1581 } 1356 }
1582 1357
1583 InstantController* LocationBarView::GetInstant() { 1358 InstantController* LocationBarView::GetInstant() {
1584 return delegate_->GetInstant(); 1359 return delegate_->GetInstant();
1585 } 1360 }
1586 1361
1587 const ToolbarModel* LocationBarView::GetToolbarModel() const { 1362 const ToolbarModel* LocationBarView::GetToolbarModel() const {
1588 return delegate_->GetToolbarModel(); 1363 return delegate_->GetToolbarModel();
1589 } 1364 }
1590 1365
1591 void LocationBarView::HideURL() {
1592 DCHECK(chrome::ShouldDisplayOriginChip());
1593
1594 // If we're currently showing, reverse the hide by swapping to the hide
1595 // animation, offset so that the text is in the same position.
1596 if (show_url_animation_->is_animating()) {
1597 const double hide_value = GetValueForAnimation(true);
1598 ResetShowAnimationAndColors();
1599 hide_url_animation_->Show();
1600 // This must be done after calling Show() and is not equivalent to Reset(n);
1601 // see comments in ShowURL().
1602 hide_url_animation_->SetCurrentValue(hide_value);
1603 } else {
1604 hide_url_animation_->Show();
1605 }
1606 }
1607
1608 //////////////////////////////////////////////////////////////////////////////// 1366 ////////////////////////////////////////////////////////////////////////////////
1609 // LocationBarView, private DropdownBarHostDelegate implementation: 1367 // LocationBarView, private DropdownBarHostDelegate implementation:
1610 1368
1611 void LocationBarView::SetFocusAndSelection(bool select_all) { 1369 void LocationBarView::SetFocusAndSelection(bool select_all) {
1612 FocusLocation(select_all); 1370 FocusLocation(select_all);
1613 } 1371 }
1614 1372
1615 void LocationBarView::SetAnimationOffset(int offset) { 1373 void LocationBarView::SetAnimationOffset(int offset) {
1616 dropdown_animation_offset_ = offset; 1374 dropdown_animation_offset_ = offset;
1617 } 1375 }
1618 1376
1619 //////////////////////////////////////////////////////////////////////////////// 1377 ////////////////////////////////////////////////////////////////////////////////
1620 // LocationBarView, private gfx::AnimationDelegate implementation:
1621
1622 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) {
1623 DCHECK((animation == show_url_animation_.get()) ||
1624 (animation == hide_url_animation_.get()));
1625 Layout();
1626 SchedulePaint();
1627 }
1628
1629 void LocationBarView::AnimationEnded(const gfx::Animation* animation) {
1630 if (animation == show_url_animation_.get()) {
1631 ResetShowAnimationAndColors();
1632 Layout();
1633 SchedulePaint();
1634 } else {
1635 DCHECK(animation == hide_url_animation_.get());
1636 hide_url_animation_->Reset();
1637 origin_chip_view_->FadeIn();
1638 omnibox_view_->HideURL(); // Calls OnChanged(), triggering layout.
1639 }
1640 }
1641
1642 ////////////////////////////////////////////////////////////////////////////////
1643 // LocationBarView, private TemplateURLServiceObserver implementation: 1378 // LocationBarView, private TemplateURLServiceObserver implementation:
1644 1379
1645 void LocationBarView::OnTemplateURLServiceChanged() { 1380 void LocationBarView::OnTemplateURLServiceChanged() {
1646 template_url_service_->RemoveObserver(this); 1381 template_url_service_->RemoveObserver(this);
1647 template_url_service_ = NULL; 1382 template_url_service_ = NULL;
1648 // If the browser is no longer active, let's not show the info bubble, as this 1383 // If the browser is no longer active, let's not show the info bubble, as this
1649 // would make the browser the active window again. 1384 // would make the browser the active window again.
1650 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1385 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1651 ShowFirstRunBubble(); 1386 ShowFirstRunBubble();
1652 } 1387 }
1653 1388
1654 //////////////////////////////////////////////////////////////////////////////// 1389 ////////////////////////////////////////////////////////////////////////////////
1655 // LocationBarView, private SearchModelObserver implementation: 1390 // LocationBarView, private SearchModelObserver implementation:
1656 1391
1657 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1392 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1658 const SearchModel::State& new_state) { 1393 const SearchModel::State& new_state) {
1659 const bool visible = !GetToolbarModel()->input_in_progress() && 1394 const bool visible = !GetToolbarModel()->input_in_progress() &&
1660 new_state.voice_search_supported; 1395 new_state.voice_search_supported;
1661 if (mic_search_view_->visible() != visible) { 1396 if (mic_search_view_->visible() != visible) {
1662 mic_search_view_->SetVisible(visible); 1397 mic_search_view_->SetVisible(visible);
1663 Layout(); 1398 Layout();
1664 } 1399 }
1665 } 1400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698