| 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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // VKEY_Q for the key beside Tab, while French uses VKEY_A. | 562 // VKEY_Q for the key beside Tab, while French uses VKEY_A. |
| 563 // -- code_ is in one-to-one correspondence with a physical keyboard | 563 // -- code_ is in one-to-one correspondence with a physical keyboard |
| 564 // location, and does not vary depending on key layout. | 564 // location, and does not vary depending on key layout. |
| 565 // | 565 // |
| 566 // For a character event, | 566 // For a character event, |
| 567 // -- is_char_ is true. | 567 // -- is_char_ is true. |
| 568 // -- type() is ET_KEY_PRESSED. | 568 // -- type() is ET_KEY_PRESSED. |
| 569 // -- character_ is a UTF-16 character value. | 569 // -- character_ is a UTF-16 character value. |
| 570 // -- key_code_ is conflated with character_ by some code, because both | 570 // -- key_code_ is conflated with character_ by some code, because both |
| 571 // arrive in the wParam field of a Windows event. | 571 // arrive in the wParam field of a Windows event. |
| 572 // -- code_ is "". | 572 // -- code_ is the empty string. |
| 573 // | 573 // |
| 574 class EVENTS_EXPORT KeyEvent : public Event { | 574 class EVENTS_EXPORT KeyEvent : public Event { |
| 575 public: | 575 public: |
| 576 // Create a KeyEvent from a NativeEvent. For Windows this native event can | 576 // Create a KeyEvent from a NativeEvent. For Windows this native event can |
| 577 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message | 577 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message |
| 578 // (WM_CHAR). Other systems have only keystroke events. | 578 // (WM_CHAR). Other systems have only keystroke events. |
| 579 explicit KeyEvent(const base::NativeEvent& native_event); | 579 explicit KeyEvent(const base::NativeEvent& native_event); |
| 580 | 580 |
| 581 // Create a keystroke event. | 581 // Create a keystroke event. |
| 582 KeyEvent(EventType type, KeyboardCode key_code, int flags); | 582 KeyEvent(EventType type, KeyboardCode key_code, int flags); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 605 uint32 platform_keycode() const { return platform_keycode_; } | 605 uint32 platform_keycode() const { return platform_keycode_; } |
| 606 KeyboardCode key_code() const { return key_code_; } | 606 KeyboardCode key_code() const { return key_code_; } |
| 607 | 607 |
| 608 // True if this is a character event, false if this is a keystroke event. | 608 // True if this is a character event, false if this is a keystroke event. |
| 609 bool is_char() const { return is_char_; } | 609 bool is_char() const { return is_char_; } |
| 610 | 610 |
| 611 // This is only intended to be used externally by classes that are modifying | 611 // This is only intended to be used externally by classes that are modifying |
| 612 // events in an EventRewriter. | 612 // events in an EventRewriter. |
| 613 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } | 613 void set_key_code(KeyboardCode key_code) { key_code_ = key_code; } |
| 614 | 614 |
| 615 // Returns the same value as key_code(), except that located codes are |
| 616 // returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT |
| 617 // instead of VKEY_SHIFT). This is a hybrid of semantic and physical |
| 618 // for legacy DOM reasons. |
| 619 KeyboardCode GetLocatedWindowsKeyboardCode() const; |
| 620 |
| 615 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. | 621 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win. |
| 616 // TODO(msw): Additional work may be needed for analogues on other platforms. | 622 // TODO(msw): Additional work may be needed for analogues on other platforms. |
| 617 bool IsUnicodeKeyCode() const; | 623 bool IsUnicodeKeyCode() const; |
| 618 | 624 |
| 619 std::string code() const { return code_; } | 625 std::string code() const { return code_; } |
| 620 | 626 |
| 621 // Normalizes flags_ so that it describes the state after the event. | 627 // Normalizes flags_ so that it describes the state after the event. |
| 622 // (Native X11 event flags describe the state before the event.) | 628 // (Native X11 event flags describe the state before the event.) |
| 623 void NormalizeFlags(); | 629 void NormalizeFlags(); |
| 624 | 630 |
| 625 // Returns true if the key event has already been processed by an input method | 631 // Returns true if the key event has already been processed by an input method |
| 626 // and there is no need to pass the key event to the input method again. | 632 // and there is no need to pass the key event to the input method again. |
| 627 bool IsTranslated() const; | 633 bool IsTranslated() const; |
| 628 // Marks this key event as translated or not translated. | 634 // Marks this key event as translated or not translated. |
| 629 void SetTranslated(bool translated); | 635 void SetTranslated(bool translated); |
| 630 | 636 |
| 631 protected: | 637 protected: |
| 632 friend class KeyEventTestApi; | 638 friend class KeyEventTestApi; |
| 633 | 639 |
| 634 // This allows a subclass TranslatedKeyEvent to be a non character event. | 640 // This allows a subclass TranslatedKeyEvent to be a non character event. |
| 635 void set_is_char(bool is_char) { is_char_ = is_char; } | 641 void set_is_char(bool is_char) { is_char_ = is_char; } |
| 636 | 642 |
| 637 private: | 643 private: |
| 644 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). |
| 645 bool IsRightSideKey() const; |
| 646 |
| 638 KeyboardCode key_code_; | 647 KeyboardCode key_code_; |
| 639 | 648 |
| 640 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') | 649 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') |
| 641 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | 650 // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
| 642 // | 651 // |
| 643 // This value represents the physical position in the keyboard and can be | 652 // This value represents the physical position in the keyboard and can be |
| 644 // converted from / to keyboard scan code like XKB. | 653 // converted from / to keyboard scan code like XKB. |
| 645 std::string code_; | 654 std::string code_; |
| 646 | 655 |
| 647 // True if this is a character event, false if this is a keystroke event. | 656 // True if this is a character event, false if this is a keystroke event. |
| 648 bool is_char_; | 657 bool is_char_; |
| 649 | 658 |
| 650 // The platform related keycode value. For XKB, it's keysym value. | 659 // The platform related keycode value. For XKB, it's keysym value. |
| 651 // For now, this is used for CharacterComposer in ChromeOS. | 660 // For now, this is used for CharacterComposer in ChromeOS. |
| 652 uint32 platform_keycode_; | 661 uint32 platform_keycode_; |
| 653 | 662 |
| 654 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') | 663 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'â') |
| 655 // http://www.w3.org/TR/uievents/#keyboard-key-codes. | 664 // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
| 656 // | 665 // |
| 657 // This value represents the text that the key event will insert to input | 666 // This value represents the text that the key event will insert to input |
| 658 // field. For key with modifier key, it may have specifial text. | 667 // field. For key with modifier key, it may have specifial text. |
| 659 // e.g. CTRL+A has '\x01'. | 668 // e.g. CTRL+A has '\x01'. |
| 660 base::char16 character_; | 669 mutable base::char16 character_; |
| 661 | 670 |
| 662 static bool IsRepeated(const KeyEvent& event); | 671 static bool IsRepeated(const KeyEvent& event); |
| 663 | 672 |
| 664 static KeyEvent* last_key_event_; | 673 static KeyEvent* last_key_event_; |
| 665 }; | 674 }; |
| 666 | 675 |
| 667 class EVENTS_EXPORT ScrollEvent : public MouseEvent { | 676 class EVENTS_EXPORT ScrollEvent : public MouseEvent { |
| 668 public: | 677 public: |
| 669 explicit ScrollEvent(const base::NativeEvent& native_event); | 678 explicit ScrollEvent(const base::NativeEvent& native_event); |
| 670 template <class T> | 679 template <class T> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 | 742 |
| 734 const GestureEventDetails& details() const { return details_; } | 743 const GestureEventDetails& details() const { return details_; } |
| 735 | 744 |
| 736 private: | 745 private: |
| 737 GestureEventDetails details_; | 746 GestureEventDetails details_; |
| 738 }; | 747 }; |
| 739 | 748 |
| 740 } // namespace ui | 749 } // namespace ui |
| 741 | 750 |
| 742 #endif // UI_EVENTS_EVENT_H_ | 751 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |