diff options
101 files changed, 915 insertions, 812 deletions
diff --git a/app/gfx/canvas.cc b/app/gfx/canvas.cc index 75f8011..75ec0a1 100644 --- a/app/gfx/canvas.cc +++ b/app/gfx/canvas.cc @@ -8,6 +8,7 @@ #include "app/gfx/font.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "gfx/rect.h" #include "third_party/skia/include/core/SkShader.h" @@ -218,7 +219,7 @@ void Canvas::DrawStringInt(const std::wstring& text, const SkColor& color, int x, int y, int w, int h) { DrawStringInt(text, font, color, x, y, w, h, - l10n_util::DefaultCanvasTextAlignment()); + gfx::Canvas::DefaultCanvasTextAlignment()); } void Canvas::DrawStringInt(const std::wstring& text, @@ -267,4 +268,11 @@ SkBitmap Canvas::ExtractBitmap() const { return result; } +// static +int Canvas::DefaultCanvasTextAlignment() { + if (!base::i18n::IsRTL()) + return gfx::Canvas::TEXT_ALIGN_LEFT; + return gfx::Canvas::TEXT_ALIGN_RIGHT; +} + } // namespace gfx diff --git a/app/gfx/canvas.h b/app/gfx/canvas.h index 79eed9c..ea4fbf3 100644 --- a/app/gfx/canvas.h +++ b/app/gfx/canvas.h @@ -211,6 +211,15 @@ class Canvas : public skia::PlatformCanvas { static void SizeStringInt(const std::wstring& test, const gfx::Font& font, int *width, int* height, int flags); + // Returns the default text alignment to be used when drawing text on a + // gfx::Canvas based on the directionality of the system locale language. This + // function is used by gfx::Canvas::DrawStringInt when the text alignment is + // not specified. + // + // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or + // gfx::Canvas::TEXT_ALIGN_RIGHT. + static int DefaultCanvasTextAlignment(); + private: #if defined(OS_WIN) // Draws text with the specified color, font and location. The text is diff --git a/app/gfx/canvas_win.cc b/app/gfx/canvas_win.cc index de9d45a..abe722c 100644 --- a/app/gfx/canvas_win.cc +++ b/app/gfx/canvas_win.cc @@ -7,7 +7,7 @@ #include <limits> #include "app/gfx/font.h" -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "gfx/rect.h" #include "third_party/skia/include/core/SkShader.h" @@ -24,7 +24,7 @@ void DoDrawText(HDC hdc, const std::wstring& text, // 1. The current locale is RTL. // 2. The string itself has RTL directionality. if (flags & DT_RTLREADING) { - if (l10n_util::AdjustStringForLocaleDirection(text, &localized_text)) { + if (base::i18n::AdjustStringForLocaleDirection(text, &localized_text)) { string_ptr = localized_text.c_str(); string_size = static_cast<int>(localized_text.length()); } @@ -42,7 +42,7 @@ int ComputeFormatFlags(int flags, const std::wstring& text) { if (!(flags & (gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT))) { - flags |= l10n_util::DefaultCanvasTextAlignment(); + flags |= gfx::Canvas::DefaultCanvasTextAlignment(); } // horizontal alignment @@ -113,8 +113,8 @@ int ComputeFormatFlags(int flags, const std::wstring& text) { // using RTL directionality then we respect that and pass DT_RTLREADING to // ::DrawText even if the locale is LTR. if ((flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY) || - ((l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) && - (f & DT_RIGHT) && l10n_util::StringContainsStrongRTLChars(text))) { + (base::i18n::IsRTL() && + (f & DT_RIGHT) && base::i18n::StringContainsStrongRTLChars(text))) { f |= DT_RTLREADING; } diff --git a/app/l10n_util.cc b/app/l10n_util.cc index 503f708..d51dc89 100644 --- a/app/l10n_util.cc +++ b/app/l10n_util.cc @@ -14,6 +14,7 @@ #include "base/command_line.h" #include "base/file_util.h" #include "base/i18n/file_util_icu.h" +#include "base/i18n/rtl.h" #include "base/path_service.h" #include "base/scoped_ptr.h" #include "base/string16.h" @@ -21,15 +22,7 @@ #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "build/build_config.h" -#include "unicode/coll.h" -#include "unicode/locid.h" #include "unicode/rbbi.h" -#include "unicode/uchar.h" -#include "unicode/uscript.h" - -#if defined(TOOLKIT_GTK) -#include <gtk/gtk.h> -#endif #if defined(OS_MACOSX) #include "app/l10n_util_mac.h" @@ -188,71 +181,6 @@ static const char* const kAcceptLanguageList[] = { "zu", // Zulu }; - -// Get language and region from the OS. -void GetLanguageAndRegionFromOS(std::string* lang, std::string* region) { - // Later we may have to change this to be OS-dependent so that - // it's not affected by ICU's default locale. It's all right - // to do this way because SetICUDefaultLocale is internal - // to this file and we know that it's not yet called when this function - // is called. - icu::Locale locale = icu::Locale::getDefault(); - const char* language = locale.getLanguage(); - const char* country = locale.getCountry(); - DCHECK(language); - *lang = language; - *region = country; -} - -// Convert Chrome locale name to ICU locale name -std::string ICULocaleName(const std::string& locale_string) { - // If not Spanish, just return it. - if (locale_string.substr(0, 2) != "es") - return locale_string; - // Expand es to es-ES. - if (LowerCaseEqualsASCII(locale_string, "es")) - return "es-ES"; - // Map es-419 (Latin American Spanish) to es-FOO depending on the system - // locale. If it's es-RR other than es-ES, map to es-RR. Otherwise, map - // to es-MX (the most populous in Spanish-speaking Latin America). - if (LowerCaseEqualsASCII(locale_string, "es-419")) { - std::string lang, region; - GetLanguageAndRegionFromOS(&lang, ®ion); - if (LowerCaseEqualsASCII(lang, "es") && - !LowerCaseEqualsASCII(region, "es")) { - lang.append("-"); - lang.append(region); - return lang; - } - return "es-MX"; - } - // Currently, Chrome has only "es" and "es-419", but later we may have - // more specific "es-RR". - return locale_string; -} - -// Represents the locale-specific ICU text direction. -l10n_util::TextDirection g_icu_text_direction = l10n_util::UNKNOWN_DIRECTION; - -// Sets the default locale of ICU. -// Once the application locale of Chrome in GetApplicationLocale is determined, -// the default locale of ICU need to be changed to match the application locale -// so that ICU functions work correctly in a locale-dependent manner. -// This is handy in that we don't have to call GetApplicationLocale() -// everytime we call locale-dependent ICU APIs as long as we make sure -// that this is called before any locale-dependent API is called. -void SetICUDefaultLocale(const std::string& locale_string) { - icu::Locale locale(ICULocaleName(locale_string).c_str()); - UErrorCode error_code = U_ZERO_ERROR; - icu::Locale::setDefault(locale, error_code); - // This return value is actually bogus because Locale object is - // an ID and setDefault seems to always succeed (regardless of the - // presence of actual locale data). However, - // it does not hurt to have it as a sanity check. - DCHECK(U_SUCCESS(error_code)); - g_icu_text_direction = l10n_util::UNKNOWN_DIRECTION; -} - // Returns true if |locale_name| has an alias in the ICU data file. bool IsDuplicateName(const std::string& locale_name) { static const char* const kDuplicateNames[] = { @@ -386,7 +314,7 @@ bool CheckAndResolveLocale(const std::string& locale, // ISO-639. std::string GetSystemLocale() { std::string language, region; - GetLanguageAndRegionFromOS(&language, ®ion); + base::i18n::GetLanguageAndRegionFromOS(&language, ®ion); std::string ret; if (!language.empty()) ret.append(language); @@ -490,7 +418,7 @@ std::string GetApplicationLocale(const std::wstring& pref_locale) { std::vector<std::string>::const_iterator i = candidates.begin(); for (; i != candidates.end(); ++i) { if (CheckAndResolveLocale(*i, locale_path, &resolved_locale)) { - SetICUDefaultLocale(resolved_locale); + base::i18n::SetICUDefaultLocale(resolved_locale); return resolved_locale; } } @@ -498,7 +426,7 @@ std::string GetApplicationLocale(const std::wstring& pref_locale) { // Fallback on en-US. const std::string fallback_locale("en-US"); if (IsLocaleAvailable(fallback_locale, locale_path)) { - SetICUDefaultLocale(fallback_locale); + base::i18n::SetICUDefaultLocale(fallback_locale); return fallback_locale; } @@ -527,7 +455,7 @@ std::string GetApplicationLocale(const std::wstring& pref_locale) { // Mac doesn't use a locale directory tree of resources (it uses Mac style // resources), so mirror the Windows/Linux behavior of calling // SetICUDefaultLocale. - SetICUDefaultLocale(app_locale); + base::i18n::SetICUDefaultLocale(app_locale); return app_locale; #endif // !defined(OS_MACOSX) } @@ -567,9 +495,8 @@ string16 GetDisplayNameForLocale(const std::string& locale, DCHECK(U_SUCCESS(error)); display_name.resize(actual_size); // Add an RTL mark so parentheses are properly placed. - if (is_for_ui && GetTextDirection() == RIGHT_TO_LEFT) { - display_name.push_back(static_cast<char16>(kRightToLeftMark)); - } + if (is_for_ui && base::i18n::IsRTL()) + display_name.push_back(static_cast<char16>(base::i18n::kRightToLeftMark)); return display_name; } @@ -817,157 +744,6 @@ string16 ToUpper(const string16& string) { return result; } -TextDirection GetICUTextDirection() { - if (g_icu_text_direction == UNKNOWN_DIRECTION) { - const icu::Locale& locale = icu::Locale::getDefault(); - g_icu_text_direction = GetTextDirectionForLocale(locale.getName()); - } - return g_icu_text_direction; -} - -TextDirection GetTextDirection() { -#if defined(TOOLKIT_GTK) - GtkTextDirection gtk_dir = gtk_widget_get_default_direction(); - return (gtk_dir == GTK_TEXT_DIR_LTR) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT; -#else - return GetICUTextDirection(); -#endif -} - -TextDirection GetTextDirectionForLocale(const char* locale_name) { - UErrorCode status = U_ZERO_ERROR; - ULayoutType layout_dir = uloc_getCharacterOrientation(locale_name, &status); - DCHECK(U_SUCCESS(status)); - // Treat anything other than RTL as LTR. - return (layout_dir != ULOC_LAYOUT_RTL) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT; -} - -TextDirection GetFirstStrongCharacterDirection(const std::wstring& text) { -#if defined(WCHAR_T_IS_UTF32) - string16 text_utf16 = WideToUTF16(text); - const UChar* string = text_utf16.c_str(); -#else - const UChar* string = text.c_str(); -#endif - size_t length = text.length(); - size_t position = 0; - while (position < length) { - UChar32 character; - size_t next_position = position; - U16_NEXT(string, next_position, length, character); - - // Now that we have the character, we use ICU in order to query for the - // appropriate Unicode BiDi character type. - int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); - if ((property == U_RIGHT_TO_LEFT) || - (property == U_RIGHT_TO_LEFT_ARABIC) || - (property == U_RIGHT_TO_LEFT_EMBEDDING) || - (property == U_RIGHT_TO_LEFT_OVERRIDE)) { - return RIGHT_TO_LEFT; - } else if ((property == U_LEFT_TO_RIGHT) || - (property == U_LEFT_TO_RIGHT_EMBEDDING) || - (property == U_LEFT_TO_RIGHT_OVERRIDE)) { - return LEFT_TO_RIGHT; - } - - position = next_position; - } - - return LEFT_TO_RIGHT; -} - -bool AdjustStringForLocaleDirection(const std::wstring& text, - std::wstring* localized_text) { - if (GetTextDirection() == LEFT_TO_RIGHT || text.length() == 0) - return false; - - // Marking the string as LTR if the locale is RTL and the string does not - // contain strong RTL characters. Otherwise, mark the string as RTL. - *localized_text = text; - bool has_rtl_chars = StringContainsStrongRTLChars(text); - if (!has_rtl_chars) - WrapStringWithLTRFormatting(localized_text); - else - WrapStringWithRTLFormatting(localized_text); - - return true; -} - -bool StringContainsStrongRTLChars(const std::wstring& text) { -#if defined(WCHAR_T_IS_UTF32) - string16 text_utf16 = WideToUTF16(text); - const UChar* string = text_utf16.c_str(); -#else - const UChar* string = text.c_str(); -#endif - size_t length = text.length(); - size_t position = 0; - while (position < length) { - UChar32 character; - size_t next_position = position; - U16_NEXT(string, next_position, length, character); - - // Now that we have the character, we use ICU in order to query for the - // appropriate Unicode BiDi character type. - int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); - if ((property == U_RIGHT_TO_LEFT) || (property == U_RIGHT_TO_LEFT_ARABIC)) - return true; - - position = next_position; - } - - return false; -} - -void WrapStringWithLTRFormatting(std::wstring* text) { - // Inserting an LRE (Left-To-Right Embedding) mark as the first character. - text->insert(0, 1, static_cast<wchar_t>(kLeftToRightEmbeddingMark)); - - // Inserting a PDF (Pop Directional Formatting) mark as the last character. - text->push_back(static_cast<wchar_t>(kPopDirectionalFormatting)); -} - -void WrapStringWithRTLFormatting(std::wstring* text) { - // Inserting an RLE (Right-To-Left Embedding) mark as the first character. - text->insert(0, 1, static_cast<wchar_t>(kRightToLeftEmbeddingMark)); - - // Inserting a PDF (Pop Directional Formatting) mark as the last character. - text->push_back(static_cast<wchar_t>(kPopDirectionalFormatting)); -} - -void WrapPathWithLTRFormatting(const FilePath& path, - string16* rtl_safe_path) { - // Wrap the overall path with LRE-PDF pair which essentialy marks the - // string as a Left-To-Right string. - // Inserting an LRE (Left-To-Right Embedding) mark as the first character. - rtl_safe_path->push_back(kLeftToRightEmbeddingMark); -#if defined(OS_MACOSX) - rtl_safe_path->append(UTF8ToUTF16(path.value())); -#elif defined(OS_WIN) - rtl_safe_path->append(path.value()); -#else // defined(OS_POSIX) && !defined(OS_MACOSX) - std::wstring wide_path = base::SysNativeMBToWide(path.value()); - rtl_safe_path->append(WideToUTF16(wide_path)); -#endif - // Inserting a PDF (Pop Directional Formatting) mark as the last character. - rtl_safe_path->push_back(kPopDirectionalFormatting); -} - -std::wstring GetDisplayStringInLTRDirectionality(std::wstring* text) { - if (GetTextDirection() == RIGHT_TO_LEFT) - WrapStringWithLTRFormatting(text); - return *text; -} - -int DefaultCanvasTextAlignment() { - if (GetTextDirection() == LEFT_TO_RIGHT) { - return gfx::Canvas::TEXT_ALIGN_LEFT; - } else { - return gfx::Canvas::TEXT_ALIGN_RIGHT; - } -} - - // Compares the character data stored in two different strings by specified // Collator instance. UCollationResult CompareStringWithCollator(const icu::Collator* collator, diff --git a/app/l10n_util.h b/app/l10n_util.h index b87442c..c176f73f 100644 --- a/app/l10n_util.h +++ b/app/l10n_util.h @@ -25,17 +25,10 @@ #include "app/l10n_util_mac.h" #endif // OS_MACOSX -class FilePath; class PrefService; namespace l10n_util { -const char16 kRightToLeftMark = 0x200f; -const char16 kLeftToRightMark = 0x200e; -const char16 kLeftToRightEmbeddingMark = 0x202A; -const char16 kRightToLeftEmbeddingMark = 0x202B; -const char16 kPopDirectionalFormatting = 0x202C; - // This method is responsible for determining the locale as defined below. In // nearly all cases you shouldn't call this, rather use GetApplicationLocale // defined on browser_process. @@ -181,97 +174,6 @@ string16 ToLower(const string16& string); // Returns the upper case equivalent of string. string16 ToUpper(const string16& string); -// Represents the text direction returned by the GetTextDirection() function. -enum TextDirection { - UNKNOWN_DIRECTION, - RIGHT_TO_LEFT, - LEFT_TO_RIGHT, -}; - -// Returns the text direction for the default ICU locale. It is assumed -// that SetICUDefaultLocale has been called to set the default locale to -// the UI locale of Chrome. Its return is one of the following three: -// * LEFT_TO_RIGHT: Left-To-Right (e.g. English, Chinese, etc.); -// * RIGHT_TO_LEFT: Right-To-Left (e.g. Arabic, Hebrew, etc.), and; -// * UNKNOWN_DIRECTION: unknown (or error). -TextDirection GetICUTextDirection(); - -// Get the application text direction. (This is just the ICU direction, -// except on GTK.) -TextDirection GetTextDirection(); - -// Returns the text direction for |locale_name|. -TextDirection GetTextDirectionForLocale(const char* locale_name); - -// Given the string in |text|, returns the directionality of the first -// character with strong directionality in the string. If no character in the -// text has strong directionality, LEFT_TO_RIGHT is returned. The Bidi -// character types L, LRE, LRO, R, AL, RLE, and RLO are considered as strong -// directionality characters. Please refer to http://unicode.org/reports/tr9/ -// for more information. -TextDirection GetFirstStrongCharacterDirection(const std::wstring& text); - -// Given the string in |text|, this function creates a copy of the string with -// the appropriate Unicode formatting marks that mark the string direction -// (either left-to-right or right-to-left). The new string is returned in -// |localized_text|. The function checks both the current locale and the -// contents of the string in order to determine the direction of the returned -// string. The function returns true if the string in |text| was properly -// adjusted. -// -// Certain LTR strings are not rendered correctly when the context is RTL. For -// example, the string "Foo!" will appear as "!Foo" if it is rendered as is in -// an RTL context. Calling this function will make sure the returned localized -// string is always treated as a right-to-left string. This is done by -// inserting certain Unicode formatting marks into the returned string. -// -// TODO(idana) bug# 1206120: this function adjusts the string in question only -// if the current locale is right-to-left. The function does not take care of -// the opposite case (an RTL string displayed in an LTR context) since -// adjusting the string involves inserting Unicode formatting characters that -// Windows does not handle well unless right-to-left language support is -// installed. Since the English version of Windows doesn't have right-to-left -// language support installed by default, inserting the direction Unicode mark -// results in Windows displaying squares. -bool AdjustStringForLocaleDirection(const std::wstring& text, - std::wstring* localized_text); - -// Returns true if the string contains at least one character with strong right -// to left directionality; that is, a character with either R or AL Unicode -// BiDi character type. -bool StringContainsStrongRTLChars(const std::wstring& text); - -// Wraps a string with an LRE-PDF pair which essentialy marks the string as a -// Left-To-Right string. Doing this is useful in order to make sure LTR -// strings are rendered properly in an RTL context. -void WrapStringWithLTRFormatting(std::wstring* text); - -// Wraps a string with an RLE-PDF pair which essentialy marks the string as a -// Right-To-Left string. Doing this is useful in order to make sure RTL -// strings are rendered properly in an LTR context. -void WrapStringWithRTLFormatting(std::wstring* text); - -// Wraps file path to get it to display correctly in RTL UI. All filepaths -// should be passed through this function before display in UI for RTL locales. -void WrapPathWithLTRFormatting(const FilePath& path, - string16* rtl_safe_path); - -// Given the string in |text|, this function returns the adjusted string having -// LTR directionality for display purpose. Which means that in RTL locale the -// 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); - -// Returns the default text alignment to be used when drawing text on a -// gfx::Canvas based on the directionality of the system locale language. This -// function is used by gfx::Canvas::DrawStringInt when the text alignment is -// not specified. -// -// This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or -// gfx::Canvas::TEXT_ALIGN_RIGHT. -int DefaultCanvasTextAlignment(); - // In place sorting of strings using collation rules for |locale|. // TODO(port): this should take string16. void SortStrings(const std::string& locale, diff --git a/app/l10n_util_dummy.cc b/app/l10n_util_dummy.cc index a9a4a92..0907da5 100644 --- a/app/l10n_util_dummy.cc +++ b/app/l10n_util_dummy.cc @@ -16,9 +16,6 @@ namespace l10n_util { -// Represents the locale-specific text direction. -static TextDirection g_text_direction = UNKNOWN_DIRECTION; - std::wstring GetString(int message_id) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); return UTF16ToWide(rb.GetLocalizedString(message_id)); diff --git a/app/l10n_util_unittest.cc b/app/l10n_util_unittest.cc index cd299d1..94dd8fd 100644 --- a/app/l10n_util_unittest.cc +++ b/app/l10n_util_unittest.cc @@ -39,10 +39,6 @@ class StringWrapper { DISALLOW_COPY_AND_ASSIGN(StringWrapper); }; -l10n_util::TextDirection GetTextDirection(const char* locale_name) { - return l10n_util::GetTextDirectionForLocale(locale_name); -} - } // namespace class L10nUtilTest : public PlatformTest { @@ -274,244 +270,6 @@ TEST_F(L10nUtilTest, SortStringsUsingFunction) { STLDeleteElements(&strings); } -TEST_F(L10nUtilTest, GetFirstStrongCharacterDirection) { - // Test pure LTR string. - std::wstring string(L"foo bar"); - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test bidi string in which the first character with strong directionality - // is a character with type L. - string.assign(L"foo \x05d0 bar"); - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test bidi string in which the first character with strong directionality - // is a character with type R. - string.assign(L"\x05d0 foo bar"); - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test bidi string which starts with a character with weak directionality - // and in which the first character with strong directionality is a character - // with type L. - string.assign(L"!foo \x05d0 bar"); - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test bidi string which starts with a character with weak directionality - // and in which the first character with strong directionality is a character - // with type R. - string.assign(L",\x05d0 foo bar"); - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test bidi string in which the first character with strong directionality - // is a character with type LRE. - string.assign(L"\x202a \x05d0 foo bar"); - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test bidi string in which the first character with strong directionality - // is a character with type LRO. - string.assign(L"\x202d \x05d0 foo bar"); - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test bidi string in which the first character with strong directionality - // is a character with type RLE. - string.assign(L"\x202b foo \x05d0 bar"); - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test bidi string in which the first character with strong directionality - // is a character with type RLO. - string.assign(L"\x202e foo \x05d0 bar"); - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test bidi string in which the first character with strong directionality - // is a character with type AL. - string.assign(L"\x0622 foo \x05d0 bar"); - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test a string without strong directionality characters. - string.assign(L",!.{}"); - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test empty string. - string.assign(L""); - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, - l10n_util::GetFirstStrongCharacterDirection(string)); - - // Test characters in non-BMP (e.g. Phoenician letters. Please refer to - // http://demo.icu-project.org/icu-bin/ubrowse?scr=151&b=10910 for more - // information). -#if defined(WCHAR_T_IS_UTF32) - string.assign(L" ! \x10910" L"abc 123"); -#elif defined(WCHAR_T_IS_UTF16) - string.assign(L" ! \xd802\xdd10" L"abc 123"); -#else -#error wchar_t should be either UTF-16 or UTF-32 -#endif - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, - l10n_util::GetFirstStrongCharacterDirection(string)); - -#if defined(WCHAR_T_IS_UTF32) - string.assign(L" ! \x10401" L"abc 123"); -#elif defined(WCHAR_T_IS_UTF16) - string.assign(L" ! \xd801\xdc01" L"abc 123"); -#else -#error wchar_t should be either UTF-16 or UTF-32 -#endif - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, - l10n_util::GetFirstStrongCharacterDirection(string)); -} - -typedef struct { - std::wstring path; - std::wstring wrapped_path; -} PathAndWrappedPath; - -TEST_F(L10nUtilTest, WrapPathWithLTRFormatting) { - std::wstring kSeparator; - kSeparator.push_back(static_cast<wchar_t>(FilePath::kSeparators[0])); - const PathAndWrappedPath test_data[] = { - // Test common path, such as "c:\foo\bar". - { L"c:" + kSeparator + L"foo" + kSeparator + L"bar", - L"\x202a"L"c:" + kSeparator + L"foo" + kSeparator + - L"bar\x202c" - }, - // Test path with file name, such as "c:\foo\bar\test.jpg". - { L"c:" + kSeparator + L"foo" + kSeparator + L"bar" + kSeparator + - L"test.jpg", - L"\x202a"L"c:" + kSeparator + L"foo" + kSeparator + - L"bar" + kSeparator + L"test.jpg\x202c" - }, - // Test path ending with punctuation, such as "c:\(foo)\bar.". - { L"c:" + kSeparator + L"(foo)" + kSeparator + L"bar.", - L"\x202a"L"c:" + kSeparator + L"(foo)" + kSeparator + - L"bar.\x202c" - }, - // Test path ending with separator, such as "c:\foo\bar\". - { L"c:" + kSeparator + L"foo" + kSeparator + L"bar" + kSeparator, - L"\x202a"L"c:" + kSeparator + L"foo" + kSeparator + - L"bar" + kSeparator + L"\x202c", - }, - // Test path with RTL character. - { L"c:" + kSeparator + L"\x05d0", - L"\x202a"L"c:" + kSeparator + L"\x05d0\x202c", - }, - // Test path with 2 level RTL directory names. - { L"c:" + kSeparator + L"\x05d0" + kSeparator + L"\x0622", - L"\x202a"L"c:" + kSeparator + L"\x05d0" + kSeparator + - L"\x0622\x202c", - }, - // Test path with mixed RTL/LTR directory names and ending with punctuation. - { L"c:" + kSeparator + L"\x05d0" + kSeparator + L"\x0622" + kSeparator + - L"(foo)" + kSeparator + L"b.a.r.", - L"\x202a"L"c:" + kSeparator + L"\x05d0" + kSeparator + - L"\x0622" + kSeparator + L"(foo)" + kSeparator + - L"b.a.r.\x202c", - }, - // Test path without driver name, such as "/foo/bar/test/jpg". - { kSeparator + L"foo" + kSeparator + L"bar" + kSeparator + L"test.jpg", - L"\x202a" + kSeparator + L"foo" + kSeparator + L"bar" + - kSeparator + L"test.jpg" + L"\x202c" - }, - // Test path start with current directory, such as "./foo". - { L"." + kSeparator + L"foo", - L"\x202a"L"." + kSeparator + L"foo" + L"\x202c" - }, - // Test path start with parent directory, such as "../foo/bar.jpg". - { L".." + kSeparator + L"foo" + kSeparator + L"bar.jpg", - L"\x202a"L".." + kSeparator + L"foo" + kSeparator + - L"bar.jpg" + L"\x202c" - }, - // Test absolute path, such as "//foo/bar.jpg". - { kSeparator + kSeparator + L"foo" + kSeparator + L"bar.jpg", - L"\x202a" + kSeparator + kSeparator + L"foo" + kSeparator + - L"bar.jpg" + L"\x202c" - }, - // Test path with mixed RTL/LTR directory names. - { L"c:" + kSeparator + L"foo" + kSeparator + L"\x05d0" + kSeparator + - L"\x0622" + kSeparator + L"\x05d1.jpg", - L"\x202a"L"c:" + kSeparator + L"foo" + kSeparator + L"\x05d0" + - kSeparator + L"\x0622" + kSeparator + L"\x05d1.jpg" + L"\x202c", - }, - // Test empty path. - { L"", - L"\x202a\x202c" - } - }; - for (unsigned int i = 0; i < arraysize(test_data); ++i) { - string16 localized_file_path_string; - FilePath path = FilePath::FromWStringHack(test_data[i].path); - l10n_util::WrapPathWithLTRFormatting(path, &localized_file_path_string); - std::wstring wrapped_path = UTF16ToWide(localized_file_path_string); - EXPECT_EQ(wrapped_path, test_data[i].wrapped_path); - } -} - -typedef struct { - std::wstring raw_filename; - std::wstring display_string; -} StringAndLTRString; - -TEST_F(L10nUtilTest, GetDisplayStringInLTRDirectionality) { - const StringAndLTRString test_data[] = { - { L"test", L"\x202atest\x202c" }, - { L"test.html", L"\x202atest.html\x202c" }, - { L"\x05d0\x05d1\x05d2", L"\x202a\x05d0\x05d1\x05d2\x202c" }, - { L"\x05d0\x05d1\x05d2.txt", L"\x202a\x05d0\x05d1\x05d2.txt\x202c" }, - { L"\x05d0"L"abc", L"\x202a\x05d0"L"abc\x202c" }, - { L"\x05d0"L"abc.txt", L"\x202a\x05d0"L"abc.txt\x202c" }, - { L"abc\x05d0\x05d1", L"\x202a"L"abc\x05d0\x05d1\x202c" }, - { 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 = - l10n_util::GetDisplayStringInLTRDirectionality(&input); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - EXPECT_EQ(test_data[i].display_string, expected); - else - EXPECT_EQ(input, expected); - } -} - -TEST_F(L10nUtilTest, GetTextDirection) { - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, GetTextDirection("ar")); - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, GetTextDirection("ar_EG")); - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, GetTextDirection("he")); - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, GetTextDirection("he_IL")); - // iw is an obsolete code for Hebrew. - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, GetTextDirection("iw")); - // Although we're not yet localized to Farsi and Urdu, we - // do have the text layout direction information for them. - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, GetTextDirection("fa")); - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, GetTextDirection("ur")); -#if 0 - // Enable these when we include the minimal locale data for Azerbaijani - // written in Arabic and Dhivehi. At the moment, our copy of - // ICU data does not have entries for them. - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, GetTextDirection("az_Arab")); - // Dhivehi that uses Thaana script. - EXPECT_EQ(l10n_util::RIGHT_TO_LEFT, GetTextDirection("dv")); -#endif - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("en")); - // Chinese in China with '-'. - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("zh-CN")); - // Filipino : 3-letter code - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("fil")); - // Russian - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ru")); - // Japanese that uses multiple scripts - EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ja")); -} - // Test upper and lower case string conversion. TEST_F(L10nUtilTest, UpperLower) { string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE.")); diff --git a/app/l10n_util_win.cc b/app/l10n_util_win.cc index 0ffdad7..92dfac1 100644 --- a/app/l10n_util_win.cc +++ b/app/l10n_util_win.cc @@ -3,11 +3,12 @@ // found in the LICENSE file. #include "app/l10n_util.h" -#include "app/l10n_util_win.h" #include <algorithm> #include <windowsx.h> +#include "app/l10n_util_win.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "base/win_util.h" @@ -39,12 +40,11 @@ void AdjustLogFont(const std::wstring& font_family, namespace l10n_util { int GetExtendedStyles() { - return GetTextDirection() == LEFT_TO_RIGHT ? 0 : - WS_EX_LAYOUTRTL | WS_EX_RTLREADING; + return !base::i18n::IsRTL() ? 0 : WS_EX_LAYOUTRTL | WS_EX_RTLREADING; } int GetExtendedTooltipStyles() { - return GetTextDirection() == LEFT_TO_RIGHT ? 0 : WS_EX_LAYOUTRTL; + return !base::i18n::IsRTL() ? 0 : WS_EX_LAYOUTRTL; } void HWNDSetRTLLayout(HWND hwnd) { diff --git a/app/resource_bundle_linux.cc b/app/resource_bundle_linux.cc index 49c271a..cc9dbad 100644 --- a/app/resource_bundle_linux.cc +++ b/app/resource_bundle_linux.cc @@ -13,6 +13,7 @@ #include "base/data_pack.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/path_service.h" #include "base/string_piece.h" @@ -40,8 +41,7 @@ GdkPixbuf* LoadPixbuf(RefCountedStaticMemory* data, bool rtl_enabled) { if (!pixbuf) return NULL; - if ((l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) && - rtl_enabled) { + if (base::i18n::IsRTL() && rtl_enabled) { // |pixbuf| will get unreffed and destroyed (see below). The returned value // has ref count 1. return gdk_pixbuf_flip(pixbuf, TRUE); diff --git a/app/text_elider.cc b/app/text_elider.cc index 21d5201..98b9090 100644 --- a/app/text_elider.cc +++ b/app/text_elider.cc @@ -8,6 +8,7 @@ #include "app/text_elider.h" #include "app/l10n_util.h" #include "base/file_path.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" @@ -263,7 +264,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 l10n_util::GetDisplayStringInLTRDirectionality(&elided_name); + return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name); } #if defined(OS_WIN) @@ -277,7 +278,7 @@ std::wstring ElideFilename(const FilePath& filename, if (rootname.empty() || extension.empty()) { std::wstring elided_name = ElideText(filename.ToWStringHack(), font, available_pixel_width); - return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name); + return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name); } int ext_width = font.GetStringWidth(extension); @@ -286,13 +287,13 @@ 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 l10n_util::GetDisplayStringInLTRDirectionality(&elided_name); + return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name); } int available_root_width = available_pixel_width - ext_width; std::wstring elided_name = ElideText(rootname, font, available_root_width); elided_name += extension; - return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name); + return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name); } // This function adds an ellipsis at the end of the text if the text diff --git a/app/text_elider.h b/app/text_elider.h index aa33c29..f93b944 100644 --- a/app/text_elider.h +++ b/app/text_elider.h @@ -28,7 +28,7 @@ namespace gfx { // // Note: in RTL locales, if the URL returned by this function is going to be // displayed in the UI, then it is likely that the string needs to be marked -// as an LTR string (using l10n_util::WrapStringWithLTRFormatting()) so that it +// as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it // is displayed properly in an RTL context. Please refer to // http://crbug.com/6487 for more information. std::wstring ElideUrl(const GURL& url, diff --git a/app/text_elider_unittest.cc b/app/text_elider_unittest.cc index f8a30ef..f2a81f4f 100644 --- a/app/text_elider_unittest.cc +++ b/app/text_elider_unittest.cc @@ -6,6 +6,7 @@ #include "app/text_elider.h" #include "app/l10n_util.h" #include "base/file_path.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" @@ -178,8 +179,8 @@ TEST(TextEliderTest, TestFilenameEliding) { for (size_t i = 0; i < arraysize(testcases); ++i) { FilePath filepath(testcases[i].input); std::wstring expected = testcases[i].output; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&expected); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&expected); EXPECT_EQ(expected, ElideFilename(filepath, font, font.GetStringWidth(testcases[i].output))); diff --git a/app/win_util.cc b/app/win_util.cc index a85ca9b..b043db3 100644 --- a/app/win_util.cc +++ b/app/win_util.cc @@ -16,6 +16,7 @@ #include "base/base_switches.h" #include "base/command_line.h" #include "base/file_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/native_library.h" #include "base/registry.h" @@ -519,17 +520,17 @@ int MessageBox(HWND hwnd, return IDOK; UINT actual_flags = flags; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) actual_flags |= MB_RIGHT | MB_RTLREADING; std::wstring localized_text; const wchar_t* text_ptr = text.c_str(); - if (l10n_util::AdjustStringForLocaleDirection(text, &localized_text)) + if (base::i18n::AdjustStringForLocaleDirection(text, &localized_text)) text_ptr = localized_text.c_str(); std::wstring localized_caption; const wchar_t* caption_ptr = caption.c_str(); - if (l10n_util::AdjustStringForLocaleDirection(caption, &localized_caption)) + if (base::i18n::AdjustStringForLocaleDirection(caption, &localized_caption)) caption_ptr = localized_caption.c_str(); return ::MessageBox(hwnd, text_ptr, caption_ptr, actual_flags); diff --git a/base/base.gyp b/base/base.gyp index 802147e..581b38b 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -31,6 +31,8 @@ 'i18n/icu_util.h', 'i18n/number_formatting.cc', 'i18n/number_formatting.h', + 'i18n/rtl.cc', + 'i18n/rtl.h', 'i18n/time_formatting.cc', 'i18n/time_formatting.h', 'i18n/word_iterator.cc', @@ -76,6 +78,7 @@ 'id_map_unittest.cc', 'i18n/file_util_icu_unittest.cc', 'i18n/icu_string_conversions_unittest.cc', + 'i18n/rtl_unittest.cc', 'i18n/word_iterator_unittest.cc', 'json/json_reader_unittest.cc', 'json/json_writer_unittest.cc', diff --git a/base/file_path.h b/base/file_path.h index a328c8a..61aa4fb 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -66,7 +66,7 @@ // // WARNING: FilePaths should ALWAYS be displayed with LTR directionality, even // when the UI language is RTL. This means you always need to pass filepaths -// through l10n_util::WrapPathWithLTRFormatting() before displaying it in the +// through base::i18n::WrapPathWithLTRFormatting() before displaying it in the // RTL UI. // // This is a very common source of bugs, please try to keep this in mind. diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc new file mode 100644 index 0000000..52f7de7 --- /dev/null +++ b/base/i18n/rtl.cc @@ -0,0 +1,228 @@ +// 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 "base/i18n/rtl.h" + +#include "base/file_path.h" +#include "base/logging.h" +#include "base/string_util.h" +#include "base/utf_string_conversions.h" +#include "base/sys_string_conversions.h" +#include "unicode/coll.h" +#include "unicode/locid.h" +#include "unicode/uchar.h" +#include "unicode/uscript.h" + +#if defined(TOOLKIT_GTK) +#include <gtk/gtk.h> +#endif + +namespace base { +namespace i18n { + +// Represents the locale-specific ICU text direction. +static TextDirection g_icu_text_direction = UNKNOWN_DIRECTION; + +void GetLanguageAndRegionFromOS(std::string* lang, std::string* region) { + // Later we may have to change this to be OS-dependent so that + // it's not affected by ICU's default locale. It's all right + // to do this way because SetICUDefaultLocale is internal + // to this file and we know that it's not yet called when this function + // is called. + icu::Locale locale = icu::Locale::getDefault(); + const char* language = locale.getLanguage(); + const char* country = locale.getCountry(); + DCHECK(language); + *lang = language; + *region = country; +} + +// Convert Chrome locale name to ICU locale name +std::string ICULocaleName(const std::string& locale_string) { + // If not Spanish, just return it. + if (locale_string.substr(0, 2) != "es") + return locale_string; + // Expand es to es-ES. + if (LowerCaseEqualsASCII(locale_string, "es")) + return "es-ES"; + // Map es-419 (Latin American Spanish) to es-FOO depending on the system + // locale. If it's es-RR other than es-ES, map to es-RR. Otherwise, map + // to es-MX (the most populous in Spanish-speaking Latin America). + if (LowerCaseEqualsASCII(locale_string, "es-419")) { + std::string lang, region; + GetLanguageAndRegionFromOS(&lang, ®ion); + if (LowerCaseEqualsASCII(lang, "es") && + !LowerCaseEqualsASCII(region, "es")) { + lang.append("-"); + lang.append(region); + return lang; + } + return "es-MX"; + } + // Currently, Chrome has only "es" and "es-419", but later we may have + // more specific "es-RR". + return locale_string; +} + +void SetICUDefaultLocale(const std::string& locale_string) { + icu::Locale locale(ICULocaleName(locale_string).c_str()); + UErrorCode error_code = U_ZERO_ERROR; + icu::Locale::setDefault(locale, error_code); + // This return value is actually bogus because Locale object is + // an ID and setDefault seems to always succeed (regardless of the + // presence of actual locale data). However, + // it does not hurt to have it as a sanity check. + DCHECK(U_SUCCESS(error_code)); + g_icu_text_direction = UNKNOWN_DIRECTION; +} + +TextDirection GetICUTextDirection() { + if (g_icu_text_direction == UNKNOWN_DIRECTION) { + const icu::Locale& locale = icu::Locale::getDefault(); + g_icu_text_direction = GetTextDirectionForLocale(locale.getName()); + } + return g_icu_text_direction; +} + +TextDirection GetTextDirection() { +#if defined(TOOLKIT_GTK) + GtkTextDirection gtk_dir = gtk_widget_get_default_direction(); + return (gtk_dir == GTK_TEXT_DIR_LTR) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT; +#else + return GetICUTextDirection(); +#endif +} + +bool IsRTL() { + return GetTextDirection() == RIGHT_TO_LEFT; +} + +TextDirection GetTextDirectionForLocale(const char* locale_name) { + UErrorCode status = U_ZERO_ERROR; + ULayoutType layout_dir = uloc_getCharacterOrientation(locale_name, &status); + DCHECK(U_SUCCESS(status)); + // Treat anything other than RTL as LTR. + return (layout_dir != ULOC_LAYOUT_RTL) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT; +} + +TextDirection GetFirstStrongCharacterDirection(const std::wstring& text) { +#if defined(WCHAR_T_IS_UTF32) + string16 text_utf16 = WideToUTF16(text); + const UChar* string = text_utf16.c_str(); +#else + const UChar* string = text.c_str(); +#endif + size_t length = text.length(); + size_t position = 0; + while (position < length) { + UChar32 character; + size_t next_position = position; + U16_NEXT(string, next_position, length, character); + + // Now that we have the character, we use ICU in order to query for the + // appropriate Unicode BiDi character type. + int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); + if ((property == U_RIGHT_TO_LEFT) || + (property == U_RIGHT_TO_LEFT_ARABIC) || + (property == U_RIGHT_TO_LEFT_EMBEDDING) || + (property == U_RIGHT_TO_LEFT_OVERRIDE)) { + return RIGHT_TO_LEFT; + } else if ((property == U_LEFT_TO_RIGHT) || + (property == U_LEFT_TO_RIGHT_EMBEDDING) || + (property == U_LEFT_TO_RIGHT_OVERRIDE)) { + return LEFT_TO_RIGHT; + } + + position = next_position; + } + + return LEFT_TO_RIGHT; +} + +bool AdjustStringForLocaleDirection(const std::wstring& text, + std::wstring* localized_text) { + if (GetTextDirection() == LEFT_TO_RIGHT || text.length() == 0) + return false; + + // Marking the string as LTR if the locale is RTL and the string does not + // contain strong RTL characters. Otherwise, mark the string as RTL. + *localized_text = text; + bool has_rtl_chars = StringContainsStrongRTLChars(text); + if (!has_rtl_chars) + WrapStringWithLTRFormatting(localized_text); + else + WrapStringWithRTLFormatting(localized_text); + + return true; +} + +bool StringContainsStrongRTLChars(const std::wstring& text) { +#if defined(WCHAR_T_IS_UTF32) + string16 text_utf16 = WideToUTF16(text); + const UChar* string = text_utf16.c_str(); +#else + const UChar* string = text.c_str(); +#endif + size_t length = text.length(); + size_t position = 0; + while (position < length) { + UChar32 character; + size_t next_position = position; + U16_NEXT(string, next_position, length, character); + + // Now that we have the character, we use ICU in order to query for the + // appropriate Unicode BiDi character type. + int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); + if ((property == U_RIGHT_TO_LEFT) || (property == U_RIGHT_TO_LEFT_ARABIC)) + return true; + + position = next_position; + } + + return false; +} + +void WrapStringWithLTRFormatting(std::wstring* text) { + // Inserting an LRE (Left-To-Right Embedding) mark as the first character. + text->insert(0, 1, static_cast<wchar_t>(kLeftToRightEmbeddingMark)); + + // Inserting a PDF (Pop Directional Formatting) mark as the last character. + text->push_back(static_cast<wchar_t>(kPopDirectionalFormatting)); +} + +void WrapStringWithRTLFormatting(std::wstring* text) { + // Inserting an RLE (Right-To-Left Embedding) mark as the first character. + text->insert(0, 1, static_cast<wchar_t>(kRightToLeftEmbeddingMark)); + + // Inserting a PDF (Pop Directional Formatting) mark as the last character. + text->push_back(static_cast<wchar_t>(kPopDirectionalFormatting)); +} + +void WrapPathWithLTRFormatting(const FilePath& path, + string16* rtl_safe_path) { + // Wrap the overall path with LRE-PDF pair which essentialy marks the + // string as a Left-To-Right string. + // Inserting an LRE (Left-To-Right Embedding) mark as the first character. + rtl_safe_path->push_back(kLeftToRightEmbeddingMark); +#if defined(OS_MACOSX) + rtl_safe_path->append(UTF8ToUTF16(path.value())); +#elif defined(OS_WIN) + rtl_safe_path->append(path.value()); +#else // defined(OS_POSIX) && !defined(OS_MACOSX) + std::wstring wide_path = base::SysNativeMBToWide(path.value()); + rtl_safe_path->append(WideToUTF16(wide_path)); +#endif + // Inserting a PDF (Pop Directional Formatting) mark as the last character. + rtl_safe_path->push_back(kPopDirectionalFormatting); +} + +std::wstring GetDisplayStringInLTRDirectionality(std::wstring* text) { + if (GetTextDirection() == RIGHT_TO_LEFT) + WrapStringWithLTRFormatting(text); + return *text; +} + +} // namespace i18n +} // namespace base + diff --git a/base/i18n/rtl.h b/base/i18n/rtl.h new file mode 100644 index 0000000..05a5ff0 --- /dev/null +++ b/base/i18n/rtl.h @@ -0,0 +1,121 @@ +// 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. + +#ifndef BASE_I18N_RTL_H_ +#define BASE_I18N_RTL_H_ + +#include "base/string16.h" + +class FilePath; + +namespace base { +namespace i18n { + +const char16 kRightToLeftMark = 0x200f; +const char16 kLeftToRightMark = 0x200e; +const char16 kLeftToRightEmbeddingMark = 0x202A; +const char16 kRightToLeftEmbeddingMark = 0x202B; +const char16 kPopDirectionalFormatting = 0x202C; + +// Represents the text direction returned by the GetTextDirection() function. +enum TextDirection { + UNKNOWN_DIRECTION, + RIGHT_TO_LEFT, + LEFT_TO_RIGHT, +}; + +// Get language and region from the OS. +void GetLanguageAndRegionFromOS(std::string* lang, std::string* region); + +// Sets the default locale of ICU. +// Once the application locale of Chrome in GetApplicationLocale is determined, +// the default locale of ICU need to be changed to match the application locale +// so that ICU functions work correctly in a locale-dependent manner. +// This is handy in that we don't have to call GetApplicationLocale() +// everytime we call locale-dependent ICU APIs as long as we make sure +// that this is called before any locale-dependent API is called. +void SetICUDefaultLocale(const std::string& locale_string); + +// Returns the text direction for the default ICU locale. It is assumed +// that SetICUDefaultLocale has been called to set the default locale to +// the UI locale of Chrome. Its return is one of the following three: +// * LEFT_TO_RIGHT: Left-To-Right (e.g. English, Chinese, etc.); +// * RIGHT_TO_LEFT: Right-To-Left (e.g. Arabic, Hebrew, etc.), and; +// * UNKNOWN_DIRECTION: unknown (or error). +TextDirection GetICUTextDirection(); + +// Get the application text direction. (This is just the ICU direction, +// except on GTK.) +TextDirection GetTextDirection(); + +// Returns true if the application text direction is right-to-left. +bool IsRTL(); + +// Returns the text direction for |locale_name|. +TextDirection GetTextDirectionForLocale(const char* locale_name); + +// Given the string in |text|, returns the directionality of the first +// character with strong directionality in the string. If no character in the +// text has strong directionality, LEFT_TO_RIGHT is returned. The Bidi +// character types L, LRE, LRO, R, AL, RLE, and RLO are considered as strong +// directionality characters. Please refer to http://unicode.org/reports/tr9/ +// for more information. +TextDirection GetFirstStrongCharacterDirection(const std::wstring& text); + +// Given the string in |text|, this function creates a copy of the string with +// the appropriate Unicode formatting marks that mark the string direction +// (either left-to-right or right-to-left). The new string is returned in +// |localized_text|. The function checks both the current locale and the +// contents of the string in order to determine the direction of the returned +// string. The function returns true if the string in |text| was properly +// adjusted. +// +// Certain LTR strings are not rendered correctly when the context is RTL. For +// example, the string "Foo!" will appear as "!Foo" if it is rendered as is in +// an RTL context. Calling this function will make sure the returned localized +// string is always treated as a right-to-left string. This is done by +// inserting certain Unicode formatting marks into the returned string. +// +// TODO(idana) bug# 1206120: this function adjusts the string in question only +// if the current locale is right-to-left. The function does not take care of +// the opposite case (an RTL string displayed in an LTR context) since +// adjusting the string involves inserting Unicode formatting characters that +// Windows does not handle well unless right-to-left language support is +// installed. Since the English version of Windows doesn't have right-to-left +// language support installed by default, inserting the direction Unicode mark +// results in Windows displaying squares. +bool AdjustStringForLocaleDirection(const std::wstring& text, + std::wstring* localized_text); + +// Returns true if the string contains at least one character with strong right +// to left directionality; that is, a character with either R or AL Unicode +// BiDi character type. +bool StringContainsStrongRTLChars(const std::wstring& text); + +// Wraps a string with an LRE-PDF pair which essentialy marks the string as a +// Left-To-Right string. Doing this is useful in order to make sure LTR +// strings are rendered properly in an RTL context. +void WrapStringWithLTRFormatting(std::wstring* text); + +// Wraps a string with an RLE-PDF pair which essentialy marks the string as a +// Right-To-Left string. Doing this is useful in order to make sure RTL +// strings are rendered properly in an LTR context. +void WrapStringWithRTLFormatting(std::wstring* text); + +// Wraps file path to get it to display correctly in RTL UI. All filepaths +// should be passed through this function before display in UI for RTL locales. +void WrapPathWithLTRFormatting(const FilePath& path, + string16* rtl_safe_path); + +// Given the string in |text|, this function returns the adjusted string having +// LTR directionality for display purpose. Which means that in RTL locale the +// 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); + +} // namespace i18n +} // namespace base + +#endif // BASE_I18N_RTL_H_ diff --git a/base/i18n/rtl_unittest.cc b/base/i18n/rtl_unittest.cc new file mode 100644 index 0000000..65d0f6b --- /dev/null +++ b/base/i18n/rtl_unittest.cc @@ -0,0 +1,258 @@ +// Copyright (c) 2006-2008 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 "base/i18n/rtl.h" + +#include "base/file_path.h" +#include "base/string_util.h" +#include "base/utf_string_conversions.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/platform_test.h" + +namespace { +base::i18n::TextDirection GetTextDirection(const char* locale_name) { + return base::i18n::GetTextDirectionForLocale(locale_name); +} +} + +class RTLTest : public PlatformTest { +}; + +TEST_F(RTLTest, GetFirstStrongCharacterDirection) { + // Test pure LTR string. + std::wstring string(L"foo bar"); + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test bidi string in which the first character with strong directionality + // is a character with type L. + string.assign(L"foo \x05d0 bar"); + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test bidi string in which the first character with strong directionality + // is a character with type R. + string.assign(L"\x05d0 foo bar"); + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test bidi string which starts with a character with weak directionality + // and in which the first character with strong directionality is a character + // with type L. + string.assign(L"!foo \x05d0 bar"); + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test bidi string which starts with a character with weak directionality + // and in which the first character with strong directionality is a character + // with type R. + string.assign(L",\x05d0 foo bar"); + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test bidi string in which the first character with strong directionality + // is a character with type LRE. + string.assign(L"\x202a \x05d0 foo bar"); + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test bidi string in which the first character with strong directionality + // is a character with type LRO. + string.assign(L"\x202d \x05d0 foo bar"); + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test bidi string in which the first character with strong directionality + // is a character with type RLE. + string.assign(L"\x202b foo \x05d0 bar"); + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test bidi string in which the first character with strong directionality + // is a character with type RLO. + string.assign(L"\x202e foo \x05d0 bar"); + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test bidi string in which the first character with strong directionality + // is a character with type AL. + string.assign(L"\x0622 foo \x05d0 bar"); + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test a string without strong directionality characters. + string.assign(L",!.{}"); + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test empty string. + string.assign(L""); + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, + base::i18n::GetFirstStrongCharacterDirection(string)); + + // Test characters in non-BMP (e.g. Phoenician letters. Please refer to + // http://demo.icu-project.org/icu-bin/ubrowse?scr=151&b=10910 for more + // information). +#if defined(WCHAR_T_IS_UTF32) + string.assign(L" ! \x10910" L"abc 123"); +#elif defined(WCHAR_T_IS_UTF16) + string.assign(L" ! \xd802\xdd10" L"abc 123"); +#else +#error wchar_t should be either UTF-16 or UTF-32 +#endif + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, + base::i18n::GetFirstStrongCharacterDirection(string)); + +#if defined(WCHAR_T_IS_UTF32) + string.assign(L" ! \x10401" L"abc 123"); +#elif defined(WCHAR_T_IS_UTF16) + string.assign(L" ! \xd801\xdc01" L"abc 123"); +#else +#error wchar_t should be either UTF-16 or UTF-32 +#endif + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, + base::i18n::GetFirstStrongCharacterDirection(string)); +} + +typedef struct { + std::wstring path; + std::wstring wrapped_path; +} PathAndWrappedPath; + +TEST_F(RTLTest, WrapPathWithLTRFormatting) { + std::wstring kSeparator; + kSeparator.push_back(static_cast<wchar_t>(FilePath::kSeparators[0])); + const PathAndWrappedPath test_data[] = { + // Test common path, such as "c:\foo\bar". + { L"c:" + kSeparator + L"foo" + kSeparator + L"bar", + L"\x202a"L"c:" + kSeparator + L"foo" + kSeparator + + L"bar\x202c" + }, + // Test path with file name, such as "c:\foo\bar\test.jpg". + { L"c:" + kSeparator + L"foo" + kSeparator + L"bar" + kSeparator + + L"test.jpg", + L"\x202a"L"c:" + kSeparator + L"foo" + kSeparator + + L"bar" + kSeparator + L"test.jpg\x202c" + }, + // Test path ending with punctuation, such as "c:\(foo)\bar.". + { L"c:" + kSeparator + L"(foo)" + kSeparator + L"bar.", + L"\x202a"L"c:" + kSeparator + L"(foo)" + kSeparator + + L"bar.\x202c" + }, + // Test path ending with separator, such as "c:\foo\bar\". + { L"c:" + kSeparator + L"foo" + kSeparator + L"bar" + kSeparator, + L"\x202a"L"c:" + kSeparator + L"foo" + kSeparator + + L"bar" + kSeparator + L"\x202c", + }, + // Test path with RTL character. + { L"c:" + kSeparator + L"\x05d0", + L"\x202a"L"c:" + kSeparator + L"\x05d0\x202c", + }, + // Test path with 2 level RTL directory names. + { L"c:" + kSeparator + L"\x05d0" + kSeparator + L"\x0622", + L"\x202a"L"c:" + kSeparator + L"\x05d0" + kSeparator + + L"\x0622\x202c", + }, + // Test path with mixed RTL/LTR directory names and ending with punctuation. + { L"c:" + kSeparator + L"\x05d0" + kSeparator + L"\x0622" + kSeparator + + L"(foo)" + kSeparator + L"b.a.r.", + L"\x202a"L"c:" + kSeparator + L"\x05d0" + kSeparator + + L"\x0622" + kSeparator + L"(foo)" + kSeparator + + L"b.a.r.\x202c", + }, + // Test path without driver name, such as "/foo/bar/test/jpg". + { kSeparator + L"foo" + kSeparator + L"bar" + kSeparator + L"test.jpg", + L"\x202a" + kSeparator + L"foo" + kSeparator + L"bar" + + kSeparator + L"test.jpg" + L"\x202c" + }, + // Test path start with current directory, such as "./foo". + { L"." + kSeparator + L"foo", + L"\x202a"L"." + kSeparator + L"foo" + L"\x202c" + }, + // Test path start with parent directory, such as "../foo/bar.jpg". + { L".." + kSeparator + L"foo" + kSeparator + L"bar.jpg", + L"\x202a"L".." + kSeparator + L"foo" + kSeparator + + L"bar.jpg" + L"\x202c" + }, + // Test absolute path, such as "//foo/bar.jpg". + { kSeparator + kSeparator + L"foo" + kSeparator + L"bar.jpg", + L"\x202a" + kSeparator + kSeparator + L"foo" + kSeparator + + L"bar.jpg" + L"\x202c" + }, + // Test path with mixed RTL/LTR directory names. + { L"c:" + kSeparator + L"foo" + kSeparator + L"\x05d0" + kSeparator + + L"\x0622" + kSeparator + L"\x05d1.jpg", + L"\x202a"L"c:" + kSeparator + L"foo" + kSeparator + L"\x05d0" + + kSeparator + L"\x0622" + kSeparator + L"\x05d1.jpg" + L"\x202c", + }, + // Test empty path. + { L"", + L"\x202a\x202c" + } + }; + for (unsigned int i = 0; i < arraysize(test_data); ++i) { + string16 localized_file_path_string; + FilePath path = FilePath::FromWStringHack(test_data[i].path); + base::i18n::WrapPathWithLTRFormatting(path, &localized_file_path_string); + std::wstring wrapped_path = UTF16ToWide(localized_file_path_string); + EXPECT_EQ(wrapped_path, test_data[i].wrapped_path); + } +} + +typedef struct { + std::wstring raw_filename; + std::wstring display_string; +} StringAndLTRString; + +TEST_F(RTLTest, GetDisplayStringInLTRDirectionality) { + const StringAndLTRString test_data[] = { + { L"test", L"\x202atest\x202c" }, + { L"test.html", L"\x202atest.html\x202c" }, + { L"\x05d0\x05d1\x05d2", L"\x202a\x05d0\x05d1\x05d2\x202c" }, + { L"\x05d0\x05d1\x05d2.txt", L"\x202a\x05d0\x05d1\x05d2.txt\x202c" }, + { L"\x05d0"L"abc", L"\x202a\x05d0"L"abc\x202c" }, + { L"\x05d0"L"abc.txt", L"\x202a\x05d0"L"abc.txt\x202c" }, + { L"abc\x05d0\x05d1", L"\x202a"L"abc\x05d0\x05d1\x202c" }, + { 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); + if (base::i18n::IsRTL()) + EXPECT_EQ(test_data[i].display_string, expected); + else + EXPECT_EQ(input, expected); + } +} + +TEST_F(RTLTest, GetTextDirection) { + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, GetTextDirection("ar")); + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, GetTextDirection("ar_EG")); + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, GetTextDirection("he")); + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, GetTextDirection("he_IL")); + // iw is an obsolete code for Hebrew. + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, GetTextDirection("iw")); + // Although we're not yet localized to Farsi and Urdu, we + // do have the text layout direction information for them. + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, GetTextDirection("fa")); + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, GetTextDirection("ur")); +#if 0 + // Enable these when we include the minimal locale data for Azerbaijani + // written in Arabic and Dhivehi. At the moment, our copy of + // ICU data does not have entries for them. + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, GetTextDirection("az_Arab")); + // Dhivehi that uses Thaana script. + EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, GetTextDirection("dv")); +#endif + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, GetTextDirection("en")); + // Chinese in China with '-'. + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, GetTextDirection("zh-CN")); + // Filipino : 3-letter code + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, GetTextDirection("fil")); + // Russian + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, GetTextDirection("ru")); + // Japanese that uses multiple scripts + EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, GetTextDirection("ja")); +}
\ No newline at end of file diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index 03ef0f0..fa547d3 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -20,6 +20,7 @@ #include "base/base_drag_source.h" #include "base/base_drop_target.h" #include "base/basictypes.h" +#include "base/i18n/rtl.h" #include "base/iat_patch.h" #include "base/keyboard_codes.h" #include "base/lazy_instance.h" @@ -1993,7 +1994,7 @@ LONG AutocompleteEditViewWin::ClipXCoordToVisibleText( // paragraph. bool ltr_text_in_ltr_layout = true; if ((pf2.wEffects & PFE_RTLPARA) || - l10n_util::StringContainsStrongRTLChars(GetText())) { + base::i18n::StringContainsStrongRTLChars(GetText())) { ltr_text_in_ltr_layout = false; } const int length = GetTextLength(); diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc index da54e88..b94c3b0 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc @@ -10,9 +10,9 @@ #include <string> #include "app/gfx/font.h" -#include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/basictypes.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete.h" @@ -397,7 +397,7 @@ gboolean AutocompletePopupViewGtk::HandleButtonRelease(GtkWidget* widget, gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget, GdkEventExpose* event) { - bool ltr = (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT); + bool ltr = !base::i18n::IsRTL(); const AutocompleteResult& result = model_->result(); gfx::Rect window_rect = GetWindowRect(event->window); diff --git a/chrome/browser/bookmarks/bookmark_table_model.cc b/chrome/browser/bookmarks/bookmark_table_model.cc index 4d8b01a..f7848e4 100644 --- a/chrome/browser/bookmarks/bookmark_table_model.cc +++ b/chrome/browser/bookmarks/bookmark_table_model.cc @@ -9,6 +9,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/table_model_observer.h" +#include "base/i18n/rtl.h" #include "base/i18n/time_formatting.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -314,7 +315,7 @@ std::wstring BookmarkTableModel::GetText(int row, int column_id) { // TODO(xji): Consider adding a special case if the title text is a URL, // since those should always be displayed LTR. Please refer to // http://crbug.com/6726 for more information. - l10n_util::AdjustStringForLocaleDirection(title, &title); + base::i18n::AdjustStringForLocaleDirection(title, &title); return title; } @@ -326,8 +327,8 @@ std::wstring BookmarkTableModel::GetText(int row, int column_id) { : std::wstring(); std::wstring url_text = net::FormatUrl(node->GetURL(), languages, false, UnescapeRule::SPACES, NULL, NULL, NULL); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&url_text); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&url_text); return url_text; } @@ -353,8 +354,8 @@ std::wstring BookmarkTableModel::GetText(int row, int column_id) { // Firefox, IE, Nautilus, gedit choose to format only the whole path as // LTR too. The point here is to display the path the same way as it's // displayed by other software. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&path); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&path); return path; } } diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index 2c9f6ee..5981a66 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -5,6 +5,7 @@ #include <string> #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/sys_info.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/app_modal_dialog.h" @@ -135,9 +136,9 @@ class BrowserTest : public ExtensionBrowserTest { std::wstring page_title = WindowCaptionFromPageTitle(expected_title); #if defined(OS_WIN) std::string locale = g_browser_process->GetApplicationLocale(); - if (l10n_util::GetTextDirectionForLocale(locale.c_str()) == - l10n_util::RIGHT_TO_LEFT) { - l10n_util::WrapStringWithLTRFormatting(&page_title); + if (base::i18n::GetTextDirectionForLocale(locale.c_str()) == + base::i18n::RIGHT_TO_LEFT) { + base::i18n::WrapStringWithLTRFormatting(&page_title); } return page_title; diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc index 7138288..833807a 100644 --- a/chrome/browser/browser_main_win.cc +++ b/chrome/browser/browser_main_win.cc @@ -12,6 +12,7 @@ #include "app/message_box_flags.h" #include "app/win_util.h" #include "base/command_line.h" +#include "base/i18n/rtl.h" #include "base/path_service.h" #include "base/win_util.h" #include "chrome/browser/first_run.h" @@ -132,7 +133,7 @@ void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) { dlg_strings.append(L"|"); dlg_strings.append(l10n_util::GetString(IDS_CRASH_RECOVERY_CONTENT)); dlg_strings.append(L"|"); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) dlg_strings.append(env_vars::kRtlLocale); else dlg_strings.append(env_vars::kLtrLocale); diff --git a/chrome/browser/browser_theme_provider_gtk.cc b/chrome/browser/browser_theme_provider_gtk.cc index cd8d26e..8052086 100644 --- a/chrome/browser/browser_theme_provider_gtk.cc +++ b/chrome/browser/browser_theme_provider_gtk.cc @@ -6,7 +6,7 @@ #include <gdk-pixbuf/gdk-pixbuf.h> -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "gfx/gtk_util.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -34,8 +34,7 @@ GdkPixbuf* BrowserThemeProvider::GetPixbufImpl(int id, bool rtl_enabled) const { // We loaded successfully. Cache the pixbuf. if (pixbuf) { - if ((l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) && - rtl_enabled) { + if (base::i18n::IsRTL() && rtl_enabled) { GdkPixbuf* original_pixbuf = pixbuf; pixbuf = gdk_pixbuf_flip(pixbuf, TRUE); g_object_unref(original_pixbuf); diff --git a/chrome/browser/chromeos/compact_location_bar_host.cc b/chrome/browser/chromeos/compact_location_bar_host.cc index 328549d..a412cb6 100644 --- a/chrome/browser/chromeos/compact_location_bar_host.cc +++ b/chrome/browser/chromeos/compact_location_bar_host.cc @@ -6,8 +6,8 @@ #include <algorithm> -#include "app/l10n_util.h" #include "app/slide_animation.h" +#include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" @@ -217,9 +217,8 @@ gfx::Rect CompactLocationBarHost::GetBoundsUnderTab(int index) const { view()->GetPreferredSize()); // For RTL case x() defines tab right corner. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) navbar_bounds.set_x(navbar_bounds.x() + bounds.width()); - } navbar_bounds.set_x(navbar_bounds.x() + tabstrip->x()); navbar_bounds.set_y(navbar_bounds.y() + tabstrip->y()); diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index 032443f..affcdfab 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -6,6 +6,7 @@ #include "app/l10n_util_mac.h" #include "app/resource_bundle.h" +#include "base/i18n/rtl.h" #include "base/nsimage_cache_mac.h" #include "base/stl_util-inl.h" #include "base/string_util.h" @@ -82,7 +83,7 @@ std::wstring CalculateMinString(const std::wstring& description) { } else { min_string = description.substr(0, chop_index); } - l10n_util::AdjustStringForLocaleDirection(min_string, &min_string); + base::i18n::AdjustStringForLocaleDirection(min_string, &min_string); return min_string; } diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc index 3fd2fca..7fd0179 100644 --- a/chrome/browser/cookies_tree_model.cc +++ b/chrome/browser/cookies_tree_model.cc @@ -13,6 +13,7 @@ #include "app/table_model_observer.h" #include "app/tree_node_model.h" #include "base/callback.h" +#include "base/i18n/rtl.h" #include "base/linked_ptr.h" #include "base/string_util.h" #include "chrome/browser/extensions/extensions_service.h" @@ -590,7 +591,7 @@ std::wstring CookiesTreeModel::FormExtensionNodeName( // "Great Extension!" the concatenated result would be something like // "!Great Extension :NOISNETXE", in which capital letters "NOISNETXE" // stand for the Hebrew word for "extension". - l10n_util::AdjustStringForLocaleDirection(extension_name, &extension_name); + base::i18n::AdjustStringForLocaleDirection(extension_name, &extension_name); return l10n_util::GetStringF(IDS_TASK_MANAGER_EXTENSION_PREFIX, extension_name); } diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc index 0fa68d4..46a26f4 100644 --- a/chrome/browser/dom_ui/chrome_url_data_manager.cc +++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "base/file_util.h" +#include "base/i18n/rtl.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/singleton.h" @@ -299,8 +300,7 @@ void ChromeURLDataManager::DataSource::SetFontAndTextDirection( l10n_util::GetString(web_font_size_id)); localized_strings->SetString(L"textdirection", - (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? - L"rtl" : L"ltr"); + base::i18n::IsRTL() ? L"rtl" : L"ltr"); } URLRequestJob* ChromeURLDataManager::Factory(URLRequest* request, diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc index 9a1e614..8f83db1 100644 --- a/chrome/browser/dom_ui/dom_ui.cc +++ b/chrome/browser/dom_ui/dom_ui.cc @@ -4,9 +4,10 @@ #include "chrome/browser/dom_ui/dom_ui.h" -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/json/json_writer.h" #include "base/stl_util-inl.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/browser_theme_provider.h" @@ -129,12 +130,12 @@ void DOMMessageHandler::SetURLAndTitle(DictionaryValue* dictionary, // as the title, we mark the title as LTR since URLs are always treated as // left to right strings. std::wstring title_to_set(title); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { if (using_url_as_the_title) { - l10n_util::WrapStringWithLTRFormatting(&title_to_set); + base::i18n::WrapStringWithLTRFormatting(&title_to_set); } else { bool success = - l10n_util::AdjustStringForLocaleDirection(title, &title_to_set); + base::i18n::AdjustStringForLocaleDirection(title, &title_to_set); DCHECK(success ? (title != title_to_set) : (title == title_to_set)); } } diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 7b01684..ecf009a 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -12,6 +12,7 @@ #include "base/callback.h" #include "base/command_line.h" #include "base/histogram.h" +#include "base/i18n/rtl.h" #include "base/singleton.h" #include "base/thread.h" #include "chrome/browser/browser.h" @@ -643,15 +644,15 @@ void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, // example, without LRE-PDF pair, the title "Yahoo!" will be rendered as // "!Yahoo" within the tooltip when the mouse is over the title link. std::wstring direction = kDefaultHtmlTextDirection; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { if (using_url_as_the_title) { - l10n_util::WrapStringWithLTRFormatting(&title_to_set); + base::i18n::WrapStringWithLTRFormatting(&title_to_set); } else { - if (l10n_util::StringContainsStrongRTLChars(wstring_title)) { - l10n_util::WrapStringWithRTLFormatting(&title_to_set); + if (base::i18n::StringContainsStrongRTLChars(wstring_title)) { + base::i18n::WrapStringWithRTLFormatting(&title_to_set); direction = kRTLHtmlTextDirection; } else { - l10n_util::WrapStringWithLTRFormatting(&title_to_set); + base::i18n::WrapStringWithLTRFormatting(&title_to_set); } } } diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc index 7371c8c..b69d85f 100644 --- a/chrome/browser/download/download_item_model.cc +++ b/chrome/browser/download/download_item_model.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "base/i18n/number_formatting.h" +#include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/save_package.h" @@ -38,8 +39,8 @@ std::wstring DownloadItemModel::GetStatusText() { // 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); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&simple_total); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&simple_total); TimeDelta remaining; std::wstring simple_time; diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index b839074..b8619e4 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -15,6 +15,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/file_util.h" +#include "base/i18n/rtl.h" #include "base/i18n/time_formatting.h" #include "base/path_service.h" #include "base/singleton.h" @@ -366,8 +367,8 @@ DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id) { file_value->SetString(L"file_path", download->full_path().ToWStringHack()); // Keep file names as LTR. std::wstring file_name = download->GetFileName().ToWStringHack(); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&file_name); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&file_name); file_value->SetString(L"file_name", file_name); file_value->SetString(L"url", download->url().spec()); file_value->SetBoolean(L"otr", download->is_otr()); @@ -414,7 +415,7 @@ std::wstring GetProgressStatusText(DownloadItem* download) { // Adjust both strings for the locale direction since we don't yet know which // string we'll end up using for constructing the final progress string. std::wstring amount_localized; - if (l10n_util::AdjustStringForLocaleDirection(amount, &amount_localized)) { + if (base::i18n::AdjustStringForLocaleDirection(amount, &amount_localized)) { amount.assign(amount_localized); received_size.assign(amount_localized); } @@ -423,8 +424,8 @@ std::wstring GetProgressStatusText(DownloadItem* download) { amount_units = GetByteDisplayUnits(total); std::wstring total_text = FormatBytes(total, amount_units, true); std::wstring total_text_localized; - if (l10n_util::AdjustStringForLocaleDirection(total_text, - &total_text_localized)) + if (base::i18n::AdjustStringForLocaleDirection(total_text, + &total_text_localized)) total_text.assign(total_text_localized); amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, @@ -437,8 +438,8 @@ std::wstring GetProgressStatusText(DownloadItem* download) { std::wstring speed_text = FormatSpeed(download->CurrentSpeed(), amount_units, true); std::wstring speed_text_localized; - if (l10n_util::AdjustStringForLocaleDirection(speed_text, - &speed_text_localized)) + if (base::i18n::AdjustStringForLocaleDirection(speed_text, + &speed_text_localized)) speed_text.assign(speed_text_localized); base::TimeDelta remaining; diff --git a/chrome/browser/encoding_menu_controller.cc b/chrome/browser/encoding_menu_controller.cc index cfb59cf..9667f5f 100644 --- a/chrome/browser/encoding_menu_controller.cc +++ b/chrome/browser/encoding_menu_controller.cc @@ -5,6 +5,7 @@ #include "chrome/browser/encoding_menu_controller.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser_process.h" @@ -135,8 +136,8 @@ void EncodingMenuController::GetEncodingMenuItems(Profile* profile, if (it->encoding_id) { std::wstring encoding = it->encoding_display_name; std::wstring bidi_safe_encoding; - if (l10n_util::AdjustStringForLocaleDirection(encoding, - &bidi_safe_encoding)) + if (base::i18n::AdjustStringForLocaleDirection(encoding, + &bidi_safe_encoding)) encoding.swap(bidi_safe_encoding); menuItems->push_back(EncodingMenuItem(it->encoding_id, WideToUTF16(encoding))); diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc index 70ac7fc..e6d1211 100644 --- a/chrome/browser/external_tab_container.cc +++ b/chrome/browser/external_tab_container.cc @@ -6,8 +6,8 @@ #include <string> -#include "app/l10n_util.h" #include "app/win_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/win_util.h" #include "chrome/app/chrome_dll_resource.h" @@ -539,7 +539,7 @@ bool ExternalTabContainer::HandleContextMenu(const ContextMenuParams& params) { ipc_params.page_url = params.page_url; ipc_params.frame_url = params.frame_url; - bool rtl = l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT; + bool rtl = base::i18n::IsRTL(); automation_->Send( new AutomationMsg_ForwardContextMenuToExternalHost(0, tab_handle_, external_context_menu_->GetMenuHandle(), diff --git a/chrome/browser/find_bar_controller.cc b/chrome/browser/find_bar_controller.cc index b7ddf69..b56b929 100644 --- a/chrome/browser/find_bar_controller.cc +++ b/chrome/browser/find_bar_controller.cc @@ -4,7 +4,7 @@ #include "chrome/browser/find_bar_controller.h" -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "build/build_config.h" #include "chrome/browser/find_bar.h" #include "chrome/browser/tab_contents/navigation_entry.h" @@ -154,7 +154,7 @@ gfx::Rect FindBarController::GetLocationForFindbarView( gfx::Rect view_location, const gfx::Rect& dialog_bounds, const gfx::Rect& avoid_overlapping_rect) { - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { int boundary = dialog_bounds.width() - view_location.width(); view_location.set_x(std::min(view_location.x(), boundary)); } else { @@ -168,7 +168,7 @@ gfx::Rect FindBarController::GetLocationForFindbarView( // rectangle. if (!avoid_overlapping_rect.IsEmpty() && avoid_overlapping_rect.Intersects(new_pos)) { - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { new_pos.set_x(avoid_overlapping_rect.x() + avoid_overlapping_rect.width() + (2 * kMinFindWndDistanceFromSelection)); diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc index 8c6e13a..3e09a4a 100644 --- a/chrome/browser/gtk/bookmark_bubble_gtk.cc +++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc @@ -9,6 +9,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/basictypes.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/message_loop.h" #include "chrome/browser/bookmarks/bookmark_editor.h" @@ -221,7 +222,7 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* toplevel_window, gtk_container_set_focus_child(GTK_CONTAINER(content), table); InfoBubbleGtk::ArrowLocationGtk arrow_location = - (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) ? + !base::i18n::IsRTL() ? InfoBubbleGtk::ARROW_LOCATION_TOP_LEFT : InfoBubbleGtk::ARROW_LOCATION_TOP_RIGHT; bubble_ = InfoBubbleGtk::Show(toplevel_window_, diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index a3a5e5d..997d20d 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -13,6 +13,7 @@ #include "app/menus/accelerator_gtk.h" #include "app/resource_bundle.h" #include "base/base_paths.h" +#include "base/i18n/rtl.h" #include "base/keyboard_codes_posix.h" #include "base/logging.h" #include "base/path_service.h" @@ -449,7 +450,7 @@ gfx::Rect BrowserToolbarGtk::GetLocationStackBounds() const { GtkWidget* left; GtkWidget* right; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { left = go_->widget(); right = star_->widget(); } else { diff --git a/chrome/browser/gtk/content_blocked_bubble_gtk.cc b/chrome/browser/gtk/content_blocked_bubble_gtk.cc index 956e014..5f083c21 100644 --- a/chrome/browser/gtk/content_blocked_bubble_gtk.cc +++ b/chrome/browser/gtk/content_blocked_bubble_gtk.cc @@ -5,6 +5,7 @@ #include "chrome/browser/gtk/content_blocked_bubble_gtk.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "chrome/browser/blocked_popup_container.h" #include "chrome/browser/content_setting_bubble_model.h" #include "chrome/browser/gtk/gtk_chrome_link_button.h" @@ -165,7 +166,7 @@ void ContentSettingBubbleGtk::BuildBubble() { gtk_box_pack_start(GTK_BOX(bubble_content), bottom_box, FALSE, FALSE, 0); InfoBubbleGtk::ArrowLocationGtk arrow_location = - (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) ? + !base::i18n::IsRTL() ? InfoBubbleGtk::ARROW_LOCATION_TOP_RIGHT : InfoBubbleGtk::ARROW_LOCATION_TOP_LEFT; info_bubble_ = InfoBubbleGtk::Show( diff --git a/chrome/browser/gtk/edit_search_engine_dialog.cc b/chrome/browser/gtk/edit_search_engine_dialog.cc index f639f0c..1978862 100644 --- a/chrome/browser/gtk/edit_search_engine_dialog.cc +++ b/chrome/browser/gtk/edit_search_engine_dialog.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/i18n/rtl.h" #include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" @@ -182,7 +183,7 @@ void EditSearchEngineDialog::Init(GtkWindow* parent_window, Profile* profile) { // is displayed correctly when rendered in an RTL context. std::string description = l10n_util::GetStringUTF8(IDS_SEARCH_ENGINES_EDITOR_URL_DESCRIPTION_LABEL); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { const std::string reversed_percent("s%"); std::wstring::size_type percent_index = description.find("%s", static_cast<std::string::size_type>(0)); diff --git a/chrome/browser/gtk/extension_installed_bubble_gtk.cc b/chrome/browser/gtk/extension_installed_bubble_gtk.cc index 8cf8bb2..2ac515f 100644 --- a/chrome/browser/gtk/extension_installed_bubble_gtk.cc +++ b/chrome/browser/gtk/extension_installed_bubble_gtk.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/i18n/rtl.h" #include "base/message_loop.h" #include "chrome/browser/browser.h" #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h" @@ -202,7 +203,7 @@ void ExtensionInstalledBubbleGtk::ShowInternal() { FALSE, FALSE, 0); InfoBubbleGtk::ArrowLocationGtk arrow_location = - (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) ? + !base::i18n::IsRTL() ? InfoBubbleGtk::ARROW_LOCATION_TOP_RIGHT : InfoBubbleGtk::ARROW_LOCATION_TOP_LEFT; info_bubble_ = InfoBubbleGtk::Show(browser_window->window(), diff --git a/chrome/browser/gtk/extension_popup_gtk.cc b/chrome/browser/gtk/extension_popup_gtk.cc index 2d25d96..878e6db 100644 --- a/chrome/browser/gtk/extension_popup_gtk.cc +++ b/chrome/browser/gtk/extension_popup_gtk.cc @@ -6,7 +6,7 @@ #include <gtk/gtk.h> -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/profile.h" @@ -74,7 +74,7 @@ void ExtensionPopupGtk::ShowPopup() { // want to put the arrow at the upper-right corner of the bubble to match the // page and app menus. InfoBubbleGtk::ArrowLocationGtk arrow_location = - (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) ? + !base::i18n::IsRTL() ? InfoBubbleGtk::ARROW_LOCATION_TOP_RIGHT : InfoBubbleGtk::ARROW_LOCATION_TOP_LEFT; bubble_ = InfoBubbleGtk::Show(browser_->window()->GetNativeHandle(), diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index 965dcf9..39b6511 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "chrome/browser/browser.h" #include "chrome/browser/find_bar_controller.h" @@ -73,7 +74,7 @@ std::vector<GdkPoint> MakeFramePolygonPoints(int width, using gtk_util::MakeBidiGdkPoint; std::vector<GdkPoint> points; - bool ltr = l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT; + bool ltr = !base::i18n::IsRTL(); // If we have a stroke, we have to offset some of our points by 1 pixel. // We have to inset by 1 pixel when we draw horizontal lines that are on the // bottom or when we draw vertical lines that are closer to the end (end is @@ -404,7 +405,7 @@ void FindBarGtk::AudibleAlert() { } gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) { - bool ltr = l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT; + bool ltr = !base::i18n::IsRTL(); // 15 is the size of the scrollbar, copied from ScrollbarThemeChromium. // The height is not used. // At very low browser widths we can wind up with a negative |dialog_bounds| @@ -838,7 +839,7 @@ gboolean FindBarGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e, GtkAllocation border_allocation = bar->border_bin_->allocation; // Blit the left part of the background image once on the left. - bool rtl = l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT; + bool rtl = base::i18n::IsRTL(); CairoCachedSurface* background_left = bar->theme_provider_->GetSurfaceNamed( rtl ? IDR_FIND_BOX_BACKGROUND_LEFT_RTL : IDR_FIND_BOX_BACKGROUND_LEFT, widget); diff --git a/chrome/browser/gtk/first_run_bubble.cc b/chrome/browser/gtk/first_run_bubble.cc index b2989d6..d70c94c 100644 --- a/chrome/browser/gtk/first_run_bubble.cc +++ b/chrome/browser/gtk/first_run_bubble.cc @@ -8,6 +8,7 @@ #include "app/gtk_util.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" #include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/options_window.h" @@ -148,7 +149,7 @@ FirstRunBubble::FirstRunBubble(Profile* profile, gtk_widget_grab_focus(keep_button); InfoBubbleGtk::ArrowLocationGtk arrow_location = - (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) ? + !base::i18n::IsRTL() ? InfoBubbleGtk::ARROW_LOCATION_TOP_LEFT : InfoBubbleGtk::ARROW_LOCATION_TOP_RIGHT; bubble_ = InfoBubbleGtk::Show(parent_, diff --git a/chrome/browser/gtk/go_button_gtk.cc b/chrome/browser/gtk/go_button_gtk.cc index eba8f82..2df9932 100644 --- a/chrome/browser/gtk/go_button_gtk.cc +++ b/chrome/browser/gtk/go_button_gtk.cc @@ -5,6 +5,7 @@ #include "chrome/browser/gtk/go_button_gtk.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/message_loop.h" #include "chrome/app/chrome_dll_resource.h" @@ -175,8 +176,8 @@ gboolean GoButtonGtk::OnQueryTooltip(GtkTooltip* tooltip) { std::string text; if (visible_mode_ == MODE_GO) { std::wstring current_text_wstr(location_bar_->location_entry()->GetText()); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(¤t_text_wstr); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(¤t_text_wstr); string16 current_text = WideToUTF16Hack( l10n_util::TruncateString(current_text_wstr, kMaxTooltipTextLength)); diff --git a/chrome/browser/gtk/gtk_util.cc b/chrome/browser/gtk/gtk_util.cc index ea46705..305a411 100644 --- a/chrome/browser/gtk/gtk_util.cc +++ b/chrome/browser/gtk/gtk_util.cc @@ -11,9 +11,9 @@ #include <map> #include "app/gtk_util.h" -#include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/x11_util.h" +#include "base/i18n/rtl.h" #include "base/linux_util.h" #include "base/logging.h" #include "chrome/browser/browser_list.h" @@ -504,16 +504,14 @@ void SetButtonTriggersNavigation(GtkWidget* button) { } int MirroredLeftPointForRect(GtkWidget* widget, const gfx::Rect& bounds) { - if (l10n_util::GetTextDirection() != l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) return bounds.x(); - } return widget->allocation.width - bounds.x() - bounds.width(); } int MirroredXCoordinate(GtkWidget* widget, int x) { - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) return widget->allocation.width - x; - } return x; } diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 815bb2f..dabdf18 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -10,6 +10,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/basictypes.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/string_util.h" #include "chrome/app/chrome_dll_resource.h" @@ -120,7 +121,7 @@ std::wstring CalculateMinString(const std::wstring& description) { } else { min_string = description.substr(0, chop_index); } - l10n_util::AdjustStringForLocaleDirection(min_string, &min_string); + base::i18n::AdjustStringForLocaleDirection(min_string, &min_string); return min_string; } @@ -841,7 +842,7 @@ void LocationBarViewGtk::ShowFirstRunBubbleInternal(bool use_OEM_bubble) { // of star button, so shift x and y co-ordinates. int y_offset = widget()->allocation.height + kFirstRunBubbleTopMargin; int x_offset = 0; - if (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) + if (!base::i18n::IsRTL()) x_offset = kFirstRunBubbleLeftMargin; else x_offset = widget()->allocation.width - kFirstRunBubbleLeftMargin; diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index acc325c..dd6945d 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -9,6 +9,7 @@ #include "app/l10n_util.h" #include "app/menus/accelerator_gtk.h" #include "app/menus/menu_model.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/stl_util-inl.h" @@ -459,7 +460,7 @@ void MenuGtk::WidgetMenuPositionFunc(GtkMenu* menu, bool start_align = !!g_object_get_data(G_OBJECT(widget), "left-align-popup"); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) start_align = !start_align; if (!start_align) diff --git a/chrome/browser/gtk/nine_box.cc b/chrome/browser/gtk/nine_box.cc index a0f8f40..973d3c5 100644 --- a/chrome/browser/gtk/nine_box.cc +++ b/chrome/browser/gtk/nine_box.cc @@ -4,10 +4,10 @@ #include "chrome/browser/gtk/nine_box.h" -#include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/theme_provider.h" #include "base/basictypes.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "gfx/gtk_util.h" #include "gfx/point.h" @@ -132,7 +132,7 @@ void NineBox::RenderToWidgetWithOpacity(GtkWidget* dst, double opacity) const { cairo_translate(cr, dst->allocation.x, dst->allocation.y); } - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { cairo_translate(cr, dst_width, 0.0f); cairo_scale(cr, -1.0f, 1.0f); } @@ -224,7 +224,7 @@ void NineBox::ContourWidget(GtkWidget* widget) const { cairo_destroy(cr); // Mask the widget's window's shape. - if (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) { + if (!base::i18n::IsRTL()) { gtk_widget_shape_combine_mask(widget, mask, 0, 0); } else { GdkBitmap* flipped_mask = gdk_pixmap_new(NULL, width, height, 1); diff --git a/chrome/browser/gtk/rounded_window.cc b/chrome/browser/gtk/rounded_window.cc index 06cae21..540a465 100644 --- a/chrome/browser/gtk/rounded_window.cc +++ b/chrome/browser/gtk/rounded_window.cc @@ -7,7 +7,7 @@ #include <gtk/gtk.h> #include <math.h> -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "chrome/browser/gtk/gtk_util.h" namespace gtk_util { @@ -60,7 +60,7 @@ std::vector<GdkPoint> MakeFramePolygonPoints(RoundedWindowData* data, std::vector<GdkPoint> points; - bool ltr = l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT; + bool ltr = !base::i18n::IsRTL(); // If we have a stroke, we have to offset some of our points by 1 pixel. // We have to inset by 1 pixel when we draw horizontal lines that are on the // bottom or when we draw vertical lines that are closer to the end (end is diff --git a/chrome/browser/gtk/status_bubble_gtk.cc b/chrome/browser/gtk/status_bubble_gtk.cc index 076cff5..fa7742b3 100644 --- a/chrome/browser/gtk/status_bubble_gtk.cc +++ b/chrome/browser/gtk/status_bubble_gtk.cc @@ -8,8 +8,8 @@ #include <algorithm> -#include "app/l10n_util.h" #include "app/text_elider.h" +#include "base/i18n/rtl.h" #include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "chrome/browser/gtk/gtk_theme_provider.h" @@ -157,7 +157,7 @@ void StatusBubbleGtk::MouseMoved( if (!toplevel || !GTK_WIDGET_REALIZED(toplevel)) return; - bool ltr = (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT); + bool ltr = !base::i18n::IsRTL(); GtkRequisition requisition; gtk_widget_size_request(container_.get(), &requisition); @@ -219,7 +219,7 @@ void StatusBubbleGtk::Observe(NotificationType type, } void StatusBubbleGtk::InitWidgets() { - bool ltr = (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT); + bool ltr = !base::i18n::IsRTL(); label_ = gtk_label_new(NULL); @@ -275,7 +275,7 @@ void StatusBubbleGtk::SetFlipHorizontally(bool flip_horizontally) { flip_horizontally_ = flip_horizontally; - bool ltr = (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT); + bool ltr = !base::i18n::IsRTL(); bool on_left = (ltr && !flip_horizontally) || (!ltr && flip_horizontally); gtk_alignment_set_padding(GTK_ALIGNMENT(padding_), diff --git a/chrome/browser/gtk/tab_contents_container_gtk.cc b/chrome/browser/gtk/tab_contents_container_gtk.cc index 3760f86..af83a0e 100644 --- a/chrome/browser/gtk/tab_contents_container_gtk.cc +++ b/chrome/browser/gtk/tab_contents_container_gtk.cc @@ -4,7 +4,7 @@ #include "chrome/browser/gtk/tab_contents_container_gtk.h" -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "chrome/browser/gtk/gtk_expanded_container.h" #include "chrome/browser/gtk/gtk_floating_container.h" #include "chrome/browser/gtk/status_bubble_gtk.h" @@ -167,7 +167,7 @@ void TabContentsContainerGtk::OnSetFloatingPosition( GtkRequisition requisition; gtk_widget_size_request(status->widget(), &requisition); - bool ltr = (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT); + bool ltr = !base::i18n::IsRTL(); GValue value = { 0, }; g_value_init(&value, G_TYPE_INT); diff --git a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc index c11e3f4..2093fda 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc +++ b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc @@ -9,8 +9,8 @@ #include <algorithm> #include "app/gfx/canvas_paint.h" -#include "app/l10n_util.h" #include "app/x11_util.h" +#include "base/i18n/rtl.h" #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/tabs/tab_renderer_gtk.h" @@ -160,7 +160,7 @@ void DraggedTabGtk::Layout() { renderer_->SetBounds(gfx::Rect(0, 0, prefsize.width(), prefsize.height())); } else { int left = 0; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) left = GetPreferredSize().width() - attached_tab_size_.width(); // The renderer_'s width should be attached_tab_size_.width() in both LTR diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index 11e4521..e7e2ac6 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -8,9 +8,9 @@ #include "app/gfx/canvas_paint.h" #include "app/gtk_dnd_util.h" -#include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/slide_animation.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/browser_theme_provider.h" @@ -1239,7 +1239,7 @@ int TabStripGtk::GetMiniTabCount() const { } int TabStripGtk::GetAvailableWidthForTabs(TabGtk* last_tab) const { - if (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) + if (!base::i18n::IsRTL()) return last_tab->x() - bounds_.x() + last_tab->width(); else return bounds_.width() - last_tab->x(); diff --git a/chrome/browser/language_combobox_model.cc b/chrome/browser/language_combobox_model.cc index 95d9598..9d256e7 100644 --- a/chrome/browser/language_combobox_model.cc +++ b/chrome/browser/language_combobox_model.cc @@ -5,6 +5,7 @@ #include "chrome/browser/language_combobox_model.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/metrics/user_metrics.h" @@ -86,16 +87,16 @@ std::wstring LanguageList::GetLanguageNameAt(int index) const { // parentheses or languages appearing in the wrong order. std::wstring locale_name_localized; std::wstring locale_name; - if (l10n_util::AdjustStringForLocaleDirection(locale_names_[index], - &locale_name_localized)) + if (base::i18n::AdjustStringForLocaleDirection(locale_names_[index], + &locale_name_localized)) locale_name.assign(locale_name_localized); else locale_name.assign(locale_names_[index]); std::wstring native_name_localized; std::wstring native_name; - if (l10n_util::AdjustStringForLocaleDirection(it->second.native_name, - &native_name_localized)) + if (base::i18n::AdjustStringForLocaleDirection(it->second.native_name, + &native_name_localized)) native_name.assign(native_name_localized); else native_name.assign(it->second.native_name); @@ -106,7 +107,7 @@ std::wstring LanguageList::GetLanguageNameAt(int index) const { std::wstring formatted_item; SStringPrintf(&formatted_item, L"%ls - %ls", locale_name.c_str(), native_name.c_str()); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) // Somehow combo box (even with LAYOUTRTL flag) doesn't get this // right so we add RTL BDO (U+202E) to set the direction // explicitly. diff --git a/chrome/browser/possible_url_model.cc b/chrome/browser/possible_url_model.cc index a8bc57b..2f4fdc8 100644 --- a/chrome/browser/possible_url_model.cc +++ b/chrome/browser/possible_url_model.cc @@ -8,6 +8,7 @@ #include "app/resource_bundle.h" #include "app/table_model_observer.h" #include "base/callback.h" +#include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" #include "chrome/browser/cancelable_request.h" #include "chrome/browser/favicon_service.h" @@ -113,7 +114,7 @@ std::wstring PossibleURLModel::GetText(int row, int col_id) { // since those should always have LTR directionality. Please refer to // http://crbug.com/6726 for more information. std::wstring localized_title; - if (l10n_util::AdjustStringForLocaleDirection(title, &localized_title)) + if (base::i18n::AdjustStringForLocaleDirection(title, &localized_title)) return localized_title; return title; } @@ -121,11 +122,11 @@ 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. const string16& url = results_[row].display_url.display_url(); - if (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) + if (!base::i18n::IsRTL()) return UTF16ToWideHack(url); // Force URL to be LTR. std::wstring localized_url = UTF16ToWideHack(url); - l10n_util::WrapStringWithLTRFormatting(&localized_url); + base::i18n::WrapStringWithLTRFormatting(&localized_url); return localized_url; } diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index f4e297c..ed12fda 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -8,8 +8,8 @@ #include <utility> #include <vector> -#include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/i18n/rtl.h" #include "base/json/json_reader.h" #include "base/stats_counters.h" #include "base/string_util.h" @@ -1297,13 +1297,13 @@ void RenderViewHost::OnMsgSetTooltipText( std::wstring wrapped_tooltip_text = tooltip_text; if (!tooltip_text.empty()) { if (text_direction_hint == WebKit::WebTextDirectionLeftToRight && - l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + base::i18n::IsRTL()) { // Force the tooltip to have LTR directionality. - l10n_util::WrapStringWithLTRFormatting(&wrapped_tooltip_text); + base::i18n::WrapStringWithLTRFormatting(&wrapped_tooltip_text); } else if (text_direction_hint == WebKit::WebTextDirectionRightToLeft && - l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) { + !base::i18n::IsRTL()) { // Force the tooltip to have RTL directionality. - l10n_util::WrapStringWithRTLFormatting(&wrapped_tooltip_text); + base::i18n::WrapStringWithRTLFormatting(&wrapped_tooltip_text); } } if (view()) diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc index 3996a8a..84e190f 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc @@ -10,6 +10,7 @@ #include "app/resource_bundle.h" #include "base/command_line.h" #include "base/histogram.h" +#include "base/i18n/rtl.h" #include "base/process_util.h" #include "base/thread.h" #include "base/win_util.h" @@ -558,7 +559,7 @@ void RenderWidgetHostViewWin::UpdateCursorIfOverSelf() { BOOL result = ::ScreenToClient(m_hWnd, &pt); DCHECK(result); if (render_widget_host_->GetRootWindowResizerRect().Contains(pt.x, pt.y)) { - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) SetCursor(kCursorResizeLeft); else SetCursor(kCursorResizeRight); @@ -651,8 +652,7 @@ void RenderWidgetHostViewWin::DrawResizeCorner(const gfx::Rect& paint_rect, canvas.getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0); int x = resize_corner_rect.x() + resize_corner_rect.width() - bitmap->width(); - bool rtl_dir = (l10n_util::GetTextDirection() == - l10n_util::RIGHT_TO_LEFT); + bool rtl_dir = base::i18n::IsRTL(); if (rtl_dir) { canvas.TranslateInt(bitmap->width(), 0); canvas.ScaleInt(-1, 1); @@ -1235,7 +1235,7 @@ LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, render_widget_host_->GetRootWindowResizerRect(). Contains(GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam))) { WPARAM wparam = HTBOTTOMRIGHT; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) wparam = HTBOTTOMLEFT; HWND root_hwnd = ::GetAncestor(m_hWnd, GA_ROOT); if (SendMessage(root_hwnd, WM_NCLBUTTONDOWN, wparam, lparam) == 0) diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index d37c6ce..f5ef76e 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -11,6 +11,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/histogram.h" +#include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/chrome_thread.h" @@ -238,9 +239,7 @@ void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_PROCEED_BUTTON)); strings->SetString(L"back_button", l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); - strings->SetString(L"textdirection", - (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? - L"rtl" : L"ltr"); + strings->SetString(L"textdirection", base::i18n::IsRTL() ? L"rtl" : L"ltr"); } void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( @@ -280,9 +279,7 @@ void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_PROCEED_BUTTON)); strings->SetString(L"back_button", l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); - strings->SetString(L"textdirection", - (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? - L"rtl" : L"ltr"); + strings->SetString(L"textdirection", base::i18n::IsRTL() ? L"rtl" : L"ltr"); } void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( @@ -303,9 +300,7 @@ void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON)); strings->SetString(L"report_error", l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR)); - strings->SetString(L"textdirection", - (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? - L"rtl" : L"ltr"); + strings->SetString(L"textdirection", base::i18n::IsRTL() ? L"rtl" : L"ltr"); } void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index 09201d6..fe83561 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "base/i18n/icu_string_conversions.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" @@ -546,8 +547,8 @@ bool TemplateURL::SupportsReplacement(const TemplateURL* turl) { std::wstring TemplateURL::AdjustedShortNameForLocaleDirection() const { std::wstring bidi_safe_short_name; - if (l10n_util::AdjustStringForLocaleDirection(short_name_, - &bidi_safe_short_name)) + if (base::i18n::AdjustStringForLocaleDirection(short_name_, + &bidi_safe_short_name)) return bidi_safe_short_name; return short_name_; } diff --git a/chrome/browser/search_engines/template_url_table_model.cc b/chrome/browser/search_engines/template_url_table_model.cc index 84ce653..961506e 100644 --- a/chrome/browser/search_engines/template_url_table_model.cc +++ b/chrome/browser/search_engines/template_url_table_model.cc @@ -10,6 +10,7 @@ #include "app/resource_bundle.h" #include "app/table_model_observer.h" #include "base/callback.h" +#include "base/i18n/rtl.h" #include "base/stl_util-inl.h" #include "base/utf_string_conversions.h" #include "chrome/browser/favicon_service.h" @@ -180,8 +181,8 @@ std::wstring TemplateURLTableModel::GetText(int row, int col_id) { // TODO(xji): Consider adding a special case if the short name is a URL, // since those should always be displayed LTR. Please refer to // http://crbug.com/6726 for more information. - l10n_util::AdjustStringForLocaleDirection(url_short_name, - &url_short_name); + base::i18n::AdjustStringForLocaleDirection(url_short_name, + &url_short_name); return (template_url_model_->GetDefaultSearchProvider() == &url) ? l10n_util::GetStringF(IDS_SEARCH_ENGINES_EDITOR_DEFAULT_ENGINE, url_short_name) : url_short_name; @@ -190,9 +191,9 @@ std::wstring TemplateURLTableModel::GetText(int row, int col_id) { case IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN: { const std::wstring& keyword = url.keyword(); // Keyword should be domain name. Force it to have LTR directionality. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { std::wstring localized_keyword = keyword; - l10n_util::WrapStringWithLTRFormatting(&localized_keyword); + base::i18n::WrapStringWithLTRFormatting(&localized_keyword); return localized_keyword; } return keyword; diff --git a/chrome/browser/ssl/ssl_blocking_page.cc b/chrome/browser/ssl/ssl_blocking_page.cc index 0746d61..904c083 100644 --- a/chrome/browser/ssl/ssl_blocking_page.cc +++ b/chrome/browser/ssl/ssl_blocking_page.cc @@ -7,6 +7,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/histogram.h" +#include "base/i18n/rtl.h" #include "base/string_piece.h" #include "base/values.h" #include "chrome/browser/browser.h" @@ -78,9 +79,7 @@ std::string SSLBlockingPage::GetHTMLContents() { strings.SetString(L"exit", l10n_util::GetString(IDS_SSL_BLOCKING_PAGE_EXIT)); - strings.SetString(L"textdirection", - (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? - L"rtl" : L"ltr"); + strings.SetString(L"textdirection", base::i18n::IsRTL() ? L"rtl" : L"ltr"); static const base::StringPiece html( ResourceBundle::GetSharedInstance().GetRawDataResource( diff --git a/chrome/browser/ssl/ssl_policy.cc b/chrome/browser/ssl/ssl_policy.cc index 0612558..2f21e5d 100644 --- a/chrome/browser/ssl/ssl_policy.cc +++ b/chrome/browser/ssl/ssl_policy.cc @@ -8,6 +8,7 @@ #include "app/resource_bundle.h" #include "base/base_switches.h" #include "base/command_line.h" +#include "base/i18n/rtl.h" #include "base/singleton.h" #include "base/string_piece.h" #include "base/string_util.h" @@ -218,9 +219,7 @@ void SSLPolicy::ShowErrorPage(SSLCertErrorHandler* handler) { strings.SetString(L"back", l10n_util::GetString(IDS_SSL_ERROR_PAGE_BACK)); - strings.SetString(L"textdirection", - (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? - L"rtl" : L"ltr"); + strings.SetString(L"textdirection", base::i18n::IsRTL() ? L"rtl" : L"ltr"); static const base::StringPiece html( ResourceBundle::GetSharedInstance().GetRawDataResource( diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 384cdd1..c8d3e95 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -9,6 +9,7 @@ #include "app/text_elider.h" #include "base/auto_reset.h" #include "base/file_version_info.h" +#include "base/i18n/rtl.h" #include "base/process_util.h" #include "base/string16.h" #include "base/string_util.h" @@ -2855,8 +2856,8 @@ std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url, std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0, profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); // Force URL to have LTR directionality. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&base_address); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&base_address); return l10n_util::GetStringF( is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE, diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index 6453663..533a696 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -8,6 +8,7 @@ #include "app/resource_bundle.h" #include "base/compiler_specific.h" #include "base/i18n/number_formatting.h" +#include "base/i18n/rtl.h" #include "base/process_util.h" #include "base/stats_table.h" #include "base/string_util.h" @@ -122,8 +123,8 @@ std::wstring TaskManagerModel::GetResourceNetworkUsage(int index) const { std::wstring net_byte = FormatSpeed(net_usage, GetByteDisplayUnits(net_usage), true); // Force number string to have LTR directionality. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&net_byte); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&net_byte); return net_byte; } @@ -450,7 +451,7 @@ std::wstring TaskManagerModel::GetMemCellText(int64 number) const { std::wstring str = UTF16ToWide(base::FormatNumber(number / 1024)); // Adjust number string if necessary. - l10n_util::AdjustStringForLocaleDirection(str, &str); + base::i18n::AdjustStringForLocaleDirection(str, &str); return l10n_util::GetStringF(IDS_TASK_MANAGER_MEM_CELL_TEXT, str); #else // System expectation is to show "100 KB", "200 MB", etc. diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc index f1ffefd..8d43db0 100644 --- a/chrome/browser/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager_resource_providers.cc @@ -10,6 +10,7 @@ #include "app/resource_bundle.h" #include "base/basictypes.h" #include "base/file_version_info.h" +#include "base/i18n/rtl.h" #include "base/process_util.h" #include "base/stl_util-inl.h" #include "base/string_util.h" @@ -73,8 +74,8 @@ std::wstring TaskManagerTabContentsResource::GetTitle() const { if (tab_title.empty()) { tab_title = UTF8ToWide(tab_contents_->GetURL().spec()); // Force URL to be LTR. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&tab_title); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&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 @@ -85,7 +86,7 @@ std::wstring TaskManagerTabContentsResource::GetTitle() const { // as LTR format, the concatenated result will be "!Yahoo! Mail: The best // web-based Email :BAT", in which the capital letters "BAT" stands for // the Hebrew word for "tab". - l10n_util::AdjustStringForLocaleDirection(tab_title, &tab_title); + base::i18n::AdjustStringForLocaleDirection(tab_title, &tab_title); } return l10n_util::GetStringF(IDS_TASK_MANAGER_TAB_PREFIX, tab_title); @@ -532,7 +533,7 @@ TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( // "Great Extension!" the concatenated result would be something like // "!Great Extension :NOISNETXE", in which capital letters "NOISNETXE" // stand for the Hebrew word for "extension". - l10n_util::AdjustStringForLocaleDirection(extension_name, &extension_name); + base::i18n::AdjustStringForLocaleDirection(extension_name, &extension_name); title_ = l10n_util::GetStringF(IDS_TASK_MANAGER_EXTENSION_PREFIX, extension_name); } diff --git a/chrome/browser/views/about_chrome_view.cc b/chrome/browser/views/about_chrome_view.cc index 443a86f..228e8e5 100644 --- a/chrome/browser/views/about_chrome_view.cc +++ b/chrome/browser/views/about_chrome_view.cc @@ -10,6 +10,7 @@ #include "app/resource_bundle.h" #include "base/callback.h" #include "base/file_version_info.h" +#include "base/i18n/rtl.h" #include "base/i18n/word_iterator.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_list.h" @@ -127,8 +128,7 @@ AboutChromeView::~AboutChromeView() { } void AboutChromeView::Init() { - text_direction_is_rtl_ = - l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT; + text_direction_is_rtl_ = base::i18n::IsRTL(); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); scoped_ptr<FileVersionInfo> version_info( @@ -871,9 +871,9 @@ void AboutChromeView::UpdateStatus(GoogleUpdateUpgradeResult result, l10n_util::GetStringF(IDS_UPGRADE_ALREADY_UP_TO_DATE, l10n_util::GetString(IDS_PRODUCT_NAME), current_version_); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { update_label_text.push_back( - static_cast<wchar_t>(l10n_util::kLeftToRightMark)); + static_cast<wchar_t>(base::i18n::kLeftToRightMark)); } update_label_.SetText(update_label_text); show_success_indicator = true; diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 77c9ae3..5a2bdd8 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -10,6 +10,7 @@ #include "app/resource_bundle.h" #include "app/theme_provider.h" #include "base/compiler_specific.h" +#include "base/i18n/rtl.h" #include "chrome/browser/autocomplete/autocomplete_edit_view.h" #include "chrome/browser/autocomplete/autocomplete_popup_model.h" #include "chrome/browser/bubble_positioner.h" @@ -484,7 +485,7 @@ int AutocompleteResultView::DrawString( const bool force_rtl_directionality = !(classifications[i].style & ACMatchClassification::URL) && (run_direction == UBIDI_RTL) && - (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT); + !base::i18n::IsRTL(); if (text_start < text_end) { x += DrawStringFragment(canvas, diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index 5954725..f1fb348 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -14,6 +14,7 @@ #include "app/os_exchange_data.h" #include "app/resource_bundle.h" #include "app/text_elider.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_utils.h" @@ -140,7 +141,7 @@ static std::wstring CreateToolTipForURLAndTitle(const gfx::Point& screen_loc, // First the title. if (!title.empty()) { std::wstring localized_title; - if (l10n_util::AdjustStringForLocaleDirection(title, &localized_title)) + if (base::i18n::AdjustStringForLocaleDirection(title, &localized_title)) result.append(gfx::ElideText(localized_title, tt_font, max_width)); else result.append(gfx::ElideText(title, tt_font, max_width)); @@ -158,8 +159,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)); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&elided_url); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&elided_url); result.append(elided_url); } return result; diff --git a/chrome/browser/views/bookmark_context_menu.cc b/chrome/browser/views/bookmark_context_menu.cc index fee7865..aef8070 100644 --- a/chrome/browser/views/bookmark_context_menu.cc +++ b/chrome/browser/views/bookmark_context_menu.cc @@ -5,6 +5,7 @@ #include "chrome/browser/views/bookmark_context_menu.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "chrome/browser/profile.h" #include "grit/generated_resources.h" #include "views/controls/menu/menu_item_view.h" @@ -35,8 +36,7 @@ BookmarkContextMenu::~BookmarkContextMenu() { void BookmarkContextMenu::RunMenuAt(const gfx::Point& point) { // width/height don't matter here. - views::MenuItemView::AnchorPosition anchor = - (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? + views::MenuItemView::AnchorPosition anchor = base::i18n::IsRTL() ? views::MenuItemView::TOPRIGHT : views::MenuItemView::TOPLEFT; menu_->RunMenuAt(parent_window_, NULL, gfx::Rect(point.x(), point.y(), 0, 0), anchor, true); diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc index 66e6ca7..add4203 100644 --- a/chrome/browser/views/download_item_view.cc +++ b/chrome/browser/views/download_item_view.cc @@ -13,6 +13,7 @@ #include "app/theme_provider.h" #include "base/callback.h" #include "base/file_path.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "chrome/browser/browser_process.h" @@ -90,7 +91,7 @@ class DownloadShelfContextMenuWin : public DownloadShelfContextMenu { // The menu's alignment is determined based on the UI layout. views::Menu2::Alignment alignment; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) alignment = views::Menu2::ALIGN_TOPRIGHT; else alignment = views::Menu2::ALIGN_TOPLEFT; @@ -285,8 +286,8 @@ DownloadItemView::DownloadItemView(DownloadItem* download, } else { ElideString(rootname, kFileNameMaxLength - extension.length(), &rootname); std::wstring filename = rootname + L"." + extension; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(&filename); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(&filename); dangerous_download_label_ = new views::Label( l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, filename)); } diff --git a/chrome/browser/views/edit_search_engine_dialog.cc b/chrome/browser/views/edit_search_engine_dialog.cc index 1a58f3f..c32eaba 100644 --- a/chrome/browser/views/edit_search_engine_dialog.cc +++ b/chrome/browser/views/edit_search_engine_dialog.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "chrome/browser/search_engines/edit_search_engine_controller.h" #include "chrome/browser/search_engines/template_url.h" @@ -203,7 +204,7 @@ void EditSearchEngineDialog::Init() { layout->StartRowWithPadding(0, 2, 0, unrelated_y); std::wstring description = l10n_util::GetString(IDS_SEARCH_ENGINES_EDITOR_URL_DESCRIPTION_LABEL); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { const std::wstring reversed_percent(L"s%"); std::wstring::size_type percent_index = description.find(L"%s", static_cast<std::wstring::size_type>(0)); diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 3312812..1970be1 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -14,6 +14,7 @@ #include "app/os_exchange_data.h" #include "app/resource_bundle.h" #include "base/command_line.h" +#include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "base/time.h" #include "build/build_config.h" @@ -211,7 +212,7 @@ class ResizeCorner : public views::View { SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_TEXTAREA_RESIZER); bitmap->buildMipMap(false); - bool rtl_dir = (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT); + bool rtl_dir = base::i18n::IsRTL(); if (rtl_dir) { canvas->TranslateInt(width(), 0); canvas->ScaleInt(-1, 1); @@ -930,7 +931,7 @@ gfx::Rect BrowserView::GetRootWindowResizerRect() const { gfx::Rect client_rect = contents_split_->bounds(); gfx::Size resize_corner_size = ResizeCorner::GetSize(); int x = client_rect.width() - resize_corner_size.width(); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) x = 0; return gfx::Rect(x, client_rect.height() - resize_corner_size.height(), resize_corner_size.width(), resize_corner_size.height()); @@ -1548,7 +1549,7 @@ int BrowserView::NonClientHitTest(const gfx::Point& point) { gfx::Rect resize_corner_rect(client_rect.right - resize_corner_size.width(), client_rect.bottom - resize_corner_size.height(), resize_corner_size.width(), resize_corner_size.height()); - bool rtl_dir = (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT); + bool rtl_dir = base::i18n::IsRTL(); if (rtl_dir) resize_corner_rect.set_x(0); if (resize_corner_rect.Contains(point)) { diff --git a/chrome/browser/views/go_button.cc b/chrome/browser/views/go_button.cc index 29451c3..05fc1c4 100644 --- a/chrome/browser/views/go_button.cc +++ b/chrome/browser/views/go_button.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "base/compiler_specific.h" +#include "base/i18n/rtl.h" #include "base/message_loop.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser.h" @@ -104,8 +105,8 @@ bool GoButton::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { // Note that we mark the URL's text as LTR (instead of examining the // characters and guessing the text directionality) since URLs are always // treated as left-to-right text, even when they contain RTL characters. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(¤t_text); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(¤t_text); AutocompleteEditModel* edit_model = location_bar_->location_entry()->model(); if (edit_model->CurrentTextIsURL()) { diff --git a/chrome/browser/views/hung_renderer_view.cc b/chrome/browser/views/hung_renderer_view.cc index 523e5cc..10f4a25 100644 --- a/chrome/browser/views/hung_renderer_view.cc +++ b/chrome/browser/views/hung_renderer_view.cc @@ -7,6 +7,7 @@ #include "app/gfx/canvas.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/i18n/rtl.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -95,7 +96,7 @@ std::wstring HungPagesTableModel::GetText(int row, int column_id) { // TODO(xji): Consider adding a special case if the title text is a URL, // since those should always have LTR directionality. Please refer to // http://crbug.com/6726 for more information. - l10n_util::AdjustStringForLocaleDirection(title, &title); + base::i18n::AdjustStringForLocaleDirection(title, &title); return title; } diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index 6021532..d657c06 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -12,6 +12,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/theme_provider.h" +#include "base/i18n/rtl.h" #include "base/stl_util-inl.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/alternate_nav_url_fetcher.h" @@ -996,7 +997,7 @@ std::wstring LocationBarView::SelectedKeywordView::CalculateMinString( } else { min_string = description.substr(0, chop_index); } - l10n_util::AdjustStringForLocaleDirection(min_string, &min_string); + base::i18n::AdjustStringForLocaleDirection(min_string, &min_string); return min_string; } diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc index ab09db9..e7dcfa8 100644 --- a/chrome/browser/views/options/advanced_contents_view.cc +++ b/chrome/browser/views/options/advanced_contents_view.cc @@ -17,6 +17,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/file_util.h" +#include "base/i18n/rtl.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/thread.h" @@ -146,9 +147,9 @@ FileDisplayArea::~FileDisplayArea() { void FileDisplayArea::SetFile(const FilePath& file_path) { // Force file path to have LTR directionality. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { string16 localized_file_path; - l10n_util::WrapPathWithLTRFormatting(file_path, &localized_file_path); + base::i18n::WrapPathWithLTRFormatting(file_path, &localized_file_path); text_field_->SetText(UTF16ToWide(localized_file_path)); } else { text_field_->SetText(file_path.ToWStringHack()); @@ -210,7 +211,7 @@ void FileDisplayArea::InitClass() { // We'd prefer to use UILayoutIsRightToLeft() to perform the RTL // environment check, but it's nonstatic, so, instead, we check whether the // locale is RTL. - bool ui_is_rtl = l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT; + bool ui_is_rtl = base::i18n::IsRTL(); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); default_folder_icon_ = *rb.GetBitmapNamed(ui_is_rtl ? IDR_FOLDER_CLOSED_RTL : @@ -756,7 +757,7 @@ void WebContentSection::ButtonPressed( void WebContentSection::InitControlLayout() { AdvancedSection::InitControlLayout(); - if (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) { + if (!base::i18n::IsRTL()) { gears_label_ = new views::Label( l10n_util::GetString(IDS_OPTIONS_GEARSSETTINGS_GROUP_NAME)); } else { @@ -765,7 +766,7 @@ void WebContentSection::InitControlLayout() { std::wstring gearssetting_group_name = l10n_util::GetString(IDS_OPTIONS_GEARSSETTINGS_GROUP_NAME); gearssetting_group_name.push_back( - static_cast<wchar_t>(l10n_util::kRightToLeftMark)); + static_cast<wchar_t>(base::i18n::kRightToLeftMark)); gears_label_ = new views::Label(gearssetting_group_name); } gears_settings_button_ = new views::NativeButton( diff --git a/chrome/browser/views/options/passwords_page_view.cc b/chrome/browser/views/options/passwords_page_view.cc index 0cff819..c03700f 100644 --- a/chrome/browser/views/options/passwords_page_view.cc +++ b/chrome/browser/views/options/passwords_page_view.cc @@ -5,6 +5,7 @@ #include "chrome/browser/views/options/passwords_page_view.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/pref_service.h" @@ -71,16 +72,16 @@ std::wstring PasswordsTableModel::GetText(int row, case IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN: { // Site. const std::wstring& url = saved_signons_[row]->display_url.display_url(); // Force URL to have LTR directionality. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { std::wstring localized_url = url; - l10n_util::WrapStringWithLTRFormatting(&localized_url); + base::i18n::WrapStringWithLTRFormatting(&localized_url); return localized_url; } return url; } case IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN: { // Username. std::wstring username = GetPasswordFormAt(row)->username_value; - l10n_util::AdjustStringForLocaleDirection(username, &username); + base::i18n::AdjustStringForLocaleDirection(username, &username); return username; } default: diff --git a/chrome/browser/views/status_bubble_views.cc b/chrome/browser/views/status_bubble_views.cc index ff6ebc2..b533729 100644 --- a/chrome/browser/views/status_bubble_views.cc +++ b/chrome/browser/views/status_bubble_views.cc @@ -11,6 +11,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/text_elider.h" +#include "base/i18n/rtl.h" #include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/browser_theme_provider.h" @@ -497,7 +498,7 @@ gfx::Size StatusBubbleViews::GetPreferredSize() { void StatusBubbleViews::SetBounds(int x, int y, int w, int h) { // If the UI layout is RTL, we need to mirror the position of the bubble // relative to the parent. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { gfx::Rect frame_bounds; frame_->GetBounds(&frame_bounds, false); int mirrored_x = frame_bounds.width() - x - w; @@ -558,9 +559,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. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT && - !url_text_.empty()) - l10n_util::WrapStringWithLTRFormatting(&url_text_); + if (base::i18n::IsRTL() && !url_text_.empty()) + base::i18n::WrapStringWithLTRFormatting(&url_text_); if (IsFrameVisible()) view_->SetText(url_text_); diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc index c8c055f..b953466 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/views/tabs/dragged_tab_controller.cc @@ -13,6 +13,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/callback.h" +#include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" @@ -83,7 +84,7 @@ class DockView : public views::View { SkBitmap* high_icon = rb.GetBitmapNamed(IDR_DOCK_HIGH); SkBitmap* wide_icon = rb.GetBitmapNamed(IDR_DOCK_WIDE); - bool rtl_ui = l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT; + bool rtl_ui = base::i18n::IsRTL(); if (rtl_ui) { // Flip canvas to draw the mirrored tab images for RTL UI. canvas->save(); @@ -1136,7 +1137,7 @@ bool DraggedTabController::CompleteDrag() { gfx::Size(browser_rect.width(), browser_rect.height())); // When modifying the following if statement, please make sure not to // introduce issue listed in http://crbug.com/6223 comment #11. - bool rtl_ui = (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT); + bool rtl_ui = base::i18n::IsRTL(); bool has_dock_position = (dock_info_.type() != DockInfo::NONE); if (rtl_ui && has_dock_position) { // Mirror X axis so the docked tab is aligned using the mouse click as diff --git a/chrome/common/child_process_info.cc b/chrome/common/child_process_info.cc index 74b362e..eb69db3 100644 --- a/chrome/common/child_process_info.cc +++ b/chrome/common/child_process_info.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "base/atomicops.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/process_util.h" #include "base/rand_util.h" @@ -92,7 +93,7 @@ std::wstring ChildProcessInfo::GetLocalizedTitle() const { // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew // or Arabic word for "plugin". - l10n_util::AdjustStringForLocaleDirection(title, &title); + base::i18n::AdjustStringForLocaleDirection(title, &title); return l10n_util::GetStringF(message_id, title); } diff --git a/chrome/common/extensions/extension_message_bundle.cc b/chrome/common/extensions/extension_message_bundle.cc index b069c9b..6b001b1 100644 --- a/chrome/common/extensions/extension_message_bundle.cc +++ b/chrome/common/extensions/extension_message_bundle.cc @@ -9,6 +9,7 @@ #include "app/l10n_util.h" #include "base/hash_tables.h" +#include "base/i18n/rtl.h" #include "base/linked_ptr.h" #include "base/scoped_ptr.h" #include "base/singleton.h" @@ -95,10 +96,10 @@ bool ExtensionMessageBundle::AppendReservedMessagesForLocale( SubstitutionMap append_messages; append_messages[kUILocaleKey] = app_locale; - // Calling l10n_util::GetTextDirection on non-UI threads doesn't seems safe, + // Calling base::i18n::GetTextDirection on non-UI threads doesn't seems safe, // so we use GetTextDirectionForLocale instead. - if (l10n_util::GetTextDirectionForLocale(app_locale.c_str()) == - l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::GetTextDirectionForLocale(app_locale.c_str()) == + base::i18n::RIGHT_TO_LEFT) { append_messages[kBidiDirectionKey] = "rtl"; append_messages[kBidiReversedDirectionKey] = "ltr"; append_messages[kBidiStartEdgeKey] = kBidiRightEdgeValue; diff --git a/chrome/common/extensions/extension_message_bundle_unittest.cc b/chrome/common/extensions/extension_message_bundle_unittest.cc index 94ffd37..372b629 100644 --- a/chrome/common/extensions/extension_message_bundle_unittest.cc +++ b/chrome/common/extensions/extension_message_bundle_unittest.cc @@ -8,6 +8,7 @@ #include <vector> #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/linked_ptr.h" #include "base/scoped_ptr.h" #include "base/string_util.h" @@ -129,8 +130,8 @@ class ExtensionMessageBundleTest : public testing::Test { handler->GetL10nMessage(ExtensionMessageBundle::kUILocaleKey)); std::string text_dir = "ltr"; - if (l10n_util::GetTextDirectionForLocale(ui_locale.c_str()) == - l10n_util::RIGHT_TO_LEFT) + if (base::i18n::GetTextDirectionForLocale(ui_locale.c_str()) == + base::i18n::RIGHT_TO_LEFT) text_dir = "rtl"; EXPECT_EQ(text_dir, handler->GetL10nMessage( diff --git a/chrome/renderer/localized_error.cc b/chrome/renderer/localized_error.cc index 71624cd..5365964c 100644 --- a/chrome/renderer/localized_error.cc +++ b/chrome/renderer/localized_error.cc @@ -5,6 +5,7 @@ #include "chrome/renderer/localized_error.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/string_util.h" #include "base/values.h" @@ -106,11 +107,11 @@ WebErrorNetErrorMap net_error_options[] = { bool LocaleIsRTL() { #if defined(TOOLKIT_GTK) - // l10n_util::GetTextDirection uses the GTK text direction, which doesn't work + // base::i18n::GetTextDirection uses the GTK text direction, which doesn't work // within the renderer sandbox. - return l10n_util::GetICUTextDirection() == l10n_util::RIGHT_TO_LEFT; + return base::i18n::GetICUTextDirection() == base::i18n::RIGHT_TO_LEFT; #else - return l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT; + return base::i18n::IsRTL(); #endif } @@ -156,7 +157,7 @@ void GetLocalizedErrorValues(const WebURLError& error, ASCIIToWide(std::string(error.unreachableURL.spec()))); // URLs are always LTR. if (rtl) - l10n_util::WrapStringWithLTRFormatting(&failed_url); + base::i18n::WrapStringWithLTRFormatting(&failed_url); error_strings->SetString(L"title", l10n_util::GetStringF(options.title_resource_id, failed_url)); @@ -197,7 +198,7 @@ void GetLocalizedErrorValues(const WebURLError& error, std::wstring homepage(ASCIIToWide(failed_url.GetWithEmptyPath().spec())); // URLs are always LTR. if (rtl) - l10n_util::WrapStringWithLTRFormatting(&homepage); + base::i18n::WrapStringWithLTRFormatting(&homepage); suggest_home_page->SetString(L"homePage", homepage); // TODO(tc): we actually want the unicode hostname suggest_home_page->SetString(L"hostName", @@ -242,7 +243,7 @@ void GetFormRepostErrorValues(const GURL& display_url, std::wstring failed_url(ASCIIToWide(display_url.spec())); // URLs are always LTR. if (rtl) - l10n_util::WrapStringWithLTRFormatting(&failed_url); + base::i18n::WrapStringWithLTRFormatting(&failed_url); error_strings->SetString( L"title", l10n_util::GetStringF(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, failed_url.c_str())); diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc index 0767ca7..9ff86df 100644 --- a/chrome/test/automation/automation_proxy_uitest.cc +++ b/chrome/test/automation/automation_proxy_uitest.cc @@ -10,6 +10,7 @@ #include "base/command_line.h" #include "base/compiler_specific.h" #include "base/file_path.h" +#include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "base/string_util.h" #include "base/sys_info.h" @@ -122,8 +123,8 @@ TEST_F(AutomationProxyVisibleTest, MAYBE_WindowGetViewBounds) { EXPECT_TRUE(automation()->GetBrowserLocale(&browser_locale)); const std::string& locale_utf8 = UTF16ToUTF8(browser_locale); - if (l10n_util::GetTextDirectionForLocale(locale_utf8.c_str()) == - l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::GetTextDirectionForLocale(locale_utf8.c_str()) == + base::i18n::RIGHT_TO_LEFT) { EXPECT_LT(bounds2.x(), bounds.x()); } else { EXPECT_GT(bounds2.x(), bounds.x()); diff --git a/views/accelerator.cc b/views/accelerator.cc index 7ecec58..0dbb759 100644 --- a/views/accelerator.cc +++ b/views/accelerator.cc @@ -9,6 +9,7 @@ #endif #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/string_util.h" #include "grit/app_strings.h" @@ -92,10 +93,8 @@ std::wstring Accelerator::GetShortcutText() const { // required. std::wstring shortcut_rtl; bool adjust_shortcut_for_rtl = false; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT && - shortcut.length() == 1 && - !IsAsciiAlpha(shortcut.at(0)) && - !IsAsciiDigit(shortcut.at(0))) { + if (base::i18n::IsRTL() && shortcut.length() == 1 && + !IsAsciiAlpha(shortcut.at(0)) && !IsAsciiDigit(shortcut.at(0))) { adjust_shortcut_for_rtl = true; shortcut_rtl.assign(shortcut); } diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc index 141cf328..5bdc9c73 100644 --- a/views/controls/button/native_button.cc +++ b/views/controls/button/native_button.cc @@ -10,6 +10,7 @@ #endif #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "base/logging.h" #include "views/controls/native/native_view_host.h" @@ -71,7 +72,7 @@ void NativeButton::SetLabel(const std::wstring& label) { // RTL strings explicitly (using the appropriate Unicode formatting) so that // Windows displays the text correctly regardless of the HWND hierarchy. std::wstring localized_label; - if (l10n_util::AdjustStringForLocaleDirection(label_, &localized_label)) + if (base::i18n::AdjustStringForLocaleDirection(label_, &localized_label)) label_ = localized_label; if (native_wrapper_) diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc index 042f9d2..ca0954d 100644 --- a/views/controls/button/text_button.cc +++ b/views/controls/button/text_button.cc @@ -7,7 +7,6 @@ #include <algorithm> #include "app/gfx/canvas.h" -#include "app/l10n_util.h" #include "app/throb_animation.h" #include "app/resource_bundle.h" #include "views/controls/button/button.h" @@ -321,7 +320,7 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { text_bounds.y(), text_bounds.width(), text_bounds.height(), - l10n_util::DefaultCanvasTextAlignment()); + gfx::Canvas::DefaultCanvasTextAlignment()); #else canvas->DrawStringInt(text_, font_, diff --git a/views/controls/combobox/native_combobox_win.cc b/views/controls/combobox/native_combobox_win.cc index 69ca8a3..c95520e 100644 --- a/views/controls/combobox/native_combobox_win.cc +++ b/views/controls/combobox/native_combobox_win.cc @@ -8,6 +8,7 @@ #include "app/gfx/font.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/i18n/rtl.h" #include "gfx/native_theme_win.h" #include "views/controls/combobox/combobox.h" #include "views/widget/widget.h" @@ -52,7 +53,7 @@ void NativeComboboxWin::UpdateFromModel() { // text is displayed correctly in right-to-left UIs. std::wstring localized_text; const wchar_t* text_ptr = text.c_str(); - if (l10n_util::AdjustStringForLocaleDirection(text, &localized_text)) + if (base::i18n::AdjustStringForLocaleDirection(text, &localized_text)) text_ptr = localized_text.c_str(); SendMessage(native_view(), CB_ADDSTRING, 0, diff --git a/views/controls/label.cc b/views/controls/label.cc index b3d4e41..0116b5a 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -12,6 +12,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/text_elider.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/utf_string_conversions.h" #include "gfx/color_utils.h" @@ -148,8 +149,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. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) - l10n_util::WrapStringWithLTRFormatting(paint_text); + if (base::i18n::IsRTL()) + base::i18n::WrapStringWithLTRFormatting(paint_text); } else { *paint_text = text_; } diff --git a/views/controls/label_unittest.cc b/views/controls/label_unittest.cc index 7d08595..8caabb0 100644 --- a/views/controls/label_unittest.cc +++ b/views/controls/label_unittest.cc @@ -4,6 +4,7 @@ #include "app/gfx/canvas.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" #include "views/border.h" @@ -65,8 +66,7 @@ TEST(LabelTest, ColorProperty) { TEST(LabelTest, AlignmentProperty) { Label label; - bool reverse_alignment = - l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT; + bool reverse_alignment = base::i18n::IsRTL(); label.SetHorizontalAlignment(Label::ALIGN_RIGHT); EXPECT_EQ( diff --git a/views/controls/menu/menu.cc b/views/controls/menu/menu.cc index 6a81d9c..479a545 100644 --- a/views/controls/menu/menu.cc +++ b/views/controls/menu/menu.cc @@ -4,13 +4,13 @@ #include "views/controls/menu/menu.h" -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "third_party/skia/include/core/SkBitmap.h" namespace views { bool Menu::Delegate::IsRightToLeftUILayout() const { - return l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT; + return base::i18n::IsRTL(); } const SkBitmap& Menu::Delegate::GetEmptyIcon() const { diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index 49f68ed..a1fd9ad 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -7,6 +7,7 @@ #include "app/gfx/canvas.h" #include "app/l10n_util.h" #include "app/os_exchange_data.h" +#include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "base/time.h" #include "views/controls/button/menu_button.h" @@ -730,14 +731,14 @@ bool MenuController::OnKeyDown(int key_code // Handling of VK_RIGHT and VK_LEFT is different depending on the UI // layout. case base::VKEY_RIGHT: - if (l10n_util::TextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) CloseSubmenu(); else OpenSubmenuChangeSelectionIfCan(); break; case base::VKEY_LEFT: - if (l10n_util::TextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) OpenSubmenuChangeSelectionIfCan(); else CloseSubmenu(); diff --git a/views/controls/menu/native_menu_gtk.cc b/views/controls/menu/native_menu_gtk.cc index 300ef2c6..395e9a5 100644 --- a/views/controls/menu/native_menu_gtk.cc +++ b/views/controls/menu/native_menu_gtk.cc @@ -9,8 +9,8 @@ #include <string> #include "app/gfx/font.h" -#include "app/l10n_util.h" #include "app/menus/menu_model.h" +#include "base/i18n/rtl.h" #include "base/keyboard_code_conversion_gtk.h" #include "base/keyboard_codes.h" #include "base/message_loop.h" @@ -328,7 +328,7 @@ void NativeMenuGtk::MenuPositionFunc(GtkMenu* menu, *x = position->point.x(); *y = position->point.y(); views::Menu2::Alignment alignment = position->alignment; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { switch (alignment) { case Menu2::ALIGN_TOPRIGHT: alignment = Menu2::ALIGN_TOPLEFT; diff --git a/views/controls/message_box_view.cc b/views/controls/message_box_view.cc index c5d8882..756919a 100644 --- a/views/controls/message_box_view.cc +++ b/views/controls/message_box_view.cc @@ -6,8 +6,8 @@ #include "app/clipboard/clipboard.h" #include "app/clipboard/scoped_clipboard_writer.h" -#include "app/l10n_util.h" #include "app/message_box_flags.h" +#include "base/i18n/rtl.h" #include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "views/controls/button/checkbox.h" @@ -120,10 +120,10 @@ void MessageBoxView::Init(int dialog_flags, if (dialog_flags & MessageBoxFlags::kAutoDetectAlignment) { // Determine the alignment and directionality based on the first character // with strong directionality. - l10n_util::TextDirection direction = - l10n_util::GetFirstStrongCharacterDirection(message_label_->GetText()); + base::i18n::TextDirection direction = + base::i18n::GetFirstStrongCharacterDirection(message_label_->GetText()); views::Label::Alignment alignment; - if (direction == l10n_util::RIGHT_TO_LEFT) + if (direction == base::i18n::RIGHT_TO_LEFT) alignment = views::Label::ALIGN_RIGHT; else alignment = views::Label::ALIGN_LEFT; diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index 6122e44..3d1acd1 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -15,6 +15,7 @@ #include "app/l10n_util_win.h" #include "app/resource_bundle.h" #include "app/table_model.h" +#include "base/i18n/rtl.h" #include "base/string_util.h" #include "base/win_util.h" #include "gfx/favicon_size.h" @@ -1131,7 +1132,7 @@ void TableView::PaintAltText() { // Pad by 1 for halo. canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1, 1, bounds.width() - 2, bounds.height() - 2, - l10n_util::DefaultCanvasTextAlignment()); + gfx::Canvas::DefaultCanvasTextAlignment()); canvas.getTopPlatformDevice().drawToHDC(dc, bounds.x(), bounds.y(), NULL); ReleaseDC(GetNativeControlHWND(), dc); } diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index 9f2392f..f66b949 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -11,6 +11,7 @@ #include "app/l10n_util.h" #include "app/l10n_util_win.h" #include "app/win_util.h" +#include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "base/string_util.h" #include "base/win_util.h" @@ -131,7 +132,7 @@ void NativeTextfieldWin::UpdateText() { // Adjusting the string direction before setting the text in order to make // sure both RTL and LTR strings are displayed properly. std::wstring text_to_set; - if (!l10n_util::AdjustStringForLocaleDirection(text, &text_to_set)) + if (!base::i18n::AdjustStringForLocaleDirection(text, &text_to_set)) text_to_set = text; if (textfield_->style() & Textfield::STYLE_LOWERCASE) text_to_set = l10n_util::ToLower(text_to_set); @@ -808,7 +809,7 @@ LONG NativeTextfieldWin::ClipXCoordToVisibleText(LONG x, // paragraph. bool ltr_text_in_ltr_layout = true; if ((pf2.wEffects & PFE_RTLPARA) || - l10n_util::StringContainsStrongRTLChars(GetText())) { + base::i18n::StringContainsStrongRTLChars(GetText())) { ltr_text_in_ltr_layout = false; } const int length = GetTextLength(); diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc index 7cf1e8f..f70ac17 100644 --- a/views/controls/tree/tree_view.cc +++ b/views/controls/tree/tree_view.cc @@ -11,6 +11,7 @@ #include "app/l10n_util.h" #include "app/l10n_util_win.h" #include "app/resource_bundle.h" +#include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "base/stl_util-inl.h" #include "base/win_util.h" @@ -399,7 +400,7 @@ LRESULT TreeView::OnNotify(int w_param, LPNMHDR l_param) { // Adjust the string direction if such adjustment is required. std::wstring localized_text; - if (l10n_util::AdjustStringForLocaleDirection(text, &localized_text)) + if (base::i18n::AdjustStringForLocaleDirection(text, &localized_text)) text.swap(localized_text); wcsncpy_s(info->item.pszText, info->item.cchTextMax, text.c_str(), @@ -729,7 +730,7 @@ LRESULT CALLBACK TreeView::TreeWndProc(HWND window, return 0; HDC dc = canvas.beginPlatformPaint(); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { // gfx::Canvas ends up configuring the DC with a mode of GM_ADVANCED. // For some reason a graphics mode of ADVANCED triggers all the text // to be mirrored when RTL. Set the mode back to COMPATIBLE and @@ -757,7 +758,7 @@ LRESULT CALLBACK TreeView::TreeWndProc(HWND window, -canvas.paintStruct().rcPaint.top, NULL); } SendMessage(window, WM_PRINTCLIENT, reinterpret_cast<WPARAM>(dc), 0); - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + if (base::i18n::IsRTL()) { // Reset the origin of the dc back to 0. This way when we copy the bits // over we copy the right bits. SetViewportOrgEx(dc, 0, 0, NULL); diff --git a/views/view.cc b/views/view.cc index b5e7173..a35cf49 100644 --- a/views/view.cc +++ b/views/view.cc @@ -11,7 +11,7 @@ #include "app/drag_drop_types.h" #include "app/gfx/canvas.h" -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/scoped_handle.h" @@ -235,8 +235,7 @@ void View::SetLayoutManager(LayoutManager* layout_manager) { } bool View::UILayoutIsRightToLeft() const { - return (ui_mirroring_is_enabled_for_rtl_languages_ && - l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT); + return (ui_mirroring_is_enabled_for_rtl_languages_ && base::i18n::IsRTL()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/views/widget/tooltip_manager_win.cc b/views/widget/tooltip_manager_win.cc index e0b48c3..137d32c 100644 --- a/views/widget/tooltip_manager_win.cc +++ b/views/widget/tooltip_manager_win.cc @@ -11,6 +11,7 @@ #include "app/l10n_util.h" #include "app/l10n_util_win.h" #include "app/win_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/message_loop.h" #include "views/screen.h" @@ -174,8 +175,8 @@ LRESULT TooltipManagerWin::OnNotify(int w_param, TrimTooltipToFit(&clipped_text_, &tooltip_width_, &line_count_, screen_loc.x(), screen_loc.y()); // Adjust the clipped tooltip text for locale direction. - l10n_util::AdjustStringForLocaleDirection(clipped_text_, - &clipped_text_); + base::i18n::AdjustStringForLocaleDirection(clipped_text_, + &clipped_text_); tooltip_info->lpszText = const_cast<WCHAR*>(clipped_text_.c_str()); } else { tooltip_text_.clear(); diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index 38e0d82..a7ef80d 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "gfx/rect.h" +#include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" #include "gfx/path.h" #include "views/event.h" @@ -203,7 +204,7 @@ void WindowGtk::UpdateWindowTitle() { // the native frame is being used, since this also updates the taskbar, etc. std::wstring window_title = window_delegate_->GetWindowTitle(); std::wstring localized_text; - if (l10n_util::AdjustStringForLocaleDirection(window_title, &localized_text)) + if (base::i18n::AdjustStringForLocaleDirection(window_title, &localized_text)) window_title.assign(localized_text); gtk_window_set_title(GetNativeWindow(), WideToUTF8(window_title).c_str()); diff --git a/views/window/window_win.cc b/views/window/window_win.cc index 9a8cdcb..b58bcd4 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -13,6 +13,7 @@ #include "app/resource_bundle.h" #include "app/theme_provider.h" #include "app/win_util.h" +#include "base/i18n/rtl.h" #include "base/win_util.h" #include "gfx/icon_util.h" #include "gfx/path.h" @@ -405,7 +406,7 @@ void WindowWin::UpdateWindowTitle() { // the native frame is being used, since this also updates the taskbar, etc. std::wstring window_title = window_delegate_->GetWindowTitle(); std::wstring localized_text; - if (l10n_util::AdjustStringForLocaleDirection(window_title, &localized_text)) + if (base::i18n::AdjustStringForLocaleDirection(window_title, &localized_text)) window_title.assign(localized_text); SetWindowText(GetNativeView(), window_title.c_str()); } @@ -991,7 +992,7 @@ void WindowWin::OnRButtonUp(UINT ht_component, const CPoint& point) { MAKELPARAM(screen_point.x, screen_point.y)); if (ht_component == HTCAPTION || ht_component == HTSYSMENU) { UINT flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD; - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) + if (base::i18n::IsRTL()) flags |= TPM_RIGHTALIGN; HMENU system_menu = GetSystemMenu(GetNativeView(), FALSE); int id = TrackPopupMenu(system_menu, flags, screen_point.x, |