gesture_event_details.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_event_details.h"
  5. #include <ostream>
  6. #include "base/check_op.h"
  7. #include "base/notreached.h"
  8. namespace ui {
  9. GestureEventDetails::GestureEventDetails()
  10. : type_(ET_UNKNOWN),
  11. device_type_(GestureDeviceType::DEVICE_UNKNOWN),
  12. touch_points_(0) {}
  13. GestureEventDetails::GestureEventDetails(ui::EventType type)
  14. : type_(type),
  15. device_type_(GestureDeviceType::DEVICE_UNKNOWN),
  16. touch_points_(1) {
  17. DCHECK_GE(type, ET_GESTURE_TYPE_START);
  18. DCHECK_LE(type, ET_GESTURE_TYPE_END);
  19. }
  20. GestureEventDetails::GestureEventDetails(ui::EventType type,
  21. float delta_x,
  22. float delta_y,
  23. ui::ScrollGranularity units)
  24. : type_(type),
  25. device_type_(GestureDeviceType::DEVICE_UNKNOWN),
  26. touch_points_(1) {
  27. DCHECK_GE(type, ET_GESTURE_TYPE_START);
  28. DCHECK_LE(type, ET_GESTURE_TYPE_END);
  29. switch (type_) {
  30. case ui::ET_GESTURE_SCROLL_BEGIN:
  31. data_.scroll_begin.x_hint = delta_x;
  32. data_.scroll_begin.y_hint = delta_y;
  33. data_.scroll_begin.delta_hint_units = units;
  34. break;
  35. case ui::ET_GESTURE_SCROLL_UPDATE:
  36. data_.scroll_update.x = delta_x;
  37. data_.scroll_update.y = delta_y;
  38. data_.scroll_update.delta_units = units;
  39. break;
  40. case ui::ET_SCROLL_FLING_START:
  41. data_.fling_velocity.x = delta_x;
  42. data_.fling_velocity.y = delta_y;
  43. break;
  44. case ui::ET_GESTURE_TWO_FINGER_TAP:
  45. data_.first_finger_enclosing_rectangle.width = delta_x;
  46. data_.first_finger_enclosing_rectangle.height = delta_y;
  47. break;
  48. case ui::ET_GESTURE_SWIPE:
  49. data_.swipe.left = delta_x < 0;
  50. data_.swipe.right = delta_x > 0;
  51. data_.swipe.up = delta_y < 0;
  52. data_.swipe.down = delta_y > 0;
  53. break;
  54. default:
  55. NOTREACHED() << "Invalid event type for constructor: " << type;
  56. }
  57. }
  58. GestureEventDetails::GestureEventDetails(ui::EventType type,
  59. const GestureEventDetails& other)
  60. : type_(type),
  61. data_(other.data_),
  62. device_type_(other.device_type_),
  63. primary_pointer_type_(other.primary_pointer_type_),
  64. primary_unique_touch_event_id_(other.primary_unique_touch_event_id_),
  65. touch_points_(other.touch_points_),
  66. bounding_box_(other.bounding_box_) {
  67. DCHECK_GE(type, ET_GESTURE_TYPE_START);
  68. DCHECK_LE(type, ET_GESTURE_TYPE_END);
  69. switch (type) {
  70. case ui::ET_GESTURE_SCROLL_BEGIN:
  71. // Synthetic creation of SCROLL_BEGIN from PINCH_BEGIN is explicitly
  72. // allowed as an exception.
  73. if (other.type() == ui::ET_GESTURE_PINCH_BEGIN)
  74. break;
  75. [[fallthrough]];
  76. case ui::ET_GESTURE_SCROLL_UPDATE:
  77. case ui::ET_SCROLL_FLING_START:
  78. case ui::ET_GESTURE_SWIPE:
  79. case ui::ET_GESTURE_PINCH_UPDATE:
  80. DCHECK_EQ(type, other.type()) << " - Invalid gesture conversion from "
  81. << other.type() << " to " << type;
  82. break;
  83. default:
  84. break;
  85. }
  86. }
  87. GestureEventDetails::Details::Details() {
  88. memset(this, 0, sizeof(Details));
  89. }
  90. } // namespace ui