blob: fd9d5641d5e38fca453140e5d9bbd386092723fb [file] [log] [blame]
[email protected]70e983cc2012-10-16 21:08:221// 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
3// found in the LICENSE file.
4
5#include "ui/views/controls/button/label_button.h"
6
7#include "base/logging.h"
8#include "grit/ui_resources.h"
[email protected]70e983cc2012-10-16 21:08:229#include "ui/base/resource/resource_bundle.h"
[email protected]ffb15d12013-09-15 17:29:3010#include "ui/gfx/animation/throb_animation.h"
[email protected]b518c3b2014-01-07 22:06:2911#include "ui/gfx/canvas.h"
[email protected]750f4492013-12-25 18:17:0912#include "ui/gfx/font_list.h"
[email protected]8858a832013-06-19 14:46:3013#include "ui/gfx/sys_color_change_listener.h"
[email protected]990e6222012-11-16 13:31:1814#include "ui/native_theme/native_theme.h"
[email protected]b518c3b2014-01-07 22:06:2915#include "ui/views/background.h"
[email protected]70e983cc2012-10-16 21:08:2216#include "ui/views/controls/button/label_button_border.h"
[email protected]1966d6d12013-12-05 04:19:3517#include "ui/views/painter.h"
[email protected]6d114932013-04-24 02:38:2018#include "ui/views/window/dialog_delegate.h"
[email protected]70e983cc2012-10-16 21:08:2219
[email protected]ea6fdc172014-01-22 23:34:0120#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
21#include "ui/views/linux_ui/linux_ui.h"
22#endif
23
[email protected]70e983cc2012-10-16 21:08:2224namespace {
25
26// The spacing between the icon and text.
[email protected]c5de33662012-10-27 22:37:3027const int kSpacing = 5;
[email protected]70e983cc2012-10-16 21:08:2228
[email protected]9d3086262014-03-10 21:40:2229#if !(defined(OS_LINUX) && !defined(OS_CHROMEOS))
[email protected]8858a832013-06-19 14:46:3030// Default text and shadow colors for STYLE_BUTTON.
31const SkColor kStyleButtonTextColor = SK_ColorBLACK;
32const SkColor kStyleButtonShadowColor = SK_ColorWHITE;
[email protected]9d3086262014-03-10 21:40:2233#endif
[email protected]8858a832013-06-19 14:46:3034
[email protected]70e983cc2012-10-16 21:08:2235} // namespace
36
[email protected]c5de33662012-10-27 22:37:3037namespace views {
38
[email protected]fe22ba12013-02-21 13:43:4839// static
[email protected]c77910fa2013-12-11 09:03:3040const int LabelButton::kHoverAnimationDurationMs = 170;
41
42// static
[email protected]f4167cf2013-05-26 23:36:1543const char LabelButton::kViewClassName[] = "LabelButton";
[email protected]fe22ba12013-02-21 13:43:4844
[email protected]2aadf212013-12-18 20:03:4445LabelButton::LabelButton(ButtonListener* listener, const base::string16& text)
[email protected]70e983cc2012-10-16 21:08:2246 : CustomButton(listener),
47 image_(new ImageView()),
[email protected]3e4efae2013-04-05 13:17:3648 label_(new Label()),
[email protected]379bc982012-12-19 19:56:5349 button_state_images_(),
50 button_state_colors_(),
51 explicitly_set_colors_(),
[email protected]e59fc52a2013-02-20 20:24:1152 is_default_(false),
[email protected]24d5c002014-05-09 07:07:0753 style_(STYLE_TEXTBUTTON),
54 border_is_themed_border_(true) {
[email protected]70e983cc2012-10-16 21:08:2255 SetAnimationDuration(kHoverAnimationDurationMs);
[email protected]3e4efae2013-04-05 13:17:3656 SetText(text);
[email protected]22a96102014-01-28 06:36:0957 SetFontList(gfx::FontList());
[email protected]70e983cc2012-10-16 21:08:2258
59 AddChildView(image_);
60 image_->set_interactive(false);
61
62 AddChildView(label_);
63 label_->SetAutoColorReadabilityEnabled(false);
[email protected]cc563f02012-11-07 17:37:3664 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
[email protected]70e983cc2012-10-16 21:08:2265
[email protected]fe22ba12013-02-21 13:43:4866 // Initialize the colors, border, and layout.
67 SetStyle(style_);
[email protected]cd70b3e2013-04-03 20:01:3768
69 SetAccessibleName(text);
[email protected]70e983cc2012-10-16 21:08:2270}
71
72LabelButton::~LabelButton() {}
73
74const gfx::ImageSkia& LabelButton::GetImage(ButtonState for_state) {
[email protected]fca8dc02012-11-14 16:25:5675 if (for_state != STATE_NORMAL && button_state_images_[for_state].isNull())
76 return button_state_images_[STATE_NORMAL];
[email protected]70e983cc2012-10-16 21:08:2277 return button_state_images_[for_state];
78}
79
80void LabelButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) {
81 button_state_images_[for_state] = image;
[email protected]987b7662013-05-23 10:45:4982 UpdateImage();
[email protected]70e983cc2012-10-16 21:08:2283}
84
[email protected]2aadf212013-12-18 20:03:4485const base::string16& LabelButton::GetText() const {
[email protected]70e983cc2012-10-16 21:08:2286 return label_->text();
87}
88
[email protected]2aadf212013-12-18 20:03:4489void LabelButton::SetText(const base::string16& text) {
[email protected]3e4efae2013-04-05 13:17:3690 SetAccessibleName(text);
[email protected]70e983cc2012-10-16 21:08:2291 label_->SetText(text);
92}
93
94void LabelButton::SetTextColor(ButtonState for_state, SkColor color) {
95 button_state_colors_[for_state] = color;
[email protected]fca8dc02012-11-14 16:25:5696 if (for_state == STATE_DISABLED)
[email protected]70e983cc2012-10-16 21:08:2297 label_->SetDisabledColor(color);
98 else if (for_state == state())
99 label_->SetEnabledColor(color);
[email protected]204b2082012-11-07 17:53:03100 explicitly_set_colors_[for_state] = true;
[email protected]70e983cc2012-10-16 21:08:22101}
102
103bool LabelButton::GetTextMultiLine() const {
104 return label_->is_multi_line();
105}
106
107void LabelButton::SetTextMultiLine(bool text_multi_line) {
108 label_->SetMultiLine(text_multi_line);
109}
110
[email protected]750f4492013-12-25 18:17:09111const gfx::FontList& LabelButton::GetFontList() const {
112 return label_->font_list();
113}
114
115void LabelButton::SetFontList(const gfx::FontList& font_list) {
[email protected]22a96102014-01-28 06:36:09116 cached_normal_font_list_ = font_list;
[email protected]d7e92bb2014-02-05 08:50:50117 cached_bold_font_list_ = font_list.DeriveWithStyle(
118 font_list.GetFontStyle() | gfx::Font::BOLD);
[email protected]22a96102014-01-28 06:36:09119
120 // STYLE_BUTTON uses bold text to indicate default buttons.
121 label_->SetFontList(
122 style_ == STYLE_BUTTON && is_default_ ?
123 cached_bold_font_list_ : cached_normal_font_list_);
[email protected]750f4492013-12-25 18:17:09124}
125
[email protected]252cec32013-09-24 03:17:52126void LabelButton::SetElideBehavior(Label::ElideBehavior elide_behavior) {
127 label_->SetElideBehavior(elide_behavior);
128}
129
[email protected]cc563f02012-11-07 17:37:36130gfx::HorizontalAlignment LabelButton::GetHorizontalAlignment() const {
[email protected]70e983cc2012-10-16 21:08:22131 return label_->horizontal_alignment();
132}
133
[email protected]cc563f02012-11-07 17:37:36134void LabelButton::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
[email protected]70e983cc2012-10-16 21:08:22135 label_->SetHorizontalAlignment(alignment);
136 InvalidateLayout();
137}
138
[email protected]e59fc52a2013-02-20 20:24:11139void LabelButton::SetIsDefault(bool is_default) {
140 if (is_default == is_default_)
[email protected]70e983cc2012-10-16 21:08:22141 return;
[email protected]e59fc52a2013-02-20 20:24:11142 is_default_ = is_default;
[email protected]70e983cc2012-10-16 21:08:22143 ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE);
[email protected]e59fc52a2013-02-20 20:24:11144 is_default_ ? AddAccelerator(accel) : RemoveAccelerator(accel);
[email protected]640bff12013-04-17 21:08:14145
146 // STYLE_BUTTON uses bold text to indicate default buttons.
147 if (style_ == STYLE_BUTTON) {
[email protected]750f4492013-12-25 18:17:09148 label_->SetFontList(
[email protected]22a96102014-01-28 06:36:09149 is_default ? cached_bold_font_list_ : cached_normal_font_list_);
[email protected]640bff12013-04-17 21:08:14150 }
[email protected]70e983cc2012-10-16 21:08:22151}
152
[email protected]fe22ba12013-02-21 13:43:48153void LabelButton::SetStyle(ButtonStyle style) {
154 style_ = style;
[email protected]fe22ba12013-02-21 13:43:48155 // Inset the button focus rect from the actual border; roughly match Windows.
[email protected]1966d6d12013-12-05 04:19:35156 if (style == STYLE_BUTTON) {
157 SetFocusPainter(scoped_ptr<Painter>());
158 } else {
159 SetFocusPainter(Painter::CreateDashedFocusPainterWithInsets(
160 gfx::Insets(3, 3, 3, 3)));
161 }
[email protected]ab821b12014-01-15 14:12:57162 if (style == STYLE_BUTTON) {
[email protected]d0abd282013-02-28 23:59:08163 label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
[email protected]505df7b2013-12-16 14:07:19164 SetFocusable(true);
[email protected]640bff12013-04-17 21:08:14165 }
[email protected]8858a832013-06-19 14:46:30166 if (style == STYLE_BUTTON)
[email protected]31012722013-06-12 22:00:10167 set_min_size(gfx::Size(70, 33));
[email protected]fd42d132014-01-15 23:19:13168
[email protected]24d5c002014-05-09 07:07:07169 OnNativeThemeChanged(GetNativeTheme());
[email protected]204b2082012-11-07 17:53:03170}
171
[email protected]1966d6d12013-12-05 04:19:35172void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) {
173 focus_painter_ = focus_painter.Pass();
174}
175
[email protected]e1b62b72014-05-20 17:24:44176gfx::Size LabelButton::GetPreferredSize() const {
[email protected]9baef622013-05-14 05:30:46177 // Use a temporary label copy for sizing to avoid calculation side-effects.
[email protected]22a96102014-01-28 06:36:09178 Label label(GetText(), cached_normal_font_list_);
[email protected]9baef622013-05-14 05:30:46179 label.SetMultiLine(GetTextMultiLine());
[email protected]640bff12013-04-17 21:08:14180
[email protected]5b7355b2013-07-17 04:44:54181 if (style() == STYLE_BUTTON) {
182 // Some text appears wider when rendered normally than when rendered bold.
183 // Accommodate the widest, as buttons may show bold and shouldn't resize.
184 const int current_width = label.GetPreferredSize().width();
[email protected]22a96102014-01-28 06:36:09185 label.SetFontList(cached_bold_font_list_);
[email protected]5b7355b2013-07-17 04:44:54186 if (label.GetPreferredSize().width() < current_width)
[email protected]22a96102014-01-28 06:36:09187 label.SetFontList(cached_normal_font_list_);
[email protected]5b7355b2013-07-17 04:44:54188 }
189
[email protected]9baef622013-05-14 05:30:46190 // Resize multi-line labels given the current limited available width.
[email protected]7f39bb692013-01-07 23:08:16191 const gfx::Size image_size(image_->GetPreferredSize());
[email protected]9baef622013-05-14 05:30:46192 const int image_width = image_size.width();
193 if (GetTextMultiLine() && (width() > image_width + kSpacing))
194 label.SizeToFit(width() - image_width - (image_width > 0 ? kSpacing : 0));
[email protected]7f39bb692013-01-07 23:08:16195
196 // Calculate the required size.
[email protected]9baef622013-05-14 05:30:46197 gfx::Size size(label.GetPreferredSize());
198 if (image_width > 0 && size.width() > 0)
[email protected]7f39bb692013-01-07 23:08:16199 size.Enlarge(kSpacing, 0);
[email protected]a4a08d02013-05-30 00:18:00200 size.SetToMax(gfx::Size(0, image_size.height()));
[email protected]9baef622013-05-14 05:30:46201 const gfx::Insets insets(GetInsets());
202 size.Enlarge(image_size.width() + insets.width(), insets.height());
[email protected]640bff12013-04-17 21:08:14203
[email protected]7ad32c12013-11-23 01:39:40204 // Make the size at least as large as the minimum size needed by the border.
[email protected]7689cfb2014-02-16 22:18:03205 size.SetToMax(border() ? border()->GetMinimumSize() : gfx::Size());
[email protected]7ad32c12013-11-23 01:39:40206
[email protected]7f39bb692013-01-07 23:08:16207 // Increase the minimum size monotonically with the preferred size.
[email protected]a4a08d02013-05-30 00:18:00208 size.SetToMax(min_size_);
[email protected]7f39bb692013-01-07 23:08:16209 min_size_ = size;
210
211 // Return the largest known size clamped to the maximum size (if valid).
212 if (max_size_.width() > 0)
213 size.set_width(std::min(max_size_.width(), size.width()));
214 if (max_size_.height() > 0)
215 size.set_height(std::min(max_size_.height(), size.height()));
216 return size;
217}
218
[email protected]987b7662013-05-23 10:45:49219void LabelButton::Layout() {
220 gfx::HorizontalAlignment adjusted_alignment = GetHorizontalAlignment();
221 if (base::i18n::IsRTL() && adjusted_alignment != gfx::ALIGN_CENTER)
222 adjusted_alignment = (adjusted_alignment == gfx::ALIGN_LEFT) ?
223 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT;
224
225 gfx::Rect child_area(GetLocalBounds());
226 child_area.Inset(GetInsets());
227
228 gfx::Size image_size(image_->GetPreferredSize());
[email protected]7689cfb2014-02-16 22:18:03229 image_size.SetToMin(child_area.size());
[email protected]987b7662013-05-23 10:45:49230
231 // The label takes any remaining width after sizing the image, unless both
232 // views are centered. In that case, using the tighter preferred label width
233 // avoids wasted space within the label that would look like awkward padding.
234 gfx::Size label_size(child_area.size());
235 if (!image_size.IsEmpty() && !label_size.IsEmpty()) {
236 label_size.set_width(
237 std::max(child_area.width() - image_size.width() - kSpacing, 0));
238 if (adjusted_alignment == gfx::ALIGN_CENTER) {
239 // Ensure multi-line labels paired with images use their available width.
240 if (GetTextMultiLine())
241 label_->SizeToFit(label_size.width());
242 label_size.set_width(
243 std::min(label_size.width(), label_->GetPreferredSize().width()));
244 }
245 }
246
247 gfx::Point image_origin(child_area.origin());
248 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2);
249 if (adjusted_alignment == gfx::ALIGN_CENTER) {
250 const int total_width = image_size.width() + label_size.width() +
251 ((image_size.width() > 0 && label_size.width() > 0) ? kSpacing : 0);
252 image_origin.Offset((child_area.width() - total_width) / 2, 0);
253 } else if (adjusted_alignment == gfx::ALIGN_RIGHT) {
254 image_origin.Offset(child_area.width() - image_size.width(), 0);
255 }
256
257 gfx::Point label_origin(child_area.origin());
258 if (!image_size.IsEmpty() &&adjusted_alignment != gfx::ALIGN_RIGHT)
259 label_origin.set_x(image_origin.x() + image_size.width() + kSpacing);
260
261 image_->SetBoundsRect(gfx::Rect(image_origin, image_size));
262 label_->SetBoundsRect(gfx::Rect(label_origin, label_size));
263}
264
[email protected]707bd372013-05-09 08:32:27265const char* LabelButton::GetClassName() const {
[email protected]fe22ba12013-02-21 13:43:48266 return kViewClassName;
267}
268
[email protected]beb1dc02014-05-14 23:03:48269scoped_ptr<Border> LabelButton::CreateDefaultBorder() const {
270 return scoped_ptr<Border>(new LabelButtonBorder(style_));
271}
272
[email protected]24d5c002014-05-09 07:07:07273void LabelButton::SetBorder(scoped_ptr<Border> border) {
274 border_is_themed_border_ = false;
275 View::SetBorder(border.Pass());
276}
277
[email protected]1966d6d12013-12-05 04:19:35278void LabelButton::OnPaint(gfx::Canvas* canvas) {
279 View::OnPaint(canvas);
280 Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
281}
282
[email protected]73ecc1802013-12-04 07:09:49283void LabelButton::OnFocus() {
284 View::OnFocus();
285 // Typically the border renders differently when focused.
286 SchedulePaint();
287}
288
289void LabelButton::OnBlur() {
290 View::OnBlur();
291 // Typically the border renders differently when focused.
292 SchedulePaint();
293}
294
[email protected]987b7662013-05-23 10:45:49295void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
296 params->button.checked = false;
297 params->button.indeterminate = false;
298 params->button.is_default = is_default_;
299 params->button.is_focused = HasFocus() && IsAccessibilityFocusable();
[email protected]ab821b12014-01-15 14:12:57300 params->button.has_border = false;
[email protected]987b7662013-05-23 10:45:49301 params->button.classic_state = 0;
[email protected]b518c3b2014-01-07 22:06:29302 params->button.background_color = label_->background_color();
[email protected]987b7662013-05-23 10:45:49303}
304
[email protected]379bc982012-12-19 19:56:53305void LabelButton::ResetColorsFromNativeTheme() {
[email protected]204b2082012-11-07 17:53:03306 const ui::NativeTheme* theme = GetNativeTheme();
[email protected]fca8dc02012-11-14 16:25:56307 SkColor colors[STATE_COUNT] = {
[email protected]1b768f8f2013-05-17 01:16:52308 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor),
309 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
310 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHoverColor),
311 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonDisabledColor),
[email protected]70e983cc2012-10-16 21:08:22312 };
[email protected]644f4fb2013-03-01 21:14:34313
314 // Certain styles do not change text color when hovered or pressed.
[email protected]8858a832013-06-19 14:46:30315 bool constant_text_color = false;
[email protected]8858a832013-06-19 14:46:30316 // Use hardcoded colors for inverted color scheme support and STYLE_BUTTON.
317 if (gfx::IsInvertedColorScheme()) {
318 constant_text_color = true;
319 colors[STATE_NORMAL] = SK_ColorWHITE;
320 label_->SetBackgroundColor(SK_ColorBLACK);
[email protected]b518c3b2014-01-07 22:06:29321 label_->set_background(Background::CreateSolidBackground(SK_ColorBLACK));
[email protected]8858a832013-06-19 14:46:30322 label_->SetAutoColorReadabilityEnabled(true);
323 label_->ClearEmbellishing();
324 } else if (style() == STYLE_BUTTON) {
[email protected]9d3086262014-03-10 21:40:22325 // TODO(erg): This is disabled on desktop linux because of the binary asset
326 // confusion. These details should either be pushed into ui::NativeThemeWin
327 // or should be obsoleted by rendering buttons with paint calls instead of
328 // with static assets. http://crbug.com/350498
329#if !(defined(OS_LINUX) && !defined(OS_CHROMEOS))
[email protected]8858a832013-06-19 14:46:30330 constant_text_color = true;
331 colors[STATE_NORMAL] = kStyleButtonTextColor;
[email protected]763f83b2013-09-17 18:26:32332 label_->SetBackgroundColor(theme->GetSystemColor(
333 ui::NativeTheme::kColorId_ButtonBackgroundColor));
[email protected]8858a832013-06-19 14:46:30334 label_->SetAutoColorReadabilityEnabled(false);
335 label_->SetShadowColors(kStyleButtonShadowColor, kStyleButtonShadowColor);
336 label_->SetShadowOffset(0, 1);
[email protected]9d3086262014-03-10 21:40:22337#endif
338 label_->set_background(NULL);
[email protected]b518c3b2014-01-07 22:06:29339 } else {
340 label_->set_background(NULL);
[email protected]8858a832013-06-19 14:46:30341 }
342
[email protected]644f4fb2013-03-01 21:14:34343 if (constant_text_color)
344 colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL];
345
[email protected]fca8dc02012-11-14 16:25:56346 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) {
[email protected]379bc982012-12-19 19:56:53347 if (!explicitly_set_colors_[state]) {
[email protected]204b2082012-11-07 17:53:03348 SetTextColor(static_cast<ButtonState>(state), colors[state]);
349 explicitly_set_colors_[state] = false;
350 }
351 }
[email protected]70e983cc2012-10-16 21:08:22352}
353
[email protected]763f83b2013-09-17 18:26:32354void LabelButton::UpdateImage() {
355 image_->SetImage(GetImage(state()));
356}
357
[email protected]beb1dc02014-05-14 23:03:48358void LabelButton::UpdateThemedBorder() {
[email protected]24d5c002014-05-09 07:07:07359 // Don't override borders set by others.
360 if (!border_is_themed_border_)
361 return;
362
[email protected]beb1dc02014-05-14 23:03:48363 scoped_ptr<Border> label_button_border = CreateDefaultBorder();
364
[email protected]ea6fdc172014-01-22 23:34:01365#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
366 views::LinuxUI* linux_ui = views::LinuxUI::instance();
367 if (linux_ui) {
[email protected]9137e732014-01-24 22:49:41368 SetBorder(linux_ui->CreateNativeBorder(this, label_button_border.Pass()));
[email protected]ea6fdc172014-01-22 23:34:01369 } else
370#endif
371 {
[email protected]9137e732014-01-24 22:49:41372 SetBorder(label_button_border.Pass());
[email protected]ea6fdc172014-01-22 23:34:01373 }
[email protected]24d5c002014-05-09 07:07:07374
375 border_is_themed_border_ = true;
[email protected]ea6fdc172014-01-22 23:34:01376}
377
[email protected]70e983cc2012-10-16 21:08:22378void LabelButton::StateChanged() {
379 const gfx::Size previous_image_size(image_->GetPreferredSize());
[email protected]987b7662013-05-23 10:45:49380 UpdateImage();
[email protected]70e983cc2012-10-16 21:08:22381 const SkColor color = button_state_colors_[state()];
[email protected]fca8dc02012-11-14 16:25:56382 if (state() != STATE_DISABLED && label_->enabled_color() != color)
[email protected]70e983cc2012-10-16 21:08:22383 label_->SetEnabledColor(color);
[email protected]4e88e352012-12-04 19:12:09384 label_->SetEnabled(state() != STATE_DISABLED);
[email protected]70e983cc2012-10-16 21:08:22385 if (image_->GetPreferredSize() != previous_image_size)
386 Layout();
387}
388
[email protected]70e983cc2012-10-16 21:08:22389void LabelButton::ChildPreferredSizeChanged(View* child) {
390 PreferredSizeChanged();
391}
392
[email protected]204b2082012-11-07 17:53:03393void LabelButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
[email protected]379bc982012-12-19 19:56:53394 ResetColorsFromNativeTheme();
[email protected]beb1dc02014-05-14 23:03:48395 UpdateThemedBorder();
[email protected]24d5c002014-05-09 07:07:07396 // Invalidate the layout to pickup the new insets from the border.
397 InvalidateLayout();
[email protected]204b2082012-11-07 17:53:03398}
399
[email protected]70e983cc2012-10-16 21:08:22400ui::NativeTheme::Part LabelButton::GetThemePart() const {
401 return ui::NativeTheme::kPushButton;
402}
403
404gfx::Rect LabelButton::GetThemePaintRect() const {
405 return GetLocalBounds();
406}
407
408ui::NativeTheme::State LabelButton::GetThemeState(
409 ui::NativeTheme::ExtraParams* params) const {
410 GetExtraParams(params);
[email protected]987b7662013-05-23 10:45:49411 switch (state()) {
[email protected]fca8dc02012-11-14 16:25:56412 case STATE_NORMAL: return ui::NativeTheme::kNormal;
413 case STATE_HOVERED: return ui::NativeTheme::kHovered;
414 case STATE_PRESSED: return ui::NativeTheme::kPressed;
415 case STATE_DISABLED: return ui::NativeTheme::kDisabled;
416 case STATE_COUNT: NOTREACHED() << "Unknown state: " << state();
[email protected]70e983cc2012-10-16 21:08:22417 }
418 return ui::NativeTheme::kNormal;
419}
420
[email protected]ffb15d12013-09-15 17:29:30421const gfx::Animation* LabelButton::GetThemeAnimation() const {
[email protected]70e983cc2012-10-16 21:08:22422 return hover_animation_.get();
423}
424
425ui::NativeTheme::State LabelButton::GetBackgroundThemeState(
426 ui::NativeTheme::ExtraParams* params) const {
427 GetExtraParams(params);
428 return ui::NativeTheme::kNormal;
429}
430
431ui::NativeTheme::State LabelButton::GetForegroundThemeState(
432 ui::NativeTheme::ExtraParams* params) const {
433 GetExtraParams(params);
434 return ui::NativeTheme::kHovered;
435}
436
[email protected]70e983cc2012-10-16 21:08:22437} // namespace views