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

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

Issue 1411523009: Adds OnClickCanceled callback to views::Button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds NotifyReleasedWithoutClick callback to views::Button (corrections) Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/accessibility/ax_view_state.h" 7 #include "ui/accessibility/ax_view_state.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
10 #include "ui/events/keycodes/keyboard_codes.h" 10 #include "ui/events/keycodes/keyboard_codes.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); 121 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL);
122 else 122 else
123 SetState(STATE_DISABLED); 123 SetState(STATE_DISABLED);
124 } 124 }
125 125
126 const char* CustomButton::GetClassName() const { 126 const char* CustomButton::GetClassName() const {
127 return kViewClassName; 127 return kViewClassName;
128 } 128 }
129 129
130 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { 130 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) {
131 if (state_ != STATE_DISABLED) { 131 if (state_ == STATE_DISABLED)
132 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) 132 return true;
133 SetState(STATE_PRESSED); 133 if (ShouldEnterPushedState(event) && HitTestPoint(event.location()))
134 if (request_focus_on_press_) 134 SetState(STATE_PRESSED);
135 RequestFocus(); 135 if (request_focus_on_press_)
136 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) { 136 RequestFocus();
137 if (notify_action_ == NOTIFY_ON_PRESS) {
138 if (IsTriggerableEvent(event)) {
137 NotifyClick(event); 139 NotifyClick(event);
138 // NOTE: We may be deleted at this point (by the listener's notification 140 // NOTE: We may be deleted at this point (by the listener's notification
139 // handler). 141 // handler).
142 } else {
143 NotifyReleasedWithoutClick(event);
140 } 144 }
141 } 145 }
142 return true; 146 return true;
143 } 147 }
144 148
145 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) { 149 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) {
146 if (state_ != STATE_DISABLED) { 150 if (state_ != STATE_DISABLED) {
147 if (HitTestPoint(event.location())) 151 if (HitTestPoint(event.location()))
148 SetState(ShouldEnterPushedState(event) ? STATE_PRESSED : STATE_HOVERED); 152 SetState(ShouldEnterPushedState(event) ? STATE_PRESSED : STATE_HOVERED);
149 else 153 else
150 SetState(STATE_NORMAL); 154 SetState(STATE_NORMAL);
151 } 155 }
152 return true; 156 return true;
153 } 157 }
154 158
155 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { 159 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) {
156 if (state_ == STATE_DISABLED) 160 if (state_ == STATE_DISABLED)
157 return; 161 return;
158
159 if (!HitTestPoint(event.location())) { 162 if (!HitTestPoint(event.location())) {
160 SetState(STATE_NORMAL); 163 SetState(STATE_NORMAL);
161 return; 164 } else {
165 SetState(STATE_HOVERED);
166 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_RELEASE) {
167 NotifyClick(event);
168 // NOTE: We may be deleted at this point (by the listener's notification
169 // handler).
170 return;
171 }
162 } 172 }
163 173 if (notify_action_ == NOTIFY_ON_RELEASE)
164 SetState(STATE_HOVERED); 174 NotifyReleasedWithoutClick(event);
165 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_RELEASE) {
166 NotifyClick(event);
167 // NOTE: We may be deleted at this point (by the listener's notification
168 // handler).
169 }
170 } 175 }
171 176
172 void CustomButton::OnMouseCaptureLost() { 177 void CustomButton::OnMouseCaptureLost() {
173 // Starting a drag results in a MouseCaptureLost, we need to ignore it. 178 // Starting a drag results in a MouseCaptureLost, we need to ignore it.
174 if (state_ != STATE_DISABLED && !InDrag()) 179 if (state_ != STATE_DISABLED && !InDrag())
175 SetState(STATE_NORMAL); 180 SetState(STATE_NORMAL);
176 } 181 }
177 182
178 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { 183 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) {
179 if (state_ != STATE_DISABLED) 184 if (state_ != STATE_DISABLED)
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 if (!details.is_add && state_ != STATE_DISABLED) 374 if (!details.is_add && state_ != STATE_DISABLED)
370 SetState(STATE_NORMAL); 375 SetState(STATE_NORMAL);
371 } 376 }
372 377
373 void CustomButton::OnBlur() { 378 void CustomButton::OnBlur() {
374 if (IsHotTracked()) 379 if (IsHotTracked())
375 SetState(STATE_NORMAL); 380 SetState(STATE_NORMAL);
376 } 381 }
377 382
378 } // namespace views 383 } // namespace views
OLDNEW
« ui/views/controls/button/button.h ('K') | « ui/views/controls/button/button.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698