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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "cc/output/compositor_frame.h" | 26 #include "cc/output/compositor_frame.h" |
27 #include "cc/output/compositor_frame_metadata.h" | 27 #include "cc/output/compositor_frame_metadata.h" |
28 #include "cc/output/copy_output_request.h" | 28 #include "cc/output/copy_output_request.h" |
29 #include "cc/surfaces/surface.h" | 29 #include "cc/surfaces/surface.h" |
30 #include "cc/surfaces/surface_manager.h" | 30 #include "cc/surfaces/surface_manager.h" |
31 #include "components/display_compositor/gl_helper.h" | 31 #include "components/display_compositor/gl_helper.h" |
32 #include "content/browser/browser_thread_impl.h" | 32 #include "content/browser/browser_thread_impl.h" |
33 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 33 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
34 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 34 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
35 #include "content/browser/gpu/compositor_util.h" | 35 #include "content/browser/gpu/compositor_util.h" |
| 36 #include "content/browser/renderer_host/delegated_frame_host.h" |
| 37 #include "content/browser/renderer_host/delegated_frame_host_client_aura.h" |
36 #include "content/browser/renderer_host/input/input_router.h" | 38 #include "content/browser/renderer_host/input/input_router.h" |
37 #include "content/browser/renderer_host/input/mouse_wheel_event_queue.h" | 39 #include "content/browser/renderer_host/input/mouse_wheel_event_queue.h" |
38 #include "content/browser/renderer_host/overscroll_controller.h" | 40 #include "content/browser/renderer_host/overscroll_controller.h" |
39 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 41 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
40 #include "content/browser/renderer_host/render_view_host_factory.h" | 42 #include "content/browser/renderer_host/render_view_host_factory.h" |
41 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 43 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
42 #include "content/browser/renderer_host/render_widget_host_impl.h" | 44 #include "content/browser/renderer_host/render_widget_host_impl.h" |
43 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h" | 45 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h" |
44 #include "content/browser/renderer_host/resize_lock.h" | 46 #include "content/browser/renderer_host/resize_lock.h" |
45 #include "content/browser/renderer_host/text_input_manager.h" | 47 #include "content/browser/renderer_host/text_input_manager.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 101 |
100 using blink::WebGestureEvent; | 102 using blink::WebGestureEvent; |
101 using blink::WebInputEvent; | 103 using blink::WebInputEvent; |
102 using blink::WebMouseEvent; | 104 using blink::WebMouseEvent; |
103 using blink::WebMouseWheelEvent; | 105 using blink::WebMouseWheelEvent; |
104 using blink::WebTouchEvent; | 106 using blink::WebTouchEvent; |
105 using blink::WebTouchPoint; | 107 using blink::WebTouchPoint; |
106 using ui::WebInputEventTraits; | 108 using ui::WebInputEventTraits; |
107 | 109 |
108 namespace content { | 110 namespace content { |
| 111 |
| 112 void InstallDelegatedFrameHostClient( |
| 113 RenderWidgetHostViewAura* render_widget_host_view, |
| 114 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client); |
| 115 |
109 namespace { | 116 namespace { |
110 | 117 |
111 class TestOverscrollDelegate : public OverscrollControllerDelegate { | 118 class TestOverscrollDelegate : public OverscrollControllerDelegate { |
112 public: | 119 public: |
113 explicit TestOverscrollDelegate(RenderWidgetHostView* view) | 120 explicit TestOverscrollDelegate(RenderWidgetHostView* view) |
114 : view_(view), | 121 : view_(view), |
115 current_mode_(OVERSCROLL_NONE), | 122 current_mode_(OVERSCROLL_NONE), |
116 completed_mode_(OVERSCROLL_NONE), | 123 completed_mode_(OVERSCROLL_NONE), |
117 delta_x_(0.f), | 124 delta_x_(0.f), |
118 delta_y_(0.f) {} | 125 delta_y_(0.f) {} |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 size_t GetAndResetProcessedTouchEventCount() { | 323 size_t GetAndResetProcessedTouchEventCount() { |
317 size_t count = processed_touch_event_count_; | 324 size_t count = processed_touch_event_count_; |
318 processed_touch_event_count_ = 0; | 325 processed_touch_event_count_ = 0; |
319 return count; | 326 return count; |
320 } | 327 } |
321 | 328 |
322 private: | 329 private: |
323 size_t processed_touch_event_count_; | 330 size_t processed_touch_event_count_; |
324 }; | 331 }; |
325 | 332 |
| 333 class FakeDelegatedFrameHostClientAura : public DelegatedFrameHostClientAura { |
| 334 public: |
| 335 explicit FakeDelegatedFrameHostClientAura( |
| 336 RenderWidgetHostViewAura* render_widget_host_view) |
| 337 : DelegatedFrameHostClientAura(render_widget_host_view) {} |
| 338 ~FakeDelegatedFrameHostClientAura() override {} |
| 339 |
| 340 void DisableResizeLock() { can_create_resize_lock_ = false; } |
| 341 |
| 342 private: |
| 343 // A lock that doesn't actually do anything to the compositor, and does not |
| 344 // time out. |
| 345 class FakeResizeLock : public ResizeLock { |
| 346 public: |
| 347 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) |
| 348 : ResizeLock(new_size, defer_compositor_lock) {} |
| 349 }; |
| 350 |
| 351 // DelegatedFrameHostClientAura: |
| 352 std::unique_ptr<ResizeLock> DelegatedFrameHostCreateResizeLock( |
| 353 bool defer_compositor_lock) override { |
| 354 gfx::Size desired_size = |
| 355 render_widget_host_view()->GetNativeView()->bounds().size(); |
| 356 return std::unique_ptr<ResizeLock>( |
| 357 new FakeResizeLock(desired_size, defer_compositor_lock)); |
| 358 } |
| 359 bool DelegatedFrameCanCreateResizeLock() const override { |
| 360 return can_create_resize_lock_; |
| 361 } |
| 362 |
| 363 bool can_create_resize_lock_ = true; |
| 364 |
| 365 DISALLOW_COPY_AND_ASSIGN(FakeDelegatedFrameHostClientAura); |
| 366 }; |
| 367 |
326 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { | 368 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { |
327 public: | 369 public: |
328 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget, | 370 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget, |
329 bool is_guest_view_hack) | 371 bool is_guest_view_hack) |
330 : RenderWidgetHostViewAura(widget, is_guest_view_hack), | 372 : RenderWidgetHostViewAura(widget, is_guest_view_hack), |
331 can_create_resize_lock_(true) {} | 373 delegated_frame_host_client_( |
| 374 new FakeDelegatedFrameHostClientAura(this)) { |
| 375 std::unique_ptr<DelegatedFrameHostClient> client( |
| 376 delegated_frame_host_client_); |
| 377 InstallDelegatedFrameHostClient(this, std::move(client)); |
| 378 } |
| 379 |
| 380 ~FakeRenderWidgetHostViewAura() override {} |
| 381 |
| 382 void DisableResizeLock() { |
| 383 delegated_frame_host_client_->DisableResizeLock(); |
| 384 } |
332 | 385 |
333 void UseFakeDispatcher() { | 386 void UseFakeDispatcher() { |
334 dispatcher_ = new FakeWindowEventDispatcher(window()->GetHost()); | 387 dispatcher_ = new FakeWindowEventDispatcher(window()->GetHost()); |
335 std::unique_ptr<aura::WindowEventDispatcher> dispatcher(dispatcher_); | 388 std::unique_ptr<aura::WindowEventDispatcher> dispatcher(dispatcher_); |
336 aura::test::SetHostDispatcher(window()->GetHost(), std::move(dispatcher)); | 389 aura::test::SetHostDispatcher(window()->GetHost(), std::move(dispatcher)); |
337 } | 390 } |
338 | 391 |
339 ~FakeRenderWidgetHostViewAura() override {} | |
340 | |
341 std::unique_ptr<ResizeLock> DelegatedFrameHostCreateResizeLock( | |
342 bool defer_compositor_lock) override { | |
343 gfx::Size desired_size = window()->bounds().size(); | |
344 return std::unique_ptr<ResizeLock>( | |
345 new FakeResizeLock(desired_size, defer_compositor_lock)); | |
346 } | |
347 | |
348 bool DelegatedFrameCanCreateResizeLock() const override { | |
349 return can_create_resize_lock_; | |
350 } | |
351 | |
352 void RunOnCompositingDidCommit() { | 392 void RunOnCompositingDidCommit() { |
353 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting( | 393 GetDelegatedFrameHost()->OnCompositingDidCommitForTesting( |
354 window()->GetHost()->compositor()); | 394 window()->GetHost()->compositor()); |
355 } | 395 } |
356 | 396 |
357 void InterceptCopyOfOutput(std::unique_ptr<cc::CopyOutputRequest> request) { | 397 void InterceptCopyOfOutput(std::unique_ptr<cc::CopyOutputRequest> request) { |
358 last_copy_request_ = std::move(request); | 398 last_copy_request_ = std::move(request); |
359 if (last_copy_request_->has_texture_mailbox()) { | 399 if (last_copy_request_->has_texture_mailbox()) { |
360 // Give the resulting texture a size. | 400 // Give the resulting texture a size. |
361 display_compositor::GLHelper* gl_helper = | 401 display_compositor::GLHelper* gl_helper = |
(...skipping 19 matching lines...) Expand all Loading... |
381 bool released_front_lock_active() const { | 421 bool released_front_lock_active() const { |
382 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting(); | 422 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting(); |
383 } | 423 } |
384 | 424 |
385 void ReturnResources(const cc::ReturnedResourceArray& resources) { | 425 void ReturnResources(const cc::ReturnedResourceArray& resources) { |
386 GetDelegatedFrameHost()->ReturnResources(resources); | 426 GetDelegatedFrameHost()->ReturnResources(resources); |
387 } | 427 } |
388 | 428 |
389 void ResetCompositor() { GetDelegatedFrameHost()->ResetCompositor(); } | 429 void ResetCompositor() { GetDelegatedFrameHost()->ResetCompositor(); } |
390 | 430 |
391 // A lock that doesn't actually do anything to the compositor, and does not | |
392 // time out. | |
393 class FakeResizeLock : public ResizeLock { | |
394 public: | |
395 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) | |
396 : ResizeLock(new_size, defer_compositor_lock) {} | |
397 }; | |
398 | |
399 const ui::MotionEventAura& pointer_state_for_test() { | 431 const ui::MotionEventAura& pointer_state_for_test() { |
400 return event_handler()->pointer_state(); | 432 return event_handler()->pointer_state(); |
401 } | 433 } |
402 | 434 |
403 bool can_create_resize_lock_; | |
404 gfx::Size last_frame_size_; | 435 gfx::Size last_frame_size_; |
405 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_; | 436 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_; |
406 FakeWindowEventDispatcher* dispatcher_; | 437 FakeWindowEventDispatcher* dispatcher_; |
| 438 |
| 439 private: |
| 440 FakeDelegatedFrameHostClientAura* delegated_frame_host_client_; |
| 441 |
| 442 DISALLOW_COPY_AND_ASSIGN(FakeRenderWidgetHostViewAura); |
407 }; | 443 }; |
408 | 444 |
409 // A layout manager that always resizes a child to the root window size. | 445 // A layout manager that always resizes a child to the root window size. |
410 class FullscreenLayoutManager : public aura::LayoutManager { | 446 class FullscreenLayoutManager : public aura::LayoutManager { |
411 public: | 447 public: |
412 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {} | 448 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {} |
413 ~FullscreenLayoutManager() override {} | 449 ~FullscreenLayoutManager() override {} |
414 | 450 |
415 // Overridden from aura::LayoutManager: | 451 // Overridden from aura::LayoutManager: |
416 void OnWindowResized() override { | 452 void OnWindowResized() override { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 520 } |
485 | 521 |
486 } // namespace | 522 } // namespace |
487 | 523 |
488 class RenderWidgetHostViewAuraTest : public testing::Test { | 524 class RenderWidgetHostViewAuraTest : public testing::Test { |
489 public: | 525 public: |
490 RenderWidgetHostViewAuraTest() | 526 RenderWidgetHostViewAuraTest() |
491 : widget_host_uses_shutdown_to_destroy_(false), | 527 : widget_host_uses_shutdown_to_destroy_(false), |
492 is_guest_view_hack_(false) {} | 528 is_guest_view_hack_(false) {} |
493 | 529 |
| 530 static void InstallDelegatedFrameHostClient( |
| 531 RenderWidgetHostViewAura* render_widget_host_view, |
| 532 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client) { |
| 533 render_widget_host_view->delegated_frame_host_client_ = |
| 534 std::move(delegated_frame_host_client); |
| 535 } |
| 536 |
494 void SetUpEnvironment() { | 537 void SetUpEnvironment() { |
495 ImageTransportFactory::InitializeForUnitTests( | 538 ImageTransportFactory::InitializeForUnitTests( |
496 std::unique_ptr<ImageTransportFactory>( | 539 std::unique_ptr<ImageTransportFactory>( |
497 new NoTransportImageTransportFactory)); | 540 new NoTransportImageTransportFactory)); |
498 aura_test_helper_.reset( | 541 aura_test_helper_.reset( |
499 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); | 542 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
500 aura_test_helper_->SetUp( | 543 aura_test_helper_->SetUp( |
501 ImageTransportFactory::GetInstance()->GetContextFactory(), | 544 ImageTransportFactory::GetInstance()->GetContextFactory(), |
502 ImageTransportFactory::GetInstance()->GetContextFactoryPrivate()); | 545 ImageTransportFactory::GetInstance()->GetContextFactoryPrivate()); |
503 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 546 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 // destruction. | 726 // destruction. |
684 MockRenderWidgetHostImpl* widget_host_; | 727 MockRenderWidgetHostImpl* widget_host_; |
685 FakeRenderWidgetHostViewAura* view_; | 728 FakeRenderWidgetHostViewAura* view_; |
686 | 729 |
687 IPC::TestSink* sink_; | 730 IPC::TestSink* sink_; |
688 | 731 |
689 private: | 732 private: |
690 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); | 733 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); |
691 }; | 734 }; |
692 | 735 |
| 736 void InstallDelegatedFrameHostClient( |
| 737 RenderWidgetHostViewAura* render_widget_host_view, |
| 738 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client) { |
| 739 RenderWidgetHostViewAuraTest::InstallDelegatedFrameHostClient( |
| 740 render_widget_host_view, std::move(delegated_frame_host_client)); |
| 741 } |
| 742 |
693 // Helper class to instantiate RenderWidgetHostViewGuest which is backed | 743 // Helper class to instantiate RenderWidgetHostViewGuest which is backed |
694 // by an aura platform view. | 744 // by an aura platform view. |
695 class RenderWidgetHostViewGuestAuraTest : public RenderWidgetHostViewAuraTest { | 745 class RenderWidgetHostViewGuestAuraTest : public RenderWidgetHostViewAuraTest { |
696 public: | 746 public: |
697 RenderWidgetHostViewGuestAuraTest() { | 747 RenderWidgetHostViewGuestAuraTest() { |
698 // Use RWH::Shutdown to destroy RWH, instead of deleting. | 748 // Use RWH::Shutdown to destroy RWH, instead of deleting. |
699 // This will ensure that the RenderWidgetHostViewGuest is not leaked and | 749 // This will ensure that the RenderWidgetHostViewGuest is not leaked and |
700 // is deleted properly upon RWH going away. | 750 // is deleted properly upon RWH going away. |
701 set_widget_host_uses_shutdown_to_destroy(true); | 751 set_widget_host_uses_shutdown_to_destroy(true); |
702 } | 752 } |
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1935 } | 1985 } |
1936 | 1986 |
1937 // If the view size is larger than the compositor frame then extra layers | 1987 // If the view size is larger than the compositor frame then extra layers |
1938 // should be created to fill the gap. | 1988 // should be created to fill the gap. |
1939 TEST_F(RenderWidgetHostViewAuraTest, DelegatedFrameGutter) { | 1989 TEST_F(RenderWidgetHostViewAuraTest, DelegatedFrameGutter) { |
1940 gfx::Size large_size(100, 100); | 1990 gfx::Size large_size(100, 100); |
1941 gfx::Size small_size(40, 45); | 1991 gfx::Size small_size(40, 45); |
1942 gfx::Size medium_size(40, 95); | 1992 gfx::Size medium_size(40, 95); |
1943 | 1993 |
1944 // Prevent the DelegatedFrameHost from skipping frames. | 1994 // Prevent the DelegatedFrameHost from skipping frames. |
1945 view_->can_create_resize_lock_ = false; | 1995 // XXX |
| 1996 view_->DisableResizeLock(); |
1946 | 1997 |
1947 view_->InitAsChild(nullptr); | 1998 view_->InitAsChild(nullptr); |
1948 aura::client::ParentWindowWithContext( | 1999 aura::client::ParentWindowWithContext( |
1949 view_->GetNativeView(), parent_view_->GetNativeView()->GetRootWindow(), | 2000 view_->GetNativeView(), parent_view_->GetNativeView()->GetRootWindow(), |
1950 gfx::Rect()); | 2001 gfx::Rect()); |
1951 view_->SetSize(large_size); | 2002 view_->SetSize(large_size); |
1952 view_->Show(); | 2003 view_->Show(); |
1953 cc::CompositorFrame frame = | 2004 cc::CompositorFrame frame = |
1954 MakeDelegatedFrame(1.f, small_size, gfx::Rect(small_size)); | 2005 MakeDelegatedFrame(1.f, small_size, gfx::Rect(small_size)); |
1955 frame.metadata.root_background_color = SK_ColorRED; | 2006 frame.metadata.root_background_color = SK_ColorRED; |
(...skipping 2721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4677 | 4728 |
4678 // Retrieve the selected text from clipboard and verify it is as expected. | 4729 // Retrieve the selected text from clipboard and verify it is as expected. |
4679 base::string16 result_text; | 4730 base::string16 result_text; |
4680 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); | 4731 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); |
4681 EXPECT_EQ(expected_text, result_text); | 4732 EXPECT_EQ(expected_text, result_text); |
4682 } | 4733 } |
4683 } | 4734 } |
4684 #endif | 4735 #endif |
4685 | 4736 |
4686 } // namespace content | 4737 } // namespace content |
OLD | NEW |