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 "views/events/event.h" | 5 #include "views/events/event.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" | 10 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 case GDK_ENTER_NOTIFY: | 70 case GDK_ENTER_NOTIFY: |
71 case GDK_LEAVE_NOTIFY: | 71 case GDK_LEAVE_NOTIFY: |
72 return native_event->crossing.state; | 72 return native_event->crossing.state; |
73 default: | 73 default: |
74 NOTREACHED(); | 74 NOTREACHED(); |
75 break; | 75 break; |
76 } | 76 } |
77 return 0; | 77 return 0; |
78 } | 78 } |
79 | 79 |
80 #if !defined(TOUCH_UI) | |
81 uint16 GetCharacterFromGdkKeyval(guint keyval) { | |
82 guint32 ch = gdk_keyval_to_unicode(keyval); | |
83 | |
84 // We only support BMP characters. | |
85 return ch < 0xFFFE ? static_cast<uint16>(ch) : 0; | |
86 } | |
87 #endif | |
88 | |
80 } // namespace | 89 } // namespace |
81 | 90 |
82 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
83 // Event, public: | 92 // Event, public: |
84 | 93 |
85 // static | 94 // static |
86 int Event::GetFlagsFromGdkState(unsigned int state) { | 95 int Event::GetFlagsFromGdkState(unsigned int state) { |
87 int flags = 0; | 96 int flags = 0; |
88 if (state & GDK_LOCK_MASK) | 97 if (state & GDK_LOCK_MASK) |
89 flags |= ui::EF_CAPS_LOCK_DOWN; | 98 flags |= ui::EF_CAPS_LOCK_DOWN; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 GetGdkEventKeyFromNative(native_event))) { | 181 GetGdkEventKeyFromNative(native_event))) { |
173 } | 182 } |
174 | 183 |
175 #if !defined(TOUCH_UI) | 184 #if !defined(TOUCH_UI) |
176 KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native) | 185 KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native) |
177 : Event(native_event_2, ui::ET_UNKNOWN, 0, from_native) { | 186 : Event(native_event_2, ui::ET_UNKNOWN, 0, from_native) { |
178 // No one should ever call this on Gtk-views. | 187 // No one should ever call this on Gtk-views. |
179 // TODO(beng): remove once we rid views of Gtk/Gdk. | 188 // TODO(beng): remove once we rid views of Gtk/Gdk. |
180 NOTREACHED(); | 189 NOTREACHED(); |
181 } | 190 } |
191 | |
192 uint16 KeyEvent::GetCharacter() const { | |
193 // Gtk doesn't support control characters. | |
194 if (IsControlDown() || !native_event()) | |
195 return GetCharacterFromKeyCode(key_code_, flags()); | |
196 | |
197 uint16 ch = GetCharacterFromGdkKeyval( | |
198 GetGdkEventKeyFromNative(native_event())->keyval); | |
199 return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); | |
200 } | |
201 | |
202 uint16 KeyEvent::GetUnmodifiedCharacter() const { | |
203 static const guint kIgnoredModifiers = | |
Evan Stade
2011/03/18 21:13:07
declare this right above where it's used (and near
James Su
2011/03/18 21:22:14
Done.
| |
204 GDK_CONTROL_MASK | GDK_LOCK_MASK | GDK_MOD1_MASK | GDK_MOD2_MASK | | |
205 GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK | GDK_SUPER_MASK | | |
206 GDK_HYPER_MASK | GDK_META_MASK; | |
207 | |
208 if (!native_event()) | |
209 return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | |
210 | |
211 GdkEventKey* key = GetGdkEventKeyFromNative(native_event()); | |
212 | |
213 // We can't use things like (key->state & GDK_SHIFT_MASK), as it may mask out | |
214 // bits used by X11 or Gtk internally. | |
215 GdkModifierType modifiers = | |
216 static_cast<GdkModifierType>(key->state & ~kIgnoredModifiers); | |
217 guint keyval = 0; | |
218 uint16 ch = 0; | |
219 if (gdk_keymap_translate_keyboard_state( | |
220 NULL, key->hardware_keycode, modifiers, key->group, &keyval, | |
221 NULL, NULL, NULL)) | |
Evan Stade
2011/03/18 21:13:07
curlies
James Su
2011/03/18 21:22:14
Done.
| |
222 ch = GetCharacterFromGdkKeyval(keyval); | |
223 | |
224 return ch ? ch : | |
225 GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | |
226 } | |
182 #endif | 227 #endif |
183 | 228 |
184 //////////////////////////////////////////////////////////////////////////////// | 229 //////////////////////////////////////////////////////////////////////////////// |
185 // MouseWheelEvent, public: | 230 // MouseWheelEvent, public: |
186 | 231 |
187 MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) | 232 MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) |
188 : MouseEvent(native_event), | 233 : MouseEvent(native_event), |
189 offset_(GetMouseWheelOffset(native_event)) { | 234 offset_(GetMouseWheelOffset(native_event)) { |
190 } | 235 } |
191 | 236 |
192 #if !defined(TOUCH_UI) | 237 #if !defined(TOUCH_UI) |
193 MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, | 238 MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, |
194 FromNativeEvent2 from_native) | 239 FromNativeEvent2 from_native) |
195 : MouseEvent(native_event_2, from_native) { | 240 : MouseEvent(native_event_2, from_native) { |
196 // No one should ever call this on Gtk-views. | 241 // No one should ever call this on Gtk-views. |
197 // TODO(msw): remove once we rid views of Gtk/Gdk. | 242 // TODO(msw): remove once we rid views of Gtk/Gdk. |
198 NOTREACHED(); | 243 NOTREACHED(); |
199 } | 244 } |
200 #endif | 245 #endif |
201 | 246 |
202 } // namespace views | 247 } // namespace views |
OLD | NEW |