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" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 generated_credit_card_view_(NULL), | 216 generated_credit_card_view_(NULL), |
218 open_pdf_in_reader_view_(NULL), | 217 open_pdf_in_reader_view_(NULL), |
219 manage_passwords_icon_view_(NULL), | 218 manage_passwords_icon_view_(NULL), |
220 translate_icon_view_(NULL), | 219 translate_icon_view_(NULL), |
221 star_view_(NULL), | 220 star_view_(NULL), |
222 search_button_(NULL), | 221 search_button_(NULL), |
223 is_popup_mode_(is_popup_mode), | 222 is_popup_mode_(is_popup_mode), |
224 show_focus_rect_(false), | 223 show_focus_rect_(false), |
225 template_url_service_(NULL), | 224 template_url_service_(NULL), |
226 dropdown_animation_offset_(0), | 225 dropdown_animation_offset_(0), |
227 animated_host_label_(NULL), | 226 current_omnibox_offset_(0), |
227 starting_omnibox_offset_(0), | |
228 current_omnibox_leading_inset_(0), | |
229 starting_omnibox_leading_inset_(0), | |
230 current_omnibox_width_(0), | |
231 ending_omnibox_width_(0), | |
228 weak_ptr_factory_(this) { | 232 weak_ptr_factory_(this) { |
229 edit_bookmarks_enabled_.Init( | 233 edit_bookmarks_enabled_.Init( |
230 prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 234 prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
231 base::Bind(&LocationBarView::Update, base::Unretained(this), | 235 base::Bind(&LocationBarView::Update, base::Unretained(this), |
232 static_cast<content::WebContents*>(NULL))); | 236 static_cast<content::WebContents*>(NULL))); |
233 | 237 |
234 if (browser_) | 238 if (browser_) |
235 browser_->search_model()->AddObserver(this); | 239 browser_->search_model()->AddObserver(this); |
236 } | 240 } |
237 | 241 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 313 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
310 ime_inline_autocomplete_view_->set_background( | 314 ime_inline_autocomplete_view_->set_background( |
311 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 315 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
312 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 316 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
313 ime_inline_autocomplete_view_->SetEnabledColor( | 317 ime_inline_autocomplete_view_->SetEnabledColor( |
314 GetNativeTheme()->GetSystemColor( | 318 GetNativeTheme()->GetSystemColor( |
315 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 319 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
316 ime_inline_autocomplete_view_->SetVisible(false); | 320 ime_inline_autocomplete_view_->SetVisible(false); |
317 AddChildView(ime_inline_autocomplete_view_); | 321 AddChildView(ime_inline_autocomplete_view_); |
318 | 322 |
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); | 323 origin_chip_view_ = new OriginChipView(this, profile(), font_list); |
324 origin_chip_view_->SetFocusable(false); | 324 origin_chip_view_->SetFocusable(false); |
325 origin_chip_view_->set_drag_controller(this); | 325 origin_chip_view_->set_drag_controller(this); |
326 AddChildView(origin_chip_view_); | 326 AddChildView(origin_chip_view_); |
327 | 327 |
328 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); | 328 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); |
329 selected_keyword_view_ = new SelectedKeywordView( | 329 selected_keyword_view_ = new SelectedKeywordView( |
330 bubble_font_list, text_color, background_color, profile()); | 330 bubble_font_list, text_color, background_color, profile()); |
331 AddChildView(selected_keyword_view_); | 331 AddChildView(selected_keyword_view_); |
332 | 332 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 search_button_border->SetPainter(true, views::Button::STATE_HOVERED, NULL); | 417 search_button_border->SetPainter(true, views::Button::STATE_HOVERED, NULL); |
418 search_button_border->SetPainter(true, views::Button::STATE_PRESSED, NULL); | 418 search_button_border->SetPainter(true, views::Button::STATE_PRESSED, NULL); |
419 search_button_border->SetPainter(true, views::Button::STATE_DISABLED, NULL); | 419 search_button_border->SetPainter(true, views::Button::STATE_DISABLED, NULL); |
420 search_button_->SetBorder(search_button_border.PassAs<views::Border>()); | 420 search_button_->SetBorder(search_button_border.PassAs<views::Border>()); |
421 const int kSearchButtonWidth = 56; | 421 const int kSearchButtonWidth = 56; |
422 search_button_->set_min_size(gfx::Size(kSearchButtonWidth, 0)); | 422 search_button_->set_min_size(gfx::Size(kSearchButtonWidth, 0)); |
423 search_button_->SetVisible(false); | 423 search_button_->SetVisible(false); |
424 AddChildView(search_button_); | 424 AddChildView(search_button_); |
425 | 425 |
426 show_url_animation_.reset(new gfx::SlideAnimation(this)); | 426 show_url_animation_.reset(new gfx::SlideAnimation(this)); |
427 show_url_animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); | 427 show_url_animation_->SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); |
428 show_url_animation_->SetSlideDuration(200); | 428 show_url_animation_->SetSlideDuration(200); |
429 | 429 |
430 hide_url_animation_.reset(new gfx::SlideAnimation(this)); | 430 hide_url_animation_.reset(new gfx::SlideAnimation(this)); |
431 hide_url_animation_->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN); | 431 hide_url_animation_->SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN); |
432 hide_url_animation_->SetSlideDuration(200); | 432 hide_url_animation_->SetSlideDuration(175); |
433 | 433 |
434 content::Source<Profile> profile_source = content::Source<Profile>(profile()); | 434 content::Source<Profile> profile_source = content::Source<Profile>(profile()); |
435 registrar_.Add(this, | 435 registrar_.Add(this, |
436 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 436 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
437 profile_source); | 437 profile_source); |
438 registrar_.Add( | 438 registrar_.Add( |
439 this, chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, profile_source); | 439 this, chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, profile_source); |
440 registrar_.Add(this, | 440 registrar_.Add(this, |
441 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 441 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
442 profile_source); | 442 profile_source); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 if (star_view_) | 551 if (star_view_) |
552 star_view_->SetToggled(on); | 552 star_view_->SetToggled(on); |
553 } | 553 } |
554 | 554 |
555 void LocationBarView::SetTranslateIconToggled(bool on) { | 555 void LocationBarView::SetTranslateIconToggled(bool on) { |
556 translate_icon_view_->SetToggled(on); | 556 translate_icon_view_->SetToggled(on); |
557 } | 557 } |
558 | 558 |
559 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { | 559 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { |
560 gfx::Point origin(omnibox_view_->bounds().origin()); | 560 gfx::Point origin(omnibox_view_->bounds().origin()); |
561 // If the UI layout is RTL, the coordinate system is not transformed and | 561 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); | 562 views::View::ConvertPointToScreen(this, &origin); |
567 return origin; | 563 return origin; |
568 } | 564 } |
569 | 565 |
570 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { | 566 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { |
571 ime_inline_autocomplete_view_->SetText(text); | 567 ime_inline_autocomplete_view_->SetText(text); |
572 ime_inline_autocomplete_view_->SetVisible(!text.empty()); | 568 ime_inline_autocomplete_view_->SetVisible(!text.empty()); |
573 } | 569 } |
574 | 570 |
575 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { | 571 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { |
576 if (suggested_text_view_->text() != text) { | 572 if (suggested_text_view_->text() != text) { |
577 suggested_text_view_->SetText(text); | 573 suggested_text_view_->SetText(text); |
578 suggested_text_view_->SetVisible(!text.empty()); | 574 suggested_text_view_->SetVisible(!text.empty()); |
579 Layout(); | 575 Layout(); |
580 SchedulePaint(); | 576 SchedulePaint(); |
581 } | 577 } |
582 } | 578 } |
583 | 579 |
584 base::string16 LocationBarView::GetGrayTextAutocompletion() const { | 580 base::string16 LocationBarView::GetGrayTextAutocompletion() const { |
585 return HasValidSuggestText() ? suggested_text_view_->text() | 581 return HasValidSuggestText() ? |
586 : base::string16(); | 582 suggested_text_view_->text() : base::string16(); |
587 } | 583 } |
588 | 584 |
589 void LocationBarView::SetShowFocusRect(bool show) { | 585 void LocationBarView::SetShowFocusRect(bool show) { |
590 show_focus_rect_ = show; | 586 show_focus_rect_ = show; |
591 SchedulePaint(); | 587 SchedulePaint(); |
592 } | 588 } |
593 | 589 |
594 void LocationBarView::SelectAll() { | 590 void LocationBarView::SelectAll() { |
595 omnibox_view_->SelectAll(true); | 591 omnibox_view_->SelectAll(true); |
596 } | 592 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 | 727 |
732 min_size.set_width( | 728 min_size.set_width( |
733 leading_width + omnibox_view_->GetMinimumSize().width() + trailing_width); | 729 leading_width + omnibox_view_->GetMinimumSize().width() + trailing_width); |
734 return min_size; | 730 return min_size; |
735 } | 731 } |
736 | 732 |
737 void LocationBarView::Layout() { | 733 void LocationBarView::Layout() { |
738 if (!IsInitialized()) | 734 if (!IsInitialized()) |
739 return; | 735 return; |
740 | 736 |
741 animated_host_label_->SetVisible(false); | |
742 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); | 737 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); |
743 selected_keyword_view_->SetVisible(false); | 738 selected_keyword_view_->SetVisible(false); |
744 location_icon_view_->SetVisible(false); | 739 location_icon_view_->SetVisible(false); |
745 ev_bubble_view_->SetVisible(false); | 740 ev_bubble_view_->SetVisible(false); |
746 keyword_hint_view_->SetVisible(false); | 741 keyword_hint_view_->SetVisible(false); |
747 | 742 |
748 LocationBarLayout leading_decorations( | 743 LocationBarLayout leading_decorations( |
749 LocationBarLayout::LEFT_EDGE, | 744 LocationBarLayout::LEFT_EDGE, |
750 kItemPadding - GetEditLeadingInternalSpace()); | 745 kItemPadding - GetEditLeadingInternalSpace()); |
751 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, | 746 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, |
752 kItemPadding); | 747 kItemPadding); |
753 | 748 |
754 // Show and position the animated host label used in the show and hide URL | 749 const int origin_chip_preferred_width = |
755 // animations. | 750 origin_chip_view_->GetPreferredSize().width(); |
756 if (show_url_animation_->is_animating() || | 751 const int origin_chip_width = |
757 hide_url_animation_->is_animating()) { | 752 origin_chip_view_->visible() ? origin_chip_preferred_width : 0; |
758 WebContents* web_contents = GetWebContents(); | 753 // 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(); | 754 // it's not visible, so we can calculate the correct animation values below |
760 const base::string16 host = | 755 // when switching to tabs that have the origin chip hidden. |
761 OriginChip::LabelFromURLForProfile(url, profile()); | 756 origin_chip_view_->SetBounds(0, 0, origin_chip_preferred_width, height()); |
762 animated_host_label_->SetText(host); | 757 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 | 758 |
799 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; | 759 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; |
800 const base::string16 keyword(omnibox_view_->model()->keyword()); | 760 const base::string16 keyword(omnibox_view_->model()->keyword()); |
801 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 761 // 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 | 762 // 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 | 763 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
804 // hits ctrl-d). | 764 // hits ctrl-d). |
805 const int location_height = GetInternalHeight(false); | 765 const int location_height = GetInternalHeight(false); |
806 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); | 766 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); |
807 if (ShouldShowKeywordBubble()) { | 767 if (ShouldShowKeywordBubble()) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 | 872 |
913 int location_needed_width = omnibox_view_->GetTextWidth(); | 873 int location_needed_width = omnibox_view_->GetTextWidth(); |
914 int available_width = entry_width - location_needed_width; | 874 int available_width = entry_width - location_needed_width; |
915 // The bounds must be wide enough for all the decorations to fit. | 875 // The bounds must be wide enough for all the decorations to fit. |
916 gfx::Rect location_bounds( | 876 gfx::Rect location_bounds( |
917 origin_chip_width + horizontal_edge_thickness, vertical_edge_thickness(), | 877 origin_chip_width + horizontal_edge_thickness, vertical_edge_thickness(), |
918 std::max(full_width, full_width - entry_width), location_height); | 878 std::max(full_width, full_width - entry_width), location_height); |
919 leading_decorations.LayoutPass3(&location_bounds, &available_width); | 879 leading_decorations.LayoutPass3(&location_bounds, &available_width); |
920 trailing_decorations.LayoutPass3(&location_bounds, &available_width); | 880 trailing_decorations.LayoutPass3(&location_bounds, &available_width); |
921 | 881 |
882 // Calculate the target omnibox offset. We have to do this in Layout, after | |
Justin Donnelly
2014/05/29 21:37:29
It took me a pretty good while to understand this
Peter Kasting
2014/05/29 23:32:16
Done.
| |
883 // |origin_chip_view_| is laid out, because this may affect the host label | |
884 // offset in the origin chip. | |
885 const base::string16& chip_text(origin_chip_view_->host_label_text()); | |
886 // If the chip is clicked, the omnibox text will become the toolbar model's | |
887 // formatted URL. We can't ask the omnibox for its current text, because | |
888 // while the chip is visible the current text is empty. | |
889 const base::string16& omnibox_text(GetToolbarModel()->GetFormattedURL()); | |
890 size_t chip_text_offset = omnibox_text.find(chip_text); | |
891 const gfx::FontList& font_list = omnibox_view_->GetFontList(); | |
892 const int chip_text_width = gfx::GetStringWidth(chip_text, font_list); | |
893 const int old_starting_offset = starting_omnibox_offset_; | |
894 const int old_starting_leading_inset = starting_omnibox_leading_inset_; | |
895 const int old_ending_width = ending_omnibox_width_; | |
896 starting_omnibox_offset_ = current_omnibox_offset_ = 0; | |
897 starting_omnibox_leading_inset_ = current_omnibox_leading_inset_ = 0; | |
898 ending_omnibox_width_ = current_omnibox_width_ = chip_text_width; | |
899 if (chip_text_offset < omnibox_text.length()) { | |
900 if (base::i18n::IsRTL()) | |
901 chip_text_offset += chip_text.length(); | |
902 base::string16 extra_omnibox_text(base::i18n::IsRTL() ? | |
903 omnibox_text.substr(chip_text_offset) : | |
904 omnibox_text.substr(0, chip_text_offset)); | |
905 starting_omnibox_leading_inset_ = | |
906 gfx::GetStringWidth(extra_omnibox_text, font_list); | |
907 starting_omnibox_offset_ = origin_chip_view_->HostLabelOffset() - | |
908 starting_omnibox_leading_inset_; | |
909 ending_omnibox_width_ = gfx::GetStringWidth(omnibox_text, font_list); | |
910 } | |
911 | |
912 // End the animations immediately if the parameters have changed. | |
913 if ((starting_omnibox_offset_ != old_starting_offset) || | |
914 (starting_omnibox_leading_inset_ != old_starting_leading_inset) || | |
915 (ending_omnibox_width_ != old_ending_width)) | |
916 EndOriginChipAnimations(); | |
917 | |
918 // Also end the animations immediately if there's nothing to animate. | |
919 const ui::NativeTheme* native_theme = GetNativeTheme(); | |
920 const SkColor ending_selection_text_color = native_theme->GetSystemColor( | |
921 ui::NativeTheme::kColorId_TextfieldSelectionColor); | |
922 const SkColor ending_selection_background_color = | |
923 native_theme->GetSystemColor( | |
924 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); | |
925 if ((starting_omnibox_offset_ == 0) && | |
926 (starting_omnibox_leading_inset_ == 0) && | |
927 (ending_omnibox_width_ == chip_text_width) && | |
928 (hide_url_animation_->is_animating() || | |
929 ((ending_selection_text_color == | |
930 origin_chip_view_->pressed_text_color()) && | |
931 (ending_selection_background_color == | |
932 origin_chip_view_->pressed_background_color())))) | |
933 EndOriginChipAnimations(); | |
934 | |
935 if (show_url_animation_->is_animating()) { | |
936 omnibox_view_->SetSelectionTextColor(gfx::Tween::ColorValueBetween( | |
937 show_url_animation_->GetCurrentValue(), | |
938 origin_chip_view_->pressed_text_color(), | |
939 ending_selection_text_color)); | |
940 omnibox_view_->SetSelectionBackgroundColor(gfx::Tween::ColorValueBetween( | |
941 show_url_animation_->GetCurrentValue(), | |
942 origin_chip_view_->pressed_background_color(), | |
943 ending_selection_background_color)); | |
944 current_omnibox_offset_ = | |
945 show_url_animation_->CurrentValueBetween(starting_omnibox_offset_, 0); | |
946 current_omnibox_leading_inset_ = show_url_animation_->CurrentValueBetween( | |
947 starting_omnibox_leading_inset_, 0); | |
948 current_omnibox_width_ = show_url_animation_->CurrentValueBetween( | |
949 chip_text_width, ending_omnibox_width_); | |
950 } else if (hide_url_animation_->is_animating()) { | |
951 current_omnibox_offset_ = | |
952 hide_url_animation_->CurrentValueBetween(0, starting_omnibox_offset_); | |
953 current_omnibox_leading_inset_ = hide_url_animation_->CurrentValueBetween( | |
954 0, starting_omnibox_leading_inset_); | |
955 current_omnibox_width_ = hide_url_animation_->CurrentValueBetween( | |
956 ending_omnibox_width_, chip_text_width); | |
957 } | |
958 // Contract |available_width| is necessary, but never expand it. This way, | |
Justin Donnelly
2014/05/29 21:37:29
s/is necessary/as necessary/
Peter Kasting
2014/05/29 23:32:16
Done.
| |
959 // we'll never draw suggested text at first and then have it disappear | |
960 // midway through the animation. | |
961 if (current_omnibox_offset_ > 0) | |
962 available_width -= current_omnibox_offset_; | |
963 location_bounds.Inset(current_omnibox_offset_, 0, 0, 0); | |
964 | |
922 // Layout out the suggested text view right aligned to the location | 965 // 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 | 966 // 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 | 967 // 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, | 968 // suggested text. If we can't it means either the suggested text is too big, |
926 // or the user has scrolled. | 969 // or the user has scrolled. |
927 | 970 |
928 // TODO(sky): We could potentially adjust this to take into account suggested | 971 // 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 | 972 // 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 | 973 // showing keyword hints and suggested text is minimal and we're not confident |
931 // this is the right approach for suggested text. | 974 // this is the right approach for suggested text. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1031 | 1074 |
1032 if (contents) | 1075 if (contents) |
1033 omnibox_view_->OnTabChanged(contents); | 1076 omnibox_view_->OnTabChanged(contents); |
1034 else | 1077 else |
1035 omnibox_view_->Update(); | 1078 omnibox_view_->Update(); |
1036 | 1079 |
1037 OnChanged(); // NOTE: Calls Layout(). | 1080 OnChanged(); // NOTE: Calls Layout(). |
1038 } | 1081 } |
1039 | 1082 |
1040 void LocationBarView::ShowURL() { | 1083 void LocationBarView::ShowURL() { |
1084 // Start the animation before calling ShowURL(), since the latter eventually | |
1085 // calls back to Layout(), and if the animation is not marked as "running", | |
1086 // we'll draw the omnibox in its final position briefly until the first | |
1087 // animation callback reaches us. | |
1041 if (chrome::ShouldDisplayOriginChip()) { | 1088 if (chrome::ShouldDisplayOriginChip()) { |
1042 omnibox_view_->SetVisible(false); | 1089 if (hide_url_animation_->is_animating()) { |
1043 omnibox_view_->ShowURL(); | 1090 const double show_value = GetValueForAnimation(false); |
1044 show_url_animation_->Show(); | 1091 hide_url_animation_->Reset(); |
1045 } else { | 1092 show_url_animation_->Show(); |
1046 omnibox_view_->ShowURL(); | 1093 // This must be done after calling Show() and is not equivalent to |
1094 // Reset(n). | |
Justin Donnelly
2014/05/29 21:37:29
Can you add a note as to how it's not equivalent?
Peter Kasting
2014/05/29 23:32:16
Done.
| |
1095 show_url_animation_->SetCurrentValue(show_value); | |
1096 } else { | |
1097 show_url_animation_->Show(); | |
1098 } | |
1047 } | 1099 } |
1100 omnibox_view_->ShowURL(); | |
1101 } | |
1102 | |
1103 void LocationBarView::EndOriginChipAnimations() { | |
1104 show_url_animation_->End(); | |
1105 hide_url_animation_->End(); | |
1106 origin_chip_view_->CancelFade(); | |
1048 } | 1107 } |
1049 | 1108 |
1050 ToolbarModel* LocationBarView::GetToolbarModel() { | 1109 ToolbarModel* LocationBarView::GetToolbarModel() { |
1051 return delegate_->GetToolbarModel(); | 1110 return delegate_->GetToolbarModel(); |
1052 } | 1111 } |
1053 | 1112 |
1054 WebContents* LocationBarView::GetWebContents() { | 1113 WebContents* LocationBarView::GetWebContents() { |
1055 return delegate_->GetWebContents(); | 1114 return delegate_->GetWebContents(); |
1056 } | 1115 } |
1057 | 1116 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 bool LocationBarView::ShouldShowKeywordBubble() const { | 1294 bool LocationBarView::ShouldShowKeywordBubble() const { |
1236 return !omnibox_view_->model()->keyword().empty() && | 1295 return !omnibox_view_->model()->keyword().empty() && |
1237 !omnibox_view_->model()->is_keyword_hint(); | 1296 !omnibox_view_->model()->is_keyword_hint(); |
1238 } | 1297 } |
1239 | 1298 |
1240 bool LocationBarView::ShouldShowEVBubble() const { | 1299 bool LocationBarView::ShouldShowEVBubble() const { |
1241 return !chrome::ShouldDisplayOriginChip() && | 1300 return !chrome::ShouldDisplayOriginChip() && |
1242 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); | 1301 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); |
1243 } | 1302 } |
1244 | 1303 |
1245 void LocationBarView::OnShowURLAnimationEnded() { | 1304 double LocationBarView::GetValueForAnimation(bool hide) const { |
1246 animated_host_label_->SetVisible(false); | 1305 int calculated_offset; |
1247 omnibox_view_->SetVisible(true); | 1306 const gfx::Tween::Type tween_type = |
1248 omnibox_view_->FadeIn(); | 1307 hide ? gfx::Tween::FAST_OUT_LINEAR_IN : gfx::Tween::LINEAR_OUT_SLOW_IN; |
Justin Donnelly
2014/05/29 21:37:29
These should probably be constants in this file to
Peter Kasting
2014/05/29 23:32:16
Done.
| |
1249 omnibox_view_->SetFocus(); | 1308 int start_offset = starting_omnibox_offset_, end_offset = 0; |
1250 | 1309 if (hide) |
1251 // Sometimes the selection established by OmniboxView::ShowURL() is lost at | 1310 std::swap(start_offset, end_offset); |
1252 // the call to SetFocus() above. Select all again to be sure. | 1311 const int desired_offset = abs(current_omnibox_offset_); |
1253 // TODO(jdonnelly): Figure out why the selection is sometimes lost and | 1312 // Binary-search the value space (0 <= value <= 1) to find the appropriate |
1254 // implement a more principled fix. | 1313 // position. We only bother to iterate to within 1/64 of the desired value, |
1255 omnibox_view_->SelectAll(true); | 1314 // because the longer of the two animations will only run for twelve frames |
1315 // anyway (200 ms * 60 Hz), so at this point we'll have a maximum error of | |
1316 // less than a fifth of an animation frame, which the user isn't going to | |
1317 // notice. | |
1318 // | |
1319 // We have to use this method because Tween::CalculateValue() is not | |
1320 // necessarily easily invertible. Luckily, this only runs when the user | |
1321 // reverses the animation (rare), and the limit on how many iterations we'll | |
1322 // do ensures the cost is unnoticeable. | |
1323 double value = 0.5; | |
1324 double step = value / 2; | |
1325 do { | |
1326 calculated_offset = abs(gfx::Tween::IntValueBetween( | |
1327 gfx::Tween::CalculateValue(tween_type, value), start_offset, | |
1328 end_offset)); | |
1329 if (calculated_offset < desired_offset) | |
1330 value += step; | |
1331 else if (calculated_offset > desired_offset) | |
1332 value -= step; | |
1333 step /= 2; | |
1334 } while ((calculated_offset != desired_offset) && (step >= (1.0 / 64))); | |
1335 return value; | |
1256 } | 1336 } |
1257 | 1337 |
1258 void LocationBarView::OnHideURLAnimationEnded() { | 1338 void LocationBarView::ResetShowAnimationAndColors() { |
1259 animated_host_label_->SetVisible(false); | 1339 show_url_animation_->Reset(); |
1260 omnibox_view_->HideURL(); | 1340 omnibox_view_->UseDefaultSelectionTextColor(); |
1261 omnibox_view_->SetVisible(true); | 1341 omnibox_view_->UseDefaultSelectionBackgroundColor(); |
1262 origin_chip_view_->FadeIn(); | |
1263 } | 1342 } |
1264 | 1343 |
1265 //////////////////////////////////////////////////////////////////////////////// | 1344 //////////////////////////////////////////////////////////////////////////////// |
1266 // LocationBarView, private LocationBar implementation: | 1345 // LocationBarView, private LocationBar implementation: |
1267 | 1346 |
1268 void LocationBarView::ShowFirstRunBubble() { | 1347 void LocationBarView::ShowFirstRunBubble() { |
1269 // Wait until search engines have loaded to show the first run bubble. | 1348 // Wait until search engines have loaded to show the first run bubble. |
1270 TemplateURLService* url_service = | 1349 TemplateURLService* url_service = |
1271 TemplateURLServiceFactory::GetForProfile(profile()); | 1350 TemplateURLServiceFactory::GetForProfile(profile()); |
1272 if (!url_service->loaded()) { | 1351 if (!url_service->loaded()) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1347 SchedulePaint(); | 1426 SchedulePaint(); |
1348 } | 1427 } |
1349 | 1428 |
1350 void LocationBarView::UpdateGeneratedCreditCardView() { | 1429 void LocationBarView::UpdateGeneratedCreditCardView() { |
1351 generated_credit_card_view_->Update(); | 1430 generated_credit_card_view_->Update(); |
1352 Layout(); | 1431 Layout(); |
1353 SchedulePaint(); | 1432 SchedulePaint(); |
1354 } | 1433 } |
1355 | 1434 |
1356 void LocationBarView::SaveStateToContents(WebContents* contents) { | 1435 void LocationBarView::SaveStateToContents(WebContents* contents) { |
1436 // If we're about to switch tabs, complete any current animations, so that if | |
1437 // the user is in the midst of hiding the URL, when he returns to this tab, | |
1438 // the URL will be hidden rather than shown. | |
1439 // NOTE: This must be called before SaveStateToTab(). | |
1440 EndOriginChipAnimations(); | |
1357 omnibox_view_->SaveStateToTab(contents); | 1441 omnibox_view_->SaveStateToTab(contents); |
1358 } | 1442 } |
1359 | 1443 |
1360 const OmniboxView* LocationBarView::GetOmniboxView() const { | 1444 const OmniboxView* LocationBarView::GetOmniboxView() const { |
1361 return omnibox_view_; | 1445 return omnibox_view_; |
1362 } | 1446 } |
1363 | 1447 |
1364 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { | 1448 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { |
1365 return this; | 1449 return this; |
1366 } | 1450 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1459 const int kBorderCornerRadius = 2; | 1543 const int kBorderCornerRadius = 2; |
1460 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1544 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
1461 } | 1545 } |
1462 | 1546 |
1463 // The border itself will be drawn in PaintChildren() since it includes an | 1547 // The border itself will be drawn in PaintChildren() since it includes an |
1464 // inner shadow which should be drawn over the contents. | 1548 // inner shadow which should be drawn over the contents. |
1465 } | 1549 } |
1466 | 1550 |
1467 void LocationBarView::PaintChildren(gfx::Canvas* canvas, | 1551 void LocationBarView::PaintChildren(gfx::Canvas* canvas, |
1468 const views::CullSet& cull_set) { | 1552 const views::CullSet& cull_set) { |
1469 // Paint all the children except for the origin chip and the search button, | 1553 // Paint all the children except for the omnibox itself, which may need to be |
1554 // clipped if it's animating in, and the origin chip and the search button, | |
1470 // which will be painted after the border. | 1555 // which will be painted after the border. |
1471 for (int i = 0, count = child_count(); i < count; ++i) { | 1556 for (int i = 0, count = child_count(); i < count; ++i) { |
1472 if (!child_at(i)->layer() && | 1557 views::View* child = child_at(i); |
1473 (child_at(i) != origin_chip_view_) && | 1558 if (!child->layer() && (child != omnibox_view_) && |
1474 (child_at(i) != search_button_)) | 1559 (child != origin_chip_view_) && (child != search_button_)) |
1475 child_at(i)->Paint(canvas, cull_set); | 1560 child->Paint(canvas, cull_set); |
1561 } | |
1562 | |
1563 { | |
1564 gfx::ScopedCanvas scoped_canvas(canvas); | |
1565 if (show_url_animation_->is_animating() || | |
1566 hide_url_animation_->is_animating()) { | |
1567 gfx::Rect clip_rect(omnibox_view_->bounds()); | |
1568 clip_rect.Inset(current_omnibox_leading_inset_, 0, 0, 0); | |
1569 clip_rect.set_width(current_omnibox_width_); | |
1570 clip_rect.set_x(GetMirroredXForRect(clip_rect)); | |
1571 canvas->ClipRect(clip_rect); | |
1572 } | |
1573 omnibox_view_->Paint(canvas, cull_set); | |
1476 } | 1574 } |
1477 | 1575 |
1478 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | 1576 // 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 | 1577 // the focus rect to appear on top of children we paint here rather than |
1480 // OnPaint(). | 1578 // OnPaint(). |
1481 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | 1579 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. |
1482 if (show_focus_rect_ && HasFocus()) | 1580 if (show_focus_rect_ && HasFocus()) |
1483 canvas->DrawFocusRect(omnibox_view_->bounds()); | 1581 canvas->DrawFocusRect(omnibox_view_->bounds()); |
1484 | 1582 |
1485 // Maximized popup windows don't draw the horizontal edges. We implement this | 1583 // 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) && | 1663 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && |
1566 (toolbar_model->WouldPerformSearchTermReplacement(true) || | 1664 (toolbar_model->WouldPerformSearchTermReplacement(true) || |
1567 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && | 1665 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && |
1568 toolbar_model->input_in_progress()))); | 1666 toolbar_model->input_in_progress()))); |
1569 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); | 1667 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); |
1570 search_button_->SetImage( | 1668 search_button_->SetImage( |
1571 views::Button::STATE_NORMAL, | 1669 views::Button::STATE_NORMAL, |
1572 *GetThemeProvider()->GetImageSkiaNamed((icon_id == IDR_OMNIBOX_SEARCH) ? | 1670 *GetThemeProvider()->GetImageSkiaNamed((icon_id == IDR_OMNIBOX_SEARCH) ? |
1573 IDR_OMNIBOX_SEARCH_BUTTON_LOUPE : IDR_OMNIBOX_SEARCH_BUTTON_ARROW)); | 1671 IDR_OMNIBOX_SEARCH_BUTTON_LOUPE : IDR_OMNIBOX_SEARCH_BUTTON_ARROW)); |
1574 | 1672 |
1575 if (origin_chip_view_->visible()) | 1673 origin_chip_view_->OnChanged(); |
1576 origin_chip_view_->OnChanged(); | |
1577 | 1674 |
1578 Layout(); | 1675 Layout(); |
1579 SchedulePaint(); | 1676 SchedulePaint(); |
1580 } | 1677 } |
1581 | 1678 |
1582 void LocationBarView::OnSetFocus() { | 1679 void LocationBarView::OnSetFocus() { |
1583 GetFocusManager()->SetFocusedView(this); | 1680 GetFocusManager()->SetFocusedView(this); |
1584 } | 1681 } |
1585 | 1682 |
1586 InstantController* LocationBarView::GetInstant() { | 1683 InstantController* LocationBarView::GetInstant() { |
1587 return delegate_->GetInstant(); | 1684 return delegate_->GetInstant(); |
1588 } | 1685 } |
1589 | 1686 |
1590 const ToolbarModel* LocationBarView::GetToolbarModel() const { | 1687 const ToolbarModel* LocationBarView::GetToolbarModel() const { |
1591 return delegate_->GetToolbarModel(); | 1688 return delegate_->GetToolbarModel(); |
1592 } | 1689 } |
1593 | 1690 |
1594 void LocationBarView::HideURL() { | 1691 void LocationBarView::HideURL() { |
Justin Donnelly
2014/05/29 21:37:29
Currently this method is only called if the origin
Peter Kasting
2014/05/29 23:32:16
I'm not keen on conditionals that should never be
| |
1595 omnibox_view_->SetVisible(false); | 1692 if (show_url_animation_->is_animating()) { |
1596 hide_url_animation_->Show(); | 1693 const double hide_value = GetValueForAnimation(true); |
1694 ResetShowAnimationAndColors(); | |
1695 hide_url_animation_->Show(); | |
1696 // This must be done after calling Show() and is not equivalent to Reset(n). | |
1697 hide_url_animation_->SetCurrentValue(hide_value); | |
1698 } else { | |
1699 hide_url_animation_->Show(); | |
1700 } | |
1597 } | 1701 } |
1598 | 1702 |
1599 //////////////////////////////////////////////////////////////////////////////// | 1703 //////////////////////////////////////////////////////////////////////////////// |
1600 // LocationBarView, private DropdownBarHostDelegate implementation: | 1704 // LocationBarView, private DropdownBarHostDelegate implementation: |
1601 | 1705 |
1602 void LocationBarView::SetFocusAndSelection(bool select_all) { | 1706 void LocationBarView::SetFocusAndSelection(bool select_all) { |
1603 FocusLocation(select_all); | 1707 FocusLocation(select_all); |
1604 } | 1708 } |
1605 | 1709 |
1606 void LocationBarView::SetAnimationOffset(int offset) { | 1710 void LocationBarView::SetAnimationOffset(int offset) { |
1607 dropdown_animation_offset_ = offset; | 1711 dropdown_animation_offset_ = offset; |
1608 } | 1712 } |
1609 | 1713 |
1610 //////////////////////////////////////////////////////////////////////////////// | 1714 //////////////////////////////////////////////////////////////////////////////// |
1611 // LocationBarView, private gfx::AnimationDelegate implementation: | 1715 // LocationBarView, private gfx::AnimationDelegate implementation: |
1612 | 1716 |
1613 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) { | 1717 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) { |
1614 if (animation == show_url_animation_.get() || | 1718 DCHECK((animation == show_url_animation_.get()) || |
1615 animation == hide_url_animation_.get()) { | 1719 (animation == hide_url_animation_.get())); |
1616 Layout(); | 1720 Layout(); |
1617 SchedulePaint(); | 1721 SchedulePaint(); |
1618 } | |
1619 } | 1722 } |
1620 | 1723 |
1621 void LocationBarView::AnimationEnded(const gfx::Animation* animation) { | 1724 void LocationBarView::AnimationEnded(const gfx::Animation* animation) { |
1622 if (animation == show_url_animation_.get()) { | 1725 if (animation == show_url_animation_.get()) { |
1623 show_url_animation_->Reset(); | 1726 ResetShowAnimationAndColors(); |
1624 OnShowURLAnimationEnded(); | 1727 Layout(); |
1625 } else if (animation == hide_url_animation_.get()) { | 1728 SchedulePaint(); |
1729 } else { | |
1730 DCHECK(animation == hide_url_animation_.get()); | |
1626 hide_url_animation_->Reset(); | 1731 hide_url_animation_->Reset(); |
1627 OnHideURLAnimationEnded(); | 1732 origin_chip_view_->FadeIn(); |
1733 omnibox_view_->HideURL(); // Calls OnChanged(), triggering layout. | |
1628 } | 1734 } |
1629 } | 1735 } |
1630 | 1736 |
1631 //////////////////////////////////////////////////////////////////////////////// | 1737 //////////////////////////////////////////////////////////////////////////////// |
1632 // LocationBarView, private TemplateURLServiceObserver implementation: | 1738 // LocationBarView, private TemplateURLServiceObserver implementation: |
1633 | 1739 |
1634 void LocationBarView::OnTemplateURLServiceChanged() { | 1740 void LocationBarView::OnTemplateURLServiceChanged() { |
1635 template_url_service_->RemoveObserver(this); | 1741 template_url_service_->RemoveObserver(this); |
1636 template_url_service_ = NULL; | 1742 template_url_service_ = NULL; |
1637 // If the browser is no longer active, let's not show the info bubble, as this | 1743 // 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, | 1776 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1671 const SearchModel::State& new_state) { | 1777 const SearchModel::State& new_state) { |
1672 const bool visible = !GetToolbarModel()->input_in_progress() && | 1778 const bool visible = !GetToolbarModel()->input_in_progress() && |
1673 new_state.voice_search_supported; | 1779 new_state.voice_search_supported; |
1674 if (mic_search_view_->visible() != visible) { | 1780 if (mic_search_view_->visible() != visible) { |
1675 mic_search_view_->SetVisible(visible); | 1781 mic_search_view_->SetVisible(visible); |
1676 Layout(); | 1782 Layout(); |
1677 } | 1783 } |
1678 } | 1784 } |
1679 | 1785 |
OLD | NEW |