| 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 "content/browser/frame_host/render_widget_host_view_child_frame.h" | 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "cc/output/copy_output_request.h" | 16 #include "cc/output/copy_output_request.h" |
| 17 #include "cc/output/copy_output_result.h" | 17 #include "cc/output/copy_output_result.h" |
| 18 #include "cc/surfaces/compositor_frame_sink_support.h" | 18 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 19 #include "cc/surfaces/surface.h" | 19 #include "cc/surfaces/surface.h" |
| 20 #include "cc/surfaces/surface_manager.h" | 20 #include "cc/surfaces/surface_manager.h" |
| 21 #include "content/browser/accessibility/browser_accessibility_manager.h" | 21 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 22 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 22 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 23 #include "content/browser/compositor/surface_utils.h" | 23 #include "content/browser/compositor/surface_utils.h" |
| 24 #include "content/browser/frame_host/cross_process_frame_connector.h" | 24 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 25 #include "content/browser/frame_host/touch_selection_controller_client_child_fra
me.h" |
| 25 #include "content/browser/gpu/compositor_util.h" | 26 #include "content/browser/gpu/compositor_util.h" |
| 26 #include "content/browser/renderer_host/render_view_host_impl.h" | 27 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 27 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 28 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 28 #include "content/browser/renderer_host/render_widget_host_impl.h" | 29 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 29 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 30 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| 31 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h" |
| 32 #include "content/browser/renderer_host/text_input_manager.h" |
| 30 #include "content/common/text_input_state.h" | 33 #include "content/common/text_input_state.h" |
| 31 #include "content/common/view_messages.h" | 34 #include "content/common/view_messages.h" |
| 32 #include "content/public/browser/guest_mode.h" | 35 #include "content/public/browser/guest_mode.h" |
| 33 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 34 #include "gpu/ipc/common/gpu_messages.h" | 37 #include "gpu/ipc/common/gpu_messages.h" |
| 35 #include "third_party/WebKit/public/platform/WebTouchEvent.h" | 38 #include "third_party/WebKit/public/platform/WebTouchEvent.h" |
| 36 #include "ui/gfx/geometry/size_conversions.h" | 39 #include "ui/gfx/geometry/size_conversions.h" |
| 37 #include "ui/gfx/geometry/size_f.h" | 40 #include "ui/gfx/geometry/size_f.h" |
| 41 #include "ui/touch_selection/touch_selection_controller.h" |
| 38 | 42 |
| 39 namespace content { | 43 namespace content { |
| 40 | 44 |
| 41 // static | 45 // static |
| 42 RenderWidgetHostViewChildFrame* RenderWidgetHostViewChildFrame::Create( | 46 RenderWidgetHostViewChildFrame* RenderWidgetHostViewChildFrame::Create( |
| 43 RenderWidgetHost* widget) { | 47 RenderWidgetHost* widget) { |
| 44 RenderWidgetHostViewChildFrame* view = | 48 RenderWidgetHostViewChildFrame* view = |
| 45 new RenderWidgetHostViewChildFrame(widget); | 49 new RenderWidgetHostViewChildFrame(widget); |
| 46 view->Init(); | 50 view->Init(); |
| 47 return view; | 51 return view; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 67 if (GetSurfaceManager()) | 71 if (GetSurfaceManager()) |
| 68 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); | 72 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); |
| 69 } | 73 } |
| 70 | 74 |
| 71 void RenderWidgetHostViewChildFrame::Init() { | 75 void RenderWidgetHostViewChildFrame::Init() { |
| 72 RegisterFrameSinkId(); | 76 RegisterFrameSinkId(); |
| 73 host_->SetView(this); | 77 host_->SetView(this); |
| 74 GetTextInputManager(); | 78 GetTextInputManager(); |
| 75 } | 79 } |
| 76 | 80 |
| 81 void RenderWidgetHostViewChildFrame:: |
| 82 DetachFromTouchSelectionClientManagerIfNecessary() { |
| 83 if (!selection_controller_client_) |
| 84 return; |
| 85 |
| 86 auto* root_view = frame_connector_->GetRootRenderWidgetHostView(); |
| 87 if (root_view) { |
| 88 auto* manager = root_view->touch_selection_controller_client_manager(); |
| 89 if (manager) |
| 90 manager->RemoveObserver(this); |
| 91 } |
| 92 |
| 93 selection_controller_client_.reset(); |
| 94 } |
| 95 |
| 77 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( | 96 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( |
| 78 CrossProcessFrameConnector* frame_connector) { | 97 CrossProcessFrameConnector* frame_connector) { |
| 79 if (frame_connector_ == frame_connector) | 98 if (frame_connector_ == frame_connector) |
| 80 return; | 99 return; |
| 81 | 100 |
| 82 if (frame_connector_) { | 101 if (frame_connector_) { |
| 83 if (parent_frame_sink_id_.is_valid()) { | 102 if (parent_frame_sink_id_.is_valid()) { |
| 84 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, | 103 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, |
| 85 frame_sink_id_); | 104 frame_sink_id_); |
| 86 } | 105 } |
| 87 parent_frame_sink_id_ = cc::FrameSinkId(); | 106 parent_frame_sink_id_ = cc::FrameSinkId(); |
| 88 local_surface_id_ = cc::LocalSurfaceId(); | 107 local_surface_id_ = cc::LocalSurfaceId(); |
| 89 | 108 |
| 90 // Unlocks the mouse if this RenderWidgetHostView holds the lock. | 109 // Unlocks the mouse if this RenderWidgetHostView holds the lock. |
| 91 UnlockMouse(); | 110 UnlockMouse(); |
| 111 DetachFromTouchSelectionClientManagerIfNecessary(); |
| 92 } | 112 } |
| 93 frame_connector_ = frame_connector; | 113 frame_connector_ = frame_connector; |
| 94 if (frame_connector_) { | 114 if (frame_connector_) { |
| 95 RenderWidgetHostViewBase* parent_view = | 115 RenderWidgetHostViewBase* parent_view = |
| 96 frame_connector_->GetParentRenderWidgetHostView(); | 116 frame_connector_->GetParentRenderWidgetHostView(); |
| 97 if (parent_view) { | 117 if (parent_view) { |
| 98 parent_frame_sink_id_ = parent_view->GetFrameSinkId(); | 118 parent_frame_sink_id_ = parent_view->GetFrameSinkId(); |
| 99 DCHECK(parent_frame_sink_id_.is_valid()); | 119 DCHECK(parent_frame_sink_id_.is_valid()); |
| 100 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, | 120 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, |
| 101 frame_sink_id_); | 121 frame_sink_id_); |
| 102 } | 122 } |
| 123 |
| 124 auto* root_view = frame_connector_->GetRootRenderWidgetHostView(); |
| 125 if (root_view) { |
| 126 // Make sure we're not using the zero-valued default for |
| 127 // current_device_scale_factor_. |
| 128 current_device_scale_factor_ = root_view->current_device_scale_factor(); |
| 129 if (current_device_scale_factor_ == 0.f) |
| 130 current_device_scale_factor_ = 1.f; |
| 131 |
| 132 auto* manager = root_view->touch_selection_controller_client_manager(); |
| 133 if (manager) { |
| 134 // We will only have a manager on Aura (and eventually Android). |
| 135 // TODO(wjmaclean): update this comment when TSE OOPIF support becomes |
| 136 // available on Android. |
| 137 selection_controller_client_ = |
| 138 base::MakeUnique<TouchSelectionControllerClientChildFrame>(this, |
| 139 manager); |
| 140 manager->AddObserver(this); |
| 141 } |
| 142 } |
| 103 } | 143 } |
| 104 } | 144 } |
| 105 | 145 |
| 146 void RenderWidgetHostViewChildFrame::OnManagerWillDestroy( |
| 147 TouchSelectionControllerClientManager* manager) { |
| 148 // We get the manager via the observer callback instead of through the |
| 149 // frame_connector_ since our connection to the root_view may disappear by |
| 150 // the time this function is called, but before frame_connector_ is reset. |
| 151 manager->RemoveObserver(this); |
| 152 selection_controller_client_.reset(); |
| 153 } |
| 154 |
| 106 void RenderWidgetHostViewChildFrame::InitAsChild( | 155 void RenderWidgetHostViewChildFrame::InitAsChild( |
| 107 gfx::NativeView parent_view) { | 156 gfx::NativeView parent_view) { |
| 108 NOTREACHED(); | 157 NOTREACHED(); |
| 109 } | 158 } |
| 110 | 159 |
| 111 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const { | 160 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const { |
| 112 return host_; | 161 return host_; |
| 113 } | 162 } |
| 114 | 163 |
| 115 void RenderWidgetHostViewChildFrame::SetSize(const gfx::Size& size) { | 164 void RenderWidgetHostViewChildFrame::SetSize(const gfx::Size& size) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 if (!router->is_registered(frame_sink_id_)) | 360 if (!router->is_registered(frame_sink_id_)) |
| 312 router->AddFrameSinkIdOwner(frame_sink_id_, this); | 361 router->AddFrameSinkIdOwner(frame_sink_id_, this); |
| 313 } | 362 } |
| 314 } | 363 } |
| 315 | 364 |
| 316 void RenderWidgetHostViewChildFrame::UnregisterFrameSinkId() { | 365 void RenderWidgetHostViewChildFrame::UnregisterFrameSinkId() { |
| 317 DCHECK(host_); | 366 DCHECK(host_); |
| 318 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { | 367 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { |
| 319 host_->delegate()->GetInputEventRouter()->RemoveFrameSinkIdOwner( | 368 host_->delegate()->GetInputEventRouter()->RemoveFrameSinkIdOwner( |
| 320 frame_sink_id_); | 369 frame_sink_id_); |
| 370 DetachFromTouchSelectionClientManagerIfNecessary(); |
| 321 } | 371 } |
| 322 } | 372 } |
| 323 | 373 |
| 324 void RenderWidgetHostViewChildFrame::UpdateViewportIntersection( | 374 void RenderWidgetHostViewChildFrame::UpdateViewportIntersection( |
| 325 const gfx::Rect& viewport_intersection) { | 375 const gfx::Rect& viewport_intersection) { |
| 326 if (host_) | 376 if (host_) |
| 327 host_->Send(new ViewMsg_SetViewportIntersection(host_->GetRoutingID(), | 377 host_->Send(new ViewMsg_SetViewportIntersection(host_->GetRoutingID(), |
| 328 viewport_intersection)); | 378 viewport_intersection)); |
| 329 } | 379 } |
| 330 | 380 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 current_surface_scale_factor_ = frame.metadata.device_scale_factor; | 419 current_surface_scale_factor_ = frame.metadata.device_scale_factor; |
| 370 | 420 |
| 371 support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); | 421 support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 372 has_frame_ = true; | 422 has_frame_ = true; |
| 373 | 423 |
| 374 if (local_surface_id_ != local_surface_id || HasEmbedderChanged()) { | 424 if (local_surface_id_ != local_surface_id || HasEmbedderChanged()) { |
| 375 local_surface_id_ = local_surface_id; | 425 local_surface_id_ = local_surface_id; |
| 376 SendSurfaceInfoToEmbedder(); | 426 SendSurfaceInfoToEmbedder(); |
| 377 } | 427 } |
| 378 | 428 |
| 429 if (selection_controller_client_) { |
| 430 selection_controller_client_->UpdateSelectionBoundsIfNeeded( |
| 431 frame.metadata.selection, current_device_scale_factor_); |
| 432 } |
| 433 |
| 379 ProcessFrameSwappedCallbacks(); | 434 ProcessFrameSwappedCallbacks(); |
| 380 } | 435 } |
| 381 | 436 |
| 382 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { | 437 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { |
| 383 cc::SurfaceSequence sequence = | 438 cc::SurfaceSequence sequence = |
| 384 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); | 439 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); |
| 385 cc::SurfaceManager* manager = GetSurfaceManager(); | 440 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 386 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); | 441 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); |
| 387 // The renderer process will satisfy this dependency when it creates a | 442 // The renderer process will satisfy this dependency when it creates a |
| 388 // SurfaceLayer. | 443 // SurfaceLayer. |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, | 778 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, |
| 724 frame_sink_id_); | 779 frame_sink_id_); |
| 725 } | 780 } |
| 726 support_.reset(); | 781 support_.reset(); |
| 727 } | 782 } |
| 728 | 783 |
| 729 bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() { | 784 bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() { |
| 730 return false; | 785 return false; |
| 731 } | 786 } |
| 732 | 787 |
| 788 bool RenderWidgetHostViewChildFrame::GetSelectionRange( |
| 789 gfx::Range* range) const { |
| 790 if (!text_input_manager_ || !GetFocusedWidget()) |
| 791 return false; |
| 792 |
| 793 const TextInputManager::TextSelection* selection = |
| 794 text_input_manager_->GetTextSelection(GetFocusedWidget()->GetView()); |
| 795 if (!selection) |
| 796 return false; |
| 797 |
| 798 range->set_start(selection->range().start()); |
| 799 range->set_end(selection->range().end()); |
| 800 |
| 801 return true; |
| 802 } |
| 803 |
| 804 ui::TextInputType RenderWidgetHostViewChildFrame::GetTextInputType() const { |
| 805 if (!text_input_manager_) |
| 806 return ui::TEXT_INPUT_TYPE_NONE; |
| 807 |
| 808 if (text_input_manager_->GetTextInputState()) |
| 809 return text_input_manager_->GetTextInputState()->type; |
| 810 return ui::TEXT_INPUT_TYPE_NONE; |
| 811 } |
| 812 |
| 813 gfx::Point RenderWidgetHostViewChildFrame::GetViewOriginInRoot() const { |
| 814 if (frame_connector_) { |
| 815 auto origin = GetViewBounds().origin() - |
| 816 frame_connector_->GetRootRenderWidgetHostView() |
| 817 ->GetViewBounds() |
| 818 .origin(); |
| 819 return gfx::Point(origin.x(), origin.y()); |
| 820 } |
| 821 return gfx::Point(); |
| 822 } |
| 823 |
| 733 } // namespace content | 824 } // namespace content |
| OLD | NEW |