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

Side by Side Diff: views/events/event.cc

Issue 8511061: Move GetCharacterFromKeyCode from views::KeyEvent to ui/base/keycodes/keyboard_code_conversion.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win_shared builder Created 9 years, 1 month 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/base/keycodes/keyboard_code_conversion.h"
8 #include "views/view.h" 9 #include "views/view.h"
9 #include "views/widget/root_view.h" 10 #include "views/widget/root_view.h"
10 11
11 namespace views { 12 namespace views {
12 13
13 //////////////////////////////////////////////////////////////////////////////// 14 ////////////////////////////////////////////////////////////////////////////////
14 // Event, protected: 15 // Event, protected:
15 16
16 Event::Event(ui::EventType type, int flags) 17 Event::Event(ui::EventType type, int flags)
17 : type_(type), 18 : type_(type),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 : Event(type, event_flags), 90 : Event(type, event_flags),
90 key_code_(key_code), 91 key_code_(key_code),
91 character_(GetCharacterFromKeyCode(key_code, event_flags)), 92 character_(GetCharacterFromKeyCode(key_code, event_flags)),
92 unmodified_character_(0) { 93 unmodified_character_(0) {
93 } 94 }
94 95
95 // KeyEvent, private: --------------------------------------------------------- 96 // KeyEvent, private: ---------------------------------------------------------
96 97
97 // static 98 // static
98 uint16 KeyEvent::GetCharacterFromKeyCode(ui::KeyboardCode key_code, int flags) { 99 uint16 KeyEvent::GetCharacterFromKeyCode(ui::KeyboardCode key_code, int flags) {
99 const bool ctrl = (flags & ui::EF_CONTROL_DOWN) != 0; 100 return ui::GetCharacterFromKeyCode(key_code, flags);
100 const bool shift = (flags & ui::EF_SHIFT_DOWN) != 0;
101 const bool upper = shift ^ ((flags & ui::EF_CAPS_LOCK_DOWN) != 0);
102
103 // Following Windows behavior to map ctrl-a ~ ctrl-z to \x01 ~ \x1A.
104 if (key_code >= ui::VKEY_A && key_code <= ui::VKEY_Z)
105 return key_code - ui::VKEY_A + (ctrl ? 1 : (upper ? 'A' : 'a'));
106
107 // Other ctrl characters
108 if (ctrl) {
109 if (shift) {
110 // following graphics chars require shift key to input.
111 switch (key_code) {
112 // ctrl-@ maps to \x00 (Null byte)
113 case ui::VKEY_2:
114 return 0;
115 // ctrl-^ maps to \x1E (Record separator, Information separator two)
116 case ui::VKEY_6:
117 return 0x1E;
118 // ctrl-_ maps to \x1F (Unit separator, Information separator one)
119 case ui::VKEY_OEM_MINUS:
120 return 0x1F;
121 // Returns 0 for all other keys to avoid inputting unexpected chars.
122 default:
123 return 0;
124 }
125 } else {
126 switch (key_code) {
127 // ctrl-[ maps to \x1B (Escape)
128 case ui::VKEY_OEM_4:
129 return 0x1B;
130 // ctrl-\ maps to \x1C (File separator, Information separator four)
131 case ui::VKEY_OEM_5:
132 return 0x1C;
133 // ctrl-] maps to \x1D (Group separator, Information separator three)
134 case ui::VKEY_OEM_6:
135 return 0x1D;
136 // ctrl-Enter maps to \x0A (Line feed)
137 case ui::VKEY_RETURN:
138 return 0x0A;
139 // Returns 0 for all other keys to avoid inputting unexpected chars.
140 default:
141 return 0;
142 }
143 }
144 }
145
146 // Normal characters
147 if (key_code >= ui::VKEY_0 && key_code <= ui::VKEY_9)
148 return shift ? ")!@#$%^&*("[key_code - ui::VKEY_0] : key_code;
149 else if (key_code >= ui::VKEY_NUMPAD0 && key_code <= ui::VKEY_NUMPAD9)
150 return key_code - ui::VKEY_NUMPAD0 + '0';
151
152 switch (key_code) {
153 case ui::VKEY_TAB:
154 return '\t';
155 case ui::VKEY_RETURN:
156 return '\r';
157 case ui::VKEY_MULTIPLY:
158 return '*';
159 case ui::VKEY_ADD:
160 return '+';
161 case ui::VKEY_SUBTRACT:
162 return '-';
163 case ui::VKEY_DECIMAL:
164 return '.';
165 case ui::VKEY_DIVIDE:
166 return '/';
167 case ui::VKEY_SPACE:
168 return ' ';
169 case ui::VKEY_OEM_1:
170 return shift ? ':' : ';';
171 case ui::VKEY_OEM_PLUS:
172 return shift ? '+' : '=';
173 case ui::VKEY_OEM_COMMA:
174 return shift ? '<' : ',';
175 case ui::VKEY_OEM_MINUS:
176 return shift ? '_' : '-';
177 case ui::VKEY_OEM_PERIOD:
178 return shift ? '>' : '.';
179 case ui::VKEY_OEM_2:
180 return shift ? '?' : '/';
181 case ui::VKEY_OEM_3:
182 return shift ? '~' : '`';
183 case ui::VKEY_OEM_4:
184 return shift ? '{' : '[';
185 case ui::VKEY_OEM_5:
186 return shift ? '|' : '\\';
187 case ui::VKEY_OEM_6:
188 return shift ? '}' : ']';
189 case ui::VKEY_OEM_7:
190 return shift ? '"' : '\'';
191 default:
192 return 0;
193 }
194 } 101 }
195 102
196 //////////////////////////////////////////////////////////////////////////////// 103 ////////////////////////////////////////////////////////////////////////////////
197 // MouseEvent, public: 104 // MouseEvent, public:
198 105
199 MouseEvent::MouseEvent(const NativeEvent& native_event) 106 MouseEvent::MouseEvent(const NativeEvent& native_event)
200 : LocatedEvent(native_event) { 107 : LocatedEvent(native_event) {
201 } 108 }
202 109
203 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target) 110 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 198 }
292 199
293 //////////////////////////////////////////////////////////////////////////////// 200 ////////////////////////////////////////////////////////////////////////////////
294 // MouseWheelEvent, public: 201 // MouseWheelEvent, public:
295 202
296 // This value matches windows WHEEL_DELTA. 203 // This value matches windows WHEEL_DELTA.
297 // static 204 // static
298 const int MouseWheelEvent::kWheelDelta = 120; 205 const int MouseWheelEvent::kWheelDelta = 120;
299 206
300 } // namespace views 207 } // namespace views
OLDNEW
« ui/base/keycodes/keyboard_code_conversion.h ('K') | « views/events/event.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698