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