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

Side by Side Diff: ui/aura/event.cc

Issue 8567021: Port views::KeyEvent functions to aura::KeyEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review 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
« no previous file with comments | « ui/aura/event.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/aura/event.h" 5 #include "ui/aura/event.h"
6 6
7 #if defined(USE_X11)
8 #include <X11/Xlib.h>
9 #endif
10
7 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/base/keycodes/keyboard_code_conversion.h"
8 #include "ui/gfx/point3.h" 13 #include "ui/gfx/point3.h"
9 #include "ui/gfx/transform.h" 14 #include "ui/gfx/transform.h"
10 15
16 #if defined(USE_X11)
17 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
18 #endif
19
11 namespace aura { 20 namespace aura {
12 21
13 Event::Event(ui::EventType type, int flags) 22 Event::Event(ui::EventType type, int flags)
14 : type_(type), 23 : type_(type),
15 time_stamp_(base::Time::NowFromSystemTime()), 24 time_stamp_(base::Time::NowFromSystemTime()),
16 flags_(flags) { 25 flags_(flags) {
17 Init(); 26 Init();
18 } 27 }
19 28
20 Event::Event(const base::NativeEvent& native_event, 29 Event::Event(const base::NativeEvent& native_event,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 radius_y_(1.0f), 132 radius_y_(1.0f),
124 rotation_angle_(0.0f), 133 rotation_angle_(0.0f),
125 force_(0.0f) { 134 force_(0.0f) {
126 } 135 }
127 136
128 KeyEvent::KeyEvent(const base::NativeEvent& native_event, bool is_char) 137 KeyEvent::KeyEvent(const base::NativeEvent& native_event, bool is_char)
129 : Event(native_event, 138 : Event(native_event,
130 ui::EventTypeFromNative(native_event), 139 ui::EventTypeFromNative(native_event),
131 ui::EventFlagsFromNative(native_event)), 140 ui::EventFlagsFromNative(native_event)),
132 key_code_(ui::KeyboardCodeFromNative(native_event)), 141 key_code_(ui::KeyboardCodeFromNative(native_event)),
133 is_char_(is_char) { 142 is_char_(is_char),
143 character_(0),
144 unmodified_character_(0) {
134 } 145 }
135 146
136 KeyEvent::KeyEvent(ui::EventType type, 147 KeyEvent::KeyEvent(ui::EventType type,
137 ui::KeyboardCode key_code, 148 ui::KeyboardCode key_code,
138 int flags) 149 int flags)
139 : Event(type, flags), 150 : Event(type, flags),
140 key_code_(key_code), 151 key_code_(key_code),
141 is_char_(false) { 152 is_char_(false),
153 character_(ui::GetCharacterFromKeyCode(key_code, flags)),
154 unmodified_character_(0) {
155 }
156
157 uint16 KeyEvent::GetCharacter() const {
158 if (character_)
159 return character_;
160
161 #if defined(OS_WIN)
162 return (native_event().message == WM_CHAR) ? key_code_ :
163 ui::GetCharacterFromKeyCode(key_code_, flags());
164 #elif defined(USE_X11)
165 if (!native_event()) {
James Su 2011/11/15 11:51:10 nit: no { } for single line if statement.
Yusuke Sato 2011/11/15 12:20:59 Done.
166 return ui::GetCharacterFromKeyCode(key_code_, flags());
167 }
168
169 DCHECK(native_event()->type == KeyPress ||
170 native_event()->type == KeyRelease);
171
172 uint16 ch = ui::DefaultSymbolFromXEvent(native_event());
173 return ch ? ch : ui::GetCharacterFromKeyCode(key_code_, flags());
174 #else
175 NOTIMPLEMENTED();
176 return 0;
177 #endif
178 }
179
180 uint16 KeyEvent::GetUnmodifiedCharacter() const {
181 if (unmodified_character_)
182 return unmodified_character_;
183
184 #if defined(OS_WIN)
185 // Looks like there is no way to get unmodified character on Windows.
186 return (native_event().message == WM_CHAR) ? key_code_ :
187 ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN);
188 #elif defined(USE_X11)
189 if (!native_event()) {
190 return ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN);
James Su 2011/11/15 11:51:10 ditto.
Yusuke Sato 2011/11/15 12:20:59 Done.
191 }
192
193 DCHECK(native_event()->type == KeyPress ||
194 native_event()->type == KeyRelease);
195
196 XKeyEvent *key = &native_event()->xkey;
197
198 static const unsigned int kIgnoredModifiers = ControlMask | LockMask |
199 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask;
200
201 // We can't use things like (key.state & ShiftMask), as it may mask out bits
202 // used by X11 internally.
203 key->state &= ~kIgnoredModifiers;
204 uint16 ch = ui::DefaultSymbolFromXEvent(native_event());
205 return ch ? ch :
206 ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN);
207 #else
208 NOTIMPLEMENTED();
209 return 0;
210 #endif
142 } 211 }
143 212
144 } // namespace aura 213 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/event.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698