| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/events/event.h" | 5 #include "ui/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.h" | 15 #include "ui/base/keycodes/keyboard_code_conversion.h" |
| 16 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 16 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 17 #include "ui/base/touch/touch_factory.h" | 17 #include "ui/base/touch/touch_factory.h" |
| 18 #include "ui/views/widget/root_view.h" | 18 #include "ui/views/widget/root_view.h" |
| 19 | 19 |
| 20 namespace views { | 20 namespace views { |
| 21 | 21 |
| 22 //////////////////////////////////////////////////////////////////////////////// | 22 //////////////////////////////////////////////////////////////////////////////// |
| 23 // KeyEvent, public: | |
| 24 | |
| 25 uint16 KeyEvent::GetCharacter() const { | |
| 26 if (character_) | |
| 27 return character_; | |
| 28 | |
| 29 if (!native_event()) { | |
| 30 return ui::GetCharacterFromKeyCode(key_code_, flags()); | |
| 31 } | |
| 32 | |
| 33 DCHECK(native_event()->type == KeyPress || | |
| 34 native_event()->type == KeyRelease); | |
| 35 | |
| 36 uint16 ch = 0; | |
| 37 if (!IsControlDown()) | |
| 38 ch = ui::GetCharacterFromXEvent(native_event()); | |
| 39 return ch ? ch : ui::GetCharacterFromKeyCode(key_code_, flags()); | |
| 40 } | |
| 41 | |
| 42 uint16 KeyEvent::GetUnmodifiedCharacter() const { | |
| 43 if (unmodified_character_) | |
| 44 return unmodified_character_; | |
| 45 | |
| 46 if (!native_event()) { | |
| 47 return ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | |
| 48 } | |
| 49 | |
| 50 DCHECK(native_event()->type == KeyPress || | |
| 51 native_event()->type == KeyRelease); | |
| 52 | |
| 53 static const unsigned int kIgnoredModifiers = ControlMask | LockMask | | |
| 54 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask; | |
| 55 | |
| 56 XKeyEvent copy = native_event()->xkey; // bit-wise copy is safe. | |
| 57 // We can't use things like (native_event()->xkey.state & ShiftMask), as it | |
| 58 // may mask out bits used by X11 internally. | |
| 59 copy.state &= ~kIgnoredModifiers; | |
| 60 uint16 ch = ui::GetCharacterFromXEvent(reinterpret_cast<XEvent*>(©)); | |
| 61 return ch ? ch : | |
| 62 ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | |
| 63 } | |
| 64 | |
| 65 //////////////////////////////////////////////////////////////////////////////// | |
| 66 // TouchEvent, public: | 23 // TouchEvent, public: |
| 67 | 24 |
| 68 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 25 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
| 69 : LocatedEvent(native_event), | 26 : LocatedEvent(native_event), |
| 70 touch_id_(ui::GetTouchId(native_event)), | 27 touch_id_(ui::GetTouchId(native_event)), |
| 71 radius_x_(ui::GetTouchRadiusX(native_event)), | 28 radius_x_(ui::GetTouchRadiusX(native_event)), |
| 72 radius_y_(ui::GetTouchRadiusY(native_event)), | 29 radius_y_(ui::GetTouchRadiusY(native_event)), |
| 73 rotation_angle_(ui::GetTouchAngle(native_event)), | 30 rotation_angle_(ui::GetTouchAngle(native_event)), |
| 74 force_(ui::GetTouchForce(native_event)) { | 31 force_(ui::GetTouchForce(native_event)) { |
| 75 #if defined(USE_XI2_MT) | 32 #if defined(USE_XI2_MT) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 91 float slot; | 48 float slot; |
| 92 if (factory->ExtractTouchParam(*native_event, | 49 if (factory->ExtractTouchParam(*native_event, |
| 93 ui::TouchFactory::TP_SLOT_ID, &slot)) { | 50 ui::TouchFactory::TP_SLOT_ID, &slot)) { |
| 94 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); | 51 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); |
| 95 } | 52 } |
| 96 } | 53 } |
| 97 #endif | 54 #endif |
| 98 } | 55 } |
| 99 | 56 |
| 100 } // namespace views | 57 } // namespace views |
| OLD | NEW |