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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_result_view.cc

Issue 15745031: Restyle omnibox popup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove code from toolbar. Created 7 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 | Annotate | Revision Log
OLDNEW
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 // For WinDDK ATL compatibility, these ATL headers must come first. 5 // For WinDDK ATL compatibility, these ATL headers must come first.
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <atlbase.h> // NOLINT 8 #include <atlbase.h> // NOLINT
9 #include <atlwin.h> // NOLINT 9 #include <atlwin.h> // NOLINT
10 #endif 10 #endif
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 private: 99 private:
100 int center_; 100 int center_;
101 int right_; 101 int right_;
102 102
103 DISALLOW_COPY_AND_ASSIGN(MirroringContext); 103 DISALLOW_COPY_AND_ASSIGN(MirroringContext);
104 }; 104 };
105 105
106 OmniboxResultView::OmniboxResultView( 106 OmniboxResultView::OmniboxResultView(
107 OmniboxResultViewModel* model, 107 OmniboxResultViewModel* model,
108 int model_index, 108 int model_index,
109 views::View* location_bar, 109 LocationBarView* location_bar_view,
110 const gfx::Font& font) 110 const gfx::Font& font)
111 : edge_item_padding_(LocationBarView::GetItemPadding()), 111 : edge_item_padding_(LocationBarView::GetItemPadding()),
112 item_padding_(LocationBarView::GetItemPadding()), 112 item_padding_(LocationBarView::GetItemPadding()),
113 minimum_text_vertical_padding_(kMinimumTextVerticalPadding), 113 minimum_text_vertical_padding_(kMinimumTextVerticalPadding),
114 model_(model), 114 model_(model),
115 model_index_(model_index), 115 model_index_(model_index),
116 location_bar_(location_bar), 116 location_bar_view_(location_bar_view),
117 font_(font), 117 font_(font),
118 font_height_(std::max(font.GetHeight(), 118 font_height_(std::max(font.GetHeight(),
119 font.DeriveFont(0, gfx::BOLD).GetHeight())), 119 font.DeriveFont(0, gfx::BOLD).GetHeight())),
120 ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), 120 ellipsis_width_(font.GetStringWidth(string16(kEllipsis))),
121 mirroring_context_(new MirroringContext()), 121 mirroring_context_(new MirroringContext()),
122 keyword_icon_(new views::ImageView()), 122 keyword_icon_(new views::ImageView()),
123 animation_(new ui::SlideAnimation(this)) { 123 animation_(new ui::SlideAnimation(this)) {
124 CHECK_GE(model_index, 0); 124 CHECK_GE(model_index, 0);
125 if (default_icon_size_ == 0) { 125 if (default_icon_size_ == 0) {
126 default_icon_size_ = 126 default_icon_size_ =
127 location_bar_->GetThemeProvider()->GetImageSkiaNamed( 127 location_bar_view_->GetThemeProvider()->GetImageSkiaNamed(
128 AutocompleteMatch::TypeToIcon( 128 AutocompleteMatch::TypeToIcon(
129 AutocompleteMatchType::URL_WHAT_YOU_TYPED))->width(); 129 AutocompleteMatchType::URL_WHAT_YOU_TYPED))->width();
130 } 130 }
131 keyword_icon_->set_owned_by_client(); 131 keyword_icon_->set_owned_by_client();
132 keyword_icon_->EnableCanvasFlippingForRTLUI(true); 132 keyword_icon_->EnableCanvasFlippingForRTLUI(true);
133 keyword_icon_->SetImage(GetKeywordIcon()); 133 keyword_icon_->SetImage(GetKeywordIcon());
134 keyword_icon_->SizeToPreferredSize(); 134 keyword_icon_->SizeToPreferredSize();
135 } 135 }
136 136
137 OmniboxResultView::~OmniboxResultView() { 137 OmniboxResultView::~OmniboxResultView() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 214
215 //////////////////////////////////////////////////////////////////////////////// 215 ////////////////////////////////////////////////////////////////////////////////
216 // OmniboxResultView, protected: 216 // OmniboxResultView, protected:
217 217
218 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const { 218 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const {
219 if (model_->IsSelectedIndex(model_index_)) 219 if (model_->IsSelectedIndex(model_index_))
220 return SELECTED; 220 return SELECTED;
221 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL; 221 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL;
222 } 222 }
223 223
224 int OmniboxResultView::GetTextHeight() const {
225 return font_height_;
226 }
227
224 void OmniboxResultView::PaintMatch(gfx::Canvas* canvas, 228 void OmniboxResultView::PaintMatch(gfx::Canvas* canvas,
225 const AutocompleteMatch& match, 229 const AutocompleteMatch& match,
226 int x) { 230 int x) {
227 x = DrawString(canvas, match.contents, match.contents_class, false, x, 231 x = DrawString(canvas, match.contents, match.contents_class, false, x,
228 text_bounds_.y()); 232 text_bounds_.y());
229 233
230 // Paint the description. 234 // Paint the description.
231 // TODO(pkasting): Because we paint in multiple separate pieces, we can wind 235 // TODO(pkasting): Because we paint in multiple separate pieces, we can wind
232 // up with no space even for an ellipsis for one or both of these pieces. 236 // up with no space even for an ellipsis for one or both of these pieces.
233 // Instead, we should paint the entire match as a single long string. This 237 // Instead, we should paint the entire match as a single long string. This
234 // would also let us use a more properly-localizable string than we get with 238 // would also let us use a more properly-localizable string than we get with
235 // just the IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR. 239 // just the IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR.
236 if (!match.description.empty()) { 240 if (!match.description.empty()) {
237 string16 separator = 241 string16 separator =
238 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); 242 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR);
239 ACMatchClassifications classifications; 243 ACMatchClassifications classifications;
240 classifications.push_back( 244 classifications.push_back(
241 ACMatchClassification(0, ACMatchClassification::NONE)); 245 ACMatchClassification(0, ACMatchClassification::NONE));
242 x = DrawString(canvas, separator, classifications, true, x, 246 x = DrawString(canvas, separator, classifications, true, x,
243 text_bounds_.y()); 247 text_bounds_.y());
244 248
245 DrawString(canvas, match.description, match.description_class, true, x, 249 DrawString(canvas, match.description, match.description_class, true, x,
246 text_bounds_.y()); 250 text_bounds_.y());
247 } 251 }
248 } 252 }
249 253
250 int OmniboxResultView::GetTextHeight() const {
251 return font_height_;
252 }
253
254 // static 254 // static
255 void OmniboxResultView::CommonInitColors(const ui::NativeTheme* theme, 255 void OmniboxResultView::CommonInitColors(const ui::NativeTheme* theme,
256 SkColor colors[][NUM_KINDS]) { 256 SkColor colors[][NUM_KINDS]) {
257 colors[HOVERED][BACKGROUND] = 257 colors[HOVERED][BACKGROUND] =
258 color_utils::AlphaBlend(colors[SELECTED][BACKGROUND], 258 color_utils::AlphaBlend(colors[SELECTED][BACKGROUND],
259 colors[NORMAL][BACKGROUND], 64); 259 colors[NORMAL][BACKGROUND], 64);
260 colors[HOVERED][TEXT] = colors[NORMAL][TEXT]; 260 colors[HOVERED][TEXT] = colors[NORMAL][TEXT];
261 #if defined(USE_AURA) 261 #if defined(USE_AURA)
262 const bool is_aura = theme == ui::NativeThemeAura::instance(); 262 const bool is_aura = theme == ui::NativeThemeAura::instance();
263 #else 263 #else
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 icon = IDR_OMNIBOX_SEARCH_SELECTED; 318 icon = IDR_OMNIBOX_SEARCH_SELECTED;
319 break; 319 break;
320 case IDR_OMNIBOX_STAR: 320 case IDR_OMNIBOX_STAR:
321 icon = IDR_OMNIBOX_STAR_SELECTED; 321 icon = IDR_OMNIBOX_STAR_SELECTED;
322 break; 322 break;
323 default: 323 default:
324 NOTREACHED(); 324 NOTREACHED();
325 break; 325 break;
326 } 326 }
327 } 327 }
328 return *(location_bar_->GetThemeProvider()->GetImageSkiaNamed(icon)); 328 return *(location_bar_view_->GetThemeProvider()->GetImageSkiaNamed(icon));
329 } 329 }
330 330
331 const gfx::ImageSkia* OmniboxResultView::GetKeywordIcon() const { 331 const gfx::ImageSkia* OmniboxResultView::GetKeywordIcon() const {
332 // NOTE: If we ever begin returning icons of varying size, then callers need 332 // NOTE: If we ever begin returning icons of varying size, then callers need
333 // to ensure that |keyword_icon_| is resized each time its image is reset. 333 // to ensure that |keyword_icon_| is resized each time its image is reset.
334 return location_bar_->GetThemeProvider()->GetImageSkiaNamed( 334 return location_bar_view_->GetThemeProvider()->GetImageSkiaNamed(
335 (GetState() == SELECTED) ? IDR_OMNIBOX_TTS_SELECTED : IDR_OMNIBOX_TTS); 335 (GetState() == SELECTED) ? IDR_OMNIBOX_TTS_SELECTED : IDR_OMNIBOX_TTS);
336 } 336 }
337 337
338 int OmniboxResultView::DrawString( 338 int OmniboxResultView::DrawString(
339 gfx::Canvas* canvas, 339 gfx::Canvas* canvas,
340 const string16& text, 340 const string16& text,
341 const ACMatchClassifications& classifications, 341 const ACMatchClassifications& classifications,
342 bool force_dim, 342 bool force_dim,
343 int x, 343 int x,
344 int y) { 344 int y) {
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 int x = GetMirroredXForRect(keyword_text_bounds_); 623 int x = GetMirroredXForRect(keyword_text_bounds_);
624 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); 624 mirroring_context_->Initialize(x, keyword_text_bounds_.width());
625 PaintMatch(canvas, *match_.associated_keyword.get(), x); 625 PaintMatch(canvas, *match_.associated_keyword.get(), x);
626 } 626 }
627 } 627 }
628 628
629 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) { 629 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) {
630 Layout(); 630 Layout();
631 SchedulePaint(); 631 SchedulePaint();
632 } 632 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698