| 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/keycodes/keyboard_code_conversion_x.h" | 14 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 15 #include "views/touchui/touch_factory.h" | 15 #include "ui/base/touchui/touch_factory.h" |
| 16 #include "views/widget/root_view.h" | 16 #include "views/widget/root_view.h" |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. | |
| 23 static int kWheelScrollAmount = 53; | |
| 24 | |
| 25 int GetEventFlagsFromXState(unsigned int state) { | |
| 26 int flags = 0; | |
| 27 if (state & ControlMask) | |
| 28 flags |= ui::EF_CONTROL_DOWN; | |
| 29 if (state & ShiftMask) | |
| 30 flags |= ui::EF_SHIFT_DOWN; | |
| 31 if (state & Mod1Mask) | |
| 32 flags |= ui::EF_ALT_DOWN; | |
| 33 if (state & LockMask) | |
| 34 flags |= ui::EF_CAPS_LOCK_DOWN; | |
| 35 if (state & Button1Mask) | |
| 36 flags |= ui::EF_LEFT_BUTTON_DOWN; | |
| 37 if (state & Button2Mask) | |
| 38 flags |= ui::EF_MIDDLE_BUTTON_DOWN; | |
| 39 if (state & Button3Mask) | |
| 40 flags |= ui::EF_RIGHT_BUTTON_DOWN; | |
| 41 | |
| 42 return flags; | |
| 43 } | |
| 44 | |
| 45 // Get the event flag for the button in XButtonEvent. During a ButtonPress | |
| 46 // event, |state| in XButtonEvent does not include the button that has just been | |
| 47 // pressed. Instead |state| contains flags for the buttons (if any) that had | |
| 48 // already been pressed before the current button, and |button| stores the most | |
| 49 // current pressed button. So, if you press down left mouse button, and while | |
| 50 // pressing it down, press down the right mouse button, then for the latter | |
| 51 // event, |state| would have Button1Mask set but not Button3Mask, and |button| | |
| 52 // would be 3. | |
| 53 int GetEventFlagsForButton(int button) { | |
| 54 switch (button) { | |
| 55 case 1: | |
| 56 return ui::EF_LEFT_BUTTON_DOWN; | |
| 57 case 2: | |
| 58 return ui::EF_MIDDLE_BUTTON_DOWN; | |
| 59 case 3: | |
| 60 return ui::EF_RIGHT_BUTTON_DOWN; | |
| 61 } | |
| 62 | |
| 63 DLOG(WARNING) << "Unexpected button (" << button << ") received."; | |
| 64 return 0; | |
| 65 } | |
| 66 | |
| 67 int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { | |
| 68 int buttonflags = 0; | |
| 69 | |
| 70 for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { | |
| 71 if (XIMaskIsSet(xievent->buttons.mask, i)) { | |
| 72 buttonflags |= GetEventFlagsForButton(i); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 return buttonflags; | |
| 77 } | |
| 78 | |
| 79 ui::EventType GetTouchEventType(XEvent* xev) { | |
| 80 XGenericEventCookie* cookie = &xev->xcookie; | |
| 81 DCHECK_EQ(cookie->evtype, XI_Motion); | |
| 82 | |
| 83 // Note: We will not generate a _STATIONARY event here. It will be created, | |
| 84 // when necessary, by a RWHVV. | |
| 85 // TODO(sad): When should _CANCELLED be generated? | |
| 86 | |
| 87 TouchFactory* factory = TouchFactory::GetInstance(); | |
| 88 float slot; | |
| 89 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_SLOT_ID, &slot)) | |
| 90 return ui::ET_UNKNOWN; | |
| 91 | |
| 92 if (!factory->IsSlotUsed(slot)) { | |
| 93 // This is a new touch point. | |
| 94 return ui::ET_TOUCH_PRESSED; | |
| 95 } | |
| 96 | |
| 97 float tracking; | |
| 98 if (!factory->ExtractTouchParam(*xev, TouchFactory::TP_TRACKING_ID, | |
| 99 &tracking)) | |
| 100 return ui::ET_UNKNOWN; | |
| 101 | |
| 102 if (tracking == 0l) { | |
| 103 // The touch point has been released. | |
| 104 return ui::ET_TOUCH_RELEASED; | |
| 105 } | |
| 106 | |
| 107 return ui::ET_TOUCH_MOVED; | |
| 108 } | |
| 109 | |
| 110 int GetTouchIDFromXEvent(XEvent* xev) { | 22 int GetTouchIDFromXEvent(XEvent* xev) { |
| 111 float slot = 0; | 23 float slot = 0; |
| 112 if (!TouchFactory::GetInstance()->ExtractTouchParam( | 24 if (!ui::TouchFactory::GetInstance()->ExtractTouchParam( |
| 113 *xev, TouchFactory::TP_SLOT_ID, &slot)) | 25 *xev, ui::TouchFactory::TP_SLOT_ID, &slot)) |
| 114 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; | 26 LOG(ERROR) << "Could not get the slot ID for the event. Using 0."; |
| 115 return slot; | 27 return slot; |
| 116 } | 28 } |
| 117 | 29 |
| 118 ui::EventType EventTypeFromNative(NativeEvent2 native_event) { | |
| 119 switch (native_event->type) { | |
| 120 case KeyPress: | |
| 121 return ui::ET_KEY_PRESSED; | |
| 122 case KeyRelease: | |
| 123 return ui::ET_KEY_RELEASED; | |
| 124 case ButtonPress: | |
| 125 if (native_event->xbutton.button == 4 || | |
| 126 native_event->xbutton.button == 5) | |
| 127 return ui::ET_MOUSEWHEEL; | |
| 128 return ui::ET_MOUSE_PRESSED; | |
| 129 case ButtonRelease: | |
| 130 if (native_event->xbutton.button == 4 || | |
| 131 native_event->xbutton.button == 5) | |
| 132 return ui::ET_MOUSEWHEEL; | |
| 133 return ui::ET_MOUSE_RELEASED; | |
| 134 case MotionNotify: | |
| 135 if (native_event->xmotion.state & | |
| 136 (Button1Mask | Button2Mask | Button3Mask)) | |
| 137 return ui::ET_MOUSE_DRAGGED; | |
| 138 return ui::ET_MOUSE_MOVED; | |
| 139 case GenericEvent: { | |
| 140 XIDeviceEvent* xievent = | |
| 141 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | |
| 142 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) | |
| 143 return GetTouchEventType(native_event); | |
| 144 switch (xievent->evtype) { | |
| 145 case XI_ButtonPress: | |
| 146 return (xievent->detail == 4 || xievent->detail == 5) ? | |
| 147 ui::ET_MOUSEWHEEL : ui::ET_MOUSE_PRESSED; | |
| 148 case XI_ButtonRelease: | |
| 149 return (xievent->detail == 4 || xievent->detail == 5) ? | |
| 150 ui::ET_MOUSEWHEEL : ui::ET_MOUSE_RELEASED; | |
| 151 case XI_Motion: | |
| 152 return GetButtonMaskForX2Event(xievent) ? ui::ET_MOUSE_DRAGGED : | |
| 153 ui::ET_MOUSE_MOVED; | |
| 154 } | |
| 155 } | |
| 156 default: | |
| 157 NOTREACHED(); | |
| 158 break; | |
| 159 } | |
| 160 return ui::ET_UNKNOWN; | |
| 161 } | |
| 162 | |
| 163 int GetMouseWheelOffset(XEvent* xev) { | |
| 164 if (xev->type == GenericEvent) { | |
| 165 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
| 166 return xiev->detail == 4 ? kWheelScrollAmount : -kWheelScrollAmount; | |
| 167 } | |
| 168 return xev->xbutton.button == 4 ? kWheelScrollAmount : -kWheelScrollAmount; | |
| 169 } | |
| 170 | |
| 171 gfx::Point GetEventLocation(XEvent* xev) { | |
| 172 switch (xev->type) { | |
| 173 case ButtonPress: | |
| 174 case ButtonRelease: | |
| 175 return gfx::Point(xev->xbutton.x, xev->xbutton.y); | |
| 176 | |
| 177 case MotionNotify: | |
| 178 return gfx::Point(xev->xmotion.x, xev->xmotion.y); | |
| 179 | |
| 180 case GenericEvent: { | |
| 181 XIDeviceEvent* xievent = | |
| 182 static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
| 183 return gfx::Point(static_cast<int>(xievent->event_x), | |
| 184 static_cast<int>(xievent->event_y)); | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 return gfx::Point(); | |
| 189 } | |
| 190 | |
| 191 int GetLocatedEventFlags(XEvent* xev) { | |
| 192 switch (xev->type) { | |
| 193 case ButtonPress: | |
| 194 case ButtonRelease: | |
| 195 return GetEventFlagsFromXState(xev->xbutton.state) | | |
| 196 GetEventFlagsForButton(xev->xbutton.button); | |
| 197 | |
| 198 case MotionNotify: | |
| 199 return GetEventFlagsFromXState(xev->xmotion.state); | |
| 200 | |
| 201 case GenericEvent: { | |
| 202 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
| 203 bool touch = | |
| 204 TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid); | |
| 205 switch (xievent->evtype) { | |
| 206 case XI_ButtonPress: | |
| 207 case XI_ButtonRelease: | |
| 208 return GetButtonMaskForX2Event(xievent) | | |
| 209 GetEventFlagsFromXState(xievent->mods.effective) | | |
| 210 (touch ? 0 : GetEventFlagsForButton(xievent->detail)); | |
| 211 | |
| 212 case XI_Motion: | |
| 213 return GetButtonMaskForX2Event(xievent) | | |
| 214 GetEventFlagsFromXState(xievent->mods.effective); | |
| 215 } | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 return 0; | |
| 220 } | |
| 221 | |
| 222 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { | 30 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { |
| 223 char buf[6]; | 31 char buf[6]; |
| 224 int bytes_written = XLookupString(key, buf, 6, NULL, NULL); | 32 int bytes_written = XLookupString(key, buf, 6, NULL, NULL); |
| 225 DCHECK_LE(bytes_written, 6); | 33 DCHECK_LE(bytes_written, 6); |
| 226 | 34 |
| 227 string16 result; | 35 string16 result; |
| 228 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && | 36 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && |
| 229 result.length() == 1) ? result[0] : 0; | 37 result.length() == 1) ? result[0] : 0; |
| 230 } | 38 } |
| 231 | 39 |
| 232 float GetTouchParamFromXEvent(XEvent* xev, | 40 float GetTouchParamFromXEvent(XEvent* xev, |
| 233 TouchFactory::TouchParam tp, | 41 ui::TouchFactory::TouchParam tp, |
| 234 float default_value) { | 42 float default_value) { |
| 235 TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value); | 43 ui::TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value); |
| 236 return default_value; | 44 return default_value; |
| 237 } | 45 } |
| 238 | 46 |
| 239 float GetTouchForceFromXEvent(XEvent* xev) { | 47 float GetTouchForceFromXEvent(XEvent* xev) { |
| 240 float force = 0.0; | 48 float force = 0.0; |
| 241 force = GetTouchParamFromXEvent(xev, TouchFactory::TP_PRESSURE, 0.0); | 49 force = GetTouchParamFromXEvent(xev, ui::TouchFactory::TP_PRESSURE, 0.0); |
| 242 unsigned int deviceid = | 50 unsigned int deviceid = |
| 243 static_cast<XIDeviceEvent*>(xev->xcookie.data)->sourceid; | 51 static_cast<XIDeviceEvent*>(xev->xcookie.data)->sourceid; |
| 244 // Force is normalized to fall into [0, 1] | 52 // Force is normalized to fall into [0, 1] |
| 245 if (!TouchFactory::GetInstance()->NormalizeTouchParam( | 53 if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam( |
| 246 deviceid, TouchFactory::TP_PRESSURE, &force)) | 54 deviceid, ui::TouchFactory::TP_PRESSURE, &force)) |
| 247 force = 0.0; | 55 force = 0.0; |
| 248 return force; | 56 return force; |
| 249 } | 57 } |
| 250 | 58 |
| 251 // The following two functions are copied from event_gtk.cc. These will be | 59 // The following two functions are copied from event_gtk.cc. These will be |
| 252 // removed when GTK dependency is removed. | 60 // removed when GTK dependency is removed. |
| 61 #if defined(TOOLKIT_USES_GTK) |
| 253 uint16 GetCharacterFromGdkKeyval(guint keyval) { | 62 uint16 GetCharacterFromGdkKeyval(guint keyval) { |
| 254 guint32 ch = gdk_keyval_to_unicode(keyval); | 63 guint32 ch = gdk_keyval_to_unicode(keyval); |
| 255 | 64 |
| 256 // We only support BMP characters. | 65 // We only support BMP characters. |
| 257 return ch < 0xFFFE ? static_cast<uint16>(ch) : 0; | 66 return ch < 0xFFFE ? static_cast<uint16>(ch) : 0; |
| 258 } | 67 } |
| 259 | 68 |
| 260 GdkEventKey* GetGdkEventKeyFromNative(NativeEvent native_event) { | 69 GdkEventKey* GetGdkEventKeyFromNative(GdkEvent* gdk_event) { |
| 261 DCHECK(native_event->type == GDK_KEY_PRESS || | 70 DCHECK(gdk_event->type == GDK_KEY_PRESS || |
| 262 native_event->type == GDK_KEY_RELEASE); | 71 gdk_event->type == GDK_KEY_RELEASE); |
| 263 return &native_event->key; | 72 return &gdk_event->key; |
| 264 } | 73 } |
| 74 #endif |
| 265 | 75 |
| 266 } // namespace | 76 } // namespace |
| 267 | 77 |
| 268 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
| 269 // Event, private: | |
| 270 | |
| 271 void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, | |
| 272 FromNativeEvent2) { | |
| 273 native_event_ = NULL; | |
| 274 // TODO(beng): remove once we rid views of Gtk/Gdk. | |
| 275 native_event_2_ = native_event_2; | |
| 276 } | |
| 277 | |
| 278 //////////////////////////////////////////////////////////////////////////////// | |
| 279 // LocatedEvent, protected: | |
| 280 | |
| 281 LocatedEvent::LocatedEvent(NativeEvent2 native_event_2, | |
| 282 FromNativeEvent2 from_native) | |
| 283 : Event(native_event_2, | |
| 284 EventTypeFromNative(native_event_2), | |
| 285 GetLocatedEventFlags(native_event_2), | |
| 286 from_native), | |
| 287 location_(GetEventLocation(native_event_2)) { | |
| 288 } | |
| 289 | |
| 290 //////////////////////////////////////////////////////////////////////////////// | |
| 291 // KeyEvent, public: | 79 // KeyEvent, public: |
| 292 | 80 |
| 293 KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native) | |
| 294 : Event(native_event_2, | |
| 295 EventTypeFromNative(native_event_2), | |
| 296 GetEventFlagsFromXState(native_event_2->xkey.state), | |
| 297 from_native), | |
| 298 key_code_(ui::KeyboardCodeFromXKeyEvent(native_event_2)), | |
| 299 character_(0), | |
| 300 unmodified_character_(0) { | |
| 301 } | |
| 302 | |
| 303 uint16 KeyEvent::GetCharacter() const { | 81 uint16 KeyEvent::GetCharacter() const { |
| 304 if (character_) | 82 if (character_) |
| 305 return character_; | 83 return character_; |
| 306 | 84 |
| 307 if (!native_event_2()) { | 85 if (!native_event()) { |
| 86 #if defined(TOOLKIT_USES_GTK) |
| 308 // This event may have been created from a Gdk event. | 87 // This event may have been created from a Gdk event. |
| 309 if (IsControlDown() || !native_event()) | 88 if (!IsControlDown() && gdk_event()) { |
| 310 return GetCharacterFromKeyCode(key_code_, flags()); | 89 uint16 ch = GetCharacterFromGdkKeyval( |
| 311 | 90 GetGdkEventKeyFromNative(gdk_event())->keyval); |
| 312 uint16 ch = GetCharacterFromGdkKeyval( | 91 if (ch) |
| 313 GetGdkEventKeyFromNative(native_event())->keyval); | 92 return ch; |
| 314 return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); | 93 } |
| 94 #endif |
| 95 return GetCharacterFromKeyCode(key_code_, flags()); |
| 315 } | 96 } |
| 316 | 97 |
| 317 DCHECK(native_event_2()->type == KeyPress || | 98 DCHECK(native_event()->type == KeyPress || |
| 318 native_event_2()->type == KeyRelease); | 99 native_event()->type == KeyRelease); |
| 319 | 100 |
| 320 uint16 ch = GetCharacterFromXKeyEvent(&native_event_2()->xkey); | 101 uint16 ch = GetCharacterFromXKeyEvent(&native_event()->xkey); |
| 321 return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); | 102 return ch ? ch : GetCharacterFromKeyCode(key_code_, flags()); |
| 322 } | 103 } |
| 323 | 104 |
| 324 uint16 KeyEvent::GetUnmodifiedCharacter() const { | 105 uint16 KeyEvent::GetUnmodifiedCharacter() const { |
| 325 if (unmodified_character_) | 106 if (unmodified_character_) |
| 326 return unmodified_character_; | 107 return unmodified_character_; |
| 327 | 108 |
| 328 if (!native_event_2()) { | 109 if (!native_event()) { |
| 110 #if defined(TOOLKIT_USES_GTK) |
| 329 // This event may have been created from a Gdk event. | 111 // This event may have been created from a Gdk event. |
| 330 if (!native_event()) | 112 if (gdk_event()) { |
| 331 return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | 113 GdkEventKey* key = GetGdkEventKeyFromNative(gdk_event()); |
| 332 | 114 |
| 333 GdkEventKey* key = GetGdkEventKeyFromNative(native_event()); | 115 static const guint kIgnoredModifiers = |
| 116 GDK_CONTROL_MASK | GDK_LOCK_MASK | GDK_MOD1_MASK | GDK_MOD2_MASK | |
| 117 GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK | GDK_SUPER_MASK | |
| 118 GDK_HYPER_MASK | GDK_META_MASK; |
| 334 | 119 |
| 335 static const guint kIgnoredModifiers = | 120 // We can't use things like (key->state & GDK_SHIFT_MASK), as it may mask |
| 336 GDK_CONTROL_MASK | GDK_LOCK_MASK | GDK_MOD1_MASK | GDK_MOD2_MASK | | 121 // out bits used by X11 or Gtk internally. |
| 337 GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK | GDK_SUPER_MASK | | 122 GdkModifierType modifiers = |
| 338 GDK_HYPER_MASK | GDK_META_MASK; | 123 static_cast<GdkModifierType>(key->state & ~kIgnoredModifiers); |
| 339 | 124 guint keyval = 0; |
| 340 // We can't use things like (key->state & GDK_SHIFT_MASK), as it may mask | 125 if (gdk_keymap_translate_keyboard_state(NULL, key->hardware_keycode, |
| 341 // out bits used by X11 or Gtk internally. | 126 modifiers, key->group, &keyval, NULL, NULL, NULL)) { |
| 342 GdkModifierType modifiers = | 127 uint16 ch = GetCharacterFromGdkKeyval(keyval); |
| 343 static_cast<GdkModifierType>(key->state & ~kIgnoredModifiers); | 128 if (ch) |
| 344 guint keyval = 0; | 129 return ch; |
| 345 uint16 ch = 0; | 130 } |
| 346 if (gdk_keymap_translate_keyboard_state(NULL, key->hardware_keycode, | |
| 347 modifiers, key->group, &keyval, | |
| 348 NULL, NULL, NULL)) { | |
| 349 ch = GetCharacterFromGdkKeyval(keyval); | |
| 350 } | 131 } |
| 351 | 132 #endif |
| 352 return ch ? ch : | 133 return GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); |
| 353 GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | |
| 354 } | 134 } |
| 355 | 135 |
| 356 DCHECK(native_event_2()->type == KeyPress || | 136 DCHECK(native_event()->type == KeyPress || |
| 357 native_event_2()->type == KeyRelease); | 137 native_event()->type == KeyRelease); |
| 358 | 138 |
| 359 XKeyEvent key = native_event_2()->xkey; | 139 XKeyEvent key = native_event()->xkey; |
| 360 | 140 |
| 361 static const unsigned int kIgnoredModifiers = ControlMask | LockMask | | 141 static const unsigned int kIgnoredModifiers = ControlMask | LockMask | |
| 362 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask; | 142 Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask; |
| 363 | 143 |
| 364 // We can't use things like (key.state & ShiftMask), as it may mask out bits | 144 // We can't use things like (key.state & ShiftMask), as it may mask out bits |
| 365 // used by X11 internally. | 145 // used by X11 internally. |
| 366 key.state &= ~kIgnoredModifiers; | 146 key.state &= ~kIgnoredModifiers; |
| 367 uint16 ch = GetCharacterFromXKeyEvent(&key); | 147 uint16 ch = GetCharacterFromXKeyEvent(&key); |
| 368 return ch ? ch : | 148 return ch ? ch : |
| 369 GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); | 149 GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN); |
| 370 } | 150 } |
| 371 | 151 |
| 372 //////////////////////////////////////////////////////////////////////////////// | 152 //////////////////////////////////////////////////////////////////////////////// |
| 373 // MouseEvent, public: | |
| 374 | |
| 375 MouseEvent::MouseEvent(NativeEvent2 native_event_2, | |
| 376 FromNativeEvent2 from_native) | |
| 377 : LocatedEvent(native_event_2, from_native) { | |
| 378 } | |
| 379 | |
| 380 //////////////////////////////////////////////////////////////////////////////// | |
| 381 // MouseWheelEvent, public: | |
| 382 | |
| 383 MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, | |
| 384 FromNativeEvent2 from_native) | |
| 385 : MouseEvent(native_event_2, from_native), | |
| 386 offset_(GetMouseWheelOffset(native_event_2)) { | |
| 387 } | |
| 388 | |
| 389 //////////////////////////////////////////////////////////////////////////////// | |
| 390 // TouchEvent, public: | 153 // TouchEvent, public: |
| 391 | 154 |
| 392 TouchEvent::TouchEvent(NativeEvent2 native_event_2, | 155 TouchEvent::TouchEvent(const ui::NativeEvent& native_event) |
| 393 FromNativeEvent2 from_native) | 156 : LocatedEvent(native_event), |
| 394 : LocatedEvent(native_event_2, from_native), | 157 touch_id_(GetTouchIDFromXEvent(native_event)), |
| 395 touch_id_(GetTouchIDFromXEvent(native_event_2)), | 158 radius_x_(GetTouchParamFromXEvent(native_event, |
| 396 radius_x_(GetTouchParamFromXEvent(native_event_2, | 159 ui::TouchFactory::TP_TOUCH_MAJOR, |
| 397 TouchFactory::TP_TOUCH_MAJOR, | |
| 398 2.0) / 2.0), | 160 2.0) / 2.0), |
| 399 radius_y_(GetTouchParamFromXEvent(native_event_2, | 161 radius_y_(GetTouchParamFromXEvent(native_event, |
| 400 TouchFactory::TP_TOUCH_MINOR, | 162 ui::TouchFactory::TP_TOUCH_MINOR, |
| 401 2.0) / 2.0), | 163 2.0) / 2.0), |
| 402 rotation_angle_(GetTouchParamFromXEvent(native_event_2, | 164 rotation_angle_(GetTouchParamFromXEvent(native_event, |
| 403 TouchFactory::TP_ORIENTATION, | 165 ui::TouchFactory::TP_ORIENTATION, |
| 404 0.0)), | 166 0.0)), |
| 405 force_(GetTouchForceFromXEvent(native_event_2)) { | 167 force_(GetTouchForceFromXEvent(native_event)) { |
| 406 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { | 168 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { |
| 407 TouchFactory* factory = TouchFactory::GetInstance(); | 169 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
| 408 float slot; | 170 float slot; |
| 409 if (factory->ExtractTouchParam(*native_event_2, | 171 if (factory->ExtractTouchParam(*native_event, |
| 410 TouchFactory::TP_SLOT_ID, &slot)) { | 172 ui::TouchFactory::TP_SLOT_ID, &slot)) { |
| 411 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); | 173 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); |
| 412 } | 174 } |
| 413 } | 175 } |
| 414 } | 176 } |
| 415 | 177 |
| 416 } // namespace views | 178 } // namespace views |
| OLD | NEW |