blob: 4e7f51b545063f0193425184d0fbcdbf16e8fe22 [file] [log] [blame]
[email protected]8d37b112011-09-15 18:01:011// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]48977d582011-11-28 01:32:005#include "ui/views/controls/button/button.h"
[email protected]79e549f2011-03-14 06:56:336
[email protected]c7057fbe2013-06-07 18:54:017#include "base/strings/utf_string_conversions.h"
[email protected]739c8bc2014-02-25 18:28:138#include "ui/accessibility/ax_view_state.h"
initial.commit09911bf2008-07-26 23:55:299
[email protected]c2dacc92008-10-16 23:51:3810namespace views {
initial.commit09911bf2008-07-26 23:55:2911
initial.commit09911bf2008-07-26 23:55:2912////////////////////////////////////////////////////////////////////////////////
[email protected]ddc19b02014-01-25 07:18:2813// Button, static public:
14
15// static
16Button::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::kMaxState: NOTREACHED() << "Unknown state: " << state;
23 }
24 return Button::STATE_NORMAL;
25}
26
27////////////////////////////////////////////////////////////////////////////////
[email protected]48c8fa62009-03-16 23:25:1328// Button, public:
initial.commit09911bf2008-07-26 23:55:2929
30Button::~Button() {
31}
32
[email protected]2aadf212013-12-18 20:03:4433void Button::SetTooltipText(const base::string16& tooltip_text) {
[email protected]8d37b112011-09-15 18:01:0134 tooltip_text_ = tooltip_text;
[email protected]cd70b3e2013-04-03 20:01:3735 if (accessible_name_.empty())
36 accessible_name_ = tooltip_text_;
initial.commit09911bf2008-07-26 23:55:2937 TooltipTextChanged();
38}
39
[email protected]2aadf212013-12-18 20:03:4440void Button::SetAccessibleName(const base::string16& name) {
[email protected]79e549f2011-03-14 06:56:3341 accessible_name_ = name;
42}
43
initial.commit09911bf2008-07-26 23:55:2944////////////////////////////////////////////////////////////////////////////////
[email protected]48c8fa62009-03-16 23:25:1345// Button, View overrides:
initial.commit09911bf2008-07-26 23:55:2946
[email protected]2aadf212013-12-18 20:03:4447bool Button::GetTooltipText(const gfx::Point& p,
48 base::string16* tooltip) const {
[email protected]e9adf0702010-03-08 23:34:0749 if (tooltip_text_.empty())
50 return false;
51
[email protected]8d37b112011-09-15 18:01:0152 *tooltip = tooltip_text_;
[email protected]e9adf0702010-03-08 23:34:0753 return true;
[email protected]48c8fa62009-03-16 23:25:1354}
initial.commit09911bf2008-07-26 23:55:2955
[email protected]739c8bc2014-02-25 18:28:1356void Button::GetAccessibleState(ui::AXViewState* state) {
57 state->role = ui::AX_ROLE_BUTTON;
[email protected]79e549f2011-03-14 06:56:3358 state->name = accessible_name_;
[email protected]e92070ac2009-04-28 00:12:0159}
60
initial.commit09911bf2008-07-26 23:55:2961////////////////////////////////////////////////////////////////////////////////
[email protected]48c8fa62009-03-16 23:25:1362// Button, protected:
63
64Button::Button(ButtonListener* listener)
65 : listener_(listener),
[email protected]437e1bbc2012-11-29 20:26:4866 tag_(-1) {
[email protected]505df7b2013-12-16 14:07:1967 SetAccessibilityFocusable(true);
initial.commit09911bf2008-07-26 23:55:2968}
69
[email protected]0fe4c792012-08-10 19:29:0470void Button::NotifyClick(const ui::Event& event) {
[email protected]720d1a82009-03-19 00:39:2071 // We can be called when there is no listener, in cases like double clicks on
72 // menu buttons etc.
73 if (listener_)
[email protected]a071e652009-09-03 20:58:0174 listener_->ButtonPressed(this, event);
initial.commit09911bf2008-07-26 23:55:2975}
[email protected]c2dacc92008-10-16 23:51:3876
77} // namespace views