| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame_host/render_widget_host_view_guest.h" | 5 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 #if defined(USE_AURA) | 160 #if defined(USE_AURA) |
| 161 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent( | 161 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent( |
| 162 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { | 162 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { |
| 163 // TODO(tdresser): Since all ProcessAckedTouchEvent() uses is the event id, | 163 // TODO(tdresser): Since all ProcessAckedTouchEvent() uses is the event id, |
| 164 // don't pass the full event object here. https://crbug.com/550581. | 164 // don't pass the full event object here. https://crbug.com/550581. |
| 165 GetOwnerRenderWidgetHostView()->ProcessAckedTouchEvent(touch, ack_result); | 165 GetOwnerRenderWidgetHostView()->ProcessAckedTouchEvent(touch, ack_result); |
| 166 } | 166 } |
| 167 #endif | 167 #endif |
| 168 | 168 |
| 169 void RenderWidgetHostViewGuest::ProcessMouseEvent( |
| 170 const blink::WebMouseEvent& event, |
| 171 const ui::LatencyInfo& latency) { |
| 172 if (event.type == blink::WebInputEvent::MouseDown) { |
| 173 DCHECK(guest_->GetOwnerRenderWidgetHostView()); |
| 174 RenderWidgetHost* embedder = |
| 175 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost(); |
| 176 if (!embedder->GetView()->HasFocus()) |
| 177 embedder->GetView()->Focus(); |
| 178 |
| 179 // With direct routing, the embedder would not know to focus the guest on |
| 180 // click. Sends a synthetic event for the focusing side effect. |
| 181 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code. |
| 182 // http://crbug.com/533069 |
| 183 MaybeSendSyntheticTapGesture( |
| 184 blink::WebFloatPoint(event.x, event.y), |
| 185 blink::WebFloatPoint(event.globalX, event.globalY)); |
| 186 } |
| 187 host_->ForwardMouseEventWithLatencyInfo(event, latency); |
| 188 } |
| 189 |
| 169 void RenderWidgetHostViewGuest::ProcessTouchEvent( | 190 void RenderWidgetHostViewGuest::ProcessTouchEvent( |
| 170 const blink::WebTouchEvent& event, | 191 const blink::WebTouchEvent& event, |
| 171 const ui::LatencyInfo& latency) { | 192 const ui::LatencyInfo& latency) { |
| 172 if (event.type == blink::WebInputEvent::TouchStart) { | 193 if (event.type == blink::WebInputEvent::TouchStart) { |
| 173 DCHECK(guest_->GetOwnerRenderWidgetHostView()); | 194 DCHECK(guest_->GetOwnerRenderWidgetHostView()); |
| 174 RenderWidgetHostImpl* embedder = static_cast<RenderWidgetHostImpl*>( | 195 RenderWidgetHost* embedder = |
| 175 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost()); | 196 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost(); |
| 176 if (!embedder->GetView()->HasFocus()) | 197 if (!embedder->GetView()->HasFocus()) |
| 177 embedder->GetView()->Focus(); | 198 embedder->GetView()->Focus(); |
| 178 | 199 |
| 179 // Since we now route GestureEvents directly to the guest renderer, we need | 200 // With direct routing, the embedder would not know to focus the guest on |
| 180 // a way to make sure that the BrowserPlugin in the embedder gets focused so | 201 // touch. Sends a synthetic event for the focusing side effect. |
| 181 // that keyboard input (which still travels via BrowserPlugin) is routed to | |
| 182 // the plugin and thus onwards to the guest. | |
| 183 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code. | 202 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code. |
| 184 // http://crbug.com/533069 | 203 // http://crbug.com/533069 |
| 185 if (!HasFocus()) { | 204 MaybeSendSyntheticTapGesture(event.touches[0].position, |
| 186 // We need to a account for the position of the guest view within the | 205 event.touches[0].screenPosition); |
| 187 // embedder, as well as the fact that the embedder's host will add its | |
| 188 // offset in screen coordinates before sending the event (with the latter | |
| 189 // component just serving to confuse the renderer, hence why it should be | |
| 190 // removed). | |
| 191 gfx::Vector2d offset = GetViewBounds().origin() - | |
| 192 GetOwnerRenderWidgetHostView()->GetBoundsInRootWindow().origin(); | |
| 193 blink::WebGestureEvent gesture_tap_event; | |
| 194 gesture_tap_event.sourceDevice = blink::WebGestureDeviceTouchscreen; | |
| 195 gesture_tap_event.type = blink::WebGestureEvent::GestureTapDown; | |
| 196 gesture_tap_event.x = event.touches[0].position.x + offset.x(); | |
| 197 gesture_tap_event.y = event.touches[0].position.y + offset.y(); | |
| 198 gesture_tap_event.globalX = event.touches[0].screenPosition.x; | |
| 199 gesture_tap_event.globalY = event.touches[0].screenPosition.y; | |
| 200 GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event, | |
| 201 ui::LatencyInfo()); | |
| 202 gesture_tap_event.type = blink::WebGestureEvent::GestureTapCancel; | |
| 203 GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event, | |
| 204 ui::LatencyInfo()); | |
| 205 } | |
| 206 } | 206 } |
| 207 | 207 |
| 208 host_->ForwardTouchEventWithLatencyInfo(event, latency); | 208 host_->ForwardTouchEventWithLatencyInfo(event, latency); |
| 209 } | 209 } |
| 210 | 210 |
| 211 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const { | 211 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const { |
| 212 if (!guest_) | 212 if (!guest_) |
| 213 return gfx::Rect(); | 213 return gfx::Rect(); |
| 214 | 214 |
| 215 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView(); | 215 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView(); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 void RenderWidgetHostViewGuest::UnlockCompositingSurface() { | 524 void RenderWidgetHostViewGuest::UnlockCompositingSurface() { |
| 525 NOTIMPLEMENTED(); | 525 NOTIMPLEMENTED(); |
| 526 } | 526 } |
| 527 | 527 |
| 528 RenderWidgetHostViewBase* | 528 RenderWidgetHostViewBase* |
| 529 RenderWidgetHostViewGuest::GetOwnerRenderWidgetHostView() const { | 529 RenderWidgetHostViewGuest::GetOwnerRenderWidgetHostView() const { |
| 530 return static_cast<RenderWidgetHostViewBase*>( | 530 return static_cast<RenderWidgetHostViewBase*>( |
| 531 guest_->GetOwnerRenderWidgetHostView()); | 531 guest_->GetOwnerRenderWidgetHostView()); |
| 532 } | 532 } |
| 533 | 533 |
| 534 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code. |
| 535 // http://crbug.com/533069 |
| 536 void RenderWidgetHostViewGuest::MaybeSendSyntheticTapGesture( |
| 537 const blink::WebFloatPoint& position, |
| 538 const blink::WebFloatPoint& screenPosition) const { |
| 539 if (!HasFocus()) { |
| 540 // We need to a account for the position of the guest view within the |
| 541 // embedder, as well as the fact that the embedder's host will add its |
| 542 // offset in screen coordinates before sending the event (with the latter |
| 543 // component just serving to confuse the renderer, hence why it should be |
| 544 // removed). |
| 545 gfx::Vector2d offset = |
| 546 GetViewBounds().origin() - |
| 547 GetOwnerRenderWidgetHostView()->GetBoundsInRootWindow().origin(); |
| 548 blink::WebGestureEvent gesture_tap_event; |
| 549 gesture_tap_event.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 550 gesture_tap_event.type = blink::WebGestureEvent::GestureTapDown; |
| 551 gesture_tap_event.x = position.x + offset.x(); |
| 552 gesture_tap_event.y = position.y + offset.y(); |
| 553 gesture_tap_event.globalX = screenPosition.x; |
| 554 gesture_tap_event.globalY = screenPosition.y; |
| 555 GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event, |
| 556 ui::LatencyInfo()); |
| 557 gesture_tap_event.type = blink::WebGestureEvent::GestureTapCancel; |
| 558 GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event, |
| 559 ui::LatencyInfo()); |
| 560 } |
| 561 } |
| 562 |
| 534 void RenderWidgetHostViewGuest::WheelEventAck( | 563 void RenderWidgetHostViewGuest::WheelEventAck( |
| 535 const blink::WebMouseWheelEvent& event, | 564 const blink::WebMouseWheelEvent& event, |
| 536 InputEventAckState ack_result) { | 565 InputEventAckState ack_result) { |
| 537 if (ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED || | 566 if (ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED || |
| 538 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) { | 567 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) { |
| 539 guest_->ResendEventToEmbedder(event); | 568 guest_->ResendEventToEmbedder(event); |
| 540 } | 569 } |
| 541 } | 570 } |
| 542 | 571 |
| 543 void RenderWidgetHostViewGuest::GestureEventAck( | 572 void RenderWidgetHostViewGuest::GestureEventAck( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 gesture_event.data.scrollUpdate.inertialPhase == | 667 gesture_event.data.scrollUpdate.inertialPhase == |
| 639 blink::WebGestureEvent::MomentumPhase) { | 668 blink::WebGestureEvent::MomentumPhase) { |
| 640 return; | 669 return; |
| 641 } | 670 } |
| 642 host_->ForwardGestureEvent(gesture_event); | 671 host_->ForwardGestureEvent(gesture_event); |
| 643 return; | 672 return; |
| 644 } | 673 } |
| 645 } | 674 } |
| 646 | 675 |
| 647 } // namespace content | 676 } // namespace content |
| OLD | NEW |