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/events/event.h" | 5 #include "ui/events/event.h" |
6 | 6 |
7 #if defined(USE_X11) | 7 #if defined(USE_X11) |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 #endif | 10 #endif |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 DCHECK(success); | 472 DCHECK(success); |
473 if (decomp.scale[0]) | 473 if (decomp.scale[0]) |
474 radius_x_ *= decomp.scale[0]; | 474 radius_x_ *= decomp.scale[0]; |
475 if (decomp.scale[1]) | 475 if (decomp.scale[1]) |
476 radius_y_ *= decomp.scale[1]; | 476 radius_y_ *= decomp.scale[1]; |
477 } | 477 } |
478 | 478 |
479 //////////////////////////////////////////////////////////////////////////////// | 479 //////////////////////////////////////////////////////////////////////////////// |
480 // KeyEvent | 480 // KeyEvent |
481 | 481 |
| 482 // static |
| 483 KeyEvent* KeyEvent::last_key_event_ = NULL; |
| 484 |
| 485 // static |
| 486 bool KeyEvent::IsRepeated(const KeyEvent& event) { |
| 487 // A safe guard in case if there were continous key pressed events that are |
| 488 // not auto repeat. |
| 489 const int kMaxAutoRepeatTimeMs = 2000; |
| 490 |
| 491 if (event.is_char()) |
| 492 return false; |
| 493 if (event.type() == ui::ET_KEY_RELEASED) { |
| 494 delete last_key_event_; |
| 495 last_key_event_ = NULL; |
| 496 return false; |
| 497 } |
| 498 CHECK_EQ(ui::ET_KEY_PRESSED, event.type()); |
| 499 if (!last_key_event_) { |
| 500 last_key_event_ = new KeyEvent(event); |
| 501 return false; |
| 502 } |
| 503 if (event.key_code() == last_key_event_->key_code() && |
| 504 event.flags() == last_key_event_->flags() && |
| 505 (event.time_stamp() - last_key_event_->time_stamp()).InMilliseconds() < |
| 506 kMaxAutoRepeatTimeMs) { |
| 507 return true; |
| 508 } |
| 509 delete last_key_event_; |
| 510 last_key_event_ = new KeyEvent(event); |
| 511 return false; |
| 512 } |
| 513 |
482 KeyEvent::KeyEvent(const base::NativeEvent& native_event, bool is_char) | 514 KeyEvent::KeyEvent(const base::NativeEvent& native_event, bool is_char) |
483 : Event(native_event, | 515 : Event(native_event, |
484 EventTypeFromNative(native_event), | 516 EventTypeFromNative(native_event), |
485 EventFlagsFromNative(native_event)), | 517 EventFlagsFromNative(native_event)), |
486 key_code_(KeyboardCodeFromNative(native_event)), | 518 key_code_(KeyboardCodeFromNative(native_event)), |
487 code_(CodeFromNative(native_event)), | 519 code_(CodeFromNative(native_event)), |
488 is_char_(is_char), | 520 is_char_(is_char), |
489 character_(0) { | 521 character_(0) { |
| 522 if (IsRepeated(*this)) |
| 523 set_flags(flags() | ui::EF_IS_REPEAT); |
| 524 |
490 #if defined(USE_X11) | 525 #if defined(USE_X11) |
491 NormalizeFlags(); | 526 NormalizeFlags(); |
492 #endif | 527 #endif |
493 } | 528 } |
494 | 529 |
495 KeyEvent::KeyEvent(EventType type, | 530 KeyEvent::KeyEvent(EventType type, |
496 KeyboardCode key_code, | 531 KeyboardCode key_code, |
497 int flags, | 532 int flags, |
498 bool is_char) | 533 bool is_char) |
499 : Event(type, EventTimeForNow(), flags), | 534 : Event(type, EventTimeForNow(), flags), |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 int GestureEvent::GetLowestTouchId() const { | 723 int GestureEvent::GetLowestTouchId() const { |
689 if (touch_ids_bitfield_ == 0) | 724 if (touch_ids_bitfield_ == 0) |
690 return -1; | 725 return -1; |
691 int i = -1; | 726 int i = -1; |
692 // Find the index of the least significant 1 bit | 727 // Find the index of the least significant 1 bit |
693 while (!(1 << ++i & touch_ids_bitfield_)); | 728 while (!(1 << ++i & touch_ids_bitfield_)); |
694 return i; | 729 return i; |
695 } | 730 } |
696 | 731 |
697 } // namespace ui | 732 } // namespace ui |
OLD | NEW |