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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
14 #include "chrome/browser/search/search.h" | 14 #include "chrome/browser/search/search.h" |
15 #include "chrome/browser/search_engines/template_url_service_factory.h" | 15 #include "chrome/browser/search_engines/template_url_service_factory.h" |
16 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 16 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
17 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 17 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
18 #include "components/search_engines/template_url.h" | 18 #include "components/search_engines/template_url.h" |
19 #include "components/search_engines/template_url_service.h" | 19 #include "components/search_engines/template_url_service.h" |
| 20 #include "grit/component_scaled_resources.h" |
20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 22 #include "grit/theme_resources.h" |
21 #include "ui/base/clipboard/clipboard.h" | 23 #include "ui/base/clipboard/clipboard.h" |
22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
23 | 25 |
24 // static | 26 // static |
25 base::string16 OmniboxView::StripJavascriptSchemas(const base::string16& text) { | 27 base::string16 OmniboxView::StripJavascriptSchemas(const base::string16& text) { |
26 const base::string16 kJsPrefix( | 28 const base::string16 kJsPrefix( |
27 base::ASCIIToUTF16(url::kJavaScriptScheme) + base::ASCIIToUTF16(":")); | 29 base::ASCIIToUTF16(url::kJavaScriptScheme) + base::ASCIIToUTF16(":")); |
28 base::string16 out(text); | 30 base::string16 out(text); |
29 while (StartsWith(out, kJsPrefix, false)) { | 31 while (StartsWith(out, kJsPrefix, false)) { |
30 base::TrimWhitespace(out.substr(kJsPrefix.length()), base::TRIM_LEADING, | 32 base::TrimWhitespace(out.substr(kJsPrefix.length()), base::TRIM_LEADING, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 115 } |
114 | 116 |
115 bool OmniboxView::IsEditingOrEmpty() const { | 117 bool OmniboxView::IsEditingOrEmpty() const { |
116 return (model_.get() && model_->user_input_in_progress()) || | 118 return (model_.get() && model_->user_input_in_progress()) || |
117 (GetOmniboxTextLength() == 0); | 119 (GetOmniboxTextLength() == 0); |
118 } | 120 } |
119 | 121 |
120 int OmniboxView::GetIcon() const { | 122 int OmniboxView::GetIcon() const { |
121 if (!IsEditingOrEmpty()) | 123 if (!IsEditingOrEmpty()) |
122 return controller_->GetToolbarModel()->GetIcon(); | 124 return controller_->GetToolbarModel()->GetIcon(); |
123 return AutocompleteMatch::TypeToLocationBarIcon(model_.get() ? | 125 int id = AutocompleteMatch::TypeToIcon(model_.get() ? |
124 model_->CurrentTextType() : AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 126 model_->CurrentTextType() : AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 127 return (id == IDR_OMNIBOX_HTTP) ? IDR_LOCATION_BAR_HTTP : id; |
125 } | 128 } |
126 | 129 |
127 base::string16 OmniboxView::GetHintText() const { | 130 base::string16 OmniboxView::GetHintText() const { |
128 // If the user is in keyword mode (the "Search <some site>:" chip is showing) | 131 // If the user is in keyword mode (the "Search <some site>:" chip is showing) |
129 // then it doesn't make sense to show the "Search <default search engine>" | 132 // then it doesn't make sense to show the "Search <default search engine>" |
130 // hint text. | 133 // hint text. |
131 if (model_->is_keyword_selected()) | 134 if (model_->is_keyword_selected()) |
132 return base::string16(); | 135 return base::string16(); |
133 | 136 |
134 // Attempt to determine the default search provider and use that in the hint | 137 // Attempt to determine the default search provider and use that in the hint |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // |profile| can be NULL in tests. | 227 // |profile| can be NULL in tests. |
225 if (profile) | 228 if (profile) |
226 model_.reset(new OmniboxEditModel(this, controller, profile)); | 229 model_.reset(new OmniboxEditModel(this, controller, profile)); |
227 } | 230 } |
228 | 231 |
229 void OmniboxView::TextChanged() { | 232 void OmniboxView::TextChanged() { |
230 EmphasizeURLComponents(); | 233 EmphasizeURLComponents(); |
231 if (model_.get()) | 234 if (model_.get()) |
232 model_->OnChanged(); | 235 model_->OnChanged(); |
233 } | 236 } |
OLD | NEW |