| 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.type() == ui::ET_KEY_RELEASED) { |
| 492 delete last_key_event_; |
| 493 last_key_event_ = NULL; |
| 494 return false; |
| 495 } |
| 496 if (!last_key_event_) { |
| 497 last_key_event_ = new KeyEvent(event); |
| 498 return false; |
| 499 } |
| 500 if (event.key_code() == last_key_event_->key_code() && |
| 501 event.flags() == last_key_event_->flags() && |
| 502 (event.time_stamp() - last_key_event_->time_stamp()).InMilliseconds() < |
| 503 kMaxAutoRepeatTimeMs) { |
| 504 return true; |
| 505 } |
| 506 delete last_key_event_; |
| 507 last_key_event_ = new KeyEvent(event); |
| 508 return false; |
| 509 } |
| 510 |
| 482 KeyEvent::KeyEvent(const base::NativeEvent& native_event, bool is_char) | 511 KeyEvent::KeyEvent(const base::NativeEvent& native_event, bool is_char) |
| 483 : Event(native_event, | 512 : Event(native_event, |
| 484 EventTypeFromNative(native_event), | 513 EventTypeFromNative(native_event), |
| 485 EventFlagsFromNative(native_event)), | 514 EventFlagsFromNative(native_event)), |
| 486 key_code_(KeyboardCodeFromNative(native_event)), | 515 key_code_(KeyboardCodeFromNative(native_event)), |
| 487 code_(CodeFromNative(native_event)), | 516 code_(CodeFromNative(native_event)), |
| 488 is_char_(is_char), | 517 is_char_(is_char), |
| 489 character_(0) { | 518 character_(0) { |
| 519 if (IsRepeated(*this)) |
| 520 set_flags(flags() | ui::EF_IS_REPEAT); |
| 521 |
| 490 #if defined(USE_X11) | 522 #if defined(USE_X11) |
| 491 NormalizeFlags(); | 523 NormalizeFlags(); |
| 492 #endif | 524 #endif |
| 493 } | 525 } |
| 494 | 526 |
| 495 KeyEvent::KeyEvent(EventType type, | 527 KeyEvent::KeyEvent(EventType type, |
| 496 KeyboardCode key_code, | 528 KeyboardCode key_code, |
| 497 int flags, | 529 int flags, |
| 498 bool is_char) | 530 bool is_char) |
| 499 : Event(type, EventTimeForNow(), flags), | 531 : Event(type, EventTimeForNow(), flags), |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 int GestureEvent::GetLowestTouchId() const { | 720 int GestureEvent::GetLowestTouchId() const { |
| 689 if (touch_ids_bitfield_ == 0) | 721 if (touch_ids_bitfield_ == 0) |
| 690 return -1; | 722 return -1; |
| 691 int i = -1; | 723 int i = -1; |
| 692 // Find the index of the least significant 1 bit | 724 // Find the index of the least significant 1 bit |
| 693 while (!(1 << ++i & touch_ids_bitfield_)); | 725 while (!(1 << ++i & touch_ids_bitfield_)); |
| 694 return i; | 726 return i; |
| 695 } | 727 } |
| 696 | 728 |
| 697 } // namespace ui | 729 } // namespace ui |
| OLD | NEW |