diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-12 14:33:27 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-12 14:33:27 +0000 |
commit | 9c0b6647367bdc43549a00d1b6678820ed2dc54a (patch) | |
tree | a23e629a9bb3c4a9167ae25e59050a671a8ef1c6 /base | |
parent | 9507403c64711e7fe6b6112668f3a8bea69481a0 (diff) | |
download | chromium_src-9c0b6647367bdc43549a00d1b6678820ed2dc54a.zip chromium_src-9c0b6647367bdc43549a00d1b6678820ed2dc54a.tar.gz chromium_src-9c0b6647367bdc43549a00d1b6678820ed2dc54a.tar.bz2 |
Fix extension install UI for extensions with RTL Names.
Add a version of AdjustStringForLocaleDirection() that handles the quirks of GTK/OSX label autodirectionality.
Comment from the CL:
// On OS X & GTK the directionality of a label is determined by the first
// strongly directional character.
// However, we want to make sure that in an LTR-language UI all strings are
// left aligned and vice versa.
// A problem can arise if we display a string which starts with user input.
// User input may be the opposite directionality and so the whole string will
// be displayed in the opposite directionality, e.g. if we want to display in
// an LTR UI [such as US English]:
//
// EMAN_NOISNETXE is now installed.
//
// Since EXTENSION_NAME begins with a strong RTL char, the label's
// directionality will be set to RTL and the string will be displayed visually
// as:
//
// .is now installed EMAN_NOISNETXE
//
// In order to solve this issue, we prepend an LRM to the string which is a
// strongly directional LTR char.
// We also append an LRM at the end which ensures that we're in an LTR
// context.
// Unlike Windows, Linux and OS X can correctly display RTL glyphs out of the
// box so there is no issue with displaying zero-width bidi control characters
// on any system. Thus no need for the !IsRTL() check here.
BUG=63303
TEST=1. Try scenario described in bug. 2. Make sure there areno regressions displaying RTL strings in LTR UI and vice versa on OS X.
Review URL: http://codereview.chromium.org/5291009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68967 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/i18n/rtl.cc | 52 | ||||
-rw-r--r-- | base/i18n/rtl.h | 1 |
2 files changed, 53 insertions, 0 deletions
diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc index 6a5d293..12b376d 100644 --- a/base/i18n/rtl.cc +++ b/base/i18n/rtl.cc @@ -163,6 +163,7 @@ TextDirection GetFirstStrongCharacterDirection(const std::wstring& text) { } #endif +#if defined(OS_WIN) bool AdjustStringForLocaleDirection(string16* text) { if (!IsRTL() || text->empty()) return false; @@ -177,6 +178,57 @@ bool AdjustStringForLocaleDirection(string16* text) { return true; } +#else +bool AdjustStringForLocaleDirection(string16* text) { + // On OS X & GTK the directionality of a label is determined by the first + // strongly directional character. + // However, we want to make sure that in an LTR-language-UI all strings are + // left aligned and vice versa. + // A problem can arise if we display a string which starts with user input. + // User input may be of the opposite directionality to the UI. So the whole + // string will be displayed in the opposite directionality, e.g. if we want to + // display in an LTR UI [such as US English]: + // + // EMAN_NOISNETXE is now installed. + // + // Since EXTENSION_NAME begins with a strong RTL char, the label's + // directionality will be set to RTL and the string will be displayed visually + // as: + // + // .is now installed EMAN_NOISNETXE + // + // In order to solve this issue, we prepend an LRM to the string. An LRM is a + // strongly directional LTR char. + // We also append an LRM at the end, which ensures that we're in an LTR + // context. + + // Unlike Windows, Linux and OS X can correctly display RTL glyphs out of the + // box so there is no issue with displaying zero-width bidi control characters + // on any system. Thus no need for the !IsRTL() check here. + if (text->empty()) + return false; + + bool ui_direction_is_rtl = IsRTL(); + + bool has_rtl_chars = StringContainsStrongRTLChars(*text); + if (!ui_direction_is_rtl && has_rtl_chars) { + WrapStringWithRTLFormatting(text); + text->insert(0, 1, kLeftToRightMark); + text->push_back(kLeftToRightMark); + } else if (ui_direction_is_rtl && has_rtl_chars) { + WrapStringWithRTLFormatting(text); + text->insert(0, 1, kRightToLeftMark); + text->push_back(kRightToLeftMark); + } else if (ui_direction_is_rtl) { + WrapStringWithLTRFormatting(text); + text->insert(0, 1, kRightToLeftMark); + text->push_back(kRightToLeftMark); + } + + return true; +} + +#endif // !OS_WIN #if defined(WCHAR_T_IS_UTF32) bool AdjustStringForLocaleDirection(std::wstring* text) { diff --git a/base/i18n/rtl.h b/base/i18n/rtl.h index 82ac576..a75ed4f 100644 --- a/base/i18n/rtl.h +++ b/base/i18n/rtl.h @@ -84,6 +84,7 @@ TextDirection GetFirstStrongCharacterDirection(const std::wstring& text); // string is always treated as a right-to-left string. This is done by // inserting certain Unicode formatting marks into the returned string. // +// ** Notes about the Windows version of this function: // TODO(idana) bug 6806: 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 |