| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
| 9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
| 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 anchor_.SetPoint(touch_event.touches[0].position.x, | 161 anchor_.SetPoint(touch_event.touches[0].position.x, |
| 162 touch_event.touches[0].position.y); | 162 touch_event.touches[0].position.y); |
| 163 started_ = true; | 163 started_ = true; |
| 164 } else { | 164 } else { |
| 165 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); | 165 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); |
| 166 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); | 166 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); |
| 167 // Ignore move events. | 167 // Ignore move events. |
| 168 | 168 |
| 169 if (touch_event.type == WebInputEvent::TouchEnd) | 169 if (touch_event.type == WebInputEvent::TouchEnd) |
| 170 scroll_distance_ = | 170 scroll_distance_ = |
| 171 anchor_ - gfx::PointF(touch_event.touches[0].position.x, | 171 anchor_ - gfx::PointF(touch_event.touches[0].position); |
| 172 touch_event.touches[0].position.y); | |
| 173 } | 172 } |
| 174 } | 173 } |
| 175 | 174 |
| 176 protected: | 175 protected: |
| 177 gfx::Point anchor_; | 176 gfx::Point anchor_; |
| 178 bool started_; | 177 bool started_; |
| 179 }; | 178 }; |
| 180 | 179 |
| 181 class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { | 180 class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { |
| 182 public: | 181 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 195 | 194 |
| 196 virtual void DispatchInputEventToPlatform( | 195 virtual void DispatchInputEventToPlatform( |
| 197 const WebInputEvent& event) OVERRIDE { | 196 const WebInputEvent& event) OVERRIDE { |
| 198 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); | 197 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
| 199 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); | 198 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
| 200 ASSERT_EQ(touch_event.touchesLength, 2U); | 199 ASSERT_EQ(touch_event.touchesLength, 2U); |
| 201 | 200 |
| 202 if (!started_) { | 201 if (!started_) { |
| 203 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); | 202 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); |
| 204 | 203 |
| 205 start_0_ = gfx::PointF(touch_event.touches[0].position.x, | 204 start_0_ = gfx::PointF(touch_event.touches[0].position); |
| 206 touch_event.touches[0].position.y); | 205 start_1_ = gfx::PointF(touch_event.touches[1].position); |
| 207 start_1_ = gfx::PointF(touch_event.touches[1].position.x, | |
| 208 touch_event.touches[1].position.y); | |
| 209 last_pointer_distance_ = (start_0_ - start_1_).Length(); | 206 last_pointer_distance_ = (start_0_ - start_1_).Length(); |
| 210 | 207 |
| 211 started_ = true; | 208 started_ = true; |
| 212 } else { | 209 } else { |
| 213 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); | 210 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); |
| 214 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); | 211 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); |
| 215 | 212 |
| 216 gfx::PointF current_0 = gfx::PointF(touch_event.touches[0].position.x, | 213 gfx::PointF current_0 = gfx::PointF(touch_event.touches[0].position); |
| 217 touch_event.touches[0].position.y); | 214 gfx::PointF current_1 = gfx::PointF(touch_event.touches[1].position); |
| 218 gfx::PointF current_1 = gfx::PointF(touch_event.touches[1].position.x, | |
| 219 touch_event.touches[1].position.y); | |
| 220 | 215 |
| 221 total_num_pixels_covered_ = | 216 total_num_pixels_covered_ = |
| 222 (current_0 - start_0_).Length() + (current_1 - start_1_).Length(); | 217 (current_0 - start_0_).Length() + (current_1 - start_1_).Length(); |
| 223 float pointer_distance = (current_0 - current_1).Length(); | 218 float pointer_distance = (current_0 - current_1).Length(); |
| 224 | 219 |
| 225 if (last_pointer_distance_ != pointer_distance) { | 220 if (last_pointer_distance_ != pointer_distance) { |
| 226 if (zoom_direction_ == ZOOM_DIRECTION_UNKNOWN) | 221 if (zoom_direction_ == ZOOM_DIRECTION_UNKNOWN) |
| 227 zoom_direction_ = | 222 zoom_direction_ = |
| 228 ComputeZoomDirection(last_pointer_distance_, pointer_distance); | 223 ComputeZoomDirection(last_pointer_distance_, pointer_distance); |
| 229 else | 224 else |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 gfx::PointF position() const { return position_; } | 259 gfx::PointF position() const { return position_; } |
| 265 base::TimeDelta GetDuration() const { return stop_time_ - start_time_; } | 260 base::TimeDelta GetDuration() const { return stop_time_ - start_time_; } |
| 266 | 261 |
| 267 protected: | 262 protected: |
| 268 enum GestureState { | 263 enum GestureState { |
| 269 NOT_STARTED, | 264 NOT_STARTED, |
| 270 STARTED, | 265 STARTED, |
| 271 FINISHED | 266 FINISHED |
| 272 }; | 267 }; |
| 273 | 268 |
| 274 // TODO(tdresser): clean up accesses to position_ once WebTouchPoint stores | |
| 275 // its location as a WebFloatPoint. See crbug.com/336807. | |
| 276 gfx::PointF position_; | 269 gfx::PointF position_; |
| 277 base::TimeDelta start_time_; | 270 base::TimeDelta start_time_; |
| 278 base::TimeDelta stop_time_; | 271 base::TimeDelta stop_time_; |
| 279 GestureState state_; | 272 GestureState state_; |
| 280 }; | 273 }; |
| 281 | 274 |
| 282 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget { | 275 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget { |
| 283 public: | 276 public: |
| 284 MockSyntheticTapTouchTarget() {} | 277 MockSyntheticTapTouchTarget() {} |
| 285 virtual ~MockSyntheticTapTouchTarget() {} | 278 virtual ~MockSyntheticTapTouchTarget() {} |
| 286 | 279 |
| 287 virtual void DispatchInputEventToPlatform( | 280 virtual void DispatchInputEventToPlatform( |
| 288 const WebInputEvent& event) OVERRIDE { | 281 const WebInputEvent& event) OVERRIDE { |
| 289 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); | 282 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
| 290 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); | 283 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
| 291 ASSERT_EQ(touch_event.touchesLength, 1U); | 284 ASSERT_EQ(touch_event.touchesLength, 1U); |
| 292 | 285 |
| 293 switch (state_) { | 286 switch (state_) { |
| 294 case NOT_STARTED: | 287 case NOT_STARTED: |
| 295 EXPECT_EQ(touch_event.type, WebInputEvent::TouchStart); | 288 EXPECT_EQ(touch_event.type, WebInputEvent::TouchStart); |
| 296 position_ = gfx::PointF(touch_event.touches[0].position.x, | 289 position_ = gfx::PointF(touch_event.touches[0].position); |
| 297 touch_event.touches[0].position.y); | |
| 298 start_time_ = base::TimeDelta::FromMilliseconds( | 290 start_time_ = base::TimeDelta::FromMilliseconds( |
| 299 static_cast<int64>(touch_event.timeStampSeconds * 1000)); | 291 static_cast<int64>(touch_event.timeStampSeconds * 1000)); |
| 300 state_ = STARTED; | 292 state_ = STARTED; |
| 301 break; | 293 break; |
| 302 case STARTED: | 294 case STARTED: |
| 303 EXPECT_EQ(touch_event.type, WebInputEvent::TouchEnd); | 295 EXPECT_EQ(touch_event.type, WebInputEvent::TouchEnd); |
| 304 EXPECT_EQ(position_, gfx::PointF(touch_event.touches[0].position.x, | 296 EXPECT_EQ(position_, gfx::PointF(touch_event.touches[0].position)); |
| 305 touch_event.touches[0].position.y)); | |
| 306 stop_time_ = base::TimeDelta::FromMilliseconds( | 297 stop_time_ = base::TimeDelta::FromMilliseconds( |
| 307 static_cast<int64>(touch_event.timeStampSeconds * 1000)); | 298 static_cast<int64>(touch_event.timeStampSeconds * 1000)); |
| 308 state_ = FINISHED; | 299 state_ = FINISHED; |
| 309 break; | 300 break; |
| 310 case FINISHED: | 301 case FINISHED: |
| 311 EXPECT_FALSE(true); | 302 EXPECT_FALSE(true); |
| 312 break; | 303 break; |
| 313 } | 304 } |
| 314 } | 305 } |
| 315 }; | 306 }; |
| 316 | 307 |
| 317 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget { | 308 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget { |
| 318 public: | 309 public: |
| 319 MockSyntheticTapMouseTarget() {} | 310 MockSyntheticTapMouseTarget() {} |
| 320 virtual ~MockSyntheticTapMouseTarget() {} | 311 virtual ~MockSyntheticTapMouseTarget() {} |
| 321 | 312 |
| 322 virtual void DispatchInputEventToPlatform( | 313 virtual void DispatchInputEventToPlatform( |
| 323 const WebInputEvent& event) OVERRIDE { | 314 const WebInputEvent& event) OVERRIDE { |
| 324 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); | 315 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); |
| 325 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | 316 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
| 326 | 317 |
| 327 switch (state_) { | 318 switch (state_) { |
| 328 case NOT_STARTED: | 319 case NOT_STARTED: |
| 329 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown); | 320 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown); |
| 330 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); | 321 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); |
| 331 EXPECT_EQ(mouse_event.clickCount, 1); | 322 EXPECT_EQ(mouse_event.clickCount, 1); |
| 332 position_ = gfx::Point(mouse_event.x, mouse_event.y); | 323 position_ = gfx::PointF(mouse_event.x, mouse_event.y); |
| 333 start_time_ = base::TimeDelta::FromMilliseconds( | 324 start_time_ = base::TimeDelta::FromMilliseconds( |
| 334 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); | 325 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); |
| 335 state_ = STARTED; | 326 state_ = STARTED; |
| 336 break; | 327 break; |
| 337 case STARTED: | 328 case STARTED: |
| 338 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseUp); | 329 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseUp); |
| 339 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); | 330 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); |
| 340 EXPECT_EQ(mouse_event.clickCount, 1); | 331 EXPECT_EQ(mouse_event.clickCount, 1); |
| 341 EXPECT_EQ(position_, gfx::Point(mouse_event.x, mouse_event.y)); | 332 EXPECT_EQ(position_, gfx::PointF(mouse_event.x, mouse_event.y)); |
| 342 stop_time_ = base::TimeDelta::FromMilliseconds( | 333 stop_time_ = base::TimeDelta::FromMilliseconds( |
| 343 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); | 334 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); |
| 344 state_ = FINISHED; | 335 state_ = FINISHED; |
| 345 break; | 336 break; |
| 346 case FINISHED: | 337 case FINISHED: |
| 347 EXPECT_FALSE(true); | 338 EXPECT_FALSE(true); |
| 348 break; | 339 break; |
| 349 } | 340 } |
| 350 } | 341 } |
| 351 }; | 342 }; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 EXPECT_TRUE(tap_target->GestureFinished()); | 819 EXPECT_TRUE(tap_target->GestureFinished()); |
| 829 EXPECT_EQ(tap_target->position(), params.position); | 820 EXPECT_EQ(tap_target->position(), params.position); |
| 830 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 821 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
| 831 EXPECT_GE(GetTotalTime(), | 822 EXPECT_GE(GetTotalTime(), |
| 832 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 823 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
| 833 } | 824 } |
| 834 | 825 |
| 835 } // namespace | 826 } // namespace |
| 836 | 827 |
| 837 } // namespace content | 828 } // namespace content |
| OLD | NEW |