| 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 "". | 590 // -- code_ is the empty string. |
| 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 |
| 639 // Gets the platform key code. For XKB, this is the xksym value. | 648 // Gets the platform key code. For XKB, this is the xksym value. |
| 640 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } | 649 void set_platform_keycode(uint32 keycode) { platform_keycode_ = keycode; } |
| 641 uint32 platform_keycode() const { return platform_keycode_; } | 650 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(). |
| 642 KeyboardCode key_code() const { return key_code_; } | 657 KeyboardCode key_code() const { return key_code_; } |
| 643 | 658 |
| 644 // True if this is a character event, false if this is a keystroke event. | 659 // True if this is a character event, false if this is a keystroke event. |
| 645 bool is_char() const { return is_char_; } | 660 bool is_char() const { return is_char_; } |
| 646 | 661 |
| 647 // This is only intended to be used externally by classes that are modifying | 662 // This is only intended to be used externally by classes that are modifying |
| 648 // events in an EventRewriter. | 663 // events in an EventRewriter. |
| 649 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } | 664 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } |
| 650 | 665 |
| 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 |
| 651 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. | 677 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. |
| 652 // TODO(msw): Additional work may be needed for analogues on other platforms. | 678 // TODO(msw): Additional work may be needed for analogues on other platforms. |
| 653 bool IsUnicodeKeyCode() const; | 679 bool IsUnicodeKeyCode() const; |
| 654 | 680 |
| 655 std::string code() const { return code_; } | 681 std::string code() const { return code_; } |
| 656 | 682 |
| 657 // Normalizes flags_ so that it describes the state after the event. | 683 // Normalizes flags_ so that it describes the state after the event. |
| 658 // (Native X11 event flags describe the state before the event.) | 684 // (Native X11 event flags describe the state before the event.) |
| 659 void NormalizeFlags(); | 685 void NormalizeFlags(); |
| 660 | 686 |
| 661 // Returns true if the key event has already been processed by an input method | 687 // Returns true if the key event has already been processed by an input method |
| 662 // and there is no need to pass the key event to the input method again. | 688 // and there is no need to pass the key event to the input method again. |
| 663 bool IsTranslated() const; | 689 bool IsTranslated() const; |
| 664 // Marks this key event as translated or not translated. | 690 // Marks this key event as translated or not translated. |
| 665 void SetTranslated(bool translated); | 691 void SetTranslated(bool translated); |
| 666 | 692 |
| 667 protected: | 693 protected: |
| 668 friend class KeyEventTestApi; | 694 friend class KeyEventTestApi; |
| 669 | 695 |
| 670 // This allows a subclass TranslatedKeyEvent to be a non character event. | 696 // This allows a subclass TranslatedKeyEvent to be a non character event. |
| 671 void set_is_char(bool is_char) { is_char_ = is_char; } | 697 void set_is_char(bool is_char) { is_char_ = is_char; } |
| 672 | 698 |
| 673 private: | 699 private: |
| 700 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). |
| 701 bool IsRightSideKey() const; |
| 702 |
| 674 KeyboardCode key_code_; | 703 KeyboardCode key_code_; |
| 675 | 704 |
| 676 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') | 705 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') |
| 677 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | 706 // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
| 678 // | 707 // |
| 679 // This value represents the physical position in the keyboard and can be | 708 // This value represents the physical position in the keyboard and can be |
| 680 // converted from / to keyboard scan code like XKB. | 709 // converted from / to keyboard scan code like XKB. |
| 681 std::string code_; | 710 std::string code_; |
| 682 | 711 |
| 683 // True if this is a character event, false if this is a keystroke event. | 712 // True if this is a character event, false if this is a keystroke event. |
| 684 bool is_char_; | 713 bool is_char_; |
| 685 | 714 |
| 686 // The platform related keycode value. For XKB, it's keysym value. | 715 // The platform related keycode value. For XKB, it's keysym value. |
| 687 // For now, this is used for CharacterComposer in ChromeOS. | 716 // For now, this is used for CharacterComposer in ChromeOS. |
| 688 uint32 platform_keycode_; | 717 uint32 platform_keycode_; |
| 689 | 718 |
| 690 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') | 719 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') |
| 691 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | 720 // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
| 692 // | 721 // |
| 693 // This value represents the text that the key event will insert to input | 722 // This value represents the text that the key event will insert to input |
| 694 // field. For key with modifier key, it may have specifial text. | 723 // field. For key with modifier key, it may have specifial text. |
| 695 // e.g. CTRL+A has '\x01'. | 724 // e.g. CTRL+A has '\x01'. |
| 696 base::char16 character_; | 725 mutable base::char16 character_; |
| 697 | 726 |
| 698 // Parts of our event handling require raw native events (see both the | 727 // Parts of our event handling require raw native events (see both the |
| 699 // windows and linux implementations of web_input_event in content/). Because | 728 // windows and linux implementations of web_input_event in content/). Because |
| 700 // mojo instead serializes and deserializes events in potentially different | 729 // mojo instead serializes and deserializes events in potentially different |
| 701 // processes, we need to have a mechanism to keep track of this data. | 730 // processes, we need to have a mechanism to keep track of this data. |
| 702 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; | 731 scoped_ptr<ExtendedKeyEventData> extended_key_event_data_; |
| 703 | 732 |
| 704 static bool IsRepeated(const KeyEvent& event); | 733 static bool IsRepeated(const KeyEvent& event); |
| 705 | 734 |
| 706 static KeyEvent* last_key_event_; | 735 static KeyEvent* last_key_event_; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 | 804 |
| 776 const GestureEventDetails& details() const { return details_; } | 805 const GestureEventDetails& details() const { return details_; } |
| 777 | 806 |
| 778 private: | 807 private: |
| 779 GestureEventDetails details_; | 808 GestureEventDetails details_; |
| 780 }; | 809 }; |
| 781 | 810 |
| 782 } // namespace ui | 811 } // namespace ui |
| 783 | 812 |
| 784 #endif // UI_EVENTS_EVENT_H_ | 813 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |