| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "cc/quads/surface_draw_quad.h" | 10 #include "cc/quads/surface_draw_quad.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 gfx::Point transformed_point; | 175 gfx::Point transformed_point; |
| 176 | 176 |
| 177 // When the mouse is locked, directly route the events to the widget that | 177 // When the mouse is locked, directly route the events to the widget that |
| 178 // holds the lock and return. | 178 // holds the lock and return. |
| 179 if (root_view->IsMouseLocked()) { | 179 if (root_view->IsMouseLocked()) { |
| 180 target = RenderWidgetHostImpl::From(root_view->GetRenderWidgetHost()) | 180 target = RenderWidgetHostImpl::From(root_view->GetRenderWidgetHost()) |
| 181 ->delegate() | 181 ->delegate() |
| 182 ->GetMouseLockWidget() | 182 ->GetMouseLockWidget() |
| 183 ->GetView(); | 183 ->GetView(); |
| 184 if (!root_view->TransformPointToCoordSpaceForView( | 184 if (!root_view->TransformPointToCoordSpaceForView( |
| 185 gfx::Point(event->x, event->y), target, &transformed_point)) | 185 gfx::Point(event->positionInWidget().x, |
| 186 event->positionInWidget().y), |
| 187 target, &transformed_point)) |
| 186 return; | 188 return; |
| 187 | 189 |
| 188 event->x = transformed_point.x(); | 190 event->setPositionInWidget(transformed_point.x(), transformed_point.y()); |
| 189 event->y = transformed_point.y(); | |
| 190 target->ProcessMouseEvent(*event, latency); | 191 target->ProcessMouseEvent(*event, latency); |
| 191 return; | 192 return; |
| 192 } | 193 } |
| 193 | 194 |
| 194 const int mouse_button_modifiers = blink::WebInputEvent::LeftButtonDown | | 195 const int mouse_button_modifiers = blink::WebInputEvent::LeftButtonDown | |
| 195 blink::WebInputEvent::MiddleButtonDown | | 196 blink::WebInputEvent::MiddleButtonDown | |
| 196 blink::WebInputEvent::RightButtonDown | | 197 blink::WebInputEvent::RightButtonDown | |
| 197 blink::WebInputEvent::BackButtonDown | | 198 blink::WebInputEvent::BackButtonDown | |
| 198 blink::WebInputEvent::ForwardButtonDown; | 199 blink::WebInputEvent::ForwardButtonDown; |
| 199 if (mouse_capture_target_.target && | 200 if (mouse_capture_target_.target && |
| 200 event->type() != blink::WebInputEvent::MouseDown && | 201 event->type() != blink::WebInputEvent::MouseDown && |
| 201 (event->type() == blink::WebInputEvent::MouseUp || | 202 (event->type() == blink::WebInputEvent::MouseUp || |
| 202 event->modifiers() & mouse_button_modifiers)) { | 203 event->modifiers() & mouse_button_modifiers)) { |
| 203 target = mouse_capture_target_.target; | 204 target = mouse_capture_target_.target; |
| 204 if (!root_view->TransformPointToCoordSpaceForView( | 205 if (!root_view->TransformPointToCoordSpaceForView( |
| 205 gfx::Point(event->x, event->y), target, &transformed_point)) | 206 gfx::Point(event->positionInWidget().x, |
| 207 event->positionInWidget().y), |
| 208 target, &transformed_point)) |
| 206 return; | 209 return; |
| 207 if (event->type() == blink::WebInputEvent::MouseUp) | 210 if (event->type() == blink::WebInputEvent::MouseUp) |
| 208 mouse_capture_target_.target = nullptr; | 211 mouse_capture_target_.target = nullptr; |
| 209 } else { | 212 } else { |
| 210 target = FindEventTarget(root_view, gfx::Point(event->x, event->y), | 213 target = FindEventTarget( |
| 211 &transformed_point); | 214 root_view, |
| 215 gfx::Point(event->positionInWidget().x, event->positionInWidget().y), |
| 216 &transformed_point); |
| 212 } | 217 } |
| 213 | 218 |
| 214 // RenderWidgetHostViewGuest does not properly handle direct routing of mouse | 219 // RenderWidgetHostViewGuest does not properly handle direct routing of mouse |
| 215 // events, so they have to go by the double-hop forwarding path through | 220 // events, so they have to go by the double-hop forwarding path through |
| 216 // the embedding renderer and then BrowserPluginGuest. | 221 // the embedding renderer and then BrowserPluginGuest. |
| 217 if (target && target->IsRenderWidgetHostViewGuest()) { | 222 if (target && target->IsRenderWidgetHostViewGuest()) { |
| 218 ui::LatencyInfo latency_info; | 223 ui::LatencyInfo latency_info; |
| 219 RenderWidgetHostViewBase* owner_view = | 224 RenderWidgetHostViewBase* owner_view = |
| 220 static_cast<RenderWidgetHostViewGuest*>(target) | 225 static_cast<RenderWidgetHostViewGuest*>(target) |
| 221 ->GetOwnerRenderWidgetHostView(); | 226 ->GetOwnerRenderWidgetHostView(); |
| 222 // In case there is nested RenderWidgetHostViewGuests (i.e., PDF inside | 227 // In case there is nested RenderWidgetHostViewGuests (i.e., PDF inside |
| 223 // <webview>), we will need the owner view of the top-most guest for input | 228 // <webview>), we will need the owner view of the top-most guest for input |
| 224 // routing. | 229 // routing. |
| 225 while (owner_view->IsRenderWidgetHostViewGuest()) { | 230 while (owner_view->IsRenderWidgetHostViewGuest()) { |
| 226 owner_view = static_cast<RenderWidgetHostViewGuest*>(owner_view) | 231 owner_view = static_cast<RenderWidgetHostViewGuest*>(owner_view) |
| 227 ->GetOwnerRenderWidgetHostView(); | 232 ->GetOwnerRenderWidgetHostView(); |
| 228 } | 233 } |
| 229 | 234 |
| 230 if (owner_view != root_view) { | 235 if (owner_view != root_view) { |
| 231 // This happens when the view is embedded inside a cross-process frame | 236 // This happens when the view is embedded inside a cross-process frame |
| 232 // (i.e., owner view is a RenderWidgetHostViewChildFrame). | 237 // (i.e., owner view is a RenderWidgetHostViewChildFrame). |
| 233 gfx::Point owner_point; | 238 gfx::Point owner_point; |
| 234 if (!root_view->TransformPointToCoordSpaceForView( | 239 if (!root_view->TransformPointToCoordSpaceForView( |
| 235 gfx::Point(event->x, event->y), owner_view, &owner_point)) { | 240 gfx::Point(event->positionInWidget().x, |
| 241 event->positionInWidget().y), |
| 242 owner_view, &owner_point)) { |
| 236 return; | 243 return; |
| 237 } | 244 } |
| 238 event->x = owner_point.x(); | 245 event->setPositionInWidget(owner_point.x(), owner_point.y()); |
| 239 event->y = owner_point.y(); | |
| 240 } | 246 } |
| 241 owner_view->ProcessMouseEvent(*event, latency_info); | 247 owner_view->ProcessMouseEvent(*event, latency_info); |
| 242 return; | 248 return; |
| 243 } | 249 } |
| 244 | 250 |
| 245 if (event->type() == blink::WebInputEvent::MouseDown) | 251 if (event->type() == blink::WebInputEvent::MouseDown) |
| 246 mouse_capture_target_.target = target; | 252 mouse_capture_target_.target = target; |
| 247 | 253 |
| 248 if (!target) | 254 if (!target) |
| 249 return; | 255 return; |
| 250 | 256 |
| 251 // SendMouseEnterOrLeaveEvents is called with the original event | 257 // SendMouseEnterOrLeaveEvents is called with the original event |
| 252 // coordinates, which are transformed independently for each view that will | 258 // coordinates, which are transformed independently for each view that will |
| 253 // receive an event. | 259 // receive an event. |
| 254 if ((event->type() == blink::WebInputEvent::MouseLeave || | 260 if ((event->type() == blink::WebInputEvent::MouseLeave || |
| 255 event->type() == blink::WebInputEvent::MouseMove) && | 261 event->type() == blink::WebInputEvent::MouseMove) && |
| 256 target != last_mouse_move_target_) | 262 target != last_mouse_move_target_) |
| 257 SendMouseEnterOrLeaveEvents(event, target, root_view); | 263 SendMouseEnterOrLeaveEvents(event, target, root_view); |
| 258 | 264 |
| 259 event->x = transformed_point.x(); | 265 event->setPositionInWidget(transformed_point.x(), transformed_point.y()); |
| 260 event->y = transformed_point.y(); | |
| 261 target->ProcessMouseEvent(*event, latency); | 266 target->ProcessMouseEvent(*event, latency); |
| 262 } | 267 } |
| 263 | 268 |
| 264 void RenderWidgetHostInputEventRouter::RouteMouseWheelEvent( | 269 void RenderWidgetHostInputEventRouter::RouteMouseWheelEvent( |
| 265 RenderWidgetHostViewBase* root_view, | 270 RenderWidgetHostViewBase* root_view, |
| 266 blink::WebMouseWheelEvent* event, | 271 blink::WebMouseWheelEvent* event, |
| 267 const ui::LatencyInfo& latency) { | 272 const ui::LatencyInfo& latency) { |
| 268 RenderWidgetHostViewBase* target = nullptr; | 273 RenderWidgetHostViewBase* target = nullptr; |
| 269 gfx::Point transformed_point; | 274 gfx::Point transformed_point; |
| 270 | 275 |
| 271 if (root_view->IsMouseLocked()) { | 276 if (root_view->IsMouseLocked()) { |
| 272 target = RenderWidgetHostImpl::From(root_view->GetRenderWidgetHost()) | 277 target = RenderWidgetHostImpl::From(root_view->GetRenderWidgetHost()) |
| 273 ->delegate() | 278 ->delegate() |
| 274 ->GetMouseLockWidget() | 279 ->GetMouseLockWidget() |
| 275 ->GetView(); | 280 ->GetView(); |
| 276 if (!root_view->TransformPointToCoordSpaceForView( | 281 if (!root_view->TransformPointToCoordSpaceForView( |
| 277 gfx::Point(event->x, event->y), target, &transformed_point)) | 282 gfx::Point(event->positionInWidget().x, |
| 283 event->positionInWidget().y), |
| 284 target, &transformed_point)) |
| 278 return; | 285 return; |
| 279 } else { | 286 } else { |
| 280 target = FindEventTarget(root_view, gfx::Point(event->x, event->y), | 287 target = FindEventTarget( |
| 281 &transformed_point); | 288 root_view, |
| 289 gfx::Point(event->positionInWidget().x, event->positionInWidget().y), |
| 290 &transformed_point); |
| 282 } | 291 } |
| 283 | 292 |
| 284 if (!target) | 293 if (!target) |
| 285 return; | 294 return; |
| 286 | 295 |
| 287 event->x = transformed_point.x(); | 296 event->setPositionInWidget(transformed_point.x(), transformed_point.y()); |
| 288 event->y = transformed_point.y(); | |
| 289 target->ProcessMouseWheelEvent(*event, latency); | 297 target->ProcessMouseWheelEvent(*event, latency); |
| 290 } | 298 } |
| 291 | 299 |
| 292 void RenderWidgetHostInputEventRouter::RouteGestureEvent( | 300 void RenderWidgetHostInputEventRouter::RouteGestureEvent( |
| 293 RenderWidgetHostViewBase* root_view, | 301 RenderWidgetHostViewBase* root_view, |
| 294 blink::WebGestureEvent* event, | 302 blink::WebGestureEvent* event, |
| 295 const ui::LatencyInfo& latency) { | 303 const ui::LatencyInfo& latency) { |
| 296 switch (event->sourceDevice) { | 304 switch (event->sourceDevice) { |
| 297 case blink::WebGestureDeviceUninitialized: | 305 case blink::WebGestureDeviceUninitialized: |
| 298 NOTREACHED() << "Uninitialized device type is not allowed"; | 306 NOTREACHED() << "Uninitialized device type is not allowed"; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 gfx::Point transformed_point; | 496 gfx::Point transformed_point; |
| 489 // Send MouseLeaves. | 497 // Send MouseLeaves. |
| 490 for (auto* view : exited_views) { | 498 for (auto* view : exited_views) { |
| 491 blink::WebMouseEvent mouse_leave(*event); | 499 blink::WebMouseEvent mouse_leave(*event); |
| 492 mouse_leave.setType(blink::WebInputEvent::MouseLeave); | 500 mouse_leave.setType(blink::WebInputEvent::MouseLeave); |
| 493 // There is a chance of a race if the last target has recently created a | 501 // There is a chance of a race if the last target has recently created a |
| 494 // new compositor surface. The SurfaceID for that might not have | 502 // new compositor surface. The SurfaceID for that might not have |
| 495 // propagated to its embedding surface, which makes it impossible to | 503 // propagated to its embedding surface, which makes it impossible to |
| 496 // compute the transformation for it | 504 // compute the transformation for it |
| 497 if (!root_view->TransformPointToCoordSpaceForView( | 505 if (!root_view->TransformPointToCoordSpaceForView( |
| 498 gfx::Point(event->x, event->y), view, &transformed_point)) | 506 gfx::Point(event->positionInWidget().x, |
| 507 event->positionInWidget().y), |
| 508 view, &transformed_point)) |
| 499 transformed_point = gfx::Point(); | 509 transformed_point = gfx::Point(); |
| 500 mouse_leave.x = transformed_point.x(); | 510 mouse_leave.setPositionInWidget(transformed_point.x(), |
| 501 mouse_leave.y = transformed_point.y(); | 511 transformed_point.y()); |
| 502 view->ProcessMouseEvent(mouse_leave, ui::LatencyInfo()); | 512 view->ProcessMouseEvent(mouse_leave, ui::LatencyInfo()); |
| 503 } | 513 } |
| 504 | 514 |
| 505 // The ancestor might need to trigger MouseOut handlers. | 515 // The ancestor might need to trigger MouseOut handlers. |
| 506 if (common_ancestor && common_ancestor != target) { | 516 if (common_ancestor && common_ancestor != target) { |
| 507 blink::WebMouseEvent mouse_move(*event); | 517 blink::WebMouseEvent mouse_move(*event); |
| 508 mouse_move.setType(blink::WebInputEvent::MouseMove); | 518 mouse_move.setType(blink::WebInputEvent::MouseMove); |
| 509 if (!root_view->TransformPointToCoordSpaceForView( | 519 if (!root_view->TransformPointToCoordSpaceForView( |
| 510 gfx::Point(event->x, event->y), common_ancestor, | 520 gfx::Point(event->positionInWidget().x, |
| 511 &transformed_point)) | 521 event->positionInWidget().y), |
| 522 common_ancestor, &transformed_point)) |
| 512 transformed_point = gfx::Point(); | 523 transformed_point = gfx::Point(); |
| 513 mouse_move.x = transformed_point.x(); | 524 mouse_move.setPositionInWidget(transformed_point.x(), |
| 514 mouse_move.y = transformed_point.y(); | 525 transformed_point.y()); |
| 515 common_ancestor->ProcessMouseEvent(mouse_move, ui::LatencyInfo()); | 526 common_ancestor->ProcessMouseEvent(mouse_move, ui::LatencyInfo()); |
| 516 } | 527 } |
| 517 | 528 |
| 518 // Send MouseMoves to trigger MouseEnter handlers. | 529 // Send MouseMoves to trigger MouseEnter handlers. |
| 519 for (auto* view : entered_views) { | 530 for (auto* view : entered_views) { |
| 520 if (view == target) | 531 if (view == target) |
| 521 continue; | 532 continue; |
| 522 blink::WebMouseEvent mouse_enter(*event); | 533 blink::WebMouseEvent mouse_enter(*event); |
| 523 mouse_enter.setType(blink::WebInputEvent::MouseMove); | 534 mouse_enter.setType(blink::WebInputEvent::MouseMove); |
| 524 if (!root_view->TransformPointToCoordSpaceForView( | 535 if (!root_view->TransformPointToCoordSpaceForView( |
| 525 gfx::Point(event->x, event->y), view, &transformed_point)) | 536 gfx::Point(event->positionInWidget().x, |
| 537 event->positionInWidget().y), |
| 538 view, &transformed_point)) |
| 526 transformed_point = gfx::Point(); | 539 transformed_point = gfx::Point(); |
| 527 mouse_enter.x = transformed_point.x(); | 540 mouse_enter.setPositionInWidget(transformed_point.x(), |
| 528 mouse_enter.y = transformed_point.y(); | 541 transformed_point.y()); |
| 529 view->ProcessMouseEvent(mouse_enter, ui::LatencyInfo()); | 542 view->ProcessMouseEvent(mouse_enter, ui::LatencyInfo()); |
| 530 } | 543 } |
| 531 | 544 |
| 532 last_mouse_move_target_ = target; | 545 last_mouse_move_target_ = target; |
| 533 last_mouse_move_root_view_ = root_view; | 546 last_mouse_move_root_view_ = root_view; |
| 534 } | 547 } |
| 535 | 548 |
| 536 void RenderWidgetHostInputEventRouter::BubbleScrollEvent( | 549 void RenderWidgetHostInputEventRouter::BubbleScrollEvent( |
| 537 RenderWidgetHostViewBase* target_view, | 550 RenderWidgetHostViewBase* target_view, |
| 538 const blink::WebGestureEvent& event) { | 551 const blink::WebGestureEvent& event) { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 if (!touchpad_gesture_target_.target) | 823 if (!touchpad_gesture_target_.target) |
| 811 return; | 824 return; |
| 812 | 825 |
| 813 // TODO(mohsen): Add tests to check event location. | 826 // TODO(mohsen): Add tests to check event location. |
| 814 event->x += touchpad_gesture_target_.delta.x(); | 827 event->x += touchpad_gesture_target_.delta.x(); |
| 815 event->y += touchpad_gesture_target_.delta.y(); | 828 event->y += touchpad_gesture_target_.delta.y(); |
| 816 touchpad_gesture_target_.target->ProcessGestureEvent(*event, latency); | 829 touchpad_gesture_target_.target->ProcessGestureEvent(*event, latency); |
| 817 } | 830 } |
| 818 | 831 |
| 819 } // namespace content | 832 } // namespace content |
| OLD | NEW |