diff options
author | xji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 23:32:34 +0000 |
---|---|---|
committer | xji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 23:32:34 +0000 |
commit | 3f49b8167ced932005ae75e29adb1f9f7f5908da (patch) | |
tree | e93c4bfe9860bc8c5c3c446da32b80bd6c3bbad7 /views | |
parent | 606788603dbb0d5ce1e9eac0e6009b5bcc308b65 (diff) | |
download | chromium_src-3f49b8167ced932005ae75e29adb1f9f7f5908da.zip chromium_src-3f49b8167ced932005ae75e29adb1f9f7f5908da.tar.gz chromium_src-3f49b8167ced932005ae75e29adb1f9f7f5908da.tar.bz2 |
Introduce FORCE_LTR_DIRECTIONALTY in Canvas.
For strings coming from webpage (such as alert in JS), its directionality is set according to the directionality of its first strong character's directionality.
For chrome's UI string, its directionality is set as RTL if the UI is RTL and the string contains strong RTL characters.
BUG=91698
TEST=start chrome in RTL locale, check about:crash, "!" should be displayed at very left. check the directionality of alert() with bidi text in LTR and RTL chrome, the directionality should be determined by its first strong directionality character.
Review URL: http://codereview.chromium.org/7655037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97392 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/label.cc | 9 | ||||
-rw-r--r-- | views/controls/label_unittest.cc | 78 |
2 files changed, 45 insertions, 42 deletions
diff --git a/views/controls/label.cc b/views/controls/label.cc index fe32884..54978ec 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -463,6 +463,15 @@ void Label::CalculateDrawStringParams(std::wstring* paint_text, *text_bounds = GetTextBounds(); *flags = ComputeMultiLineFlags(); + // If rtl_alignment_mode_ is AUTO_DETECT_ALIGNMENT (such as for text from + // webpage, not from chrome's UI), its directionality is forced to be RTL if + // it is right aligned. Otherwise, its directionality is forced to be LTR. + if (rtl_alignment_mode_ == AUTO_DETECT_ALIGNMENT) { + if (horiz_alignment_ == ALIGN_RIGHT) + *flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; + else + *flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; + } } } // namespace views diff --git a/views/controls/label_unittest.cc b/views/controls/label_unittest.cc index 358a136..d0a162f 100644 --- a/views/controls/label_unittest.cc +++ b/views/controls/label_unittest.cc @@ -306,7 +306,7 @@ TEST(LabelTest, DrawSingleLineString) { EXPECT_EQ(extra.height() / 2 , text_bounds.y()); EXPECT_EQ(required_size.width(), text_bounds.width()); EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); + EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); // Left aligned text. label.SetHorizontalAlignment(Label::ALIGN_LEFT); @@ -319,7 +319,7 @@ TEST(LabelTest, DrawSingleLineString) { EXPECT_EQ(extra.height() / 2 , text_bounds.y()); EXPECT_EQ(required_size.width(), text_bounds.width()); EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); + EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); // Right aligned text. label.SetHorizontalAlignment(Label::ALIGN_RIGHT); @@ -332,7 +332,7 @@ TEST(LabelTest, DrawSingleLineString) { EXPECT_EQ(extra.height() / 2 , text_bounds.y()); EXPECT_EQ(required_size.width(), text_bounds.width()); EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); + EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY, flags); // Test single line drawing with a border. gfx::Insets border(39, 34, 8, 96); @@ -362,7 +362,7 @@ TEST(LabelTest, DrawSingleLineString) { EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); EXPECT_EQ(required_size.width(), text_bounds.width()); EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); + EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); // Left aligned text with border. label.SetHorizontalAlignment(Label::ALIGN_LEFT); @@ -375,7 +375,7 @@ TEST(LabelTest, DrawSingleLineString) { EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); EXPECT_EQ(required_size.width(), text_bounds.width()); EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); + EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); // Right aligned text. label.SetHorizontalAlignment(Label::ALIGN_RIGHT); @@ -388,7 +388,7 @@ TEST(LabelTest, DrawSingleLineString) { EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); EXPECT_EQ(required_size.width(), text_bounds.width()); EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); + EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY, flags); } // On Linux the underlying pango routines require a max height in order to @@ -422,14 +422,13 @@ TEST(LabelTest, DrawMultiLineString) { EXPECT_EQ(extra.height() / 2, text_bounds.y()); EXPECT_GT(text_bounds.width(), kMinTextDimension); EXPECT_GT(text_bounds.height(), kMinTextDimension); + int expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_CENTER | + gfx::Canvas::FORCE_LTR_DIRECTIONALITY; #if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); + EXPECT_EQ(expected_flags, flags); #else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_CENTER | - gfx::Canvas::NO_ELLIPSIS, - flags); + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); #endif gfx::Rect center_bounds(text_bounds); @@ -442,14 +441,13 @@ TEST(LabelTest, DrawMultiLineString) { EXPECT_EQ(extra.height() / 2, text_bounds.y()); EXPECT_GT(text_bounds.width(), kMinTextDimension); EXPECT_GT(text_bounds.height(), kMinTextDimension); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_LEFT | + gfx::Canvas::FORCE_LTR_DIRECTIONALITY; #if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT, flags); + EXPECT_EQ(expected_flags, flags); #else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_LEFT | - gfx::Canvas::NO_ELLIPSIS, - flags); + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); #endif label.SetHorizontalAlignment(Label::ALIGN_RIGHT); @@ -461,14 +459,13 @@ TEST(LabelTest, DrawMultiLineString) { EXPECT_EQ(extra.height() / 2, text_bounds.y()); EXPECT_GT(text_bounds.width(), kMinTextDimension); EXPECT_GT(text_bounds.height(), kMinTextDimension); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_RIGHT | + gfx::Canvas::FORCE_RTL_DIRECTIONALITY; #if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT, flags); + EXPECT_EQ(expected_flags, flags); #else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_RIGHT | - gfx::Canvas::NO_ELLIPSIS, - flags); + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); #endif // Test multiline drawing with a border. @@ -492,14 +489,13 @@ TEST(LabelTest, DrawMultiLineString) { EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); EXPECT_EQ(center_bounds.width(), text_bounds.width()); EXPECT_EQ(center_bounds.height(), text_bounds.height()); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_CENTER | + gfx::Canvas::FORCE_LTR_DIRECTIONALITY; #if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); + EXPECT_EQ(expected_flags, flags); #else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_CENTER | - gfx::Canvas::NO_ELLIPSIS, - flags); + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); #endif label.SetHorizontalAlignment(Label::ALIGN_LEFT); @@ -511,14 +507,13 @@ TEST(LabelTest, DrawMultiLineString) { EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); EXPECT_EQ(center_bounds.width(), text_bounds.width()); EXPECT_EQ(center_bounds.height(), text_bounds.height()); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_LEFT | + gfx::Canvas::FORCE_LTR_DIRECTIONALITY; #if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT, flags); + EXPECT_EQ(expected_flags, flags); #else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_LEFT | - gfx::Canvas::NO_ELLIPSIS, - flags); + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); #endif label.SetHorizontalAlignment(Label::ALIGN_RIGHT); @@ -530,14 +525,13 @@ TEST(LabelTest, DrawMultiLineString) { EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); EXPECT_EQ(center_bounds.width(), text_bounds.width()); EXPECT_EQ(center_bounds.height(), text_bounds.height()); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_RIGHT | + gfx::Canvas::FORCE_RTL_DIRECTIONALITY; #if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT, flags); + EXPECT_EQ(expected_flags, flags); #else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_RIGHT | - gfx::Canvas::NO_ELLIPSIS, - flags); + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); #endif } |