Chromium Code Reviews| Index: ui/events/event.h |
| diff --git a/ui/events/event.h b/ui/events/event.h |
| index 427a731c0a203a44500cdbf1eadb34c60be0feb3..7a4638862a72cf5a9923d66c6c438af32da48b99 100644 |
| --- a/ui/events/event.h |
| +++ b/ui/events/event.h |
| @@ -27,6 +27,7 @@ class Transform; |
| namespace ui { |
| class EventTarget; |
| enum class DomCode; |
| +enum class DomKey; |
| class EVENTS_EXPORT Event { |
| public: |
| @@ -573,25 +574,35 @@ class EVENTS_EXPORT ExtendedKeyEventData { |
| // |
| // For a keystroke event, |
| // -- is_char_ is false. |
| -// -- type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED, |
| +// -- Event::type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED, |
| // ET_TRANSLATED_KEY_PRESS, or ET_TRANSLATED_KEY_RELEASE. |
| -// -- character_ functions as a bypass or cache for GetCharacter(). |
| +// -- code_ and Event::flags() represent the physical key event. |
| +// - code_ is a platform-independent representation of the physical key, |
| +// based on DOM KeyboardEvent |code| values. It does not vary depending |
| +// on key layout. |
| +// - Event::flags() provides the active modifiers for the physical key |
| +// press. Its value reflects the state after the event; that is, for |
| +// a modifier key, a press includes the corresponding flag and a release |
| +// does not. |
| +// -- key_ and character_ provide the meaning of the key event. Together they |
|
Wez
2014/12/12 20:04:18
nit: suggest "in the context of the active layout
kpschoedel
2014/12/12 21:20:39
Done.
|
| +// correspond to DOM KeyboardEvent |key| values. |
| +// - key_ is an enumeration of non-Unicode meanings, plus sentinels |
| +// (specifically DomKey::CHARACTER for Unicode meanings). |
| +// - character_ is the code point for Unicode meanings. |
| // -- key_code_ is a VKEY_ value associated with the key. For printable |
|
Wez
2014/12/12 20:04:18
nit: Worth mentioning that this supports the legac
|
| // characters, this may or may not be a mapped value, imitating MS Windows: |
| // if the mapped key generates a character that has an associated VKEY_ |
| // code, then key_code_ is that code; if not, then key_code_ is the unmapped |
| // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use |
| // VKEY_Q for the key beside Tab, while French uses VKEY_A. |
| -// -- code_ is in one-to-one correspondence with a physical keyboard |
| -// location, and does not vary depending on key layout. |
| // |
| // For a character event, |
| // -- is_char_ is true. |
| // -- type() is ET_KEY_PRESSED. |
| -// -- character_ is a UTF-16 character value. |
| +// -- code_ is DomCode::NONE. |
| +// -- key_ is DomKey::CHARACTER and character_ is a UTF-16 code point. |
|
Wez
2014/12/12 20:04:18
Setting |key_| for character events feels wrong, e
kpschoedel
2014/12/12 21:20:39
The reason for doing so here is that some event-co
|
| // -- key_code_ is conflated with character_ by some code, because both |
| // arrive in the wParam field of a Windows event. |
| -// -- code_ is DomCode::NONE. |
| // |
| class EVENTS_EXPORT KeyEvent : public Event { |
| public: |
| @@ -603,6 +614,14 @@ class EVENTS_EXPORT KeyEvent : public Event { |
| // Create a keystroke event. |
| KeyEvent(EventType type, KeyboardCode key_code, int flags); |
| + // Create a fully defined keystroke event. |
| + KeyEvent(EventType type, |
| + KeyboardCode key_code, |
| + DomCode code, |
| + int flags, |
| + DomKey key, |
| + base::char16 character); |
| + |
| // Create a character event. |
| KeyEvent(base::char16 character, KeyboardCode key_code, int flags); |
| @@ -686,6 +705,9 @@ class EVENTS_EXPORT KeyEvent : public Event { |
| DomCode code() const { return code_; }; |
| std::string GetCodeString() const; |
| + // Returns the DOM .key (layout meaning) for a keystroke event. |
| + DomKey GetDomKey() const; |
| + |
| // Normalizes flags_ so that it describes the state after the event. |
| // (Native X11 event flags describe the state before the event.) |
| void NormalizeFlags(); |
| @@ -706,6 +728,9 @@ class EVENTS_EXPORT KeyEvent : public Event { |
| // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.). |
| bool IsRightSideKey() const; |
| + // Determine key_ and character_ on a keystroke event from code_ and flags(). |
| + void ApplyLayout() const; |
| + |
| KeyboardCode key_code_; |
| // DOM KeyboardEvent |code| (e.g. DomCode::KEY_A, DomCode::SPACE). |
| @@ -722,6 +747,21 @@ class EVENTS_EXPORT KeyEvent : public Event { |
| // For now, this is used for CharacterComposer in ChromeOS. |
| uint32 platform_keycode_; |
| + // TODO(kpschoedel): refactor so that key_ and character_ are not mutable. |
| + // This requires defining the KeyEvent completely at construction rather |
| + // than lazily under GetCharacter(), which likely also means removing |
| + // the two 'incomplete' constructors. |
| + // |
| + // DOM KeyboardEvent |key| |
| + // http://www.w3.org/TR/DOM-Level-3-Events-key/ |
| + // |
| + // This value, together with character_, represents the meaning of a key. |
| + // The value is DomKey::CHARACTER when the interpretation is a character. |
| + // This, along with character_, is not necessarily initialized when the |
| + // event is constructed; it may be set only if and when GetCharacter() |
| + // or GetDomKey() is called. |
| + mutable DomKey key_; |
| + |
| // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'รข') |
| // http://www.w3.org/TR/uievents/#keyboard-key-codes. |
| // |