| 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" | 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 24 matching lines...) Expand all Loading... |
| 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 == current_touch_target_) { |
| 42 current_touch_target_ = nullptr; | 42 current_touch_target_ = nullptr; |
| 43 active_touches_ = 0; | 43 active_touches_ = 0; |
| 44 } | 44 } |
| 45 |
| 46 // If the target that's being destroyed is in the gesture target queue, we |
| 47 // replace it with nullptr so that we maintain the 1:1 correspondence between |
| 48 // queue entries and the touch sequences that underly them. |
| 49 for (size_t i = 0; i < gesture_target_queue_.size(); ++i) { |
| 50 if (gesture_target_queue_[i].target == view) |
| 51 gesture_target_queue_[i].target = nullptr; |
| 52 } |
| 53 |
| 54 if (view == current_gesture_target_) |
| 55 current_gesture_target_ = nullptr; |
| 45 } | 56 } |
| 46 | 57 |
| 47 void RenderWidgetHostInputEventRouter::ClearAllObserverRegistrations() { | 58 void RenderWidgetHostInputEventRouter::ClearAllObserverRegistrations() { |
| 48 for (auto entry : owner_map_) | 59 for (auto entry : owner_map_) |
| 49 entry.second->RemoveObserver(this); | 60 entry.second->RemoveObserver(this); |
| 50 owner_map_.clear(); | 61 owner_map_.clear(); |
| 51 } | 62 } |
| 52 | 63 |
| 53 RenderWidgetHostInputEventRouter::HittestDelegate::HittestDelegate( | 64 RenderWidgetHostInputEventRouter::HittestDelegate::HittestDelegate( |
| 54 const std::unordered_map<cc::SurfaceId, HittestData, cc::SurfaceIdHash>& | 65 const std::unordered_map<cc::SurfaceId, HittestData, cc::SurfaceIdHash>& |
| (...skipping 12 matching lines...) Expand all Loading... |
| 67 bool RenderWidgetHostInputEventRouter::HittestDelegate::AcceptHitTarget( | 78 bool RenderWidgetHostInputEventRouter::HittestDelegate::AcceptHitTarget( |
| 68 const cc::SurfaceDrawQuad* surface_quad, | 79 const cc::SurfaceDrawQuad* surface_quad, |
| 69 const gfx::Point& point_in_quad_space) { | 80 const gfx::Point& point_in_quad_space) { |
| 70 auto it = hittest_data_.find(surface_quad->surface_id); | 81 auto it = hittest_data_.find(surface_quad->surface_id); |
| 71 if (it != hittest_data_.end() && !it->second.ignored_for_hittest) | 82 if (it != hittest_data_.end() && !it->second.ignored_for_hittest) |
| 72 return true; | 83 return true; |
| 73 return false; | 84 return false; |
| 74 } | 85 } |
| 75 | 86 |
| 76 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() | 87 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() |
| 77 : current_touch_target_(nullptr), active_touches_(0) {} | 88 : current_touch_target_(nullptr), |
| 89 current_gesture_target_(nullptr), |
| 90 active_touches_(0) {} |
| 78 | 91 |
| 79 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { | 92 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { |
| 80 // We may be destroyed before some of the owners in the map, so we must | 93 // We may be destroyed before some of the owners in the map, so we must |
| 81 // remove ourself from their observer lists. | 94 // remove ourself from their observer lists. |
| 82 ClearAllObserverRegistrations(); | 95 ClearAllObserverRegistrations(); |
| 83 } | 96 } |
| 84 | 97 |
| 85 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget( | 98 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget( |
| 86 RenderWidgetHostViewBase* root_view, | 99 RenderWidgetHostViewBase* root_view, |
| 87 const gfx::Point& point, | 100 const gfx::Point& point, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 root_view, gfx::Point(event->x, event->y), &transformed_point); | 150 root_view, gfx::Point(event->x, event->y), &transformed_point); |
| 138 if (!target) | 151 if (!target) |
| 139 return; | 152 return; |
| 140 | 153 |
| 141 event->x = transformed_point.x(); | 154 event->x = transformed_point.x(); |
| 142 event->y = transformed_point.y(); | 155 event->y = transformed_point.y(); |
| 143 | 156 |
| 144 target->ProcessMouseWheelEvent(*event); | 157 target->ProcessMouseWheelEvent(*event); |
| 145 } | 158 } |
| 146 | 159 |
| 160 void RenderWidgetHostInputEventRouter::RouteGestureEvent( |
| 161 RenderWidgetHostViewBase* root_view, |
| 162 blink::WebGestureEvent* event, |
| 163 const ui::LatencyInfo& latency) { |
| 164 // We use GestureTapDown to detect the start of a gesture sequence since there |
| 165 // is not WebGestureEvent equivalent for ET_GESTURE_BEGIN. Note that this |
| 166 // means the GestureFlingCancel that always comes between ET_GESTURE_BEGIN and |
| 167 // GestureTapDown is sent to the previous target, but that is intentional. |
| 168 if (event->type == blink::WebInputEvent::GestureTapDown) { |
| 169 if (!gesture_target_queue_.empty()) { |
| 170 GestureTargetData& data = gesture_target_queue_.front(); |
| 171 current_gesture_target_ = data.target; |
| 172 gesture_delta_ = data.delta; |
| 173 gesture_target_queue_.pop_front(); |
| 174 } else { |
| 175 NOTIMPLEMENTED(); |
| 176 } |
| 177 } |
| 178 |
| 179 if (!current_gesture_target_) |
| 180 return; |
| 181 |
| 182 event->x += gesture_delta_.x(); |
| 183 event->y += gesture_delta_.y(); |
| 184 current_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(!current_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 current_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 current_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(current_touch_target_, touch_delta_); |
| 210 |
| 211 if (!current_touch_target_) |
| 212 return; |
| 171 } | 213 } |
| 172 ++active_touches_; | 214 ++active_touches_; |
| 173 if (current_touch_target_) { | 215 if (current_touch_target_) { |
| 174 TransformEventTouchPositions(event, touch_delta_); | 216 TransformEventTouchPositions(event, touch_delta_); |
| 175 current_touch_target_->ProcessTouchEvent(*event, latency); | 217 current_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 (current_touch_target_) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |