| 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/dom/dom_key.h" |
| 18 #include "ui/events/keycodes/keyboard_codes.h" | 19 #include "ui/events/keycodes/keyboard_codes.h" |
| 19 #include "ui/events/latency_info.h" | 20 #include "ui/events/latency_info.h" |
| 20 #include "ui/gfx/geometry/point.h" | 21 #include "ui/gfx/geometry/point.h" |
| 21 #include "ui/gfx/geometry/point_conversions.h" | 22 #include "ui/gfx/geometry/point_conversions.h" |
| 22 | 23 |
| 23 namespace gfx { | 24 namespace gfx { |
| 24 class Transform; | 25 class Transform; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace ui { | 28 namespace ui { |
| 28 class EventTarget; | 29 class EventTarget; |
| 29 enum class DomCode; | 30 enum class DomCode; |
| 30 enum class DomKey; | |
| 31 | 31 |
| 32 class EVENTS_EXPORT Event { | 32 class EVENTS_EXPORT Event { |
| 33 public: | 33 public: |
| 34 static scoped_ptr<Event> Clone(const Event& event); | 34 static scoped_ptr<Event> Clone(const Event& event); |
| 35 | 35 |
| 36 virtual ~Event(); | 36 virtual ~Event(); |
| 37 | 37 |
| 38 class DispatcherApi { | 38 class DispatcherApi { |
| 39 public: | 39 public: |
| 40 explicit DispatcherApi(Event* event) : event_(event) {} | 40 explicit DispatcherApi(Event* event) : event_(event) {} |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 virtual ~ExtendedKeyEventData() {} | 663 virtual ~ExtendedKeyEventData() {} |
| 664 | 664 |
| 665 virtual ExtendedKeyEventData* Clone() const = 0; | 665 virtual ExtendedKeyEventData* Clone() const = 0; |
| 666 }; | 666 }; |
| 667 | 667 |
| 668 // A KeyEvent is really two distinct classes, melded together due to the | 668 // A KeyEvent is really two distinct classes, melded together due to the |
| 669 // DOM legacy of Windows key events: a keystroke event (is_char_ == false), | 669 // DOM legacy of Windows key events: a keystroke event (is_char_ == false), |
| 670 // or a character event (is_char_ == true). | 670 // or a character event (is_char_ == true). |
| 671 // | 671 // |
| 672 // For a keystroke event, | 672 // For a keystroke event, |
| 673 // -- is_char_ is false. | 673 // -- |bool is_char_| is false. |
| 674 // -- Event::type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED. | 674 // -- |EventType Event::type()| can be ET_KEY_PRESSED or ET_KEY_RELEASED. |
| 675 // -- code_ and Event::flags() represent the physical key event. | 675 // -- |DomCode code_| and |int Event::flags()| represent the physical key event. |
| 676 // - code_ is a platform-independent representation of the physical key, | 676 // - code_ is a platform-independent representation of the physical key, |
| 677 // based on DOM KeyboardEvent |code| values. It does not vary depending | 677 // based on DOM UI Events KeyboardEvent |code| values. It does not |
| 678 // on key layout. | 678 // vary depending on key layout. |
| 679 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
| 679 // - Event::flags() provides the active modifiers for the physical key | 680 // - Event::flags() provides the active modifiers for the physical key |
| 680 // press. Its value reflects the state after the event; that is, for | 681 // press. Its value reflects the state after the event; that is, for |
| 681 // a modifier key, a press includes the corresponding flag and a release | 682 // a modifier key, a press includes the corresponding flag and a release |
| 682 // does not. | 683 // does not. |
| 683 // -- key_ and character_ provide the meaning of the key event, in the context | 684 // -- |DomKey key_| provides the meaning (character or action) of the key |
| 684 // of the active layout and modifiers. Together they correspond to DOM | 685 // event, in the context of the active layout and modifiers. It corresponds |
| 685 // KeyboardEvent |key| values. | 686 // to DOM UI Events KeyboardEvent |key| values. |
| 686 // - key_ is an enumeration of non-Unicode meanings, plus sentinels | 687 // http://www.w3.org/TR/DOM-Level-3-Events-key/ |
| 687 // (specifically DomKey::CHARACTER for Unicode meanings). | 688 // -- |KeyboardCode key_code_| supports the legacy web event |keyCode| field, |
| 688 // - character_ is the code point for Unicode meanings. | 689 // and its VKEY_ values are chosen to match Windows/IE for compatibility. |
| 689 // -- key_code_ is a KeyboardCode value associated with the key. This supports | 690 // For printable characters, this may or may not be a layout-mapped value, |
| 690 // the legacy web event |keyCode| field, and the VKEY_ values are chosen | 691 // imitating MS Windows: if the mapped key generates a character that has |
| 691 // to match Windows/IE for compatibility. For printable characters, this | 692 // an associated VKEY_ code, then key_code_ is that code; if not, then |
| 692 // may or may not be a layout-mapped value, imitating MS Windows: | 693 // key_code_ is the unmapped VKEY_ code. For example, US, Greek, Cyrillic, |
| 693 // if the mapped key generates a character that has an associated VKEY_ | 694 // Japanese, etc. all use VKEY_Q for the key beside Tab, while French uses |
| 694 // code, then key_code_ is that code; if not, then key_code_ is the unmapped | 695 // VKEY_A. The stored key_code_ is non-located (e.g. VKEY_SHIFT rather than |
| 695 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use | 696 // VKEY_LSHIFT, VKEY_1 rather than VKEY_NUMPAD1). |
| 696 // VKEY_Q for the key beside Tab, while French uses VKEY_A. The stored | |
| 697 // key_code_ is non-located (e.g. VKEY_SHIFT rather than VKEY_LSHIFT, | |
| 698 // VKEY_1 rather than VKEY_NUMPAD1). | |
| 699 // | 697 // |
| 700 // For a character event, | 698 // For a character event, |
| 701 // -- is_char_ is true. | 699 // -- |bool is_char_| is true. |
| 702 // -- type() is ET_KEY_PRESSED. | 700 // -- |EventType Event::type()| is ET_KEY_PRESSED. |
| 703 // -- code_ is DomCode::NONE. | 701 // -- |DomCode code_| is DomCode::NONE. |
| 704 // -- key_ is DomKey::CHARACTER and character_ is a UTF-16 code point. | 702 // -- |DomKey key_| is a UTF-16 code point. |
| 705 // -- key_code_ is conflated with character_ by some code, because both | 703 // -- |KeyboardCode key_code_| is conflated with the character-valued key_ |
| 706 // arrive in the wParam field of a Windows event. | 704 // by some code, because both arrive in the wParam field of a Windows event. |
| 707 // | 705 // |
| 708 class EVENTS_EXPORT KeyEvent : public Event { | 706 class EVENTS_EXPORT KeyEvent : public Event { |
| 709 public: | 707 public: |
| 710 // Create a KeyEvent from a NativeEvent. For Windows this native event can | 708 // Create a KeyEvent from a NativeEvent. For Windows this native event can |
| 711 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message | 709 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message |
| 712 // (WM_CHAR). Other systems have only keystroke events. | 710 // (WM_CHAR). Other systems have only keystroke events. |
| 713 explicit KeyEvent(const base::NativeEvent& native_event); | 711 explicit KeyEvent(const base::NativeEvent& native_event); |
| 714 | 712 |
| 715 // Create a keystroke event. | 713 // Create a keystroke event from a legacy KeyboardCode. |
| 714 // This should not be used in new code. |
| 716 KeyEvent(EventType type, KeyboardCode key_code, int flags); | 715 KeyEvent(EventType type, KeyboardCode key_code, int flags); |
| 717 | 716 |
| 718 // Create a fully defined keystroke event. | 717 // Create a fully defined keystroke event. |
| 719 KeyEvent(EventType type, | 718 KeyEvent(EventType type, |
| 720 KeyboardCode key_code, | 719 KeyboardCode key_code, |
| 721 DomCode code, | 720 DomCode code, |
| 722 int flags, | 721 int flags, |
| 723 DomKey key, | 722 DomKey key, |
| 724 base::char16 character, | |
| 725 base::TimeDelta time_stamp); | 723 base::TimeDelta time_stamp); |
| 726 | 724 |
| 727 // Create a character event. | 725 // Create a character event. |
| 728 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); | 726 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); |
| 729 | 727 |
| 730 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') | 728 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') |
| 731 // See also: ui/events/keycodes/dom/dom_values.txt | 729 // See also: ui/events/keycodes/dom/dom_values.txt |
| 732 KeyEvent(EventType type, | 730 KeyEvent(EventType type, |
| 733 KeyboardCode key_code, | 731 KeyboardCode key_code, |
| 734 DomCode code, | 732 DomCode code, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 748 // resulting data when read across IPC boundaries. | 746 // resulting data when read across IPC boundaries. |
| 749 void SetExtendedKeyEventData(scoped_ptr<ExtendedKeyEventData> data); | 747 void SetExtendedKeyEventData(scoped_ptr<ExtendedKeyEventData> data); |
| 750 const ExtendedKeyEventData* extended_key_event_data() const { | 748 const ExtendedKeyEventData* extended_key_event_data() const { |
| 751 return extended_key_event_data_.get(); | 749 return extended_key_event_data_.get(); |
| 752 } | 750 } |
| 753 | 751 |
| 754 // This bypasses the normal mapping from keystroke events to characters, | 752 // This bypasses the normal mapping from keystroke events to characters, |
| 755 // which allows an I18N virtual keyboard to fabricate a keyboard event that | 753 // which allows an I18N virtual keyboard to fabricate a keyboard event that |
| 756 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small | 754 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small |
| 757 // letter A with acute, U+0410 Cyrillic capital letter A). | 755 // letter A with acute, U+0410 Cyrillic capital letter A). |
| 758 void set_character(base::char16 character) { character_ = character; } | 756 void set_character(base::char16 character) { |
| 757 key_ = DomKey::FromCharacter(character); |
| 758 } |
| 759 | 759 |
| 760 // Gets the character generated by this key event. It only supports Unicode | 760 // Gets the character generated by this key event. It only supports Unicode |
| 761 // BMP characters. | 761 // BMP characters. |
| 762 base::char16 GetCharacter() const; | 762 base::char16 GetCharacter() const; |
| 763 | 763 |
| 764 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; | 764 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; |
| 765 // otherwise returns the same as GetCharacter(). | 765 // otherwise returns the same as GetCharacter(). |
| 766 base::char16 GetUnmodifiedText() const; | 766 base::char16 GetUnmodifiedText() const; |
| 767 | 767 |
| 768 // If the Control key is down in the event, returns a layout-independent | 768 // If the Control key is down in the event, returns a layout-independent |
| 769 // character (corresponding to US layout); otherwise returns the same | 769 // character (corresponding to US layout); otherwise returns the same |
| 770 // as GetUnmodifiedText(). | 770 // as GetUnmodifiedText(). |
| 771 base::char16 GetText() const; | 771 base::char16 GetText() const; |
| 772 | 772 |
| 773 // Gets the platform key code. For XKB, this is the xksym value. | 773 // Gets the platform key code. For XKB, this is the xksym value. |
| 774 // This should not be used in new code. |
| 774 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } | 775 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } |
| 775 uint32 platform_keycode() const { return platform_keycode_; } | 776 uint32 platform_keycode() const { return platform_keycode_; } |
| 776 | 777 |
| 777 // Gets the associated (Windows-based) KeyboardCode for this key event. | 778 // Gets the associated (Windows-based) KeyboardCode for this key event. |
| 778 // Historically, this has also been used to obtain the character associated | 779 // Historically, this has also been used to obtain the character associated |
| 779 // with a character event, because both use the Window message 'wParam' field. | 780 // with a character event, because both use the Window message 'wParam' field. |
| 780 // This should be avoided; if necessary for backwards compatibility, use | 781 // This should be avoided; if necessary for backwards compatibility, use |
| 781 // GetConflatedWindowsKeyCode(). | 782 // GetConflatedWindowsKeyCode(). |
| 782 KeyboardCode key_code() const { return key_code_; } | 783 KeyboardCode key_code() const { return key_code_; } |
| 783 | 784 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 814 // (Native X11 event flags describe the state before the event.) | 815 // (Native X11 event flags describe the state before the event.) |
| 815 void NormalizeFlags(); | 816 void NormalizeFlags(); |
| 816 | 817 |
| 817 protected: | 818 protected: |
| 818 friend class KeyEventTestApi; | 819 friend class KeyEventTestApi; |
| 819 | 820 |
| 820 // This allows a subclass TranslatedKeyEvent to be a non character event. | 821 // This allows a subclass TranslatedKeyEvent to be a non character event. |
| 821 void set_is_char(bool is_char) { is_char_ = is_char; } | 822 void set_is_char(bool is_char) { is_char_ = is_char; } |
| 822 | 823 |
| 823 private: | 824 private: |
| 824 // Determine key_ and character_ on a keystroke event from code_ and flags(). | 825 // Determine key_ on a keystroke event from code_ and flags(). |
| 825 void ApplyLayout() const; | 826 void ApplyLayout() const; |
| 826 | 827 |
| 827 KeyboardCode key_code_; | 828 KeyboardCode key_code_; |
| 828 | 829 |
| 829 // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE). | 830 // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE). |
| 830 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 831 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
| 831 // | 832 // |
| 832 // This value represents the physical position in the keyboard and can be | 833 // This value represents the physical position in the keyboard and can be |
| 833 // converted from / to keyboard scan code like XKB. | 834 // converted from / to keyboard scan code like XKB. |
| 834 DomCode code_; | 835 DomCode code_; |
| 835 | 836 |
| 836 // True if this is a character event, false if this is a keystroke event. | 837 // True if this is a character event, false if this is a keystroke event. |
| 837 bool is_char_; | 838 bool is_char_ = false; |
| 838 | 839 |
| 839 // The platform related keycode value. For XKB, it's keysym value. | 840 // The platform related keycode value. For XKB, it's keysym value. |
| 840 // For now, this is used for CharacterComposer in ChromeOS. | 841 // For now, this is used for CharacterComposer in ChromeOS. |
| 841 mutable uint32 platform_keycode_; | 842 mutable uint32 platform_keycode_ = 0; |
| 842 | 843 |
| 843 // TODO(kpschoedel): refactor so that key_ and character_ are not mutable. | 844 // TODO(kpschoedel): refactor so that key_ is not mutable. |
| 844 // This requires defining the KeyEvent completely at construction rather | 845 // This requires defining the KeyEvent completely at construction rather |
| 845 // than lazily under GetCharacter(), which likely also means removing | 846 // than lazily under GetCharacter(), which likely also means removing |
| 846 // the two 'incomplete' constructors. crbug.com/444045 | 847 // the two 'incomplete' constructors. crbug.com/444045 |
| 847 // | 848 // |
| 848 // DOM KeyboardEvent |key| | 849 // DOM KeyboardEvent |key| |
| 849 // http://www.w3.org/TR/DOM-Level-3-Events-key/ | 850 // http://www.w3.org/TR/DOM-Level-3-Events-key/ |
| 850 // | 851 // |
| 851 // This value, together with character_, represents the meaning of a key. | 852 // This value represents the meaning of a key, which is either a Unicode |
| 852 // The value is DomKey::CHARACTER when the interpretation is a character. | 853 // character, or a named DomKey:: value. |
| 853 // This, along with character_, is not necessarily initialized when the | 854 // This is not necessarily initialized when the event is constructed; |
| 854 // event is constructed; it may be set only if and when GetCharacter() | 855 // it may be set only if and when GetCharacter() or GetDomKey() is called. |
| 855 // or GetDomKey() is called. | 856 mutable DomKey key_ = DomKey::NONE; |
| 856 mutable DomKey key_; | |
| 857 | |
| 858 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'รข') | |
| 859 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | |
| 860 // | |
| 861 // This value represents the text that the key event will insert to input | |
| 862 // field. For key with modifier key, it may have specifial text. | |
| 863 // e.g. CTRL+A has '\x01'. | |
| 864 mutable base::char16 character_; | |
| 865 | 857 |
| 866 // Parts of our event handling require raw native events (see both the | 858 // Parts of our event handling require raw native events (see both the |
| 867 // windows and linux implementations of web_input_event in content/). Because | 859 // windows and linux implementations of web_input_event in content/). Because |
| 868 // mojo instead serializes and deserializes events in potentially different | 860 // mojo instead serializes and deserializes events in potentially different |
| 869 // processes, we need to have a mechanism to keep track of this data. | 861 // processes, we need to have a mechanism to keep track of this data. |
| 870 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; | 862 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; |
| 871 | 863 |
| 872 static bool IsRepeated(const KeyEvent& event); | 864 static bool IsRepeated(const KeyEvent& event); |
| 873 | 865 |
| 874 static KeyEvent* last_key_event_; | 866 static KeyEvent* last_key_event_; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 | 935 |
| 944 const GestureEventDetails& details() const { return details_; } | 936 const GestureEventDetails& details() const { return details_; } |
| 945 | 937 |
| 946 private: | 938 private: |
| 947 GestureEventDetails details_; | 939 GestureEventDetails details_; |
| 948 }; | 940 }; |
| 949 | 941 |
| 950 } // namespace ui | 942 } // namespace ui |
| 951 | 943 |
| 952 #endif // UI_EVENTS_EVENT_H_ | 944 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |