Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: content/browser/frame_host/cross_process_frame_connector.cc

Issue 2184033003: Refactor browser process coordinate transformation methods (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed problematic DCHECK Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/cross_process_frame_connector.h" 5 #include "content/browser/frame_host/cross_process_frame_connector.h"
6 6
7 #include "cc/surfaces/surface.h" 7 #include "cc/surfaces/surface.h"
8 #include "cc/surfaces/surface_hittest.h"
8 #include "cc/surfaces/surface_manager.h" 9 #include "cc/surfaces/surface_manager.h"
9 #include "content/browser/compositor/surface_utils.h" 10 #include "content/browser/compositor/surface_utils.h"
10 #include "content/browser/frame_host/frame_tree.h" 11 #include "content/browser/frame_host/frame_tree.h"
11 #include "content/browser/frame_host/frame_tree_node.h" 12 #include "content/browser/frame_host/frame_tree_node.h"
12 #include "content/browser/frame_host/render_frame_host_manager.h" 13 #include "content/browser/frame_host/render_frame_host_manager.h"
13 #include "content/browser/frame_host/render_frame_proxy_host.h" 14 #include "content/browser/frame_host/render_frame_proxy_host.h"
14 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" 15 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
15 #include "content/browser/renderer_host/render_view_host_impl.h" 16 #include "content/browser/renderer_host/render_view_host_impl.h"
16 #include "content/browser/renderer_host/render_widget_host_delegate.h" 17 #include "content/browser/renderer_host/render_widget_host_delegate.h"
17 #include "content/browser/renderer_host/render_widget_host_impl.h" 18 #include "content/browser/renderer_host/render_widget_host_impl.h"
18 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" 19 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
19 #include "content/browser/renderer_host/render_widget_host_view_base.h" 20 #include "content/browser/renderer_host/render_widget_host_view_base.h"
20 #include "content/common/frame_messages.h" 21 #include "content/common/frame_messages.h"
21 #include "gpu/ipc/common/gpu_messages.h" 22 #include "gpu/ipc/common/gpu_messages.h"
22 #include "third_party/WebKit/public/web/WebInputEvent.h" 23 #include "third_party/WebKit/public/web/WebInputEvent.h"
24 #include "ui/gfx/geometry/dip_util.h"
23 25
24 namespace content { 26 namespace content {
25 27
26 CrossProcessFrameConnector::CrossProcessFrameConnector( 28 CrossProcessFrameConnector::CrossProcessFrameConnector(
27 RenderFrameProxyHost* frame_proxy_in_parent_renderer) 29 RenderFrameProxyHost* frame_proxy_in_parent_renderer)
28 : frame_proxy_in_parent_renderer_(frame_proxy_in_parent_renderer), 30 : frame_proxy_in_parent_renderer_(frame_proxy_in_parent_renderer),
29 view_(nullptr), 31 view_(nullptr),
30 device_scale_factor_(1), 32 device_scale_factor_(1),
31 is_scroll_bubbling_(false) {} 33 is_scroll_bubbling_(false) {}
32 34
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 131 }
130 132
131 void CrossProcessFrameConnector::UpdateCursor(const WebCursor& cursor) { 133 void CrossProcessFrameConnector::UpdateCursor(const WebCursor& cursor) {
132 RenderWidgetHostViewBase* root_view = GetRootRenderWidgetHostView(); 134 RenderWidgetHostViewBase* root_view = GetRootRenderWidgetHostView();
133 if (root_view) 135 if (root_view)
134 root_view->UpdateCursor(cursor); 136 root_view->UpdateCursor(cursor);
135 } 137 }
136 138
137 gfx::Point CrossProcessFrameConnector::TransformPointToRootCoordSpace( 139 gfx::Point CrossProcessFrameConnector::TransformPointToRootCoordSpace(
138 const gfx::Point& point, 140 const gfx::Point& point,
139 cc::SurfaceId surface_id) { 141 const cc::SurfaceId& surface_id) {
140 gfx::Point transformed_point = point; 142 return TransformPointToCoordSpaceForView(point, GetRootRenderWidgetHostView(),
143 surface_id);
144 }
145
146 gfx::Point CrossProcessFrameConnector::TransformPointToLocalCoordSpace(
147 const gfx::Point& point,
148 const cc::SurfaceId& original_surface,
149 const cc::SurfaceId& local_surface_id) {
150 if (original_surface == local_surface_id)
151 return point;
152
153 // Transformations use physical pixels rather than DIP, so conversion
154 // is necessary.
155 gfx::Point transformed_point =
156 gfx::ConvertPointToPixel(device_scale_factor_, point);
157 cc::SurfaceHittest hittest(nullptr, GetSurfaceManager());
158 if (!hittest.TransformPointToTargetSurface(original_surface, local_surface_id,
159 &transformed_point))
160 DCHECK(false);
161
162 return gfx::ConvertPointToDIP(device_scale_factor_, transformed_point);
163 }
164
165 gfx::Point CrossProcessFrameConnector::TransformPointToCoordSpaceForView(
166 const gfx::Point& point,
167 RenderWidgetHostViewBase* target_view,
168 const cc::SurfaceId& local_surface_id) {
141 RenderWidgetHostViewBase* root_view = GetRootRenderWidgetHostView(); 169 RenderWidgetHostViewBase* root_view = GetRootRenderWidgetHostView();
142 if (root_view) 170 if (!root_view)
143 root_view->TransformPointToLocalCoordSpace(point, surface_id, 171 return point;
144 &transformed_point); 172
145 return transformed_point; 173 // It is possible that neither the original surface or target surface is an
174 // ancestor of the other in the RenderWidgetHostView tree (e.g. they could
175 // be siblings). To account for this, the point is first tranformed into the
176 // root coordinate space and then the root is asked to perform the conversion.
177 gfx::Point root_point =
178 root_view->TransformPointToLocalCoordSpace(point, local_surface_id);
179
180 if (target_view == root_view)
181 return root_point;
182
183 return root_view->TransformPointToCoordSpaceForView(point, target_view);
146 } 184 }
147 185
148 void CrossProcessFrameConnector::ForwardProcessAckedTouchEvent( 186 void CrossProcessFrameConnector::ForwardProcessAckedTouchEvent(
149 const TouchEventWithLatencyInfo& touch, 187 const TouchEventWithLatencyInfo& touch,
150 InputEventAckState ack_result) { 188 InputEventAckState ack_result) {
151 auto main_view = GetRootRenderWidgetHostView(); 189 auto main_view = GetRootRenderWidgetHostView();
152 if (main_view) 190 if (main_view)
153 main_view->ProcessAckedTouchEvent(touch, ack_result); 191 main_view->ProcessAckedTouchEvent(touch, ack_result);
154 } 192 }
155 193
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 388
351 if (parent) { 389 if (parent) {
352 return static_cast<RenderWidgetHostViewBase*>( 390 return static_cast<RenderWidgetHostViewBase*>(
353 parent->current_frame_host()->GetView()); 391 parent->current_frame_host()->GetView());
354 } 392 }
355 393
356 return nullptr; 394 return nullptr;
357 } 395 }
358 396
359 } // namespace content 397 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698