Chromium Code Reviews| Index: content/browser/frame_host/render_widget_host_view_child_frame.cc |
| diff --git a/content/browser/frame_host/render_widget_host_view_child_frame.cc b/content/browser/frame_host/render_widget_host_view_child_frame.cc |
| index 5e9dca9239819183ac3f9ec7c079b918a7e244ee..5532e49ff4cf692897901581be6047b9f8e3a74f 100644 |
| --- a/content/browser/frame_host/render_widget_host_view_child_frame.cc |
| +++ b/content/browser/frame_host/render_widget_host_view_child_frame.cc |
| @@ -23,10 +23,13 @@ |
| #include "content/browser/compositor/surface_utils.h" |
| #include "content/browser/frame_host/cross_process_frame_connector.h" |
| #include "content/browser/gpu/compositor_util.h" |
| +#include "content/browser/renderer_host/input/touch_selection_controller_client_child_frame.h" |
| #include "content/browser/renderer_host/render_view_host_impl.h" |
| #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| #include "content/browser/renderer_host/render_widget_host_impl.h" |
| #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| +#include "content/browser/renderer_host/render_widget_host_view_event_handler.h" |
| +#include "content/browser/renderer_host/text_input_manager.h" |
| #include "content/common/text_input_state.h" |
| #include "content/common/view_messages.h" |
| #include "content/public/browser/guest_mode.h" |
| @@ -35,6 +38,7 @@ |
| #include "third_party/WebKit/public/platform/WebTouchEvent.h" |
| #include "ui/gfx/geometry/size_conversions.h" |
| #include "ui/gfx/geometry/size_f.h" |
| +#include "ui/touch_selection/touch_selection_controller.h" |
| namespace content { |
| @@ -74,6 +78,21 @@ void RenderWidgetHostViewChildFrame::Init() { |
| GetTextInputManager(); |
| } |
| +void RenderWidgetHostViewChildFrame:: |
| + DetachFromTouchSelectionClientManagerIfNecessary() { |
| + if (!selection_controller_client_) |
| + return; |
| + |
| + auto* root_view = frame_connector_->GetRootRenderWidgetHostView(); |
| + if (root_view) { |
| + auto* manager = root_view->touch_selection_controller_client_manager(); |
| + if (manager) |
| + manager->RemoveObserver(this); |
| + } |
| + |
| + selection_controller_client_.reset(); |
| +} |
| + |
| void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( |
| CrossProcessFrameConnector* frame_connector) { |
| if (frame_connector_ == frame_connector) |
| @@ -89,6 +108,7 @@ void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( |
| // Unlocks the mouse if this RenderWidgetHostView holds the lock. |
| UnlockMouse(); |
| + DetachFromTouchSelectionClientManagerIfNecessary(); |
| } |
| frame_connector_ = frame_connector; |
| if (frame_connector_) { |
| @@ -100,9 +120,38 @@ void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( |
| GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, |
| frame_sink_id_); |
| } |
| + |
| + auto* root_view = frame_connector_->GetRootRenderWidgetHostView(); |
| + if (root_view) { |
| + // Make sure we're not using the zero-valued default for |
| + // current_device_scale_factor_. |
| + current_device_scale_factor_ = root_view->current_device_scale_factor(); |
| + if (current_device_scale_factor_ == 0.f) |
| + current_device_scale_factor_ = 1.f; |
| + |
| + auto* manager = root_view->touch_selection_controller_client_manager(); |
| + if (manager) { |
| + // We will only have a manager on Aura (and eventually Android). |
| + // TODO(wjmaclean): update this comment when TSE OOPIF support becomes |
| + // available on Android. |
| + selection_controller_client_ = |
| + base::MakeUnique<TouchSelectionControllerClientChildFrame>(this, |
| + manager); |
| + manager->AddObserver(this); |
| + } |
| + } |
| } |
| } |
| +void RenderWidgetHostViewChildFrame::OnManagerWillDestroy( |
| + TouchSelectionControllerClientManager* manager) { |
| + // We get the manager via the observer callback instead of through the |
| + // frame_connector_ since our connection to the root_view may disappear by |
| + // the time this function is called, but before frame_connector_ is reset. |
| + manager->RemoveObserver(this); |
| + selection_controller_client_.reset(); |
| +} |
| + |
| void RenderWidgetHostViewChildFrame::InitAsChild( |
| gfx::NativeView parent_view) { |
| NOTREACHED(); |
| @@ -318,6 +367,7 @@ void RenderWidgetHostViewChildFrame::UnregisterFrameSinkId() { |
| if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { |
| host_->delegate()->GetInputEventRouter()->RemoveFrameSinkIdOwner( |
| frame_sink_id_); |
| + DetachFromTouchSelectionClientManagerIfNecessary(); |
| } |
| } |
| @@ -378,6 +428,11 @@ void RenderWidgetHostViewChildFrame::ProcessCompositorFrame( |
| SendSurfaceInfoToEmbedder(); |
| } |
| + if (selection_controller_client_) { |
| + selection_controller_client_->UpdateSelectionBoundsIfNeeded( |
| + frame.metadata.selection, current_device_scale_factor_); |
| + } |
| + |
| ProcessFrameSwappedCallbacks(); |
| } |
| @@ -732,4 +787,40 @@ bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() { |
| return false; |
| } |
| +bool RenderWidgetHostViewChildFrame::GetSelectionRange( |
| + gfx::Range* range) const { |
| + 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
|
| + return false; |
| + |
| + const TextInputManager::TextSelection* selection = |
| + text_input_manager_->GetTextSelection(GetFocusedWidget()->GetView()); |
| + if (!selection) |
| + return false; |
| + |
| + range->set_start(selection->range().start()); |
| + range->set_end(selection->range().end()); |
| + |
| + return true; |
| +} |
| + |
| +ui::TextInputType RenderWidgetHostViewChildFrame::GetTextInputType() const { |
| + if (!text_input_manager_) |
| + return ui::TEXT_INPUT_TYPE_NONE; |
| + |
| + if (text_input_manager_->GetTextInputState()) |
| + return text_input_manager_->GetTextInputState()->type; |
| + return ui::TEXT_INPUT_TYPE_NONE; |
| +} |
| + |
| +gfx::Point RenderWidgetHostViewChildFrame::GetViewOriginInRoot() const { |
| + if (frame_connector_) { |
| + auto origin = GetViewBounds().origin() - |
| + frame_connector_->GetRootRenderWidgetHostView() |
| + ->GetViewBounds() |
| + .origin(); |
| + return gfx::Point(origin.x(), origin.y()); |
| + } |
| + return gfx::Point(); |
| +} |
| + |
| } // namespace content |