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