1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
7 #include "cc/surfaces/surface_manager.h"
8 #include "content/browser/renderer_host/render_widget_host_view_base.h"
9 #include "third_party/WebKit/public/web/WebInputEvent.h"
13 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() {}
15 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() {
19 RenderWidgetHostViewBase
* RenderWidgetHostInputEventRouter::FindEventTarget(
20 RenderWidgetHostViewBase
* root_view
,
21 const gfx::Point
& point
,
22 gfx::Point
* transformed_point
) {
23 // Short circuit if owner_map has only one RenderWidgetHostView, no need for
25 if (owner_map_
.size() <= 1) {
26 *transformed_point
= point
;
30 // The conversion of point to transform_point is done over the course of the
31 // hit testing, and reflect transformations that would normally be applied in
32 // the renderer process if the event was being routed between frames within a
33 // single process with only one RenderWidgetHost.
34 uint32_t surface_id_namespace
=
35 root_view
->SurfaceIdNamespaceAtPoint(point
, transformed_point
);
36 const SurfaceIdNamespaceOwnerMap::iterator iter
=
37 owner_map_
.find(surface_id_namespace
);
38 // If the point hit a Surface whose namspace is no longer in the map, then
39 // it likely means the RenderWidgetHostView has been destroyed but its
40 // parent frame has not sent a new compositor frame since that happened.
41 if (iter
== owner_map_
.end())
46 void RenderWidgetHostInputEventRouter::RouteMouseEvent(
47 RenderWidgetHostViewBase
* root_view
,
48 blink::WebMouseEvent
* event
) {
49 gfx::Point transformed_point
;
50 RenderWidgetHostViewBase
* target
= FindEventTarget(
51 root_view
, gfx::Point(event
->x
, event
->y
), &transformed_point
);
52 event
->x
= transformed_point
.x();
53 event
->y
= transformed_point
.y();
55 target
->ProcessMouseEvent(*event
);
58 void RenderWidgetHostInputEventRouter::RouteMouseWheelEvent(
59 RenderWidgetHostViewBase
* root_view
,
60 blink::WebMouseWheelEvent
* event
) {
61 gfx::Point transformed_point
;
62 RenderWidgetHostViewBase
* target
= FindEventTarget(
63 root_view
, gfx::Point(event
->x
, event
->y
), &transformed_point
);
64 event
->x
= transformed_point
.x();
65 event
->y
= transformed_point
.y();
67 target
->ProcessMouseWheelEvent(*event
);
70 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner(
72 RenderWidgetHostViewBase
* owner
) {
73 DCHECK(owner_map_
.find(id
) == owner_map_
.end());
74 owner_map_
.insert(std::make_pair(id
, owner
));
77 void RenderWidgetHostInputEventRouter::RemoveSurfaceIdNamespaceOwner(
82 } // namespace content