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 // Keeping only white - listed set of flags and resetting the KeyEventFlags. | |
201 int flags = event.flags() & | |
202 ~(ui::EF_IME_FABRICATED_KEY | ui::EF_IS_REPEAT | ui::EF_FINAL); | |
200 // TODO(beng): remove once NotifyClick takes ui::Event. | 203 // TODO(beng): remove once NotifyClick takes ui::Event. |
sadrul
2015/08/17 14:40:11
NotifyClick() now takes a ui::Event. Can we addres
Deepak
2015/08/18 04:34:56
Done.
| |
201 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED, gfx::Point(), | 204 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED, gfx::Point(), |
202 gfx::Point(), ui::EventTimeForNow(), | 205 gfx::Point(), ui::EventTimeForNow(), |
203 ui::EF_LEFT_MOUSE_BUTTON, | 206 ui::EF_LEFT_MOUSE_BUTTON | flags, |
204 ui::EF_LEFT_MOUSE_BUTTON); | 207 ui::EF_LEFT_MOUSE_BUTTON); |
205 NotifyClick(synthetic_event); | 208 NotifyClick(synthetic_event); |
206 } else { | 209 } else { |
207 return false; | 210 return false; |
208 } | 211 } |
209 return true; | 212 return true; |
210 } | 213 } |
211 | 214 |
212 bool CustomButton::OnKeyReleased(const ui::KeyEvent& event) { | 215 bool CustomButton::OnKeyReleased(const ui::KeyEvent& event) { |
213 if ((state_ == STATE_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) | 216 if ((state_ == STATE_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 if (!details.is_add && state_ != STATE_DISABLED) | 352 if (!details.is_add && state_ != STATE_DISABLED) |
350 SetState(STATE_NORMAL); | 353 SetState(STATE_NORMAL); |
351 } | 354 } |
352 | 355 |
353 void CustomButton::OnBlur() { | 356 void CustomButton::OnBlur() { |
354 if (IsHotTracked()) | 357 if (IsHotTracked()) |
355 SetState(STATE_NORMAL); | 358 SetState(STATE_NORMAL); |
356 } | 359 } |
357 | 360 |
358 } // namespace views | 361 } // namespace views |
OLD | NEW |