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 // This file defines helper functions shared by the various implementations | 5 // This file defines helper functions shared by the various implementations |
6 // of OmniboxView. | 6 // of OmniboxView. |
7 | 7 |
8 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 8 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 108 } |
109 | 109 |
110 int OmniboxView::GetIcon() const { | 110 int OmniboxView::GetIcon() const { |
111 if (!IsEditingOrEmpty()) | 111 if (!IsEditingOrEmpty()) |
112 return controller_->GetToolbarModel()->GetIcon(); | 112 return controller_->GetToolbarModel()->GetIcon(); |
113 int id = AutocompleteMatch::TypeToIcon(model_.get() ? | 113 int id = AutocompleteMatch::TypeToIcon(model_.get() ? |
114 model_->CurrentTextType() : AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 114 model_->CurrentTextType() : AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
115 return (id == IDR_OMNIBOX_HTTP) ? IDR_LOCATION_BAR_HTTP : id; | 115 return (id == IDR_OMNIBOX_HTTP) ? IDR_LOCATION_BAR_HTTP : id; |
116 } | 116 } |
117 | 117 |
118 base::string16 OmniboxView::GetHintText() const { | |
119 // If the user is in keyword mode (the "Search <some site>:" chip is showing) | |
120 // then it doesn't make sense to show the "Search <default search engine>" | |
121 // hint text. | |
122 if (model_->is_keyword_selected()) | |
123 return base::string16(); | |
124 | |
125 // Attempt to determine the default search provider and use that in the hint | |
126 // text. | |
127 TemplateURLService* template_url_service = | |
128 TemplateURLServiceFactory::GetForProfile(model_->profile()); | |
129 if (template_url_service) { | |
130 TemplateURL* template_url = | |
131 template_url_service->GetDefaultSearchProvider(); | |
132 if (template_url) | |
133 return l10n_util::GetStringFUTF16( | |
134 IDS_OMNIBOX_EMPTY_HINT_WITH_DEFAULT_SEARCH_PROVIDER, | |
135 template_url->AdjustedShortNameForLocaleDirection()); | |
136 } | |
137 | |
138 // Otherwise return a hint based on there being no default search provider. | |
139 return l10n_util::GetStringUTF16( | |
140 IDS_OMNIBOX_EMPTY_HINT_NO_DEFAULT_SEARCH_PROVIDER); | |
141 } | |
142 | |
143 void OmniboxView::SetUserText(const base::string16& text) { | 118 void OmniboxView::SetUserText(const base::string16& text) { |
144 SetUserText(text, text, true); | 119 SetUserText(text, text, true); |
145 } | 120 } |
146 | 121 |
147 void OmniboxView::SetUserText(const base::string16& text, | 122 void OmniboxView::SetUserText(const base::string16& text, |
148 const base::string16& display_text, | 123 const base::string16& display_text, |
149 bool update_popup) { | 124 bool update_popup) { |
150 if (model_.get()) | 125 if (model_.get()) |
151 model_->SetUserText(text); | 126 model_->SetUserText(text); |
152 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, | 127 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // |profile| can be NULL in tests. | 187 // |profile| can be NULL in tests. |
213 if (profile) | 188 if (profile) |
214 model_.reset(new OmniboxEditModel(this, controller, profile)); | 189 model_.reset(new OmniboxEditModel(this, controller, profile)); |
215 } | 190 } |
216 | 191 |
217 void OmniboxView::TextChanged() { | 192 void OmniboxView::TextChanged() { |
218 EmphasizeURLComponents(); | 193 EmphasizeURLComponents(); |
219 if (model_.get()) | 194 if (model_.get()) |
220 model_->OnChanged(); | 195 model_->OnChanged(); |
221 } | 196 } |
OLD | NEW |