diff options
29 files changed, 118 insertions, 102 deletions
diff --git a/app/text_elider.cc b/app/text_elider.cc index 855e3c3..c4052aa 100644 --- a/app/text_elider.cc +++ b/app/text_elider.cc @@ -19,9 +19,10 @@ #include "net/base/net_util.h" #include "net/base/registry_controlled_domain.h" + namespace { -const wchar_t kEllipsis[] = L"\x2026"; +const char* kEllipsis = "\xE2\x80\xA6"; // Cuts |text| to be |length| characters long. If |cut_in_middle| is true, the // middle of the string is removed to leave equal-length pieces from the @@ -29,12 +30,13 @@ const wchar_t kEllipsis[] = L"\x2026"; // and only the beginning remains. If |insert_ellipsis| is true, then an // ellipsis character will by inserted at the cut point. string16 CutString(const string16& text, - size_t length, - bool cut_in_middle, - bool insert_ellipsis) { + size_t length, + bool cut_in_middle, + bool insert_ellipsis) { // TODO(tony): This is wrong, it might split the string in the middle of a // surrogate pair. - const string16 kInsert = WideToUTF16(insert_ellipsis ? kEllipsis : L""); + const string16 kInsert = insert_ellipsis ? UTF8ToUTF16(kEllipsis) : + ASCIIToUTF16(""); if (!cut_in_middle) return text.substr(0, length) + kInsert; // We put the extra character, if any, before the cut. @@ -74,7 +76,7 @@ string16 ElideUrl(const GURL& url, // Now start eliding url_string to fit within available pixel width. // Fist pass - check to see whether entire url_string fits. - int pixel_width_url_string = font.GetStringWidth(UTF16ToWideHack(url_string)); + int pixel_width_url_string = font.GetStringWidth(url_string); if (available_pixel_width >= pixel_width_url_string) return url_string; @@ -86,8 +88,7 @@ string16 ElideUrl(const GURL& url, // Return general elided text if url minus the query fits. string16 url_minus_query = url_string.substr(0, path_start_index + path_len); - if (available_pixel_width >= - font.GetStringWidth(UTF16ToWideHack(url_minus_query))) + if (available_pixel_width >= font.GetStringWidth(url_minus_query)) return ElideText(url_string, font, available_pixel_width, false); // Get Host. @@ -135,17 +136,15 @@ string16 ElideUrl(const GURL& url, } // Second Pass - remove scheme - the rest fits. - int pixel_width_url_host = font.GetStringWidth(UTF16ToWideHack(url_host)); - int pixel_width_url_path = font.GetStringWidth(UTF16ToWideHack( - url_path_query_etc)); + int pixel_width_url_host = font.GetStringWidth(url_host); + int pixel_width_url_path = font.GetStringWidth(url_path_query_etc); if (available_pixel_width >= pixel_width_url_host + pixel_width_url_path) return url_host + url_path_query_etc; // Third Pass: Subdomain, domain and entire path fits. - int pixel_width_url_domain = font.GetStringWidth(UTF16ToWideHack(url_domain)); - int pixel_width_url_subdomain = font.GetStringWidth(UTF16ToWideHack( - url_subdomain)); + int pixel_width_url_domain = font.GetStringWidth(url_domain); + int pixel_width_url_subdomain = font.GetStringWidth(url_subdomain); if (available_pixel_width >= pixel_width_url_subdomain + pixel_width_url_domain + pixel_width_url_path) @@ -153,12 +152,13 @@ string16 ElideUrl(const GURL& url, // Query element. string16 url_query; - const int kPixelWidthDotsTrailer = font.GetStringWidth(kEllipsis); + const int kPixelWidthDotsTrailer = + font.GetStringWidth(UTF8ToUTF16(kEllipsis)); if (parsed.query.is_nonempty()) { url_query = UTF8ToUTF16("?") + url_string.substr(parsed.query.begin); if (available_pixel_width >= (pixel_width_url_subdomain + pixel_width_url_domain + pixel_width_url_path - - font.GetStringWidth(UTF16ToWideHack(url_query)))) { + font.GetStringWidth(url_query))) { return ElideText(url_subdomain + url_domain + url_path_query_etc, font, available_pixel_width, false); } @@ -193,17 +193,14 @@ string16 ElideUrl(const GURL& url, } // Start eliding the path and replacing elements by "../". - static const string16 kEllipsisAndSlash = WideToUTF16(kEllipsis) + - kForwardSlash; - int pixel_width_url_filename = font.GetStringWidth(UTF16ToWideHack( - url_filename)); - int pixel_width_dot_dot_slash = font.GetStringWidth(UTF16ToWideHack( - kEllipsisAndSlash)); - int pixel_width_slash = font.GetStringWidth(L"/"); + const string16 kEllipsisAndSlash = UTF8ToUTF16(kEllipsis) + kForwardSlash; + int pixel_width_url_filename = font.GetStringWidth(url_filename); + int pixel_width_dot_dot_slash = font.GetStringWidth(kEllipsisAndSlash); + int pixel_width_slash = font.GetStringWidth(ASCIIToUTF16("/")); int pixel_width_url_path_elements[kMaxNumberOfUrlPathElementsAllowed]; for (size_t i = 0; i < url_path_number_of_elements; ++i) { pixel_width_url_path_elements[i] = - font.GetStringWidth(UTF16ToWideHack(url_path_elements.at(i))); + font.GetStringWidth(url_path_elements.at(i)); } // Check with both subdomain and domain. @@ -282,14 +279,16 @@ string16 ElideUrl(const GURL& url, // Return elided domain/../filename anyway. string16 final_elided_url_string(url_elided_domain); - int url_elided_domain_width = font.GetStringWidth(UTF16ToWideHack( - url_elided_domain)); + int url_elided_domain_width = font.GetStringWidth(url_elided_domain); + + // A hack to prevent trailing "../...". if ((available_pixel_width - url_elided_domain_width) > pixel_width_dot_dot_slash + kPixelWidthDotsTrailer + - font.GetStringWidth(L"UV")) // A hack to prevent trailing "../...". + font.GetStringWidth(ASCIIToUTF16("UV"))) { final_elided_url_string += elided_path; - else + } else { final_elided_url_string += url_path; + } return ElideText(final_elided_url_string, font, available_pixel_width, false); } @@ -310,7 +309,7 @@ string16 ElideFilename(const FilePath& filename, filename.BaseName().RemoveExtension().value())); #endif - int full_width = font.GetStringWidth(UTF16ToWideHack(filename_utf16)); + int full_width = font.GetStringWidth(filename_utf16); if (full_width <= available_pixel_width) return base::i18n::GetDisplayStringInLTRDirectionality(filename_utf16); @@ -320,8 +319,8 @@ string16 ElideFilename(const FilePath& filename, return base::i18n::GetDisplayStringInLTRDirectionality(elided_name); } - int ext_width = font.GetStringWidth(UTF16ToWideHack(extension)); - int root_width = font.GetStringWidth(UTF16ToWideHack(rootname)); + int ext_width = font.GetStringWidth(extension); + int root_width = font.GetStringWidth(rootname); // We may have trimmed the path. if (root_width + ext_width <= available_pixel_width) { @@ -345,7 +344,7 @@ string16 ElideText(const string16& text, if (text.empty()) return text; - int current_text_pixel_width = font.GetStringWidth(UTF16ToWideHack(text)); + int current_text_pixel_width = font.GetStringWidth(text); // Pango will return 0 width for absurdly long strings. Cut the string in // half and try again. @@ -363,7 +362,7 @@ string16 ElideText(const string16& text, if (current_text_pixel_width <= available_pixel_width) return text; - if (font.GetStringWidth(kEllipsis) > available_pixel_width) + if (font.GetStringWidth(UTF8ToUTF16(kEllipsis)) > available_pixel_width) return string16(); // Use binary search to compute the elided text. @@ -372,8 +371,8 @@ string16 ElideText(const string16& text, for (size_t guess = (lo + hi) / 2; guess != lo; guess = (lo + hi) / 2) { // We check the length of the whole desired string at once to ensure we // handle kerning/ligatures/etc. correctly. - int guess_length = font.GetStringWidth(UTF16ToWideHack( - CutString(text, guess, elide_in_middle, true))); + int guess_length = font.GetStringWidth( + CutString(text, guess, elide_in_middle, true)); // Check again that we didn't hit a Pango width overflow. If so, cut the // current string in half and start over. if (guess_length <= 0) { diff --git a/app/text_elider_unittest.cc b/app/text_elider_unittest.cc index ab1a73f..7d0cbda 100644 --- a/app/text_elider_unittest.cc +++ b/app/text_elider_unittest.cc @@ -44,7 +44,8 @@ void RunTest(Testcase* testcases, size_t num_testcases) { // Should we test with non-empty language list? // That's kinda redundant with net_util_unittests. EXPECT_EQ(WideToUTF16(testcases[i].output), - ElideUrl(url, font, font.GetStringWidth(testcases[i].output), + ElideUrl(url, font, + font.GetStringWidth(WideToUTF16(testcases[i].output)), std::wstring())); } } @@ -183,7 +184,7 @@ TEST(TextEliderTest, TestFilenameEliding) { expected = base::i18n::GetDisplayStringInLTRDirectionality(expected); EXPECT_EQ(expected, ElideFilename(filepath, font, - font.GetStringWidth(testcases[i].output))); + font.GetStringWidth(WideToUTF16(testcases[i].output)))); } } @@ -212,14 +213,13 @@ TEST(TextEliderTest, ElideTextLongStrings) { }; const gfx::Font font; - int ellipsis_width = font.GetStringWidth(UTF16ToWideHack(kEllipsisStr)); + int ellipsis_width = font.GetStringWidth(kEllipsisStr); for (size_t i = 0; i < arraysize(testcases_end); ++i) { // Compare sizes rather than actual contents because if the test fails, // output is rather long. EXPECT_EQ(testcases_end[i].output.size(), ElideText(testcases_end[i].input, font, - font.GetStringWidth(UTF16ToWideHack( - testcases_end[i].output)), + font.GetStringWidth(testcases_end[i].output), false).size()); EXPECT_EQ(kEllipsisStr, ElideText(testcases_end[i].input, font, ellipsis_width, false)); @@ -243,8 +243,7 @@ TEST(TextEliderTest, ElideTextLongStrings) { // output is rather long. EXPECT_EQ(testcases_middle[i].output.size(), ElideText(testcases_middle[i].input, font, - font.GetStringWidth(UTF16ToWideHack( - testcases_middle[i].output)), + font.GetStringWidth(testcases_middle[i].output), false).size()); EXPECT_EQ(kEllipsisStr, ElideText(testcases_middle[i].input, font, ellipsis_width, diff --git a/chrome/browser/gtk/tabs/tab_gtk.cc b/chrome/browser/gtk/tabs/tab_gtk.cc index 440084b..c0f8e82 100644 --- a/chrome/browser/gtk/tabs/tab_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_gtk.cc @@ -21,7 +21,7 @@ namespace { // Returns the width of the title for the current font, in pixels. -int GetTitleWidth(gfx::Font* font, std::wstring title) { +int GetTitleWidth(gfx::Font* font, string16 title) { DCHECK(font); if (title.empty()) return 0; @@ -338,7 +338,7 @@ void TabGtk::ContextMenuClosed() { void TabGtk::UpdateTooltipState() { // Only show the tooltip if the title is truncated. if (title_width_ > title_bounds().width()) { - gtk_widget_set_tooltip_text(widget(), WideToUTF8(GetTitle()).c_str()); + gtk_widget_set_tooltip_text(widget(), UTF16ToUTF8(GetTitle()).c_str()); } else { gtk_widget_set_has_tooltip(widget(), FALSE); } diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc index fc1f7c2..52ab163 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc @@ -562,8 +562,8 @@ void TabRendererGtk::Observe(NotificationType type, //////////////////////////////////////////////////////////////////////////////// // TabRendererGtk, protected: -std::wstring TabRendererGtk::GetTitle() const { - return UTF16ToWideHack(data_.title); +string16 TabRendererGtk::GetTitle() const { + return data_.title; } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.h b/chrome/browser/gtk/tabs/tab_renderer_gtk.h index 6849a2a..8ec952f 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.h +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.h @@ -225,7 +225,7 @@ class TabRendererGtk : public AnimationDelegate, const gfx::Rect& close_button_bounds() const { return close_button_bounds_; } // Returns the title of the Tab. - std::wstring GetTitle() const; + string16 GetTitle() const; // enter-notify-event handler that signals when the mouse enters the tab. CHROMEGTK_CALLBACK_1(TabRendererGtk, gboolean, OnEnterNotifyEvent, diff --git a/chrome/browser/ui/cocoa/status_bubble_mac.mm b/chrome/browser/ui/cocoa/status_bubble_mac.mm index 6231e5d..685096d 100644 --- a/chrome/browser/ui/cocoa/status_bubble_mac.mm +++ b/chrome/browser/ui/cocoa/status_bubble_mac.mm @@ -613,7 +613,7 @@ void StatusBubbleMac::ExpandBubble() { // Scale width from gfx::Font in view coordinates to window coordinates. int required_width_for_string = - font_chr.GetStringWidth(UTF16ToWide(expanded_url)) + + font_chr.GetStringWidth(expanded_url) + kTextPadding * 2 + kBubbleViewTextPositionX; NSSize scaled_width = NSMakeSize(required_width_for_string, 0); scaled_width = [[parent_ contentView] convertSize:scaled_width toView:nil]; diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc index fa3ab68..857db9d 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc @@ -422,7 +422,7 @@ AutocompleteResultView::AutocompleteResultView( model_index_(model_index), normal_font_(font), bold_font_(bold_font), - ellipsis_width_(font.GetStringWidth(kEllipsis)), + ellipsis_width_(font.GetStringWidth(WideToUTF16(kEllipsis))), mirroring_context_(new MirroringContext()), match_(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED) { CHECK(model_index >= 0); @@ -614,7 +614,8 @@ int AutocompleteResultView::DrawString( else current_data->color = GetColor(state, force_dim ? DIMMED_TEXT : TEXT); current_data->pixel_width = - current_data->font->GetStringWidth(current_data->text); + current_data->font->GetStringWidth( + WideToUTF16Hack(current_data->text)); current_run->pixel_width += current_data->pixel_width; } DCHECK(!current_run->classifications.empty()); @@ -740,7 +741,7 @@ void AutocompleteResultView::Elide(Runs* runs, int remaining_width) const { (prior_classification->font == &normal_font_))) j->font = &normal_font_; - j->pixel_width = j->font->GetStringWidth(elided_text); + j->pixel_width = j->font->GetStringWidth(WideToUTF16Hack(elided_text)); // Erase any other classifications that come after the elided one. i->classifications.erase(j.base(), i->classifications.end()); diff --git a/chrome/browser/ui/views/autofill_profiles_view_win.cc b/chrome/browser/ui/views/autofill_profiles_view_win.cc index 2f44c5a..3edac72 100644 --- a/chrome/browser/ui/views/autofill_profiles_view_win.cc +++ b/chrome/browser/ui/views/autofill_profiles_view_win.cc @@ -1152,11 +1152,11 @@ void AutoFillProfilesView::EditableSetViewContents::InitLayoutGrid( // The sizes: 4 characters for drop down icon + 2 for a month or 4 for a year. column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, views::GridLayout::FIXED, - font.GetStringWidth(std::wstring(L"000000")), 0); + font.GetStringWidth(ASCIIToUTF16("000000")), 0); column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, views::GridLayout::FIXED, - font.GetStringWidth(std::wstring(L"00000000")), 0); + font.GetStringWidth(ASCIIToUTF16("00000000")), 0); column_set = layout->AddColumnSet(three_column_header_); column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, diff --git a/chrome/browser/ui/views/download_item_view.cc b/chrome/browser/ui/views/download_item_view.cc index 4c7dc06..27406db 100644 --- a/chrome/browser/ui/views/download_item_view.cc +++ b/chrome/browser/ui/views/download_item_view.cc @@ -612,8 +612,8 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) { font_, kTextWidth); } else { // First, Calculate the download status opening string width. - std::wstring status_string = UTF16ToWide( - l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16())); + string16 status_string = + l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16()); int status_string_width = font_.GetStringWidth(status_string); // Then, elide the file name. string16 filename_string = diff --git a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc index cd151bb..a1bf8ee 100644 --- a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc +++ b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc @@ -104,7 +104,7 @@ void ContentSettingImageView::UpdateFromTabContents(TabContents* tab_contents) { animation_in_progress_ = true; // Initialize animated string. It will be cleared when animation is // completed. - animated_text_ = l10n_util::GetString(animated_string_id); + animated_text_ = l10n_util::GetStringUTF16(animated_string_id); text_size_ = ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::MediumFont).GetStringWidth(animated_text_); text_size_ += 2 * kTextMarginPixels + kIconLeftMargin; @@ -183,7 +183,7 @@ void ContentSettingImageView::Paint(gfx::Canvas* canvas) { if (animation_in_progress_) { // Paint text to the right of the icon. ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - canvas->DrawStringInt(animated_text_, + canvas->DrawStringInt(UTF16ToWideHack(animated_text_), rb.GetFont(ResourceBundle::MediumFont), SK_ColorBLACK, GetImageBounds().right() + kTextMarginPixels, y(), width() - GetImageBounds().width(), height(), diff --git a/chrome/browser/ui/views/location_bar/content_setting_image_view.h b/chrome/browser/ui/views/location_bar/content_setting_image_view.h index 297aadb..fd112da 100644 --- a/chrome/browser/ui/views/location_bar/content_setting_image_view.h +++ b/chrome/browser/ui/views/location_bar/content_setting_image_view.h @@ -8,6 +8,7 @@ #include "app/linear_animation.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "chrome/browser/views/info_bubble.h" #include "chrome/common/content_settings_types.h" #include "views/controls/image_view.h" @@ -67,7 +68,7 @@ class ContentSettingImageView : public views::ImageView, // The currently shown info bubble if any. InfoBubble* info_bubble_; - std::wstring animated_text_; + string16 animated_text_; bool animation_in_progress_; int text_size_; int visible_text_size_; diff --git a/chrome/browser/ui/views/sad_tab_view.cc b/chrome/browser/ui/views/sad_tab_view.cc index 3af2197e..7dbdb71 100644 --- a/chrome/browser/ui/views/sad_tab_view.cc +++ b/chrome/browser/ui/views/sad_tab_view.cc @@ -150,7 +150,7 @@ void SadTabView::InitClass() { sad_tab_bitmap_ = rb.GetBitmapNamed(IDR_SAD_TAB); title_ = l10n_util::GetString(IDS_SAD_TAB_TITLE); - title_width_ = title_font_->GetStringWidth(title_); + title_width_ = title_font_->GetStringWidth(WideToUTF16Hack(title_)); message_ = l10n_util::GetString(IDS_SAD_TAB_MESSAGE); initialized = true; diff --git a/chrome/browser/ui/views/status_bubble_views.cc b/chrome/browser/ui/views/status_bubble_views.cc index 599e726..b4abc31 100644 --- a/chrome/browser/ui/views/status_bubble_views.cc +++ b/chrome/browser/ui/views/status_bubble_views.cc @@ -430,7 +430,7 @@ void StatusBubbleViews::StatusView::Paint(gfx::Canvas* canvas) { // is aligned to the right on RTL UIs, we mirror the text bounds if the // locale is RTL. int text_width = std::min( - views::Label::font().GetStringWidth(UTF16ToWide(text_)), + views::Label::font().GetStringWidth(text_), width - (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding); int text_height = height - (kShadowThickness * 2); gfx::Rect body_bounds(kShadowThickness + kTextPositionX, @@ -805,7 +805,7 @@ void StatusBubbleViews::ExpandBubble() { url_text_ = gfx::ElideUrl(url_, view_->Label::font(), max_status_bubble_width, UTF16ToWideHack(languages_)); int expanded_bubble_width =std::max(GetStandardStatusBubbleWidth(), - std::min(view_->Label::font().GetStringWidth(UTF16ToWide(url_text_)) + + std::min(view_->Label::font().GetStringWidth(url_text_) + (kShadowThickness * 2) + kTextPositionX + kTextHorizPadding + 1, max_status_bubble_width)); diff --git a/chrome/browser/ui/views/tabs/base_tab.cc b/chrome/browser/ui/views/tabs/base_tab.cc index a33bc8f..4598a8b 100644 --- a/chrome/browser/ui/views/tabs/base_tab.cc +++ b/chrome/browser/ui/views/tabs/base_tab.cc @@ -291,10 +291,9 @@ bool BaseTab::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { if (data_.title.empty()) return false; - std::wstring title = UTF16ToWide(data_.title); // Only show the tooltip if the title is truncated. - if (font_->GetStringWidth(title) > title_bounds().width()) { - *tooltip = title; + if (font_->GetStringWidth(data_.title) > title_bounds().width()) { + *tooltip = UTF16ToWide(data_.title); return true; } return false; diff --git a/chrome/browser/ui/views/theme_install_bubble_view.cc b/chrome/browser/ui/views/theme_install_bubble_view.cc index d811774..157e7fd 100644 --- a/chrome/browser/ui/views/theme_install_bubble_view.cc +++ b/chrome/browser/ui/views/theme_install_bubble_view.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_service.h" #include "gfx/canvas_skia.h" @@ -32,7 +33,7 @@ ThemeInstallBubbleView::ThemeInstallBubbleView(TabContents* tab_contents) if (!tab_contents) Close(); - text_ = l10n_util::GetString(IDS_THEME_LOADING_TITLE); + text_ = l10n_util::GetStringUTF16(IDS_THEME_LOADING_TITLE); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); gfx::Font font(rb.GetFont(ResourceBundle::LargeFont)); SetFont(font); @@ -134,8 +135,12 @@ void ThemeInstallBubbleView::Paint(gfx::Canvas* canvas) { body_bounds.set_x(MirroredLeftPointForRect(body_bounds)); SkColor text_color = SK_ColorWHITE; - canvas->DrawStringInt(text_, views::Label::font(), text_color, - body_bounds.x(), body_bounds.y(), body_bounds.width(), + canvas->DrawStringInt(UTF16ToWideHack(text_), + views::Label::font(), + text_color, + body_bounds.x(), + body_bounds.y(), + body_bounds.width(), body_bounds.height()); } diff --git a/chrome/browser/ui/views/theme_install_bubble_view.h b/chrome/browser/ui/views/theme_install_bubble_view.h index ca4c827..4bd070f 100644 --- a/chrome/browser/ui/views/theme_install_bubble_view.h +++ b/chrome/browser/ui/views/theme_install_bubble_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,8 +6,7 @@ #define CHROME_BROWSER_UI_VIEWS_THEME_INSTALL_BUBBLE_VIEW_H_ #pragma once -#include <string> - +#include "base/string16.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "gfx/canvas.h" @@ -66,7 +65,7 @@ class ThemeInstallBubbleView : public NotificationObserver, views::Widget* popup_; // Text to show warning that theme is being installed. - std::wstring text_; + string16 text_; // A scoped container for notification registries. NotificationRegistrar registrar_; diff --git a/chrome/browser/ui/views/wrench_menu.cc b/chrome/browser/ui/views/wrench_menu.cc index 3d86f91..d791005 100644 --- a/chrome/browser/ui/views/wrench_menu.cc +++ b/chrome/browser/ui/views/wrench_menu.cc @@ -525,11 +525,13 @@ class WrenchMenu::ZoomView : public WrenchMenuView, int step = (max_percent - min_percent) / 10; for (int i = min_percent; i <= max_percent; i += step) { - int w = font.GetStringWidth(l10n_util::GetStringF(IDS_ZOOM_PERCENT, i)); + int w = font.GetStringWidth( + l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, i)); max_w = std::max(w, max_w); } } else { - max_w = font.GetStringWidth(l10n_util::GetStringF(IDS_ZOOM_PERCENT, 100)); + max_w = font.GetStringWidth( + l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); } return max_w + insets.width(); diff --git a/gfx/font.cc b/gfx/font.cc index 1c3400b..6897022 100644 --- a/gfx/font.cc +++ b/gfx/font.cc @@ -58,8 +58,8 @@ int Font::GetAverageCharacterWidth() const { return platform_font_->GetAverageCharacterWidth(); } -int Font::GetStringWidth(const std::wstring& text) const { - return platform_font_->GetStringWidth(WideToUTF16Hack(text)); +int Font::GetStringWidth(const string16& text) const { + return platform_font_->GetStringWidth(text); } int Font::GetExpectedTextWidth(int length) const { @@ -9,6 +9,7 @@ #include <string> #include "base/ref_counted.h" +#include "base/string16.h" #include "gfx/native_widget_types.h" namespace gfx { @@ -73,7 +74,7 @@ class Font { // Returns the number of horizontal pixels needed to display the specified // string. - int GetStringWidth(const std::wstring& text) const; + int GetStringWidth(const string16& text) const; // Returns the expected number of horizontal pixels needed to display the // specified length of characters. Call GetStringWidth() to retrieve the diff --git a/gfx/font_unittest.cc b/gfx/font_unittest.cc index 1cf1b11..3f26507 100644 --- a/gfx/font_unittest.cc +++ b/gfx/font_unittest.cc @@ -1,9 +1,10 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "gfx/font.h" +#include "base/utf_string_conversions.h" #if defined(OS_WIN) #include "gfx/platform_font_win.h" #endif // defined(OS_WIN) @@ -82,10 +83,13 @@ TEST_F(FontTest, AvgWidths) { TEST_F(FontTest, Widths) { Font cf(L"Arial", 16); - ASSERT_EQ(cf.GetStringWidth(L""), 0); - ASSERT_GT(cf.GetStringWidth(L"a"), cf.GetStringWidth(L"")); - ASSERT_GT(cf.GetStringWidth(L"ab"), cf.GetStringWidth(L"a")); - ASSERT_GT(cf.GetStringWidth(L"abc"), cf.GetStringWidth(L"ab")); + ASSERT_EQ(cf.GetStringWidth(ASCIIToUTF16("")), 0); + ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), + cf.GetStringWidth(ASCIIToUTF16(""))); + ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), + cf.GetStringWidth(ASCIIToUTF16("a"))); + ASSERT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), + cf.GetStringWidth(ASCIIToUTF16("ab"))); } #if defined(OS_WIN) diff --git a/printing/printed_document.cc b/printing/printed_document.cc index 2369618..5993b3d 100644 --- a/printing/printed_document.cc +++ b/printing/printed_document.cc @@ -184,7 +184,8 @@ void PrintedDocument::PrintHeaderFooter(gfx::NativeDrawingContext context, // May happen if document name or url is empty. return; } - const gfx::Size string_size(font.GetStringWidth(output), font.GetHeight()); + const gfx::Size string_size(font.GetStringWidth(WideToUTF16Hack(output)), + font.GetHeight()); gfx::Rect bounding; bounding.set_height(string_size.height()); const gfx::Rect& overlay_area( diff --git a/views/controls/label.cc b/views/controls/label.cc index b228c78b..cdf2c8a 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -186,7 +186,8 @@ bool Label::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { // Show the full text if the text does not fit. if (!is_multi_line_ && - (font_.GetStringWidth(text_) > GetAvailableRect().width())) { + (font_.GetStringWidth(WideToUTF16Hack(text_)) > + GetAvailableRect().width())) { *tooltip = text_; return true; } @@ -237,8 +238,10 @@ void Label::SizeToFit(int max_width) { int label_width = 0; for (std::vector<std::wstring>::const_iterator iter = lines.begin(); - iter != lines.end(); ++iter) - label_width = std::max(label_width, font_.GetStringWidth(*iter)); + iter != lines.end(); ++iter) { + label_width = std::max(label_width, + font_.GetStringWidth(WideToUTF16Hack(*iter))); + } label_width += GetInsets().width(); diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index 17e8ef8..985ecb7 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -429,7 +429,7 @@ void MenuItemView::Layout() { } int MenuItemView::GetAcceleratorTextWidth() { - std::wstring text = GetAcceleratorText(); + string16 text = WideToUTF16Hack(GetAcceleratorText()); return text.empty() ? 0 : MenuConfig::instance().font.GetStringWidth(text); } diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc index 73599e2..87fcdca 100644 --- a/views/controls/menu/menu_item_view_gtk.cc +++ b/views/controls/menu/menu_item_view_gtk.cc @@ -5,6 +5,7 @@ #include "views/controls/menu/menu_item_view.h" #include "app/resource_bundle.h" +#include "base/utf_string_conversions.h" #include "gfx/canvas_skia.h" #include "gfx/favicon_size.h" #include "grit/app_resources.h" @@ -30,8 +31,8 @@ gfx::Size MenuItemView::GetPreferredSize() { // kFavIconSize if we're showing icons. int content_height = std::max(kFavIconSize, font.GetHeight()); return gfx::Size( - font.GetStringWidth(title_) + label_start_ + item_right_margin_ + - GetChildPreferredWidth(), + font.GetStringWidth(WideToUTF16Hack(title_)) + label_start_ + + item_right_margin_ + GetChildPreferredWidth(), content_height + GetBottomMargin() + GetTopMargin()); } diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc index baef032..5ea8b23 100644 --- a/views/controls/textfield/native_textfield_views.cc +++ b/views/controls/textfield/native_textfield_views.cc @@ -328,7 +328,7 @@ void NativeTextfieldViews::UpdateCursorBoundsAndTextOffset() { // TODO(oshima): bidi const gfx::Font& font = GetFont(); - int full_width = font.GetStringWidth(UTF16ToWide(model_->GetVisibleText())); + int full_width = font.GetStringWidth(model_->GetVisibleText()); cursor_bounds_ = model_->GetCursorBounds(font); cursor_bounds_.set_y(cursor_bounds_.y() + insets.top()); @@ -381,7 +381,7 @@ void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { string16 text = model_->GetVisibleText((*iter).begin, (*iter).end); // TODO(oshima): This does not give the accurate position due to // kerning. Figure out how webkit does this with skia. - int width = GetFont().GetStringWidth(UTF16ToWide(text)); + int width = GetFont().GetStringWidth(text); if ((*iter).selected) { canvas->FillRectInt(selection_color, x_offset, y, width, text_height); @@ -601,7 +601,7 @@ size_t NativeTextfieldViews::FindCursorPosition(const gfx::Point& point) const { // TODO(oshima): BIDI/i18n support. gfx::Font font = GetFont(); gfx::Insets insets = GetInsets(); - std::wstring text = UTF16ToWide(model_->GetVisibleText()); + string16 text = model_->GetVisibleText(); int left = 0; int left_pos = 0; int right = font.GetStringWidth(text); diff --git a/views/controls/textfield/textfield_views_model.cc b/views/controls/textfield/textfield_views_model.cc index 21783ec..0b88c8a 100644 --- a/views/controls/textfield/textfield_views_model.cc +++ b/views/controls/textfield/textfield_views_model.cc @@ -196,14 +196,13 @@ bool TextfieldViewsModel::MoveCursorTo(size_t pos, bool select) { gfx::Rect TextfieldViewsModel::GetCursorBounds(const gfx::Font& font) const { string16 text = GetVisibleText(); - int x = font.GetStringWidth(UTF16ToWide(text.substr(0U, cursor_pos_))); + int x = font.GetStringWidth(text.substr(0U, cursor_pos_)); int h = font.GetHeight(); DCHECK(x >= 0); if (text.length() == cursor_pos_) { return gfx::Rect(x, 0, 0, h); } else { - int x_end = - font.GetStringWidth(UTF16ToWide(text.substr(0U, cursor_pos_ + 1U))); + int x_end = font.GetStringWidth(text.substr(0U, cursor_pos_ + 1U)); return gfx::Rect(x, 0, x_end - x, h); } } diff --git a/views/view_text_utils.cc b/views/view_text_utils.cc index df42544..8f13617 100644 --- a/views/view_text_utils.cc +++ b/views/view_text_utils.cc @@ -116,7 +116,7 @@ void DrawTextStartingFrom(gfx::Canvas* canvas, else word = text; // Draw the whole text at once. - int w = font.GetStringWidth(word), h = font.GetHeight(); + int w = font.GetStringWidth(WideToUTF16Hack(word)), h = font.GetHeight(); gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(word), font, &w, &h, flags); // If we exceed the boundaries, we need to wrap. @@ -130,8 +130,9 @@ void DrawTextStartingFrom(gfx::Canvas* canvas, // draw the trailing space (if one exists after the LTR text) to the // left of the LTR string. if (ltr_within_rtl && word[word.size() - 1] == L' ') { - int space_w = font.GetStringWidth(L" "), space_h = font.GetHeight(); - gfx::CanvasSkia::SizeStringInt(UTF8ToUTF16(" "), font, &space_w, + int space_w = font.GetStringWidth(ASCIIToUTF16(" ")); + int space_h = font.GetHeight(); + gfx::CanvasSkia::SizeStringInt(ASCIIToUTF16(" "), font, &space_w, &space_h, flags); x += space_w; } diff --git a/views/widget/tooltip_manager.cc b/views/widget/tooltip_manager.cc index 5c400eb9..d71a566 100644 --- a/views/widget/tooltip_manager.cc +++ b/views/widget/tooltip_manager.cc @@ -58,16 +58,16 @@ void TooltipManager::TrimTooltipToFit(std::wstring* text, std::wstring result; for (std::vector<std::wstring>::iterator i = lines.begin(); i != lines.end(); ++i) { - std::wstring elided_text = UTF16ToWideHack(gfx::ElideText(WideToUTF16Hack( - *i), font, available_width, false)); + string16 elided_text = gfx::ElideText(WideToUTF16Hack(*i), + font, available_width, false); *max_width = std::max(*max_width, font.GetStringWidth(elided_text)); if (i == lines.begin() && i + 1 == lines.end()) { - *text = elided_text; + *text = UTF16ToWideHack(elided_text); return; } if (!result.empty()) result.append(GetLineSeparator()); - result.append(elided_text); + result.append(UTF16ToWideHack(elided_text)); } *text = result; } diff --git a/views/window/dialog_client_view.cc b/views/window/dialog_client_view.cc index 8ce2224..ad89187 100644 --- a/views/window/dialog_client_view.cc +++ b/views/window/dialog_client_view.cc @@ -447,7 +447,8 @@ int DialogClientView::GetButtonWidth(int button) const { DialogDelegate* dd = GetDialogDelegate(); std::wstring button_label = dd->GetDialogButtonLabel( static_cast<MessageBoxFlags::DialogButton>(button)); - int string_width = dialog_button_font_->GetStringWidth(button_label); + int string_width = dialog_button_font_->GetStringWidth( + WideToUTF16Hack(button_label)); return std::max(string_width + kDialogButtonLabelSpacing, kDialogMinButtonWidth); } |