OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/button/custom_button.h" | 5 #include "ui/views/controls/button/custom_button.h" |
6 | 6 |
7 #include "ui/base/accessibility/accessible_view_state.h" | 7 #include "ui/base/accessibility/accessible_view_state.h" |
8 #include "ui/base/animation/throb_animation.h" | 8 #include "ui/base/animation/throb_animation.h" |
9 #include "ui/base/keycodes/keyboard_codes.h" | 9 #include "ui/base/keycodes/keyboard_codes.h" |
10 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 GetWidget()->NotifyAccessibilityEvent( | 87 GetWidget()->NotifyAccessibilityEvent( |
88 this, ui::AccessibilityTypes::EVENT_FOCUS, true); | 88 this, ui::AccessibilityTypes::EVENT_FOCUS, true); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 bool CustomButton::IsHotTracked() const { | 92 bool CustomButton::IsHotTracked() const { |
93 return state_ == BS_HOT; | 93 return state_ == BS_HOT; |
94 } | 94 } |
95 | 95 |
96 void CustomButton::OnEnabledChanged() { | 96 void CustomButton::OnEnabledChanged() { |
97 if (View::IsEnabled() ? (state_ != BS_DISABLED) : (state_ == BS_DISABLED)) | 97 if (enabled() ? (state_ != BS_DISABLED) : (state_ == BS_DISABLED)) |
98 return; | 98 return; |
99 | 99 |
100 if (View::IsEnabled()) | 100 if (enabled()) |
101 SetState(IsMouseHovered() ? BS_HOT : BS_NORMAL); | 101 SetState(IsMouseHovered() ? BS_HOT : BS_NORMAL); |
102 else | 102 else |
103 SetState(BS_DISABLED); | 103 SetState(BS_DISABLED); |
104 } | 104 } |
105 | 105 |
106 bool CustomButton::IsEnabled() const { | |
107 return state_ != BS_DISABLED; | |
108 } | |
109 | |
110 std::string CustomButton::GetClassName() const { | 106 std::string CustomButton::GetClassName() const { |
111 return kViewClassName; | 107 return kViewClassName; |
112 } | 108 } |
113 | 109 |
114 bool CustomButton::OnMousePressed(const MouseEvent& event) { | 110 bool CustomButton::OnMousePressed(const MouseEvent& event) { |
115 if (state_ != BS_DISABLED) { | 111 if (state_ != BS_DISABLED) { |
116 if (ShouldEnterPushedState(event) && HitTest(event.location())) | 112 if (ShouldEnterPushedState(event) && HitTest(event.location())) |
117 SetState(BS_PUSHED); | 113 SetState(BS_PUSHED); |
118 if (request_focus_on_press_) | 114 if (request_focus_on_press_) |
119 RequestFocus(); | 115 RequestFocus(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 bool CustomButton::OnKeyReleased(const KeyEvent& event) { | 187 bool CustomButton::OnKeyReleased(const KeyEvent& event) { |
192 if ((state_ == BS_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) | 188 if ((state_ == BS_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) |
193 return false; | 189 return false; |
194 | 190 |
195 SetState(BS_NORMAL); | 191 SetState(BS_NORMAL); |
196 NotifyClick(event); | 192 NotifyClick(event); |
197 return true; | 193 return true; |
198 } | 194 } |
199 | 195 |
200 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { | 196 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { |
201 if (!View::IsEnabled()) | 197 if (!enabled()) |
202 return false; | 198 return false; |
203 | 199 |
204 SetState(BS_NORMAL); | 200 SetState(BS_NORMAL); |
205 KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(), | 201 KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(), |
206 accelerator.modifiers()); | 202 accelerator.modifiers()); |
207 NotifyClick(key_event); | 203 NotifyClick(key_event); |
208 return true; | 204 return true; |
209 } | 205 } |
210 | 206 |
211 void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { | 207 void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 bool CustomButton::IsFocusable() const { | 282 bool CustomButton::IsFocusable() const { |
287 return (state_ != BS_DISABLED) && View::IsFocusable(); | 283 return (state_ != BS_DISABLED) && View::IsFocusable(); |
288 } | 284 } |
289 | 285 |
290 void CustomButton::OnBlur() { | 286 void CustomButton::OnBlur() { |
291 if (IsHotTracked()) | 287 if (IsHotTracked()) |
292 SetState(BS_NORMAL); | 288 SetState(BS_NORMAL); |
293 } | 289 } |
294 | 290 |
295 } // namespace views | 291 } // namespace views |
OLD | NEW |