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 "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 int h = font_.GetHeight(); | 70 int h = font_.GetHeight(); |
71 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, | 71 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, |
72 ComputeMultiLineFlags()); | 72 ComputeMultiLineFlags()); |
73 return h + GetInsets().height(); | 73 return h + GetInsets().height(); |
74 } | 74 } |
75 | 75 |
76 void Label::OnBoundsChanged() { | 76 void Label::OnBoundsChanged() { |
77 text_size_valid_ &= !is_multi_line_; | 77 text_size_valid_ &= !is_multi_line_; |
78 } | 78 } |
79 | 79 |
| 80 std::string Label::GetClassName() const { |
| 81 return kViewClassName; |
| 82 } |
| 83 |
80 void Label::OnPaint(gfx::Canvas* canvas) { | 84 void Label::OnPaint(gfx::Canvas* canvas) { |
81 OnPaintBackground(canvas); | 85 OnPaintBackground(canvas); |
82 | 86 |
83 std::wstring paint_text; | 87 std::wstring paint_text; |
84 gfx::Rect text_bounds; | 88 gfx::Rect text_bounds; |
85 int flags = 0; | 89 int flags = 0; |
86 CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 90 CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
87 PaintText(canvas, paint_text, text_bounds, flags); | 91 PaintText(canvas, paint_text, text_bounds, flags); |
88 } | 92 } |
89 | 93 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 url_set_ = true; | 125 url_set_ = true; |
122 text_size_valid_ = false; | 126 text_size_valid_ = false; |
123 PreferredSizeChanged(); | 127 PreferredSizeChanged(); |
124 SchedulePaint(); | 128 SchedulePaint(); |
125 } | 129 } |
126 | 130 |
127 const GURL Label::GetURL() const { | 131 const GURL Label::GetURL() const { |
128 return url_set_ ? url_ : GURL(UTF16ToUTF8(text_)); | 132 return url_set_ ? url_ : GURL(UTF16ToUTF8(text_)); |
129 } | 133 } |
130 | 134 |
| 135 void Label::SetColor(const SkColor& color) { |
| 136 color_ = color; |
| 137 } |
| 138 |
| 139 SkColor Label::GetColor() const { |
| 140 return color_; |
| 141 } |
| 142 |
131 void Label::SetHorizontalAlignment(Alignment alignment) { | 143 void Label::SetHorizontalAlignment(Alignment alignment) { |
132 // If the View's UI layout is right-to-left and rtl_alignment_mode_ is | 144 // If the View's UI layout is right-to-left and rtl_alignment_mode_ is |
133 // USE_UI_ALIGNMENT, we need to flip the alignment so that the alignment | 145 // USE_UI_ALIGNMENT, we need to flip the alignment so that the alignment |
134 // settings take into account the text directionality. | 146 // settings take into account the text directionality. |
135 if (base::i18n::IsRTL() && (rtl_alignment_mode_ == USE_UI_ALIGNMENT) && | 147 if (base::i18n::IsRTL() && (rtl_alignment_mode_ == USE_UI_ALIGNMENT) && |
136 (alignment != ALIGN_CENTER)) | 148 (alignment != ALIGN_CENTER)) |
137 alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; | 149 alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; |
138 if (horiz_alignment_ != alignment) { | 150 if (horiz_alignment_ != alignment) { |
139 horiz_alignment_ = alignment; | 151 horiz_alignment_ = alignment; |
140 SchedulePaint(); | 152 SchedulePaint(); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 font_, GetAvailableRect().width(), true)); | 457 font_, GetAvailableRect().width(), true)); |
446 } else { | 458 } else { |
447 *paint_text = UTF16ToWideHack(text_); | 459 *paint_text = UTF16ToWideHack(text_); |
448 } | 460 } |
449 | 461 |
450 *text_bounds = GetTextBounds(); | 462 *text_bounds = GetTextBounds(); |
451 *flags = ComputeMultiLineFlags(); | 463 *flags = ComputeMultiLineFlags(); |
452 } | 464 } |
453 | 465 |
454 } // namespace views | 466 } // namespace views |
OLD | NEW |