Chromium Code Reviews| 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 #ifndef UI_EVENTS_EVENT_H_ | 5 #ifndef UI_EVENTS_EVENT_H_ |
| 6 #define UI_EVENTS_EVENT_H_ | 6 #define UI_EVENTS_EVENT_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/event_types.h" | 10 #include "base/event_types.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
| 16 #include "ui/events/gesture_event_details.h" | 16 #include "ui/events/gesture_event_details.h" |
| 17 #include "ui/events/gestures/gesture_types.h" | 17 #include "ui/events/gestures/gesture_types.h" |
| 18 #include "ui/events/keycodes/keyboard_codes.h" | 18 #include "ui/events/keycodes/keyboard_codes.h" |
| 19 #include "ui/events/latency_info.h" | 19 #include "ui/events/latency_info.h" |
| 20 #include "ui/gfx/point.h" | 20 #include "ui/gfx/point.h" |
| 21 #include "ui/gfx/point_conversions.h" | 21 #include "ui/gfx/point_conversions.h" |
| 22 | 22 |
| 23 namespace gfx { | 23 namespace gfx { |
| 24 class Transform; | 24 class Transform; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace ui { | 27 namespace ui { |
| 28 class EventTarget; | 28 class EventTarget; |
| 29 enum class DomCode; | 29 enum class DomCode; |
| 30 enum class DomKey; | |
| 30 | 31 |
| 31 class EVENTS_EXPORT Event { | 32 class EVENTS_EXPORT Event { |
| 32 public: | 33 public: |
| 33 static scoped_ptr<Event> Clone(const Event& event); | 34 static scoped_ptr<Event> Clone(const Event& event); |
| 34 | 35 |
| 35 virtual ~Event(); | 36 virtual ~Event(); |
| 36 | 37 |
| 37 class DispatcherApi { | 38 class DispatcherApi { |
| 38 public: | 39 public: |
| 39 explicit DispatcherApi(Event* event) : event_(event) {} | 40 explicit DispatcherApi(Event* event) : event_(event) {} |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 // ET_TRANSLATED_KEY_PRESS, or ET_TRANSLATED_KEY_RELEASE. | 578 // ET_TRANSLATED_KEY_PRESS, or ET_TRANSLATED_KEY_RELEASE. |
| 578 // -- character_ functions as a bypass or cache for GetCharacter(). | 579 // -- character_ functions as a bypass or cache for GetCharacter(). |
| 579 // -- key_code_ is a VKEY_ value associated with the key. For printable | 580 // -- key_code_ is a VKEY_ value associated with the key. For printable |
| 580 // characters, this may or may not be a mapped value, imitating MS Windows: | 581 // characters, this may or may not be a mapped value, imitating MS Windows: |
| 581 // if the mapped key generates a character that has an associated VKEY_ | 582 // if the mapped key generates a character that has an associated VKEY_ |
| 582 // code, then key_code_ is that code; if not, then key_code_ is the unmapped | 583 // code, then key_code_ is that code; if not, then key_code_ is the unmapped |
| 583 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use | 584 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use |
| 584 // VKEY_Q for the key beside Tab, while French uses VKEY_A. | 585 // VKEY_Q for the key beside Tab, while French uses VKEY_A. |
| 585 // -- code_ is in one-to-one correspondence with a physical keyboard | 586 // -- code_ is in one-to-one correspondence with a physical keyboard |
| 586 // location, and does not vary depending on key layout. | 587 // location, and does not vary depending on key layout. |
| 588 // -- key_, possibly in conjuction with character_, is the interpretation | |
| 589 // of the keystroke under the current key layout. | |
| 587 // | 590 // |
| 588 // For a character event, | 591 // For a character event, |
| 589 // -- is_char_ is true. | 592 // -- is_char_ is true. |
| 590 // -- type() is ET_KEY_PRESSED. | 593 // -- type() is ET_KEY_PRESSED. |
| 591 // -- character_ is a UTF-16 character value. | 594 // -- character_ is a UTF-16 character value. |
| 592 // -- key_code_ is conflated with character_ by some code, because both | 595 // -- key_code_ is conflated with character_ by some code, because both |
| 593 // arrive in the wParam field of a Windows event. | 596 // arrive in the wParam field of a Windows event. |
| 594 // -- code_ is DomCode::NONE. | 597 // -- code_ is DomCode::NONE. |
| 598 // -- key_ is DomKey::CHARACTER. | |
| 595 // | 599 // |
| 596 class EVENTS_EXPORT KeyEvent : public Event { | 600 class EVENTS_EXPORT KeyEvent : public Event { |
| 597 public: | 601 public: |
| 598 // Create a KeyEvent from a NativeEvent. For Windows this native event can | 602 // Create a KeyEvent from a NativeEvent. For Windows this native event can |
| 599 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message | 603 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message |
| 600 // (WM_CHAR). Other systems have only keystroke events. | 604 // (WM_CHAR). Other systems have only keystroke events. |
| 601 explicit KeyEvent(const base::NativeEvent& native_event); | 605 explicit KeyEvent(const base::NativeEvent& native_event); |
| 602 | 606 |
| 603 // Create a keystroke event. | 607 // Create a keystroke event. |
| 604 KeyEvent(EventType type, KeyboardCode key_code, int flags); | 608 KeyEvent(EventType type, KeyboardCode key_code, int flags); |
| 605 | 609 |
| 610 // Create a fully defined keystroke event. | |
| 611 KeyEvent(EventType type, | |
| 612 KeyboardCode key_code, | |
| 613 DomCode code, | |
| 614 int flags, | |
| 615 DomKey key, | |
| 616 base::char16 character); | |
| 617 | |
| 606 // Create a character event. | 618 // Create a character event. |
| 607 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); | 619 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); |
| 608 | 620 |
| 609 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') | 621 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') |
| 610 // See also: ui/events/keycodes/dom3/dom_values.txt | 622 // See also: ui/events/keycodes/dom3/dom_values.txt |
| 611 KeyEvent(EventType type, | 623 KeyEvent(EventType type, |
| 612 KeyboardCode key_code, | 624 KeyboardCode key_code, |
| 613 DomCode code, | 625 DomCode code, |
| 614 int flags); | 626 int flags); |
| 615 | 627 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 uint16 GetConflatedWindowsKeyCode() const; | 691 uint16 GetConflatedWindowsKeyCode() const; |
| 680 | 692 |
| 681 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. | 693 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. |
| 682 // TODO(msw): Additional work may be needed for analogues on other platforms. | 694 // TODO(msw): Additional work may be needed for analogues on other platforms. |
| 683 bool IsUnicodeKeyCode() const; | 695 bool IsUnicodeKeyCode() const; |
| 684 | 696 |
| 685 // Returns the DOM .code (physical key identifier) for a keystroke event. | 697 // Returns the DOM .code (physical key identifier) for a keystroke event. |
| 686 DomCode code() const { return code_; }; | 698 DomCode code() const { return code_; }; |
| 687 std::string GetCodeString() const; | 699 std::string GetCodeString() const; |
| 688 | 700 |
| 701 // Returns the DOM .key (layout interpretation) for a keystroke event. | |
| 702 DomKey GetDomKey() const; | |
|
Wez
2014/12/02 05:45:08
Indentation looks wrong?
It's a shame that we can
kpschoedel
2014/12/02 16:45:45
Acknowledged.
| |
| 703 | |
| 689 // Normalizes flags_ so that it describes the state after the event. | 704 // Normalizes flags_ so that it describes the state after the event. |
| 690 // (Native X11 event flags describe the state before the event.) | 705 // (Native X11 event flags describe the state before the event.) |
| 691 void NormalizeFlags(); | 706 void NormalizeFlags(); |
| 692 | 707 |
| 693 // Returns true if the key event has already been processed by an input method | 708 // Returns true if the key event has already been processed by an input method |
| 694 // and there is no need to pass the key event to the input method again. | 709 // and there is no need to pass the key event to the input method again. |
| 695 bool IsTranslated() const; | 710 bool IsTranslated() const; |
| 696 // Marks this key event as translated or not translated. | 711 // Marks this key event as translated or not translated. |
| 697 void SetTranslated(bool translated); | 712 void SetTranslated(bool translated); |
| 698 | 713 |
| 699 protected: | 714 protected: |
| 700 friend class KeyEventTestApi; | 715 friend class KeyEventTestApi; |
| 701 | 716 |
| 702 // This allows a subclass TranslatedKeyEvent to be a non character event. | 717 // This allows a subclass TranslatedKeyEvent to be a non character event. |
| 703 void set_is_char(bool is_char) { is_char_ = is_char; } | 718 void set_is_char(bool is_char) { is_char_ = is_char; } |
| 704 | 719 |
| 705 private: | 720 private: |
| 706 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). | 721 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). |
| 707 bool IsRightSideKey() const; | 722 bool IsRightSideKey() const; |
| 708 | 723 |
| 724 // Determine key_ and character_ on a keystroke event from code_ and flags(). | |
| 725 void ApplyLayout() const; | |
| 726 | |
| 709 KeyboardCode key_code_; | 727 KeyboardCode key_code_; |
| 710 | 728 |
| 711 // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE). | 729 // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE). |
| 712 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 730 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
| 713 // | 731 // |
| 714 // This value represents the physical position in the keyboard and can be | 732 // This value represents the physical position in the keyboard and can be |
| 715 // converted from / to keyboard scan code like XKB. | 733 // converted from / to keyboard scan code like XKB. |
| 716 DomCode code_; | 734 DomCode code_; |
| 717 | 735 |
| 736 // DOM KeyboardEvent |key| | |
| 737 // http://www.w3.org/TR/DOM-Level-3-Events-key/ | |
| 738 // | |
| 739 // This value represents the interpretation of a key. The value is | |
| 740 // DomKey::CHARACTER when the interpretation is a character. | |
| 741 // This, along with character_, may be lazily evaluated, since in some cases | |
| 742 // (e.g. native ChromeOS) we are not interested in the values until after | |
| 743 // the event has been transformed. | |
| 744 mutable DomKey key_; | |
|
Wez
2014/12/02 05:45:07
Why does this need mutable?
kpschoedel
2014/12/02 16:45:45
Same as character_; the existing code mutates char
| |
| 745 | |
| 718 // True if this is a character event, false if this is a keystroke event. | 746 // True if this is a character event, false if this is a keystroke event. |
| 719 bool is_char_; | 747 bool is_char_; |
| 720 | 748 |
| 721 // The platform related keycode value. For XKB, it's keysym value. | 749 // The platform related keycode value. For XKB, it's keysym value. |
| 722 // For now, this is used for CharacterComposer in ChromeOS. | 750 // For now, this is used for CharacterComposer in ChromeOS. |
| 723 uint32 platform_keycode_; | 751 uint32 platform_keycode_; |
| 724 | 752 |
| 725 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') | 753 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') |
| 726 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | 754 // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
| 727 // | 755 // |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 | 838 |
| 811 const GestureEventDetails& details() const { return details_; } | 839 const GestureEventDetails& details() const { return details_; } |
| 812 | 840 |
| 813 private: | 841 private: |
| 814 GestureEventDetails details_; | 842 GestureEventDetails details_; |
| 815 }; | 843 }; |
| 816 | 844 |
| 817 } // namespace ui | 845 } // namespace ui |
| 818 | 846 |
| 819 #endif // UI_EVENTS_EVENT_H_ | 847 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |