OLD | NEW |
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/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_split.h" | |
15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/command_updater.h" | 17 #include "chrome/browser/command_updater.h" |
19 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
20 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 19 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
21 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
22 #include "chrome/browser/extensions/location_bar_controller.h" | 21 #include "chrome/browser/extensions/location_bar_controller.h" |
23 #include "chrome/browser/extensions/tab_helper.h" | 22 #include "chrome/browser/extensions/tab_helper.h" |
24 #include "chrome/browser/favicon/favicon_tab_helper.h" | 23 #include "chrome/browser/favicon/favicon_tab_helper.h" |
25 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/search/instant_service.h" | 25 #include "chrome/browser/search/instant_service.h" |
27 #include "chrome/browser/search/instant_service_factory.h" | 26 #include "chrome/browser/search/instant_service_factory.h" |
28 #include "chrome/browser/search/search.h" | 27 #include "chrome/browser/search/search.h" |
29 #include "chrome/browser/search_engines/template_url.h" | 28 #include "chrome/browser/search_engines/template_url.h" |
30 #include "chrome/browser/search_engines/template_url_service.h" | 29 #include "chrome/browser/search_engines/template_url_service.h" |
31 #include "chrome/browser/search_engines/template_url_service_factory.h" | 30 #include "chrome/browser/search_engines/template_url_service_factory.h" |
32 #include "chrome/browser/translate/translate_service.h" | 31 #include "chrome/browser/translate/translate_service.h" |
33 #include "chrome/browser/translate/translate_tab_helper.h" | 32 #include "chrome/browser/translate/translate_tab_helper.h" |
34 #include "chrome/browser/ui/browser.h" | 33 #include "chrome/browser/ui/browser.h" |
35 #include "chrome/browser/ui/browser_finder.h" | 34 #include "chrome/browser/ui/browser_finder.h" |
36 #include "chrome/browser/ui/browser_instant_controller.h" | 35 #include "chrome/browser/ui/browser_instant_controller.h" |
37 #include "chrome/browser/ui/browser_window.h" | 36 #include "chrome/browser/ui/browser_window.h" |
38 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 37 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
39 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 38 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
40 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" | 39 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" |
41 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" | 40 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" |
42 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 41 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
43 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 42 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
44 #include "chrome/browser/ui/toolbar/origin_chip_info.h" | |
45 #include "chrome/browser/ui/view_ids.h" | 43 #include "chrome/browser/ui/view_ids.h" |
46 #include "chrome/browser/ui/views/browser_dialogs.h" | 44 #include "chrome/browser/ui/views/browser_dialogs.h" |
47 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 45 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
48 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 46 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
49 #include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h" | 47 #include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h" |
50 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 48 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
51 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" | 49 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" |
52 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 50 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
53 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" | 51 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" |
54 #include "chrome/browser/ui/views/location_bar/origin_chip_view.h" | 52 #include "chrome/browser/ui/views/location_bar/origin_chip_view.h" |
(...skipping 21 matching lines...) Expand all Loading... |
76 #include "ui/base/dragdrop/drag_drop_types.h" | 74 #include "ui/base/dragdrop/drag_drop_types.h" |
77 #include "ui/base/l10n/l10n_util.h" | 75 #include "ui/base/l10n/l10n_util.h" |
78 #include "ui/base/resource/resource_bundle.h" | 76 #include "ui/base/resource/resource_bundle.h" |
79 #include "ui/base/theme_provider.h" | 77 #include "ui/base/theme_provider.h" |
80 #include "ui/events/event.h" | 78 #include "ui/events/event.h" |
81 #include "ui/gfx/animation/slide_animation.h" | 79 #include "ui/gfx/animation/slide_animation.h" |
82 #include "ui/gfx/canvas.h" | 80 #include "ui/gfx/canvas.h" |
83 #include "ui/gfx/color_utils.h" | 81 #include "ui/gfx/color_utils.h" |
84 #include "ui/gfx/image/image.h" | 82 #include "ui/gfx/image/image.h" |
85 #include "ui/gfx/image/image_skia_operations.h" | 83 #include "ui/gfx/image/image_skia_operations.h" |
| 84 #include "ui/gfx/scoped_canvas.h" |
86 #include "ui/gfx/skia_util.h" | 85 #include "ui/gfx/skia_util.h" |
87 #include "ui/gfx/text_utils.h" | 86 #include "ui/gfx/text_utils.h" |
88 #include "ui/native_theme/native_theme.h" | 87 #include "ui/native_theme/native_theme.h" |
89 #include "ui/views/background.h" | 88 #include "ui/views/background.h" |
90 #include "ui/views/border.h" | 89 #include "ui/views/border.h" |
91 #include "ui/views/button_drag_utils.h" | 90 #include "ui/views/button_drag_utils.h" |
92 #include "ui/views/controls/button/image_button.h" | 91 #include "ui/views/controls/button/image_button.h" |
93 #include "ui/views/controls/button/label_button.h" | 92 #include "ui/views/controls/button/label_button.h" |
94 #include "ui/views/controls/button/label_button_border.h" | 93 #include "ui/views/controls/button/label_button_border.h" |
95 #include "ui/views/controls/label.h" | 94 #include "ui/views/controls/label.h" |
96 #include "ui/views/widget/widget.h" | 95 #include "ui/views/widget/widget.h" |
97 | 96 |
98 #if !defined(OS_CHROMEOS) | 97 #if !defined(OS_CHROMEOS) |
99 #include "chrome/browser/ui/views/first_run_bubble.h" | 98 #include "chrome/browser/ui/views/first_run_bubble.h" |
100 #endif | 99 #endif |
101 | 100 |
102 using content::WebContents; | 101 using content::WebContents; |
103 using views::View; | 102 using views::View; |
104 | 103 |
105 namespace { | 104 namespace { |
106 | 105 |
| 106 const gfx::Tween::Type kShowTweenType = gfx::Tween::LINEAR_OUT_SLOW_IN; |
| 107 const gfx::Tween::Type kHideTweenType = gfx::Tween::FAST_OUT_LINEAR_IN; |
| 108 |
107 // The search button images are made to look as if they overlay the normal edge | 109 // The search button images are made to look as if they overlay the normal edge |
108 // images, but to align things, the search button needs to be inset horizontally | 110 // images, but to align things, the search button needs to be inset horizontally |
109 // by 1 px. | 111 // by 1 px. |
110 const int kSearchButtonInset = 1; | 112 const int kSearchButtonInset = 1; |
111 | 113 |
112 // Given a containing |height| and a |base_font_list|, shrinks the font size | 114 // Given a containing |height| and a |base_font_list|, shrinks the font size |
113 // until the font list will fit within |height| while having its cap height | 115 // until the font list will fit within |height| while having its cap height |
114 // vertically centered. Returns the correctly-sized font list. | 116 // vertically centered. Returns the correctly-sized font list. |
115 // | 117 // |
116 // The expected layout: | 118 // The expected layout: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 generated_credit_card_view_(NULL), | 219 generated_credit_card_view_(NULL), |
218 open_pdf_in_reader_view_(NULL), | 220 open_pdf_in_reader_view_(NULL), |
219 manage_passwords_icon_view_(NULL), | 221 manage_passwords_icon_view_(NULL), |
220 translate_icon_view_(NULL), | 222 translate_icon_view_(NULL), |
221 star_view_(NULL), | 223 star_view_(NULL), |
222 search_button_(NULL), | 224 search_button_(NULL), |
223 is_popup_mode_(is_popup_mode), | 225 is_popup_mode_(is_popup_mode), |
224 show_focus_rect_(false), | 226 show_focus_rect_(false), |
225 template_url_service_(NULL), | 227 template_url_service_(NULL), |
226 dropdown_animation_offset_(0), | 228 dropdown_animation_offset_(0), |
227 animated_host_label_(NULL), | 229 starting_omnibox_offset_(0), |
| 230 current_omnibox_offset_(0), |
| 231 starting_omnibox_leading_inset_(0), |
| 232 current_omnibox_leading_inset_(0), |
| 233 current_omnibox_width_(0), |
| 234 ending_omnibox_width_(0), |
228 weak_ptr_factory_(this) { | 235 weak_ptr_factory_(this) { |
229 edit_bookmarks_enabled_.Init( | 236 edit_bookmarks_enabled_.Init( |
230 prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 237 prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
231 base::Bind(&LocationBarView::Update, base::Unretained(this), | 238 base::Bind(&LocationBarView::Update, base::Unretained(this), |
232 static_cast<content::WebContents*>(NULL))); | 239 static_cast<content::WebContents*>(NULL))); |
233 | 240 |
234 if (browser_) | 241 if (browser_) |
235 browser_->search_model()->AddObserver(this); | 242 browser_->search_model()->AddObserver(this); |
236 } | 243 } |
237 | 244 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 316 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
310 ime_inline_autocomplete_view_->set_background( | 317 ime_inline_autocomplete_view_->set_background( |
311 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 318 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
312 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 319 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
313 ime_inline_autocomplete_view_->SetEnabledColor( | 320 ime_inline_autocomplete_view_->SetEnabledColor( |
314 GetNativeTheme()->GetSystemColor( | 321 GetNativeTheme()->GetSystemColor( |
315 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 322 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
316 ime_inline_autocomplete_view_->SetVisible(false); | 323 ime_inline_autocomplete_view_->SetVisible(false); |
317 AddChildView(ime_inline_autocomplete_view_); | 324 AddChildView(ime_inline_autocomplete_view_); |
318 | 325 |
319 animated_host_label_ = new views::Label(base::string16(), font_list); | |
320 animated_host_label_->SetVisible(false); | |
321 AddChildView(animated_host_label_); | |
322 | |
323 origin_chip_view_ = new OriginChipView(this, profile(), font_list); | 326 origin_chip_view_ = new OriginChipView(this, profile(), font_list); |
324 origin_chip_view_->SetFocusable(false); | 327 origin_chip_view_->SetFocusable(false); |
325 origin_chip_view_->set_drag_controller(this); | 328 origin_chip_view_->set_drag_controller(this); |
326 AddChildView(origin_chip_view_); | 329 AddChildView(origin_chip_view_); |
327 | 330 |
328 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); | 331 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); |
329 selected_keyword_view_ = new SelectedKeywordView( | 332 selected_keyword_view_ = new SelectedKeywordView( |
330 bubble_font_list, text_color, background_color, profile()); | 333 bubble_font_list, text_color, background_color, profile()); |
331 AddChildView(selected_keyword_view_); | 334 AddChildView(selected_keyword_view_); |
332 | 335 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 search_button_border->SetPainter(true, views::Button::STATE_HOVERED, NULL); | 420 search_button_border->SetPainter(true, views::Button::STATE_HOVERED, NULL); |
418 search_button_border->SetPainter(true, views::Button::STATE_PRESSED, NULL); | 421 search_button_border->SetPainter(true, views::Button::STATE_PRESSED, NULL); |
419 search_button_border->SetPainter(true, views::Button::STATE_DISABLED, NULL); | 422 search_button_border->SetPainter(true, views::Button::STATE_DISABLED, NULL); |
420 search_button_->SetBorder(search_button_border.PassAs<views::Border>()); | 423 search_button_->SetBorder(search_button_border.PassAs<views::Border>()); |
421 const int kSearchButtonWidth = 56; | 424 const int kSearchButtonWidth = 56; |
422 search_button_->set_min_size(gfx::Size(kSearchButtonWidth, 0)); | 425 search_button_->set_min_size(gfx::Size(kSearchButtonWidth, 0)); |
423 search_button_->SetVisible(false); | 426 search_button_->SetVisible(false); |
424 AddChildView(search_button_); | 427 AddChildView(search_button_); |
425 | 428 |
426 show_url_animation_.reset(new gfx::SlideAnimation(this)); | 429 show_url_animation_.reset(new gfx::SlideAnimation(this)); |
427 show_url_animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); | 430 show_url_animation_->SetTweenType(kShowTweenType); |
428 show_url_animation_->SetSlideDuration(200); | 431 show_url_animation_->SetSlideDuration(200); |
429 | 432 |
430 hide_url_animation_.reset(new gfx::SlideAnimation(this)); | 433 hide_url_animation_.reset(new gfx::SlideAnimation(this)); |
431 hide_url_animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); | 434 hide_url_animation_->SetTweenType(kHideTweenType); |
432 hide_url_animation_->SetSlideDuration(200); | 435 hide_url_animation_->SetSlideDuration(175); |
433 | 436 |
434 content::Source<Profile> profile_source = content::Source<Profile>(profile()); | 437 content::Source<Profile> profile_source = content::Source<Profile>(profile()); |
435 registrar_.Add(this, | 438 registrar_.Add(this, |
436 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 439 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
437 profile_source); | 440 profile_source); |
438 registrar_.Add( | 441 registrar_.Add( |
439 this, chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, profile_source); | 442 this, chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, profile_source); |
440 registrar_.Add(this, | 443 registrar_.Add(this, |
441 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 444 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
442 profile_source); | 445 profile_source); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 if (star_view_) | 554 if (star_view_) |
552 star_view_->SetToggled(on); | 555 star_view_->SetToggled(on); |
553 } | 556 } |
554 | 557 |
555 void LocationBarView::SetTranslateIconToggled(bool on) { | 558 void LocationBarView::SetTranslateIconToggled(bool on) { |
556 translate_icon_view_->SetToggled(on); | 559 translate_icon_view_->SetToggled(on); |
557 } | 560 } |
558 | 561 |
559 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { | 562 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { |
560 gfx::Point origin(omnibox_view_->bounds().origin()); | 563 gfx::Point origin(omnibox_view_->bounds().origin()); |
561 // If the UI layout is RTL, the coordinate system is not transformed and | 564 origin.set_x(GetMirroredXInView(origin.x() - current_omnibox_offset_)); |
562 // therefore we need to adjust the X coordinate so that bubble appears on the | |
563 // right hand side of the location bar. | |
564 if (base::i18n::IsRTL()) | |
565 origin.set_x(width() - origin.x()); | |
566 views::View::ConvertPointToScreen(this, &origin); | 565 views::View::ConvertPointToScreen(this, &origin); |
567 return origin; | 566 return origin; |
568 } | 567 } |
569 | 568 |
570 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { | 569 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { |
571 ime_inline_autocomplete_view_->SetText(text); | 570 ime_inline_autocomplete_view_->SetText(text); |
572 ime_inline_autocomplete_view_->SetVisible(!text.empty()); | 571 ime_inline_autocomplete_view_->SetVisible(!text.empty()); |
573 } | 572 } |
574 | 573 |
575 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { | 574 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { |
576 if (suggested_text_view_->text() != text) { | 575 if (suggested_text_view_->text() != text) { |
577 suggested_text_view_->SetText(text); | 576 suggested_text_view_->SetText(text); |
578 suggested_text_view_->SetVisible(!text.empty()); | 577 suggested_text_view_->SetVisible(!text.empty()); |
579 Layout(); | 578 Layout(); |
580 SchedulePaint(); | 579 SchedulePaint(); |
581 } | 580 } |
582 } | 581 } |
583 | 582 |
584 base::string16 LocationBarView::GetGrayTextAutocompletion() const { | 583 base::string16 LocationBarView::GetGrayTextAutocompletion() const { |
585 return HasValidSuggestText() ? suggested_text_view_->text() | 584 return HasValidSuggestText() ? |
586 : base::string16(); | 585 suggested_text_view_->text() : base::string16(); |
587 } | 586 } |
588 | 587 |
589 void LocationBarView::SetShowFocusRect(bool show) { | 588 void LocationBarView::SetShowFocusRect(bool show) { |
590 show_focus_rect_ = show; | 589 show_focus_rect_ = show; |
591 SchedulePaint(); | 590 SchedulePaint(); |
592 } | 591 } |
593 | 592 |
594 void LocationBarView::SelectAll() { | 593 void LocationBarView::SelectAll() { |
595 omnibox_view_->SelectAll(true); | 594 omnibox_view_->SelectAll(true); |
596 } | 595 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 | 730 |
732 min_size.set_width( | 731 min_size.set_width( |
733 leading_width + omnibox_view_->GetMinimumSize().width() + trailing_width); | 732 leading_width + omnibox_view_->GetMinimumSize().width() + trailing_width); |
734 return min_size; | 733 return min_size; |
735 } | 734 } |
736 | 735 |
737 void LocationBarView::Layout() { | 736 void LocationBarView::Layout() { |
738 if (!IsInitialized()) | 737 if (!IsInitialized()) |
739 return; | 738 return; |
740 | 739 |
741 animated_host_label_->SetVisible(false); | |
742 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); | 740 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); |
743 selected_keyword_view_->SetVisible(false); | 741 selected_keyword_view_->SetVisible(false); |
744 location_icon_view_->SetVisible(false); | 742 location_icon_view_->SetVisible(false); |
745 ev_bubble_view_->SetVisible(false); | 743 ev_bubble_view_->SetVisible(false); |
746 keyword_hint_view_->SetVisible(false); | 744 keyword_hint_view_->SetVisible(false); |
747 | 745 |
748 LocationBarLayout leading_decorations( | 746 LocationBarLayout leading_decorations( |
749 LocationBarLayout::LEFT_EDGE, | 747 LocationBarLayout::LEFT_EDGE, |
750 kItemPadding - GetEditLeadingInternalSpace()); | 748 kItemPadding - GetEditLeadingInternalSpace()); |
751 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, | 749 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, |
752 kItemPadding); | 750 kItemPadding); |
753 | 751 |
754 // Show and position the animated host label used in the show and hide URL | 752 const int origin_chip_preferred_width = |
755 // animations. | 753 origin_chip_view_->GetPreferredSize().width(); |
756 if (show_url_animation_->is_animating() || | 754 const int origin_chip_width = |
757 hide_url_animation_->is_animating()) { | 755 origin_chip_view_->visible() ? origin_chip_preferred_width : 0; |
758 WebContents* web_contents = GetWebContents(); | 756 // Always give the origin chip view its desired size and lay it out, even when |
759 const GURL url = web_contents ? web_contents->GetURL() : GURL(); | 757 // it's not visible, so we can calculate the correct animation values below |
760 const base::string16 host = | 758 // when switching to tabs that have the origin chip hidden. |
761 OriginChip::LabelFromURLForProfile(url, profile()); | 759 origin_chip_view_->SetBounds(0, 0, origin_chip_preferred_width, height()); |
762 animated_host_label_->SetText(host); | 760 origin_chip_view_->Layout(); |
763 | |
764 const base::string16 formatted_url = GetToolbarModel()->GetFormattedURL(); | |
765 | |
766 // Split the formatted URL on the host name in order to determine the size | |
767 // of the text leading up to it. | |
768 std::vector<base::string16> substrings; | |
769 base::SplitStringUsingSubstr(formatted_url, host, &substrings); | |
770 const base::string16 text_leading_host = substrings[0]; | |
771 const int leading_text_width = | |
772 gfx::Canvas::GetStringWidth(text_leading_host, | |
773 origin_chip_view_->GetFontList()); | |
774 | |
775 const int position_of_host_name_in_chip = origin_chip_view_->host_label_x(); | |
776 const int position_of_host_name_in_url = | |
777 position_of_host_name_in_chip + leading_text_width; | |
778 | |
779 int host_label_x = position_of_host_name_in_chip; | |
780 if (show_url_animation_->is_animating()) { | |
781 host_label_x = show_url_animation_-> | |
782 CurrentValueBetween(position_of_host_name_in_chip, | |
783 position_of_host_name_in_url); | |
784 } else if (hide_url_animation_->is_animating()) { | |
785 host_label_x = hide_url_animation_-> | |
786 CurrentValueBetween(position_of_host_name_in_url, | |
787 position_of_host_name_in_chip); | |
788 } | |
789 animated_host_label_->SetBounds( | |
790 host_label_x, 0, | |
791 animated_host_label_->GetPreferredSize().width(), height()); | |
792 animated_host_label_->SetVisible(true); | |
793 } | |
794 | |
795 const int origin_chip_width = origin_chip_view_->visible() ? | |
796 origin_chip_view_->GetPreferredSize().width() : 0; | |
797 origin_chip_view_->SetBounds(0, 0, origin_chip_width, height()); | |
798 | 761 |
799 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; | 762 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; |
800 const base::string16 keyword(omnibox_view_->model()->keyword()); | 763 const base::string16 keyword(omnibox_view_->model()->keyword()); |
801 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 764 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
802 // to position our child views in this case, because other things may be | 765 // to position our child views in this case, because other things may be |
803 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 766 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
804 // hits ctrl-d). | 767 // hits ctrl-d). |
805 const int location_height = GetInternalHeight(false); | 768 const int location_height = GetInternalHeight(false); |
806 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); | 769 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); |
807 if (ShouldShowKeywordBubble()) { | 770 if (ShouldShowKeywordBubble()) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 | 875 |
913 int location_needed_width = omnibox_view_->GetTextWidth(); | 876 int location_needed_width = omnibox_view_->GetTextWidth(); |
914 int available_width = entry_width - location_needed_width; | 877 int available_width = entry_width - location_needed_width; |
915 // The bounds must be wide enough for all the decorations to fit. | 878 // The bounds must be wide enough for all the decorations to fit. |
916 gfx::Rect location_bounds( | 879 gfx::Rect location_bounds( |
917 origin_chip_width + horizontal_edge_thickness, vertical_edge_thickness(), | 880 origin_chip_width + horizontal_edge_thickness, vertical_edge_thickness(), |
918 std::max(full_width, full_width - entry_width), location_height); | 881 std::max(full_width, full_width - entry_width), location_height); |
919 leading_decorations.LayoutPass3(&location_bounds, &available_width); | 882 leading_decorations.LayoutPass3(&location_bounds, &available_width); |
920 trailing_decorations.LayoutPass3(&location_bounds, &available_width); | 883 trailing_decorations.LayoutPass3(&location_bounds, &available_width); |
921 | 884 |
| 885 // Calculate the animation parameters (see comments on these members in the |
| 886 // header). We have to do this in Layout, after |origin_chip_view_| is laid |
| 887 // out, because that may affect the host label offset in the origin chip. |
| 888 const base::string16& chip_text(origin_chip_view_->host_label_text()); |
| 889 // If the chip is clicked, the omnibox text will become the toolbar model's |
| 890 // formatted URL. We can't ask the omnibox for its current text, because |
| 891 // while the chip is visible the current text is empty. |
| 892 size_t prefix_end = 0; |
| 893 const base::string16& omnibox_text( |
| 894 GetToolbarModel()->GetFormattedURL(&prefix_end)); |
| 895 // Do a case-insensitive search to better match cases like |
| 896 // "Settings" <-> "chrome://settings". Skip any pre-hostname text. |
| 897 size_t chip_text_offset = std::search( |
| 898 omnibox_text.begin() + prefix_end, omnibox_text.end(), |
| 899 chip_text.begin(), chip_text.end(), |
| 900 base::CaseInsensitiveCompare<base::char16>()) - omnibox_text.begin(); |
| 901 // If we couldn't find the chip text, try checking whether the omnibox text |
| 902 // starts with it, as is true for e.g. file: URLs. |
| 903 if ((chip_text_offset >= omnibox_text.length()) && |
| 904 StartsWith(omnibox_text, chip_text, true)) |
| 905 chip_text_offset = 0; |
| 906 const gfx::FontList& font_list = omnibox_view_->GetFontList(); |
| 907 const int chip_text_width = gfx::GetStringWidth(chip_text, font_list); |
| 908 const int old_starting_offset = starting_omnibox_offset_; |
| 909 const int old_starting_leading_inset = starting_omnibox_leading_inset_; |
| 910 const int old_ending_width = ending_omnibox_width_; |
| 911 starting_omnibox_offset_ = current_omnibox_offset_ = 0; |
| 912 starting_omnibox_leading_inset_ = current_omnibox_leading_inset_ = 0; |
| 913 ending_omnibox_width_ = gfx::GetStringWidth(omnibox_text, font_list); |
| 914 if (chip_text_offset < omnibox_text.length()) { |
| 915 if (base::i18n::IsRTL()) |
| 916 chip_text_offset += chip_text.length(); |
| 917 base::string16 extra_omnibox_text(base::i18n::IsRTL() ? |
| 918 omnibox_text.substr(chip_text_offset) : |
| 919 omnibox_text.substr(0, chip_text_offset)); |
| 920 starting_omnibox_leading_inset_ = |
| 921 gfx::GetStringWidth(extra_omnibox_text, font_list); |
| 922 starting_omnibox_offset_ = origin_chip_view_->HostLabelOffset() - |
| 923 starting_omnibox_leading_inset_; |
| 924 current_omnibox_width_ = chip_text_width; |
| 925 } else { |
| 926 // If the chip text wasn't found in the omnibox text, then instead of |
| 927 // starting the show animation clipped to the "hostname", we'll start with |
| 928 // the entire omnibox text visible, clipped to the remaining chip width, and |
| 929 // only animate any necessary expansion of that width, without moving the |
| 930 // omnibox bounds. |
| 931 current_omnibox_width_ = origin_chip_view_->WidthFromStartOfLabels(); |
| 932 } |
| 933 |
| 934 // End the animations immediately if the parameters have changed. |
| 935 if ((starting_omnibox_offset_ != old_starting_offset) || |
| 936 (starting_omnibox_leading_inset_ != old_starting_leading_inset) || |
| 937 (ending_omnibox_width_ != old_ending_width)) |
| 938 EndOriginChipAnimations(true); |
| 939 |
| 940 // Also end the animations immediately if there's nothing to animate (but do |
| 941 // allow the chip to fade back in). |
| 942 const ui::NativeTheme* native_theme = GetNativeTheme(); |
| 943 const SkColor ending_selection_text_color = native_theme->GetSystemColor( |
| 944 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
| 945 const SkColor ending_selection_background_color = |
| 946 native_theme->GetSystemColor( |
| 947 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); |
| 948 if ((starting_omnibox_offset_ == 0) && |
| 949 (starting_omnibox_leading_inset_ == 0) && |
| 950 (ending_omnibox_width_ == chip_text_width) && |
| 951 (hide_url_animation_->is_animating() || |
| 952 ((ending_selection_text_color == |
| 953 origin_chip_view_->pressed_text_color()) && |
| 954 (ending_selection_background_color == |
| 955 origin_chip_view_->pressed_background_color())))) |
| 956 EndOriginChipAnimations(false); |
| 957 |
| 958 if (show_url_animation_->is_animating()) { |
| 959 omnibox_view_->SetSelectionTextColor(gfx::Tween::ColorValueBetween( |
| 960 show_url_animation_->GetCurrentValue(), |
| 961 origin_chip_view_->pressed_text_color(), |
| 962 ending_selection_text_color)); |
| 963 omnibox_view_->SetSelectionBackgroundColor(gfx::Tween::ColorValueBetween( |
| 964 show_url_animation_->GetCurrentValue(), |
| 965 origin_chip_view_->pressed_background_color(), |
| 966 ending_selection_background_color)); |
| 967 current_omnibox_offset_ = |
| 968 show_url_animation_->CurrentValueBetween(starting_omnibox_offset_, 0); |
| 969 current_omnibox_leading_inset_ = show_url_animation_->CurrentValueBetween( |
| 970 starting_omnibox_leading_inset_, 0); |
| 971 current_omnibox_width_ = show_url_animation_->CurrentValueBetween( |
| 972 chip_text_width, ending_omnibox_width_); |
| 973 } else if (hide_url_animation_->is_animating()) { |
| 974 current_omnibox_offset_ = |
| 975 hide_url_animation_->CurrentValueBetween(0, starting_omnibox_offset_); |
| 976 current_omnibox_leading_inset_ = hide_url_animation_->CurrentValueBetween( |
| 977 0, starting_omnibox_leading_inset_); |
| 978 current_omnibox_width_ = hide_url_animation_->CurrentValueBetween( |
| 979 ending_omnibox_width_, chip_text_width); |
| 980 } |
| 981 // Contract |available_width| as necessary, but never expand it. This way, |
| 982 // we'll never draw suggested text at first and then have it disappear |
| 983 // midway through the animation. |
| 984 if (current_omnibox_offset_ > 0) |
| 985 available_width -= current_omnibox_offset_; |
| 986 location_bounds.Inset(current_omnibox_offset_, 0, 0, 0); |
| 987 |
922 // Layout out the suggested text view right aligned to the location | 988 // Layout out the suggested text view right aligned to the location |
923 // entry. Only show the suggested text if we can fit the text from one | 989 // entry. Only show the suggested text if we can fit the text from one |
924 // character before the end of the selection to the end of the text and the | 990 // character before the end of the selection to the end of the text and the |
925 // suggested text. If we can't it means either the suggested text is too big, | 991 // suggested text. If we can't it means either the suggested text is too big, |
926 // or the user has scrolled. | 992 // or the user has scrolled. |
927 | 993 |
928 // TODO(sky): We could potentially adjust this to take into account suggested | 994 // TODO(sky): We could potentially adjust this to take into account suggested |
929 // text to force using minimum size if necessary, but currently the chance of | 995 // text to force using minimum size if necessary, but currently the chance of |
930 // showing keyword hints and suggested text is minimal and we're not confident | 996 // showing keyword hints and suggested text is minimal and we're not confident |
931 // this is the right approach for suggested text. | 997 // this is the right approach for suggested text. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 | 1097 |
1032 if (contents) | 1098 if (contents) |
1033 omnibox_view_->OnTabChanged(contents); | 1099 omnibox_view_->OnTabChanged(contents); |
1034 else | 1100 else |
1035 omnibox_view_->Update(); | 1101 omnibox_view_->Update(); |
1036 | 1102 |
1037 OnChanged(); // NOTE: Calls Layout(). | 1103 OnChanged(); // NOTE: Calls Layout(). |
1038 } | 1104 } |
1039 | 1105 |
1040 void LocationBarView::ShowURL() { | 1106 void LocationBarView::ShowURL() { |
| 1107 // Start the animation before calling ShowURL(), since the latter eventually |
| 1108 // calls back to Layout(), and if the animation is not marked as "running", |
| 1109 // we'll draw the omnibox in its final position briefly until the first |
| 1110 // animation callback reaches us. |
1041 if (chrome::ShouldDisplayOriginChip()) { | 1111 if (chrome::ShouldDisplayOriginChip()) { |
1042 omnibox_view_->SetVisible(false); | 1112 // If we're currently hiding, reverse the hide by swapping to the show |
1043 omnibox_view_->ShowURL(); | 1113 // animation, offset so that the text is in the same position. |
1044 show_url_animation_->Show(); | 1114 if (hide_url_animation_->is_animating()) { |
1045 } else { | 1115 const double show_value = GetValueForAnimation(false); |
1046 omnibox_view_->ShowURL(); | 1116 hide_url_animation_->Reset(); |
| 1117 show_url_animation_->Show(); |
| 1118 // This must be done after calling Show() and is not equivalent to |
| 1119 // calling Reset(n) before Show(); Reset() would have caused the entire |
| 1120 // animation curve (and time) to run between this value and the final |
| 1121 // value, whereas Show() + SetCurrentValue() skips the animation forward |
| 1122 // to the supplied value. |
| 1123 show_url_animation_->SetCurrentValue(show_value); |
| 1124 } else { |
| 1125 show_url_animation_->Show(); |
| 1126 } |
1047 } | 1127 } |
| 1128 omnibox_view_->ShowURL(); |
| 1129 } |
| 1130 |
| 1131 void LocationBarView::EndOriginChipAnimations(bool cancel_fade) { |
| 1132 show_url_animation_->End(); |
| 1133 hide_url_animation_->End(); |
| 1134 if (cancel_fade) |
| 1135 origin_chip_view_->CancelFade(); |
1048 } | 1136 } |
1049 | 1137 |
1050 ToolbarModel* LocationBarView::GetToolbarModel() { | 1138 ToolbarModel* LocationBarView::GetToolbarModel() { |
1051 return delegate_->GetToolbarModel(); | 1139 return delegate_->GetToolbarModel(); |
1052 } | 1140 } |
1053 | 1141 |
1054 WebContents* LocationBarView::GetWebContents() { | 1142 WebContents* LocationBarView::GetWebContents() { |
1055 return delegate_->GetWebContents(); | 1143 return delegate_->GetWebContents(); |
1056 } | 1144 } |
1057 | 1145 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 bool LocationBarView::ShouldShowKeywordBubble() const { | 1323 bool LocationBarView::ShouldShowKeywordBubble() const { |
1236 return !omnibox_view_->model()->keyword().empty() && | 1324 return !omnibox_view_->model()->keyword().empty() && |
1237 !omnibox_view_->model()->is_keyword_hint(); | 1325 !omnibox_view_->model()->is_keyword_hint(); |
1238 } | 1326 } |
1239 | 1327 |
1240 bool LocationBarView::ShouldShowEVBubble() const { | 1328 bool LocationBarView::ShouldShowEVBubble() const { |
1241 return !chrome::ShouldDisplayOriginChip() && | 1329 return !chrome::ShouldDisplayOriginChip() && |
1242 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); | 1330 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); |
1243 } | 1331 } |
1244 | 1332 |
1245 void LocationBarView::OnShowURLAnimationEnded() { | 1333 double LocationBarView::GetValueForAnimation(bool hide) const { |
1246 animated_host_label_->SetVisible(false); | 1334 int calculated_offset; |
1247 omnibox_view_->SetVisible(true); | 1335 const gfx::Tween::Type tween_type = hide ? kHideTweenType : kShowTweenType; |
1248 omnibox_view_->FadeIn(); | 1336 int start_offset = starting_omnibox_offset_, end_offset = 0; |
1249 omnibox_view_->SetFocus(); | 1337 if (hide) |
1250 | 1338 std::swap(start_offset, end_offset); |
1251 // Sometimes the selection established by OmniboxView::ShowURL() is lost at | 1339 const int desired_offset = abs(current_omnibox_offset_); |
1252 // the call to SetFocus() above. Select all again to be sure. | 1340 // Binary-search the value space (0 <= value <= 1) to find the appropriate |
1253 // TODO(jdonnelly): Figure out why the selection is sometimes lost and | 1341 // position. We only bother to iterate to within 1/64 of the desired value, |
1254 // implement a more principled fix. | 1342 // because the longer of the two animations will only run for twelve frames |
1255 omnibox_view_->SelectAll(true); | 1343 // anyway (200 ms * 60 Hz), so at this point we'll have a maximum error of |
| 1344 // less than a fifth of an animation frame, which the user isn't going to |
| 1345 // notice. |
| 1346 // |
| 1347 // We have to use this method because Tween::CalculateValue() is not |
| 1348 // necessarily easily invertible. Luckily, this only runs when the user |
| 1349 // reverses the animation (rare), and the limit on how many iterations we'll |
| 1350 // do ensures the cost is unnoticeable. |
| 1351 double value = 0.5; |
| 1352 double step = value / 2; |
| 1353 do { |
| 1354 calculated_offset = abs(gfx::Tween::IntValueBetween( |
| 1355 gfx::Tween::CalculateValue(tween_type, value), start_offset, |
| 1356 end_offset)); |
| 1357 if (calculated_offset < desired_offset) |
| 1358 value += step; |
| 1359 else if (calculated_offset > desired_offset) |
| 1360 value -= step; |
| 1361 step /= 2; |
| 1362 } while ((calculated_offset != desired_offset) && (step >= (1.0 / 64))); |
| 1363 return value; |
1256 } | 1364 } |
1257 | 1365 |
1258 void LocationBarView::OnHideURLAnimationEnded() { | 1366 void LocationBarView::ResetShowAnimationAndColors() { |
1259 animated_host_label_->SetVisible(false); | 1367 show_url_animation_->Reset(); |
1260 omnibox_view_->HideURL(); | 1368 omnibox_view_->UseDefaultSelectionTextColor(); |
1261 omnibox_view_->SetVisible(true); | 1369 omnibox_view_->UseDefaultSelectionBackgroundColor(); |
1262 origin_chip_view_->FadeIn(); | |
1263 } | 1370 } |
1264 | 1371 |
1265 //////////////////////////////////////////////////////////////////////////////// | 1372 //////////////////////////////////////////////////////////////////////////////// |
1266 // LocationBarView, private LocationBar implementation: | 1373 // LocationBarView, private LocationBar implementation: |
1267 | 1374 |
1268 void LocationBarView::ShowFirstRunBubble() { | 1375 void LocationBarView::ShowFirstRunBubble() { |
1269 // Wait until search engines have loaded to show the first run bubble. | 1376 // Wait until search engines have loaded to show the first run bubble. |
1270 TemplateURLService* url_service = | 1377 TemplateURLService* url_service = |
1271 TemplateURLServiceFactory::GetForProfile(profile()); | 1378 TemplateURLServiceFactory::GetForProfile(profile()); |
1272 if (!url_service->loaded()) { | 1379 if (!url_service->loaded()) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 SchedulePaint(); | 1454 SchedulePaint(); |
1348 } | 1455 } |
1349 | 1456 |
1350 void LocationBarView::UpdateGeneratedCreditCardView() { | 1457 void LocationBarView::UpdateGeneratedCreditCardView() { |
1351 generated_credit_card_view_->Update(); | 1458 generated_credit_card_view_->Update(); |
1352 Layout(); | 1459 Layout(); |
1353 SchedulePaint(); | 1460 SchedulePaint(); |
1354 } | 1461 } |
1355 | 1462 |
1356 void LocationBarView::SaveStateToContents(WebContents* contents) { | 1463 void LocationBarView::SaveStateToContents(WebContents* contents) { |
| 1464 // If we're about to switch tabs, complete any current animations, so that if |
| 1465 // the user is in the midst of hiding the URL, when he returns to this tab, |
| 1466 // the URL will be hidden rather than shown. |
| 1467 // NOTE: This must be called before SaveStateToTab(). |
| 1468 EndOriginChipAnimations(true); |
1357 omnibox_view_->SaveStateToTab(contents); | 1469 omnibox_view_->SaveStateToTab(contents); |
1358 } | 1470 } |
1359 | 1471 |
1360 const OmniboxView* LocationBarView::GetOmniboxView() const { | 1472 const OmniboxView* LocationBarView::GetOmniboxView() const { |
1361 return omnibox_view_; | 1473 return omnibox_view_; |
1362 } | 1474 } |
1363 | 1475 |
1364 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { | 1476 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { |
1365 return this; | 1477 return this; |
1366 } | 1478 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 const int kBorderCornerRadius = 2; | 1571 const int kBorderCornerRadius = 2; |
1460 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1572 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
1461 } | 1573 } |
1462 | 1574 |
1463 // The border itself will be drawn in PaintChildren() since it includes an | 1575 // The border itself will be drawn in PaintChildren() since it includes an |
1464 // inner shadow which should be drawn over the contents. | 1576 // inner shadow which should be drawn over the contents. |
1465 } | 1577 } |
1466 | 1578 |
1467 void LocationBarView::PaintChildren(gfx::Canvas* canvas, | 1579 void LocationBarView::PaintChildren(gfx::Canvas* canvas, |
1468 const views::CullSet& cull_set) { | 1580 const views::CullSet& cull_set) { |
1469 // Paint all the children except for the origin chip and the search button, | 1581 // Paint all the children except for the omnibox itself, which may need to be |
| 1582 // clipped if it's animating in, and the origin chip and the search button, |
1470 // which will be painted after the border. | 1583 // which will be painted after the border. |
1471 for (int i = 0, count = child_count(); i < count; ++i) { | 1584 for (int i = 0, count = child_count(); i < count; ++i) { |
1472 if (!child_at(i)->layer() && | 1585 views::View* child = child_at(i); |
1473 (child_at(i) != origin_chip_view_) && | 1586 if (!child->layer() && (child != omnibox_view_) && |
1474 (child_at(i) != search_button_)) | 1587 (child != origin_chip_view_) && (child != search_button_)) |
1475 child_at(i)->Paint(canvas, cull_set); | 1588 child->Paint(canvas, cull_set); |
| 1589 } |
| 1590 |
| 1591 { |
| 1592 gfx::ScopedCanvas scoped_canvas(canvas); |
| 1593 if (show_url_animation_->is_animating() || |
| 1594 hide_url_animation_->is_animating()) { |
| 1595 gfx::Rect clip_rect(omnibox_view_->bounds()); |
| 1596 clip_rect.Inset(current_omnibox_leading_inset_, 0, 0, 0); |
| 1597 clip_rect.set_width(current_omnibox_width_); |
| 1598 clip_rect.set_x(GetMirroredXForRect(clip_rect)); |
| 1599 canvas->ClipRect(clip_rect); |
| 1600 } |
| 1601 omnibox_view_->Paint(canvas, cull_set); |
1476 } | 1602 } |
1477 | 1603 |
1478 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | 1604 // 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 | 1605 // the focus rect to appear on top of children we paint here rather than |
1480 // OnPaint(). | 1606 // OnPaint(). |
1481 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | 1607 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. |
1482 if (show_focus_rect_ && HasFocus()) | 1608 if (show_focus_rect_ && HasFocus()) |
1483 canvas->DrawFocusRect(omnibox_view_->bounds()); | 1609 canvas->DrawFocusRect(omnibox_view_->bounds()); |
1484 | 1610 |
1485 // Maximized popup windows don't draw the horizontal edges. We implement this | 1611 // Maximized popup windows don't draw the horizontal edges. We implement this |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1565 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && | 1691 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && |
1566 (toolbar_model->WouldPerformSearchTermReplacement(true) || | 1692 (toolbar_model->WouldPerformSearchTermReplacement(true) || |
1567 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && | 1693 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && |
1568 toolbar_model->input_in_progress()))); | 1694 toolbar_model->input_in_progress()))); |
1569 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); | 1695 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); |
1570 search_button_->SetImage( | 1696 search_button_->SetImage( |
1571 views::Button::STATE_NORMAL, | 1697 views::Button::STATE_NORMAL, |
1572 *GetThemeProvider()->GetImageSkiaNamed((icon_id == IDR_OMNIBOX_SEARCH) ? | 1698 *GetThemeProvider()->GetImageSkiaNamed((icon_id == IDR_OMNIBOX_SEARCH) ? |
1573 IDR_OMNIBOX_SEARCH_BUTTON_LOUPE : IDR_OMNIBOX_SEARCH_BUTTON_ARROW)); | 1699 IDR_OMNIBOX_SEARCH_BUTTON_LOUPE : IDR_OMNIBOX_SEARCH_BUTTON_ARROW)); |
1574 | 1700 |
1575 if (origin_chip_view_->visible()) | 1701 origin_chip_view_->OnChanged(); |
1576 origin_chip_view_->OnChanged(); | |
1577 | 1702 |
1578 Layout(); | 1703 Layout(); |
1579 SchedulePaint(); | 1704 SchedulePaint(); |
1580 } | 1705 } |
1581 | 1706 |
1582 void LocationBarView::OnSetFocus() { | 1707 void LocationBarView::OnSetFocus() { |
1583 GetFocusManager()->SetFocusedView(this); | 1708 GetFocusManager()->SetFocusedView(this); |
1584 } | 1709 } |
1585 | 1710 |
1586 InstantController* LocationBarView::GetInstant() { | 1711 InstantController* LocationBarView::GetInstant() { |
1587 return delegate_->GetInstant(); | 1712 return delegate_->GetInstant(); |
1588 } | 1713 } |
1589 | 1714 |
1590 const ToolbarModel* LocationBarView::GetToolbarModel() const { | 1715 const ToolbarModel* LocationBarView::GetToolbarModel() const { |
1591 return delegate_->GetToolbarModel(); | 1716 return delegate_->GetToolbarModel(); |
1592 } | 1717 } |
1593 | 1718 |
1594 void LocationBarView::HideURL() { | 1719 void LocationBarView::HideURL() { |
1595 omnibox_view_->SetVisible(false); | 1720 DCHECK(chrome::ShouldDisplayOriginChip()); |
1596 hide_url_animation_->Show(); | 1721 |
| 1722 // If we're currently showing, reverse the hide by swapping to the hide |
| 1723 // animation, offset so that the text is in the same position. |
| 1724 if (show_url_animation_->is_animating()) { |
| 1725 const double hide_value = GetValueForAnimation(true); |
| 1726 ResetShowAnimationAndColors(); |
| 1727 hide_url_animation_->Show(); |
| 1728 // This must be done after calling Show() and is not equivalent to Reset(n); |
| 1729 // see comments in ShowURL(). |
| 1730 hide_url_animation_->SetCurrentValue(hide_value); |
| 1731 } else { |
| 1732 hide_url_animation_->Show(); |
| 1733 } |
1597 } | 1734 } |
1598 | 1735 |
1599 //////////////////////////////////////////////////////////////////////////////// | 1736 //////////////////////////////////////////////////////////////////////////////// |
1600 // LocationBarView, private DropdownBarHostDelegate implementation: | 1737 // LocationBarView, private DropdownBarHostDelegate implementation: |
1601 | 1738 |
1602 void LocationBarView::SetFocusAndSelection(bool select_all) { | 1739 void LocationBarView::SetFocusAndSelection(bool select_all) { |
1603 FocusLocation(select_all); | 1740 FocusLocation(select_all); |
1604 } | 1741 } |
1605 | 1742 |
1606 void LocationBarView::SetAnimationOffset(int offset) { | 1743 void LocationBarView::SetAnimationOffset(int offset) { |
1607 dropdown_animation_offset_ = offset; | 1744 dropdown_animation_offset_ = offset; |
1608 } | 1745 } |
1609 | 1746 |
1610 //////////////////////////////////////////////////////////////////////////////// | 1747 //////////////////////////////////////////////////////////////////////////////// |
1611 // LocationBarView, private gfx::AnimationDelegate implementation: | 1748 // LocationBarView, private gfx::AnimationDelegate implementation: |
1612 | 1749 |
1613 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) { | 1750 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) { |
1614 if (animation == show_url_animation_.get() || | 1751 DCHECK((animation == show_url_animation_.get()) || |
1615 animation == hide_url_animation_.get()) { | 1752 (animation == hide_url_animation_.get())); |
1616 Layout(); | 1753 Layout(); |
1617 SchedulePaint(); | 1754 SchedulePaint(); |
1618 } | |
1619 } | 1755 } |
1620 | 1756 |
1621 void LocationBarView::AnimationEnded(const gfx::Animation* animation) { | 1757 void LocationBarView::AnimationEnded(const gfx::Animation* animation) { |
1622 if (animation == show_url_animation_.get()) { | 1758 if (animation == show_url_animation_.get()) { |
1623 show_url_animation_->Reset(); | 1759 ResetShowAnimationAndColors(); |
1624 OnShowURLAnimationEnded(); | 1760 Layout(); |
1625 } else if (animation == hide_url_animation_.get()) { | 1761 SchedulePaint(); |
| 1762 } else { |
| 1763 DCHECK(animation == hide_url_animation_.get()); |
1626 hide_url_animation_->Reset(); | 1764 hide_url_animation_->Reset(); |
1627 OnHideURLAnimationEnded(); | 1765 origin_chip_view_->FadeIn(); |
| 1766 omnibox_view_->HideURL(); // Calls OnChanged(), triggering layout. |
1628 } | 1767 } |
1629 } | 1768 } |
1630 | 1769 |
1631 //////////////////////////////////////////////////////////////////////////////// | 1770 //////////////////////////////////////////////////////////////////////////////// |
1632 // LocationBarView, private TemplateURLServiceObserver implementation: | 1771 // LocationBarView, private TemplateURLServiceObserver implementation: |
1633 | 1772 |
1634 void LocationBarView::OnTemplateURLServiceChanged() { | 1773 void LocationBarView::OnTemplateURLServiceChanged() { |
1635 template_url_service_->RemoveObserver(this); | 1774 template_url_service_->RemoveObserver(this); |
1636 template_url_service_ = NULL; | 1775 template_url_service_ = NULL; |
1637 // If the browser is no longer active, let's not show the info bubble, as this | 1776 // If the browser is no longer active, let's not show the info bubble, as this |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1809 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1671 const SearchModel::State& new_state) { | 1810 const SearchModel::State& new_state) { |
1672 const bool visible = !GetToolbarModel()->input_in_progress() && | 1811 const bool visible = !GetToolbarModel()->input_in_progress() && |
1673 new_state.voice_search_supported; | 1812 new_state.voice_search_supported; |
1674 if (mic_search_view_->visible() != visible) { | 1813 if (mic_search_view_->visible() != visible) { |
1675 mic_search_view_->SetVisible(visible); | 1814 mic_search_view_->SetVisible(visible); |
1676 Layout(); | 1815 Layout(); |
1677 } | 1816 } |
1678 } | 1817 } |
1679 | 1818 |
OLD | NEW |