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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/events/event.h" 5 #include "views/events/event.h"
6 6
7 #include "views/view.h" 7 #include "views/view.h"
8 #include "views/widget/root_view.h" 8 #include "views/widget/root_view.h"
9 9
10 namespace views { 10 namespace views {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
63 // KeyEvent, public: 63 // KeyEvent, public:
64 64
65 KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code, 65 KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code,
66 int event_flags) 66 int event_flags)
67 : Event(type, event_flags), 67 : Event(type, event_flags),
68 key_code_(key_code) { 68 key_code_(key_code) {
69 } 69 }
70 70
71 //////////////////////////////////////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////////////////
72 // KeyEvent, private:
73
74 // static
75 uint16 KeyEvent::GetCharacterFromKeyCode(ui::KeyboardCode key_code, int flags) {
76 const bool ctrl = (flags & ui::EF_CONTROL_DOWN) != 0;
77 const bool shift = (flags & ui::EF_SHIFT_DOWN) != 0;
78 const bool upper = shift ^ ((flags & ui::EF_CAPS_LOCK_DOWN) != 0);
79
80 // Following Windows behavior to map ctrl-z ~ ctrl-z to \x01 ~ \x1A.
Yusuke Sato 2011/03/18 12:07:41 the first ctrl-z should be ctrl-a?
James Su 2011/03/18 15:54:09 Done.
81 if (key_code >= ui::VKEY_A && key_code <= ui::VKEY_Z)
82 return key_code - ui::VKEY_A + (ctrl ? 1 : (upper ? 'A' : 'a'));
83
84 // Other ctrl characters
85 if (ctrl) {
86 if (shift) {
87 // following graphics chars require shift key to input.
88 switch (key_code) {
89 // ctrl-@ maps to \x00 (Null byte)
90 case ui::VKEY_2:
91 return 0;
92 // ctrl-^ maps to \x1E (Record separator, Information separator two)
93 case ui::VKEY_6:
94 return 0x1E;
95 // ctrl-_ maps to \x1F (Unit separator, Information separator one)
96 case ui::VKEY_OEM_MINUS:
97 return 0x1F;
98 // Returns 0 for all other keys to avoid inputting unexpected chars.
99 default:
100 return 0;
101 }
102 } else {
103 switch (key_code) {
104 // ctrl-[ maps to \x1B (Escape)
105 case ui::VKEY_OEM_4:
106 return 0x1B;
107 // ctrl-\ maps to \x1C (File separator, Information separator four)
108 case ui::VKEY_OEM_5:
109 return 0x1C;
110 // ctrl-] maps to \x1D (Group separator, Information separator three)
111 case ui::VKEY_OEM_6:
112 return 0x1D;
113 // ctrl-Enter maps to \x0A (Line feed)
114 case ui::VKEY_RETURN:
115 return 0x0A;
116 // Returns 0 for all other keys to avoid inputting unexpected chars.
117 default:
118 return 0;
119 }
120 }
121 }
122
123 // Normal characters
124 if (key_code >= ui::VKEY_0 && key_code <= ui::VKEY_9)
125 return shift ? ")!@#$%^&*("[key_code - ui::VKEY_0] : key_code;
Yusuke Sato 2011/03/18 12:07:41 It seems that the US keyboard layout is assumed he
James Su 2011/03/18 15:54:09 Updated the comment in the header file.
126 else if (key_code >= ui::VKEY_NUMPAD0 && key_code <= ui::VKEY_NUMPAD9)
127 return key_code - ui::VKEY_NUMPAD0 + '0';
128
129 switch (key_code) {
130 case ui::VKEY_TAB:
131 return '\t';
132 case ui::VKEY_RETURN:
133 return '\r';
134 case ui::VKEY_MULTIPLY:
135 return '*';
136 case ui::VKEY_ADD:
137 return '+';
138 case ui::VKEY_SUBTRACT:
139 return '-';
140 case ui::VKEY_DECIMAL:
141 return '.';
142 case ui::VKEY_DIVIDE:
143 return '/';
144 case ui::VKEY_SPACE:
145 return ' ';
146 case ui::VKEY_OEM_1:
147 return shift ? ':' : ';';
148 case ui::VKEY_OEM_PLUS:
149 return shift ? '+' : '=';
150 case ui::VKEY_OEM_COMMA:
151 return shift ? '<' : ',';
152 case ui::VKEY_OEM_MINUS:
153 return shift ? '_' : '-';
154 case ui::VKEY_OEM_PERIOD:
155 return shift ? '>' : '.';
156 case ui::VKEY_OEM_2:
157 return shift ? '?' : '/';
158 case ui::VKEY_OEM_3:
159 return shift ? '~' : '`';
160 case ui::VKEY_OEM_4:
161 return shift ? '{' : '[';
162 case ui::VKEY_OEM_5:
163 return shift ? '|' : '\\';
164 case ui::VKEY_OEM_6:
165 return shift ? '}' : ']';
166 case ui::VKEY_OEM_7:
167 return shift ? '"' : '\'';
168 default:
169 return 0;
170 }
171 }
172
173 ////////////////////////////////////////////////////////////////////////////////
72 // MouseEvent, public: 174 // MouseEvent, public:
73 175
74 // TODO(msw): Kill this legacy constructor when we update uses. 176 // TODO(msw): Kill this legacy constructor when we update uses.
75 MouseEvent::MouseEvent(ui::EventType type, 177 MouseEvent::MouseEvent(ui::EventType type,
76 View* source, 178 View* source,
77 View* target, 179 View* target,
78 const gfx::Point &l, 180 const gfx::Point &l,
79 int flags) 181 int flags)
80 : LocatedEvent(MouseEvent(type, l.x(), l.y(), flags), source, target) { 182 : LocatedEvent(MouseEvent(type, l.x(), l.y(), flags), source, target) {
81 } 183 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 #endif 215 #endif
114 216
115 //////////////////////////////////////////////////////////////////////////////// 217 ////////////////////////////////////////////////////////////////////////////////
116 // MouseWheelEvent, public: 218 // MouseWheelEvent, public:
117 219
118 // This value matches windows WHEEL_DELTA. 220 // This value matches windows WHEEL_DELTA.
119 // static 221 // static
120 const int MouseWheelEvent::kWheelDelta = 120; 222 const int MouseWheelEvent::kWheelDelta = 120;
121 223
122 } // namespace views 224 } // namespace views
OLDNEW
« no previous file with comments | « views/events/event.h ('k') | views/events/event_gtk.cc » ('j') | views/events/event_gtk.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698