Chromium Code Reviews| Index: ui/views/controls/label.cc |
| diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc |
| index f907f9f51ae1959ce9f051b9c277938bc8d9f45a..70130e8998712ee3fc07cacdc8b0dc2b86e2ee34 100644 |
| --- a/ui/views/controls/label.cc |
| +++ b/ui/views/controls/label.cc |
| @@ -112,12 +112,15 @@ void Label::ClearEmbellishing() { |
| } |
| void Label::SetHorizontalAlignment(Alignment alignment) { |
| - // If the View's UI layout is right-to-left and directionality_mode_ is |
| - // USE_UI_DIRECTIONALITY, we need to flip the alignment so that the alignment |
| - // settings take into account the text directionality. |
| - if (base::i18n::IsRTL() && (directionality_mode_ == USE_UI_DIRECTIONALITY) && |
| - (alignment != ALIGN_CENTER)) |
| + // TODO(msw): Change Alignment to LEADING/TRAILING? |
| + // TODO(msw): Check (and potentially flip) the alignment when setting text? |
| + // TODO(msw): Check against multi-line label regressions (not RenderText)... |
| + // If the string's directionality is right-to-left, flip the alignment. |
| + if (base::i18n::GetFirstStrongCharacterDirection(text()) == |
| + base::i18n::RIGHT_TO_LEFT && |
| + alignment != ALIGN_CENTER) { |
| alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; |
| + } |
|
xji
2012/07/10 19:59:57
so the alignment is also based on text directional
|
| if (horiz_alignment_ != alignment) { |
| horiz_alignment_ = alignment; |
| SchedulePaint(); |
| @@ -373,7 +376,6 @@ void Label::Init(const string16& text, const gfx::Font& font) { |
| elide_in_middle_ = false; |
| is_email_ = false; |
| collapse_when_hidden_ = false; |
| - directionality_mode_ = USE_UI_DIRECTIONALITY; |
| paint_as_focused_ = false; |
| has_focus_border_ = false; |
| enabled_shadow_color_ = 0; |
| @@ -444,15 +446,6 @@ int Label::ComputeDrawStringFlags() const { |
| if (SkColorGetA(background_color_) != 0xFF) |
| flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; |
| - if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) { |
| - base::i18n::TextDirection direction = |
| - base::i18n::GetFirstStrongCharacterDirection(text_); |
| - if (direction == base::i18n::RIGHT_TO_LEFT) |
| - flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; |
| - else |
| - flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
| - } |
| - |
| if (!is_multi_line_) |
| return flags; |
| @@ -499,18 +492,10 @@ void Label::CalculateDrawStringParams(string16* paint_text, |
| // preference and use it when calling ElideUrl. |
| *paint_text = |
| ui::ElideUrl(url_, font_, GetAvailableRect().width(), std::string()); |
| - |
| - // An URLs is always treated as an LTR text and therefore we should |
| - // explicitly mark it as such if the locale is RTL so that URLs containing |
| - // Hebrew or Arabic characters are displayed correctly. |
| - // |
| - // Note that we don't check the View's UI layout setting in order to |
| - // determine whether or not to insert the special Unicode formatting |
| - // 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. |
| - *paint_text = base::i18n::GetDisplayStringInLTRDirectionality( |
| - *paint_text); |
| + // Ensure that URLs have LTR directionality. |
| + // TODO(msw): Check cases like "/\x05d0", "://\x05d0". |
| + DCHECK_EQ(base::i18n::GetFirstStrongCharacterDirection(*paint_text), |
| + base::i18n::LEFT_TO_RIGHT); |
| } else if (is_email_) { |
| *paint_text = ui::ElideEmail(text_, font_, GetAvailableRect().width()); |
| } else if (elide_in_middle_) { |