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

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

Issue 768413003: TEST ONLY - DO NOT SUBMIT - FOR TRYBOTS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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"
53 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 51 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
54 #include "chrome/browser/ui/views/location_bar/star_view.h" 52 #include "chrome/browser/ui/views/location_bar/star_view.h"
55 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" 53 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
56 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 54 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
57 #include "chrome/browser/ui/views/location_bar/zoom_view.h" 55 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
58 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" 56 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
59 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" 57 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
60 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" 58 #include "chrome/browser/ui/views/translate/translate_bubble_view.h"
61 #include "chrome/browser/ui/zoom/zoom_controller.h" 59 #include "chrome/browser/ui/zoom/zoom_controller.h"
62 #include "chrome/common/pref_names.h" 60 #include "chrome/common/pref_names.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 93
96 #if !defined(OS_CHROMEOS) 94 #if !defined(OS_CHROMEOS)
97 #include "chrome/browser/ui/views/first_run_bubble.h" 95 #include "chrome/browser/ui/views/first_run_bubble.h"
98 #endif 96 #endif
99 97
100 using content::WebContents; 98 using content::WebContents;
101 using views::View; 99 using views::View;
102 100
103 namespace { 101 namespace {
104 102
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
109 // images, but to align things, the search button needs to be inset horizontally
110 // by 1 px.
111 const int kSearchButtonInset = 1;
112
113 int GetEditLeadingInternalSpace() { 103 int GetEditLeadingInternalSpace() {
114 // The textfield has 1 px of whitespace before the text in the RTL case only. 104 // The textfield has 1 px of whitespace before the text in the RTL case only.
115 return base::i18n::IsRTL() ? 1 : 0; 105 return base::i18n::IsRTL() ? 1 : 0;
116 } 106 }
117 107
118 // Functor for moving BookmarkManagerPrivate page actions to the right via 108 // Functor for moving BookmarkManagerPrivate page actions to the right via
119 // stable_partition. 109 // stable_partition.
120 class IsPageActionViewRightAligned { 110 class IsPageActionViewRightAligned {
121 public: 111 public:
122 explicit IsPageActionViewRightAligned( 112 explicit IsPageActionViewRightAligned(
(...skipping 30 matching lines...) Expand all
153 LocationBarView::LocationBarView(Browser* browser, 143 LocationBarView::LocationBarView(Browser* browser,
154 Profile* profile, 144 Profile* profile,
155 CommandUpdater* command_updater, 145 CommandUpdater* command_updater,
156 Delegate* delegate, 146 Delegate* delegate,
157 bool is_popup_mode) 147 bool is_popup_mode)
158 : LocationBar(profile), 148 : LocationBar(profile),
159 OmniboxEditController(command_updater), 149 OmniboxEditController(command_updater),
160 browser_(browser), 150 browser_(browser),
161 omnibox_view_(NULL), 151 omnibox_view_(NULL),
162 delegate_(delegate), 152 delegate_(delegate),
163 origin_chip_view_(NULL),
164 location_icon_view_(NULL), 153 location_icon_view_(NULL),
165 ev_bubble_view_(NULL), 154 ev_bubble_view_(NULL),
166 ime_inline_autocomplete_view_(NULL), 155 ime_inline_autocomplete_view_(NULL),
167 selected_keyword_view_(NULL), 156 selected_keyword_view_(NULL),
168 suggested_text_view_(NULL), 157 suggested_text_view_(NULL),
169 keyword_hint_view_(NULL), 158 keyword_hint_view_(NULL),
170 mic_search_view_(NULL), 159 mic_search_view_(NULL),
171 zoom_view_(NULL), 160 zoom_view_(NULL),
172 generated_credit_card_view_(NULL), 161 generated_credit_card_view_(NULL),
173 open_pdf_in_reader_view_(NULL), 162 open_pdf_in_reader_view_(NULL),
174 manage_passwords_icon_view_(NULL), 163 manage_passwords_icon_view_(NULL),
175 translate_icon_view_(NULL), 164 translate_icon_view_(NULL),
176 star_view_(NULL), 165 star_view_(NULL),
177 search_button_(NULL),
178 is_popup_mode_(is_popup_mode), 166 is_popup_mode_(is_popup_mode),
179 show_focus_rect_(false), 167 show_focus_rect_(false),
180 template_url_service_(NULL), 168 template_url_service_(NULL),
181 dropdown_animation_offset_(0), 169 dropdown_animation_offset_(0) {
182 starting_omnibox_offset_(0),
183 current_omnibox_offset_(0),
184 starting_omnibox_leading_inset_(0),
185 current_omnibox_leading_inset_(0),
186 current_omnibox_width_(0),
187 ending_omnibox_width_(0) {
188 edit_bookmarks_enabled_.Init( 170 edit_bookmarks_enabled_.Init(
189 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 171 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
190 base::Bind(&LocationBarView::Update, base::Unretained(this), 172 base::Bind(&LocationBarView::Update, base::Unretained(this),
191 static_cast<content::WebContents*>(NULL))); 173 static_cast<content::WebContents*>(NULL)));
192 174
193 if (browser_) 175 if (browser_)
194 browser_->search_model()->AddObserver(this); 176 browser_->search_model()->AddObserver(this);
195 } 177 }
196 178
197 LocationBarView::~LocationBarView() { 179 LocationBarView::~LocationBarView() {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); 249 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false);
268 ime_inline_autocomplete_view_->set_background( 250 ime_inline_autocomplete_view_->set_background(
269 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( 251 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
270 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); 252 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)));
271 ime_inline_autocomplete_view_->SetEnabledColor( 253 ime_inline_autocomplete_view_->SetEnabledColor(
272 GetNativeTheme()->GetSystemColor( 254 GetNativeTheme()->GetSystemColor(
273 ui::NativeTheme::kColorId_TextfieldSelectionColor)); 255 ui::NativeTheme::kColorId_TextfieldSelectionColor));
274 ime_inline_autocomplete_view_->SetVisible(false); 256 ime_inline_autocomplete_view_->SetVisible(false);
275 AddChildView(ime_inline_autocomplete_view_); 257 AddChildView(ime_inline_autocomplete_view_);
276 258
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); 259 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT);
283 selected_keyword_view_ = new SelectedKeywordView( 260 selected_keyword_view_ = new SelectedKeywordView(
284 bubble_font_list, text_color, background_color, profile()); 261 bubble_font_list, text_color, background_color, profile());
285 AddChildView(selected_keyword_view_); 262 AddChildView(selected_keyword_view_);
286 263
287 suggested_text_view_ = new views::Label(base::string16(), font_list); 264 suggested_text_view_ = new views::Label(base::string16(), font_list);
288 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 265 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
289 suggested_text_view_->SetAutoColorReadabilityEnabled(false); 266 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
290 suggested_text_view_->SetEnabledColor(GetColor( 267 suggested_text_view_->SetEnabledColor(GetColor(
291 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); 268 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 AddChildView(manage_passwords_icon_view_); 312 AddChildView(manage_passwords_icon_view_);
336 313
337 translate_icon_view_ = new TranslateIconView(command_updater()); 314 translate_icon_view_ = new TranslateIconView(command_updater());
338 translate_icon_view_->SetVisible(false); 315 translate_icon_view_->SetVisible(false);
339 AddChildView(translate_icon_view_); 316 AddChildView(translate_icon_view_);
340 317
341 star_view_ = new StarView(command_updater()); 318 star_view_ = new StarView(command_updater());
342 star_view_->SetVisible(false); 319 star_view_->SetVisible(false);
343 AddChildView(star_view_); 320 AddChildView(star_view_);
344 321
345 search_button_ = new SearchButton(this);
346 search_button_->SetVisible(false);
347 AddChildView(search_button_);
348
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 322 // Initialize the location entry. We do this to avoid a black flash which is
358 // visible when the location entry has just been initialized. 323 // visible when the location entry has just been initialized.
359 Update(NULL); 324 Update(NULL);
360 } 325 }
361 326
362 bool LocationBarView::IsInitialized() const { 327 bool LocationBarView::IsInitialized() const {
363 return omnibox_view_ != NULL; 328 return omnibox_view_ != NULL;
364 } 329 }
365 330
366 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, 331 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 if (star_view_) 429 if (star_view_)
465 star_view_->SetToggled(on); 430 star_view_->SetToggled(on);
466 } 431 }
467 432
468 void LocationBarView::SetTranslateIconToggled(bool on) { 433 void LocationBarView::SetTranslateIconToggled(bool on) {
469 translate_icon_view_->SetToggled(on); 434 translate_icon_view_->SetToggled(on);
470 } 435 }
471 436
472 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { 437 gfx::Point LocationBarView::GetOmniboxViewOrigin() const {
473 gfx::Point origin(omnibox_view_->bounds().origin()); 438 gfx::Point origin(omnibox_view_->bounds().origin());
474 origin.set_x(GetMirroredXInView(origin.x() - current_omnibox_offset_)); 439 origin.set_x(GetMirroredXInView(origin.x()));
475 views::View::ConvertPointToScreen(this, &origin); 440 views::View::ConvertPointToScreen(this, &origin);
476 return origin; 441 return origin;
477 } 442 }
478 443
479 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { 444 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) {
480 ime_inline_autocomplete_view_->SetText(text); 445 ime_inline_autocomplete_view_->SetText(text);
481 ime_inline_autocomplete_view_->SetVisible(!text.empty()); 446 ime_inline_autocomplete_view_->SetVisible(!text.empty());
482 } 447 }
483 448
484 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { 449 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 537
573 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { 538 void LocationBarView::GetAccessibleState(ui::AXViewState* state) {
574 state->role = ui::AX_ROLE_GROUP; 539 state->role = ui::AX_ROLE_GROUP;
575 } 540 }
576 541
577 gfx::Size LocationBarView::GetPreferredSize() const { 542 gfx::Size LocationBarView::GetPreferredSize() const {
578 // Compute minimum height. 543 // Compute minimum height.
579 gfx::Size min_size(border_painter_->GetMinimumSize()); 544 gfx::Size min_size(border_painter_->GetMinimumSize());
580 if (!IsInitialized()) 545 if (!IsInitialized())
581 return min_size; 546 return min_size;
582 gfx::Size search_button_min_size(search_button_->GetMinimumSize());
583 min_size.SetToMax(search_button_min_size);
584 547
585 // Compute width of omnibox-leading content. 548 // Compute width of omnibox-leading content.
586 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); 549 const int horizontal_edge_thickness = GetHorizontalEdgeThickness();
587 int leading_width = horizontal_edge_thickness; 550 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()) { 551 if (ShouldShowKeywordBubble()) {
593 // The selected keyword view can collapse completely. 552 // The selected keyword view can collapse completely.
594 } else if (ShouldShowEVBubble()) { 553 } else if (ShouldShowEVBubble()) {
595 leading_width += kBubblePadding + 554 leading_width += kBubblePadding +
596 ev_bubble_view_->GetMinimumSizeForLabelText( 555 ev_bubble_view_->GetMinimumSizeForLabelText(
597 GetToolbarModel()->GetEVCertName()).width(); 556 GetToolbarModel()->GetEVCertName()).width();
598 } else if (!origin_chip_view_->visible()) { 557 } else {
599 leading_width += 558 leading_width +=
600 kItemPadding + location_icon_view_->GetMinimumSize().width(); 559 kItemPadding + location_icon_view_->GetMinimumSize().width();
601 } 560 }
602 561
603 // Compute width of omnibox-trailing content. 562 // Compute width of omnibox-trailing content.
604 int trailing_width = search_button_->visible() ? 563 int trailing_width = horizontal_edge_thickness;
605 (search_button_->GetMinimumSize().width() + kSearchButtonInset) :
606 horizontal_edge_thickness;
607 trailing_width += IncrementalMinimumWidth(star_view_) + 564 trailing_width += IncrementalMinimumWidth(star_view_) +
608 IncrementalMinimumWidth(translate_icon_view_) + 565 IncrementalMinimumWidth(translate_icon_view_) +
609 IncrementalMinimumWidth(open_pdf_in_reader_view_) + 566 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
610 IncrementalMinimumWidth(manage_passwords_icon_view_) + 567 IncrementalMinimumWidth(manage_passwords_icon_view_) +
611 IncrementalMinimumWidth(zoom_view_) + 568 IncrementalMinimumWidth(zoom_view_) +
612 IncrementalMinimumWidth(generated_credit_card_view_) + 569 IncrementalMinimumWidth(generated_credit_card_view_) +
613 IncrementalMinimumWidth(mic_search_view_); 570 IncrementalMinimumWidth(mic_search_view_);
614 for (PageActionViews::const_iterator i(page_action_views_.begin()); 571 for (PageActionViews::const_iterator i(page_action_views_.begin());
615 i != page_action_views_.end(); ++i) 572 i != page_action_views_.end(); ++i)
616 trailing_width += IncrementalMinimumWidth((*i)); 573 trailing_width += IncrementalMinimumWidth((*i));
617 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 574 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
618 i != content_setting_views_.end(); ++i) 575 i != content_setting_views_.end(); ++i)
619 trailing_width += IncrementalMinimumWidth((*i)); 576 trailing_width += IncrementalMinimumWidth((*i));
620 577
621 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + 578 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() +
622 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width); 579 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width);
623 return min_size; 580 return min_size;
624 } 581 }
625 582
626 void LocationBarView::Layout() { 583 void LocationBarView::Layout() {
627 if (!IsInitialized()) 584 if (!IsInitialized())
628 return; 585 return;
629 586
630 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip());
631 selected_keyword_view_->SetVisible(false); 587 selected_keyword_view_->SetVisible(false);
632 location_icon_view_->SetVisible(false); 588 location_icon_view_->SetVisible(false);
633 ev_bubble_view_->SetVisible(false); 589 ev_bubble_view_->SetVisible(false);
634 keyword_hint_view_->SetVisible(false); 590 keyword_hint_view_->SetVisible(false);
635 591
636 LocationBarLayout leading_decorations( 592 LocationBarLayout leading_decorations(
637 LocationBarLayout::LEFT_EDGE, 593 LocationBarLayout::LEFT_EDGE,
638 kItemPadding - omnibox_view_->GetInsets().left() - 594 kItemPadding - omnibox_view_->GetInsets().left() -
639 GetEditLeadingInternalSpace()); 595 GetEditLeadingInternalSpace());
640 LocationBarLayout trailing_decorations( 596 LocationBarLayout trailing_decorations(
641 LocationBarLayout::RIGHT_EDGE, 597 LocationBarLayout::RIGHT_EDGE,
642 kItemPadding - omnibox_view_->GetInsets().right()); 598 kItemPadding - omnibox_view_->GetInsets().right());
643 599
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; 600 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding;
655 const base::string16 keyword(omnibox_view_->model()->keyword()); 601 const base::string16 keyword(omnibox_view_->model()->keyword());
656 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 602 // 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 603 // 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 604 // positioned relative to them (e.g. the "bookmark added" bubble if the user
659 // hits ctrl-d). 605 // hits ctrl-d).
660 const int location_height = GetInternalHeight(false); 606 const int location_height = GetInternalHeight(false);
661 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); 607 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0);
662 if (ShouldShowKeywordBubble()) { 608 if (ShouldShowKeywordBubble()) {
663 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0, 609 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); 626 selected_keyword_view_->set_is_extension_icon(false);
681 } 627 }
682 } 628 }
683 } else if (ShouldShowEVBubble()) { 629 } else if (ShouldShowEVBubble()) {
684 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); 630 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName());
685 // The largest fraction of the omnibox that can be taken by the EV bubble. 631 // The largest fraction of the omnibox that can be taken by the EV bubble.
686 const double kMaxBubbleFraction = 0.5; 632 const double kMaxBubbleFraction = 0.5;
687 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, 633 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false,
688 kMaxBubbleFraction, kBubblePadding, 634 kMaxBubbleFraction, kBubblePadding,
689 kItemPadding, ev_bubble_view_); 635 kItemPadding, ev_bubble_view_);
690 } else if (!origin_chip_view_->visible()) { 636 } else {
691 leading_decorations.AddDecoration( 637 leading_decorations.AddDecoration(
692 vertical_edge_thickness(), location_height, 638 vertical_edge_thickness(), location_height,
693 location_icon_view_); 639 location_icon_view_);
694 } 640 }
695 641
696 if (star_view_->visible()) { 642 if (star_view_->visible()) {
697 trailing_decorations.AddDecoration( 643 trailing_decorations.AddDecoration(
698 vertical_edge_thickness(), location_height, star_view_); 644 vertical_edge_thickness(), location_height, star_view_);
699 } 645 }
700 if (translate_icon_view_->visible()) { 646 if (translate_icon_view_->visible()) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 !omnibox_view_->IsImeComposing()) { 691 !omnibox_view_->IsImeComposing()) {
746 trailing_decorations.AddDecoration(vertical_edge_thickness(), 692 trailing_decorations.AddDecoration(vertical_edge_thickness(),
747 location_height, true, 0, kItemPadding, 693 location_height, true, 0, kItemPadding,
748 kItemPadding, keyword_hint_view_); 694 kItemPadding, keyword_hint_view_);
749 if (keyword_hint_view_->keyword() != keyword) 695 if (keyword_hint_view_->keyword() != keyword)
750 keyword_hint_view_->SetKeyword(keyword); 696 keyword_hint_view_->SetKeyword(keyword);
751 } 697 }
752 698
753 // Perform layout. 699 // Perform layout.
754 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); 700 const int horizontal_edge_thickness = GetHorizontalEdgeThickness();
755 int full_width = width() - horizontal_edge_thickness - origin_chip_width; 701 int full_width = width() - horizontal_edge_thickness;
756 702
757 const gfx::Size search_button_size(search_button_->GetPreferredSize()); 703 full_width -= horizontal_edge_thickness;
758 const int search_button_reserved_width =
759 search_button_size.width() + kSearchButtonInset;
760 full_width -= search_button_->visible() ?
761 search_button_reserved_width : horizontal_edge_thickness;
762 int entry_width = full_width; 704 int entry_width = full_width;
763 leading_decorations.LayoutPass1(&entry_width); 705 leading_decorations.LayoutPass1(&entry_width);
764 trailing_decorations.LayoutPass1(&entry_width); 706 trailing_decorations.LayoutPass1(&entry_width);
765 leading_decorations.LayoutPass2(&entry_width); 707 leading_decorations.LayoutPass2(&entry_width);
766 trailing_decorations.LayoutPass2(&entry_width); 708 trailing_decorations.LayoutPass2(&entry_width);
767 709
768 int location_needed_width = omnibox_view_->GetTextWidth(); 710 int location_needed_width = omnibox_view_->GetTextWidth();
769 int available_width = entry_width - location_needed_width; 711 int available_width = entry_width - location_needed_width;
770 // The bounds must be wide enough for all the decorations to fit. 712 // The bounds must be wide enough for all the decorations to fit.
771 gfx::Rect location_bounds( 713 gfx::Rect location_bounds(
772 origin_chip_width + horizontal_edge_thickness, vertical_edge_thickness(), 714 horizontal_edge_thickness, vertical_edge_thickness(),
773 std::max(full_width, full_width - entry_width), location_height); 715 std::max(full_width, full_width - entry_width), location_height);
774 leading_decorations.LayoutPass3(&location_bounds, &available_width); 716 leading_decorations.LayoutPass3(&location_bounds, &available_width);
775 trailing_decorations.LayoutPass3(&location_bounds, &available_width); 717 trailing_decorations.LayoutPass3(&location_bounds, &available_width);
776 718
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 719 // 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 720 // 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 721 // 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, 722 // suggested text. If we can't it means either the suggested text is too big,
884 // or the user has scrolled. 723 // or the user has scrolled.
885 724
886 // TODO(sky): We could potentially adjust this to take into account suggested 725 // 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 726 // 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 727 // showing keyword hints and suggested text is minimal and we're not confident
889 // this is the right approach for suggested text. 728 // this is the right approach for suggested text.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 x = 0; 787 x = 0;
949 else if (location_needed_width + width > entry_width) 788 else if (location_needed_width + width > entry_width)
950 x = entry_width - width; 789 x = entry_width - width;
951 location_bounds.set_width(x); 790 location_bounds.set_width(x);
952 ime_inline_autocomplete_view_->SetBounds( 791 ime_inline_autocomplete_view_->SetBounds(
953 location_bounds.right(), location_bounds.y(), 792 location_bounds.right(), location_bounds.y(),
954 std::min(width, entry_width), location_bounds.height()); 793 std::min(width, entry_width), location_bounds.height());
955 } 794 }
956 795
957 omnibox_view_->SetBoundsRect(location_bounds); 796 omnibox_view_->SetBoundsRect(location_bounds);
958
959 search_button_->SetBoundsRect(gfx::Rect(
960 gfx::Point(width() - search_button_reserved_width, 0),
961 search_button_size));
962 } 797 }
963 798
964 //////////////////////////////////////////////////////////////////////////////// 799 ////////////////////////////////////////////////////////////////////////////////
965 // LocationBarView, public OmniboxEditController implementation: 800 // LocationBarView, public OmniboxEditController implementation:
966 801
967 void LocationBarView::Update(const WebContents* contents) { 802 void LocationBarView::Update(const WebContents* contents) {
968 mic_search_view_->SetVisible( 803 mic_search_view_->SetVisible(
969 !GetToolbarModel()->input_in_progress() && browser_ && 804 !GetToolbarModel()->input_in_progress() && browser_ &&
970 browser_->search_model()->voice_search_supported()); 805 browser_->search_model()->voice_search_supported());
971 RefreshContentSettingViews(); 806 RefreshContentSettingViews();
(...skipping 15 matching lines...) Expand all
987 omnibox_view_->Update(); 822 omnibox_view_->Update();
988 823
989 OnChanged(); // NOTE: Calls Layout(). 824 OnChanged(); // NOTE: Calls Layout().
990 } 825 }
991 826
992 void LocationBarView::ResetTabState(WebContents* contents) { 827 void LocationBarView::ResetTabState(WebContents* contents) {
993 omnibox_view_->ResetTabState(contents); 828 omnibox_view_->ResetTabState(contents);
994 } 829 }
995 830
996 void LocationBarView::ShowURL() { 831 void LocationBarView::ShowURL() {
997 // Start the animation before calling ShowURL(), since the latter eventually
998 // calls back to Layout(), and if the animation is not marked as "running",
999 // we'll draw the omnibox in its final position briefly until the first
1000 // animation callback reaches us.
1001 if (chrome::ShouldDisplayOriginChip()) {
1002 // If we're currently hiding, reverse the hide by swapping to the show
1003 // animation, offset so that the text is in the same position.
1004 if (hide_url_animation_->is_animating()) {
1005 const double show_value = GetValueForAnimation(false);
1006 hide_url_animation_->Reset();
1007 show_url_animation_->Show();
1008 // This must be done after calling Show() and is not equivalent to
1009 // calling Reset(n) before Show(); Reset() would have caused the entire
1010 // animation curve (and time) to run between this value and the final
1011 // value, whereas Show() + SetCurrentValue() skips the animation forward
1012 // to the supplied value.
1013 show_url_animation_->SetCurrentValue(show_value);
1014 } else {
1015 show_url_animation_->Show();
1016 }
1017 }
1018 omnibox_view_->ShowURL(); 832 omnibox_view_->ShowURL();
1019 } 833 }
1020 834
1021 void LocationBarView::EndOriginChipAnimations(bool cancel_fade) {
1022 show_url_animation_->End();
1023 hide_url_animation_->End();
1024 if (cancel_fade)
1025 origin_chip_view_->CancelFade();
1026 }
1027
1028 ToolbarModel* LocationBarView::GetToolbarModel() { 835 ToolbarModel* LocationBarView::GetToolbarModel() {
1029 return delegate_->GetToolbarModel(); 836 return delegate_->GetToolbarModel();
1030 } 837 }
1031 838
1032 WebContents* LocationBarView::GetWebContents() { 839 WebContents* LocationBarView::GetWebContents() {
1033 return delegate_->GetWebContents(); 840 return delegate_->GetWebContents();
1034 } 841 }
1035 842
1036 //////////////////////////////////////////////////////////////////////////////// 843 ////////////////////////////////////////////////////////////////////////////////
1037 // LocationBarView, private: 844 // LocationBarView, private:
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 return suggested_text_view_->visible() && 995 return suggested_text_view_->visible() &&
1189 !suggested_text_view_->size().IsEmpty(); 996 !suggested_text_view_->size().IsEmpty();
1190 } 997 }
1191 998
1192 bool LocationBarView::ShouldShowKeywordBubble() const { 999 bool LocationBarView::ShouldShowKeywordBubble() const {
1193 return !omnibox_view_->model()->keyword().empty() && 1000 return !omnibox_view_->model()->keyword().empty() &&
1194 !omnibox_view_->model()->is_keyword_hint(); 1001 !omnibox_view_->model()->is_keyword_hint();
1195 } 1002 }
1196 1003
1197 bool LocationBarView::ShouldShowEVBubble() const { 1004 bool LocationBarView::ShouldShowEVBubble() const {
1198 return !chrome::ShouldDisplayOriginChip() && 1005 return
1199 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); 1006 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE);
1200 } 1007 }
1201 1008
1202 double LocationBarView::GetValueForAnimation(bool hide) const {
1203 int calculated_offset;
1204 const gfx::Tween::Type tween_type = hide ? kHideTweenType : kShowTweenType;
1205 int start_offset = starting_omnibox_offset_, end_offset = 0;
1206 if (hide)
1207 std::swap(start_offset, end_offset);
1208 const int desired_offset = abs(current_omnibox_offset_);
1209 // Binary-search the value space (0 <= value <= 1) to find the appropriate
1210 // position. We only bother to iterate to within 1/64 of the desired value,
1211 // because the longer of the two animations will only run for twelve frames
1212 // anyway (200 ms * 60 Hz), so at this point we'll have a maximum error of
1213 // less than a fifth of an animation frame, which the user isn't going to
1214 // notice.
1215 //
1216 // We have to use this method because Tween::CalculateValue() is not
1217 // necessarily easily invertible. Luckily, this only runs when the user
1218 // reverses the animation (rare), and the limit on how many iterations we'll
1219 // do ensures the cost is unnoticeable.
1220 double value = 0.5;
1221 double step = value / 2;
1222 do {
1223 calculated_offset = abs(gfx::Tween::IntValueBetween(
1224 gfx::Tween::CalculateValue(tween_type, value), start_offset,
1225 end_offset));
1226 if (calculated_offset < desired_offset)
1227 value += step;
1228 else if (calculated_offset > desired_offset)
1229 value -= step;
1230 step /= 2;
1231 } while ((calculated_offset != desired_offset) && (step >= (1.0 / 64)));
1232 return value;
1233 }
1234
1235 void LocationBarView::ResetShowAnimationAndColors() {
1236 show_url_animation_->Reset();
1237 omnibox_view_->UseDefaultSelectionTextColor();
1238 omnibox_view_->UseDefaultSelectionBackgroundColor();
1239 }
1240
1241 //////////////////////////////////////////////////////////////////////////////// 1009 ////////////////////////////////////////////////////////////////////////////////
1242 // LocationBarView, private LocationBar implementation: 1010 // LocationBarView, private LocationBar implementation:
1243 1011
1244 void LocationBarView::ShowFirstRunBubble() { 1012 void LocationBarView::ShowFirstRunBubble() {
1245 // Wait until search engines have loaded to show the first run bubble. 1013 // Wait until search engines have loaded to show the first run bubble.
1246 TemplateURLService* url_service = 1014 TemplateURLService* url_service =
1247 TemplateURLServiceFactory::GetForProfile(profile()); 1015 TemplateURLServiceFactory::GetForProfile(profile());
1248 if (!url_service->loaded()) { 1016 if (!url_service->loaded()) {
1249 template_url_service_ = url_service; 1017 template_url_service_ = url_service;
1250 template_url_service_->AddObserver(this); 1018 template_url_service_->AddObserver(this);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 SchedulePaint(); 1096 SchedulePaint();
1329 } 1097 }
1330 1098
1331 void LocationBarView::UpdateGeneratedCreditCardView() { 1099 void LocationBarView::UpdateGeneratedCreditCardView() {
1332 generated_credit_card_view_->Update(); 1100 generated_credit_card_view_->Update();
1333 Layout(); 1101 Layout();
1334 SchedulePaint(); 1102 SchedulePaint();
1335 } 1103 }
1336 1104
1337 void LocationBarView::SaveStateToContents(WebContents* contents) { 1105 void LocationBarView::SaveStateToContents(WebContents* contents) {
1338 // If we're about to switch tabs, complete any current animations, so that if
1339 // the user is in the midst of hiding the URL, when he returns to this tab,
1340 // the URL will be hidden rather than shown.
1341 // NOTE: This must be called before SaveStateToTab().
1342 EndOriginChipAnimations(true);
1343 omnibox_view_->SaveStateToTab(contents); 1106 omnibox_view_->SaveStateToTab(contents);
1344 } 1107 }
1345 1108
1346 const OmniboxView* LocationBarView::GetOmniboxView() const { 1109 const OmniboxView* LocationBarView::GetOmniboxView() const {
1347 return omnibox_view_; 1110 return omnibox_view_;
1348 } 1111 }
1349 1112
1350 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { 1113 LocationBarTesting* LocationBarView::GetLocationBarForTesting() {
1351 return this; 1114 return this;
1352 } 1115 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); 1215 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
1453 } 1216 }
1454 1217
1455 // The border itself will be drawn in PaintChildren() since it includes an 1218 // The border itself will be drawn in PaintChildren() since it includes an
1456 // inner shadow which should be drawn over the contents. 1219 // inner shadow which should be drawn over the contents.
1457 } 1220 }
1458 1221
1459 void LocationBarView::PaintChildren(gfx::Canvas* canvas, 1222 void LocationBarView::PaintChildren(gfx::Canvas* canvas,
1460 const views::CullSet& cull_set) { 1223 const views::CullSet& cull_set) {
1461 // Paint all the children except for the omnibox itself, which may need to be 1224 // Paint all the children except for the omnibox itself, which may need to be
1462 // clipped if it's animating in, and the origin chip and the search button, 1225 // clipped if it's animating in.
1463 // which will be painted after the border.
1464 for (int i = 0, count = child_count(); i < count; ++i) { 1226 for (int i = 0, count = child_count(); i < count; ++i) {
1465 views::View* child = child_at(i); 1227 views::View* child = child_at(i);
1466 if (!child->layer() && (child != omnibox_view_) && 1228 if (!child->layer() && (child != omnibox_view_))
1467 (child != origin_chip_view_) && (child != search_button_))
1468 child->Paint(canvas, cull_set); 1229 child->Paint(canvas, cull_set);
1469 } 1230 }
1470 1231
1471 { 1232 {
1472 gfx::ScopedCanvas scoped_canvas(canvas); 1233 gfx::ScopedCanvas scoped_canvas(canvas);
1473 if (show_url_animation_->is_animating() ||
1474 hide_url_animation_->is_animating()) {
1475 gfx::Rect clip_rect(omnibox_view_->bounds());
1476 clip_rect.Inset(current_omnibox_leading_inset_, 0, 0, 0);
1477 clip_rect.set_width(current_omnibox_width_);
1478 clip_rect.set_x(GetMirroredXForRect(clip_rect));
1479 canvas->ClipRect(clip_rect);
1480 }
1481 omnibox_view_->Paint(canvas, cull_set); 1234 omnibox_view_->Paint(canvas, cull_set);
1482 } 1235 }
1483 1236
1484 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need 1237 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need
1485 // the focus rect to appear on top of children we paint here rather than 1238 // the focus rect to appear on top of children we paint here rather than
1486 // OnPaint(). 1239 // OnPaint().
1487 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. 1240 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color.
1488 if (show_focus_rect_ && HasFocus()) 1241 if (show_focus_rect_ && HasFocus())
1489 canvas->DrawFocusRect(omnibox_view_->bounds()); 1242 canvas->DrawFocusRect(omnibox_view_->bounds());
1490 1243
1491 // Maximized popup windows don't draw the horizontal edges. We implement this 1244 // Maximized popup windows don't draw the horizontal edges. We implement this
1492 // by simply expanding the paint area outside the view by the edge thickness. 1245 // by simply expanding the paint area outside the view by the edge thickness.
1493 gfx::Rect border_rect(GetContentsBounds()); 1246 gfx::Rect border_rect(GetContentsBounds());
1494 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) 1247 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0))
1495 border_rect.Inset(-kPopupEdgeThickness, 0); 1248 border_rect.Inset(-kPopupEdgeThickness, 0);
1496 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect); 1249 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect);
1497
1498 // The origin chip and the search button must be painted after the border so
1499 // that the border shadow is not drawn over them.
1500 origin_chip_view_->Paint(canvas, cull_set);
1501 search_button_->Paint(canvas, cull_set);
1502 } 1250 }
1503 1251
1504 //////////////////////////////////////////////////////////////////////////////// 1252 ////////////////////////////////////////////////////////////////////////////////
1505 // LocationBarView, private views::ButtonListener implementation: 1253 // LocationBarView, private views::ButtonListener implementation:
1506 1254
1507 void LocationBarView::ButtonPressed(views::Button* sender, 1255 void LocationBarView::ButtonPressed(views::Button* sender,
1508 const ui::Event& event) { 1256 const ui::Event& event) {
1509 if (sender == mic_search_view_) { 1257 DCHECK_EQ(mic_search_view_, sender);
1510 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); 1258 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT);
1511 return;
1512 }
1513
1514 DCHECK_EQ(search_button_, sender);
1515 // TODO(pkasting): When macourteau adds UMA stats for this, wire them up here.
1516 omnibox_view_->model()->AcceptInput(
1517 ui::DispositionFromEventFlags(event.flags()), false);
1518 } 1259 }
1519 1260
1520 //////////////////////////////////////////////////////////////////////////////// 1261 ////////////////////////////////////////////////////////////////////////////////
1521 // LocationBarView, private views::DragController implementation: 1262 // LocationBarView, private views::DragController implementation:
1522 1263
1523 void LocationBarView::WriteDragDataForView(views::View* sender, 1264 void LocationBarView::WriteDragDataForView(views::View* sender,
1524 const gfx::Point& press_pt, 1265 const gfx::Point& press_pt,
1525 OSExchangeData* data) { 1266 OSExchangeData* data) {
1526 DCHECK_NE(GetDragOperationsForView(sender, press_pt), 1267 DCHECK_NE(GetDragOperationsForView(sender, press_pt),
1527 ui::DragDropTypes::DRAG_NONE); 1268 ui::DragDropTypes::DRAG_NONE);
1528 1269
1529 WebContents* web_contents = GetWebContents(); 1270 WebContents* web_contents = GetWebContents();
1530 FaviconTabHelper* favicon_tab_helper = 1271 FaviconTabHelper* favicon_tab_helper =
1531 FaviconTabHelper::FromWebContents(web_contents); 1272 FaviconTabHelper::FromWebContents(web_contents);
1532 gfx::ImageSkia favicon = favicon_tab_helper->GetFavicon().AsImageSkia(); 1273 gfx::ImageSkia favicon = favicon_tab_helper->GetFavicon().AsImageSkia();
1533 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), 1274 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(),
1534 web_contents->GetTitle(), 1275 web_contents->GetTitle(),
1535 favicon, 1276 favicon,
1536 NULL, 1277 NULL,
1537 data, 1278 data,
1538 sender->GetWidget()); 1279 sender->GetWidget());
1539 } 1280 }
1540 1281
1541 int LocationBarView::GetDragOperationsForView(views::View* sender, 1282 int LocationBarView::GetDragOperationsForView(views::View* sender,
1542 const gfx::Point& p) { 1283 const gfx::Point& p) {
1543 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_) || 1284 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_));
1544 (sender == origin_chip_view_));
1545 WebContents* web_contents = delegate_->GetWebContents(); 1285 WebContents* web_contents = delegate_->GetWebContents();
1546 return (web_contents && web_contents->GetURL().is_valid() && 1286 return (web_contents && web_contents->GetURL().is_valid() &&
1547 (!GetOmniboxView()->IsEditingOrEmpty() || 1287 (!GetOmniboxView()->IsEditingOrEmpty())) ?
1548 sender == origin_chip_view_)) ?
1549 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : 1288 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) :
1550 ui::DragDropTypes::DRAG_NONE; 1289 ui::DragDropTypes::DRAG_NONE;
1551 } 1290 }
1552 1291
1553 bool LocationBarView::CanStartDragForView(View* sender, 1292 bool LocationBarView::CanStartDragForView(View* sender,
1554 const gfx::Point& press_pt, 1293 const gfx::Point& press_pt,
1555 const gfx::Point& p) { 1294 const gfx::Point& p) {
1556 return true; 1295 return true;
1557 } 1296 }
1558 1297
1559 //////////////////////////////////////////////////////////////////////////////// 1298 ////////////////////////////////////////////////////////////////////////////////
1560 // LocationBarView, private OmniboxEditController implementation: 1299 // LocationBarView, private OmniboxEditController implementation:
1561 1300
1562 void LocationBarView::OnChanged() { 1301 void LocationBarView::OnChanged() {
1563 int icon_id = omnibox_view_->GetIcon(); 1302 int icon_id = omnibox_view_->GetIcon();
1564 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon_id)); 1303 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon_id));
1565 location_icon_view_->ShowTooltip(!GetOmniboxView()->IsEditingOrEmpty()); 1304 location_icon_view_->ShowTooltip(!GetOmniboxView()->IsEditingOrEmpty());
1566 1305
1567 ToolbarModel* toolbar_model = GetToolbarModel();
1568 chrome::DisplaySearchButtonConditions conditions =
1569 chrome::GetDisplaySearchButtonConditions();
1570 bool meets_conditions =
1571 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) ||
1572 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) &&
1573 (toolbar_model->WouldPerformSearchTermReplacement(true) ||
1574 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) &&
1575 toolbar_model->input_in_progress())));
1576 search_button_->SetVisible(!is_popup_mode_ && meets_conditions);
1577 search_button_->UpdateIcon(icon_id == IDR_OMNIBOX_SEARCH);
1578
1579 origin_chip_view_->OnChanged();
1580
1581 Layout(); 1306 Layout();
1582 SchedulePaint(); 1307 SchedulePaint();
1583 } 1308 }
1584 1309
1585 void LocationBarView::OnSetFocus() { 1310 void LocationBarView::OnSetFocus() {
1586 GetFocusManager()->SetFocusedView(this); 1311 GetFocusManager()->SetFocusedView(this);
1587 } 1312 }
1588 1313
1589 InstantController* LocationBarView::GetInstant() { 1314 InstantController* LocationBarView::GetInstant() {
1590 return delegate_->GetInstant(); 1315 return delegate_->GetInstant();
1591 } 1316 }
1592 1317
1593 const ToolbarModel* LocationBarView::GetToolbarModel() const { 1318 const ToolbarModel* LocationBarView::GetToolbarModel() const {
1594 return delegate_->GetToolbarModel(); 1319 return delegate_->GetToolbarModel();
1595 } 1320 }
1596 1321
1597 void LocationBarView::HideURL() {
1598 DCHECK(chrome::ShouldDisplayOriginChip());
1599
1600 // If we're currently showing, reverse the hide by swapping to the hide
1601 // animation, offset so that the text is in the same position.
1602 if (show_url_animation_->is_animating()) {
1603 const double hide_value = GetValueForAnimation(true);
1604 ResetShowAnimationAndColors();
1605 hide_url_animation_->Show();
1606 // This must be done after calling Show() and is not equivalent to Reset(n);
1607 // see comments in ShowURL().
1608 hide_url_animation_->SetCurrentValue(hide_value);
1609 } else {
1610 hide_url_animation_->Show();
1611 }
1612 }
1613
1614 //////////////////////////////////////////////////////////////////////////////// 1322 ////////////////////////////////////////////////////////////////////////////////
1615 // LocationBarView, private DropdownBarHostDelegate implementation: 1323 // LocationBarView, private DropdownBarHostDelegate implementation:
1616 1324
1617 void LocationBarView::SetFocusAndSelection(bool select_all) { 1325 void LocationBarView::SetFocusAndSelection(bool select_all) {
1618 FocusLocation(select_all); 1326 FocusLocation(select_all);
1619 } 1327 }
1620 1328
1621 void LocationBarView::SetAnimationOffset(int offset) { 1329 void LocationBarView::SetAnimationOffset(int offset) {
1622 dropdown_animation_offset_ = offset; 1330 dropdown_animation_offset_ = offset;
1623 } 1331 }
1624 1332
1625 //////////////////////////////////////////////////////////////////////////////// 1333 ////////////////////////////////////////////////////////////////////////////////
1626 // LocationBarView, private gfx::AnimationDelegate implementation:
1627
1628 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) {
1629 DCHECK((animation == show_url_animation_.get()) ||
1630 (animation == hide_url_animation_.get()));
1631 Layout();
1632 SchedulePaint();
1633 }
1634
1635 void LocationBarView::AnimationEnded(const gfx::Animation* animation) {
1636 if (animation == show_url_animation_.get()) {
1637 ResetShowAnimationAndColors();
1638 Layout();
1639 SchedulePaint();
1640 } else {
1641 DCHECK(animation == hide_url_animation_.get());
1642 hide_url_animation_->Reset();
1643 origin_chip_view_->FadeIn();
1644 omnibox_view_->HideURL(); // Calls OnChanged(), triggering layout.
1645 }
1646 }
1647
1648 ////////////////////////////////////////////////////////////////////////////////
1649 // LocationBarView, private TemplateURLServiceObserver implementation: 1334 // LocationBarView, private TemplateURLServiceObserver implementation:
1650 1335
1651 void LocationBarView::OnTemplateURLServiceChanged() { 1336 void LocationBarView::OnTemplateURLServiceChanged() {
1652 template_url_service_->RemoveObserver(this); 1337 template_url_service_->RemoveObserver(this);
1653 template_url_service_ = NULL; 1338 template_url_service_ = NULL;
1654 // If the browser is no longer active, let's not show the info bubble, as this 1339 // If the browser is no longer active, let's not show the info bubble, as this
1655 // would make the browser the active window again. 1340 // would make the browser the active window again.
1656 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1341 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1657 ShowFirstRunBubble(); 1342 ShowFirstRunBubble();
1658 } 1343 }
1659 1344
1660 //////////////////////////////////////////////////////////////////////////////// 1345 ////////////////////////////////////////////////////////////////////////////////
1661 // LocationBarView, private SearchModelObserver implementation: 1346 // LocationBarView, private SearchModelObserver implementation:
1662 1347
1663 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1348 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1664 const SearchModel::State& new_state) { 1349 const SearchModel::State& new_state) {
1665 const bool visible = !GetToolbarModel()->input_in_progress() && 1350 const bool visible = !GetToolbarModel()->input_in_progress() &&
1666 new_state.voice_search_supported; 1351 new_state.voice_search_supported;
1667 if (mic_search_view_->visible() != visible) { 1352 if (mic_search_view_->visible() != visible) {
1668 mic_search_view_->SetVisible(visible); 1353 mic_search_view_->SetVisible(visible);
1669 Layout(); 1354 Layout();
1670 } 1355 }
1671 } 1356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698