| 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/gestures/motion_event_aura.h" | 5 #include "ui/events/gestures/motion_event_aura.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/events/gesture_detection/gesture_configuration.h" | 8 #include "ui/events/gesture_detection/gesture_configuration.h" |
| 9 | 9 |
| 10 namespace ui { | 10 namespace ui { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 return MotionEvent::TOOL_TYPE_UNKNOWN; | 28 return MotionEvent::TOOL_TYPE_UNKNOWN; |
| 29 } | 29 } |
| 30 | 30 |
| 31 PointerProperties GetPointerPropertiesFromTouchEvent(const TouchEvent& touch) { | 31 PointerProperties GetPointerPropertiesFromTouchEvent(const TouchEvent& touch) { |
| 32 PointerProperties pointer_properties; | 32 PointerProperties pointer_properties; |
| 33 pointer_properties.x = touch.x(); | 33 pointer_properties.x = touch.x(); |
| 34 pointer_properties.y = touch.y(); | 34 pointer_properties.y = touch.y(); |
| 35 pointer_properties.raw_x = touch.root_location_f().x(); | 35 pointer_properties.raw_x = touch.root_location_f().x(); |
| 36 pointer_properties.raw_y = touch.root_location_f().y(); | 36 pointer_properties.raw_y = touch.root_location_f().y(); |
| 37 pointer_properties.id = touch.touch_id(); | 37 pointer_properties.id = touch.pointer_details().id; |
| 38 pointer_properties.pressure = touch.pointer_details().force; | 38 pointer_properties.pressure = touch.pointer_details().force; |
| 39 pointer_properties.source_device_id = touch.source_device_id(); | 39 pointer_properties.source_device_id = touch.source_device_id(); |
| 40 | 40 |
| 41 pointer_properties.SetAxesAndOrientation(touch.pointer_details().radius_x, | 41 pointer_properties.SetAxesAndOrientation(touch.pointer_details().radius_x, |
| 42 touch.pointer_details().radius_y, | 42 touch.pointer_details().radius_y, |
| 43 touch.rotation_angle()); | 43 touch.rotation_angle()); |
| 44 if (!pointer_properties.touch_major) { | 44 if (!pointer_properties.touch_major) { |
| 45 pointer_properties.touch_major = | 45 pointer_properties.touch_major = |
| 46 2.f * GestureConfiguration::GetInstance()->default_radius(); | 46 2.f * GestureConfiguration::GetInstance()->default_radius(); |
| 47 pointer_properties.touch_minor = | 47 pointer_properties.touch_minor = |
| 48 2.f * GestureConfiguration::GetInstance()->default_radius(); | 48 2.f * GestureConfiguration::GetInstance()->default_radius(); |
| 49 pointer_properties.orientation = 0; | 49 pointer_properties.orientation = 0; |
| 50 } | 50 } |
| 51 | 51 |
| 52 pointer_properties.tool_type = EventPointerTypeToMotionEventToolType( | 52 pointer_properties.tool_type = EventPointerTypeToMotionEventToolType( |
| 53 touch.pointer_details().pointer_type); | 53 touch.pointer_details().pointer_type); |
| 54 | 54 |
| 55 return pointer_properties; | 55 return pointer_properties; |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 MotionEventAura::MotionEventAura() {} | 60 MotionEventAura::MotionEventAura() {} |
| 61 | 61 |
| 62 MotionEventAura::~MotionEventAura() {} | 62 MotionEventAura::~MotionEventAura() {} |
| 63 | 63 |
| 64 bool MotionEventAura::OnTouch(const TouchEvent& touch) { | 64 bool MotionEventAura::OnTouch(const TouchEvent& touch) { |
| 65 int index = FindPointerIndexOfId(touch.touch_id()); | 65 int index = FindPointerIndexOfId(touch.pointer_details().id); |
| 66 bool pointer_id_is_active = index != -1; | 66 bool pointer_id_is_active = index != -1; |
| 67 | 67 |
| 68 if (touch.type() == ET_TOUCH_PRESSED && pointer_id_is_active) { | 68 if (touch.type() == ET_TOUCH_PRESSED && pointer_id_is_active) { |
| 69 // TODO(tdresser): This should be NOTREACHED() - crbug.com/610423. | 69 // TODO(tdresser): This should be NOTREACHED() - crbug.com/610423. |
| 70 return false; | 70 return false; |
| 71 } else if (touch.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) { | 71 } else if (touch.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) { |
| 72 // When a window begins capturing touch events, we could have an active | 72 // When a window begins capturing touch events, we could have an active |
| 73 // touch stream transfered to us, resulting in touch move or touch up events | 73 // touch stream transfered to us, resulting in touch move or touch up events |
| 74 // without associated touch down events. Ignore them. | 74 // without associated touch down events. Ignore them. |
| 75 return false; | 75 return false; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 return true; | 106 return true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 void MotionEventAura::CleanupRemovedTouchPoints(const TouchEvent& event) { | 109 void MotionEventAura::CleanupRemovedTouchPoints(const TouchEvent& event) { |
| 110 if (event.type() != ET_TOUCH_RELEASED && | 110 if (event.type() != ET_TOUCH_RELEASED && |
| 111 event.type() != ET_TOUCH_CANCELLED) { | 111 event.type() != ET_TOUCH_CANCELLED) { |
| 112 return; | 112 return; |
| 113 } | 113 } |
| 114 | 114 |
| 115 DCHECK(GetPointerCount()); | 115 DCHECK(GetPointerCount()); |
| 116 int index_to_delete = GetIndexFromId(event.touch_id()); | 116 int index_to_delete = GetIndexFromId(event.pointer_details().id); |
| 117 set_action_index(-1); | 117 set_action_index(-1); |
| 118 set_action(MotionEvent::ACTION_NONE); | 118 set_action(MotionEvent::ACTION_NONE); |
| 119 pointer(index_to_delete) = pointer(GetPointerCount() - 1); | 119 pointer(index_to_delete) = pointer(GetPointerCount() - 1); |
| 120 PopPointer(); | 120 PopPointer(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { | 123 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { |
| 124 DCHECK_LT(pointer_index, GetPointerCount()); | 124 DCHECK_LT(pointer_index, GetPointerCount()); |
| 125 return pointer(pointer_index).source_device_id; | 125 return pointer(pointer_index).source_device_id; |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool MotionEventAura::AddTouch(const TouchEvent& touch) { | 128 bool MotionEventAura::AddTouch(const TouchEvent& touch) { |
| 129 if (GetPointerCount() == MotionEvent::MAX_TOUCH_POINT_COUNT) | 129 if (GetPointerCount() == MotionEvent::MAX_TOUCH_POINT_COUNT) |
| 130 return false; | 130 return false; |
| 131 | 131 |
| 132 PushPointer(GetPointerPropertiesFromTouchEvent(touch)); | 132 PushPointer(GetPointerPropertiesFromTouchEvent(touch)); |
| 133 return true; | 133 return true; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void MotionEventAura::UpdateTouch(const TouchEvent& touch) { | 136 void MotionEventAura::UpdateTouch(const TouchEvent& touch) { |
| 137 pointer(GetIndexFromId(touch.touch_id())) = | 137 pointer(GetIndexFromId(touch.pointer_details().id)) = |
| 138 GetPointerPropertiesFromTouchEvent(touch); | 138 GetPointerPropertiesFromTouchEvent(touch); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void MotionEventAura::UpdateCachedAction(const TouchEvent& touch) { | 141 void MotionEventAura::UpdateCachedAction(const TouchEvent& touch) { |
| 142 DCHECK(GetPointerCount()); | 142 DCHECK(GetPointerCount()); |
| 143 switch (touch.type()) { | 143 switch (touch.type()) { |
| 144 case ET_TOUCH_PRESSED: | 144 case ET_TOUCH_PRESSED: |
| 145 if (GetPointerCount() == 1) { | 145 if (GetPointerCount() == 1) { |
| 146 set_action(ACTION_DOWN); | 146 set_action(ACTION_DOWN); |
| 147 } else { | 147 } else { |
| 148 set_action(ACTION_POINTER_DOWN); | 148 set_action(ACTION_POINTER_DOWN); |
| 149 set_action_index(GetIndexFromId(touch.touch_id())); | 149 set_action_index(GetIndexFromId(touch.pointer_details().id)); |
| 150 } | 150 } |
| 151 break; | 151 break; |
| 152 case ET_TOUCH_RELEASED: | 152 case ET_TOUCH_RELEASED: |
| 153 if (GetPointerCount() == 1) { | 153 if (GetPointerCount() == 1) { |
| 154 set_action(ACTION_UP); | 154 set_action(ACTION_UP); |
| 155 } else { | 155 } else { |
| 156 set_action(ACTION_POINTER_UP); | 156 set_action(ACTION_POINTER_UP); |
| 157 set_action_index(GetIndexFromId(touch.touch_id())); | 157 set_action_index(GetIndexFromId(touch.pointer_details().id)); |
| 158 } | 158 } |
| 159 break; | 159 break; |
| 160 case ET_TOUCH_CANCELLED: | 160 case ET_TOUCH_CANCELLED: |
| 161 set_action(ACTION_CANCEL); | 161 set_action(ACTION_CANCEL); |
| 162 break; | 162 break; |
| 163 case ET_TOUCH_MOVED: | 163 case ET_TOUCH_MOVED: |
| 164 set_action(ACTION_MOVE); | 164 set_action(ACTION_MOVE); |
| 165 break; | 165 break; |
| 166 default: | 166 default: |
| 167 NOTREACHED(); | 167 NOTREACHED(); |
| 168 break; | 168 break; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 int MotionEventAura::GetIndexFromId(int id) const { | 172 int MotionEventAura::GetIndexFromId(int id) const { |
| 173 int index = FindPointerIndexOfId(id); | 173 int index = FindPointerIndexOfId(id); |
| 174 // TODO(tdresser): remove these checks once crbug.com/525189 is fixed. | 174 // TODO(tdresser): remove these checks once crbug.com/525189 is fixed. |
| 175 CHECK_GE(index, 0); | 175 CHECK_GE(index, 0); |
| 176 CHECK_LT(index, static_cast<int>(GetPointerCount())); | 176 CHECK_LT(index, static_cast<int>(GetPointerCount())); |
| 177 return index; | 177 return index; |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace ui | 180 } // namespace ui |
| OLD | NEW |