Chromium Code Reviews| 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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 InputHostMsg_HandleInputEvent_ACK_Params ack; |
| 447 ack.type = type; | 447 ack.type = type; |
| 448 ack.state = ack_result; | 448 ack.state = ack_result; |
| 449 if (WebInputEvent::isTouchEventType(type)) | |
| 450 ack.unique_touch_event_id = last_send_event_id_; | |
| 449 InputHostMsg_HandleInputEvent_ACK response(0, ack); | 451 InputHostMsg_HandleInputEvent_ACK response(0, ack); |
| 450 widget_host_->OnMessageReceived(response); | 452 widget_host_->OnMessageReceived(response); |
| 451 } | 453 } |
| 452 | 454 |
| 453 size_t GetSentMessageCountAndResetSink() { | 455 size_t GetSentMessageCountAndResetSink() { |
| 454 size_t count = sink_->message_count(); | 456 size_t count = sink_->message_count(); |
| 455 sink_->ClearMessages(); | 457 sink_->ClearMessages(); |
| 456 return count; | 458 return count; |
| 457 } | 459 } |
| 458 | 460 |
| 459 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) { | 461 void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) { |
| 460 if (!sink_->message_count()) | 462 if (!sink_->message_count()) |
| 461 return; | 463 return; |
| 462 | 464 |
| 463 InputMsg_HandleInputEvent::Param params; | 465 InputMsg_HandleInputEvent::Param params; |
| 464 if (!InputMsg_HandleInputEvent::Read( | 466 if (!InputMsg_HandleInputEvent::Read( |
| 465 sink_->GetMessageAt(sink_->message_count() - 1), ¶ms)) { | 467 sink_->GetMessageAt(sink_->message_count() - 1), ¶ms)) { |
| 466 return; | 468 return; |
| 467 } | 469 } |
| 468 | 470 |
| 469 if (WebInputEventTraits::IgnoresAckDisposition(*get<0>(params))) | 471 if (!WebInputEventTraits::WillReceiveAckFromRenderer(*get<0>(params))) |
| 470 return; | 472 return; |
| 471 | 473 |
| 472 SendInputEventACK(get<0>(params)->type, ack_result); | 474 SendInputEventACK(get<0>(params)->type, ack_result); |
| 473 } | 475 } |
| 474 | 476 |
| 477 void SetLastSentEventID(uint32 event_id) { last_send_event_id_ = event_id; } | |
| 478 | |
| 475 protected: | 479 protected: |
| 476 // If true, then calls RWH::Shutdown() instead of deleting RWH. | 480 // If true, then calls RWH::Shutdown() instead of deleting RWH. |
| 477 bool widget_host_uses_shutdown_to_destroy_; | 481 bool widget_host_uses_shutdown_to_destroy_; |
| 478 | 482 |
| 479 bool is_guest_view_hack_; | 483 bool is_guest_view_hack_; |
| 480 | 484 |
| 481 base::MessageLoopForUI message_loop_; | 485 base::MessageLoopForUI message_loop_; |
| 482 BrowserThreadImpl browser_thread_for_ui_; | 486 BrowserThreadImpl browser_thread_for_ui_; |
| 483 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 487 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 484 scoped_ptr<BrowserContext> browser_context_; | 488 scoped_ptr<BrowserContext> browser_context_; |
| 485 MockRenderWidgetHostDelegate delegate_; | 489 MockRenderWidgetHostDelegate delegate_; |
| 486 MockRenderProcessHost* process_host_; | 490 MockRenderProcessHost* process_host_; |
| 487 | 491 |
| 488 // Tests should set these to NULL if they've already triggered their | 492 // Tests should set these to NULL if they've already triggered their |
| 489 // destruction. | 493 // destruction. |
| 490 RenderWidgetHostImpl* parent_host_; | 494 RenderWidgetHostImpl* parent_host_; |
| 491 RenderWidgetHostViewAura* parent_view_; | 495 RenderWidgetHostViewAura* parent_view_; |
| 492 | 496 |
| 493 // Tests should set these to NULL if they've already triggered their | 497 // Tests should set these to NULL if they've already triggered their |
| 494 // destruction. | 498 // destruction. |
| 495 RenderWidgetHostImpl* widget_host_; | 499 RenderWidgetHostImpl* widget_host_; |
| 496 FakeRenderWidgetHostViewAura* view_; | 500 FakeRenderWidgetHostViewAura* view_; |
| 497 | 501 |
| 498 IPC::TestSink* sink_; | 502 IPC::TestSink* sink_; |
| 499 | 503 |
| 504 uint32 last_send_event_id_; | |
|
jdduke (slow)
2015/05/01 19:11:09
Nit: last_sent
lanwei
2015/05/07 04:11:37
Done.
| |
| 505 | |
| 500 private: | 506 private: |
| 501 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); | 507 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); |
| 502 }; | 508 }; |
| 503 | 509 |
| 504 // Helper class to instantiate RenderWidgetHostViewGuest which is backed | 510 // Helper class to instantiate RenderWidgetHostViewGuest which is backed |
| 505 // by an aura platform view. | 511 // by an aura platform view. |
| 506 class RenderWidgetHostViewGuestAuraTest : public RenderWidgetHostViewAuraTest { | 512 class RenderWidgetHostViewGuestAuraTest : public RenderWidgetHostViewAuraTest { |
| 507 public: | 513 public: |
| 508 RenderWidgetHostViewGuestAuraTest() { | 514 RenderWidgetHostViewGuestAuraTest() { |
| 509 // Use RWH::Shutdown to destroy RWH, instead of deleting. | 515 // Use RWH::Shutdown to destroy RWH, instead of deleting. |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 return view_->overscroll_controller()->overscroll_delta_y_; | 698 return view_->overscroll_controller()->overscroll_delta_y_; |
| 693 } | 699 } |
| 694 | 700 |
| 695 TestOverscrollDelegate* overscroll_delegate() { | 701 TestOverscrollDelegate* overscroll_delegate() { |
| 696 return overscroll_delegate_.get(); | 702 return overscroll_delegate_.get(); |
| 697 } | 703 } |
| 698 | 704 |
| 699 void SendTouchEvent() { | 705 void SendTouchEvent() { |
| 700 widget_host_->ForwardTouchEventWithLatencyInfo(touch_event_, | 706 widget_host_->ForwardTouchEventWithLatencyInfo(touch_event_, |
| 701 ui::LatencyInfo()); | 707 ui::LatencyInfo()); |
| 708 last_send_event_id_ = touch_event_.uniqueTouchEventId; | |
|
jdduke (slow)
2015/05/01 19:11:09
Hmm, but what if touches are still in the queue? O
| |
| 702 touch_event_.ResetPoints(); | 709 touch_event_.ResetPoints(); |
| 703 } | 710 } |
| 704 | 711 |
| 705 void PressTouchPoint(int x, int y) { | 712 void PressTouchPoint(int x, int y) { |
| 706 touch_event_.PressPoint(x, y); | 713 touch_event_.PressPoint(x, y); |
| 707 SendTouchEvent(); | 714 SendTouchEvent(); |
| 708 } | 715 } |
| 709 | 716 |
| 710 void MoveTouchPoint(int index, int x, int y) { | 717 void MoveTouchPoint(int index, int x, int y) { |
| 711 touch_event_.MovePoint(index, x, y); | 718 touch_event_.MovePoint(index, x, y); |
| (...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3305 // lose track of the number of acks required. | 3312 // lose track of the number of acks required. |
| 3306 TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) { | 3313 TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) { |
| 3307 view_->InitAsFullscreen(parent_view_); | 3314 view_->InitAsFullscreen(parent_view_); |
| 3308 view_->Show(); | 3315 view_->Show(); |
| 3309 view_->UseFakeDispatcher(); | 3316 view_->UseFakeDispatcher(); |
| 3310 | 3317 |
| 3311 ui::TouchEvent press1( | 3318 ui::TouchEvent press1( |
| 3312 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0, ui::EventTimeForNow()); | 3319 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0, ui::EventTimeForNow()); |
| 3313 | 3320 |
| 3314 view_->OnTouchEvent(&press1); | 3321 view_->OnTouchEvent(&press1); |
| 3322 SetLastSentEventID(press1.unique_event_id()); | |
| 3315 SendInputEventACK(blink::WebInputEvent::TouchStart, | 3323 SendInputEventACK(blink::WebInputEvent::TouchStart, |
| 3316 INPUT_EVENT_ACK_STATE_CONSUMED); | 3324 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 3317 | 3325 |
| 3318 ui::TouchEvent press2( | 3326 ui::TouchEvent press2( |
| 3319 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow()); | 3327 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow()); |
| 3320 view_->OnTouchEvent(&press2); | 3328 view_->OnTouchEvent(&press2); |
| 3329 SetLastSentEventID(press2.unique_event_id()); | |
| 3321 SendInputEventACK(blink::WebInputEvent::TouchStart, | 3330 SendInputEventACK(blink::WebInputEvent::TouchStart, |
| 3322 INPUT_EVENT_ACK_STATE_CONSUMED); | 3331 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 3323 | 3332 |
| 3324 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count()); | 3333 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count()); |
| 3325 } | 3334 } |
| 3326 | 3335 |
| 3327 // Tests that the scroll deltas stored within the overscroll controller get | 3336 // 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 | 3337 // reset at the end of the overscroll gesture even if the overscroll threshold |
| 3329 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE. | 3338 // isn't surpassed and the overscroll mode stays OVERSCROLL_NONE. |
| 3330 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) { | 3339 TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3363 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 3372 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 3364 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); | 3373 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 3365 EXPECT_EQ(15.f, overscroll_delta_x()); | 3374 EXPECT_EQ(15.f, overscroll_delta_x()); |
| 3366 EXPECT_EQ(-5.f, overscroll_delta_y()); | 3375 EXPECT_EQ(-5.f, overscroll_delta_y()); |
| 3367 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad); | 3376 SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad); |
| 3368 EXPECT_EQ(0.f, overscroll_delta_x()); | 3377 EXPECT_EQ(0.f, overscroll_delta_x()); |
| 3369 EXPECT_EQ(0.f, overscroll_delta_y()); | 3378 EXPECT_EQ(0.f, overscroll_delta_y()); |
| 3370 } | 3379 } |
| 3371 | 3380 |
| 3372 } // namespace content | 3381 } // namespace content |
| OLD | NEW |