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

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

Issue 10829370: Make search icon in omnibox results hidpi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 270
271 // static 271 // static
272 bool OmniboxResultView::SortRunsVisually(const RunData& lhs, 272 bool OmniboxResultView::SortRunsVisually(const RunData& lhs,
273 const RunData& rhs) { 273 const RunData& rhs) {
274 return lhs.visual_order < rhs.visual_order; 274 return lhs.visual_order < rhs.visual_order;
275 } 275 }
276 276
277 // static 277 // static
278 int OmniboxResultView::default_icon_size_ = 0; 278 int OmniboxResultView::default_icon_size_ = 0;
279 279
280 const SkBitmap* OmniboxResultView::GetIcon() const { 280 gfx::ImageSkia OmniboxResultView::GetIcon() const {
281 const SkBitmap* bitmap = model_->GetIconIfExtensionMatch(model_index_); 281 const gfx::Image image = model_->GetIconIfExtensionMatch(model_index_);
282 if (bitmap) 282 if (!image.IsEmpty())
283 return bitmap; 283 return image.AsImageSkia();
284 284
285 int icon = match_.starred ? 285 int icon = match_.starred ?
286 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); 286 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type);
287 if (GetState() == SELECTED) { 287 if (GetState() == SELECTED) {
288 switch (icon) { 288 switch (icon) {
289 case IDR_OMNIBOX_EXTENSION_APP: 289 case IDR_OMNIBOX_EXTENSION_APP:
290 icon = IDR_OMNIBOX_EXTENSION_APP_SELECTED; 290 icon = IDR_OMNIBOX_EXTENSION_APP_SELECTED;
291 break; 291 break;
292 case IDR_OMNIBOX_HTTP: 292 case IDR_OMNIBOX_HTTP:
293 icon = IDR_OMNIBOX_HTTP_SELECTED; 293 icon = IDR_OMNIBOX_HTTP_SELECTED;
294 break; 294 break;
295 case IDR_OMNIBOX_SEARCH: 295 case IDR_OMNIBOX_SEARCH:
296 icon = IDR_OMNIBOX_SEARCH_SELECTED; 296 icon = IDR_OMNIBOX_SEARCH_SELECTED;
297 break; 297 break;
298 case IDR_OMNIBOX_STAR: 298 case IDR_OMNIBOX_STAR:
299 icon = IDR_OMNIBOX_STAR_SELECTED; 299 icon = IDR_OMNIBOX_STAR_SELECTED;
300 break; 300 break;
301 default: 301 default:
302 NOTREACHED(); 302 NOTREACHED();
303 break; 303 break;
304 } 304 }
305 } 305 }
306 return ui::ResourceBundle::GetSharedInstance().GetBitmapNamed(icon); 306 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon);
307 } 307 }
308 308
309 const gfx::ImageSkia* OmniboxResultView::GetKeywordIcon() const { 309 const gfx::ImageSkia* OmniboxResultView::GetKeywordIcon() const {
310 // NOTE: If we ever begin returning icons of varying size, then callers need 310 // NOTE: If we ever begin returning icons of varying size, then callers need
311 // to ensure that |keyword_icon_| is resized each time its image is reset. 311 // to ensure that |keyword_icon_| is resized each time its image is reset.
312 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 312 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
313 (GetState() == SELECTED) ? IDR_OMNIBOX_TTS_SELECTED : IDR_OMNIBOX_TTS); 313 (GetState() == SELECTED) ? IDR_OMNIBOX_TTS_SELECTED : IDR_OMNIBOX_TTS);
314 } 314 }
315 315
316 int OmniboxResultView::DrawString( 316 int OmniboxResultView::DrawString(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 // * It is also bold, in which case we don't want to fall back 554 // * It is also bold, in which case we don't want to fall back
555 // to a normal ellipsis anyway (see comment above). 555 // to a normal ellipsis anyway (see comment above).
556 } 556 }
557 } 557 }
558 558
559 // We couldn't draw anything. 559 // We couldn't draw anything.
560 runs->clear(); 560 runs->clear();
561 } 561 }
562 562
563 void OmniboxResultView::Layout() { 563 void OmniboxResultView::Layout() {
564 const SkBitmap* icon = GetIcon(); 564 const gfx::ImageSkia icon = GetIcon();
565 565
566 icon_bounds_.SetRect(edge_item_padding_ + 566 icon_bounds_.SetRect(edge_item_padding_ +
567 ((icon->width() == default_icon_size_) ? 567 ((icon.width() == default_icon_size_) ?
568 0 : LocationBarView::kIconInternalPadding), 568 0 : LocationBarView::kIconInternalPadding),
569 (height() - icon->height()) / 2, icon->width(), icon->height()); 569 (height() - icon.height()) / 2, icon.width(), icon.height());
570 570
571 int text_x = edge_item_padding_ + default_icon_size_ + item_padding_; 571 int text_x = edge_item_padding_ + default_icon_size_ + item_padding_;
572 int text_height = GetTextHeight(); 572 int text_height = GetTextHeight();
573 int text_width; 573 int text_width;
574 574
575 if (match_.associated_keyword.get()) { 575 if (match_.associated_keyword.get()) {
576 const int kw_collapsed_size = 576 const int kw_collapsed_size =
577 keyword_icon_->width() + edge_item_padding_; 577 keyword_icon_->width() + edge_item_padding_;
578 const int max_kw_x = width() - kw_collapsed_size; 578 const int max_kw_x = width() - kw_collapsed_size;
579 const int kw_x = 579 const int kw_x =
(...skipping 18 matching lines...) Expand all
598 } 598 }
599 599
600 void OmniboxResultView::OnPaint(gfx::Canvas* canvas) { 600 void OmniboxResultView::OnPaint(gfx::Canvas* canvas) {
601 const ResultViewState state = GetState(); 601 const ResultViewState state = GetState();
602 if (state != NORMAL) 602 if (state != NORMAL)
603 canvas->DrawColor(GetColor(state, BACKGROUND)); 603 canvas->DrawColor(GetColor(state, BACKGROUND));
604 604
605 if (!match_.associated_keyword.get() || 605 if (!match_.associated_keyword.get() ||
606 keyword_icon_->x() > icon_bounds_.right()) { 606 keyword_icon_->x() > icon_bounds_.right()) {
607 // Paint the icon. 607 // Paint the icon.
608 canvas->DrawImageInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), 608 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_),
609 icon_bounds_.y()); 609 icon_bounds_.y());
610 610
611 // Paint the text. 611 // Paint the text.
612 int x = GetMirroredXForRect(text_bounds_); 612 int x = GetMirroredXForRect(text_bounds_);
613 mirroring_context_->Initialize(x, text_bounds_.width()); 613 mirroring_context_->Initialize(x, text_bounds_.width());
614 PaintMatch(canvas, match_, x); 614 PaintMatch(canvas, match_, x);
615 } 615 }
616 616
617 if (match_.associated_keyword.get()) { 617 if (match_.associated_keyword.get()) {
618 // Paint the keyword text. 618 // Paint the keyword text.
619 int x = GetMirroredXForRect(keyword_text_bounds_); 619 int x = GetMirroredXForRect(keyword_text_bounds_);
620 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); 620 mirroring_context_->Initialize(x, keyword_text_bounds_.width());
621 PaintMatch(canvas, *match_.associated_keyword.get(), x); 621 PaintMatch(canvas, *match_.associated_keyword.get(), x);
622 } 622 }
623 } 623 }
624 624
625 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) { 625 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) {
626 Layout(); 626 Layout();
627 SchedulePaint(); 627 SchedulePaint();
628 } 628 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698