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

Unified Diff: ui/events/keycodes/keyboard_code_conversion.h

Issue 1287103004: Sync ui/events to chromium @ https://codereview.chromium.org/1210203002 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 4 months 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/keycodes/dom_us_layout_data.h ('k') | ui/events/keycodes/keyboard_code_conversion.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/keycodes/keyboard_code_conversion.h
diff --git a/ui/events/keycodes/keyboard_code_conversion.h b/ui/events/keycodes/keyboard_code_conversion.h
index b7bdd57157b9c91b177f8d7d46b572a9c5876b83..2747590955a673ca72553df08dd54b49e591f7f9 100644
--- a/ui/events/keycodes/keyboard_code_conversion.h
+++ b/ui/events/keycodes/keyboard_code_conversion.h
@@ -5,34 +5,98 @@
#ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_
#define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_
-#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/strings/string16.h"
#include "ui/events/events_base_export.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace ui {
-// A helper function to get the character generated by a key event in a
+enum class DomCode;
+enum class DomKey;
+
+// Helper functions to get the meaning of a Windows key code in a
// platform independent way. It supports control characters as well.
// It assumes a US keyboard layout is used, so it may only be used when there
// is no native event or no better way to get the character.
+//
// For example, if a virtual keyboard implementation can only generate key
// events with key_code and flags information, then there is no way for us to
// determine the actual character that should be generate by the key. Because
// a key_code only represents a physical key on the keyboard, it has nothing
// to do with the actual character printed on that key. In such case, the only
// thing we can do is to assume that we are using a US keyboard and get the
-// character according to US keyboard layout definition.
-// If a virtual keyboard implementation wants to support other keyboard
-// layouts, that may generate different text for a certain key than on a US
-// keyboard, a special native event object should be introduced to carry extra
-// information to help determine the correct character.
-// Take XKeyEvent as an example, it contains not only keycode and modifier
-// flags but also group and other extra XKB information to help determine the
-// correct character. That's why we can use XLookupString() function to get
-// the correct text generated by a X key event (See how is GetCharacter()
-// implemented in event_x.cc).
-EVENTS_BASE_EXPORT uint16 GetCharacterFromKeyCode(KeyboardCode key_code,
- int flags);
+// character according to US keyboard layout definition. Preferably, such
+// events should be created using a full KeyEvent constructor, explicitly
+// specifying the character and DOM 3 values as well as the legacy VKEY.
+//
+// TODO(kpschoedel): replace remaining uses of the ...FromKeyCode() functions
+// and remove them, to avoid future creation of underspecified key events.
+// crbug.com/444045
+EVENTS_BASE_EXPORT base::char16 GetCharacterFromKeyCode(KeyboardCode key_code,
+ int flags);
+EVENTS_BASE_EXPORT bool GetMeaningFromKeyCode(KeyboardCode key_code,
+ int flags,
+ DomKey* dom_key,
+ base::char16* character);
+
+// Helper function to map a physical key state (dom_code and flags)
+// to a meaning (dom_key and character, together corresponding to the
+// DOM keyboard event |key| value), along with a corresponding Windows-based
+// key_code.
+//
+// This follows a US keyboard layout, so it should only be used when there
+// is no other better way to obtain the meaning (e.g. actual keyboard layout).
+// Returns true and sets the output parameters if the (dom_code, flags) pair
+// has an interpretation in the US English layout; otherwise the output
+// parameters are untouched.
+EVENTS_BASE_EXPORT bool DomCodeToUsLayoutMeaning(DomCode dom_code,
+ int flags,
+ DomKey* dom_key,
+ base::char16* character,
+ KeyboardCode* key_code)
+ WARN_UNUSED_RESULT;
+
+// Obtains the control character corresponding to a physical key;
+// that is, the meaning of the physical key state (dom_code, and flags
+// containing EF_CONTROL_DOWN) under the base US English layout.
+// Returns true and sets the output parameters if the (dom_code, flags) pair
+// is interpreted as a control character; otherwise the output parameters
+// are untouched.
+EVENTS_BASE_EXPORT bool DomCodeToControlCharacter(DomCode dom_code,
+ int flags,
+ DomKey* dom_key,
+ base::char16* character,
+ KeyboardCode* key_code)
+ WARN_UNUSED_RESULT;
+
+// Returns the DomKey value associated with an ASCII/Unicode character.
+// All printable characters and most other character codes use
+// DomKey::CHARACTER, but a few ASCII C0 codes have their own DomKey.
+EVENTS_BASE_EXPORT DomKey CharacterToDomKey(uint32 character);
+
+// Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|.
+// The returned VKEY is non-located (e.g. VKEY_SHIFT).
+EVENTS_BASE_EXPORT KeyboardCode
+NonPrintableDomKeyToKeyboardCode(DomKey dom_key);
+
+// Determine the non-located VKEY corresponding to a located VKEY.
+// Most modifier keys have two kinds of KeyboardCode: located (e.g.
+// VKEY_LSHIFT and VKEY_RSHIFT), that indentify one of two specific
+// physical keys, and non-located (e.g. VKEY_SHIFT) that identify
+// only the operation.
+EVENTS_BASE_EXPORT KeyboardCode
+LocatedToNonLocatedKeyboardCode(KeyboardCode key_code);
+
+// Determine the located VKEY corresponding to a non-located VKEY.
+EVENTS_BASE_EXPORT KeyboardCode
+NonLocatedToLocatedKeyboardCode(KeyboardCode key_code, DomCode dom_code);
+
+// Returns a DOM Level 3 |code| from a Windows-based VKEY value.
+// This assumes a US layout and should only be used when |code| cannot be
+// determined from a physical scan code, for example when a key event was
+// generated synthetically by JavaScript with only a VKEY value supplied.
+EVENTS_BASE_EXPORT DomCode UsLayoutKeyboardCodeToDomCode(KeyboardCode key_code);
} // namespace ui
« no previous file with comments | « ui/events/keycodes/dom_us_layout_data.h ('k') | ui/events/keycodes/keyboard_code_conversion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698