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
3 // found in the LICENSE file.
5 #include "ui/views/controls/button/blue_button.h"
7 #include "ui/base/resource/resource_bundle.h"
8 #include "ui/gfx/geometry/vector2d.h"
9 #include "ui/gfx/sys_color_change_listener.h"
10 #include "ui/resources/grit/ui_resources.h"
11 #include "ui/views/controls/button/label_button_border.h"
16 const char BlueButton::kViewClassName
[] = "views/BlueButton";
18 BlueButton::BlueButton(ButtonListener
* listener
, const base::string16
& text
)
19 : LabelButton(listener
, text
) {
20 // Inherit STYLE_BUTTON insets, minimum size, alignment, etc.
21 SetStyle(STYLE_BUTTON
);
25 BlueButton::~BlueButton() {}
27 void BlueButton::ResetColorsFromNativeTheme() {
28 LabelButton::ResetColorsFromNativeTheme();
29 if (!gfx::IsInvertedColorScheme()) {
30 SetTextColor(STATE_NORMAL
, GetNativeTheme()->
31 GetSystemColor(ui::NativeTheme::kColorId_BlueButtonEnabledColor
));
32 SetTextColor(STATE_HOVERED
, GetNativeTheme()->
33 GetSystemColor(ui::NativeTheme::kColorId_BlueButtonHoverColor
));
34 SetTextColor(STATE_PRESSED
, GetNativeTheme()->
35 GetSystemColor(ui::NativeTheme::kColorId_BlueButtonPressedColor
));
36 SetTextColor(STATE_DISABLED
, GetNativeTheme()->
37 GetSystemColor(ui::NativeTheme::kColorId_BlueButtonDisabledColor
));
39 label()->SetShadows(gfx::ShadowValues(
41 gfx::Vector2d(0, 1), 0,
42 GetNativeTheme()->GetSystemColor(
43 ui::NativeTheme::kColorId_BlueButtonShadowColor
))));
47 const char* BlueButton::GetClassName() const {
48 return BlueButton::kViewClassName
;
51 scoped_ptr
<LabelButtonBorder
> BlueButton::CreateDefaultBorder() const {
52 // Insets for splitting the images.
53 const gfx::Insets
insets(5, 5, 5, 5);
54 scoped_ptr
<LabelButtonBorder
> button_border(new LabelButtonBorder(style()));
55 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
56 button_border
->SetPainter(false, STATE_NORMAL
, Painter::CreateImagePainter(
57 *rb
.GetImageSkiaNamed(IDR_BLUE_BUTTON_NORMAL
), insets
));
58 button_border
->SetPainter(false, STATE_HOVERED
, Painter::CreateImagePainter(
59 *rb
.GetImageSkiaNamed(IDR_BLUE_BUTTON_HOVER
), insets
));
60 button_border
->SetPainter(false, STATE_PRESSED
, Painter::CreateImagePainter(
61 *rb
.GetImageSkiaNamed(IDR_BLUE_BUTTON_PRESSED
), insets
));
62 button_border
->SetPainter(false, STATE_DISABLED
, Painter::CreateImagePainter(
63 *rb
.GetImageSkiaNamed(IDR_BLUE_BUTTON_DISABLED
), insets
));
64 button_border
->SetPainter(true, STATE_NORMAL
, Painter::CreateImagePainter(
65 *rb
.GetImageSkiaNamed(IDR_BLUE_BUTTON_FOCUSED_NORMAL
), insets
));
66 button_border
->SetPainter(true, STATE_HOVERED
, Painter::CreateImagePainter(
67 *rb
.GetImageSkiaNamed(IDR_BLUE_BUTTON_FOCUSED_HOVER
), insets
));
68 button_border
->SetPainter(true, STATE_PRESSED
, Painter::CreateImagePainter(
69 *rb
.GetImageSkiaNamed(IDR_BLUE_BUTTON_FOCUSED_PRESSED
), insets
));
70 button_border
->SetPainter(true, STATE_DISABLED
, Painter::CreateImagePainter(
71 *rb
.GetImageSkiaNamed(IDR_BLUE_BUTTON_DISABLED
), insets
));
72 return button_border
.Pass();