diff options
author | xji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-23 06:00:44 +0000 |
---|---|---|
committer | xji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-23 06:00:44 +0000 |
commit | 4ea6cab1939dff2111f779d8fff80e5dc5d7b8c6 (patch) | |
tree | aa3de08379aab61f8ac17f55b419ec5119eea2ab /chrome/common/l10n_util_unittest.cc | |
parent | b285a98a45c5ddd4ad9080a06d5a7d4943ac19d9 (diff) | |
download | chromium_src-4ea6cab1939dff2111f779d8fff80e5dc5d7b8c6.zip chromium_src-4ea6cab1939dff2111f779d8fff80e5dc5d7b8c6.tar.gz chromium_src-4ea6cab1939dff2111f779d8fff80e5dc5d7b8c6.tar.bz2 |
This CL fixes issue 6099 -- bad display of multi-line English message in pop ups.
(http://crbug.com/6099)
Currently, in RTL locales, a pure *multi-line* English message is displayed as right aligned and has RTL directionality (such as the ending punctuation appears at the very left).
Single-line message works fine.
I do not know why, but simply putting LRE-PDF around a multi-line English text which has the following flags
DT_WORDBREAK | DT_RTLREADING
wont render the English message as LTR.
We have to remove the DT_RTLREADING to render multi-line English message correctly in LTR direction.
The fix is that in RTL locales, for JavaScript message, if the message is pure English, the alignment is set to be left-aligned, and the directionality is set to be left-to-right. If the message is mixed BiDi text, the alignment and the directionality is determined by the directionality of the first character with strong directionality in the text.
JavaScript message is a MessageBoxView, and the message is a view::Label. Both MessageBoxView and Label are used by Chrome's UI as well.
If the message is one of Chrome UI's, the alignment and directionality of the message should be taken from that of the UI's.
In order to distinguish where the message comes from, a new flag kFlagWebMessage is introduced in MessageBoxView, and a new argument is introduced in Label::SetHorizontalAlignment() to control whether the alignment need to be flipped or not for RTL locales.
Consequently, quite a few files which calls Label::SetHorizontalAlignment() are changed.
The main changes are in 5 areas. Other files are changed due to the signature change of Label::SetHorizontalAlignment().
1. jsmessage_box_handler.cc: pass in extra flag kFlagWebPage when creating MessageBoxView to indicate the message box is one from a web page, not from Chrome UI.
2. l10n_util.h/.cc
added function GetFirstStrongDirection()
3. label.h/.cc
a new argument is introduced in Label::SetHorizontalAlignment() to control whether the alignment need to be flipped or not for RTL locales.
4. message_box_view.cc
when init message box view, if the flag is kFlagWebPage, get the text directionality from the text itself (not Chrome UI's) and calls Label::SetHorizontalAlignment() to not resetting the flag for RTL locales.
5. chrome_canvas_win.cc
5.1 ComputeFormatFlags()
only set flag DT_RTLREADING for RTL locales if the text contains strong RTL characters and the alignment is RIGHT aligned. All labels of Chrome's UI and other Chrome UI components in RTL locales have been set as (or flipped to) RIGHT aligned.
5.2 DoDrawText()
Only adjust string for locale is the reading direction is DT_RTLREADING.
Review URL: http://codereview.chromium.org/18863
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10178 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/l10n_util_unittest.cc')
-rw-r--r-- | chrome/common/l10n_util_unittest.cc | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/chrome/common/l10n_util_unittest.cc b/chrome/common/l10n_util_unittest.cc index 3d93ef7..88c1cad 100644 --- a/chrome/common/l10n_util_unittest.cc +++ b/chrome/common/l10n_util_unittest.cc @@ -160,6 +160,102 @@ TEST_F(L10nUtilTest, GetAppLocale) { Locale::setDefault(locale, error_code); } +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; |