| 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/stl_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/command_updater.h" | 16 #include "chrome/browser/command_updater.h" |
| 17 #include "chrome/browser/defaults.h" | 17 #include "chrome/browser/defaults.h" |
| 18 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 18 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 19 #include "chrome/browser/extensions/extension_action.h" | 19 #include "chrome/browser/extensions/extension_action.h" |
| 20 #include "chrome/browser/extensions/extension_action_manager.h" | 20 #include "chrome/browser/extensions/extension_action_manager.h" |
| 21 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
| 22 #include "chrome/browser/extensions/location_bar_controller.h" | 22 #include "chrome/browser/extensions/location_bar_controller.h" |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 392 |
| 393 page_action_view->image_view()->set_preview_enabled(preview_enabled); | 393 page_action_view->image_view()->set_preview_enabled(preview_enabled); |
| 394 page_action_view->UpdateVisibility(web_contents); | 394 page_action_view->UpdateVisibility(web_contents); |
| 395 Layout(); | 395 Layout(); |
| 396 SchedulePaint(); | 396 SchedulePaint(); |
| 397 } | 397 } |
| 398 | 398 |
| 399 PageActionWithBadgeView* LocationBarView::GetPageActionView( | 399 PageActionWithBadgeView* LocationBarView::GetPageActionView( |
| 400 ExtensionAction* page_action) { | 400 ExtensionAction* page_action) { |
| 401 DCHECK(page_action); | 401 DCHECK(page_action); |
| 402 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 402 for (const auto& action_view : page_action_views_) { |
| 403 i != page_action_views_.end(); ++i) { | 403 if (action_view->image_view()->extension_action() == page_action) |
| 404 if ((*i)->image_view()->extension_action() == page_action) | 404 return action_view.get(); |
| 405 return *i; | |
| 406 } | 405 } |
| 407 return nullptr; | 406 return nullptr; |
| 408 } | 407 } |
| 409 | 408 |
| 410 void LocationBarView::SetStarToggled(bool on) { | 409 void LocationBarView::SetStarToggled(bool on) { |
| 411 if (star_view_) | 410 if (star_view_) |
| 412 star_view_->SetToggled(on); | 411 star_view_->SetToggled(on); |
| 413 } | 412 } |
| 414 | 413 |
| 415 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { | 414 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 } | 522 } |
| 524 | 523 |
| 525 // Compute width of omnibox-trailing content. | 524 // Compute width of omnibox-trailing content. |
| 526 int trailing_width = edge_thickness; | 525 int trailing_width = edge_thickness; |
| 527 trailing_width += IncrementalMinimumWidth(star_view_) + | 526 trailing_width += IncrementalMinimumWidth(star_view_) + |
| 528 IncrementalMinimumWidth(translate_icon_view_) + | 527 IncrementalMinimumWidth(translate_icon_view_) + |
| 529 IncrementalMinimumWidth(open_pdf_in_reader_view_) + | 528 IncrementalMinimumWidth(open_pdf_in_reader_view_) + |
| 530 IncrementalMinimumWidth(save_credit_card_icon_view_) + | 529 IncrementalMinimumWidth(save_credit_card_icon_view_) + |
| 531 IncrementalMinimumWidth(manage_passwords_icon_view_) + | 530 IncrementalMinimumWidth(manage_passwords_icon_view_) + |
| 532 IncrementalMinimumWidth(zoom_view_); | 531 IncrementalMinimumWidth(zoom_view_); |
| 533 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 532 for (const auto& action_view : page_action_views_) |
| 534 i != page_action_views_.end(); ++i) | 533 trailing_width += IncrementalMinimumWidth(action_view.get()); |
| 534 for (auto i = content_setting_views_.begin(); |
| 535 i != content_setting_views_.end(); ++i) { |
| 535 trailing_width += IncrementalMinimumWidth((*i)); | 536 trailing_width += IncrementalMinimumWidth((*i)); |
| 536 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 537 } |
| 537 i != content_setting_views_.end(); ++i) | |
| 538 trailing_width += IncrementalMinimumWidth((*i)); | |
| 539 | 538 |
| 540 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + | 539 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + |
| 541 2 * padding - omnibox_view_->GetInsets().width() + | 540 2 * padding - omnibox_view_->GetInsets().width() + |
| 542 trailing_width); | 541 trailing_width); |
| 543 return min_size; | 542 return min_size; |
| 544 } | 543 } |
| 545 | 544 |
| 546 void LocationBarView::Layout() { | 545 void LocationBarView::Layout() { |
| 547 if (!IsInitialized()) | 546 if (!IsInitialized()) |
| 548 return; | 547 return; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 open_pdf_in_reader_view_); | 614 open_pdf_in_reader_view_); |
| 616 } | 615 } |
| 617 if (save_credit_card_icon_view_->visible()) { | 616 if (save_credit_card_icon_view_->visible()) { |
| 618 trailing_decorations.AddDecoration(vertical_padding, location_height, | 617 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 619 save_credit_card_icon_view_); | 618 save_credit_card_icon_view_); |
| 620 } | 619 } |
| 621 if (manage_passwords_icon_view_->visible()) { | 620 if (manage_passwords_icon_view_->visible()) { |
| 622 trailing_decorations.AddDecoration(vertical_padding, location_height, | 621 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 623 manage_passwords_icon_view_); | 622 manage_passwords_icon_view_); |
| 624 } | 623 } |
| 625 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 624 for (const auto& action_view : page_action_views_) { |
| 626 i != page_action_views_.end(); ++i) { | 625 if (action_view->visible()) { |
| 627 if ((*i)->visible()) { | |
| 628 trailing_decorations.AddDecoration(vertical_padding, location_height, | 626 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 629 (*i)); | 627 action_view.get()); |
| 630 } | 628 } |
| 631 } | 629 } |
| 632 if (zoom_view_->visible()) { | 630 if (zoom_view_->visible()) { |
| 633 trailing_decorations.AddDecoration(vertical_padding, location_height, | 631 trailing_decorations.AddDecoration(vertical_padding, location_height, |
| 634 zoom_view_); | 632 zoom_view_); |
| 635 } | 633 } |
| 636 for (ContentSettingViews::const_reverse_iterator i( | 634 for (ContentSettingViews::const_reverse_iterator i( |
| 637 content_setting_views_.rbegin()); i != content_setting_views_.rend(); | 635 content_setting_views_.rbegin()); i != content_setting_views_.rend(); |
| 638 ++i) { | 636 ++i) { |
| 639 if ((*i)->visible()) { | 637 if ((*i)->visible()) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 const bool was_visible = (*i)->visible(); | 842 const bool was_visible = (*i)->visible(); |
| 845 (*i)->Update(GetToolbarModel()->input_in_progress() ? nullptr | 843 (*i)->Update(GetToolbarModel()->input_in_progress() ? nullptr |
| 846 : GetWebContents()); | 844 : GetWebContents()); |
| 847 if (was_visible != (*i)->visible()) | 845 if (was_visible != (*i)->visible()) |
| 848 visibility_changed = true; | 846 visibility_changed = true; |
| 849 } | 847 } |
| 850 return visibility_changed; | 848 return visibility_changed; |
| 851 } | 849 } |
| 852 | 850 |
| 853 void LocationBarView::DeletePageActionViews() { | 851 void LocationBarView::DeletePageActionViews() { |
| 854 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 852 for (const auto& action_view : page_action_views_) |
| 855 i != page_action_views_.end(); ++i) | 853 RemoveChildView(action_view.get()); |
| 856 RemoveChildView(*i); | 854 page_action_views_.clear(); |
| 857 base::STLDeleteElements(&page_action_views_); | |
| 858 } | 855 } |
| 859 | 856 |
| 860 bool LocationBarView::RefreshPageActionViews() { | 857 bool LocationBarView::RefreshPageActionViews() { |
| 861 if (is_popup_mode_) | 858 if (is_popup_mode_) |
| 862 return false; | 859 return false; |
| 863 | 860 |
| 864 bool changed = false; | 861 bool changed = false; |
| 865 PageActions new_page_actions; | 862 PageActions new_page_actions; |
| 866 | 863 |
| 867 WebContents* web_contents = GetWebContents(); | 864 WebContents* web_contents = GetWebContents(); |
| 868 if (web_contents) { | 865 if (web_contents) { |
| 869 extensions::TabHelper* extensions_tab_helper = | 866 extensions::TabHelper* extensions_tab_helper = |
| 870 extensions::TabHelper::FromWebContents(web_contents); | 867 extensions::TabHelper::FromWebContents(web_contents); |
| 871 extensions::LocationBarController* controller = | 868 extensions::LocationBarController* controller = |
| 872 extensions_tab_helper->location_bar_controller(); | 869 extensions_tab_helper->location_bar_controller(); |
| 873 new_page_actions = controller->GetCurrentActions(); | 870 new_page_actions = controller->GetCurrentActions(); |
| 874 } | 871 } |
| 875 web_contents_null_at_last_refresh_ = web_contents == nullptr; | 872 web_contents_null_at_last_refresh_ = web_contents == nullptr; |
| 876 | 873 |
| 877 // On startup we sometimes haven't loaded any extensions. This makes sure | 874 // On startup we sometimes haven't loaded any extensions. This makes sure |
| 878 // we catch up when the extensions (and any page actions) load. | 875 // we catch up when the extensions (and any page actions) load. |
| 879 if (PageActionsDiffer(new_page_actions)) { | 876 if (PageActionsDiffer(new_page_actions)) { |
| 880 changed = true; | 877 changed = true; |
| 881 | 878 |
| 882 DeletePageActionViews(); | 879 DeletePageActionViews(); |
| 883 | 880 |
| 884 // Create the page action views. | 881 // Create the page action views. |
| 885 for (PageActions::const_iterator i = new_page_actions.begin(); | 882 for (PageActions::const_iterator i = new_page_actions.begin(); |
| 886 i != new_page_actions.end(); ++i) { | 883 i != new_page_actions.end(); ++i) { |
| 887 PageActionWithBadgeView* page_action_view = new PageActionWithBadgeView( | 884 std::unique_ptr<PageActionWithBadgeView> page_action_view = |
| 888 delegate_->CreatePageActionImageView(this, *i)); | 885 base::MakeUnique<PageActionWithBadgeView>( |
| 886 delegate_->CreatePageActionImageView(this, *i)); |
| 889 page_action_view->SetVisible(false); | 887 page_action_view->SetVisible(false); |
| 890 page_action_views_.push_back(page_action_view); | 888 page_action_views_.push_back(std::move(page_action_view)); |
| 891 } | 889 } |
| 892 | 890 |
| 893 View* right_anchor = open_pdf_in_reader_view_; | 891 View* right_anchor = open_pdf_in_reader_view_; |
| 894 if (!right_anchor) | 892 if (!right_anchor) |
| 895 right_anchor = star_view_; | 893 right_anchor = star_view_; |
| 896 DCHECK(right_anchor); | 894 DCHECK(right_anchor); |
| 897 | 895 |
| 898 // |page_action_views_| are ordered right-to-left. Add them as children in | 896 // |page_action_views_| are ordered right-to-left. Add them as children in |
| 899 // reverse order so the logical order and visual order match for | 897 // reverse order so the logical order and visual order match for |
| 900 // accessibility purposes. | 898 // accessibility purposes. |
| 901 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin(); | 899 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin(); |
| 902 i != page_action_views_.rend(); ++i) | 900 i != page_action_views_.rend(); ++i) |
| 903 AddChildViewAt(*i, GetIndexOf(right_anchor)); | 901 AddChildViewAt(i->get(), GetIndexOf(right_anchor)); |
| 904 } | 902 } |
| 905 | 903 |
| 906 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 904 for (const auto& action_view : page_action_views_) { |
| 907 i != page_action_views_.end(); ++i) { | 905 bool old_visibility = action_view->visible(); |
| 908 bool old_visibility = (*i)->visible(); | 906 action_view->UpdateVisibility( |
| 909 (*i)->UpdateVisibility( | |
| 910 GetToolbarModel()->input_in_progress() ? nullptr : web_contents); | 907 GetToolbarModel()->input_in_progress() ? nullptr : web_contents); |
| 911 changed |= old_visibility != (*i)->visible(); | 908 changed |= old_visibility != action_view->visible(); |
| 912 } | 909 } |
| 913 return changed; | 910 return changed; |
| 914 } | 911 } |
| 915 | 912 |
| 916 bool LocationBarView::PageActionsDiffer( | 913 bool LocationBarView::PageActionsDiffer( |
| 917 const PageActions& page_actions) const { | 914 const PageActions& page_actions) const { |
| 918 if (page_action_views_.size() != page_actions.size()) | 915 if (page_action_views_.size() != page_actions.size()) |
| 919 return true; | 916 return true; |
| 920 | 917 |
| 921 for (size_t index = 0; index < page_actions.size(); ++index) { | 918 for (size_t index = 0; index < page_actions.size(); ++index) { |
| 922 PageActionWithBadgeView* view = page_action_views_[index]; | 919 PageActionWithBadgeView* view = page_action_views_[index].get(); |
| 923 if (view->image_view()->extension_action() != page_actions[index]) | 920 if (view->image_view()->extension_action() != page_actions[index]) |
| 924 return true; | 921 return true; |
| 925 } | 922 } |
| 926 | 923 |
| 927 return false; | 924 return false; |
| 928 } | 925 } |
| 929 | 926 |
| 930 bool LocationBarView::RefreshZoomView() { | 927 bool LocationBarView::RefreshZoomView() { |
| 931 DCHECK(zoom_view_); | 928 DCHECK(zoom_view_); |
| 932 WebContents* web_contents = GetWebContents(); | 929 WebContents* web_contents = GetWebContents(); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 | 1168 |
| 1172 //////////////////////////////////////////////////////////////////////////////// | 1169 //////////////////////////////////////////////////////////////////////////////// |
| 1173 // LocationBarView, private LocationBarTesting implementation: | 1170 // LocationBarView, private LocationBarTesting implementation: |
| 1174 | 1171 |
| 1175 int LocationBarView::PageActionCount() { | 1172 int LocationBarView::PageActionCount() { |
| 1176 return page_action_views_.size(); | 1173 return page_action_views_.size(); |
| 1177 } | 1174 } |
| 1178 | 1175 |
| 1179 int LocationBarView::PageActionVisibleCount() { | 1176 int LocationBarView::PageActionVisibleCount() { |
| 1180 int result = 0; | 1177 int result = 0; |
| 1181 for (size_t i = 0; i < page_action_views_.size(); i++) { | 1178 for (const auto& action_view : page_action_views_) { |
| 1182 if (page_action_views_[i]->visible()) | 1179 if (action_view->visible()) |
| 1183 ++result; | 1180 ++result; |
| 1184 } | 1181 } |
| 1185 return result; | 1182 return result; |
| 1186 } | 1183 } |
| 1187 | 1184 |
| 1188 ExtensionAction* LocationBarView::GetPageAction(size_t index) { | 1185 ExtensionAction* LocationBarView::GetPageAction(size_t index) { |
| 1189 if (index < page_action_views_.size()) | 1186 if (index < page_action_views_.size()) |
| 1190 return page_action_views_[index]->image_view()->extension_action(); | 1187 return page_action_views_[index]->image_view()->extension_action(); |
| 1191 | 1188 |
| 1192 NOTREACHED(); | 1189 NOTREACHED(); |
| 1193 return nullptr; | 1190 return nullptr; |
| 1194 } | 1191 } |
| 1195 | 1192 |
| 1196 ExtensionAction* LocationBarView::GetVisiblePageAction(size_t index) { | 1193 ExtensionAction* LocationBarView::GetVisiblePageAction(size_t index) { |
| 1197 size_t current = 0; | 1194 size_t current = 0; |
| 1198 for (size_t i = 0; i < page_action_views_.size(); ++i) { | 1195 for (const auto& action_view : page_action_views_) { |
| 1199 if (page_action_views_[i]->visible()) { | 1196 if (action_view->visible()) { |
| 1200 if (current == index) | 1197 if (current == index) |
| 1201 return page_action_views_[i]->image_view()->extension_action(); | 1198 return action_view->image_view()->extension_action(); |
| 1202 | 1199 |
| 1203 ++current; | 1200 ++current; |
| 1204 } | 1201 } |
| 1205 } | 1202 } |
| 1206 | 1203 |
| 1207 NOTREACHED(); | 1204 NOTREACHED(); |
| 1208 return nullptr; | 1205 return nullptr; |
| 1209 } | 1206 } |
| 1210 | 1207 |
| 1211 void LocationBarView::TestPageActionPressed(size_t index) { | 1208 void LocationBarView::TestPageActionPressed(size_t index) { |
| 1212 size_t current = 0; | 1209 size_t current = 0; |
| 1213 for (size_t i = 0; i < page_action_views_.size(); ++i) { | 1210 for (const auto& action_view : page_action_views_) { |
| 1214 if (page_action_views_[i]->visible()) { | 1211 if (action_view->visible()) { |
| 1215 if (current == index) { | 1212 if (current == index) { |
| 1216 page_action_views_[i]->image_view()->view_controller()-> | 1213 action_view->image_view()->view_controller()->ExecuteAction(true); |
| 1217 ExecuteAction(true); | |
| 1218 return; | 1214 return; |
| 1219 } | 1215 } |
| 1220 ++current; | 1216 ++current; |
| 1221 } | 1217 } |
| 1222 } | 1218 } |
| 1223 | 1219 |
| 1224 NOTREACHED(); | 1220 NOTREACHED(); |
| 1225 } | 1221 } |
| 1226 | 1222 |
| 1227 bool LocationBarView::GetBookmarkStarVisibility() { | 1223 bool LocationBarView::GetBookmarkStarVisibility() { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 // LocationBarView, private TemplateURLServiceObserver implementation: | 1343 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1348 | 1344 |
| 1349 void LocationBarView::OnTemplateURLServiceChanged() { | 1345 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1350 template_url_service_->RemoveObserver(this); | 1346 template_url_service_->RemoveObserver(this); |
| 1351 template_url_service_ = nullptr; | 1347 template_url_service_ = nullptr; |
| 1352 // If the browser is no longer active, let's not show the info bubble, as this | 1348 // If the browser is no longer active, let's not show the info bubble, as this |
| 1353 // would make the browser the active window again. | 1349 // would make the browser the active window again. |
| 1354 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1350 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1355 ShowFirstRunBubble(); | 1351 ShowFirstRunBubble(); |
| 1356 } | 1352 } |
| OLD | NEW |