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

Unified Diff: views/events/event.cc

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 | « views/events/event.h ('k') | views/events/event_gtk.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/events/event.cc
diff --git a/views/events/event.cc b/views/events/event.cc
index de8a1ba92b2f9867dd86289ff284a7fff1da4c47..dfab22162bdf1569e74c53b4316c142c13388d8f 100644
--- a/views/events/event.cc
+++ b/views/events/event.cc
@@ -68,6 +68,107 @@ KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code,
key_code_(key_code) {
}
+// KeyEvent, private: ---------------------------------------------------------
+
+// static
+uint16 KeyEvent::GetCharacterFromKeyCode(ui::KeyboardCode key_code, int flags) {
+ const bool ctrl = (flags & ui::EF_CONTROL_DOWN) != 0;
+ const bool shift = (flags & ui::EF_SHIFT_DOWN) != 0;
+ const bool upper = shift ^ ((flags & ui::EF_CAPS_LOCK_DOWN) != 0);
+
+ // Following Windows behavior to map ctrl-a ~ ctrl-z to \x01 ~ \x1A.
+ if (key_code >= ui::VKEY_A && key_code <= ui::VKEY_Z)
+ return key_code - ui::VKEY_A + (ctrl ? 1 : (upper ? 'A' : 'a'));
+
+ // Other ctrl characters
+ if (ctrl) {
+ if (shift) {
+ // following graphics chars require shift key to input.
+ switch (key_code) {
+ // ctrl-@ maps to \x00 (Null byte)
+ case ui::VKEY_2:
+ return 0;
+ // ctrl-^ maps to \x1E (Record separator, Information separator two)
+ case ui::VKEY_6:
+ return 0x1E;
+ // ctrl-_ maps to \x1F (Unit separator, Information separator one)
+ case ui::VKEY_OEM_MINUS:
+ return 0x1F;
+ // Returns 0 for all other keys to avoid inputting unexpected chars.
+ default:
+ return 0;
+ }
+ } else {
+ switch (key_code) {
+ // ctrl-[ maps to \x1B (Escape)
+ case ui::VKEY_OEM_4:
+ return 0x1B;
+ // ctrl-\ maps to \x1C (File separator, Information separator four)
+ case ui::VKEY_OEM_5:
+ return 0x1C;
+ // ctrl-] maps to \x1D (Group separator, Information separator three)
+ case ui::VKEY_OEM_6:
+ return 0x1D;
+ // ctrl-Enter maps to \x0A (Line feed)
+ case ui::VKEY_RETURN:
+ return 0x0A;
+ // Returns 0 for all other keys to avoid inputting unexpected chars.
+ default:
+ return 0;
+ }
+ }
+ }
+
+ // Normal characters
+ if (key_code >= ui::VKEY_0 && key_code <= ui::VKEY_9)
+ return shift ? ")!@#$%^&*("[key_code - ui::VKEY_0] : key_code;
+ else if (key_code >= ui::VKEY_NUMPAD0 && key_code <= ui::VKEY_NUMPAD9)
+ return key_code - ui::VKEY_NUMPAD0 + '0';
+
+ switch (key_code) {
+ case ui::VKEY_TAB:
+ return '\t';
+ case ui::VKEY_RETURN:
+ return '\r';
+ case ui::VKEY_MULTIPLY:
+ return '*';
+ case ui::VKEY_ADD:
+ return '+';
+ case ui::VKEY_SUBTRACT:
+ return '-';
+ case ui::VKEY_DECIMAL:
+ return '.';
+ case ui::VKEY_DIVIDE:
+ return '/';
+ case ui::VKEY_SPACE:
+ return ' ';
+ case ui::VKEY_OEM_1:
+ return shift ? ':' : ';';
+ case ui::VKEY_OEM_PLUS:
+ return shift ? '+' : '=';
+ case ui::VKEY_OEM_COMMA:
+ return shift ? '<' : ',';
+ case ui::VKEY_OEM_MINUS:
+ return shift ? '_' : '-';
+ case ui::VKEY_OEM_PERIOD:
+ return shift ? '>' : '.';
+ case ui::VKEY_OEM_2:
+ return shift ? '?' : '/';
+ case ui::VKEY_OEM_3:
+ return shift ? '~' : '`';
+ case ui::VKEY_OEM_4:
+ return shift ? '{' : '[';
+ case ui::VKEY_OEM_5:
+ return shift ? '|' : '\\';
+ case ui::VKEY_OEM_6:
+ return shift ? '}' : ']';
+ case ui::VKEY_OEM_7:
+ return shift ? '"' : '\'';
+ default:
+ return 0;
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
// MouseEvent, public:
« no previous file with comments | « views/events/event.h ('k') | views/events/event_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698