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" | |
33 #include "content/common/content_switches_internal.h" | |
kenrb
2017/05/23 16:19:02
Why is this include being added?
wjmaclean
2017/05/23 17:00:40
Removed.
Let over from an earlier version of the
| |
30 #include "content/common/text_input_state.h" | 34 #include "content/common/text_input_state.h" |
31 #include "content/common/view_messages.h" | 35 #include "content/common/view_messages.h" |
32 #include "content/public/browser/guest_mode.h" | 36 #include "content/public/browser/guest_mode.h" |
33 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
34 #include "gpu/ipc/common/gpu_messages.h" | 38 #include "gpu/ipc/common/gpu_messages.h" |
35 #include "third_party/WebKit/public/platform/WebTouchEvent.h" | 39 #include "third_party/WebKit/public/platform/WebTouchEvent.h" |
36 #include "ui/gfx/geometry/size_conversions.h" | 40 #include "ui/gfx/geometry/size_conversions.h" |
37 #include "ui/gfx/geometry/size_f.h" | 41 #include "ui/gfx/geometry/size_f.h" |
42 #include "ui/touch_selection/touch_selection_controller.h" | |
38 | 43 |
39 namespace content { | 44 namespace content { |
40 | 45 |
41 // static | 46 // static |
42 RenderWidgetHostViewChildFrame* RenderWidgetHostViewChildFrame::Create( | 47 RenderWidgetHostViewChildFrame* RenderWidgetHostViewChildFrame::Create( |
43 RenderWidgetHost* widget) { | 48 RenderWidgetHost* widget) { |
44 RenderWidgetHostViewChildFrame* view = | 49 RenderWidgetHostViewChildFrame* view = |
45 new RenderWidgetHostViewChildFrame(widget); | 50 new RenderWidgetHostViewChildFrame(widget); |
46 view->Init(); | 51 view->Init(); |
47 return view; | 52 return view; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 if (frame_connector_) { | 87 if (frame_connector_) { |
83 if (parent_frame_sink_id_.is_valid()) { | 88 if (parent_frame_sink_id_.is_valid()) { |
84 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, | 89 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, |
85 frame_sink_id_); | 90 frame_sink_id_); |
86 } | 91 } |
87 parent_frame_sink_id_ = cc::FrameSinkId(); | 92 parent_frame_sink_id_ = cc::FrameSinkId(); |
88 local_surface_id_ = cc::LocalSurfaceId(); | 93 local_surface_id_ = cc::LocalSurfaceId(); |
89 | 94 |
90 // Unlocks the mouse if this RenderWidgetHostView holds the lock. | 95 // Unlocks the mouse if this RenderWidgetHostView holds the lock. |
91 UnlockMouse(); | 96 UnlockMouse(); |
97 | |
98 if (selection_controller_client_) { | |
99 auto* root_view = frame_connector_->GetRootRenderWidgetHostView(); | |
100 if (root_view) { | |
101 auto* manager = root_view->touch_selection_controller_client_manager(); | |
102 if (manager) | |
103 manager->RemoveObserver(this); | |
104 } | |
105 | |
106 selection_controller_client_.reset(); | |
107 } | |
92 } | 108 } |
93 frame_connector_ = frame_connector; | 109 frame_connector_ = frame_connector; |
94 if (frame_connector_) { | 110 if (frame_connector_) { |
95 RenderWidgetHostViewBase* parent_view = | 111 RenderWidgetHostViewBase* parent_view = |
96 frame_connector_->GetParentRenderWidgetHostView(); | 112 frame_connector_->GetParentRenderWidgetHostView(); |
97 if (parent_view) { | 113 if (parent_view) { |
98 parent_frame_sink_id_ = parent_view->GetFrameSinkId(); | 114 parent_frame_sink_id_ = parent_view->GetFrameSinkId(); |
99 DCHECK(parent_frame_sink_id_.is_valid()); | 115 DCHECK(parent_frame_sink_id_.is_valid()); |
100 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, | 116 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, |
101 frame_sink_id_); | 117 frame_sink_id_); |
102 } | 118 } |
119 | |
120 auto* root_view = frame_connector_->GetRootRenderWidgetHostView(); | |
121 if (root_view) { | |
122 // Make sure we're not using the zero-valued default for | |
kenrb
2017/05/23 16:19:02
This is surprising. Why wouldn't this be initializ
wjmaclean
2017/05/23 17:00:40
I have no idea why it was initialized to zero, but
| |
123 // current_device_scale_factor_. | |
124 current_device_scale_factor_ = root_view->current_device_scale_factor(); | |
125 if (current_device_scale_factor_ == 0.f) | |
126 current_device_scale_factor_ = 1.f; | |
127 | |
128 auto* manager = root_view->touch_selection_controller_client_manager(); | |
129 if (manager) { | |
130 // We will only have a manarer on Aura (and eventually Android). | |
kenrb
2017/05/23 16:19:02
nit: /s/manarer/manager
Also, I'd mark this specif
wjmaclean
2017/05/23 17:00:40
Done.
| |
131 selection_controller_client_ = | |
132 base::MakeUnique<TouchSelectionControllerClientChildFrame>(this, | |
133 manager); | |
134 manager->AddObserver(this); | |
135 } | |
136 } | |
103 } | 137 } |
104 } | 138 } |
105 | 139 |
140 void RenderWidgetHostViewChildFrame::OnManagerWillDestroy( | |
141 TouchSelectionControllerClientManager* manager) { | |
142 // We get the manager via the observer callback instead of through the | |
143 // frame_connector_ since our connection to the root_view may disappear by | |
144 // the time this function is called, but before frame_connector_ is reset. | |
145 manager->RemoveObserver(this); | |
146 selection_controller_client_.reset(); | |
147 } | |
148 | |
106 void RenderWidgetHostViewChildFrame::InitAsChild( | 149 void RenderWidgetHostViewChildFrame::InitAsChild( |
107 gfx::NativeView parent_view) { | 150 gfx::NativeView parent_view) { |
108 NOTREACHED(); | 151 NOTREACHED(); |
109 } | 152 } |
110 | 153 |
111 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const { | 154 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const { |
112 return host_; | 155 return host_; |
113 } | 156 } |
114 | 157 |
115 void RenderWidgetHostViewChildFrame::SetSize(const gfx::Size& size) { | 158 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_)) | 354 if (!router->is_registered(frame_sink_id_)) |
312 router->AddFrameSinkIdOwner(frame_sink_id_, this); | 355 router->AddFrameSinkIdOwner(frame_sink_id_, this); |
313 } | 356 } |
314 } | 357 } |
315 | 358 |
316 void RenderWidgetHostViewChildFrame::UnregisterFrameSinkId() { | 359 void RenderWidgetHostViewChildFrame::UnregisterFrameSinkId() { |
317 DCHECK(host_); | 360 DCHECK(host_); |
318 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { | 361 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { |
319 host_->delegate()->GetInputEventRouter()->RemoveFrameSinkIdOwner( | 362 host_->delegate()->GetInputEventRouter()->RemoveFrameSinkIdOwner( |
320 frame_sink_id_); | 363 frame_sink_id_); |
364 selection_controller_client_.reset(); | |
kenrb
2017/05/23 16:19:02
I'm trying to understand this. UnregisterFrameSink
wjmaclean
2017/05/23 17:00:40
Hmm, good question. TSE has never worked in GuestV
| |
321 } | 365 } |
322 } | 366 } |
323 | 367 |
324 void RenderWidgetHostViewChildFrame::UpdateViewportIntersection( | 368 void RenderWidgetHostViewChildFrame::UpdateViewportIntersection( |
325 const gfx::Rect& viewport_intersection) { | 369 const gfx::Rect& viewport_intersection) { |
326 if (host_) | 370 if (host_) |
327 host_->Send(new ViewMsg_SetViewportIntersection(host_->GetRoutingID(), | 371 host_->Send(new ViewMsg_SetViewportIntersection(host_->GetRoutingID(), |
328 viewport_intersection)); | 372 viewport_intersection)); |
329 } | 373 } |
330 | 374 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 current_surface_scale_factor_ = frame.metadata.device_scale_factor; | 413 current_surface_scale_factor_ = frame.metadata.device_scale_factor; |
370 | 414 |
371 support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); | 415 support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
372 has_frame_ = true; | 416 has_frame_ = true; |
373 | 417 |
374 if (local_surface_id_ != local_surface_id || HasEmbedderChanged()) { | 418 if (local_surface_id_ != local_surface_id || HasEmbedderChanged()) { |
375 local_surface_id_ = local_surface_id; | 419 local_surface_id_ = local_surface_id; |
376 SendSurfaceInfoToEmbedder(); | 420 SendSurfaceInfoToEmbedder(); |
377 } | 421 } |
378 | 422 |
423 if (selection_controller_client_) { | |
424 selection_controller_client_->UpdateSelectionBoundsIfNeeded( | |
425 frame.metadata.selection, current_device_scale_factor_); | |
426 } | |
427 | |
379 ProcessFrameSwappedCallbacks(); | 428 ProcessFrameSwappedCallbacks(); |
380 } | 429 } |
381 | 430 |
382 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { | 431 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { |
383 cc::SurfaceSequence sequence = | 432 cc::SurfaceSequence sequence = |
384 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); | 433 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); |
385 cc::SurfaceManager* manager = GetSurfaceManager(); | 434 cc::SurfaceManager* manager = GetSurfaceManager(); |
386 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); | 435 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); |
387 // The renderer process will satisfy this dependency when it creates a | 436 // The renderer process will satisfy this dependency when it creates a |
388 // SurfaceLayer. | 437 // SurfaceLayer. |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, | 763 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, |
715 frame_sink_id_); | 764 frame_sink_id_); |
716 } | 765 } |
717 support_.reset(); | 766 support_.reset(); |
718 } | 767 } |
719 | 768 |
720 bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() { | 769 bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() { |
721 return false; | 770 return false; |
722 } | 771 } |
723 | 772 |
773 bool RenderWidgetHostViewChildFrame::GetSelectionRange( | |
774 gfx::Range* range) const { | |
775 if (!text_input_manager_ || !GetFocusedWidget()) | |
776 return false; | |
777 | |
778 const TextInputManager::TextSelection* selection = | |
779 text_input_manager_->GetTextSelection(GetFocusedWidget()->GetView()); | |
780 if (!selection) | |
781 return false; | |
782 | |
783 range->set_start(selection->range().start()); | |
784 range->set_end(selection->range().end()); | |
785 | |
786 return true; | |
787 } | |
788 | |
789 ui::TextInputType RenderWidgetHostViewChildFrame::GetTextInputType() const { | |
790 if (!text_input_manager_) | |
791 return ui::TEXT_INPUT_TYPE_NONE; | |
792 | |
793 if (text_input_manager_->GetTextInputState()) | |
794 return text_input_manager_->GetTextInputState()->type; | |
795 return ui::TEXT_INPUT_TYPE_NONE; | |
796 } | |
797 | |
798 gfx::Point RenderWidgetHostViewChildFrame::GetViewOriginInRoot() const { | |
799 if (frame_connector_) { | |
800 auto origin = GetViewBounds().origin() - | |
801 frame_connector_->GetRootRenderWidgetHostView() | |
802 ->GetViewBounds() | |
803 .origin(); | |
804 return gfx::Point(origin.x(), origin.y()); | |
805 } | |
806 return gfx::Point(); | |
807 } | |
808 | |
724 } // namespace content | 809 } // namespace content |
OLD | NEW |