| 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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/command_updater.h" | 15 #include "chrome/browser/command_updater.h" |
| 16 #include "chrome/browser/defaults.h" | 16 #include "chrome/browser/defaults.h" |
| 17 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 17 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 18 #include "chrome/browser/extensions/extension_action.h" | 18 #include "chrome/browser/extensions/extension_action.h" |
| 19 #include "chrome/browser/extensions/extension_action_manager.h" | 19 #include "chrome/browser/extensions/extension_action_manager.h" |
| 20 #include "chrome/browser/extensions/extension_util.h" | 20 #include "chrome/browser/extensions/extension_util.h" |
| 21 #include "chrome/browser/extensions/location_bar_controller.h" | 21 #include "chrome/browser/extensions/location_bar_controller.h" |
| 22 #include "chrome/browser/extensions/tab_helper.h" | 22 #include "chrome/browser/extensions/tab_helper.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/search/instant_service.h" | 24 #include "chrome/browser/search/instant_service.h" |
| 25 #include "chrome/browser/search/instant_service_factory.h" | 25 #include "chrome/browser/search/instant_service_factory.h" |
| 26 #include "chrome/browser/search/search.h" | 26 #include "chrome/browser/search/search.h" |
| 27 #include "chrome/browser/search_engines/template_url_service_factory.h" | 27 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 28 #include "chrome/browser/translate/chrome_translate_client.h" | 28 #include "chrome/browser/translate/chrome_translate_client.h" |
| 29 #include "chrome/browser/translate/translate_service.h" | 29 #include "chrome/browser/translate/translate_service.h" |
| 30 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
| 30 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
| 32 #include "chrome/browser/ui/browser_instant_controller.h" | 33 #include "chrome/browser/ui/browser_instant_controller.h" |
| 33 #include "chrome/browser/ui/browser_window.h" | 34 #include "chrome/browser/ui/browser_window.h" |
| 34 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 35 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 35 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 36 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 37 #include "chrome/browser/ui/view_ids.h" | 38 #include "chrome/browser/ui/view_ids.h" |
| 38 #include "chrome/browser/ui/views/browser_dialogs.h" | 39 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 39 #include "chrome/browser/ui/views/layout_constants.h" | 40 #include "chrome/browser/ui/views/layout_constants.h" |
| 40 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 41 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
| 41 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 42 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
| 42 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 43 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 43 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" | 44 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" |
| 44 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 45 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" | 46 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" |
| 46 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 47 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 47 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 48 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| 49 #include "chrome/browser/ui/views/location_bar/save_credit_card_icon_view.h" |
| 48 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 50 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| 49 #include "chrome/browser/ui/views/location_bar/star_view.h" | 51 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| 50 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" | 52 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" |
| 51 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 53 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| 52 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | 54 #include "chrome/browser/ui/views/location_bar/zoom_view.h" |
| 53 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" | 55 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
| 54 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" | 56 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" |
| 55 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" | 57 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" |
| 56 #include "chrome/grit/generated_resources.h" | 58 #include "chrome/grit/generated_resources.h" |
| 57 #include "components/bookmarks/common/bookmark_pref_names.h" | 59 #include "components/bookmarks/common/bookmark_pref_names.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 location_icon_view_(NULL), | 138 location_icon_view_(NULL), |
| 137 ev_bubble_view_(NULL), | 139 ev_bubble_view_(NULL), |
| 138 ime_inline_autocomplete_view_(NULL), | 140 ime_inline_autocomplete_view_(NULL), |
| 139 selected_keyword_view_(NULL), | 141 selected_keyword_view_(NULL), |
| 140 suggested_text_view_(NULL), | 142 suggested_text_view_(NULL), |
| 141 keyword_hint_view_(NULL), | 143 keyword_hint_view_(NULL), |
| 142 mic_search_view_(NULL), | 144 mic_search_view_(NULL), |
| 143 zoom_view_(NULL), | 145 zoom_view_(NULL), |
| 144 open_pdf_in_reader_view_(NULL), | 146 open_pdf_in_reader_view_(NULL), |
| 145 manage_passwords_icon_view_(NULL), | 147 manage_passwords_icon_view_(NULL), |
| 148 save_credit_card_icon_view_(nullptr), |
| 146 translate_icon_view_(NULL), | 149 translate_icon_view_(NULL), |
| 147 star_view_(NULL), | 150 star_view_(NULL), |
| 148 size_animation_(this), | 151 size_animation_(this), |
| 149 is_popup_mode_(is_popup_mode), | 152 is_popup_mode_(is_popup_mode), |
| 150 show_focus_rect_(false), | 153 show_focus_rect_(false), |
| 151 template_url_service_(NULL), | 154 template_url_service_(NULL), |
| 152 dropdown_animation_offset_(0), | 155 dropdown_animation_offset_(0), |
| 153 web_contents_null_at_last_refresh_(true) { | 156 web_contents_null_at_last_refresh_(true) { |
| 154 edit_bookmarks_enabled_.Init( | 157 edit_bookmarks_enabled_.Init( |
| 155 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 158 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 303 |
| 301 zoom_view_ = new ZoomView(delegate_); | 304 zoom_view_ = new ZoomView(delegate_); |
| 302 AddChildView(zoom_view_); | 305 AddChildView(zoom_view_); |
| 303 | 306 |
| 304 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); | 307 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); |
| 305 AddChildView(open_pdf_in_reader_view_); | 308 AddChildView(open_pdf_in_reader_view_); |
| 306 | 309 |
| 307 manage_passwords_icon_view_ = new ManagePasswordsIconViews(command_updater()); | 310 manage_passwords_icon_view_ = new ManagePasswordsIconViews(command_updater()); |
| 308 AddChildView(manage_passwords_icon_view_); | 311 AddChildView(manage_passwords_icon_view_); |
| 309 | 312 |
| 313 save_credit_card_icon_view_ = |
| 314 new SaveCreditCardIconView(command_updater(), browser_); |
| 315 save_credit_card_icon_view_->SetVisible(false); |
| 316 AddChildView(save_credit_card_icon_view_); |
| 317 |
| 310 translate_icon_view_ = new TranslateIconView(command_updater()); | 318 translate_icon_view_ = new TranslateIconView(command_updater()); |
| 311 translate_icon_view_->SetVisible(false); | 319 translate_icon_view_->SetVisible(false); |
| 312 AddChildView(translate_icon_view_); | 320 AddChildView(translate_icon_view_); |
| 313 | 321 |
| 314 star_view_ = new StarView(command_updater(), browser_); | 322 star_view_ = new StarView(command_updater(), browser_); |
| 315 star_view_->SetVisible(false); | 323 star_view_->SetVisible(false); |
| 316 AddChildView(star_view_); | 324 AddChildView(star_view_); |
| 317 | 325 |
| 318 // Initialize the location entry. We do this to avoid a black flash which is | 326 // Initialize the location entry. We do this to avoid a black flash which is |
| 319 // visible when the location entry has just been initialized. | 327 // visible when the location entry has just been initialized. |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 GetToolbarModel()->GetEVCertName()).width(); | 574 GetToolbarModel()->GetEVCertName()).width(); |
| 567 } else { | 575 } else { |
| 568 leading_width += padding + location_icon_view_->GetMinimumSize().width(); | 576 leading_width += padding + location_icon_view_->GetMinimumSize().width(); |
| 569 } | 577 } |
| 570 | 578 |
| 571 // Compute width of omnibox-trailing content. | 579 // Compute width of omnibox-trailing content. |
| 572 int trailing_width = horizontal_edge_thickness; | 580 int trailing_width = horizontal_edge_thickness; |
| 573 trailing_width += IncrementalMinimumWidth(star_view_) + | 581 trailing_width += IncrementalMinimumWidth(star_view_) + |
| 574 IncrementalMinimumWidth(translate_icon_view_) + | 582 IncrementalMinimumWidth(translate_icon_view_) + |
| 575 IncrementalMinimumWidth(open_pdf_in_reader_view_) + | 583 IncrementalMinimumWidth(open_pdf_in_reader_view_) + |
| 584 IncrementalMinimumWidth(save_credit_card_icon_view_) + |
| 576 IncrementalMinimumWidth(manage_passwords_icon_view_) + | 585 IncrementalMinimumWidth(manage_passwords_icon_view_) + |
| 577 IncrementalMinimumWidth(zoom_view_) + | 586 IncrementalMinimumWidth(zoom_view_) + |
| 578 IncrementalMinimumWidth(mic_search_view_); | 587 IncrementalMinimumWidth(mic_search_view_); |
| 579 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 588 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 580 i != page_action_views_.end(); ++i) | 589 i != page_action_views_.end(); ++i) |
| 581 trailing_width += IncrementalMinimumWidth((*i)); | 590 trailing_width += IncrementalMinimumWidth((*i)); |
| 582 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 591 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 583 i != content_setting_views_.end(); ++i) | 592 i != content_setting_views_.end(); ++i) |
| 584 trailing_width += IncrementalMinimumWidth((*i)); | 593 trailing_width += IncrementalMinimumWidth((*i)); |
| 585 | 594 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 star_view_); | 672 star_view_); |
| 664 } | 673 } |
| 665 if (translate_icon_view_->visible()) { | 674 if (translate_icon_view_->visible()) { |
| 666 trailing_decorations.AddDecoration(vertical_padding, location_height, | 675 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 667 translate_icon_view_); | 676 translate_icon_view_); |
| 668 } | 677 } |
| 669 if (open_pdf_in_reader_view_->visible()) { | 678 if (open_pdf_in_reader_view_->visible()) { |
| 670 trailing_decorations.AddDecoration(vertical_padding, location_height, | 679 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 671 open_pdf_in_reader_view_); | 680 open_pdf_in_reader_view_); |
| 672 } | 681 } |
| 682 if (save_credit_card_icon_view_->visible()) { |
| 683 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 684 save_credit_card_icon_view_); |
| 685 } |
| 673 if (manage_passwords_icon_view_->visible()) { | 686 if (manage_passwords_icon_view_->visible()) { |
| 674 trailing_decorations.AddDecoration(vertical_padding, location_height, | 687 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 675 manage_passwords_icon_view_); | 688 manage_passwords_icon_view_); |
| 676 } | 689 } |
| 677 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 690 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 678 i != page_action_views_.end(); ++i) { | 691 i != page_action_views_.end(); ++i) { |
| 679 if ((*i)->visible()) { | 692 if ((*i)->visible()) { |
| 680 trailing_decorations.AddDecoration(vertical_padding, location_height, | 693 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 681 (*i)); | 694 (*i)); |
| 682 } | 695 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 } | 821 } |
| 809 | 822 |
| 810 void LocationBarView::Update(const WebContents* contents) { | 823 void LocationBarView::Update(const WebContents* contents) { |
| 811 mic_search_view_->SetVisible( | 824 mic_search_view_->SetVisible( |
| 812 !GetToolbarModel()->input_in_progress() && browser_ && | 825 !GetToolbarModel()->input_in_progress() && browser_ && |
| 813 browser_->search_model()->voice_search_supported()); | 826 browser_->search_model()->voice_search_supported()); |
| 814 RefreshContentSettingViews(); | 827 RefreshContentSettingViews(); |
| 815 RefreshZoomView(); | 828 RefreshZoomView(); |
| 816 RefreshPageActionViews(); | 829 RefreshPageActionViews(); |
| 817 RefreshTranslateIcon(); | 830 RefreshTranslateIcon(); |
| 831 RefreshSaveCreditCardIconView(); |
| 818 RefreshManagePasswordsIconView(); | 832 RefreshManagePasswordsIconView(); |
| 819 content::WebContents* web_contents_for_sub_views = | 833 content::WebContents* web_contents_for_sub_views = |
| 820 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents(); | 834 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents(); |
| 821 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); | 835 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); |
| 822 | 836 |
| 823 if (star_view_) | 837 if (star_view_) |
| 824 UpdateBookmarkStarVisibility(); | 838 UpdateBookmarkStarVisibility(); |
| 825 | 839 |
| 826 if (contents) | 840 if (contents) |
| 827 omnibox_view_->OnTabChanged(contents); | 841 omnibox_view_->OnTabChanged(contents); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents)); | 995 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents)); |
| 982 if (!zoom_view_->visible()) | 996 if (!zoom_view_->visible()) |
| 983 ZoomBubbleView::CloseBubble(); | 997 ZoomBubbleView::CloseBubble(); |
| 984 return was_visible != zoom_view_->visible(); | 998 return was_visible != zoom_view_->visible(); |
| 985 } | 999 } |
| 986 | 1000 |
| 987 void LocationBarView::OnDefaultZoomLevelChanged() { | 1001 void LocationBarView::OnDefaultZoomLevelChanged() { |
| 988 RefreshZoomView(); | 1002 RefreshZoomView(); |
| 989 } | 1003 } |
| 990 | 1004 |
| 1005 bool LocationBarView::RefreshSaveCreditCardIconView() { |
| 1006 WebContents* web_contents = GetWebContents(); |
| 1007 if (!web_contents) |
| 1008 return false; |
| 1009 |
| 1010 const bool was_visible = save_credit_card_icon_view_->visible(); |
| 1011 // |controller| may be nullptr due to lazy initialization. |
| 1012 autofill::SaveCardBubbleControllerImpl* controller = |
| 1013 autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents); |
| 1014 bool enabled = controller && controller->IsIconVisible(); |
| 1015 command_updater()->UpdateCommandEnabled(IDC_SAVE_CREDIT_CARD_FOR_PAGE, |
| 1016 enabled); |
| 1017 save_credit_card_icon_view_->SetVisible(enabled); |
| 1018 if (enabled) |
| 1019 save_credit_card_icon_view_->SetToggled(controller->IsIconToggled()); |
| 1020 |
| 1021 return was_visible != save_credit_card_icon_view_->visible(); |
| 1022 } |
| 1023 |
| 991 void LocationBarView::RefreshTranslateIcon() { | 1024 void LocationBarView::RefreshTranslateIcon() { |
| 992 WebContents* web_contents = GetWebContents(); | 1025 WebContents* web_contents = GetWebContents(); |
| 993 if (!web_contents) | 1026 if (!web_contents) |
| 994 return; | 1027 return; |
| 995 translate::LanguageState& language_state = | 1028 translate::LanguageState& language_state = |
| 996 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState(); | 1029 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState(); |
| 997 bool enabled = language_state.translate_enabled(); | 1030 bool enabled = language_state.translate_enabled(); |
| 998 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled); | 1031 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled); |
| 999 translate_icon_view_->SetVisible(enabled); | 1032 translate_icon_view_->SetVisible(enabled); |
| 1000 translate_icon_view_->SetToggled(language_state.IsPageTranslated()); | 1033 translate_icon_view_->SetToggled(language_state.IsPageTranslated()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 } | 1119 } |
| 1087 } | 1120 } |
| 1088 | 1121 |
| 1089 void LocationBarView::UpdateManagePasswordsIconAndBubble() { | 1122 void LocationBarView::UpdateManagePasswordsIconAndBubble() { |
| 1090 if (RefreshManagePasswordsIconView()) { | 1123 if (RefreshManagePasswordsIconView()) { |
| 1091 Layout(); | 1124 Layout(); |
| 1092 SchedulePaint(); | 1125 SchedulePaint(); |
| 1093 } | 1126 } |
| 1094 } | 1127 } |
| 1095 | 1128 |
| 1129 void LocationBarView::UpdateSaveCreditCardIcon() { |
| 1130 if (RefreshSaveCreditCardIconView()) { |
| 1131 Layout(); |
| 1132 SchedulePaint(); |
| 1133 } |
| 1134 } |
| 1135 |
| 1096 void LocationBarView::UpdatePageActions() { | 1136 void LocationBarView::UpdatePageActions() { |
| 1097 if (RefreshPageActionViews()) { // Changed. | 1137 if (RefreshPageActionViews()) { // Changed. |
| 1098 Layout(); | 1138 Layout(); |
| 1099 SchedulePaint(); | 1139 SchedulePaint(); |
| 1100 } | 1140 } |
| 1101 } | 1141 } |
| 1102 | 1142 |
| 1103 void LocationBarView::UpdateBookmarkStarVisibility() { | 1143 void LocationBarView::UpdateBookmarkStarVisibility() { |
| 1104 if (star_view_) { | 1144 if (star_view_) { |
| 1105 star_view_->SetVisible( | 1145 star_view_->SetVisible( |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 | 1457 |
| 1418 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1458 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
| 1419 const SearchModel::State& new_state) { | 1459 const SearchModel::State& new_state) { |
| 1420 const bool visible = !GetToolbarModel()->input_in_progress() && | 1460 const bool visible = !GetToolbarModel()->input_in_progress() && |
| 1421 new_state.voice_search_supported; | 1461 new_state.voice_search_supported; |
| 1422 if (mic_search_view_->visible() != visible) { | 1462 if (mic_search_view_->visible() != visible) { |
| 1423 mic_search_view_->SetVisible(visible); | 1463 mic_search_view_->SetVisible(visible); |
| 1424 Layout(); | 1464 Layout(); |
| 1425 } | 1465 } |
| 1426 } | 1466 } |
| OLD | NEW |