| 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 20 matching lines...) Expand all  Loading... | 
| 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  Loading... | 
| 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  Loading... | 
| 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, in case it is still in a | 
|  | 171   // fling. | 
|  | 172   if (event->type == blink::WebInputEvent::GestureTapDown) { | 
|  | 173     DCHECK(!gesture_target_queue_.empty()); | 
|  | 174     const GestureTargetData& data = gesture_target_queue_.front(); | 
|  | 175     gesture_target_ = data.target; | 
|  | 176     gesture_delta_ = data.delta; | 
|  | 177     gesture_target_queue_.pop_front(); | 
|  | 178   } | 
|  | 179 | 
|  | 180   if (!gesture_target_) | 
|  | 181     return; | 
|  | 182 | 
|  | 183   event->x += gesture_delta_.x(); | 
|  | 184   event->y += gesture_delta_.y(); | 
|  | 185   gesture_target_->ProcessGestureEvent(*event, latency); | 
|  | 186 } | 
|  | 187 | 
| 147 void RenderWidgetHostInputEventRouter::RouteTouchEvent( | 188 void RenderWidgetHostInputEventRouter::RouteTouchEvent( | 
| 148     RenderWidgetHostViewBase* root_view, | 189     RenderWidgetHostViewBase* root_view, | 
| 149     blink::WebTouchEvent* event, | 190     blink::WebTouchEvent* event, | 
| 150     const ui::LatencyInfo& latency) { | 191     const ui::LatencyInfo& latency) { | 
| 151   switch (event->type) { | 192   switch (event->type) { | 
| 152     case blink::WebInputEvent::TouchStart: { | 193     case blink::WebInputEvent::TouchStart: { | 
| 153       if (!active_touches_) { | 194       if (!active_touches_) { | 
| 154         // Since this is the first touch, it defines the target for the rest | 195         // Since this is the first touch, it defines the target for the rest | 
| 155         // of this sequence. | 196         // of this sequence. | 
| 156         DCHECK(!current_touch_target_); | 197         DCHECK(!touch_target_); | 
| 157         gfx::Point transformed_point; | 198         gfx::Point transformed_point; | 
| 158         gfx::Point original_point(event->touches[0].position.x, | 199         gfx::Point original_point(event->touches[0].position.x, | 
| 159                                   event->touches[0].position.y); | 200                                   event->touches[0].position.y); | 
| 160         current_touch_target_ = | 201         touch_target_ = | 
| 161             FindEventTarget(root_view, original_point, &transformed_point); | 202             FindEventTarget(root_view, original_point, &transformed_point); | 
| 162         if (!current_touch_target_) |  | 
| 163           return; |  | 
| 164 | 203 | 
| 165         // TODO(wjmaclean): Instead of just computing a delta, we should extract | 204         // TODO(wjmaclean): Instead of just computing a delta, we should extract | 
| 166         // the complete transform. We assume it doesn't change for the duration | 205         // 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 | 206         // 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_ | 207         // might be to always transform each point to the touch_target_ | 
| 169         // for the duration of the sequence. | 208         // for the duration of the sequence. | 
| 170         touch_delta_ = transformed_point - original_point; | 209         touch_delta_ = transformed_point - original_point; | 
|  | 210         gesture_target_queue_.emplace_back(touch_target_, touch_delta_); | 
|  | 211 | 
|  | 212         if (!touch_target_) | 
|  | 213           return; | 
| 171       } | 214       } | 
| 172       ++active_touches_; | 215       ++active_touches_; | 
| 173       if (current_touch_target_) { | 216       if (touch_target_) { | 
| 174         TransformEventTouchPositions(event, touch_delta_); | 217         TransformEventTouchPositions(event, touch_delta_); | 
| 175         current_touch_target_->ProcessTouchEvent(*event, latency); | 218         touch_target_->ProcessTouchEvent(*event, latency); | 
| 176       } | 219       } | 
| 177       break; | 220       break; | 
| 178     } | 221     } | 
| 179     case blink::WebInputEvent::TouchMove: | 222     case blink::WebInputEvent::TouchMove: | 
| 180       if (current_touch_target_) { | 223       if (touch_target_) { | 
| 181         TransformEventTouchPositions(event, touch_delta_); | 224         TransformEventTouchPositions(event, touch_delta_); | 
| 182         current_touch_target_->ProcessTouchEvent(*event, latency); | 225         touch_target_->ProcessTouchEvent(*event, latency); | 
| 183       } | 226       } | 
| 184       break; | 227       break; | 
| 185     case blink::WebInputEvent::TouchEnd: | 228     case blink::WebInputEvent::TouchEnd: | 
| 186     case blink::WebInputEvent::TouchCancel: | 229     case blink::WebInputEvent::TouchCancel: | 
| 187       if (!current_touch_target_) | 230       if (!touch_target_) | 
| 188         break; | 231         break; | 
| 189 | 232 | 
| 190       DCHECK(active_touches_); | 233       DCHECK(active_touches_); | 
| 191       TransformEventTouchPositions(event, touch_delta_); | 234       TransformEventTouchPositions(event, touch_delta_); | 
| 192       current_touch_target_->ProcessTouchEvent(*event, latency); | 235       touch_target_->ProcessTouchEvent(*event, latency); | 
| 193       --active_touches_; | 236       --active_touches_; | 
| 194       if (!active_touches_) { | 237       if (!active_touches_) { | 
| 195         current_touch_target_ = nullptr; | 238         touch_target_ = nullptr; | 
| 196         touch_delta_ = gfx::Vector2d(); | 239         touch_delta_ = gfx::Vector2d(); | 
| 197       } | 240       } | 
| 198       break; | 241       break; | 
| 199     default: | 242     default: | 
| 200       NOTREACHED(); | 243       NOTREACHED(); | 
| 201   } | 244   } | 
| 202 } | 245 } | 
| 203 | 246 | 
| 204 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner( | 247 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner( | 
| 205     uint32_t id, | 248     uint32_t id, | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 232   if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( | 275   if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( | 
| 233           params.surface_id)) == owner_map_.end()) { | 276           params.surface_id)) == owner_map_.end()) { | 
| 234     return; | 277     return; | 
| 235   } | 278   } | 
| 236   HittestData data; | 279   HittestData data; | 
| 237   data.ignored_for_hittest = params.ignored_for_hittest; | 280   data.ignored_for_hittest = params.ignored_for_hittest; | 
| 238   hittest_data_[params.surface_id] = data; | 281   hittest_data_[params.surface_id] = data; | 
| 239 } | 282 } | 
| 240 | 283 | 
| 241 }  // namespace content | 284 }  // namespace content | 
| OLD | NEW | 
|---|