gesture_event_data.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/events/gesture_detection/gesture_event_data.h"
  5. #include <ostream>
  6. #include "base/check_op.h"
  7. #include "base/notreached.h"
  8. namespace ui {
  9. namespace {
  10. EventPointerType ToEventPointerType(MotionEvent::ToolType tool_type) {
  11. switch (tool_type) {
  12. case MotionEvent::ToolType::UNKNOWN:
  13. return EventPointerType::kUnknown;
  14. case MotionEvent::ToolType::FINGER:
  15. return EventPointerType::kTouch;
  16. case MotionEvent::ToolType::STYLUS:
  17. return EventPointerType::kPen;
  18. case MotionEvent::ToolType::MOUSE:
  19. return EventPointerType::kMouse;
  20. case MotionEvent::ToolType::ERASER:
  21. return EventPointerType::kEraser;
  22. default:
  23. NOTREACHED() << "Invalid ToolType = " << tool_type;
  24. return EventPointerType::kUnknown;
  25. }
  26. }
  27. } // anonymous namespace
  28. GestureEventData::GestureEventData(const GestureEventDetails& details,
  29. int motion_event_id,
  30. MotionEvent::ToolType primary_tool_type,
  31. base::TimeTicks time,
  32. float x,
  33. float y,
  34. float raw_x,
  35. float raw_y,
  36. size_t touch_point_count,
  37. const gfx::RectF& bounding_box,
  38. int flags,
  39. uint32_t unique_touch_event_id)
  40. : details(details),
  41. motion_event_id(motion_event_id),
  42. primary_tool_type(primary_tool_type),
  43. time(time),
  44. x(x),
  45. y(y),
  46. raw_x(raw_x),
  47. raw_y(raw_y),
  48. flags(flags),
  49. unique_touch_event_id(unique_touch_event_id) {
  50. DCHECK_GE(motion_event_id, 0);
  51. DCHECK_NE(0U, touch_point_count);
  52. this->details.set_primary_pointer_type(ToEventPointerType(primary_tool_type));
  53. this->details.set_primary_unique_touch_event_id(
  54. details.primary_unique_touch_event_id());
  55. this->details.set_touch_points(static_cast<int>(touch_point_count));
  56. this->details.set_bounding_box(bounding_box);
  57. }
  58. GestureEventData::GestureEventData(EventType type,
  59. const GestureEventData& other)
  60. : details(type, other.details),
  61. motion_event_id(other.motion_event_id),
  62. primary_tool_type(other.primary_tool_type),
  63. time(other.time),
  64. x(other.x),
  65. y(other.y),
  66. raw_x(other.raw_x),
  67. raw_y(other.raw_y),
  68. flags(other.flags),
  69. unique_touch_event_id(other.unique_touch_event_id) {
  70. details.set_primary_pointer_type(other.details.primary_pointer_type());
  71. details.set_primary_unique_touch_event_id(
  72. other.details.primary_unique_touch_event_id());
  73. details.set_touch_points(other.details.touch_points());
  74. details.set_bounding_box(other.details.bounding_box_f());
  75. }
  76. GestureEventData::GestureEventData(const GestureEventData& other) = default;
  77. GestureEventData& GestureEventData::operator=(const GestureEventData& other) =
  78. default;
  79. GestureEventData::GestureEventData()
  80. : motion_event_id(0),
  81. primary_tool_type(MotionEvent::ToolType::UNKNOWN),
  82. x(0),
  83. y(0),
  84. raw_x(0),
  85. raw_y(0),
  86. flags(EF_NONE),
  87. unique_touch_event_id(0U) {}
  88. } // namespace ui