| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 33 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
| 34 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" | 34 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" |
| 35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 36 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 36 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 37 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | 37 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
| 38 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | 38 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" |
| 39 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 39 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
| 40 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| 41 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
| 42 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" |
| 43 #import "chrome/browser/ui/cocoa/location_bar/search_token_decoration.h" |
| 43 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
| 45 #import "chrome/browser/ui/cocoa/location_bar/separator_decoration.h" |
| 44 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 46 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| 45 #import "chrome/browser/ui/cocoa/location_bar/web_intents_button_decoration.h" | 47 #import "chrome/browser/ui/cocoa/location_bar/web_intents_button_decoration.h" |
| 46 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" | 48 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
| 47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 49 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 48 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 50 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 49 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 51 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 50 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 52 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 51 #include "chrome/browser/ui/omnibox/alternate_nav_url_fetcher.h" | 53 #include "chrome/browser/ui/omnibox/alternate_nav_url_fetcher.h" |
| 52 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 54 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
| 53 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 55 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 CommandUpdater* command_updater, | 89 CommandUpdater* command_updater, |
| 88 ToolbarModel* toolbar_model, | 90 ToolbarModel* toolbar_model, |
| 89 Profile* profile, | 91 Profile* profile, |
| 90 Browser* browser) | 92 Browser* browser) |
| 91 : omnibox_view_(new OmniboxViewMac(this, toolbar_model, profile, | 93 : omnibox_view_(new OmniboxViewMac(this, toolbar_model, profile, |
| 92 command_updater, field)), | 94 command_updater, field)), |
| 93 command_updater_(command_updater), | 95 command_updater_(command_updater), |
| 94 field_(field), | 96 field_(field), |
| 95 disposition_(CURRENT_TAB), | 97 disposition_(CURRENT_TAB), |
| 96 location_icon_decoration_(new LocationIconDecoration(this)), | 98 location_icon_decoration_(new LocationIconDecoration(this)), |
| 99 search_token_decoration_(new SearchTokenDecoration()), |
| 97 selected_keyword_decoration_( | 100 selected_keyword_decoration_( |
| 98 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), | 101 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), |
| 102 separator_decoration_(new SeparatorDecoration()), |
| 99 ev_bubble_decoration_( | 103 ev_bubble_decoration_( |
| 100 new EVBubbleDecoration(location_icon_decoration_.get(), | 104 new EVBubbleDecoration(location_icon_decoration_.get(), |
| 101 OmniboxViewMac::GetFieldFont())), | 105 OmniboxViewMac::GetFieldFont())), |
| 102 plus_decoration_(NULL), | 106 plus_decoration_(NULL), |
| 103 star_decoration_(new StarDecoration(command_updater)), | 107 star_decoration_(new StarDecoration(command_updater)), |
| 104 zoom_decoration_(new ZoomDecoration(toolbar_model)), | 108 zoom_decoration_(new ZoomDecoration(toolbar_model)), |
| 105 keyword_hint_decoration_( | 109 keyword_hint_decoration_( |
| 106 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), | 110 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), |
| 107 web_intents_button_decoration_( | 111 web_intents_button_decoration_( |
| 108 new WebIntentsButtonDecoration(this, OmniboxViewMac::GetFieldFont())), | 112 new WebIntentsButtonDecoration(this, OmniboxViewMac::GetFieldFont())), |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 699 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
| 696 [cell addRightDecoration:page_action_decorations_[i]]; | 700 [cell addRightDecoration:page_action_decorations_[i]]; |
| 697 } | 701 } |
| 698 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { | 702 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { |
| 699 [cell addRightDecoration:content_setting_decorations_[i]]; | 703 [cell addRightDecoration:content_setting_decorations_[i]]; |
| 700 } | 704 } |
| 701 | 705 |
| 702 [cell addRightDecoration:keyword_hint_decoration_.get()]; | 706 [cell addRightDecoration:keyword_hint_decoration_.get()]; |
| 703 | 707 |
| 704 [cell addRightDecoration:web_intents_button_decoration_.get()]; | 708 [cell addRightDecoration:web_intents_button_decoration_.get()]; |
| 709 [cell addRightDecoration:separator_decoration_.get()]; |
| 710 [cell addRightDecoration:search_token_decoration_.get()]; |
| 705 | 711 |
| 706 // By default only the location icon is visible. | 712 // By default only the location icon is visible. |
| 707 location_icon_decoration_->SetVisible(true); | 713 location_icon_decoration_->SetVisible(true); |
| 708 selected_keyword_decoration_->SetVisible(false); | 714 selected_keyword_decoration_->SetVisible(false); |
| 709 ev_bubble_decoration_->SetVisible(false); | 715 ev_bubble_decoration_->SetVisible(false); |
| 710 keyword_hint_decoration_->SetVisible(false); | 716 keyword_hint_decoration_->SetVisible(false); |
| 717 separator_decoration_->SetVisible(false); |
| 718 search_token_decoration_->SetVisible(false); |
| 711 | 719 |
| 712 // Get the keyword to use for keyword-search and hinting. | 720 // Get the keyword to use for keyword-search and hinting. |
| 713 const string16 keyword = omnibox_view_->model()->keyword(); | 721 const string16 keyword = omnibox_view_->model()->keyword(); |
| 722 |
| 714 string16 short_name; | 723 string16 short_name; |
| 715 bool is_extension_keyword = false; | 724 bool is_extension_keyword = false; |
| 716 if (!keyword.empty()) { | 725 if (!keyword.empty()) { |
| 717 short_name = TemplateURLServiceFactory::GetForProfile(profile_)-> | 726 short_name = TemplateURLServiceFactory::GetForProfile(profile_)-> |
| 718 GetKeywordShortName(keyword, &is_extension_keyword); | 727 GetKeywordShortName(keyword, &is_extension_keyword); |
| 719 } | 728 } |
| 720 | 729 |
| 730 const string16 search_provider_name = GetSearchProviderName(); |
| 721 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); | 731 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); |
| 722 | 732 |
| 723 if (!keyword.empty() && !is_keyword_hint) { | 733 const bool show_search_token = !search_provider_name.empty(); |
| 734 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint && |
| 735 !show_search_token; |
| 736 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint && |
| 737 !show_search_token; |
| 738 |
| 739 if (show_selected_keyword) { |
| 724 // Switch from location icon to keyword mode. | 740 // Switch from location icon to keyword mode. |
| 725 location_icon_decoration_->SetVisible(false); | 741 location_icon_decoration_->SetVisible(false); |
| 726 selected_keyword_decoration_->SetVisible(true); | 742 selected_keyword_decoration_->SetVisible(true); |
| 727 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); | 743 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); |
| 728 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); | 744 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); |
| 729 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { | 745 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { |
| 730 // Switch from location icon to show the EV bubble instead. | 746 // Switch from location icon to show the EV bubble instead. |
| 731 location_icon_decoration_->SetVisible(false); | 747 location_icon_decoration_->SetVisible(false); |
| 732 ev_bubble_decoration_->SetVisible(true); | 748 ev_bubble_decoration_->SetVisible(true); |
| 733 | 749 |
| 734 string16 label(toolbar_model_->GetEVCertName()); | 750 string16 label(toolbar_model_->GetEVCertName()); |
| 735 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); | 751 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); |
| 736 } else if (!keyword.empty() && is_keyword_hint) { | 752 } else if (show_keyword_hint) { |
| 737 keyword_hint_decoration_->SetKeyword(short_name, | 753 keyword_hint_decoration_->SetKeyword(short_name, |
| 738 is_extension_keyword); | 754 is_extension_keyword); |
| 739 keyword_hint_decoration_->SetVisible(true); | 755 keyword_hint_decoration_->SetVisible(true); |
| 756 } else if (show_search_token) { |
| 757 separator_decoration_->SetVisible(true); |
| 758 search_token_decoration_->SetSearchProviderName(search_provider_name); |
| 759 search_token_decoration_->SetVisible(true); |
| 740 } | 760 } |
| 741 | 761 |
| 742 // These need to change anytime the layout changes. | 762 // These need to change anytime the layout changes. |
| 743 // TODO(shess): Anytime the field editor might have changed, the | 763 // TODO(shess): Anytime the field editor might have changed, the |
| 744 // cursor rects almost certainly should have changed. The tooltips | 764 // cursor rects almost certainly should have changed. The tooltips |
| 745 // might change even when the rects don't change. | 765 // might change even when the rects don't change. |
| 746 OnDecorationsChanged(); | 766 OnDecorationsChanged(); |
| 747 } | 767 } |
| 748 | 768 |
| 749 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { | 769 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 777 visible = false; | 797 visible = false; |
| 778 star_decoration_->SetVisible(visible); | 798 star_decoration_->SetVisible(visible); |
| 779 } | 799 } |
| 780 | 800 |
| 781 void LocationBarViewMac::UpdatePlusDecorationVisibility() { | 801 void LocationBarViewMac::UpdatePlusDecorationVisibility() { |
| 782 if (extensions::FeatureSwitch::action_box()->IsEnabled()) { | 802 if (extensions::FeatureSwitch::action_box()->IsEnabled()) { |
| 783 // If the action box is enabled, hide it when input is in progress. | 803 // If the action box is enabled, hide it when input is in progress. |
| 784 plus_decoration_->SetVisible(!toolbar_model_->GetInputInProgress()); | 804 plus_decoration_->SetVisible(!toolbar_model_->GetInputInProgress()); |
| 785 } | 805 } |
| 786 } | 806 } |
| 807 |
| 808 string16 LocationBarViewMac::GetSearchProviderName() const { |
| 809 if (!toolbar_model_->GetInputInProgress() && |
| 810 toolbar_model_->WouldReplaceSearchURLWithSearchTerms()) { |
| 811 const TemplateURL* template_url = |
| 812 TemplateURLServiceFactory::GetForProfile(profile_)-> |
| 813 GetDefaultSearchProvider(); |
| 814 if (template_url) |
| 815 return template_url->short_name(); |
| 816 } |
| 817 return string16(); |
| 818 } |
| OLD | NEW |