Skip to content

Commit

Permalink
Convert GetDisplayStringInLTRDirectionality from wstring to string16.
Browse files Browse the repository at this point in the history
BUG=23581

Review URL: http://codereview.chromium.org/3108027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56535 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tony@chromium.org committed Aug 18, 2010
1 parent 05672ca commit 70edb86
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 52 deletions.
14 changes: 10 additions & 4 deletions app/text_elider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ std::wstring CutString(const std::wstring& text,
text.substr(text.length() - half_length, half_length);
}

// TODO(tony): Get rid of wstrings.
std::wstring GetDisplayStringInLTRDirectionality(const std::wstring& text) {
return UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
WideToUTF16(text)));
}

} // namespace

namespace gfx {
Expand Down Expand Up @@ -285,7 +291,7 @@ std::wstring ElideFilename(const FilePath& filename,
int full_width = font.GetStringWidth(filename.ToWStringHack());
if (full_width <= available_pixel_width) {
std::wstring elided_name = filename.ToWStringHack();
return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name);
return GetDisplayStringInLTRDirectionality(elided_name);
}

#if defined(OS_WIN)
Expand All @@ -299,7 +305,7 @@ std::wstring ElideFilename(const FilePath& filename,
if (rootname.empty() || extension.empty()) {
std::wstring elided_name = ElideText(filename.ToWStringHack(), font,
available_pixel_width, false);
return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name);
return GetDisplayStringInLTRDirectionality(elided_name);
}

int ext_width = font.GetStringWidth(extension);
Expand All @@ -308,14 +314,14 @@ std::wstring ElideFilename(const FilePath& filename,
// We may have trimmed the path.
if (root_width + ext_width <= available_pixel_width) {
std::wstring elided_name = rootname + extension;
return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name);
return GetDisplayStringInLTRDirectionality(elided_name);
}

int available_root_width = available_pixel_width - ext_width;
std::wstring elided_name =
ElideText(rootname, font, available_root_width, false);
elided_name += extension;
return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name);
return GetDisplayStringInLTRDirectionality(elided_name);
}

// This function adds an ellipsis at the end of the text if the text
Expand Down
9 changes: 5 additions & 4 deletions app/text_elider_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/i18n/rtl.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "gfx/font.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -178,11 +179,11 @@ TEST(TextEliderTest, TestFilenameEliding) {
static const gfx::Font font;
for (size_t i = 0; i < arraysize(testcases); ++i) {
FilePath filepath(testcases[i].input);
std::wstring expected = testcases[i].output;
base::i18n::GetDisplayStringInLTRDirectionality(&expected);
EXPECT_EQ(expected, ElideFilename(filepath,
string16 expected = WideToUTF16(testcases[i].output);
expected = base::i18n::GetDisplayStringInLTRDirectionality(expected);
EXPECT_EQ(expected, WideToUTF16(ElideFilename(filepath,
font,
font.GetStringWidth(testcases[i].output)));
font.GetStringWidth(testcases[i].output))));
}
}

Expand Down
10 changes: 6 additions & 4 deletions base/i18n/rtl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,12 @@ void WrapPathWithLTRFormatting(const FilePath& path,
rtl_safe_path->push_back(kPopDirectionalFormatting);
}

std::wstring GetDisplayStringInLTRDirectionality(std::wstring* text) {
if (IsRTL())
WrapStringWithLTRFormatting(text);
return *text;
string16 GetDisplayStringInLTRDirectionality(const string16& text) {
if (!IsRTL())
return text;
string16 text_mutable(text);
WrapStringWithLTRFormatting(&text_mutable);
return text_mutable;
}

const string16 StripWrappingBidiControlCharacters(const string16& text) {
Expand Down
7 changes: 5 additions & 2 deletions base/i18n/rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BASE_I18N_RTL_H_
#pragma once

#include "base/compiler_specific.h"
#include "base/string16.h"
#include "build/build_config.h"

Expand Down Expand Up @@ -135,14 +136,16 @@ void WrapPathWithLTRFormatting(const FilePath& path,
// string is wrapped with LRE (Left-To-Right Embedding) and PDF (Pop
// Directional Formatting) marks and returned. In LTR locale, the string itself
// is returned.
std::wstring GetDisplayStringInLTRDirectionality(std::wstring* text);
string16 GetDisplayStringInLTRDirectionality(const string16& text)
WARN_UNUSED_RESULT;

// Strip the beginning (U+202A..U+202B, U+202D..U+202E) and/or ending (U+202C)
// explicit bidi control characters from |text|, if there are any. Otherwise,
// return the text itself. Explicit bidi control characters display and have
// semantic effect. They can be deleted so they might not always appear in a
// pair.
const string16 StripWrappingBidiControlCharacters(const string16& text);
const string16 StripWrappingBidiControlCharacters(const string16& text)
WARN_UNUSED_RESULT;

} // namespace i18n
} // namespace base
Expand Down
9 changes: 4 additions & 5 deletions base/i18n/rtl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,12 @@ TEST_F(RTLTest, GetDisplayStringInLTRDirectionality) {
{ L"abc\x05d0\x05d1.jpg", L"\x202a"L"abc\x05d0\x05d1.jpg\x202c" },
};
for (unsigned int i = 0; i < arraysize(test_data); ++i) {
std::wstring input = test_data[i].raw_filename;
std::wstring expected =
base::i18n::GetDisplayStringInLTRDirectionality(&input);
string16 input = WideToUTF16(test_data[i].raw_filename);
string16 expected = base::i18n::GetDisplayStringInLTRDirectionality(input);
if (base::i18n::IsRTL())
EXPECT_EQ(test_data[i].display_string, expected);
EXPECT_EQ(expected, WideToUTF16(test_data[i].display_string));
else
EXPECT_EQ(input, expected);
EXPECT_EQ(expected, input);
}
}

Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/custom_home_pages_table_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ CustomHomePagesTableModel::Entry*
std::wstring CustomHomePagesTableModel::FormattedURL(int row) const {
std::wstring languages =
UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
std::wstring url(net::FormatUrl(entries_[row].url, languages));
base::i18n::GetDisplayStringInLTRDirectionality(&url);
return url;
string16 url = WideToUTF16(net::FormatUrl(entries_[row].url, languages));
url = base::i18n::GetDisplayStringInLTRDirectionality(url);
return UTF16ToWide(url);
}
9 changes: 5 additions & 4 deletions chrome/browser/download/download_item_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ std::wstring DownloadItemModel::GetStatusText() {
// as "MB 123/456" because it ends with an LTR run. In order to solve this,
// we mark the total string as an LTR string if the UI layout is
// right-to-left so that the string "456 MB" is treated as an LTR run.
std::wstring simple_total = FormatBytes(total, amount_units, true);
base::i18n::GetDisplayStringInLTRDirectionality(&simple_total);
string16 simple_total = WideToUTF16Hack(FormatBytes(total, amount_units,
true));
simple_total = base::i18n::GetDisplayStringInLTRDirectionality(simple_total);

TimeDelta remaining;
string16 simple_time;
Expand Down Expand Up @@ -74,8 +75,8 @@ std::wstring DownloadItemModel::GetStatusText() {
true));
} else {
status_text = l10n_util::GetStringFUTF16(
IDS_DOWNLOAD_STATUS_IN_PROGRESS, simple_size,
WideToUTF16Hack(simple_total), simple_time);
IDS_DOWNLOAD_STATUS_IN_PROGRESS, simple_size, simple_total,
simple_time);
}
}
break;
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/download/download_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,10 @@ DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id) {
file_value->SetString("file_path",
WideToUTF16Hack(download->full_path().ToWStringHack()));
// Keep file names as LTR.
std::wstring file_name = download->GetFileName().ToWStringHack();
base::i18n::GetDisplayStringInLTRDirectionality(&file_name);
file_value->SetString("file_name", WideToUTF16Hack(file_name));
string16 file_name = WideToUTF16Hack(
download->GetFileName().ToWStringHack());
file_name = base::i18n::GetDisplayStringInLTRDirectionality(file_name);
file_value->SetString("file_name", file_name);
file_value->SetString("url", download->url().spec());
file_value->SetBoolean("otr", download->is_otr());

Expand Down
6 changes: 2 additions & 4 deletions chrome/browser/possible_url_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ std::wstring PossibleURLModel::GetText(int row, int col_id) {

// TODO(brettw): this should probably pass the GURL up so the URL elider
// can be used at a higher level when we know the width.
// Force URL to be LTR.
std::wstring url(UTF16ToWideHack(results_[row].display_url.display_url()));
base::i18n::GetDisplayStringInLTRDirectionality(&url);
return url;
string16 url = results_[row].display_url.display_url();
return UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(url));
}

SkBitmap PossibleURLModel::GetIcon(int row) {
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/renderer_host/render_view_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,9 @@ void RenderViewHost::OnMsgSetTooltipText(
if (!tooltip_text.empty()) {
if (text_direction_hint == WebKit::WebTextDirectionLeftToRight) {
// Force the tooltip to have LTR directionality.
base::i18n::GetDisplayStringInLTRDirectionality(&wrapped_tooltip_text);
wrapped_tooltip_text = UTF16ToWide(
base::i18n::GetDisplayStringInLTRDirectionality(
WideToUTF16(wrapped_tooltip_text)));
} else if (text_direction_hint == WebKit::WebTextDirectionRightToLeft &&
!base::i18n::IsRTL()) {
// Force the tooltip to have RTL directionality.
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/search_engines/template_url_table_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ std::wstring TemplateURLTableModel::GetText(int row, int col_id) {

case IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN: {
// Keyword should be domain name. Force it to have LTR directionality.
std::wstring keyword(url.keyword());
base::i18n::GetDisplayStringInLTRDirectionality(&keyword);
return keyword;
string16 keyword = WideToUTF16(url.keyword());
keyword = base::i18n::GetDisplayStringInLTRDirectionality(keyword);
return UTF16ToWide(keyword);
}

default:
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/tab_contents/tab_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3162,14 +3162,14 @@ std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,

// TODO(brettw) it should be easier than this to do the correct language
// handling without getting the accept language from the profile.
std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0,
UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)));
string16 base_address = WideToUTF16(gfx::ElideUrl(clean_url, gfx::Font(), 0,
UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages))));
// Force URL to have LTR directionality.
base::i18n::GetDisplayStringInLTRDirectionality(&base_address);
base_address = base::i18n::GetDisplayStringInLTRDirectionality(base_address);

return l10n_util::GetStringF(
return UTF16ToWide(l10n_util::GetStringFUTF16(
is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
base_address);
base_address));
}

gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/task_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ string16 TaskManagerModel::GetResourceNetworkUsage(int index) const {
return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT);
if (net_usage == 0)
return ASCIIToUTF16("0");
std::wstring net_byte =
FormatSpeed(net_usage, GetByteDisplayUnits(net_usage), true);
string16 net_byte = WideToUTF16(
FormatSpeed(net_usage, GetByteDisplayUnits(net_usage), true));
// Force number string to have LTR directionality.
base::i18n::GetDisplayStringInLTRDirectionality(&net_byte);
return WideToUTF16Hack(net_byte);
return base::i18n::GetDisplayStringInLTRDirectionality(net_byte);
}

string16 TaskManagerModel::GetResourceCPUUsage(int index) const {
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/task_manager_resource_providers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ std::wstring TaskManagerTabContentsResource::GetTitle() const {
if (tab_title.empty()) {
tab_title = UTF8ToWide(tab_contents_->GetURL().spec());
// Force URL to be LTR.
base::i18n::GetDisplayStringInLTRDirectionality(&tab_title);
tab_title = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
WideToUTF16(tab_title)));
} else {
// Since the tab_title will be concatenated with
// IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/views/bookmark_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ static std::wstring CreateToolTipForURLAndTitle(const gfx::Point& screen_loc,
// the Unicode BiDi algorithm puts certain characters on the left by
// default.
std::wstring elided_url(gfx::ElideUrl(url, tt_font, max_width, languages));
base::i18n::GetDisplayStringInLTRDirectionality(&elided_url);
elided_url = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
WideToUTF16(elided_url)));
result.append(elided_url);
}
return result;
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/views/download_item_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "base/i18n/rtl.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_theme_provider.h"
#include "chrome/browser/download/download_item_model.h"
Expand Down Expand Up @@ -285,7 +286,8 @@ DownloadItemView::DownloadItemView(DownloadItem* download,
} else {
ElideString(rootname, kFileNameMaxLength - extension.length(), &rootname);
std::wstring filename = rootname + L"." + extension;
base::i18n::GetDisplayStringInLTRDirectionality(&filename);
filename = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
WideToUTF16(filename)));
dangerous_download_label_ = new views::Label(
l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, filename));
}
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/views/options/passwords_page_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ std::wstring PasswordsTableModel::GetText(int row,
case IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN: { // Site.
// Force URL to have LTR directionality.
std::wstring url(saved_signons_[row]->display_url.display_url());
base::i18n::GetDisplayStringInLTRDirectionality(&url);
url = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
WideToUTF16(url)));
return url;
}
case IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN: { // Username.
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/views/status_bubble_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/i18n/rtl.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_theme_provider.h"
#include "gfx/canvas_skia.h"
#include "gfx/point.h"
Expand Down Expand Up @@ -661,7 +662,8 @@ void StatusBubbleViews::SetURL(const GURL& url, const std::wstring& languages) {
// An URL is always treated as a left-to-right string. On right-to-left UIs
// we need to explicitly mark the URL as LTR to make sure it is displayed
// correctly.
base::i18n::GetDisplayStringInLTRDirectionality(&url_text_);
url_text_ = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
WideToUTF16(url_text_)));

if (IsFrameVisible()) {
view_->SetText(url_text_, true);
Expand Down
3 changes: 2 additions & 1 deletion views/controls/label.cc
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ void Label::CalculateDrawStringParams(std::wstring* paint_text,
// characters. We use the locale settings because an URL is always treated
// as an LTR string, even if its containing view does not use an RTL UI
// layout.
base::i18n::GetDisplayStringInLTRDirectionality(paint_text);
*paint_text = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
WideToUTF16(*paint_text)));
} else if (elide_in_middle_) {
*paint_text = gfx::ElideText(text_, font_, width(), true);
} else {
Expand Down

0 comments on commit 70edb86

Please sign in to comment.