OLD | NEW |
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 if (state_ == STATE_DISABLED) | 190 if (state_ == STATE_DISABLED) |
191 return false; | 191 return false; |
192 | 192 |
193 // Space sets button state to pushed. Enter clicks the button. This matches | 193 // Space sets button state to pushed. Enter clicks the button. This matches |
194 // the Windows native behavior of buttons, where Space clicks the button on | 194 // the Windows native behavior of buttons, where Space clicks the button on |
195 // KeyRelease and Enter clicks the button on KeyPressed. | 195 // KeyRelease and Enter clicks the button on KeyPressed. |
196 if (event.key_code() == ui::VKEY_SPACE) { | 196 if (event.key_code() == ui::VKEY_SPACE) { |
197 SetState(STATE_PRESSED); | 197 SetState(STATE_PRESSED); |
198 } else if (event.key_code() == ui::VKEY_RETURN) { | 198 } else if (event.key_code() == ui::VKEY_RETURN) { |
199 SetState(STATE_NORMAL); | 199 SetState(STATE_NORMAL); |
200 // TODO(beng): remove once NotifyClick takes ui::Event. | 200 NotifyClick(event); |
201 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED, gfx::Point(), | |
202 gfx::Point(), ui::EventTimeForNow(), | |
203 ui::EF_LEFT_MOUSE_BUTTON, | |
204 ui::EF_LEFT_MOUSE_BUTTON); | |
205 NotifyClick(synthetic_event); | |
206 } else { | 201 } else { |
207 return false; | 202 return false; |
208 } | 203 } |
209 return true; | 204 return true; |
210 } | 205 } |
211 | 206 |
212 bool CustomButton::OnKeyReleased(const ui::KeyEvent& event) { | 207 bool CustomButton::OnKeyReleased(const ui::KeyEvent& event) { |
213 if ((state_ == STATE_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) | 208 if ((state_ == STATE_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) |
214 return false; | 209 return false; |
215 | 210 |
216 SetState(STATE_NORMAL); | 211 SetState(STATE_NORMAL); |
217 // TODO(beng): remove once NotifyClick takes ui::Event. | 212 NotifyClick(event); |
218 ui::MouseEvent synthetic_event( | |
219 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), | |
220 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | |
221 NotifyClick(synthetic_event); | |
222 return true; | 213 return true; |
223 } | 214 } |
224 | 215 |
225 void CustomButton::OnGestureEvent(ui::GestureEvent* event) { | 216 void CustomButton::OnGestureEvent(ui::GestureEvent* event) { |
226 if (state_ == STATE_DISABLED) { | 217 if (state_ == STATE_DISABLED) { |
227 Button::OnGestureEvent(event); | 218 Button::OnGestureEvent(event); |
228 return; | 219 return; |
229 } | 220 } |
230 | 221 |
231 if (event->type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(*event)) { | 222 if (event->type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(*event)) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 if (!details.is_add && state_ != STATE_DISABLED) | 340 if (!details.is_add && state_ != STATE_DISABLED) |
350 SetState(STATE_NORMAL); | 341 SetState(STATE_NORMAL); |
351 } | 342 } |
352 | 343 |
353 void CustomButton::OnBlur() { | 344 void CustomButton::OnBlur() { |
354 if (IsHotTracked()) | 345 if (IsHotTracked()) |
355 SetState(STATE_NORMAL); | 346 SetState(STATE_NORMAL); |
356 } | 347 } |
357 | 348 |
358 } // namespace views | 349 } // namespace views |
OLD | NEW |