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 meaning | |
Wez
2014/12/09 07:00:33
Clarify that the character meaning is explained be
kpschoedel
2014/12/09 19:58:43
Done.
| |
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 meaning) for a keystroke event. | |
702 DomKey GetDomKey() const; | |
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 |
718 // True if this is a character event, false if this is a keystroke event. | 736 // True if this is a character event, false if this is a keystroke event. |
719 bool is_char_; | 737 bool is_char_; |
720 | 738 |
721 // The platform related keycode value. For XKB, it's keysym value. | 739 // The platform related keycode value. For XKB, it's keysym value. |
722 // For now, this is used for CharacterComposer in ChromeOS. | 740 // For now, this is used for CharacterComposer in ChromeOS. |
723 uint32 platform_keycode_; | 741 uint32 platform_keycode_; |
724 | 742 |
743 // TODO(kpschoedel): refactor so that key_ and character_ are not mutable. | |
744 // This requires defining the KeyEvent completely at construction rather | |
745 // than lazily under GetCharacter(), which likely also means removing | |
746 // the two 'incomplete' constructors. | |
747 // | |
748 // DOM KeyboardEvent |key| | |
749 // http://www.w3.org/TR/DOM-Level-3-Events-key/ | |
750 // | |
751 // This value, together with character_, represents the meaning of a key. | |
752 // The value is DomKey::CHARACTER when the interpretation is a character. | |
753 // This, along with character_, may be lazily evaluated, since in some cases | |
754 // (e.g. native ChromeOS) we are not interested in the values until after | |
755 // the event has been transformed. | |
Wez
2014/12/09 07:00:33
What does it mean for it to be "lazily evaluated"?
kpschoedel
2014/12/09 19:58:43
Not set until required by an accessor. Revised the
| |
756 mutable DomKey key_; | |
757 | |
725 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') | 758 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') |
726 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | 759 // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
727 // | 760 // |
728 // This value represents the text that the key event will insert to input | 761 // This value represents the text that the key event will insert to input |
729 // field. For key with modifier key, it may have specifial text. | 762 // field. For key with modifier key, it may have specifial text. |
730 // e.g. CTRL+A has '\x01'. | 763 // e.g. CTRL+A has '\x01'. |
731 mutable base::char16 character_; | 764 mutable base::char16 character_; |
732 | 765 |
733 // Parts of our event handling require raw native events (see both the | 766 // Parts of our event handling require raw native events (see both the |
734 // windows and linux implementations of web_input_event in content/). Because | 767 // windows and linux implementations of web_input_event in content/). Because |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
810 | 843 |
811 const GestureEventDetails& details() const { return details_; } | 844 const GestureEventDetails& details() const { return details_; } |
812 | 845 |
813 private: | 846 private: |
814 GestureEventDetails details_; | 847 GestureEventDetails details_; |
815 }; | 848 }; |
816 | 849 |
817 } // namespace ui | 850 } // namespace ui |
818 | 851 |
819 #endif // UI_EVENTS_EVENT_H_ | 852 #endif // UI_EVENTS_EVENT_H_ |
OLD | NEW |