Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2728)

Unified Diff: ui/events/event.h

Issue 742103002: Ozone keyboard layout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lite-code
Patch Set: reeeeebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/BUILD.gn ('k') | ui/events/event.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/event.h
diff --git a/ui/events/event.h b/ui/events/event.h
index 57871944c0655c5e6e49c0fed482e13b979c89d1..13fc9edce830637c71210623641b7f496f5db092 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:
@@ -585,25 +586,38 @@ 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().
-// -- key_code_ is a VKEY_ value associated with the key. For printable
-// characters, this may or may not be a mapped value, imitating MS Windows:
+// -- 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, in the context
+// of the active layout and modifiers. Together they 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 KeyboardCode value associated with the key. This supports
+// the legacy web event |keyCode| field, and the VKEY_ values are chosen
+// to match Windows/IE for compatibility. For printable characters, this
+// may or may not be a layout-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.
// -- 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:
@@ -615,6 +629,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);
@@ -698,6 +720,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();
@@ -718,6 +743,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).
@@ -734,6 +762,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.
//
« no previous file with comments | « ui/events/BUILD.gn ('k') | ui/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698