Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / ui / views / controls / button / button.cc
blobb9b8b22ab03542119ad079ff21ea64bd9a032fd8
1 // Copyright (c) 2011 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/button.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/accessibility/ax_view_state.h"
10 namespace views {
12 ////////////////////////////////////////////////////////////////////////////////
13 // Button, static public:
15 // static
16 Button::ButtonState Button::GetButtonStateFrom(ui::NativeTheme::State state) {
17 switch (state) {
18 case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED;
19 case ui::NativeTheme::kHovered: return Button::STATE_HOVERED;
20 case ui::NativeTheme::kNormal: return Button::STATE_NORMAL;
21 case ui::NativeTheme::kPressed: return Button::STATE_PRESSED;
22 case ui::NativeTheme::kNumStates: NOTREACHED();
24 return Button::STATE_NORMAL;
27 ////////////////////////////////////////////////////////////////////////////////
28 // Button, public:
30 Button::~Button() {
33 void Button::SetTooltipText(const base::string16& tooltip_text) {
34 tooltip_text_ = tooltip_text;
35 if (accessible_name_.empty())
36 accessible_name_ = tooltip_text_;
37 TooltipTextChanged();
40 void Button::SetAccessibleName(const base::string16& name) {
41 accessible_name_ = name;
44 ////////////////////////////////////////////////////////////////////////////////
45 // Button, View overrides:
47 bool Button::GetTooltipText(const gfx::Point& p,
48 base::string16* tooltip) const {
49 if (tooltip_text_.empty())
50 return false;
52 *tooltip = tooltip_text_;
53 return true;
56 void Button::GetAccessibleState(ui::AXViewState* state) {
57 state->role = ui::AX_ROLE_BUTTON;
58 state->name = accessible_name_;
61 ////////////////////////////////////////////////////////////////////////////////
62 // Button, protected:
64 Button::Button(ButtonListener* listener)
65 : listener_(listener),
66 tag_(-1) {
67 SetAccessibilityFocusable(true);
70 void Button::NotifyClick(const ui::Event& event) {
71 // We can be called when there is no listener, in cases like double clicks on
72 // menu buttons etc.
73 if (listener_)
74 listener_->ButtonPressed(this, event);
77 } // namespace views