OLD | NEW |
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 Loading... |
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()) |
| 166 return ui::GetCharacterFromKeyCode(key_code_, flags()); |
| 167 |
| 168 DCHECK(native_event()->type == KeyPress || |
| 169 native_event()->type == KeyRelease); |
| 170 |
| 171 uint16 ch = ui::DefaultSymbolFromXEvent(native_event()); |
| 172 return ch ? ch : ui::GetCharacterFromKeyCode(key_code_, flags()); |
| 173 #else |
| 174 NOTIMPLEMENTED(); |
| 175 return 0; |
| 176 #endif |
| 177 } |
| 178 |
| 179 uint16 KeyEvent::GetUnmodifiedCharacter() const { |
| 180 if (unmodified_character_) |
| 181 return unmodified_character_; |
| 182 |
| 183 #if defined(OS_WIN) |
| 184 // Looks like there is no way to get unmodified character on Windows. |
| 185 return (native_event().message == WM_CHAR) ? key_code_ : |
| 186 ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); |
| 187 #elif defined(USE_X11) |
| 188 if (!native_event()) |
| 189 return ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); |
| 190 |
| 191 DCHECK(native_event()->type == KeyPress || |
| 192 native_event()->type == KeyRelease); |
| 193 |
| 194 XKeyEvent *key = &native_event()->xkey; |
| 195 |
| 196 static const unsigned int kIgnoredModifiers = ControlMask | LockMask | |
| 197 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask; |
| 198 |
| 199 // We can't use things like (key.state & ShiftMask), as it may mask out bits |
| 200 // used by X11 internally. |
| 201 key->state &= ~kIgnoredModifiers; |
| 202 uint16 ch = ui::DefaultSymbolFromXEvent(native_event()); |
| 203 return ch ? ch : |
| 204 ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); |
| 205 #else |
| 206 NOTIMPLEMENTED(); |
| 207 return 0; |
| 208 #endif |
142 } | 209 } |
143 | 210 |
144 } // namespace aura | 211 } // namespace aura |
OLD | NEW |