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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 virtual ~ExtendedKeyEventData() {} | 591 virtual ~ExtendedKeyEventData() {} |
592 | 592 |
593 virtual ExtendedKeyEventData* Clone() const = 0; | 593 virtual ExtendedKeyEventData* Clone() const = 0; |
594 }; | 594 }; |
595 | 595 |
596 // A KeyEvent is really two distinct classes, melded together due to the | 596 // A KeyEvent is really two distinct classes, melded together due to the |
597 // DOM legacy of Windows key events: a keystroke event (is_char_ == false), | 597 // DOM legacy of Windows key events: a keystroke event (is_char_ == false), |
598 // or a character event (is_char_ == true). | 598 // or a character event (is_char_ == true). |
599 // | 599 // |
600 // For a keystroke event, | 600 // For a keystroke event, |
601 // -- is_char_ is false. | 601 // -- |bool is_char_| is false. |
602 // -- Event::type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED. | 602 // -- |EventType Event::type()| can be ET_KEY_PRESSED or ET_KEY_RELEASED. |
603 // -- code_ and Event::flags() represent the physical key event. | 603 // -- |DomCode code_| and |int Event::flags()| represent the physical key event. |
604 // - code_ is a platform-independent representation of the physical key, | 604 // - code_ is a platform-independent representation of the physical key, |
605 // based on DOM KeyboardEvent |code| values. It does not vary depending | 605 // based on DOM UI Events KeyboardEvent |code| values. It does not |
606 // on key layout. | 606 // vary depending on key layout. |
607 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | |
607 // - Event::flags() provides the active modifiers for the physical key | 608 // - Event::flags() provides the active modifiers for the physical key |
608 // press. Its value reflects the state after the event; that is, for | 609 // press. Its value reflects the state after the event; that is, for |
609 // a modifier key, a press includes the corresponding flag and a release | 610 // a modifier key, a press includes the corresponding flag and a release |
610 // does not. | 611 // does not. |
611 // -- key_ and character_ provide the meaning of the key event, in the context | 612 // -- |DomKey key_| provides the meaning (character or action) of the key |
612 // of the active layout and modifiers. Together they correspond to DOM | 613 // event, in the context of the active layout and modifiers. It corresponds |
613 // KeyboardEvent |key| values. | 614 // to DOM UI Events KeyboardEvent |key| values. |
614 // - key_ is an enumeration of non-Unicode meanings, plus sentinels | 615 // http://www.w3.org/TR/DOM-Level-3-Events-key/ |
615 // (specifically DomKey::CHARACTER for Unicode meanings). | 616 // -- |KeyboardCode key_code_| supports the legacy web event |keyCode| field, |
616 // - character_ is the code point for Unicode meanings. | 617 // and its VKEY_ values are chosen to match Windows/IE for compatibility. |
617 // -- key_code_ is a KeyboardCode value associated with the key. This supports | 618 // For printable characters, this may or may not be a layout-mapped value, |
618 // the legacy web event |keyCode| field, and the VKEY_ values are chosen | 619 // imitating MS Windows: if the mapped key generates a character that has |
619 // to match Windows/IE for compatibility. For printable characters, this | 620 // an associated VKEY_ code, then key_code_ is that code; if not, then |
620 // may or may not be a layout-mapped value, imitating MS Windows: | 621 // key_code_ is the unmapped VKEY_ code. For example, US, Greek, Cyrillic, |
621 // if the mapped key generates a character that has an associated VKEY_ | 622 // Japanese, etc. all use VKEY_Q for the key beside Tab, while French uses |
622 // code, then key_code_ is that code; if not, then key_code_ is the unmapped | 623 // VKEY_A. The stored key_code_ is non-located (e.g. VKEY_SHIFT rather than |
623 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use | 624 // VKEY_LSHIFT, VKEY_1 rather than VKEY_NUMPAD1). |
624 // VKEY_Q for the key beside Tab, while French uses VKEY_A. The stored | |
625 // key_code_ is non-located (e.g. VKEY_SHIFT rather than VKEY_LSHIFT, | |
626 // VKEY_1 rather than VKEY_NUMPAD1). | |
627 // | 625 // |
628 // For a character event, | 626 // For a character event, |
629 // -- is_char_ is true. | 627 // -- |bool is_char_| is true. |
630 // -- type() is ET_KEY_PRESSED. | 628 // -- |EventType Event::type()| is ET_KEY_PRESSED. |
631 // -- code_ is DomCode::NONE. | 629 // -- |DomCode code_| is DomCode::NONE. |
632 // -- key_ is DomKey::CHARACTER and character_ is a UTF-16 code point. | 630 // -- |DomKey key_| is a UTF-16 code point. |
633 // -- key_code_ is conflated with character_ by some code, because both | 631 // -- |KeyboardCode key_code_| is conflated with the character-valued key_ |
634 // arrive in the wParam field of a Windows event. | 632 // by some code, because both arrive in the wParam field of a Windows event. |
635 // | 633 // |
636 class EVENTS_EXPORT KeyEvent : public Event { | 634 class EVENTS_EXPORT KeyEvent : public Event { |
637 public: | 635 public: |
638 // Create a KeyEvent from a NativeEvent. For Windows this native event can | 636 // Create a KeyEvent from a NativeEvent. For Windows this native event can |
639 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message | 637 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message |
640 // (WM_CHAR). Other systems have only keystroke events. | 638 // (WM_CHAR). Other systems have only keystroke events. |
641 explicit KeyEvent(const base::NativeEvent& native_event); | 639 explicit KeyEvent(const base::NativeEvent& native_event); |
642 | 640 |
643 // Create a keystroke event. | 641 // Create a keystroke event from a legacy KeyboardCode. |
642 // This should not be used in new code. | |
644 KeyEvent(EventType type, KeyboardCode key_code, int flags); | 643 KeyEvent(EventType type, KeyboardCode key_code, int flags); |
645 | 644 |
646 // Create a fully defined keystroke event. | 645 // Create a fully defined keystroke event. |
647 KeyEvent(EventType type, | 646 KeyEvent(EventType type, |
648 KeyboardCode key_code, | 647 KeyboardCode key_code, |
649 DomCode code, | 648 DomCode code, |
650 int flags, | 649 int flags, |
651 DomKey key, | 650 DomKey key, |
652 base::char16 character, | |
653 base::TimeDelta time_stamp); | 651 base::TimeDelta time_stamp); |
654 | 652 |
655 // Create a character event. | 653 // Create a character event. |
656 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); | 654 KeyEvent(base::char16 character, KeyboardCode key_code, int flags); |
657 | 655 |
658 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') | 656 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') |
659 // See also: ui/events/keycodes/dom/dom_values.txt | 657 // See also: ui/events/keycodes/dom/dom_values.txt |
660 KeyEvent(EventType type, | 658 KeyEvent(EventType type, |
661 KeyboardCode key_code, | 659 KeyboardCode key_code, |
662 DomCode code, | 660 DomCode code, |
(...skipping 13 matching lines...) Expand all Loading... | |
676 // resulting data when read across IPC boundaries. | 674 // resulting data when read across IPC boundaries. |
677 void SetExtendedKeyEventData(scoped_ptr<ExtendedKeyEventData> data); | 675 void SetExtendedKeyEventData(scoped_ptr<ExtendedKeyEventData> data); |
678 const ExtendedKeyEventData* extended_key_event_data() const { | 676 const ExtendedKeyEventData* extended_key_event_data() const { |
679 return extended_key_event_data_.get(); | 677 return extended_key_event_data_.get(); |
680 } | 678 } |
681 | 679 |
682 // This bypasses the normal mapping from keystroke events to characters, | 680 // This bypasses the normal mapping from keystroke events to characters, |
683 // which allows an I18N virtual keyboard to fabricate a keyboard event that | 681 // which allows an I18N virtual keyboard to fabricate a keyboard event that |
684 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small | 682 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small |
685 // letter A with acute, U+0410 Cyrillic capital letter A). | 683 // letter A with acute, U+0410 Cyrillic capital letter A). |
686 void set_character(base::char16 character) { character_ = character; } | 684 void set_character(base::char16 character) { key_ = character; } |
687 | 685 |
688 // Gets the character generated by this key event. It only supports Unicode | 686 // Gets the character generated by this key event. It only supports Unicode |
689 // BMP characters. | 687 // BMP characters. |
690 base::char16 GetCharacter() const; | 688 base::char16 GetCharacter() const; |
691 | 689 |
692 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; | 690 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; |
693 // otherwise returns the same as GetCharacter(). | 691 // otherwise returns the same as GetCharacter(). |
694 base::char16 GetUnmodifiedText() const; | 692 base::char16 GetUnmodifiedText() const; |
695 | 693 |
696 // If the Control key is down in the event, returns a layout-independent | 694 // If the Control key is down in the event, returns a layout-independent |
697 // character (corresponding to US layout); otherwise returns the same | 695 // character (corresponding to US layout); otherwise returns the same |
698 // as GetUnmodifiedText(). | 696 // as GetUnmodifiedText(). |
699 base::char16 GetText() const; | 697 base::char16 GetText() const; |
700 | 698 |
701 // Gets the platform key code. For XKB, this is the xksym value. | 699 // Gets the platform key code. For XKB, this is the xksym value. |
700 // This should not be used in new code. | |
702 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } | 701 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } |
703 uint32 platform_keycode() const { return platform_keycode_; } | 702 uint32 platform_keycode() const { return platform_keycode_; } |
704 | 703 |
705 // Gets the associated (Windows-based) KeyboardCode for this key event. | 704 // Gets the associated (Windows-based) KeyboardCode for this key event. |
706 // Historically, this has also been used to obtain the character associated | 705 // Historically, this has also been used to obtain the character associated |
707 // with a character event, because both use the Window message 'wParam' field. | 706 // with a character event, because both use the Window message 'wParam' field. |
708 // This should be avoided; if necessary for backwards compatibility, use | 707 // This should be avoided; if necessary for backwards compatibility, use |
709 // GetConflatedWindowsKeyCode(). | 708 // GetConflatedWindowsKeyCode(). |
710 KeyboardCode key_code() const { return key_code_; } | 709 KeyboardCode key_code() const { return key_code_; } |
711 | 710 |
(...skipping 30 matching lines...) Expand all Loading... | |
742 // (Native X11 event flags describe the state before the event.) | 741 // (Native X11 event flags describe the state before the event.) |
743 void NormalizeFlags(); | 742 void NormalizeFlags(); |
744 | 743 |
745 protected: | 744 protected: |
746 friend class KeyEventTestApi; | 745 friend class KeyEventTestApi; |
747 | 746 |
748 // This allows a subclass TranslatedKeyEvent to be a non character event. | 747 // This allows a subclass TranslatedKeyEvent to be a non character event. |
749 void set_is_char(bool is_char) { is_char_ = is_char; } | 748 void set_is_char(bool is_char) { is_char_ = is_char; } |
750 | 749 |
751 private: | 750 private: |
752 // Determine key_ and character_ on a keystroke event from code_ and flags(). | 751 // Determine key_ on a keystroke event from code_ and flags(). |
753 void ApplyLayout() const; | 752 void ApplyLayout() const; |
754 | 753 |
755 KeyboardCode key_code_; | 754 KeyboardCode key_code_; |
756 | 755 |
757 // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE). | 756 // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE). |
758 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 757 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
759 // | 758 // |
760 // This value represents the physical position in the keyboard and can be | 759 // This value represents the physical position in the keyboard and can be |
761 // converted from / to keyboard scan code like XKB. | 760 // converted from / to keyboard scan code like XKB. |
762 DomCode code_; | 761 DomCode code_; |
763 | 762 |
764 // True if this is a character event, false if this is a keystroke event. | 763 // True if this is a character event, false if this is a keystroke event. |
765 bool is_char_; | 764 bool is_char_; |
766 | 765 |
767 // The platform related keycode value. For XKB, it's keysym value. | 766 // The platform related keycode value. For XKB, it's keysym value. |
768 // For now, this is used for CharacterComposer in ChromeOS. | 767 // For now, this is used for CharacterComposer in ChromeOS. |
769 mutable uint32 platform_keycode_; | 768 mutable uint32 platform_keycode_; |
770 | 769 |
771 // TODO(kpschoedel): refactor so that key_ and character_ are not mutable. | 770 // TODO(kpschoedel): refactor so that key_ is not mutable. |
772 // This requires defining the KeyEvent completely at construction rather | 771 // This requires defining the KeyEvent completely at construction rather |
773 // than lazily under GetCharacter(), which likely also means removing | 772 // than lazily under GetCharacter(), which likely also means removing |
774 // the two 'incomplete' constructors. crbug.com/444045 | 773 // the two 'incomplete' constructors. crbug.com/444045 |
775 // | 774 // |
776 // DOM KeyboardEvent |key| | 775 // DOM KeyboardEvent |key| |
777 // http://www.w3.org/TR/DOM-Level-3-Events-key/ | 776 // http://www.w3.org/TR/DOM-Level-3-Events-key/ |
778 // | 777 // |
779 // This value, together with character_, represents the meaning of a key. | 778 // This value represents the meaning of a key, which is either a Unicode |
780 // The value is DomKey::CHARACTER when the interpretation is a character. | 779 // character, or a named DomKey:: value. |
781 // This, along with character_, is not necessarily initialized when the | 780 // This is not necessarily initialized when the event is constructed; |
782 // event is constructed; it may be set only if and when GetCharacter() | 781 // it may be set only if and when GetCharacter() or GetDomKey() is called. |
783 // or GetDomKey() is called. | |
784 mutable DomKey key_; | 782 mutable DomKey key_; |
kpschoedel
2015/08/07 20:42:12
|key_| now subsumes |character_|.
Wez
2015/08/26 23:38:33
*celebratory dance*
| |
785 | 783 |
786 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'รข') | |
787 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | |
788 // | |
789 // This value represents the text that the key event will insert to input | |
790 // field. For key with modifier key, it may have specifial text. | |
791 // e.g. CTRL+A has '\x01'. | |
792 mutable base::char16 character_; | |
793 | |
794 // Parts of our event handling require raw native events (see both the | 784 // Parts of our event handling require raw native events (see both the |
795 // windows and linux implementations of web_input_event in content/). Because | 785 // windows and linux implementations of web_input_event in content/). Because |
796 // mojo instead serializes and deserializes events in potentially different | 786 // mojo instead serializes and deserializes events in potentially different |
797 // processes, we need to have a mechanism to keep track of this data. | 787 // processes, we need to have a mechanism to keep track of this data. |
798 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; | 788 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; |
799 | 789 |
800 static bool IsRepeated(const KeyEvent& event); | 790 static bool IsRepeated(const KeyEvent& event); |
801 | 791 |
802 static KeyEvent* last_key_event_; | 792 static KeyEvent* last_key_event_; |
803 }; | 793 }; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 | 861 |
872 const GestureEventDetails& details() const { return details_; } | 862 const GestureEventDetails& details() const { return details_; } |
873 | 863 |
874 private: | 864 private: |
875 GestureEventDetails details_; | 865 GestureEventDetails details_; |
876 }; | 866 }; |
877 | 867 |
878 } // namespace ui | 868 } // namespace ui |
879 | 869 |
880 #endif // UI_EVENTS_EVENT_H_ | 870 #endif // UI_EVENTS_EVENT_H_ |
OLD | NEW |