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

Unified Diff: views/events/event.h

Issue 6713027: Add GetCharacter() and GetUnmodifiedCharacter() methods to views::Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comment. Created 9 years, 9 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 | « no previous file | views/events/event.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/events/event.h
diff --git a/views/events/event.h b/views/events/event.h
index 4173d5382cacc0d3b7dd744cb39121192cb06077..ac52a8a3d3cf5961f912e25db2779ed5e006cc55 100644
--- a/views/events/event.h
+++ b/views/events/event.h
@@ -289,14 +289,44 @@ class KeyEvent : public Event {
// Creates a new KeyEvent synthetically (i.e. not in response to an input
// event from the host environment). This is typically only used in testing as
// some metadata obtainable from the underlying native event is not present.
- // TODO(beng): see if we can kill this.
+ // It's also used by input methods to fabricate keyboard events.
KeyEvent(ui::EventType type,
ui::KeyboardCode key_code,
int event_flags);
ui::KeyboardCode key_code() const { return key_code_; }
+ // Gets the character generated by this key event. It only supports Unicode
+ // BMP characters.
+ uint16 GetCharacter() const;
+
+ // Gets the character generated by this key event ignoring concurrently-held
+ // modifiers (except shift).
+ uint16 GetUnmodifiedCharacter() const;
+
private:
+ // A helper function to get the character generated by a key event 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).
+ static uint16 GetCharacterFromKeyCode(ui::KeyboardCode key_code, int flags);
+
ui::KeyboardCode key_code_;
DISALLOW_COPY_AND_ASSIGN(KeyEvent);
« no previous file with comments | « no previous file | views/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698