| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/input/synthetic_web_input_event_builders.h" | 5 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/common/input/web_touch_event_traits.h" | 8 #include "content/common/input/web_touch_event_traits.h" |
| 9 #include "ui/events/base_event_utils.h" | 9 #include "ui/events/base_event_utils.h" |
| 10 #include "ui/events/keycodes/keyboard_codes.h" | 10 #include "ui/events/keycodes/keyboard_codes.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 break; | 182 break; |
| 183 case WebTouchPoint::StateReleased: | 183 case WebTouchPoint::StateReleased: |
| 184 case WebTouchPoint::StateCancelled: | 184 case WebTouchPoint::StateCancelled: |
| 185 touches[i] = WebTouchPoint(); | 185 touches[i] = WebTouchPoint(); |
| 186 break; | 186 break; |
| 187 case WebTouchPoint::StateUndefined: | 187 case WebTouchPoint::StateUndefined: |
| 188 break; | 188 break; |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 touchesLength = activePointCount; | 191 touchesLength = activePointCount; |
| 192 type = WebInputEvent::Undefined; | 192 m_type = WebInputEvent::Undefined; |
| 193 movedBeyondSlopRegion = false; | 193 movedBeyondSlopRegion = false; |
| 194 uniqueTouchEventId = ui::GetNextTouchEventId(); | 194 uniqueTouchEventId = ui::GetNextTouchEventId(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 int SyntheticWebTouchEvent::PressPoint(float x, float y) { | 197 int SyntheticWebTouchEvent::PressPoint(float x, float y) { |
| 198 int index = FirstFreeIndex(); | 198 int index = FirstFreeIndex(); |
| 199 if (index == -1) | 199 if (index == -1) |
| 200 return -1; | 200 return -1; |
| 201 WebTouchPoint& point = touches[index]; | 201 WebTouchPoint& point = touches[index]; |
| 202 point.id = index; | 202 point.id = index; |
| 203 point.position.x = point.screenPosition.x = x; | 203 point.position.x = point.screenPosition.x = x; |
| 204 point.position.y = point.screenPosition.y = y; | 204 point.position.y = point.screenPosition.y = y; |
| 205 point.state = WebTouchPoint::StatePressed; | 205 point.state = WebTouchPoint::StatePressed; |
| 206 point.radiusX = point.radiusY = 1.f; | 206 point.radiusX = point.radiusY = 1.f; |
| 207 point.rotationAngle = 1.f; | 207 point.rotationAngle = 1.f; |
| 208 point.force = 1.f; | 208 point.force = 1.f; |
| 209 point.tiltX = point.tiltY = 0; | 209 point.tiltX = point.tiltY = 0; |
| 210 ++touchesLength; | 210 ++touchesLength; |
| 211 WebTouchEventTraits::ResetType(WebInputEvent::TouchStart, timeStampSeconds, | 211 WebTouchEventTraits::ResetType(WebInputEvent::TouchStart, timeStampSeconds(), |
| 212 this); | 212 this); |
| 213 return point.id; | 213 return point.id; |
| 214 } | 214 } |
| 215 | 215 |
| 216 void SyntheticWebTouchEvent::MovePoint(int index, float x, float y) { | 216 void SyntheticWebTouchEvent::MovePoint(int index, float x, float y) { |
| 217 CHECK_GE(index, 0); | 217 CHECK_GE(index, 0); |
| 218 CHECK_LT(index, kTouchesLengthCap); | 218 CHECK_LT(index, kTouchesLengthCap); |
| 219 // Always set this bit to avoid otherwise unexpected touchmove suppression. | 219 // Always set this bit to avoid otherwise unexpected touchmove suppression. |
| 220 // The caller can opt-out explicitly, if necessary. | 220 // The caller can opt-out explicitly, if necessary. |
| 221 movedBeyondSlopRegion = true; | 221 movedBeyondSlopRegion = true; |
| 222 WebTouchPoint& point = touches[index]; | 222 WebTouchPoint& point = touches[index]; |
| 223 point.position.x = point.screenPosition.x = x; | 223 point.position.x = point.screenPosition.x = x; |
| 224 point.position.y = point.screenPosition.y = y; | 224 point.position.y = point.screenPosition.y = y; |
| 225 touches[index].state = WebTouchPoint::StateMoved; | 225 touches[index].state = WebTouchPoint::StateMoved; |
| 226 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove, timeStampSeconds, | 226 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove, timeStampSeconds(), |
| 227 this); | 227 this); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void SyntheticWebTouchEvent::ReleasePoint(int index) { | 230 void SyntheticWebTouchEvent::ReleasePoint(int index) { |
| 231 CHECK_GE(index, 0); | 231 CHECK_GE(index, 0); |
| 232 CHECK_LT(index, kTouchesLengthCap); | 232 CHECK_LT(index, kTouchesLengthCap); |
| 233 touches[index].state = WebTouchPoint::StateReleased; | 233 touches[index].state = WebTouchPoint::StateReleased; |
| 234 WebTouchEventTraits::ResetType(WebInputEvent::TouchEnd, timeStampSeconds, | 234 WebTouchEventTraits::ResetType(WebInputEvent::TouchEnd, timeStampSeconds(), |
| 235 this); | 235 this); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void SyntheticWebTouchEvent::CancelPoint(int index) { | 238 void SyntheticWebTouchEvent::CancelPoint(int index) { |
| 239 CHECK_GE(index, 0); | 239 CHECK_GE(index, 0); |
| 240 CHECK_LT(index, kTouchesLengthCap); | 240 CHECK_LT(index, kTouchesLengthCap); |
| 241 touches[index].state = WebTouchPoint::StateCancelled; | 241 touches[index].state = WebTouchPoint::StateCancelled; |
| 242 WebTouchEventTraits::ResetType(WebInputEvent::TouchCancel, timeStampSeconds, | 242 WebTouchEventTraits::ResetType(WebInputEvent::TouchCancel, timeStampSeconds(), |
| 243 this); | 243 this); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void SyntheticWebTouchEvent::SetTimestamp(base::TimeTicks timestamp) { | 246 void SyntheticWebTouchEvent::SetTimestamp(base::TimeTicks timestamp) { |
| 247 setTimeStampSeconds(ui::EventTimeStampToSeconds(timestamp)); | 247 setTimeStampSeconds(ui::EventTimeStampToSeconds(timestamp)); |
| 248 } | 248 } |
| 249 | 249 |
| 250 int SyntheticWebTouchEvent::FirstFreeIndex() { | 250 int SyntheticWebTouchEvent::FirstFreeIndex() { |
| 251 for (size_t i = 0; i < kTouchesLengthCap; ++i) { | 251 for (size_t i = 0; i < kTouchesLengthCap; ++i) { |
| 252 if (touches[i].state == WebTouchPoint::StateUndefined) | 252 if (touches[i].state == WebTouchPoint::StateUndefined) |
| 253 return i; | 253 return i; |
| 254 } | 254 } |
| 255 return -1; | 255 return -1; |
| 256 } | 256 } |
| 257 | 257 |
| 258 } // namespace content | 258 } // namespace content |
| OLD | NEW |