Chromium Code Reviews| 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/gpu/compositor_util.h" | 25 #include "content/browser/gpu/compositor_util.h" |
| 26 #include "content/browser/renderer_host/input/touch_selection_controller_client_ child_frame.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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 bool result = | 421 bool result = |
| 372 support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); | 422 support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 373 DCHECK(result); | 423 DCHECK(result); |
| 374 has_frame_ = true; | 424 has_frame_ = true; |
| 375 | 425 |
| 376 if (local_surface_id_ != local_surface_id || HasEmbedderChanged()) { | 426 if (local_surface_id_ != local_surface_id || HasEmbedderChanged()) { |
| 377 local_surface_id_ = local_surface_id; | 427 local_surface_id_ = local_surface_id; |
| 378 SendSurfaceInfoToEmbedder(); | 428 SendSurfaceInfoToEmbedder(); |
| 379 } | 429 } |
| 380 | 430 |
| 431 if (selection_controller_client_) { | |
| 432 selection_controller_client_->UpdateSelectionBoundsIfNeeded( | |
| 433 frame.metadata.selection, current_device_scale_factor_); | |
| 434 } | |
| 435 | |
| 381 ProcessFrameSwappedCallbacks(); | 436 ProcessFrameSwappedCallbacks(); |
| 382 } | 437 } |
| 383 | 438 |
| 384 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { | 439 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { |
| 385 cc::SurfaceSequence sequence = | 440 cc::SurfaceSequence sequence = |
| 386 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); | 441 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); |
| 387 cc::SurfaceManager* manager = GetSurfaceManager(); | 442 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 388 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); | 443 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); |
| 389 // The renderer process will satisfy this dependency when it creates a | 444 // The renderer process will satisfy this dependency when it creates a |
| 390 // SurfaceLayer. | 445 // SurfaceLayer. |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, | 780 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, |
| 726 frame_sink_id_); | 781 frame_sink_id_); |
| 727 } | 782 } |
| 728 support_.reset(); | 783 support_.reset(); |
| 729 } | 784 } |
| 730 | 785 |
| 731 bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() { | 786 bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() { |
| 732 return false; | 787 return false; |
| 733 } | 788 } |
| 734 | 789 |
| 790 bool RenderWidgetHostViewChildFrame::GetSelectionRange( | |
| 791 gfx::Range* range) const { | |
| 792 if (!text_input_manager_ || !GetFocusedWidget()) | |
|
EhsanK
2017/05/29 15:41:45
Just a comment that came to my mind when I was rea
wjmaclean
2017/05/29 16:39:06
Good to know ... I'll try this out, and revise it
| |
| 793 return false; | |
| 794 | |
| 795 const TextInputManager::TextSelection* selection = | |
| 796 text_input_manager_->GetTextSelection(GetFocusedWidget()->GetView()); | |
| 797 if (!selection) | |
| 798 return false; | |
| 799 | |
| 800 range->set_start(selection->range().start()); | |
| 801 range->set_end(selection->range().end()); | |
| 802 | |
| 803 return true; | |
| 804 } | |
| 805 | |
| 806 ui::TextInputType RenderWidgetHostViewChildFrame::GetTextInputType() const { | |
| 807 if (!text_input_manager_) | |
| 808 return ui::TEXT_INPUT_TYPE_NONE; | |
| 809 | |
| 810 if (text_input_manager_->GetTextInputState()) | |
| 811 return text_input_manager_->GetTextInputState()->type; | |
| 812 return ui::TEXT_INPUT_TYPE_NONE; | |
| 813 } | |
| 814 | |
| 815 gfx::Point RenderWidgetHostViewChildFrame::GetViewOriginInRoot() const { | |
| 816 if (frame_connector_) { | |
| 817 auto origin = GetViewBounds().origin() - | |
| 818 frame_connector_->GetRootRenderWidgetHostView() | |
| 819 ->GetViewBounds() | |
| 820 .origin(); | |
| 821 return gfx::Point(origin.x(), origin.y()); | |
| 822 } | |
| 823 return gfx::Point(); | |
| 824 } | |
| 825 | |
| 735 } // namespace content | 826 } // namespace content |
| OLD | NEW |