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

Side by Side Diff: chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc

Issue 10396003: Add Icon Support for New Autofill Gtk UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 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
« no previous file with comments | « chrome/browser/ui/gtk/gtk_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h" 5 #include "chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 // Return a Rect for the space for a result line. This excludes the border, 101 // Return a Rect for the space for a result line. This excludes the border,
102 // but includes the padding. This is the area that is colored for a selection. 102 // but includes the padding. This is the area that is colored for a selection.
103 gfx::Rect GetRectForLine(size_t line, int width) { 103 gfx::Rect GetRectForLine(size_t line, int width) {
104 return gfx::Rect(kBorderThickness, 104 return gfx::Rect(kBorderThickness,
105 (line * kHeightPerResult) + kBorderThickness, 105 (line * kHeightPerResult) + kBorderThickness,
106 width - (kBorderThickness * 2), 106 width - (kBorderThickness * 2),
107 kHeightPerResult); 107 kHeightPerResult);
108 } 108 }
109 109
110 // Helper for drawing an entire pixbuf without dithering.
111 void DrawFullImage(cairo_t* cr, GtkWidget* widget, const gfx::Image* image,
112 gint dest_x, gint dest_y) {
113 gfx::CairoCachedSurface* surface = image->ToCairo();
114 surface->SetSource(cr, widget, dest_x, dest_y);
115 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
116 cairo_rectangle(cr, dest_x, dest_y, surface->Width(), surface->Height());
117 cairo_fill(cr);
118 }
119
120 // TODO(deanm): Find some better home for this, and make it more efficient. 110 // TODO(deanm): Find some better home for this, and make it more efficient.
121 size_t GetUTF8Offset(const string16& text, size_t text_offset) { 111 size_t GetUTF8Offset(const string16& text, size_t text_offset) {
122 return UTF16ToUTF8(text.substr(0, text_offset)).length(); 112 return UTF16ToUTF8(text.substr(0, text_offset)).length();
123 } 113 }
124 114
125 // Generates the normal URL color, a green color used in unhighlighted URL 115 // Generates the normal URL color, a green color used in unhighlighted URL
126 // text. It is a mix of |kURLTextColor| and the current text color. Unlike the 116 // text. It is a mix of |kURLTextColor| and the current text color. Unlike the
127 // selected text color, it is more important to match the qualities of the 117 // selected text color, it is more important to match the qualities of the
128 // foreground typeface color instead of taking the background into account. 118 // foreground typeface color instead of taking the background into account.
129 GdkColor NormalURLColor(GdkColor foreground) { 119 GdkColor NormalURLColor(GdkColor foreground) {
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 &hovered_background_color_); 645 &hovered_background_color_);
656 // This entry is selected or hovered, fill a rect with the color. 646 // This entry is selected or hovered, fill a rect with the color.
657 cairo_rectangle(cr, line_rect.x(), line_rect.y(), 647 cairo_rectangle(cr, line_rect.x(), line_rect.y(),
658 line_rect.width(), line_rect.height()); 648 line_rect.width(), line_rect.height());
659 cairo_fill(cr); 649 cairo_fill(cr);
660 } 650 }
661 651
662 int icon_start_x = ltr ? kIconLeftPadding : 652 int icon_start_x = ltr ? kIconLeftPadding :
663 (line_rect.width() - kIconLeftPadding - kIconWidth); 653 (line_rect.width() - kIconLeftPadding - kIconWidth);
664 // Draw the icon for this result. 654 // Draw the icon for this result.
665 DrawFullImage(cr, widget, 655 gtk_util::DrawFullImage(cr, widget,
666 IconForMatch(*match, is_selected, is_selected_keyword), 656 IconForMatch(*match, is_selected,
667 icon_start_x, line_rect.y() + kIconTopPadding); 657 is_selected_keyword),
658 icon_start_x, line_rect.y() + kIconTopPadding);
668 659
669 // Draw the results text vertically centered in the results space. 660 // Draw the results text vertically centered in the results space.
670 // First draw the contents / url, but don't let it take up the whole width 661 // First draw the contents / url, but don't let it take up the whole width
671 // if there is also a description to be shown. 662 // if there is also a description to be shown.
672 bool has_description = !match->description.empty(); 663 bool has_description = !match->description.empty();
673 int text_width = window_rect.width() - (kIconAreaWidth + kRightPadding); 664 int text_width = window_rect.width() - (kIconAreaWidth + kRightPadding);
674 int allocated_content_width = has_description ? 665 int allocated_content_width = has_description ?
675 static_cast<int>(text_width * kContentWidthPercentage) : text_width; 666 static_cast<int>(text_width * kContentWidthPercentage) : text_width;
676 pango_layout_set_width(layout_, allocated_content_width * PANGO_SCALE); 667 pango_layout_set_width(layout_, allocated_content_width * PANGO_SCALE);
677 668
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 pango_cairo_show_layout(cr, layout_); 722 pango_cairo_show_layout(cr, layout_);
732 cairo_restore(cr); 723 cairo_restore(cr);
733 } 724 }
734 725
735 if (match->associated_keyword.get()) { 726 if (match->associated_keyword.get()) {
736 // If this entry has an associated keyword, draw the arrow at the extreme 727 // If this entry has an associated keyword, draw the arrow at the extreme
737 // other side of the omnibox. 728 // other side of the omnibox.
738 icon_start_x = ltr ? (line_rect.width() - kIconLeftPadding - kIconWidth) : 729 icon_start_x = ltr ? (line_rect.width() - kIconLeftPadding - kIconWidth) :
739 kIconLeftPadding; 730 kIconLeftPadding;
740 // Draw the icon for this result. 731 // Draw the icon for this result.
741 DrawFullImage(cr, widget, 732 gtk_util::DrawFullImage(cr, widget,
742 theme_service_->GetImageNamed( 733 theme_service_->GetImageNamed(
743 is_selected ? IDR_OMNIBOX_TTS_DARK : IDR_OMNIBOX_TTS), 734 is_selected ? IDR_OMNIBOX_TTS_DARK :
744 icon_start_x, line_rect.y() + kIconTopPadding); 735 IDR_OMNIBOX_TTS),
736 icon_start_x, line_rect.y() + kIconTopPadding);
745 } 737 }
746 } 738 }
747 739
748 cairo_destroy(cr); 740 cairo_destroy(cr);
749 return TRUE; 741 return TRUE;
750 } 742 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/gtk_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698