| 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" |
| 11 #include "content/common/frame_messages.h" | 11 #include "content/common/frame_messages.h" |
| 12 #include "third_party/WebKit/public/web/WebInputEvent.h" | 12 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 13 | 13 |
| 14 namespace { |
| 15 |
| 16 void TransformEventTouchPositions(blink::WebTouchEvent* event, |
| 17 const gfx::Vector2d& delta) { |
| 18 for (unsigned i = 0; i < event->touchesLength; ++i) { |
| 19 event->touches[i].position.x += delta.x(); |
| 20 event->touches[i].position.y += delta.y(); |
| 21 } |
| 22 } |
| 23 |
| 24 } // anonymous namespace |
| 25 |
| 14 namespace content { | 26 namespace content { |
| 15 | 27 |
| 16 RenderWidgetHostInputEventRouter::HittestDelegate::HittestDelegate( | 28 RenderWidgetHostInputEventRouter::HittestDelegate::HittestDelegate( |
| 17 const std::unordered_map<cc::SurfaceId, HittestData, cc::SurfaceIdHash>& | 29 const std::unordered_map<cc::SurfaceId, HittestData, cc::SurfaceIdHash>& |
| 18 hittest_data) | 30 hittest_data) |
| 19 : hittest_data_(hittest_data) {} | 31 : hittest_data_(hittest_data) {} |
| 20 | 32 |
| 21 bool RenderWidgetHostInputEventRouter::HittestDelegate::RejectHitTarget( | 33 bool RenderWidgetHostInputEventRouter::HittestDelegate::RejectHitTarget( |
| 22 const cc::SurfaceDrawQuad* surface_quad, | 34 const cc::SurfaceDrawQuad* surface_quad, |
| 23 const gfx::Point& point_in_quad_space) { | 35 const gfx::Point& point_in_quad_space) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // of this sequence. | 132 // of this sequence. |
| 121 DCHECK(!current_touch_target_); | 133 DCHECK(!current_touch_target_); |
| 122 gfx::Point transformed_point; | 134 gfx::Point transformed_point; |
| 123 gfx::Point original_point(event->touches[0].position.x, | 135 gfx::Point original_point(event->touches[0].position.x, |
| 124 event->touches[0].position.y); | 136 event->touches[0].position.y); |
| 125 RenderWidgetHostViewBase* target = | 137 RenderWidgetHostViewBase* target = |
| 126 FindEventTarget(root_view, original_point, &transformed_point); | 138 FindEventTarget(root_view, original_point, &transformed_point); |
| 127 if (!target) | 139 if (!target) |
| 128 return; | 140 return; |
| 129 | 141 |
| 142 // TODO(wjmaclean): Instead of just computing a delta, we should extract |
| 143 // the complete transform. We assume it doesn't change for the duration |
| 144 // of the touch sequence, though this could be wrong; a better approach |
| 145 // might be to always transform each point to the current_touch_target_ |
| 146 // for the duration of the sequence. |
| 147 touch_delta_ = transformed_point - original_point; |
| 148 |
| 130 // Store the weak-ptr to the target, since it could disappear in the | 149 // Store the weak-ptr to the target, since it could disappear in the |
| 131 // middle of a touch sequence. | 150 // middle of a touch sequence. |
| 132 current_touch_target_ = target->GetWeakPtr(); | 151 current_touch_target_ = target->GetWeakPtr(); |
| 133 } | 152 } |
| 134 ++active_touches_; | 153 ++active_touches_; |
| 135 if (current_touch_target_) | 154 if (current_touch_target_) { |
| 155 TransformEventTouchPositions(event, touch_delta_); |
| 136 current_touch_target_->ProcessTouchEvent(*event, latency); | 156 current_touch_target_->ProcessTouchEvent(*event, latency); |
| 157 } |
| 137 break; | 158 break; |
| 138 } | 159 } |
| 139 case blink::WebInputEvent::TouchMove: | 160 case blink::WebInputEvent::TouchMove: |
| 140 if (current_touch_target_) | 161 if (current_touch_target_) { |
| 162 TransformEventTouchPositions(event, touch_delta_); |
| 141 current_touch_target_->ProcessTouchEvent(*event, latency); | 163 current_touch_target_->ProcessTouchEvent(*event, latency); |
| 164 } |
| 142 break; | 165 break; |
| 143 case blink::WebInputEvent::TouchEnd: | 166 case blink::WebInputEvent::TouchEnd: |
| 144 case blink::WebInputEvent::TouchCancel: | 167 case blink::WebInputEvent::TouchCancel: |
| 145 DCHECK(active_touches_); | 168 DCHECK(active_touches_); |
| 146 if (current_touch_target_) | 169 if (current_touch_target_) { |
| 170 TransformEventTouchPositions(event, touch_delta_); |
| 147 current_touch_target_->ProcessTouchEvent(*event, latency); | 171 current_touch_target_->ProcessTouchEvent(*event, latency); |
| 172 } |
| 148 --active_touches_; | 173 --active_touches_; |
| 149 if (!active_touches_) | 174 if (!active_touches_) { |
| 150 current_touch_target_ = WeakTarget(); | 175 current_touch_target_ = WeakTarget(); |
| 176 touch_delta_ = gfx::Vector2d(); |
| 177 } |
| 151 break; | 178 break; |
| 152 default: | 179 default: |
| 153 NOTREACHED(); | 180 NOTREACHED(); |
| 154 } | 181 } |
| 155 } | 182 } |
| 156 | 183 |
| 157 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner( | 184 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner( |
| 158 uint32_t id, | 185 uint32_t id, |
| 159 RenderWidgetHostViewBase* owner) { | 186 RenderWidgetHostViewBase* owner) { |
| 160 DCHECK(owner_map_.find(id) == owner_map_.end()); | 187 DCHECK(owner_map_.find(id) == owner_map_.end()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 178 if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( | 205 if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( |
| 179 params.surface_id)) == owner_map_.end()) { | 206 params.surface_id)) == owner_map_.end()) { |
| 180 return; | 207 return; |
| 181 } | 208 } |
| 182 HittestData data; | 209 HittestData data; |
| 183 data.ignored_for_hittest = params.ignored_for_hittest; | 210 data.ignored_for_hittest = params.ignored_for_hittest; |
| 184 hittest_data_[params.surface_id] = data; | 211 hittest_data_[params.surface_id] = data; |
| 185 } | 212 } |
| 186 | 213 |
| 187 } // namespace content | 214 } // namespace content |
| OLD | NEW |