OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 // which uses ObserverListThreadSafe, which furthermore remembers the | 436 // which uses ObserverListThreadSafe, which furthermore remembers the |
437 // message loop for the thread it was created in. Between tests, the | 437 // message loop for the thread it was created in. Between tests, the |
438 // RendererFrameManager singleton survives and and the MessageLoop gets | 438 // RendererFrameManager singleton survives and and the MessageLoop gets |
439 // destroyed. The correct fix would be to have ObserverListThreadSafe look | 439 // destroyed. The correct fix would be to have ObserverListThreadSafe look |
440 // up the proper message loop every time (see crbug.com/443824.) | 440 // up the proper message loop every time (see crbug.com/443824.) |
441 RendererFrameManager::GetInstance()->OnMemoryPressure(level); | 441 RendererFrameManager::GetInstance()->OnMemoryPressure(level); |
442 } | 442 } |
443 | 443 |
444 void SendInputEventACK(WebInputEvent::Type type, | 444 void SendInputEventACK(WebInputEvent::Type type, |
445 InputEventAckState ack_result) { | 445 InputEventAckState ack_result) { |
446 InputHostMsg_HandleInputEvent_ACK_Params ack; | 446 DCHECK(!WebInputEvent::isTouchEventType(type)); |
447 ack.type = type; | 447 InputEventAck ack(type, ack_result); |
448 ack.state = ack_result; | |
449 InputHostMsg_HandleInputEvent_ACK response(0, ack); | 448 InputHostMsg_HandleInputEvent_ACK response(0, ack); |
450 widget_host_->OnMessageReceived(response); | 449 widget_host_->OnMessageReceived(response); |
451 } | 450 } |
| 451 |
| 452 void SendTouchEventACK(WebInputEvent::Type type, uint32 event_id, |
| 453 InputEventAckState ack_result) { |
| 454 DCHECK(WebInputEvent::isTouchEventType(type)); |
| 455 InputEventAck ack(type, ack_result); |
| 456 ack.unique_touch_event_id = event_id; |
| 457 InputHostMsg_HandleInputEvent_ACK response(0, ack); |
| 458 widget_host_->OnMessageReceived(response); |
| 459 } |
452 | 460 |
453 size_t GetSentMessageCountAndResetSink() { | 461 size_t GetSentMessageCountAndResetSink() { |
454 size_t count = sink_->message_count(); | 462 size_t count = sink_->message_count(); |
455 sink_->ClearMessages(); | 463 sink_->ClearMessages(); |
456 return count; | 464 return count; |
457 } | 465 } |
458 | 466 |
459 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) { | 467 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) { |
460 if (!sink_->message_count()) | 468 if (!sink_->message_count()) |
461 return; | 469 return; |
462 | 470 |
463 InputMsg_HandleInputEvent::Param params; | 471 InputMsg_HandleInputEvent::Param params; |
464 if (!InputMsg_HandleInputEvent::Read( | 472 if (!InputMsg_HandleInputEvent::Read( |
465 sink_->GetMessageAt(sink_->message_count() - 1), ¶ms)) { | 473 sink_->GetMessageAt(sink_->message_count() - 1), ¶ms)) { |
466 return; | 474 return; |
467 } | 475 } |
468 | 476 |
469 if (WebInputEventTraits::IgnoresAckDisposition(*get<0>(params))) | 477 if (!WebInputEventTraits::WillReceiveAckFromRenderer(*get<0>(params))) |
470 return; | 478 return; |
471 | 479 |
472 SendInputEventACK(get<0>(params)->type, ack_result); | 480 SendTouchEventACK(get<0>(params)->type, LastSentEventID(), ack_result); |
| 481 } |
| 482 |
| 483 uint32 LastSentEventID() { |
| 484 uint32 last_sent_event_id = 0; |
| 485 size_t count = sink_->message_count(); |
| 486 DCHECK_GT(count, 0U); |
| 487 for (size_t i = 0; i < count; ++i) { |
| 488 const WebInputEvent* input_event = |
| 489 GetInputEventFromMessage(*sink_->GetMessageAt(i)); |
| 490 last_sent_event_id = |
| 491 WebInputEventTraits::GetUniqueTouchEventId(*input_event); |
| 492 } |
| 493 return last_sent_event_id; |
473 } | 494 } |
474 | 495 |
475 protected: | 496 protected: |
476 // If true, then calls RWH::Shutdown() instead of deleting RWH. | 497 // If true, then calls RWH::Shutdown() instead of deleting RWH. |
477 bool widget_host_uses_shutdown_to_destroy_; | 498 bool widget_host_uses_shutdown_to_destroy_; |
478 | 499 |
479 bool is_guest_view_hack_; | 500 bool is_guest_view_hack_; |
480 | 501 |
481 base::MessageLoopForUI message_loop_; | 502 base::MessageLoopForUI message_loop_; |
482 BrowserThreadImpl browser_thread_for_ui_; | 503 BrowserThreadImpl browser_thread_for_ui_; |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 view_->OnTouchEvent(&press); | 1116 view_->OnTouchEvent(&press); |
1096 EXPECT_TRUE(press.synchronous_handling_disabled()); | 1117 EXPECT_TRUE(press.synchronous_handling_disabled()); |
1097 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type); | 1118 EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type); |
1098 EXPECT_EQ(1U, view_->touch_event_->touchesLength); | 1119 EXPECT_EQ(1U, view_->touch_event_->touchesLength); |
1099 EXPECT_EQ(blink::WebTouchPoint::StatePressed, | 1120 EXPECT_EQ(blink::WebTouchPoint::StatePressed, |
1100 view_->touch_event_->touches[0].state); | 1121 view_->touch_event_->touches[0].state); |
1101 | 1122 |
1102 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); | 1123 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); |
1103 | 1124 |
1104 // Ack'ing the outstanding event should flush the pending touch queue. | 1125 // Ack'ing the outstanding event should flush the pending touch queue. |
1105 InputHostMsg_HandleInputEvent_ACK_Params ack; | 1126 InputEventAck ack(blink::WebInputEvent::TouchStart, |
1106 ack.type = blink::WebInputEvent::TouchStart; | 1127 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
1107 ack.state = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 1128 ack.unique_touch_event_id = press.unique_event_id(); |
1108 widget_host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); | 1129 widget_host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); |
1109 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1130 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
1110 | 1131 |
1111 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0, | 1132 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0, |
1112 base::Time::NowFromSystemTime() - base::Time()); | 1133 base::Time::NowFromSystemTime() - base::Time()); |
1113 view_->OnTouchEvent(&move2); | 1134 view_->OnTouchEvent(&move2); |
1114 EXPECT_TRUE(press.synchronous_handling_disabled()); | 1135 EXPECT_TRUE(press.synchronous_handling_disabled()); |
1115 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type); | 1136 EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type); |
1116 EXPECT_EQ(1U, view_->touch_event_->touchesLength); | 1137 EXPECT_EQ(1U, view_->touch_event_->touchesLength); |
1117 EXPECT_EQ(blink::WebTouchPoint::StateMoved, | 1138 EXPECT_EQ(blink::WebTouchPoint::StateMoved, |
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2773 | 2794 |
2774 // Tests that when touch-events are dispatched to the renderer, the overscroll | 2795 // Tests that when touch-events are dispatched to the renderer, the overscroll |
2775 // gesture deals with them correctly. | 2796 // gesture deals with them correctly. |
2776 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) { | 2797 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) { |
2777 SetUpOverscrollEnvironmentWithDebounce(10); | 2798 SetUpOverscrollEnvironmentWithDebounce(10); |
2778 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 2799 widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
2779 sink_->ClearMessages(); | 2800 sink_->ClearMessages(); |
2780 | 2801 |
2781 // The test sends an intermingled sequence of touch and gesture events. | 2802 // The test sends an intermingled sequence of touch and gesture events. |
2782 PressTouchPoint(0, 1); | 2803 PressTouchPoint(0, 1); |
2783 SendInputEventACK(WebInputEvent::TouchStart, | 2804 SendTouchEventACK(WebInputEvent::TouchStart, LastSentEventID(), |
2784 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2805 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2785 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 2806 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
2786 | 2807 |
2787 MoveTouchPoint(0, 20, 5); | 2808 MoveTouchPoint(0, 20, 5); |
| 2809 SendTouchEventACK(WebInputEvent::TouchMove, LastSentEventID(), |
| 2810 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2788 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 2811 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
2789 SendInputEventACK(WebInputEvent::TouchMove, | |
2790 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
2791 | 2812 |
2792 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); | 2813 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
2793 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); | 2814 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
2794 | 2815 |
2795 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 2816 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
2796 blink::WebGestureDeviceTouchscreen); | 2817 blink::WebGestureDeviceTouchscreen); |
2797 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 2818 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
2798 SimulateGestureScrollUpdateEvent(20, 0, 0); | 2819 SimulateGestureScrollUpdateEvent(20, 0, 0); |
2799 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 2820 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
2800 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2821 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3305 // lose track of the number of acks required. | 3326 // lose track of the number of acks required. |
3306 TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) { | 3327 TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) { |
3307 view_->InitAsFullscreen(parent_view_); | 3328 view_->InitAsFullscreen(parent_view_); |
3308 view_->Show(); | 3329 view_->Show(); |
3309 view_->UseFakeDispatcher(); | 3330 view_->UseFakeDispatcher(); |
3310 | 3331 |
3311 ui::TouchEvent press1( | 3332 ui::TouchEvent press1( |
3312 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0, ui::EventTimeForNow()); | 3333 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0, ui::EventTimeForNow()); |
3313 | 3334 |
3314 view_->OnTouchEvent(&press1); | 3335 view_->OnTouchEvent(&press1); |
3315 SendInputEventACK(blink::WebInputEvent::TouchStart, | 3336 SendTouchEventACK(blink::WebInputEvent::TouchStart, press1.unique_event_id(), |
3316 INPUT_EVENT_ACK_STATE_CONSUMED); | 3337 INPUT_EVENT_ACK_STATE_CONSUMED); |
3317 | 3338 |
3318 ui::TouchEvent press2( | 3339 ui::TouchEvent press2( |
3319 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow()); | 3340 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow()); |
3320 view_->OnTouchEvent(&press2); | 3341 view_->OnTouchEvent(&press2); |
3321 SendInputEventACK(blink::WebInputEvent::TouchStart, | 3342 SendTouchEventACK(blink::WebInputEvent::TouchStart, press2.unique_event_id(), |
3322 INPUT_EVENT_ACK_STATE_CONSUMED); | 3343 INPUT_EVENT_ACK_STATE_CONSUMED); |
3323 | 3344 |
3324 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count()); | 3345 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count()); |
3325 } | 3346 } |
3326 | 3347 |
3327 // Tests that the scroll deltas stored within the overscroll controller get | 3348 // Tests that the scroll deltas stored within the overscroll controller get |
3328 // reset at the end of the overscroll gesture even if the overscroll threshold | 3349 // reset at the end of the overscroll gesture even if the overscroll threshold |
3329 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE. | 3350 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE. |
3330 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) { | 3351 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) { |
3331 SetUpOverscrollEnvironment(); | 3352 SetUpOverscrollEnvironment(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3363 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 3384 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
3364 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); | 3385 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
3365 EXPECT_EQ(15.f, overscroll_delta_x()); | 3386 EXPECT_EQ(15.f, overscroll_delta_x()); |
3366 EXPECT_EQ(-5.f, overscroll_delta_y()); | 3387 EXPECT_EQ(-5.f, overscroll_delta_y()); |
3367 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad); | 3388 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad); |
3368 EXPECT_EQ(0.f, overscroll_delta_x()); | 3389 EXPECT_EQ(0.f, overscroll_delta_x()); |
3369 EXPECT_EQ(0.f, overscroll_delta_y()); | 3390 EXPECT_EQ(0.f, overscroll_delta_y()); |
3370 } | 3391 } |
3371 | 3392 |
3372 } // namespace content | 3393 } // namespace content |
OLD | NEW |