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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc

Issue 6306011: Remove wstring from autocomplete. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/autocomplete/autocomplete_popup_view_gtk.h" 5 #include "chrome/browser/autocomplete/autocomplete_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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 void DrawFullPixbuf(GdkDrawable* drawable, GdkGC* gc, GdkPixbuf* pixbuf, 99 void DrawFullPixbuf(GdkDrawable* drawable, GdkGC* gc, GdkPixbuf* pixbuf,
100 gint dest_x, gint dest_y) { 100 gint dest_x, gint dest_y) {
101 gdk_draw_pixbuf(drawable, gc, pixbuf, 101 gdk_draw_pixbuf(drawable, gc, pixbuf,
102 0, 0, // Source. 102 0, 0, // Source.
103 dest_x, dest_y, // Dest. 103 dest_x, dest_y, // Dest.
104 -1, -1, // Width/height (auto). 104 -1, -1, // Width/height (auto).
105 GDK_RGB_DITHER_NONE, 0, 0); // Don't dither. 105 GDK_RGB_DITHER_NONE, 0, 0); // Don't dither.
106 } 106 }
107 107
108 // TODO(deanm): Find some better home for this, and make it more efficient. 108 // TODO(deanm): Find some better home for this, and make it more efficient.
109 size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { 109 size_t GetUTF8Offset(const string16& text, size_t text_offset) {
110 return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); 110 return UTF16ToUTF8(text.substr(0, text_offset)).size();
111 } 111 }
112 112
113 // Generates the normal URL color, a green color used in unhighlighted URL 113 // Generates the normal URL color, a green color used in unhighlighted URL
114 // text. It is a mix of |kURLTextColor| and the current text color. Unlike the 114 // text. It is a mix of |kURLTextColor| and the current text color. Unlike the
115 // selected text color, it is more important to match the qualities of the 115 // selected text color, it is more important to match the qualities of the
116 // foreground typeface color instead of taking the background into account. 116 // foreground typeface color instead of taking the background into account.
117 GdkColor NormalURLColor(GdkColor foreground) { 117 GdkColor NormalURLColor(GdkColor foreground) {
118 color_utils::HSL fg_hsl; 118 color_utils::HSL fg_hsl;
119 color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl); 119 color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl);
120 120
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 double opposite_l = fg_hsl.l; 163 double opposite_l = fg_hsl.l;
164 double l = std::max(0.1, std::min(0.9, opposite_l)); 164 double l = std::max(0.1, std::min(0.9, opposite_l));
165 165
166 color_utils::HSL output = { hue_hsl.h, s, l }; 166 color_utils::HSL output = { hue_hsl.h, s, l };
167 return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255)); 167 return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255));
168 } 168 }
169 } // namespace 169 } // namespace
170 170
171 void AutocompletePopupViewGtk::SetupLayoutForMatch( 171 void AutocompletePopupViewGtk::SetupLayoutForMatch(
172 PangoLayout* layout, 172 PangoLayout* layout,
173 const std::wstring& text, 173 const string16& text,
174 const AutocompleteMatch::ACMatchClassifications& classifications, 174 const AutocompleteMatch::ACMatchClassifications& classifications,
175 const GdkColor* base_color, 175 const GdkColor* base_color,
176 const GdkColor* dim_color, 176 const GdkColor* dim_color,
177 const GdkColor* url_color, 177 const GdkColor* url_color,
178 const std::string& prefix_text) { 178 const std::string& prefix_text) {
179 // In RTL, mark text with left-to-right embedding mark if there is no strong 179 // In RTL, mark text with left-to-right embedding mark if there is no strong
180 // RTL characters inside it, so the ending punctuation displays correctly 180 // RTL characters inside it, so the ending punctuation displays correctly
181 // and the eliding ellipsis displays correctly. We only mark the text with 181 // and the eliding ellipsis displays correctly. We only mark the text with
182 // LRE. Wrapping it with LRE and PDF by calling AdjustStringForLocaleDirection 182 // LRE. Wrapping it with LRE and PDF by calling AdjustStringForLocaleDirection
183 // will render the elllipsis at the left of the elided pure LTR text. 183 // or WrapStringWithLTRFormatting will render the elllipsis at the left of the
184 // elided pure LTR text.
184 bool marked_with_lre = false; 185 bool marked_with_lre = false;
185 std::wstring localized_text = text; 186 string16 localized_text = text;
186 bool is_rtl = base::i18n::IsRTL(); 187 bool is_rtl = base::i18n::IsRTL();
187 if (is_rtl && !base::i18n::StringContainsStrongRTLChars(localized_text)) { 188 if (is_rtl && !base::i18n::StringContainsStrongRTLChars(localized_text)) {
188 localized_text.insert(0, 1, 189 localized_text.insert(0, 1, base::i18n::kLeftToRightEmbeddingMark);
189 static_cast<wchar_t>(base::i18n::kLeftToRightEmbeddingMark));
190 marked_with_lre = true; 190 marked_with_lre = true;
191 } 191 }
192 192
193 // We can have a prefix, or insert additional characters while processing the 193 // We can have a prefix, or insert additional characters while processing the
194 // classifications. We need to take this in to account when we translate the 194 // classifications. We need to take this in to account when we translate the
195 // wide offsets in the classification into text_utf8 byte offsets. 195 // UTF-16 offsets in the classification into text_utf8 byte offsets.
196 size_t additional_offset = prefix_text.size(); // Length in utf-8 bytes. 196 size_t additional_offset = prefix_text.size(); // Length in utf-8 bytes.
197 std::string text_utf8 = prefix_text + WideToUTF8(localized_text); 197 std::string text_utf8 = prefix_text + UTF16ToUTF8(localized_text);
198 198
199 PangoAttrList* attrs = pango_attr_list_new(); 199 PangoAttrList* attrs = pango_attr_list_new();
200 200
201 // TODO(deanm): This is a hack, just to handle coloring prefix_text. 201 // TODO(deanm): This is a hack, just to handle coloring prefix_text.
202 // Hopefully I can clean up the match situation a bit and this will 202 // Hopefully I can clean up the match situation a bit and this will
203 // come out cleaner. For now, apply the base color to the whole text 203 // come out cleaner. For now, apply the base color to the whole text
204 // so that our prefix will have the base color applied. 204 // so that our prefix will have the base color applied.
205 PangoAttribute* base_fg_attr = pango_attr_foreground_new( 205 PangoAttribute* base_fg_attr = pango_attr_foreground_new(
206 base_color->red, base_color->green, base_color->blue); 206 base_color->red, base_color->green, base_color->blue);
207 pango_attr_list_insert(attrs, base_fg_attr); // Ownership taken. 207 pango_attr_list_insert(attrs, base_fg_attr); // Ownership taken.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 return std::min(line, model_->result().size() - 1); 466 return std::min(line, model_->result().size() - 1);
467 } 467 }
468 468
469 void AutocompletePopupViewGtk::AcceptLine(size_t line, 469 void AutocompletePopupViewGtk::AcceptLine(size_t line,
470 WindowOpenDisposition disposition) { 470 WindowOpenDisposition disposition) {
471 const AutocompleteMatch& match = model_->result().match_at(line); 471 const AutocompleteMatch& match = model_->result().match_at(line);
472 // OpenURL() may close the popup, which will clear the result set and, by 472 // OpenURL() may close the popup, which will clear the result set and, by
473 // extension, |match| and its contents. So copy the relevant strings out to 473 // extension, |match| and its contents. So copy the relevant strings out to
474 // make sure they stay alive until the call completes. 474 // make sure they stay alive until the call completes.
475 const GURL url(match.destination_url); 475 const GURL url(match.destination_url);
476 std::wstring keyword; 476 string16 keyword;
477 const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword); 477 const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword);
478 edit_view_->OpenURL(url, disposition, match.transition, GURL(), line, 478 edit_view_->OpenURL(url, disposition, match.transition, GURL(), line,
479 is_keyword_hint ? std::wstring() : keyword); 479 is_keyword_hint ? string16() : keyword);
480 } 480 }
481 481
482 GdkPixbuf* AutocompletePopupViewGtk::IconForMatch( 482 GdkPixbuf* AutocompletePopupViewGtk::IconForMatch(
483 const AutocompleteMatch& match, bool selected) { 483 const AutocompleteMatch& match, bool selected) {
484 const SkBitmap* bitmap = model_->GetSpecialIconForMatch(match); 484 const SkBitmap* bitmap = model_->GetSpecialIconForMatch(match);
485 if (bitmap) { 485 if (bitmap) {
486 if (!ContainsKey(pixbufs_, bitmap)) 486 if (!ContainsKey(pixbufs_, bitmap))
487 pixbufs_[bitmap] = gfx::GdkPixbufFromSkBitmap(bitmap); 487 pixbufs_[bitmap] = gfx::GdkPixbufFromSkBitmap(bitmap);
488 return pixbufs_[bitmap]; 488 return pixbufs_[bitmap];
489 } 489 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 (text_width - actual_content_width - 665 (text_width - actual_content_width -
666 (actual_description_width / PANGO_SCALE)), 666 (actual_description_width / PANGO_SCALE)),
667 content_y, layout_); 667 content_y, layout_);
668 } 668 }
669 } 669 }
670 670
671 g_object_unref(gc); 671 g_object_unref(gc);
672 672
673 return TRUE; 673 return TRUE;
674 } 674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698