Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/events/gesture_event_details.h" | 5 #include "ui/events/gesture_event_details.h" |
| 6 | 6 |
| 7 namespace ui { | 7 namespace ui { |
| 8 | 8 |
| 9 GestureEventDetails::GestureEventDetails() | 9 GestureEventDetails::GestureEventDetails() |
| 10 : type_(ET_UNKNOWN), touch_points_(0), oldest_touch_id_(-1) { | 10 : type_(ET_UNKNOWN), touch_points_(0), oldest_touch_id_(-1) { |
| 11 } | 11 } |
| 12 | 12 |
| 13 GestureEventDetails::GestureEventDetails(ui::EventType type) | 13 GestureEventDetails::GestureEventDetails(ui::EventType type) |
| 14 : type_(type), touch_points_(1), oldest_touch_id_(-1) { | 14 : type_(type), touch_points_(1), oldest_touch_id_(-1) { |
| 15 DCHECK_GE(type, ET_GESTURE_TYPE_START); | 15 DCHECK_GE(type, ET_GESTURE_TYPE_START); |
| 16 DCHECK_LE(type, ET_GESTURE_TYPE_END); | 16 DCHECK_LE(type, ET_GESTURE_TYPE_END); |
| 17 } | 17 } |
| 18 | 18 |
| 19 GestureEventDetails::GestureEventDetails(ui::EventType type, | 19 GestureEventDetails::GestureEventDetails(ui::EventType type, |
| 20 float delta_x, | 20 float delta_x, |
| 21 float delta_y) | 21 float delta_y) |
| 22 : type_(type), touch_points_(1), oldest_touch_id_(-1) { | 22 : type_(type), touch_points_(1), oldest_touch_id_(-1) { |
| 23 DCHECK_GE(type, ET_GESTURE_TYPE_START); | 23 DCHECK_GE(type, ET_GESTURE_TYPE_START); |
| 24 DCHECK_LE(type, ET_GESTURE_TYPE_END); | 24 DCHECK_LE(type, ET_GESTURE_TYPE_END); |
| 25 switch (type_) { | 25 switch (type_) { |
| 26 case ui::ET_GESTURE_SCROLL_BEGIN: | 26 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 27 data.scroll_begin.x_hint = delta_x; | 27 data_.scroll_begin.x_hint = delta_x; |
| 28 data.scroll_begin.y_hint = delta_y; | 28 data_.scroll_begin.y_hint = delta_y; |
| 29 break; | 29 break; |
| 30 | 30 |
| 31 case ui::ET_GESTURE_SCROLL_UPDATE: | 31 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 32 data.scroll_update.x = delta_x; | 32 data_.scroll_update.x = delta_x; |
| 33 data.scroll_update.y = delta_y; | 33 data_.scroll_update.y = delta_y; |
| 34 break; | 34 break; |
| 35 | 35 |
| 36 case ui::ET_SCROLL_FLING_START: | 36 case ui::ET_SCROLL_FLING_START: |
| 37 data.fling_velocity.x = delta_x; | 37 data_.fling_velocity.x = delta_x; |
| 38 data.fling_velocity.y = delta_y; | 38 data_.fling_velocity.y = delta_y; |
| 39 break; | 39 break; |
| 40 | 40 |
| 41 case ui::ET_GESTURE_TWO_FINGER_TAP: | 41 case ui::ET_GESTURE_TWO_FINGER_TAP: |
| 42 data.first_finger_enclosing_rectangle.width = delta_x; | 42 data_.first_finger_enclosing_rectangle.width = delta_x; |
| 43 data.first_finger_enclosing_rectangle.height = delta_y; | 43 data_.first_finger_enclosing_rectangle.height = delta_y; |
| 44 break; | 44 break; |
| 45 | 45 |
| 46 case ui::ET_GESTURE_SWIPE: | 46 case ui::ET_GESTURE_SWIPE: |
| 47 data.swipe.left = delta_x < 0; | 47 data_.swipe.left = delta_x < 0; |
| 48 data.swipe.right = delta_x > 0; | 48 data_.swipe.right = delta_x > 0; |
| 49 data.swipe.up = delta_y < 0; | 49 data_.swipe.up = delta_y < 0; |
| 50 data.swipe.down = delta_y > 0; | 50 data_.swipe.down = delta_y > 0; |
| 51 break; | 51 break; |
| 52 | 52 |
| 53 default: | 53 default: |
| 54 NOTREACHED() << "Invalid event type for constructor: " << type; | 54 NOTREACHED() << "Invalid event type for constructor: " << type; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 GestureEventDetails::GestureEventDetails(ui::EventType type, | |
| 59 const GestureEventDetails& other) | |
| 60 : type_(type), | |
| 61 data_(other.data_), | |
| 62 touch_points_(other.touch_points_), | |
| 63 bounding_box_(other.bounding_box_), | |
| 64 oldest_touch_id_(other.oldest_touch_id_) { | |
| 65 DCHECK_GE(type, ET_GESTURE_TYPE_START); | |
| 66 DCHECK_LE(type, ET_GESTURE_TYPE_END); | |
| 67 switch (type) { | |
| 68 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 69 // Synthetic creation of SCROLL_BEGIN from PINCH_BEGIN is explicitly | |
| 70 // allowed as an exception. | |
| 71 if (other.type() == ui::ET_GESTURE_PINCH_BEGIN) | |
| 72 break; | |
| 73 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 74 case ui::ET_SCROLL_FLING_START: | |
| 75 case ui::ET_GESTURE_SWIPE: | |
| 76 case ui::ET_GESTURE_PINCH_UPDATE: | |
| 77 DCHECK_EQ(type, other.type()) << " - Invalid gesture conversion from " | |
| 78 << other.type() << " to " << type; | |
| 79 break; | |
| 80 default: | |
| 81 break; | |
|
sadrul
2014/11/18 17:53:45
NOTREACHED()? Or no because the caller is responsi
jdduke (slow)
2014/11/18 19:50:46
For these cases, we don't really care about the so
| |
| 82 } | |
| 83 } | |
| 84 | |
| 58 GestureEventDetails::Details::Details() { | 85 GestureEventDetails::Details::Details() { |
| 59 memset(this, 0, sizeof(Details)); | 86 memset(this, 0, sizeof(Details)); |
| 60 } | 87 } |
| 61 | 88 |
| 62 } // namespace ui | 89 } // namespace ui |
| OLD | NEW |