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

Side by Side Diff: content/browser/renderer_host/render_widget_host_input_event_router.cc

Issue 1752833002: Implement Gesture event hit testing/forwarding for OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wjmCFTouch.v2
Patch Set: Fix touch selection controller tests. Created 4 years, 9 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 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" 7 #include "cc/quads/surface_draw_quad.h"
8 #include "cc/surfaces/surface_id_allocator.h" 8 #include "cc/surfaces/surface_id_allocator.h"
9 #include "cc/surfaces/surface_manager.h" 9 #include "cc/surfaces/surface_manager.h"
10 #include "content/browser/renderer_host/render_widget_host_view_base.h" 10 #include "content/browser/renderer_host/render_widget_host_view_base.h"
(...skipping 20 matching lines...) Expand all
31 31
32 // Remove this view from the owner_map. 32 // Remove this view from the owner_map.
33 for (auto entry : owner_map_) { 33 for (auto entry : owner_map_) {
34 if (entry.second == view) { 34 if (entry.second == view) {
35 owner_map_.erase(entry.first); 35 owner_map_.erase(entry.first);
36 // There will only be one instance of a particular view in the map. 36 // There will only be one instance of a particular view in the map.
37 break; 37 break;
38 } 38 }
39 } 39 }
40 40
41 if (view == current_touch_target_) { 41 if (view == touch_target_) {
42 current_touch_target_ = nullptr; 42 touch_target_ = nullptr;
43 touch_delta_ = gfx::Vector2d();
43 active_touches_ = 0; 44 active_touches_ = 0;
44 } 45 }
46
47 // If the target that's being destroyed is in the gesture target queue, we
48 // replace it with nullptr so that we maintain the 1:1 correspondence between
49 // queue entries and the touch sequences that underly them.
50 for (size_t i = 0; i < gesture_target_queue_.size(); ++i) {
51 if (gesture_target_queue_[i].target == view)
52 gesture_target_queue_[i].target = nullptr;
53 }
54
55 if (view == gesture_target_) {
56 gesture_target_ = nullptr;
57 gesture_delta_ = gfx::Vector2d();
58 }
45 } 59 }
46 60
47 void RenderWidgetHostInputEventRouter::ClearAllObserverRegistrations() { 61 void RenderWidgetHostInputEventRouter::ClearAllObserverRegistrations() {
48 for (auto entry : owner_map_) 62 for (auto entry : owner_map_)
49 entry.second->RemoveObserver(this); 63 entry.second->RemoveObserver(this);
50 owner_map_.clear(); 64 owner_map_.clear();
51 } 65 }
52 66
53 RenderWidgetHostInputEventRouter::HittestDelegate::HittestDelegate( 67 RenderWidgetHostInputEventRouter::HittestDelegate::HittestDelegate(
54 const std::unordered_map<cc::SurfaceId, HittestData, cc::SurfaceIdHash>& 68 const std::unordered_map<cc::SurfaceId, HittestData, cc::SurfaceIdHash>&
(...skipping 12 matching lines...) Expand all
67 bool RenderWidgetHostInputEventRouter::HittestDelegate::AcceptHitTarget( 81 bool RenderWidgetHostInputEventRouter::HittestDelegate::AcceptHitTarget(
68 const cc::SurfaceDrawQuad* surface_quad, 82 const cc::SurfaceDrawQuad* surface_quad,
69 const gfx::Point& point_in_quad_space) { 83 const gfx::Point& point_in_quad_space) {
70 auto it = hittest_data_.find(surface_quad->surface_id); 84 auto it = hittest_data_.find(surface_quad->surface_id);
71 if (it != hittest_data_.end() && !it->second.ignored_for_hittest) 85 if (it != hittest_data_.end() && !it->second.ignored_for_hittest)
72 return true; 86 return true;
73 return false; 87 return false;
74 } 88 }
75 89
76 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() 90 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter()
77 : current_touch_target_(nullptr), active_touches_(0) {} 91 : touch_target_(nullptr),
92 gesture_target_(nullptr),
93 active_touches_(0) {}
78 94
79 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { 95 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() {
80 // We may be destroyed before some of the owners in the map, so we must 96 // We may be destroyed before some of the owners in the map, so we must
81 // remove ourself from their observer lists. 97 // remove ourself from their observer lists.
82 ClearAllObserverRegistrations(); 98 ClearAllObserverRegistrations();
83 } 99 }
84 100
85 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget( 101 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget(
86 RenderWidgetHostViewBase* root_view, 102 RenderWidgetHostViewBase* root_view,
87 const gfx::Point& point, 103 const gfx::Point& point,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 root_view, gfx::Point(event->x, event->y), &transformed_point); 153 root_view, gfx::Point(event->x, event->y), &transformed_point);
138 if (!target) 154 if (!target)
139 return; 155 return;
140 156
141 event->x = transformed_point.x(); 157 event->x = transformed_point.x();
142 event->y = transformed_point.y(); 158 event->y = transformed_point.y();
143 159
144 target->ProcessMouseWheelEvent(*event); 160 target->ProcessMouseWheelEvent(*event);
145 } 161 }
146 162
163 void RenderWidgetHostInputEventRouter::RouteGestureEvent(
164 RenderWidgetHostViewBase* root_view,
165 blink::WebGestureEvent* event,
166 const ui::LatencyInfo& latency) {
167 // We use GestureTapDown to detect the start of a gesture sequence since there
168 // is no WebGestureEvent equivalent for ET_GESTURE_BEGIN. Note that this
169 // means the GestureFlingCancel that always comes between ET_GESTURE_BEGIN and
170 // GestureTapDown is sent to the previous target, but that is intentional.
tdresser 2016/03/04 19:51:01 Describe why it's correct for the GFC to target th
wjmaclean 2016/03/04 20:02:37 Done.
171 if (event->type == blink::WebInputEvent::GestureTapDown) {
172 DCHECK(!gesture_target_queue_.empty());
173 const GestureTargetData& data = gesture_target_queue_.front();
174 gesture_target_ = data.target;
175 gesture_delta_ = data.delta;
176 gesture_target_queue_.pop_front();
177 }
178
179 if (!gesture_target_)
180 return;
181
182 event->x += gesture_delta_.x();
183 event->y += gesture_delta_.y();
184 gesture_target_->ProcessGestureEvent(*event, latency);
185 }
186
147 void RenderWidgetHostInputEventRouter::RouteTouchEvent( 187 void RenderWidgetHostInputEventRouter::RouteTouchEvent(
148 RenderWidgetHostViewBase* root_view, 188 RenderWidgetHostViewBase* root_view,
149 blink::WebTouchEvent* event, 189 blink::WebTouchEvent* event,
150 const ui::LatencyInfo& latency) { 190 const ui::LatencyInfo& latency) {
151 switch (event->type) { 191 switch (event->type) {
152 case blink::WebInputEvent::TouchStart: { 192 case blink::WebInputEvent::TouchStart: {
153 if (!active_touches_) { 193 if (!active_touches_) {
154 // Since this is the first touch, it defines the target for the rest 194 // Since this is the first touch, it defines the target for the rest
155 // of this sequence. 195 // of this sequence.
156 DCHECK(!current_touch_target_); 196 DCHECK(!touch_target_);
157 gfx::Point transformed_point; 197 gfx::Point transformed_point;
158 gfx::Point original_point(event->touches[0].position.x, 198 gfx::Point original_point(event->touches[0].position.x,
159 event->touches[0].position.y); 199 event->touches[0].position.y);
160 current_touch_target_ = 200 touch_target_ =
161 FindEventTarget(root_view, original_point, &transformed_point); 201 FindEventTarget(root_view, original_point, &transformed_point);
162 if (!current_touch_target_)
163 return;
164 202
165 // TODO(wjmaclean): Instead of just computing a delta, we should extract 203 // TODO(wjmaclean): Instead of just computing a delta, we should extract
166 // the complete transform. We assume it doesn't change for the duration 204 // the complete transform. We assume it doesn't change for the duration
167 // of the touch sequence, though this could be wrong; a better approach 205 // of the touch sequence, though this could be wrong; a better approach
168 // might be to always transform each point to the current_touch_target_ 206 // might be to always transform each point to the touch_target_
169 // for the duration of the sequence. 207 // for the duration of the sequence.
170 touch_delta_ = transformed_point - original_point; 208 touch_delta_ = transformed_point - original_point;
209 gesture_target_queue_.emplace_back(touch_target_, touch_delta_);
210
211 if (!touch_target_)
212 return;
171 } 213 }
172 ++active_touches_; 214 ++active_touches_;
173 if (current_touch_target_) { 215 if (touch_target_) {
174 TransformEventTouchPositions(event, touch_delta_); 216 TransformEventTouchPositions(event, touch_delta_);
175 current_touch_target_->ProcessTouchEvent(*event, latency); 217 touch_target_->ProcessTouchEvent(*event, latency);
176 } 218 }
177 break; 219 break;
178 } 220 }
179 case blink::WebInputEvent::TouchMove: 221 case blink::WebInputEvent::TouchMove:
180 if (current_touch_target_) { 222 if (touch_target_) {
181 TransformEventTouchPositions(event, touch_delta_); 223 TransformEventTouchPositions(event, touch_delta_);
182 current_touch_target_->ProcessTouchEvent(*event, latency); 224 touch_target_->ProcessTouchEvent(*event, latency);
183 } 225 }
184 break; 226 break;
185 case blink::WebInputEvent::TouchEnd: 227 case blink::WebInputEvent::TouchEnd:
186 case blink::WebInputEvent::TouchCancel: 228 case blink::WebInputEvent::TouchCancel:
187 if (!current_touch_target_) 229 if (!touch_target_)
188 break; 230 break;
189 231
190 DCHECK(active_touches_); 232 DCHECK(active_touches_);
191 TransformEventTouchPositions(event, touch_delta_); 233 TransformEventTouchPositions(event, touch_delta_);
192 current_touch_target_->ProcessTouchEvent(*event, latency); 234 touch_target_->ProcessTouchEvent(*event, latency);
193 --active_touches_; 235 --active_touches_;
194 if (!active_touches_) { 236 if (!active_touches_) {
195 current_touch_target_ = nullptr; 237 touch_target_ = nullptr;
196 touch_delta_ = gfx::Vector2d(); 238 touch_delta_ = gfx::Vector2d();
197 } 239 }
198 break; 240 break;
199 default: 241 default:
200 NOTREACHED(); 242 NOTREACHED();
201 } 243 }
202 } 244 }
203 245
204 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner( 246 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner(
205 uint32_t id, 247 uint32_t id,
(...skipping 26 matching lines...) Expand all
232 if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( 274 if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId(
233 params.surface_id)) == owner_map_.end()) { 275 params.surface_id)) == owner_map_.end()) {
234 return; 276 return;
235 } 277 }
236 HittestData data; 278 HittestData data;
237 data.ignored_for_hittest = params.ignored_for_hittest; 279 data.ignored_for_hittest = params.ignored_for_hittest;
238 hittest_data_[params.surface_id] = data; 280 hittest_data_[params.surface_id] = data;
239 } 281 }
240 282
241 } // namespace content 283 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698