| 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" |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 // VKEY_Q for the key beside Tab, while French uses VKEY_A. | 580 // VKEY_Q for the key beside Tab, while French uses VKEY_A. |
| 581 // -- code_ is in one-to-one correspondence with a physical keyboard | 581 // -- code_ is in one-to-one correspondence with a physical keyboard |
| 582 // location, and does not vary depending on key layout. | 582 // location, and does not vary depending on key layout. |
| 583 // | 583 // |
| 584 // For a character event, | 584 // For a character event, |
| 585 // -- is_char_ is true. | 585 // -- is_char_ is true. |
| 586 // -- type() is ET_KEY_PRESSED. | 586 // -- type() is ET_KEY_PRESSED. |
| 587 // -- character_ is a UTF-16 character value. | 587 // -- character_ is a UTF-16 character value. |
| 588 // -- key_code_ is conflated with character_ by some code, because both | 588 // -- key_code_ is conflated with character_ by some code, because both |
| 589 // arrive in the wParam field of a Windows event. | 589 // arrive in the wParam field of a Windows event. |
| 590 // -- code_ is the empty string. | 590 // -- code_ is "". |
| 591 // | 591 // |
| 592 class EVENTS_EXPORT KeyEvent : public Event { | 592 class EVENTS_EXPORT KeyEvent : public Event { |
| 593 public: | 593 public: |
| 594 // Create a KeyEvent from a NativeEvent. For Windows this native event can | 594 // Create a KeyEvent from a NativeEvent. For Windows this native event can |
| 595 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message | 595 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message |
| 596 // (WM_CHAR). Other systems have only keystroke events. | 596 // (WM_CHAR). Other systems have only keystroke events. |
| 597 explicit KeyEvent(const base::NativeEvent& native_event); | 597 explicit KeyEvent(const base::NativeEvent& native_event); |
| 598 | 598 |
| 599 // Create a keystroke event. | 599 // Create a keystroke event. |
| 600 KeyEvent(EventType type, KeyboardCode key_code, int flags); | 600 KeyEvent(EventType type, KeyboardCode key_code, int flags); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 629 // This bypasses the normal mapping from keystroke events to characters, | 629 // This bypasses the normal mapping from keystroke events to characters, |
| 630 // which allows an I18N virtual keyboard to fabricate a keyboard event that | 630 // which allows an I18N virtual keyboard to fabricate a keyboard event that |
| 631 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small | 631 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small |
| 632 // letter A with acute, U+0410 Cyrillic capital letter A). | 632 // letter A with acute, U+0410 Cyrillic capital letter A). |
| 633 void set_character(base::char16 character) { character_ = character; } | 633 void set_character(base::char16 character) { character_ = character; } |
| 634 | 634 |
| 635 // Gets the character generated by this key event. It only supports Unicode | 635 // Gets the character generated by this key event. It only supports Unicode |
| 636 // BMP characters. | 636 // BMP characters. |
| 637 base::char16 GetCharacter() const; | 637 base::char16 GetCharacter() const; |
| 638 | 638 |
| 639 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r'; | |
| 640 // otherwise returns the same as GetCharacter(). | |
| 641 base::char16 GetUnmodifiedText() const; | |
| 642 | |
| 643 // If the Control key is down in the event, returns a layout-independent | |
| 644 // character (corresponding to US layout); otherwise returns the same | |
| 645 // as GetUnmodifiedText(). | |
| 646 base::char16 GetText() const; | |
| 647 | |
| 648 // Gets the platform key code. For XKB, this is the xksym value. | 639 // Gets the platform key code. For XKB, this is the xksym value. |
| 649 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } | 640 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } |
| 650 uint32 platform_keycode() const { return platform_keycode_; } | 641 uint32 platform_keycode() const { return platform_keycode_; } |
| 651 | |
| 652 // Gets the associated (Windows-based) KeyboardCode for this key event. | |
| 653 // Historically, this has also been used to obtain the character associated | |
| 654 // with a character event, because both use the Window message 'wParam' field. | |
| 655 // This should be avoided; if necessary for backwards compatibility, use | |
| 656 // GetConflatedWindowsKeyCode(). | |
| 657 KeyboardCode key_code() const { return key_code_; } | 642 KeyboardCode key_code() const { return key_code_; } |
| 658 | 643 |
| 659 // True if this is a character event, false if this is a keystroke event. | 644 // True if this is a character event, false if this is a keystroke event. |
| 660 bool is_char() const { return is_char_; } | 645 bool is_char() const { return is_char_; } |
| 661 | 646 |
| 662 // This is only intended to be used externally by classes that are modifying | 647 // This is only intended to be used externally by classes that are modifying |
| 663 // events in an EventRewriter. | 648 // events in an EventRewriter. |
| 664 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } | 649 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } |
| 665 | 650 |
| 666 // Returns the same value as key_code(), except that located codes are | |
| 667 // returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT | |
| 668 // instead of VKEY_SHIFT). This is a hybrid of semantic and physical | |
| 669 // for legacy DOM reasons. | |
| 670 KeyboardCode GetLocatedWindowsKeyboardCode() const; | |
| 671 | |
| 672 // For a keystroke event, returns the same value as key_code(). | |
| 673 // For a character event, returns the same value as GetCharacter(). | |
| 674 // This exists for backwards compatibility with Windows key events. | |
| 675 uint16 GetConflatedWindowsKeyCode() const; | |
| 676 | |
| 677 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. | 651 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. |
| 678 // TODO(msw): Additional work may be needed for analogues on other platforms. | 652 // TODO(msw): Additional work may be needed for analogues on other platforms. |
| 679 bool IsUnicodeKeyCode() const; | 653 bool IsUnicodeKeyCode() const; |
| 680 | 654 |
| 681 std::string code() const { return code_; } | 655 std::string code() const { return code_; } |
| 682 | 656 |
| 683 // Normalizes flags_ so that it describes the state after the event. | 657 // Normalizes flags_ so that it describes the state after the event. |
| 684 // (Native X11 event flags describe the state before the event.) | 658 // (Native X11 event flags describe the state before the event.) |
| 685 void NormalizeFlags(); | 659 void NormalizeFlags(); |
| 686 | 660 |
| 687 // Returns true if the key event has already been processed by an input method | 661 // Returns true if the key event has already been processed by an input method |
| 688 // and there is no need to pass the key event to the input method again. | 662 // and there is no need to pass the key event to the input method again. |
| 689 bool IsTranslated() const; | 663 bool IsTranslated() const; |
| 690 // Marks this key event as translated or not translated. | 664 // Marks this key event as translated or not translated. |
| 691 void SetTranslated(bool translated); | 665 void SetTranslated(bool translated); |
| 692 | 666 |
| 693 protected: | 667 protected: |
| 694 friend class KeyEventTestApi; | 668 friend class KeyEventTestApi; |
| 695 | 669 |
| 696 // This allows a subclass TranslatedKeyEvent to be a non character event. | 670 // This allows a subclass TranslatedKeyEvent to be a non character event. |
| 697 void set_is_char(bool is_char) { is_char_ = is_char; } | 671 void set_is_char(bool is_char) { is_char_ = is_char; } |
| 698 | 672 |
| 699 private: | 673 private: |
| 700 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). | |
| 701 bool IsRightSideKey() const; | |
| 702 | |
| 703 KeyboardCode key_code_; | 674 KeyboardCode key_code_; |
| 704 | 675 |
| 705 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') | 676 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') |
| 706 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | 677 // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
| 707 // | 678 // |
| 708 // This value represents the physical position in the keyboard and can be | 679 // This value represents the physical position in the keyboard and can be |
| 709 // converted from / to keyboard scan code like XKB. | 680 // converted from / to keyboard scan code like XKB. |
| 710 std::string code_; | 681 std::string code_; |
| 711 | 682 |
| 712 // True if this is a character event, false if this is a keystroke event. | 683 // True if this is a character event, false if this is a keystroke event. |
| 713 bool is_char_; | 684 bool is_char_; |
| 714 | 685 |
| 715 // The platform related keycode value. For XKB, it's keysym value. | 686 // The platform related keycode value. For XKB, it's keysym value. |
| 716 // For now, this is used for CharacterComposer in ChromeOS. | 687 // For now, this is used for CharacterComposer in ChromeOS. |
| 717 uint32 platform_keycode_; | 688 uint32 platform_keycode_; |
| 718 | 689 |
| 719 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') | 690 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') |
| 720 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | 691 // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
| 721 // | 692 // |
| 722 // This value represents the text that the key event will insert to input | 693 // This value represents the text that the key event will insert to input |
| 723 // field. For key with modifier key, it may have specifial text. | 694 // field. For key with modifier key, it may have specifial text. |
| 724 // e.g. CTRL+A has '\x01'. | 695 // e.g. CTRL+A has '\x01'. |
| 725 mutable base::char16 character_; | 696 base::char16 character_; |
| 726 | 697 |
| 727 // Parts of our event handling require raw native events (see both the | 698 // Parts of our event handling require raw native events (see both the |
| 728 // windows and linux implementations of web_input_event in content/). Because | 699 // windows and linux implementations of web_input_event in content/). Because |
| 729 // mojo instead serializes and deserializes events in potentially different | 700 // mojo instead serializes and deserializes events in potentially different |
| 730 // processes, we need to have a mechanism to keep track of this data. | 701 // processes, we need to have a mechanism to keep track of this data. |
| 731 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; | 702 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; |
| 732 | 703 |
| 733 static bool IsRepeated(const KeyEvent& event); | 704 static bool IsRepeated(const KeyEvent& event); |
| 734 | 705 |
| 735 static KeyEvent* last_key_event_; | 706 static KeyEvent* last_key_event_; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 | 775 |
| 805 const GestureEventDetails& details() const { return details_; } | 776 const GestureEventDetails& details() const { return details_; } |
| 806 | 777 |
| 807 private: | 778 private: |
| 808 GestureEventDetails details_; | 779 GestureEventDetails details_; |
| 809 }; | 780 }; |
| 810 | 781 |
| 811 } // namespace ui | 782 } // namespace ui |
| 812 | 783 |
| 813 #endif // UI_EVENTS_EVENT_H_ | 784 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |