diff options
author | skanuj@chromium.org <skanuj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 20:19:06 +0000 |
---|---|---|
committer | skanuj@chromium.org <skanuj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 20:19:06 +0000 |
commit | 01a1f5bc356da845989ae23482f42a5910fc2121 (patch) | |
tree | dc397c87a8f5a1fe8cc622c7af993cde6c0f50d6 /base/i18n | |
parent | 4807c46d675f6d436fa1017b4a04a6a47706af1f (diff) | |
download | chromium_src-01a1f5bc356da845989ae23482f42a5910fc2121.zip chromium_src-01a1f5bc356da845989ae23482f42a5910fc2121.tar.gz chromium_src-01a1f5bc356da845989ae23482f42a5910fc2121.tar.bz2 |
Implement eliding/truncating at end in RenderText
patch from issue 112063003
The eliding is determined using binary search similar to the ElideText
in ui/gfx/text_elider.cc.
The mixed LTR-RTL handling for ellipsis is done using LTR/RTL markers.
There is no other way of rendering the ellipsis with the directionality
of preceding strong-directional characters. Previous scheme worked
because it rendered LTR and RTL sub-strings as different RenderText
instances.
Added helper method to be able to determine directionality of the
trailing text.
Made StringSlicer used by text_elider.cc public to be shared by RenderText.
Additional Fix:
- Call UpdateLayoutText from SetDisplayRect.
- Disable erratic tests on versions of windows older than Vista.
BUG=327833
TEST=ui_unittests,base_unittests
R=msw@chromium.org
TBR=jshin@chromium.org,pkasting@chromium.org
Review URL: https://codereview.chromium.org/107513011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241000 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/i18n')
-rw-r--r-- | base/i18n/rtl.cc | 15 | ||||
-rw-r--r-- | base/i18n/rtl.h | 4 | ||||
-rw-r--r-- | base/i18n/rtl_unittest.cc | 64 |
3 files changed, 82 insertions, 1 deletions
diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc index d9818e8..851b036 100644 --- a/base/i18n/rtl.cc +++ b/base/i18n/rtl.cc @@ -163,6 +163,21 @@ TextDirection GetFirstStrongCharacterDirection(const string16& text) { return LEFT_TO_RIGHT; } +TextDirection GetLastStrongCharacterDirection(const string16& text) { + const UChar* string = text.c_str(); + size_t position = text.length(); + while (position > 0) { + UChar32 character; + size_t prev_position = position; + U16_PREV(string, 0, prev_position, character); + TextDirection direction = GetCharacterDirection(character); + if (direction != UNKNOWN_DIRECTION) + return direction; + position = prev_position; + } + return LEFT_TO_RIGHT; +} + TextDirection GetStringDirection(const string16& text) { const UChar* string = text.c_str(); size_t length = text.length(); diff --git a/base/i18n/rtl.h b/base/i18n/rtl.h index c80d2f8..aa5f681 100644 --- a/base/i18n/rtl.h +++ b/base/i18n/rtl.h @@ -64,7 +64,7 @@ BASE_I18N_EXPORT bool ICUIsRTL(); BASE_I18N_EXPORT TextDirection GetTextDirectionForLocale( const char* locale_name); -// Given the string in |text|, returns the directionality of the first +// Given the string in |text|, returns the directionality of the first or last // 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 @@ -72,6 +72,8 @@ BASE_I18N_EXPORT TextDirection GetTextDirectionForLocale( // for more information. BASE_I18N_EXPORT TextDirection GetFirstStrongCharacterDirection( const string16& text); +BASE_I18N_EXPORT TextDirection GetLastStrongCharacterDirection( + const string16& text); // Given the string in |text|, returns LEFT_TO_RIGHT or RIGHT_TO_LEFT if all the // strong directionality characters in the string are of the same diff --git a/base/i18n/rtl_unittest.cc b/base/i18n/rtl_unittest.cc index 58772b0..8faaccf 100644 --- a/base/i18n/rtl_unittest.cc +++ b/base/i18n/rtl_unittest.cc @@ -46,6 +46,8 @@ TEST_F(RTLTest, GetFirstStrongCharacterDirection) { } cases[] = { // Test pure LTR string. { L"foo bar", LEFT_TO_RIGHT }, + // Test pure RTL string. + { L"\x05d0\x05d1\x05d2 \x05d3\x0d4\x05d5", RIGHT_TO_LEFT}, // Test bidi string in which the first character with strong directionality // is a character with type L. { L"foo \x05d0 bar", LEFT_TO_RIGHT }, @@ -107,6 +109,68 @@ TEST_F(RTLTest, GetFirstStrongCharacterDirection) { GetFirstStrongCharacterDirection(WideToUTF16(cases[i].text))); } + +// Note that the cases with LRE, LRO, RLE and RLO are invalid for +// GetLastStrongCharacterDirection because they should be followed by PDF +// character. +TEST_F(RTLTest, GetLastStrongCharacterDirection) { + struct { + const wchar_t* text; + TextDirection direction; + } cases[] = { + // Test pure LTR string. + { L"foo bar", LEFT_TO_RIGHT }, + // Test pure RTL string. + { L"\x05d0\x05d1\x05d2 \x05d3\x0d4\x05d5", RIGHT_TO_LEFT}, + // Test bidi string in which the last character with strong directionality + // is a character with type L. + { L"foo \x05d0 bar", LEFT_TO_RIGHT }, + // Test bidi string in which the last character with strong directionality + // is a character with type R. + { L"\x05d0 foo bar \x05d3", RIGHT_TO_LEFT }, + // Test bidi string which ends with a character with weak directionality + // and in which the last character with strong directionality is a + // character with type L. + { L"!foo \x05d0 bar!", LEFT_TO_RIGHT }, + // Test bidi string which ends with a character with weak directionality + // and in which the last character with strong directionality is a + // character with type R. + { L",\x05d0 foo bar \x05d1,", RIGHT_TO_LEFT }, + // Test bidi string in which the last character with strong directionality + // is a character with type AL. + { L"\x0622 foo \x05d0 bar \x0622", RIGHT_TO_LEFT }, + // Test a string without strong directionality characters. + { L",!.{}", LEFT_TO_RIGHT }, + // Test empty string. + { L"", LEFT_TO_RIGHT }, + // 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) + L"abc 123" L" ! \x10910 !", +#elif defined(WCHAR_T_IS_UTF16) + L"abc 123" L" ! \xd802\xdd10 !", +#else +#error wchar_t should be either UTF-16 or UTF-32 +#endif + RIGHT_TO_LEFT }, + { +#if defined(WCHAR_T_IS_UTF32) + L"abc 123" L" ! \x10401 !", +#elif defined(WCHAR_T_IS_UTF16) + L"abc 123" L" ! \xd801\xdc01 !", +#else +#error wchar_t should be either UTF-16 or UTF-32 +#endif + LEFT_TO_RIGHT }, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) + EXPECT_EQ(cases[i].direction, + GetLastStrongCharacterDirection(WideToUTF16(cases[i].text))); +} + TEST_F(RTLTest, GetStringDirection) { struct { const wchar_t* text; |