| 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 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
| 9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "ui/base/events.h" | 14 #include "ui/base/events.h" |
| 15 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 15 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 16 #include "ui/base/touch/touch_factory.h" | 16 #include "ui/base/touch/touch_factory.h" |
| 17 #include "views/widget/root_view.h" | 17 #include "views/widget/root_view.h" |
| 18 | 18 |
| 19 namespace views { | 19 namespace views { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { | |
| 24 char buf[6]; | |
| 25 int bytes_written = XLookupString(key, buf, 6, NULL, NULL); | |
| 26 DCHECK_LE(bytes_written, 6); | |
| 27 | |
| 28 string16 result; | |
| 29 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && | |
| 30 result.length() == 1) ? result[0] : 0; | |
| 31 } | |
| 32 | |
| 33 // The following two functions are copied from event_gtk.cc. These will be | 23 // The following two functions are copied from event_gtk.cc. These will be |
| 34 // removed when GTK dependency is removed. | 24 // removed when GTK dependency is removed. |
| 35 #if defined(TOOLKIT_USES_GTK) | 25 #if defined(TOOLKIT_USES_GTK) |
| 36 uint16 GetCharacterFromGdkKeyval(guint keyval) { | 26 uint16 GetCharacterFromGdkKeyval(guint keyval) { |
| 37 guint32 ch = gdk_keyval_to_unicode(keyval); | 27 guint32 ch = gdk_keyval_to_unicode(keyval); |
| 38 | 28 |
| 39 // We only support BMP characters. | 29 // We only support BMP characters. |
| 40 return ch < 0xFFFE ? static_cast<uint16>(ch) : 0; | 30 return ch < 0xFFFE ? static_cast<uint16>(ch) : 0; |
| 41 } | 31 } |
| 42 | 32 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 65 if (ch) | 55 if (ch) |
| 66 return ch; | 56 return ch; |
| 67 } | 57 } |
| 68 #endif | 58 #endif |
| 69 return GetCharacterFromKeyCode(key_code_, flags()); | 59 return GetCharacterFromKeyCode(key_code_, flags()); |
| 70 } | 60 } |
| 71 | 61 |
| 72 DCHECK(native_event()->type == KeyPress || | 62 DCHECK(native_event()->type == KeyPress || |
| 73 native_event()->type == KeyRelease); | 63 native_event()->type == KeyRelease); |
| 74 | 64 |
| 75 uint16 ch = GetCharacterFromXKeyEvent(&native_event()->xkey); | 65 uint16 ch = ui::DefaultSymbolFromXEvent(native_event()); |
| 76 return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); | 66 return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); |
| 77 } | 67 } |
| 78 | 68 |
| 79 uint16 KeyEvent::GetUnmodifiedCharacter() const { | 69 uint16 KeyEvent::GetUnmodifiedCharacter() const { |
| 80 if (unmodified_character_) | 70 if (unmodified_character_) |
| 81 return unmodified_character_; | 71 return unmodified_character_; |
| 82 | 72 |
| 83 if (!native_event()) { | 73 if (!native_event()) { |
| 84 #if defined(TOOLKIT_USES_GTK) | 74 #if defined(TOOLKIT_USES_GTK) |
| 85 // This event may have been created from a Gdk event. | 75 // This event may have been created from a Gdk event. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 103 return ch; | 93 return ch; |
| 104 } | 94 } |
| 105 } | 95 } |
| 106 #endif | 96 #endif |
| 107 return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | 97 return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); |
| 108 } | 98 } |
| 109 | 99 |
| 110 DCHECK(native_event()->type == KeyPress || | 100 DCHECK(native_event()->type == KeyPress || |
| 111 native_event()->type == KeyRelease); | 101 native_event()->type == KeyRelease); |
| 112 | 102 |
| 113 XKeyEvent key = native_event()->xkey; | 103 XKeyEvent *key = &native_event()->xkey; |
| 114 | 104 |
| 115 static const unsigned int kIgnoredModifiers = ControlMask | LockMask | | 105 static const unsigned int kIgnoredModifiers = ControlMask | LockMask | |
| 116 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask; | 106 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask; |
| 117 | 107 |
| 118 // We can't use things like (key.state & ShiftMask), as it may mask out bits | 108 // We can't use things like (key.state & ShiftMask), as it may mask out bits |
| 119 // used by X11 internally. | 109 // used by X11 internally. |
| 120 key.state &= ~kIgnoredModifiers; | 110 key->state &= ~kIgnoredModifiers; |
| 121 uint16 ch = GetCharacterFromXKeyEvent(&key); | 111 uint16 ch = ui::DefaultSymbolFromXEvent(native_event()); |
| 122 return ch ? ch : | 112 return ch ? ch : |
| 123 GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | 113 GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); |
| 124 } | 114 } |
| 125 | 115 |
| 126 //////////////////////////////////////////////////////////////////////////////// | 116 //////////////////////////////////////////////////////////////////////////////// |
| 127 // TouchEvent, public: | 117 // TouchEvent, public: |
| 128 | 118 |
| 129 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 119 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
| 130 : LocatedEvent(native_event), | 120 : LocatedEvent(native_event), |
| 131 touch_id_(ui::GetTouchId(native_event)), | 121 touch_id_(ui::GetTouchId(native_event)), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 152 float slot; | 142 float slot; |
| 153 if (factory->ExtractTouchParam(*native_event, | 143 if (factory->ExtractTouchParam(*native_event, |
| 154 ui::TouchFactory::TP_SLOT_ID, &slot)) { | 144 ui::TouchFactory::TP_SLOT_ID, &slot)) { |
| 155 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); | 145 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); |
| 156 } | 146 } |
| 157 } | 147 } |
| 158 #endif | 148 #endif |
| 159 } | 149 } |
| 160 | 150 |
| 161 } // namespace views | 151 } // namespace views |
| OLD | NEW |