Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm

Issue 12042002: Alternate NTP: Add search token to omnibox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update separator color Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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();
714 string16 short_name; 722 string16 short_name;
715 bool is_extension_keyword = false; 723 bool is_extension_keyword = false;
716 if (!keyword.empty()) { 724 if (!keyword.empty()) {
717 short_name = TemplateURLServiceFactory::GetForProfile(profile_)-> 725 short_name = TemplateURLServiceFactory::GetForProfile(profile_)->
718 GetKeywordShortName(keyword, &is_extension_keyword); 726 GetKeywordShortName(keyword, &is_extension_keyword);
719 } 727 }
728 bool show_search_token = !GetSearchProviderName().empty();
Scott Hess - ex-Googler 2013/01/29 23:28:37 If you captured the GetSearchProviderName() result
sail 2013/01/30 01:40:56 Done. Changed to use a local variable.
720 729
721 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); 730 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint();
722 731
723 if (!keyword.empty() && !is_keyword_hint) { 732 if (!keyword.empty() && !is_keyword_hint && !show_search_token) {
724 // Switch from location icon to keyword mode. 733 // Switch from location icon to keyword mode.
725 location_icon_decoration_->SetVisible(false); 734 location_icon_decoration_->SetVisible(false);
726 selected_keyword_decoration_->SetVisible(true); 735 selected_keyword_decoration_->SetVisible(true);
727 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); 736 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword);
728 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); 737 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword));
729 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { 738 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) {
730 // Switch from location icon to show the EV bubble instead. 739 // Switch from location icon to show the EV bubble instead.
731 location_icon_decoration_->SetVisible(false); 740 location_icon_decoration_->SetVisible(false);
732 ev_bubble_decoration_->SetVisible(true); 741 ev_bubble_decoration_->SetVisible(true);
733 742
734 string16 label(toolbar_model_->GetEVCertName()); 743 string16 label(toolbar_model_->GetEVCertName());
735 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); 744 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label));
736 } else if (!keyword.empty() && is_keyword_hint) { 745 } else if (!keyword.empty() && is_keyword_hint && !show_search_token) {
737 keyword_hint_decoration_->SetKeyword(short_name, 746 keyword_hint_decoration_->SetKeyword(short_name,
738 is_extension_keyword); 747 is_extension_keyword);
739 keyword_hint_decoration_->SetVisible(true); 748 keyword_hint_decoration_->SetVisible(true);
740 } 749 }
741 750
751 if (show_search_token) {
752 separator_decoration_->SetVisible(true);
753 search_token_decoration_->set_search_provider_name(GetSearchProviderName());
754 search_token_decoration_->SetVisible(true);
755 }
756
742 // These need to change anytime the layout changes. 757 // These need to change anytime the layout changes.
743 // TODO(shess): Anytime the field editor might have changed, the 758 // TODO(shess): Anytime the field editor might have changed, the
744 // cursor rects almost certainly should have changed. The tooltips 759 // cursor rects almost certainly should have changed. The tooltips
745 // might change even when the rects don't change. 760 // might change even when the rects don't change.
746 OnDecorationsChanged(); 761 OnDecorationsChanged();
747 } 762 }
748 763
749 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { 764 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) {
750 AutocompleteTextFieldCell* cell = [field_ cell]; 765 AutocompleteTextFieldCell* cell = [field_ cell];
751 NSRect frame = [cell frameForDecoration:decoration 766 NSRect frame = [cell frameForDecoration:decoration
(...skipping 25 matching lines...) Expand all
777 visible = false; 792 visible = false;
778 star_decoration_->SetVisible(visible); 793 star_decoration_->SetVisible(visible);
779 } 794 }
780 795
781 void LocationBarViewMac::UpdatePlusDecorationVisibility() { 796 void LocationBarViewMac::UpdatePlusDecorationVisibility() {
782 if (extensions::FeatureSwitch::action_box()->IsEnabled()) { 797 if (extensions::FeatureSwitch::action_box()->IsEnabled()) {
783 // If the action box is enabled, hide it when input is in progress. 798 // If the action box is enabled, hide it when input is in progress.
784 plus_decoration_->SetVisible(!toolbar_model_->GetInputInProgress()); 799 plus_decoration_->SetVisible(!toolbar_model_->GetInputInProgress());
785 } 800 }
786 } 801 }
802
803 string16 LocationBarViewMac::GetSearchProviderName() const {
804 if (!toolbar_model_->GetInputInProgress() &&
805 toolbar_model_->WouldReplaceSearchURLWithSearchTerms()) {
806 const TemplateURL* template_url =
807 TemplateURLServiceFactory::GetForProfile(profile_)->
808 GetDefaultSearchProvider();
809 if (template_url)
810 return template_url->short_name();
811 }
812 return string16();
813 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698