OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/location_bar/selected_keyword_view.h" | 5 #include "chrome/browser/views/location_bar/selected_keyword_view.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/search_engines/template_url_model.h" |
10 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
11 #include "chrome/browser/views/location_bar/keyword_hint_view.h" | 12 #include "chrome/browser/views/location_bar/keyword_hint_view.h" |
12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
13 | 14 |
14 SelectedKeywordView::SelectedKeywordView(const int background_images[], | 15 SelectedKeywordView::SelectedKeywordView(const int background_images[], |
15 int contained_image, | 16 int contained_image, |
16 const SkColor& color, | 17 const SkColor& color, |
17 Profile* profile) | 18 Profile* profile) |
18 : IconLabelBubbleView(background_images, contained_image, color), | 19 : IconLabelBubbleView(background_images, contained_image, color), |
19 profile_(profile) { | 20 profile_(profile) { |
(...skipping 29 matching lines...) Expand all Loading... |
49 } | 50 } |
50 | 51 |
51 void SelectedKeywordView::SetKeyword(const std::wstring& keyword) { | 52 void SelectedKeywordView::SetKeyword(const std::wstring& keyword) { |
52 keyword_ = keyword; | 53 keyword_ = keyword; |
53 if (keyword.empty()) | 54 if (keyword.empty()) |
54 return; | 55 return; |
55 DCHECK(profile_); | 56 DCHECK(profile_); |
56 if (!profile_->GetTemplateURLModel()) | 57 if (!profile_->GetTemplateURLModel()) |
57 return; | 58 return; |
58 | 59 |
59 const std::wstring short_name = | 60 bool is_extension_keyword; |
60 KeywordHintView::GetKeywordName(profile_, keyword); | 61 const std::wstring short_name = profile_->GetTemplateURLModel()-> |
61 full_label_.SetText(l10n_util::GetStringF(IDS_OMNIBOX_KEYWORD_TEXT, | 62 GetKeywordShortName(keyword, &is_extension_keyword); |
62 short_name)); | 63 int message_id = is_extension_keyword ? |
| 64 IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT; |
| 65 full_label_.SetText(l10n_util::GetStringF(message_id, short_name)); |
63 const std::wstring min_string = CalculateMinString(short_name); | 66 const std::wstring min_string = CalculateMinString(short_name); |
64 partial_label_.SetText(min_string.empty() ? | 67 partial_label_.SetText(min_string.empty() ? |
65 full_label_.GetText() : | 68 full_label_.GetText() : |
66 l10n_util::GetStringF(IDS_OMNIBOX_KEYWORD_TEXT, min_string)); | 69 l10n_util::GetStringF(message_id, min_string)); |
67 } | 70 } |
68 | 71 |
69 std::wstring SelectedKeywordView::CalculateMinString( | 72 std::wstring SelectedKeywordView::CalculateMinString( |
70 const std::wstring& description) { | 73 const std::wstring& description) { |
71 // Chop at the first '.' or whitespace. | 74 // Chop at the first '.' or whitespace. |
72 const size_t dot_index = description.find(L'.'); | 75 const size_t dot_index = description.find(L'.'); |
73 const size_t ws_index = description.find_first_of(kWhitespaceWide); | 76 const size_t ws_index = description.find_first_of(kWhitespaceWide); |
74 size_t chop_index = std::min(dot_index, ws_index); | 77 size_t chop_index = std::min(dot_index, ws_index); |
75 std::wstring min_string; | 78 std::wstring min_string; |
76 if (chop_index == std::wstring::npos) { | 79 if (chop_index == std::wstring::npos) { |
77 // No dot or whitespace, truncate to at most 3 chars. | 80 // No dot or whitespace, truncate to at most 3 chars. |
78 min_string = l10n_util::TruncateString(description, 3); | 81 min_string = l10n_util::TruncateString(description, 3); |
79 } else { | 82 } else { |
80 min_string = description.substr(0, chop_index); | 83 min_string = description.substr(0, chop_index); |
81 } | 84 } |
82 base::i18n::AdjustStringForLocaleDirection(min_string, &min_string); | 85 base::i18n::AdjustStringForLocaleDirection(min_string, &min_string); |
83 return min_string; | 86 return min_string; |
84 } | 87 } |
OLD | NEW |