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"
12 ////////////////////////////////////////////////////////////////////////////////
13 // Button, static public:
16 Button::ButtonState
Button::GetButtonStateFrom(ui::NativeTheme::State 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 ////////////////////////////////////////////////////////////////////////////////
33 void Button::SetTooltipText(const base::string16
& tooltip_text
) {
34 tooltip_text_
= tooltip_text
;
35 if (accessible_name_
.empty())
36 accessible_name_
= tooltip_text_
;
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())
52 *tooltip
= tooltip_text_
;
56 void Button::GetAccessibleState(ui::AXViewState
* state
) {
57 state
->role
= ui::AX_ROLE_BUTTON
;
58 state
->name
= accessible_name_
;
61 ////////////////////////////////////////////////////////////////////////////////
64 Button::Button(ButtonListener
* listener
)
65 : listener_(listener
),
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
74 listener_
->ButtonPressed(this, event
);