| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "content/browser/renderer_host/input/input_ack_handler.h" | 7 #include "content/browser/renderer_host/input/input_ack_handler.h" |
| 8 #include "content/browser/renderer_host/input/input_router_client.h" | 8 #include "content/browser/renderer_host/input/input_router_client.h" |
| 9 #include "content/browser/renderer_host/input/input_router_impl.h" | 9 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 10 #include "content/common/input/web_input_event_traits.h" | 10 #include "content/common/input/web_input_event_traits.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 bool HasMessages() const { return sent_count_ > 0; } | 102 bool HasMessages() const { return sent_count_ > 0; } |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 size_t sent_count_; | 105 size_t sent_count_; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 // TODO(jdduke): Use synthetic gesture pipeline, crbug.com/344598. | 108 // TODO(jdduke): Use synthetic gesture pipeline, crbug.com/344598. |
| 109 typedef std::vector<WebGestureEvent> Gestures; | 109 typedef std::vector<WebGestureEvent> Gestures; |
| 110 Gestures BuildScrollSequence(size_t steps, | 110 Gestures BuildScrollSequence(size_t steps, |
| 111 gfx::Vector2dF origin, | 111 const gfx::Vector2dF& origin, |
| 112 gfx::Vector2dF distance) { | 112 const gfx::Vector2dF& distance) { |
| 113 Gestures gestures; | 113 Gestures gestures; |
| 114 const gfx::Vector2dF delta = ScaleVector2d(distance, 1.f / steps); | 114 const gfx::Vector2dF delta = ScaleVector2d(distance, 1.f / steps); |
| 115 | 115 |
| 116 WebGestureEvent gesture; | 116 WebGestureEvent gesture; |
| 117 gesture.type = WebInputEvent::GestureScrollBegin; | 117 gesture.type = WebInputEvent::GestureScrollBegin; |
| 118 gesture.x = origin.x(); | 118 gesture.x = origin.x(); |
| 119 gesture.y = origin.y(); | 119 gesture.y = origin.y(); |
| 120 gestures.push_back(gesture); | 120 gestures.push_back(gesture); |
| 121 | 121 |
| 122 gesture.type = WebInputEvent::GestureScrollUpdate; | 122 gesture.type = WebInputEvent::GestureScrollUpdate; |
| 123 gesture.data.scrollUpdate.deltaX = delta.x(); | 123 gesture.data.scrollUpdate.deltaX = delta.x(); |
| 124 gesture.data.scrollUpdate.deltaY = delta.y(); | 124 gesture.data.scrollUpdate.deltaY = delta.y(); |
| 125 for (size_t i = 0; i < steps; ++i) { | 125 for (size_t i = 0; i < steps; ++i) { |
| 126 gesture.x += delta.x(); | 126 gesture.x += delta.x(); |
| 127 gesture.y += delta.y(); | 127 gesture.y += delta.y(); |
| 128 gestures.push_back(gesture); | 128 gestures.push_back(gesture); |
| 129 } | 129 } |
| 130 | 130 |
| 131 gesture.type = WebInputEvent::GestureScrollEnd; | 131 gesture.type = WebInputEvent::GestureScrollEnd; |
| 132 gestures.push_back(gesture); | 132 gestures.push_back(gesture); |
| 133 return gestures; | 133 return gestures; |
| 134 } | 134 } |
| 135 | 135 |
| 136 typedef std::vector<WebTouchEvent> Touches; | 136 typedef std::vector<WebTouchEvent> Touches; |
| 137 Touches BuildTouchSequence(size_t steps, | 137 Touches BuildTouchSequence(size_t steps, |
| 138 gfx::Vector2dF origin, | 138 const gfx::Vector2dF& origin, |
| 139 gfx::Vector2dF distance) { | 139 const gfx::Vector2dF& distance) { |
| 140 Touches touches; | 140 Touches touches; |
| 141 const gfx::Vector2dF delta = ScaleVector2d(distance, 1.f / steps); | 141 const gfx::Vector2dF delta = ScaleVector2d(distance, 1.f / steps); |
| 142 | 142 |
| 143 WebTouchEvent touch; | 143 WebTouchEvent touch; |
| 144 touch.touchesLength = 1; | 144 touch.touchesLength = 1; |
| 145 touch.type = WebInputEvent::TouchStart; | 145 touch.type = WebInputEvent::TouchStart; |
| 146 touch.touches[0].id = 0; | 146 touch.touches[0].id = 0; |
| 147 touch.touches[0].state = WebTouchPoint::StatePressed; | 147 touch.touches[0].state = WebTouchPoint::StatePressed; |
| 148 touch.touches[0].position.x = origin.x(); | 148 touch.touches[0].position.x = origin.x(); |
| 149 touch.touches[0].position.y = origin.y(); | 149 touch.touches[0].position.y = origin.y(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 if (ack_delay) | 291 if (ack_delay) |
| 292 SendEventAckIfNecessary(events.back(), INPUT_EVENT_ACK_STATE_CONSUMED); | 292 SendEventAckIfNecessary(events.back(), INPUT_EVENT_ACK_STATE_CONSUMED); |
| 293 | 293 |
| 294 EXPECT_EQ(event_count, GetAndResetSentEventCount()); | 294 EXPECT_EQ(event_count, GetAndResetSentEventCount()); |
| 295 EXPECT_EQ(event_count, GetAndResetAckCount()); | 295 EXPECT_EQ(event_count, GetAndResetAckCount()); |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 | 298 |
| 299 void SimulateTouchAndScrollEventSequence(const char* test_name, | 299 void SimulateTouchAndScrollEventSequence(const char* test_name, |
| 300 size_t steps, | 300 size_t steps, |
| 301 gfx::Vector2dF origin, | 301 const gfx::Vector2dF& origin, |
| 302 gfx::Vector2dF distance, | 302 const gfx::Vector2dF& distance, |
| 303 size_t iterations) { | 303 size_t iterations) { |
| 304 OnHasTouchEventHandlers(true); | 304 OnHasTouchEventHandlers(true); |
| 305 | 305 |
| 306 Gestures gestures = BuildScrollSequence(steps, origin, distance); | 306 Gestures gestures = BuildScrollSequence(steps, origin, distance); |
| 307 Touches touches = BuildTouchSequence(steps, origin, distance); | 307 Touches touches = BuildTouchSequence(steps, origin, distance); |
| 308 ASSERT_EQ(touches.size(), gestures.size()); | 308 ASSERT_EQ(touches.size(), gestures.size()); |
| 309 | 309 |
| 310 const size_t event_count = gestures.size(); | 310 const size_t event_count = gestures.size(); |
| 311 const size_t total_event_count = event_count * iterations * 2; | 311 const size_t total_event_count = event_count * iterations * 2; |
| 312 | 312 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 376 |
| 377 TEST_F(InputRouterImplPerfTest, TouchSwipeToGestureScroll) { | 377 TEST_F(InputRouterImplPerfTest, TouchSwipeToGestureScroll) { |
| 378 SimulateTouchAndScrollEventSequence("TouchSwipeToGestureScroll ", | 378 SimulateTouchAndScrollEventSequence("TouchSwipeToGestureScroll ", |
| 379 kDefaultSteps, | 379 kDefaultSteps, |
| 380 kDefaultOrigin, | 380 kDefaultOrigin, |
| 381 kDefaultDistance, | 381 kDefaultDistance, |
| 382 kDefaultIterations); | 382 kDefaultIterations); |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace content | 385 } // namespace content |
| OLD | NEW |