OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/controls/button/label_button.h" | 5 #include "ui/views/controls/button/label_button.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
10 #include "ui/gfx/animation/throb_animation.h" | 10 #include "ui/gfx/animation/throb_animation.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { | 94 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { |
95 button_state_colors_[for_state] = color; | 95 button_state_colors_[for_state] = color; |
96 if (for_state == STATE_DISABLED) | 96 if (for_state == STATE_DISABLED) |
97 label_->SetDisabledColor(color); | 97 label_->SetDisabledColor(color); |
98 else if (for_state == state()) | 98 else if (for_state == state()) |
99 label_->SetEnabledColor(color); | 99 label_->SetEnabledColor(color); |
100 explicitly_set_colors_[for_state] = true; | 100 explicitly_set_colors_[for_state] = true; |
101 } | 101 } |
102 | 102 |
103 void LabelButton::SetHaloColor(SkColor color) { | 103 void LabelButton::SetTextShadows(const gfx::ShadowValues& shadows) { |
104 label_->set_halo_color(color); | 104 label_->set_shadows(shadows); |
| 105 } |
| 106 |
| 107 void LabelButton::SetTextSubpixelRenderingEnabled(bool enabled) { |
| 108 label_->set_subpixel_rendering_enabled(enabled); |
105 } | 109 } |
106 | 110 |
107 bool LabelButton::GetTextMultiLine() const { | 111 bool LabelButton::GetTextMultiLine() const { |
108 return label_->is_multi_line(); | 112 return label_->is_multi_line(); |
109 } | 113 } |
110 | 114 |
111 void LabelButton::SetTextMultiLine(bool text_multi_line) { | 115 void LabelButton::SetTextMultiLine(bool text_multi_line) { |
112 label_->SetMultiLine(text_multi_line); | 116 label_->SetMultiLine(text_multi_line); |
113 } | 117 } |
114 | 118 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 OnNativeThemeChanged(GetNativeTheme()); | 177 OnNativeThemeChanged(GetNativeTheme()); |
174 } | 178 } |
175 | 179 |
176 void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { | 180 void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { |
177 focus_painter_ = focus_painter.Pass(); | 181 focus_painter_ = focus_painter.Pass(); |
178 } | 182 } |
179 | 183 |
180 gfx::Size LabelButton::GetPreferredSize() const { | 184 gfx::Size LabelButton::GetPreferredSize() const { |
181 // Use a temporary label copy for sizing to avoid calculation side-effects. | 185 // Use a temporary label copy for sizing to avoid calculation side-effects. |
182 Label label(GetText(), cached_normal_font_list_); | 186 Label label(GetText(), cached_normal_font_list_); |
| 187 label.set_shadows(label_->shadows()); |
183 label.SetMultiLine(GetTextMultiLine()); | 188 label.SetMultiLine(GetTextMultiLine()); |
184 | 189 |
185 if (style() == STYLE_BUTTON) { | 190 if (style() == STYLE_BUTTON) { |
186 // Some text appears wider when rendered normally than when rendered bold. | 191 // Some text appears wider when rendered normally than when rendered bold. |
187 // Accommodate the widest, as buttons may show bold and shouldn't resize. | 192 // Accommodate the widest, as buttons may show bold and shouldn't resize. |
188 const int current_width = label.GetPreferredSize().width(); | 193 const int current_width = label.GetPreferredSize().width(); |
189 label.SetFontList(cached_bold_font_list_); | 194 label.SetFontList(cached_bold_font_list_); |
190 if (label.GetPreferredSize().width() < current_width) | 195 if (label.GetPreferredSize().width() < current_width) |
191 label.SetFontList(cached_normal_font_list_); | 196 label.SetFontList(cached_normal_font_list_); |
192 } | 197 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); | 257 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); |
253 if (adjusted_alignment == gfx::ALIGN_CENTER) { | 258 if (adjusted_alignment == gfx::ALIGN_CENTER) { |
254 const int total_width = image_size.width() + label_size.width() + | 259 const int total_width = image_size.width() + label_size.width() + |
255 ((image_size.width() > 0 && label_size.width() > 0) ? kSpacing : 0); | 260 ((image_size.width() > 0 && label_size.width() > 0) ? kSpacing : 0); |
256 image_origin.Offset((child_area.width() - total_width) / 2, 0); | 261 image_origin.Offset((child_area.width() - total_width) / 2, 0); |
257 } else if (adjusted_alignment == gfx::ALIGN_RIGHT) { | 262 } else if (adjusted_alignment == gfx::ALIGN_RIGHT) { |
258 image_origin.Offset(child_area.width() - image_size.width(), 0); | 263 image_origin.Offset(child_area.width() - image_size.width(), 0); |
259 } | 264 } |
260 | 265 |
261 gfx::Point label_origin(child_area.origin()); | 266 gfx::Point label_origin(child_area.origin()); |
262 if (!image_size.IsEmpty() &&adjusted_alignment != gfx::ALIGN_RIGHT) | 267 if (!image_size.IsEmpty() && adjusted_alignment != gfx::ALIGN_RIGHT) |
263 label_origin.set_x(image_origin.x() + image_size.width() + kSpacing); | 268 label_origin.set_x(image_origin.x() + image_size.width() + kSpacing); |
264 | 269 |
265 image_->SetBoundsRect(gfx::Rect(image_origin, image_size)); | 270 image_->SetBoundsRect(gfx::Rect(image_origin, image_size)); |
266 label_->SetBoundsRect(gfx::Rect(label_origin, label_size)); | 271 label_->SetBoundsRect(gfx::Rect(label_origin, label_size)); |
267 } | 272 } |
268 | 273 |
269 const char* LabelButton::GetClassName() const { | 274 const char* LabelButton::GetClassName() const { |
270 return kViewClassName; | 275 return kViewClassName; |
271 } | 276 } |
272 | 277 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 return ui::NativeTheme::kNormal; | 442 return ui::NativeTheme::kNormal; |
438 } | 443 } |
439 | 444 |
440 ui::NativeTheme::State LabelButton::GetForegroundThemeState( | 445 ui::NativeTheme::State LabelButton::GetForegroundThemeState( |
441 ui::NativeTheme::ExtraParams* params) const { | 446 ui::NativeTheme::ExtraParams* params) const { |
442 GetExtraParams(params); | 447 GetExtraParams(params); |
443 return ui::NativeTheme::kHovered; | 448 return ui::NativeTheme::kHovered; |
444 } | 449 } |
445 | 450 |
446 } // namespace views | 451 } // namespace views |
OLD | NEW |