Index: ui/views/corewm/tooltip_aura.cc |
diff --git a/ui/views/corewm/tooltip_aura.cc b/ui/views/corewm/tooltip_aura.cc |
index 02117a8593d11df38dc6cf2a98e4d8a0ff0d50e8..27179e09ece82d4842ec243327d6594fe485c832 100644 |
--- a/ui/views/corewm/tooltip_aura.cc |
+++ b/ui/views/corewm/tooltip_aura.cc |
@@ -42,6 +42,26 @@ views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) { |
return widget; |
} |
+// Returns the appropriate label alignment based on the Locale direction and the |
+// text direction. |
+gfx::HorizontalAlignment GetTextHorizontalAlignment(const base::string16 text) { |
+ base::i18n::TextDirection dir = base::i18n::GetStringDirection(text); |
sky
2015/01/28 21:24:59
I think you should be able to set the alignment to
afakhry
2015/01/28 21:36:13
That's true, but Label::SetHorizontalAlignment() o
|
+ gfx::HorizontalAlignment result = gfx::ALIGN_LEFT; |
+ |
+ // The Label::SetHorizontalAlignment() will interpret right as left and vice |
+ // versa based on the UI layout. we need to account for that when the text |
+ // itself needs to be aligned in the opposite direction. |
+ if (base::i18n::IsRTL()) { |
+ result = (dir == base::i18n::RIGHT_TO_LEFT) ? |
+ gfx::ALIGN_LEFT : gfx::ALIGN_RIGHT; |
+ } else { |
+ result = (dir == base::i18n::RIGHT_TO_LEFT) ? |
+ gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; |
+ } |
+ |
+ return result; |
+} |
+ |
} // namespace |
namespace views { |
@@ -190,6 +210,7 @@ void TooltipAura::SetText(aura::Window* window, |
TrimTooltipToFit(label_.font_list(), GetMaxWidth(location), &trimmed_text, |
&max_width, &line_count); |
label_.SetText(trimmed_text); |
+ label_.SetHorizontalAlignment(GetTextHorizontalAlignment(trimmed_text)); |
if (!widget_) { |
widget_ = CreateTooltipWidget(tooltip_window_); |