Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: views/controls/button/custom_button.cc

Issue 6976048: views: Add OnEnabledChanged() method to View class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix DisableOnHover test? Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/button/custom_button.h ('k') | views/controls/button/native_button.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "views/controls/button/custom_button.h" 5 #include "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 "views/screen.h" 10 #include "views/screen.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 if (flag && GetWidget()) { 84 if (flag && GetWidget()) {
85 GetWidget()->NotifyAccessibilityEvent( 85 GetWidget()->NotifyAccessibilityEvent(
86 this, ui::AccessibilityTypes::EVENT_FOCUS, true); 86 this, ui::AccessibilityTypes::EVENT_FOCUS, true);
87 } 87 }
88 } 88 }
89 89
90 bool CustomButton::IsHotTracked() const { 90 bool CustomButton::IsHotTracked() const {
91 return state_ == BS_HOT; 91 return state_ == BS_HOT;
92 } 92 }
93 93
94 void CustomButton::SetEnabled(bool enabled) { 94 void CustomButton::OnEnabledChanged() {
95 if (enabled ? (state_ != BS_DISABLED) : (state_ == BS_DISABLED)) 95 if (View::IsEnabled() ? (state_ != BS_DISABLED) : (state_ == BS_DISABLED))
96 return; 96 return;
97 97
98 if (enabled) 98 if (View::IsEnabled())
99 SetState(IsMouseHovered() ? BS_HOT : BS_NORMAL); 99 SetState(IsMouseHovered() ? BS_HOT : BS_NORMAL);
100 else 100 else
101 SetState(BS_DISABLED); 101 SetState(BS_DISABLED);
102 } 102 }
103 103
104 bool CustomButton::IsEnabled() const { 104 bool CustomButton::IsEnabled() const {
105 return state_ != BS_DISABLED; 105 return state_ != BS_DISABLED;
106 } 106 }
107 107
108 std::string CustomButton::GetClassName() const { 108 std::string CustomButton::GetClassName() const {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 bool CustomButton::OnKeyReleased(const KeyEvent& event) { 189 bool CustomButton::OnKeyReleased(const KeyEvent& event) {
190 if ((state_ == BS_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) 190 if ((state_ == BS_DISABLED) || (event.key_code() != ui::VKEY_SPACE))
191 return false; 191 return false;
192 192
193 SetState(BS_NORMAL); 193 SetState(BS_NORMAL);
194 NotifyClick(event); 194 NotifyClick(event);
195 return true; 195 return true;
196 } 196 }
197 197
198 bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) { 198 bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) {
199 if (!enabled_) 199 if (!View::IsEnabled())
200 return false; 200 return false;
201 201
202 SetState(BS_NORMAL); 202 SetState(BS_NORMAL);
203 KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(), 203 KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(),
204 accelerator.modifiers()); 204 accelerator.modifiers());
205 NotifyClick(key_event); 205 NotifyClick(key_event);
206 return true; 206 return true;
207 } 207 }
208 208
209 void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { 209 void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 bool CustomButton::IsFocusable() const { 281 bool CustomButton::IsFocusable() const {
282 return (state_ != BS_DISABLED) && View::IsFocusable(); 282 return (state_ != BS_DISABLED) && View::IsFocusable();
283 } 283 }
284 284
285 void CustomButton::OnBlur() { 285 void CustomButton::OnBlur() {
286 if (IsHotTracked()) 286 if (IsHotTracked())
287 SetState(BS_NORMAL); 287 SetState(BS_NORMAL);
288 } 288 }
289 289
290 } // namespace views 290 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/button/custom_button.h ('k') | views/controls/button/native_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698