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

Side by Side Diff: chrome/browser/views/location_bar/keyword_hint_view.cc

Issue 2078021: First pass at experimental omnibox API. There are plenty of rough edges and (Closed)
Patch Set: no prefer_keyword Created 10 years, 6 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
OLDNEW
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/keyword_hint_view.h" 5 #include "chrome/browser/views/location_bar/keyword_hint_view.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 void KeywordHintView::SetKeyword(const std::wstring& keyword) { 50 void KeywordHintView::SetKeyword(const std::wstring& keyword) {
51 keyword_ = keyword; 51 keyword_ = keyword;
52 if (keyword_.empty()) 52 if (keyword_.empty())
53 return; 53 return;
54 DCHECK(profile_); 54 DCHECK(profile_);
55 if (!profile_->GetTemplateURLModel()) 55 if (!profile_->GetTemplateURLModel())
56 return; 56 return;
57 57
58 std::vector<size_t> content_param_offsets; 58 std::vector<size_t> content_param_offsets;
59 bool is_extension_keyword;
60 std::wstring short_name = profile_->GetTemplateURLModel()->
61 GetKeywordShortName(keyword, &is_extension_keyword);
62 int message_id = is_extension_keyword ?
63 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT;
59 const std::wstring keyword_hint(l10n_util::GetStringF( 64 const std::wstring keyword_hint(l10n_util::GetStringF(
60 IDS_OMNIBOX_KEYWORD_HINT, std::wstring(), 65 message_id, std::wstring(), short_name, &content_param_offsets));
61 GetKeywordName(profile_, keyword), &content_param_offsets));
62 if (content_param_offsets.size() == 2) { 66 if (content_param_offsets.size() == 2) {
63 leading_label_->SetText( 67 leading_label_->SetText(
64 keyword_hint.substr(0, content_param_offsets.front())); 68 keyword_hint.substr(0, content_param_offsets.front()));
65 trailing_label_->SetText( 69 trailing_label_->SetText(
66 keyword_hint.substr(content_param_offsets.front())); 70 keyword_hint.substr(content_param_offsets.front()));
67 } else { 71 } else {
68 // See comments on an identical NOTREACHED() in search_provider.cc. 72 // See comments on an identical NOTREACHED() in search_provider.cc.
69 NOTREACHED(); 73 NOTREACHED();
70 } 74 }
71 } 75 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 118
115 if (show_labels) { 119 if (show_labels) {
116 pref = leading_label_->GetPreferredSize(); 120 pref = leading_label_->GetPreferredSize();
117 leading_label_->SetBounds(x, 0, pref.width(), height()); 121 leading_label_->SetBounds(x, 0, pref.width(), height());
118 122
119 x += pref.width() + kTabButtonBitmap->width(); 123 x += pref.width() + kTabButtonBitmap->width();
120 pref = trailing_label_->GetPreferredSize(); 124 pref = trailing_label_->GetPreferredSize();
121 trailing_label_->SetBounds(x, 0, pref.width(), height()); 125 trailing_label_->SetBounds(x, 0, pref.width(), height());
122 } 126 }
123 } 127 }
124
125
126 // static
127 std::wstring KeywordHintView::GetKeywordName(Profile* profile,
128 const std::wstring& keyword) {
129 // Make sure the TemplateURL still exists.
130 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel
131 // to track changes to the model, this should become a DCHECK.
132 const TemplateURL* template_url =
133 profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword);
134 if (template_url)
135 return template_url->AdjustedShortNameForLocaleDirection();
136 return std::wstring();
137 }
OLDNEW
« no previous file with comments | « chrome/browser/views/location_bar/keyword_hint_view.h ('k') | chrome/browser/views/location_bar/selected_keyword_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698