OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/renderer_host/render_widget_host_input_event_router.h" | 5 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
6 | 6 |
| 7 #include "cc/quads/surface_draw_quad.h" |
| 8 #include "cc/surfaces/surface_id_allocator.h" |
7 #include "cc/surfaces/surface_manager.h" | 9 #include "cc/surfaces/surface_manager.h" |
8 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 10 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 11 #include "content/common/frame_messages.h" |
9 #include "third_party/WebKit/public/web/WebInputEvent.h" | 12 #include "third_party/WebKit/public/web/WebInputEvent.h" |
10 | 13 |
11 namespace content { | 14 namespace content { |
12 | 15 |
| 16 RenderWidgetHostInputEventRouter::HittestDelegate::HittestDelegate( |
| 17 const std::unordered_map<cc::SurfaceId, HittestData, cc::SurfaceIdHash>& |
| 18 hittest_data) |
| 19 : hittest_data_(hittest_data) {} |
| 20 |
| 21 bool RenderWidgetHostInputEventRouter::HittestDelegate::RejectHitTarget( |
| 22 const cc::SurfaceDrawQuad* surface_quad, |
| 23 const gfx::Point& point_in_quad_space) { |
| 24 auto it = hittest_data_.find(surface_quad->surface_id); |
| 25 if (it != hittest_data_.end() && it->second.ignored_for_hittest) |
| 26 return true; |
| 27 return false; |
| 28 } |
| 29 |
13 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() | 30 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() |
14 : active_touches_(0) {} | 31 : active_touches_(0) {} |
15 | 32 |
16 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { | 33 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { |
17 owner_map_.clear(); | 34 owner_map_.clear(); |
18 } | 35 } |
19 | 36 |
20 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget( | 37 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget( |
21 RenderWidgetHostViewBase* root_view, | 38 RenderWidgetHostViewBase* root_view, |
22 const gfx::Point& point, | 39 const gfx::Point& point, |
23 gfx::Point* transformed_point) { | 40 gfx::Point* transformed_point) { |
24 // Short circuit if owner_map has only one RenderWidgetHostView, no need for | 41 // Short circuit if owner_map has only one RenderWidgetHostView, no need for |
25 // hit testing. | 42 // hit testing. |
26 if (owner_map_.size() <= 1) { | 43 if (owner_map_.size() <= 1) { |
27 *transformed_point = point; | 44 *transformed_point = point; |
28 return root_view; | 45 return root_view; |
29 } | 46 } |
30 | 47 |
| 48 // The hittest delegate is used to reject hittesting quads based on extra |
| 49 // hittesting data send by the renderer. |
| 50 HittestDelegate delegate(hittest_data_); |
| 51 |
31 // The conversion of point to transform_point is done over the course of the | 52 // The conversion of point to transform_point is done over the course of the |
32 // hit testing, and reflect transformations that would normally be applied in | 53 // hit testing, and reflect transformations that would normally be applied in |
33 // the renderer process if the event was being routed between frames within a | 54 // the renderer process if the event was being routed between frames within a |
34 // single process with only one RenderWidgetHost. | 55 // single process with only one RenderWidgetHost. |
35 uint32_t surface_id_namespace = | 56 uint32_t surface_id_namespace = |
36 root_view->SurfaceIdNamespaceAtPoint(point, transformed_point); | 57 root_view->SurfaceIdNamespaceAtPoint(&delegate, point, transformed_point); |
37 const SurfaceIdNamespaceOwnerMap::iterator iter = | 58 const SurfaceIdNamespaceOwnerMap::iterator iter = |
38 owner_map_.find(surface_id_namespace); | 59 owner_map_.find(surface_id_namespace); |
39 // If the point hit a Surface whose namspace is no longer in the map, then | 60 // If the point hit a Surface whose namspace is no longer in the map, then |
40 // it likely means the RenderWidgetHostView has been destroyed but its | 61 // it likely means the RenderWidgetHostView has been destroyed but its |
41 // parent frame has not sent a new compositor frame since that happened. | 62 // parent frame has not sent a new compositor frame since that happened. |
42 if (iter == owner_map_.end()) | 63 if (iter == owner_map_.end()) |
43 return root_view; | 64 return root_view; |
44 RenderWidgetHostViewBase* target = iter->second.get(); | 65 RenderWidgetHostViewBase* target = iter->second.get(); |
45 // If we find the weak pointer is now null, it means the map entry is stale | 66 // If we find the weak pointer is now null, it means the map entry is stale |
46 // and should be removed to free space. | 67 // and should be removed to free space. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner( | 148 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner( |
128 uint32_t id, | 149 uint32_t id, |
129 RenderWidgetHostViewBase* owner) { | 150 RenderWidgetHostViewBase* owner) { |
130 DCHECK(owner_map_.find(id) == owner_map_.end()); | 151 DCHECK(owner_map_.find(id) == owner_map_.end()); |
131 owner_map_.insert(std::make_pair(id, owner->GetWeakPtr())); | 152 owner_map_.insert(std::make_pair(id, owner->GetWeakPtr())); |
132 } | 153 } |
133 | 154 |
134 void RenderWidgetHostInputEventRouter::RemoveSurfaceIdNamespaceOwner( | 155 void RenderWidgetHostInputEventRouter::RemoveSurfaceIdNamespaceOwner( |
135 uint32_t id) { | 156 uint32_t id) { |
136 owner_map_.erase(id); | 157 owner_map_.erase(id); |
| 158 |
| 159 for (auto it = hittest_data_.begin(); it != hittest_data_.end();) { |
| 160 if (cc::SurfaceIdAllocator::NamespaceForId(it->first) == id) |
| 161 it = hittest_data_.erase(it); |
| 162 else |
| 163 ++it; |
| 164 } |
| 165 } |
| 166 |
| 167 void RenderWidgetHostInputEventRouter::OnHittestData( |
| 168 const FrameHostMsg_HittestData_Params& params) { |
| 169 if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( |
| 170 params.surface_id)) == owner_map_.end()) { |
| 171 return; |
| 172 } |
| 173 HittestData data; |
| 174 data.ignored_for_hittest = params.ignored_for_hittest; |
| 175 hittest_data_[params.surface_id] = data; |
137 } | 176 } |
138 | 177 |
139 } // namespace content | 178 } // namespace content |
OLD | NEW |