OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/corewm/tooltip_aura.h" | 5 #include "ui/views/corewm/tooltip_aura.h" |
6 | 6 |
7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
9 #include "ui/aura/window_tree_host.h" | 9 #include "ui/aura/window_tree_host.h" |
10 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 // auto-parented to the right container. | 35 // auto-parented to the right container. |
36 params.type = views::Widget::InitParams::TYPE_TOOLTIP; | 36 params.type = views::Widget::InitParams::TYPE_TOOLTIP; |
37 params.context = tooltip_window; | 37 params.context = tooltip_window; |
38 DCHECK(params.context); | 38 DCHECK(params.context); |
39 params.keep_on_top = true; | 39 params.keep_on_top = true; |
40 params.accept_events = false; | 40 params.accept_events = false; |
41 widget->Init(params); | 41 widget->Init(params); |
42 return widget; | 42 return widget; |
43 } | 43 } |
44 | 44 |
45 // Returns the appropriate label alignment based on the Locale direction and the | |
46 // text direction. | |
47 gfx::HorizontalAlignment GetTextHorizontalAlignment(const base::string16 text) { | |
48 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
| |
49 gfx::HorizontalAlignment result = gfx::ALIGN_LEFT; | |
50 | |
51 // The Label::SetHorizontalAlignment() will interpret right as left and vice | |
52 // versa based on the UI layout. we need to account for that when the text | |
53 // itself needs to be aligned in the opposite direction. | |
54 if (base::i18n::IsRTL()) { | |
55 result = (dir == base::i18n::RIGHT_TO_LEFT) ? | |
56 gfx::ALIGN_LEFT : gfx::ALIGN_RIGHT; | |
57 } else { | |
58 result = (dir == base::i18n::RIGHT_TO_LEFT) ? | |
59 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; | |
60 } | |
61 | |
62 return result; | |
63 } | |
64 | |
45 } // namespace | 65 } // namespace |
46 | 66 |
47 namespace views { | 67 namespace views { |
48 namespace corewm { | 68 namespace corewm { |
49 | 69 |
50 TooltipAura::TooltipAura(gfx::ScreenType screen_type) | 70 TooltipAura::TooltipAura(gfx::ScreenType screen_type) |
51 : screen_type_(screen_type), | 71 : screen_type_(screen_type), |
52 widget_(NULL), | 72 widget_(NULL), |
53 tooltip_window_(NULL) { | 73 tooltip_window_(NULL) { |
54 label_.set_owned_by_client(); | 74 label_.set_owned_by_client(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 void TooltipAura::SetText(aura::Window* window, | 203 void TooltipAura::SetText(aura::Window* window, |
184 const base::string16& tooltip_text, | 204 const base::string16& tooltip_text, |
185 const gfx::Point& location) { | 205 const gfx::Point& location) { |
186 tooltip_window_ = window; | 206 tooltip_window_ = window; |
187 int max_width = 0; | 207 int max_width = 0; |
188 int line_count = 0; | 208 int line_count = 0; |
189 base::string16 trimmed_text(tooltip_text); | 209 base::string16 trimmed_text(tooltip_text); |
190 TrimTooltipToFit(label_.font_list(), GetMaxWidth(location), &trimmed_text, | 210 TrimTooltipToFit(label_.font_list(), GetMaxWidth(location), &trimmed_text, |
191 &max_width, &line_count); | 211 &max_width, &line_count); |
192 label_.SetText(trimmed_text); | 212 label_.SetText(trimmed_text); |
213 label_.SetHorizontalAlignment(GetTextHorizontalAlignment(trimmed_text)); | |
193 | 214 |
194 if (!widget_) { | 215 if (!widget_) { |
195 widget_ = CreateTooltipWidget(tooltip_window_); | 216 widget_ = CreateTooltipWidget(tooltip_window_); |
196 widget_->SetContentsView(&label_); | 217 widget_->SetContentsView(&label_); |
197 widget_->AddObserver(this); | 218 widget_->AddObserver(this); |
198 } | 219 } |
199 | 220 |
200 label_.SizeToFit(max_width + label_.GetInsets().width()); | 221 label_.SizeToFit(max_width + label_.GetInsets().width()); |
201 SetTooltipBounds(location, label_.size()); | 222 SetTooltipBounds(location, label_.size()); |
202 | 223 |
(...skipping 26 matching lines...) Expand all Loading... | |
229 } | 250 } |
230 | 251 |
231 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { | 252 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { |
232 DCHECK_EQ(widget_, widget); | 253 DCHECK_EQ(widget_, widget); |
233 widget_ = NULL; | 254 widget_ = NULL; |
234 tooltip_window_ = NULL; | 255 tooltip_window_ = NULL; |
235 } | 256 } |
236 | 257 |
237 } // namespace corewm | 258 } // namespace corewm |
238 } // namespace views | 259 } // namespace views |
OLD | NEW |