| 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/base/events/event.h" | 5 #include "ui/base/events/event.h" |
| 6 | 6 |
| 7 #if defined(USE_X11) | 7 #if defined(USE_X11) |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include <cmath> |
| 11 #include <cstring> | 12 #include <cstring> |
| 12 | 13 |
| 13 #include "ui/base/keycodes/keyboard_code_conversion.h" | 14 #include "ui/base/keycodes/keyboard_code_conversion.h" |
| 14 #include "ui/gfx/interpolated_transform.h" | 15 #include "ui/gfx/interpolated_transform.h" |
| 15 #include "ui/gfx/point3.h" | 16 #include "ui/gfx/point3.h" |
| 16 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
| 17 | 18 |
| 18 #if defined(USE_X11) | 19 #if defined(USE_X11) |
| 19 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 20 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { | 25 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { |
| 25 #if defined(USE_X11) | 26 #if defined(USE_X11) |
| 26 if (!event || event->type == GenericEvent) | 27 if (!event || event->type == GenericEvent) |
| 27 return NULL; | 28 return NULL; |
| 28 XEvent* copy = new XEvent; | 29 XEvent* copy = new XEvent; |
| 29 *copy = *event; | 30 *copy = *event; |
| 30 return copy; | 31 return copy; |
| 31 #elif defined(OS_WIN) | 32 #elif defined(OS_WIN) |
| 32 return event; | 33 return event; |
| 33 #else | 34 #else |
| 34 NOTREACHED() << | 35 NOTREACHED() << |
| 35 "Don't know how to copy base::NativeEvent for this platform"; | 36 "Don't know how to copy base::NativeEvent for this platform"; |
| 36 return NULL; | 37 return NULL; |
| 37 #endif | 38 #endif |
| 38 } | 39 } |
| 39 | 40 |
| 41 gfx::Point CalibratePoint(const gfx::Point& point, |
| 42 const gfx::Size& from, |
| 43 const gfx::Size& to) { |
| 44 float calibrated_x = |
| 45 static_cast<float>(point.x()) * to.width() / from.width(); |
| 46 float calibrated_y = |
| 47 static_cast<float>(point.y()) * to.height() / from.height(); |
| 48 return gfx::Point(static_cast<int>(floorf(calibrated_x + 0.5f)), |
| 49 static_cast<int>(floorf(calibrated_y + 0.5f))); |
| 50 } |
| 51 |
| 40 } // namespace | 52 } // namespace |
| 41 | 53 |
| 42 namespace ui { | 54 namespace ui { |
| 43 | 55 |
| 44 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
| 45 // Event | 57 // Event |
| 46 | 58 |
| 47 Event::~Event() { | 59 Event::~Event() { |
| 48 #if defined(USE_X11) | 60 #if defined(USE_X11) |
| 49 if (delete_native_event_) | 61 if (delete_native_event_) |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 radius_x_(0.0f), | 296 radius_x_(0.0f), |
| 285 radius_y_(0.0f), | 297 radius_y_(0.0f), |
| 286 rotation_angle_(0.0f), | 298 rotation_angle_(0.0f), |
| 287 force_(0.0f) { | 299 force_(0.0f) { |
| 288 set_time_stamp(time_stamp); | 300 set_time_stamp(time_stamp); |
| 289 } | 301 } |
| 290 | 302 |
| 291 TouchEvent::~TouchEvent() { | 303 TouchEvent::~TouchEvent() { |
| 292 } | 304 } |
| 293 | 305 |
| 306 void TouchEvent::CalibrateLocation(const gfx::Size& from, const gfx::Size& to) { |
| 307 location_ = CalibratePoint(location_, from, to); |
| 308 root_location_ = CalibratePoint(root_location_, from, to); |
| 309 } |
| 310 |
| 294 void TouchEvent::UpdateForRootTransform(const Transform& root_transform) { | 311 void TouchEvent::UpdateForRootTransform(const Transform& root_transform) { |
| 295 LocatedEvent::UpdateForRootTransform(root_transform); | 312 LocatedEvent::UpdateForRootTransform(root_transform); |
| 296 gfx::Point3f scale; | 313 gfx::Point3f scale; |
| 297 InterpolatedTransform::FactorTRS(root_transform, NULL, NULL, &scale); | 314 InterpolatedTransform::FactorTRS(root_transform, NULL, NULL, &scale); |
| 298 if (scale.x()) | 315 if (scale.x()) |
| 299 radius_x_ /= scale.x(); | 316 radius_x_ /= scale.x(); |
| 300 if (scale.y()) | 317 if (scale.y()) |
| 301 radius_y_ /= scale.y(); | 318 radius_y_ /= scale.y(); |
| 302 } | 319 } |
| 303 | 320 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 int GestureEvent::GetLowestTouchId() const { | 509 int GestureEvent::GetLowestTouchId() const { |
| 493 if (touch_ids_bitfield_ == 0) | 510 if (touch_ids_bitfield_ == 0) |
| 494 return -1; | 511 return -1; |
| 495 int i = -1; | 512 int i = -1; |
| 496 // Find the index of the least significant 1 bit | 513 // Find the index of the least significant 1 bit |
| 497 while (!(1 << ++i & touch_ids_bitfield_)); | 514 while (!(1 << ++i & touch_ids_bitfield_)); |
| 498 return i; | 515 return i; |
| 499 } | 516 } |
| 500 | 517 |
| 501 } // namespace ui | 518 } // namespace ui |
| OLD | NEW |