Chromium Code Reviews| 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_icon.h" | 36 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" |
| 36 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 37 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 38 #include "chrome/browser/ui/view_ids.h" | 39 #include "chrome/browser/ui/view_ids.h" |
| 39 #include "chrome/browser/ui/views/browser_dialogs.h" | 40 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 40 #include "chrome/browser/ui/views/layout_constants.h" | 41 #include "chrome/browser/ui/views/layout_constants.h" |
| 41 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
| 42 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
| 43 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 44 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" | 45 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" |
| 45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 46 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 46 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" | 47 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" |
| 47 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 48 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 48 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 49 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| 50 #include "chrome/browser/ui/views/location_bar/save_credit_card_icon_view.h" | |
| 49 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 51 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| 50 #include "chrome/browser/ui/views/location_bar/star_view.h" | 52 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| 51 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" | 53 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" |
| 52 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 54 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| 53 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | 55 #include "chrome/browser/ui/views/location_bar/zoom_view.h" |
| 54 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" | 56 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
| 55 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 57 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
| 56 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" | 58 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" |
| 57 #include "chrome/common/pref_names.h" | 59 #include "chrome/common/pref_names.h" |
| 58 #include "chrome/grit/generated_resources.h" | 60 #include "chrome/grit/generated_resources.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 location_icon_view_(NULL), | 139 location_icon_view_(NULL), |
| 138 ev_bubble_view_(NULL), | 140 ev_bubble_view_(NULL), |
| 139 ime_inline_autocomplete_view_(NULL), | 141 ime_inline_autocomplete_view_(NULL), |
| 140 selected_keyword_view_(NULL), | 142 selected_keyword_view_(NULL), |
| 141 suggested_text_view_(NULL), | 143 suggested_text_view_(NULL), |
| 142 keyword_hint_view_(NULL), | 144 keyword_hint_view_(NULL), |
| 143 mic_search_view_(NULL), | 145 mic_search_view_(NULL), |
| 144 zoom_view_(NULL), | 146 zoom_view_(NULL), |
| 145 open_pdf_in_reader_view_(NULL), | 147 open_pdf_in_reader_view_(NULL), |
| 146 manage_passwords_icon_view_(NULL), | 148 manage_passwords_icon_view_(NULL), |
| 149 save_credit_card_icon_view_(NULL), | |
| 147 translate_icon_view_(NULL), | 150 translate_icon_view_(NULL), |
| 148 star_view_(NULL), | 151 star_view_(NULL), |
| 149 size_animation_(this), | 152 size_animation_(this), |
| 150 is_popup_mode_(is_popup_mode), | 153 is_popup_mode_(is_popup_mode), |
| 151 show_focus_rect_(false), | 154 show_focus_rect_(false), |
| 152 template_url_service_(NULL), | 155 template_url_service_(NULL), |
| 153 dropdown_animation_offset_(0), | 156 dropdown_animation_offset_(0), |
| 154 web_contents_null_at_last_refresh_(true) { | 157 web_contents_null_at_last_refresh_(true) { |
| 155 edit_bookmarks_enabled_.Init( | 158 edit_bookmarks_enabled_.Init( |
| 156 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 159 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 | 297 |
| 295 zoom_view_ = new ZoomView(delegate_); | 298 zoom_view_ = new ZoomView(delegate_); |
| 296 AddChildView(zoom_view_); | 299 AddChildView(zoom_view_); |
| 297 | 300 |
| 298 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); | 301 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); |
| 299 AddChildView(open_pdf_in_reader_view_); | 302 AddChildView(open_pdf_in_reader_view_); |
| 300 | 303 |
| 301 manage_passwords_icon_view_ = new ManagePasswordsIconView(command_updater()); | 304 manage_passwords_icon_view_ = new ManagePasswordsIconView(command_updater()); |
| 302 AddChildView(manage_passwords_icon_view_); | 305 AddChildView(manage_passwords_icon_view_); |
| 303 | 306 |
| 307 save_credit_card_icon_view_ = | |
| 308 new SaveCreditCardIconView(command_updater(), browser_); | |
| 309 save_credit_card_icon_view_->SetVisible(false); | |
| 310 AddChildView(save_credit_card_icon_view_); | |
| 311 | |
| 304 translate_icon_view_ = new TranslateIconView(command_updater()); | 312 translate_icon_view_ = new TranslateIconView(command_updater()); |
| 305 translate_icon_view_->SetVisible(false); | 313 translate_icon_view_->SetVisible(false); |
| 306 AddChildView(translate_icon_view_); | 314 AddChildView(translate_icon_view_); |
| 307 | 315 |
| 308 star_view_ = new StarView(command_updater(), browser_); | 316 star_view_ = new StarView(command_updater(), browser_); |
| 309 star_view_->SetVisible(false); | 317 star_view_->SetVisible(false); |
| 310 AddChildView(star_view_); | 318 AddChildView(star_view_); |
| 311 | 319 |
| 312 // Initialize the location entry. We do this to avoid a black flash which is | 320 // Initialize the location entry. We do this to avoid a black flash which is |
| 313 // visible when the location entry has just been initialized. | 321 // visible when the location entry has just been initialized. |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 GetToolbarModel()->GetEVCertName()).width(); | 562 GetToolbarModel()->GetEVCertName()).width(); |
| 555 } else { | 563 } else { |
| 556 leading_width += padding + location_icon_view_->GetMinimumSize().width(); | 564 leading_width += padding + location_icon_view_->GetMinimumSize().width(); |
| 557 } | 565 } |
| 558 | 566 |
| 559 // Compute width of omnibox-trailing content. | 567 // Compute width of omnibox-trailing content. |
| 560 int trailing_width = horizontal_edge_thickness; | 568 int trailing_width = horizontal_edge_thickness; |
| 561 trailing_width += IncrementalMinimumWidth(star_view_) + | 569 trailing_width += IncrementalMinimumWidth(star_view_) + |
| 562 IncrementalMinimumWidth(translate_icon_view_) + | 570 IncrementalMinimumWidth(translate_icon_view_) + |
| 563 IncrementalMinimumWidth(open_pdf_in_reader_view_) + | 571 IncrementalMinimumWidth(open_pdf_in_reader_view_) + |
| 572 IncrementalMinimumWidth(save_credit_card_icon_view_) + | |
| 564 IncrementalMinimumWidth(manage_passwords_icon_view_) + | 573 IncrementalMinimumWidth(manage_passwords_icon_view_) + |
| 565 IncrementalMinimumWidth(zoom_view_) + | 574 IncrementalMinimumWidth(zoom_view_) + |
| 566 IncrementalMinimumWidth(mic_search_view_); | 575 IncrementalMinimumWidth(mic_search_view_); |
| 567 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 576 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 568 i != page_action_views_.end(); ++i) | 577 i != page_action_views_.end(); ++i) |
| 569 trailing_width += IncrementalMinimumWidth((*i)); | 578 trailing_width += IncrementalMinimumWidth((*i)); |
| 570 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 579 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 571 i != content_setting_views_.end(); ++i) | 580 i != content_setting_views_.end(); ++i) |
| 572 trailing_width += IncrementalMinimumWidth((*i)); | 581 trailing_width += IncrementalMinimumWidth((*i)); |
| 573 | 582 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 star_view_); | 661 star_view_); |
| 653 } | 662 } |
| 654 if (translate_icon_view_->visible()) { | 663 if (translate_icon_view_->visible()) { |
| 655 trailing_decorations.AddDecoration(vertical_padding, location_height, | 664 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 656 translate_icon_view_); | 665 translate_icon_view_); |
| 657 } | 666 } |
| 658 if (open_pdf_in_reader_view_->visible()) { | 667 if (open_pdf_in_reader_view_->visible()) { |
| 659 trailing_decorations.AddDecoration(vertical_padding, location_height, | 668 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 660 open_pdf_in_reader_view_); | 669 open_pdf_in_reader_view_); |
| 661 } | 670 } |
| 671 if (save_credit_card_icon_view_->visible()) { | |
| 672 trailing_decorations.AddDecoration(vertical_padding, location_height, | |
| 673 save_credit_card_icon_view_); | |
| 674 } | |
| 662 if (manage_passwords_icon_view_->visible()) { | 675 if (manage_passwords_icon_view_->visible()) { |
| 663 trailing_decorations.AddDecoration(vertical_padding, location_height, | 676 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 664 manage_passwords_icon_view_); | 677 manage_passwords_icon_view_); |
| 665 } | 678 } |
| 666 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 679 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 667 i != page_action_views_.end(); ++i) { | 680 i != page_action_views_.end(); ++i) { |
| 668 if ((*i)->visible()) { | 681 if ((*i)->visible()) { |
| 669 trailing_decorations.AddDecoration(vertical_padding, location_height, | 682 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 670 (*i)); | 683 (*i)); |
| 671 } | 684 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 797 } | 810 } |
| 798 | 811 |
| 799 void LocationBarView::Update(const WebContents* contents) { | 812 void LocationBarView::Update(const WebContents* contents) { |
| 800 mic_search_view_->SetVisible( | 813 mic_search_view_->SetVisible( |
| 801 !GetToolbarModel()->input_in_progress() && browser_ && | 814 !GetToolbarModel()->input_in_progress() && browser_ && |
| 802 browser_->search_model()->voice_search_supported()); | 815 browser_->search_model()->voice_search_supported()); |
| 803 RefreshContentSettingViews(); | 816 RefreshContentSettingViews(); |
| 804 RefreshZoomView(); | 817 RefreshZoomView(); |
| 805 RefreshPageActionViews(); | 818 RefreshPageActionViews(); |
| 806 RefreshTranslateIcon(); | 819 RefreshTranslateIcon(); |
| 820 RefreshSaveCreditCardIconView(); | |
| 807 RefreshManagePasswordsIconView(); | 821 RefreshManagePasswordsIconView(); |
| 808 content::WebContents* web_contents_for_sub_views = | 822 content::WebContents* web_contents_for_sub_views = |
| 809 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents(); | 823 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents(); |
| 810 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); | 824 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); |
| 811 | 825 |
| 812 if (star_view_) | 826 if (star_view_) |
| 813 UpdateBookmarkStarVisibility(); | 827 UpdateBookmarkStarVisibility(); |
| 814 | 828 |
| 815 if (contents) | 829 if (contents) |
| 816 omnibox_view_->OnTabChanged(contents); | 830 omnibox_view_->OnTabChanged(contents); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 967 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents)); | 981 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents)); |
| 968 if (!zoom_view_->visible()) | 982 if (!zoom_view_->visible()) |
| 969 ZoomBubbleView::CloseBubble(); | 983 ZoomBubbleView::CloseBubble(); |
| 970 return was_visible != zoom_view_->visible(); | 984 return was_visible != zoom_view_->visible(); |
| 971 } | 985 } |
| 972 | 986 |
| 973 void LocationBarView::OnDefaultZoomLevelChanged() { | 987 void LocationBarView::OnDefaultZoomLevelChanged() { |
| 974 RefreshZoomView(); | 988 RefreshZoomView(); |
| 975 } | 989 } |
| 976 | 990 |
| 991 bool LocationBarView::RefreshSaveCreditCardIconView() { | |
| 992 WebContents* web_contents = GetWebContents(); | |
| 993 if (!web_contents) | |
| 994 return false; | |
|
Evan Stade
2015/10/16 01:20:44
\n
bondd
2015/10/22 02:15:17
Done.
| |
| 995 const bool was_visible = save_credit_card_icon_view_->visible(); | |
| 996 // |controller| may be nullptr due to lazy initialization. | |
| 997 autofill::SaveCardBubbleControllerImpl* controller = | |
| 998 autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents); | |
| 999 bool enabled = controller && controller->IsIconVisible(); | |
| 1000 command_updater()->UpdateCommandEnabled(IDC_SAVE_CREDIT_CARD_FOR_PAGE, | |
| 1001 enabled); | |
| 1002 save_credit_card_icon_view_->SetVisible(enabled); | |
| 1003 if (enabled) | |
| 1004 save_credit_card_icon_view_->SetToggled(controller->IsIconToggled()); | |
|
Evan Stade
2015/10/16 01:20:44
\n
bondd
2015/10/22 02:15:17
Done.
| |
| 1005 return was_visible != save_credit_card_icon_view_->visible(); | |
| 1006 } | |
| 1007 | |
| 977 void LocationBarView::RefreshTranslateIcon() { | 1008 void LocationBarView::RefreshTranslateIcon() { |
| 978 if (!TranslateService::IsTranslateBubbleEnabled()) | 1009 if (!TranslateService::IsTranslateBubbleEnabled()) |
| 979 return; | 1010 return; |
| 980 | 1011 |
| 981 WebContents* web_contents = GetWebContents(); | 1012 WebContents* web_contents = GetWebContents(); |
| 982 if (!web_contents) | 1013 if (!web_contents) |
| 983 return; | 1014 return; |
| 984 translate::LanguageState& language_state = | 1015 translate::LanguageState& language_state = |
| 985 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState(); | 1016 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState(); |
| 986 bool enabled = language_state.translate_enabled(); | 1017 bool enabled = language_state.translate_enabled(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1075 } | 1106 } |
| 1076 } | 1107 } |
| 1077 | 1108 |
| 1078 void LocationBarView::UpdateManagePasswordsIconAndBubble() { | 1109 void LocationBarView::UpdateManagePasswordsIconAndBubble() { |
| 1079 if (RefreshManagePasswordsIconView()) { | 1110 if (RefreshManagePasswordsIconView()) { |
| 1080 Layout(); | 1111 Layout(); |
| 1081 SchedulePaint(); | 1112 SchedulePaint(); |
| 1082 } | 1113 } |
| 1083 } | 1114 } |
| 1084 | 1115 |
| 1116 void LocationBarView::UpdateSaveCreditCardIcon() { | |
| 1117 if (RefreshSaveCreditCardIconView()) { | |
| 1118 Layout(); | |
| 1119 SchedulePaint(); | |
| 1120 } | |
| 1121 } | |
| 1122 | |
| 1085 void LocationBarView::UpdatePageActions() { | 1123 void LocationBarView::UpdatePageActions() { |
| 1086 if (RefreshPageActionViews()) { // Changed. | 1124 if (RefreshPageActionViews()) { // Changed. |
| 1087 Layout(); | 1125 Layout(); |
| 1088 SchedulePaint(); | 1126 SchedulePaint(); |
| 1089 } | 1127 } |
| 1090 } | 1128 } |
| 1091 | 1129 |
| 1092 void LocationBarView::UpdateBookmarkStarVisibility() { | 1130 void LocationBarView::UpdateBookmarkStarVisibility() { |
| 1093 if (star_view_) { | 1131 if (star_view_) { |
| 1094 star_view_->SetVisible( | 1132 star_view_->SetVisible( |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1409 | 1447 |
| 1410 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1448 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
| 1411 const SearchModel::State& new_state) { | 1449 const SearchModel::State& new_state) { |
| 1412 const bool visible = !GetToolbarModel()->input_in_progress() && | 1450 const bool visible = !GetToolbarModel()->input_in_progress() && |
| 1413 new_state.voice_search_supported; | 1451 new_state.voice_search_supported; |
| 1414 if (mic_search_view_->visible() != visible) { | 1452 if (mic_search_view_->visible() != visible) { |
| 1415 mic_search_view_->SetVisible(visible); | 1453 mic_search_view_->SetVisible(visible); |
| 1416 Layout(); | 1454 Layout(); |
| 1417 } | 1455 } |
| 1418 } | 1456 } |
| OLD | NEW |