[email protected] | 8d37b11 | 2011-09-15 18:01:01 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 48977d58 | 2011-11-28 01:32:00 | [diff] [blame] | 5 | #include "ui/views/controls/button/button.h" |
[email protected] | 79e549f | 2011-03-14 06:56:33 | [diff] [blame] | 6 | |
[email protected] | c7057fbe | 2013-06-07 18:54:01 | [diff] [blame] | 7 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 739c8bc | 2014-02-25 18:28:13 | [diff] [blame] | 8 | #include "ui/accessibility/ax_view_state.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 10 | namespace views { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | ddc19b0 | 2014-01-25 07:18:28 | [diff] [blame] | 13 | // Button, static public: |
14 | |||||
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::kMaxState: NOTREACHED() << "Unknown state: " << state; | ||||
23 | } | ||||
24 | return Button::STATE_NORMAL; | ||||
25 | } | ||||
26 | |||||
27 | //////////////////////////////////////////////////////////////////////////////// | ||||
[email protected] | 48c8fa6 | 2009-03-16 23:25:13 | [diff] [blame] | 28 | // Button, public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 29 | |
30 | Button::~Button() { | ||||
31 | } | ||||
32 | |||||
[email protected] | 2aadf21 | 2013-12-18 20:03:44 | [diff] [blame] | 33 | void Button::SetTooltipText(const base::string16& tooltip_text) { |
[email protected] | 8d37b11 | 2011-09-15 18:01:01 | [diff] [blame] | 34 | tooltip_text_ = tooltip_text; |
[email protected] | cd70b3e | 2013-04-03 20:01:37 | [diff] [blame] | 35 | if (accessible_name_.empty()) |
36 | accessible_name_ = tooltip_text_; | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 37 | TooltipTextChanged(); |
38 | } | ||||
39 | |||||
[email protected] | 2aadf21 | 2013-12-18 20:03:44 | [diff] [blame] | 40 | void Button::SetAccessibleName(const base::string16& name) { |
[email protected] | 79e549f | 2011-03-14 06:56:33 | [diff] [blame] | 41 | accessible_name_ = name; |
42 | } | ||||
43 | |||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 44 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 48c8fa6 | 2009-03-16 23:25:13 | [diff] [blame] | 45 | // Button, View overrides: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | |
[email protected] | 2aadf21 | 2013-12-18 20:03:44 | [diff] [blame] | 47 | bool Button::GetTooltipText(const gfx::Point& p, |
48 | base::string16* tooltip) const { | ||||
[email protected] | e9adf070 | 2010-03-08 23:34:07 | [diff] [blame] | 49 | if (tooltip_text_.empty()) |
50 | return false; | ||||
51 | |||||
[email protected] | 8d37b11 | 2011-09-15 18:01:01 | [diff] [blame] | 52 | *tooltip = tooltip_text_; |
[email protected] | e9adf070 | 2010-03-08 23:34:07 | [diff] [blame] | 53 | return true; |
[email protected] | 48c8fa6 | 2009-03-16 23:25:13 | [diff] [blame] | 54 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 55 | |
[email protected] | 739c8bc | 2014-02-25 18:28:13 | [diff] [blame] | 56 | void Button::GetAccessibleState(ui::AXViewState* state) { |
57 | state->role = ui::AX_ROLE_BUTTON; | ||||
[email protected] | 79e549f | 2011-03-14 06:56:33 | [diff] [blame] | 58 | state->name = accessible_name_; |
[email protected] | e92070ac | 2009-04-28 00:12:01 | [diff] [blame] | 59 | } |
60 | |||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 61 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 48c8fa6 | 2009-03-16 23:25:13 | [diff] [blame] | 62 | // Button, protected: |
63 | |||||
64 | Button::Button(ButtonListener* listener) | ||||
65 | : listener_(listener), | ||||
[email protected] | 437e1bbc | 2012-11-29 20:26:48 | [diff] [blame] | 66 | tag_(-1) { |
[email protected] | 505df7b | 2013-12-16 14:07:19 | [diff] [blame] | 67 | SetAccessibilityFocusable(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | } |
69 | |||||
[email protected] | 0fe4c79 | 2012-08-10 19:29:04 | [diff] [blame] | 70 | void Button::NotifyClick(const ui::Event& event) { |
[email protected] | 720d1a8 | 2009-03-19 00:39:20 | [diff] [blame] | 71 | // We can be called when there is no listener, in cases like double clicks on |
72 | // menu buttons etc. | ||||
73 | if (listener_) | ||||
[email protected] | a071e65 | 2009-09-03 20:58:01 | [diff] [blame] | 74 | listener_->ButtonPressed(this, event); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 75 | } |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 76 | |
77 | } // namespace views |