OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/label.h" | 5 #include "views/controls/label.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 bool Label::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { | 177 bool Label::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { |
178 DCHECK(tooltip); | 178 DCHECK(tooltip); |
179 | 179 |
180 // If a tooltip has been explicitly set, use it. | 180 // If a tooltip has been explicitly set, use it. |
181 if (!tooltip_text_.empty()) { | 181 if (!tooltip_text_.empty()) { |
182 tooltip->assign(tooltip_text_); | 182 tooltip->assign(tooltip_text_); |
183 return true; | 183 return true; |
184 } | 184 } |
185 | 185 |
186 // Show the full text if the text does not fit. | 186 // Show the full text if the text does not fit. |
187 if (!is_multi_line_ && font_.GetStringWidth(text_) > width()) { | 187 if (!is_multi_line_ && |
| 188 (font_.GetStringWidth(text_) > GetAvailableRect().width())) { |
188 *tooltip = text_; | 189 *tooltip = text_; |
189 return true; | 190 return true; |
190 } | 191 } |
191 return false; | 192 return false; |
192 } | 193 } |
193 | 194 |
194 void Label::OnMouseMoved(const MouseEvent& e) { | 195 void Label::OnMouseMoved(const MouseEvent& e) { |
195 UpdateContainsMouse(e); | 196 UpdateContainsMouse(e); |
196 } | 197 } |
197 | 198 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 417 } |
417 | 418 |
418 void Label::CalculateDrawStringParams(std::wstring* paint_text, | 419 void Label::CalculateDrawStringParams(std::wstring* paint_text, |
419 gfx::Rect* text_bounds, | 420 gfx::Rect* text_bounds, |
420 int* flags) const { | 421 int* flags) const { |
421 DCHECK(paint_text && text_bounds && flags); | 422 DCHECK(paint_text && text_bounds && flags); |
422 | 423 |
423 if (url_set_) { | 424 if (url_set_) { |
424 // TODO(jungshik) : Figure out how to get 'intl.accept_languages' | 425 // TODO(jungshik) : Figure out how to get 'intl.accept_languages' |
425 // preference and use it when calling ElideUrl. | 426 // preference and use it when calling ElideUrl. |
426 *paint_text = UTF16ToWideHack(gfx::ElideUrl(url_, font_, width(), | 427 *paint_text = UTF16ToWideHack( |
427 std::wstring())); | 428 gfx::ElideUrl(url_, font_, GetAvailableRect().width(), std::wstring())); |
428 | 429 |
429 // An URLs is always treated as an LTR text and therefore we should | 430 // An URLs is always treated as an LTR text and therefore we should |
430 // explicitly mark it as such if the locale is RTL so that URLs containing | 431 // explicitly mark it as such if the locale is RTL so that URLs containing |
431 // Hebrew or Arabic characters are displayed correctly. | 432 // Hebrew or Arabic characters are displayed correctly. |
432 // | 433 // |
433 // Note that we don't check the View's UI layout setting in order to | 434 // Note that we don't check the View's UI layout setting in order to |
434 // determine whether or not to insert the special Unicode formatting | 435 // determine whether or not to insert the special Unicode formatting |
435 // characters. We use the locale settings because an URL is always treated | 436 // characters. We use the locale settings because an URL is always treated |
436 // as an LTR string, even if its containing view does not use an RTL UI | 437 // as an LTR string, even if its containing view does not use an RTL UI |
437 // layout. | 438 // layout. |
438 *paint_text = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality( | 439 *paint_text = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality( |
439 WideToUTF16(*paint_text))); | 440 WideToUTF16(*paint_text))); |
440 } else if (elide_in_middle_) { | 441 } else if (elide_in_middle_) { |
441 *paint_text = UTF16ToWideHack(gfx::ElideText(WideToUTF16Hack(text_), | 442 *paint_text = UTF16ToWideHack(gfx::ElideText(WideToUTF16Hack(text_), |
442 font_, width(), true)); | 443 font_, GetAvailableRect().width(), true)); |
443 } else { | 444 } else { |
444 *paint_text = text_; | 445 *paint_text = text_; |
445 } | 446 } |
446 | 447 |
447 *text_bounds = GetTextBounds(); | 448 *text_bounds = GetTextBounds(); |
448 *flags = ComputeMultiLineFlags(); | 449 *flags = ComputeMultiLineFlags(); |
449 } | 450 } |
450 | 451 |
451 } // namespace views | 452 } // namespace views |
OLD | NEW |