Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Unified Diff: ui/views/corewm/tooltip_aura.cc

Issue 864223004: Left-Align Tooltips (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698