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.
4
5#include "ui/views/controls/button/blue_button.h"
6
7#include "grit/ui_resources.h"
8#include "ui/base/accessibility/accessible_view_state.h"
9#include "ui/base/resource/resource_bundle.h"
10#include "ui/gfx/sys_color_change_listener.h"
11#include "ui/views/controls/button/label_button_border.h"
12
13namespace {
14
15// Insets for the unified blue_button images. This assumes that the images
16// are of a 9 grid, of 5x5 size each.
17const int kBlueButtonInsets = 5;
18
19// Default text and shadow colors for the blue button.
20const SkColor kBlueButtonTextColor = SK_ColorWHITE;
21const SkColor kBlueButtonShadowColor = SkColorSetRGB(0x53, 0x8C, 0xEA);
22
23}  // namespace
24
25namespace views {
26
27// static
28const char BlueButton::kViewClassName[] = "views/BlueButton";
29
30BlueButton::BlueButton(ButtonListener* listener, const string16& text)
31    : LabelButton(listener, text) {
32  // Inherit STYLE_BUTTON insets, minimum size, alignment, etc.
33  SetStyle(STYLE_BUTTON);
34
35  ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
36  const gfx::Insets insets(kBlueButtonInsets,
37                           kBlueButtonInsets,
38                           kBlueButtonInsets,
39                           kBlueButtonInsets);
40
41  LabelButtonBorder* button_border = static_cast<LabelButtonBorder*>(border());
42  button_border->SetPainter(false, STATE_NORMAL,
43      Painter::CreateImagePainter(
44          *rb.GetImageSkiaNamed(IDR_BLUE_BUTTON_NORMAL), insets));
45  button_border->SetPainter(false, STATE_HOVERED,
46      Painter::CreateImagePainter(
47          *rb.GetImageSkiaNamed(IDR_BLUE_BUTTON_HOVER), insets));
48  button_border->SetPainter(false, STATE_PRESSED,
49      Painter::CreateImagePainter(
50          *rb.GetImageSkiaNamed(IDR_BLUE_BUTTON_PRESSED), insets));
51  button_border->SetPainter(false, STATE_DISABLED,
52      Painter::CreateImagePainter(
53          *rb.GetImageSkiaNamed(IDR_BLUE_BUTTON_DISABLED), insets));
54  button_border->SetPainter(true, STATE_NORMAL,
55      Painter::CreateImagePainter(
56          *rb.GetImageSkiaNamed(IDR_BLUE_BUTTON_FOCUSED_NORMAL), insets));
57  button_border->SetPainter(true, STATE_HOVERED,
58      Painter::CreateImagePainter(
59          *rb.GetImageSkiaNamed(IDR_BLUE_BUTTON_FOCUSED_HOVER), insets));
60  button_border->SetPainter(true, STATE_PRESSED,
61      Painter::CreateImagePainter(
62          *rb.GetImageSkiaNamed(IDR_BLUE_BUTTON_FOCUSED_PRESSED), insets));
63  button_border->SetPainter(true, STATE_DISABLED,
64      Painter::CreateImagePainter(
65          *rb.GetImageSkiaNamed(IDR_BLUE_BUTTON_DISABLED), insets));
66}
67
68BlueButton::~BlueButton() {}
69
70void BlueButton::ResetColorsFromNativeTheme() {
71  LabelButton::ResetColorsFromNativeTheme();
72  if (!gfx::IsInvertedColorScheme()) {
73    for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state)
74      SetTextColor(static_cast<ButtonState>(state), kBlueButtonTextColor);
75    label()->SetShadowColors(kBlueButtonShadowColor, kBlueButtonShadowColor);
76    label()->SetShadowOffset(0, 1);
77  }
78}
79
80const char* BlueButton::GetClassName() const {
81  return BlueButton::kViewClassName;
82}
83
84}  // namespace views
85