Chromium Code Reviews| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | |
| 12 #include <unordered_map> | |
| 13 #include <vector> | |
| 11 | 14 |
| 12 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 13 #include "base/event_types.h" | 16 #include "base/event_types.h" |
| 14 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 15 #include "base/logging.h" | 18 #include "base/logging.h" |
| 16 #include "base/macros.h" | 19 #include "base/macros.h" |
| 17 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 18 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 19 #include "ui/events/event_constants.h" | 22 #include "ui/events/event_constants.h" |
| 20 #include "ui/events/gesture_event_details.h" | 23 #include "ui/events/gesture_event_details.h" |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 // For a character event, | 794 // For a character event, |
| 792 // -- |bool is_char_| is true. | 795 // -- |bool is_char_| is true. |
| 793 // -- |EventType Event::type()| is ET_KEY_PRESSED. | 796 // -- |EventType Event::type()| is ET_KEY_PRESSED. |
| 794 // -- |DomCode code_| is DomCode::NONE. | 797 // -- |DomCode code_| is DomCode::NONE. |
| 795 // -- |DomKey key_| is a UTF-16 code point. | 798 // -- |DomKey key_| is a UTF-16 code point. |
| 796 // -- |KeyboardCode key_code_| is conflated with the character-valued key_ | 799 // -- |KeyboardCode key_code_| is conflated with the character-valued key_ |
| 797 // by some code, because both arrive in the wParam field of a Windows event. | 800 // by some code, because both arrive in the wParam field of a Windows event. |
| 798 // | 801 // |
| 799 class EVENTS_EXPORT KeyEvent : public Event { | 802 class EVENTS_EXPORT KeyEvent : public Event { |
| 800 public: | 803 public: |
| 804 using Properties = std::unordered_map<std::string, std::vector<uint8_t>>; | |
| 805 | |
| 801 // Create a KeyEvent from a NativeEvent. For Windows this native event can | 806 // Create a KeyEvent from a NativeEvent. For Windows this native event can |
| 802 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message | 807 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message |
| 803 // (WM_CHAR). Other systems have only keystroke events. | 808 // (WM_CHAR). Other systems have only keystroke events. |
| 804 explicit KeyEvent(const base::NativeEvent& native_event); | 809 explicit KeyEvent(const base::NativeEvent& native_event); |
| 805 | 810 |
| 806 // Create a KeyEvent from a NativeEvent but with mocked flags. | 811 // Create a KeyEvent from a NativeEvent but with mocked flags. |
| 807 // This method is necessary for Windows since MSG does not contain all flags. | 812 // This method is necessary for Windows since MSG does not contain all flags. |
| 808 KeyEvent(const base::NativeEvent& native_event, int event_flags); | 813 KeyEvent(const base::NativeEvent& native_event, int event_flags); |
| 809 | 814 |
| 810 // Create a keystroke event from a legacy KeyboardCode. | 815 // Create a keystroke event from a legacy KeyboardCode. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 DomCode code() const { return code_; }; | 902 DomCode code() const { return code_; }; |
| 898 std::string GetCodeString() const; | 903 std::string GetCodeString() const; |
| 899 | 904 |
| 900 // Returns the DOM .key (layout meaning) for a keystroke event. | 905 // Returns the DOM .key (layout meaning) for a keystroke event. |
| 901 DomKey GetDomKey() const; | 906 DomKey GetDomKey() const; |
| 902 | 907 |
| 903 // Normalizes flags_ so that it describes the state after the event. | 908 // Normalizes flags_ so that it describes the state after the event. |
| 904 // (Native X11 event flags describe the state before the event.) | 909 // (Native X11 event flags describe the state before the event.) |
| 905 void NormalizeFlags(); | 910 void NormalizeFlags(); |
| 906 | 911 |
| 912 // Sets the properties associated with this KeyEvent. | |
| 913 void SetProperties(const Properties& properties); | |
| 914 | |
| 915 // Returns the properties associated with this event, which may be null. | |
| 916 // The properties are meant to provide a way to associate arbitrary key/value | |
| 917 // pairs with KeyEvents and not used by KeyEvent. | |
| 918 const Properties* properties() const { return properties_.get(); } | |
| 919 | |
| 907 protected: | 920 protected: |
| 908 friend class KeyEventTestApi; | 921 friend class KeyEventTestApi; |
| 909 | 922 |
| 910 // This allows a subclass TranslatedKeyEvent to be a non character event. | 923 // This allows a subclass TranslatedKeyEvent to be a non character event. |
| 911 void set_is_char(bool is_char) { is_char_ = is_char; } | 924 void set_is_char(bool is_char) { is_char_ = is_char; } |
| 912 | 925 |
| 913 private: | 926 private: |
| 914 // Determine key_ on a keystroke event from code_ and flags(). | 927 // Determine key_ on a keystroke event from code_ and flags(). |
| 915 void ApplyLayout() const; | 928 void ApplyLayout() const; |
| 916 | 929 |
| 930 static bool IsRepeated(const KeyEvent& event); | |
| 931 | |
| 917 KeyboardCode key_code_; | 932 KeyboardCode key_code_; |
| 918 | 933 |
| 919 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). | 934 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). |
| 920 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 935 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
| 921 // | 936 // |
| 922 // This value represents the physical position in the keyboard and can be | 937 // This value represents the physical position in the keyboard and can be |
| 923 // converted from / to keyboard scan code like XKB. | 938 // converted from / to keyboard scan code like XKB. |
| 924 DomCode code_; | 939 DomCode code_; |
| 925 | 940 |
| 926 // True if this is a character event, false if this is a keystroke event. | 941 // True if this is a character event, false if this is a keystroke event. |
| 927 bool is_char_ = false; | 942 bool is_char_ = false; |
| 928 | 943 |
| 929 // TODO(kpschoedel): refactor so that key_ is not mutable. | 944 // TODO(kpschoedel): refactor so that key_ is not mutable. |
| 930 // This requires defining the KeyEvent completely at construction rather | 945 // This requires defining the KeyEvent completely at construction rather |
| 931 // than lazily under GetCharacter(), which likely also means removing | 946 // than lazily under GetCharacter(), which likely also means removing |
| 932 // the two 'incomplete' constructors. crbug.com/444045 | 947 // the two 'incomplete' constructors. crbug.com/444045 |
| 933 // | 948 // |
| 934 // DOM KeyboardEvent |key| | 949 // DOM KeyboardEvent |key| |
| 935 // http://www.w3.org/TR/DOM-Level-3-Events-key/ | 950 // http://www.w3.org/TR/DOM-Level-3-Events-key/ |
| 936 // | 951 // |
| 937 // This value represents the meaning of a key, which is either a Unicode | 952 // This value represents the meaning of a key, which is either a Unicode |
| 938 // character, or a named DomKey:: value. | 953 // character, or a named DomKey:: value. |
| 939 // This is not necessarily initialized when the event is constructed; | 954 // This is not necessarily initialized when the event is constructed; |
| 940 // it may be set only if and when GetCharacter() or GetDomKey() is called. | 955 // it may be set only if and when GetCharacter() or GetDomKey() is called. |
| 941 mutable DomKey key_ = DomKey::NONE; | 956 mutable DomKey key_ = DomKey::NONE; |
| 942 | 957 |
| 943 static bool IsRepeated(const KeyEvent& event); | 958 std::unique_ptr<Properties> properties_; |
|
sadrul
2017/03/21 17:21:14
Should this be a base::Optional?
sky
2017/03/21 17:25:37
My understanding is that base::Optional's size is
| |
| 944 | 959 |
| 945 static KeyEvent* last_key_event_; | 960 static KeyEvent* last_key_event_; |
| 946 }; | 961 }; |
| 947 | 962 |
| 948 class EVENTS_EXPORT ScrollEvent : public MouseEvent { | 963 class EVENTS_EXPORT ScrollEvent : public MouseEvent { |
| 949 public: | 964 public: |
| 950 explicit ScrollEvent(const base::NativeEvent& native_event); | 965 explicit ScrollEvent(const base::NativeEvent& native_event); |
| 951 template <class T> | 966 template <class T> |
| 952 ScrollEvent(const ScrollEvent& model, | 967 ScrollEvent(const ScrollEvent& model, |
| 953 T* source, | 968 T* source, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1034 // dispatched. This field gets a non-zero value only for gestures that are | 1049 // dispatched. This field gets a non-zero value only for gestures that are |
| 1035 // released through TouchDispositionGestureFilter::SendGesture. The gesture | 1050 // released through TouchDispositionGestureFilter::SendGesture. The gesture |
| 1036 // events that aren't fired directly in response to processing a touch-event | 1051 // events that aren't fired directly in response to processing a touch-event |
| 1037 // (e.g. timer fired ones), this id is zero. See crbug.com/618738. | 1052 // (e.g. timer fired ones), this id is zero. See crbug.com/618738. |
| 1038 uint32_t unique_touch_event_id_; | 1053 uint32_t unique_touch_event_id_; |
| 1039 }; | 1054 }; |
| 1040 | 1055 |
| 1041 } // namespace ui | 1056 } // namespace ui |
| 1042 | 1057 |
| 1043 #endif // UI_EVENTS_EVENT_H_ | 1058 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |