| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { | 173 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { |
| 174 // TODO(tdresser): Since all ProcessAckedTouchEvent() uses is the event id, | 174 // TODO(tdresser): Since all ProcessAckedTouchEvent() uses is the event id, |
| 175 // don't pass the full event object here. https://crbug.com/550581. | 175 // don't pass the full event object here. https://crbug.com/550581. |
| 176 GetOwnerRenderWidgetHostView()->ProcessAckedTouchEvent(touch, ack_result); | 176 GetOwnerRenderWidgetHostView()->ProcessAckedTouchEvent(touch, ack_result); |
| 177 } | 177 } |
| 178 #endif | 178 #endif |
| 179 | 179 |
| 180 void RenderWidgetHostViewGuest::ProcessMouseEvent( | 180 void RenderWidgetHostViewGuest::ProcessMouseEvent( |
| 181 const blink::WebMouseEvent& event, | 181 const blink::WebMouseEvent& event, |
| 182 const ui::LatencyInfo& latency) { | 182 const ui::LatencyInfo& latency) { |
| 183 if (event.type == blink::WebInputEvent::MouseDown) { | 183 if (event.type() == blink::WebInputEvent::MouseDown) { |
| 184 DCHECK(guest_->GetOwnerRenderWidgetHostView()); | 184 DCHECK(guest_->GetOwnerRenderWidgetHostView()); |
| 185 RenderWidgetHost* embedder = | 185 RenderWidgetHost* embedder = |
| 186 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost(); | 186 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost(); |
| 187 if (!embedder->GetView()->HasFocus()) | 187 if (!embedder->GetView()->HasFocus()) |
| 188 embedder->GetView()->Focus(); | 188 embedder->GetView()->Focus(); |
| 189 | 189 |
| 190 // With direct routing, the embedder would not know to focus the guest on | 190 // With direct routing, the embedder would not know to focus the guest on |
| 191 // click. Sends a synthetic event for the focusing side effect. | 191 // click. Sends a synthetic event for the focusing side effect. |
| 192 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code. | 192 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code. |
| 193 // http://crbug.com/533069 | 193 // http://crbug.com/533069 |
| 194 MaybeSendSyntheticTapGesture( | 194 MaybeSendSyntheticTapGesture( |
| 195 blink::WebFloatPoint(event.x, event.y), | 195 blink::WebFloatPoint(event.x, event.y), |
| 196 blink::WebFloatPoint(event.globalX, event.globalY)); | 196 blink::WebFloatPoint(event.globalX, event.globalY)); |
| 197 } | 197 } |
| 198 host_->ForwardMouseEventWithLatencyInfo(event, latency); | 198 host_->ForwardMouseEventWithLatencyInfo(event, latency); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void RenderWidgetHostViewGuest::ProcessTouchEvent( | 201 void RenderWidgetHostViewGuest::ProcessTouchEvent( |
| 202 const blink::WebTouchEvent& event, | 202 const blink::WebTouchEvent& event, |
| 203 const ui::LatencyInfo& latency) { | 203 const ui::LatencyInfo& latency) { |
| 204 if (event.type == blink::WebInputEvent::TouchStart) { | 204 if (event.type() == blink::WebInputEvent::TouchStart) { |
| 205 DCHECK(guest_->GetOwnerRenderWidgetHostView()); | 205 DCHECK(guest_->GetOwnerRenderWidgetHostView()); |
| 206 RenderWidgetHost* embedder = | 206 RenderWidgetHost* embedder = |
| 207 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost(); | 207 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost(); |
| 208 if (!embedder->GetView()->HasFocus()) | 208 if (!embedder->GetView()->HasFocus()) |
| 209 embedder->GetView()->Focus(); | 209 embedder->GetView()->Focus(); |
| 210 | 210 |
| 211 // With direct routing, the embedder would not know to focus the guest on | 211 // With direct routing, the embedder would not know to focus the guest on |
| 212 // touch. Sends a synthetic event for the focusing side effect. | 212 // touch. Sends a synthetic event for the focusing side effect. |
| 213 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code. | 213 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code. |
| 214 // http://crbug.com/533069 | 214 // http://crbug.com/533069 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 void RenderWidgetHostViewGuest::GestureEventAck( | 593 void RenderWidgetHostViewGuest::GestureEventAck( |
| 594 const blink::WebGestureEvent& event, | 594 const blink::WebGestureEvent& event, |
| 595 InputEventAckState ack_result) { | 595 InputEventAckState ack_result) { |
| 596 bool not_consumed = ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED || | 596 bool not_consumed = ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED || |
| 597 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 597 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
| 598 // GestureScrollBegin/End are always consumed by the guest, so we only | 598 // GestureScrollBegin/End are always consumed by the guest, so we only |
| 599 // forward GestureScrollUpdate. | 599 // forward GestureScrollUpdate. |
| 600 if (event.type == blink::WebInputEvent::GestureScrollUpdate && not_consumed) | 600 if (event.type() == blink::WebInputEvent::GestureScrollUpdate && not_consumed) |
| 601 guest_->ResendEventToEmbedder(event); | 601 guest_->ResendEventToEmbedder(event); |
| 602 } | 602 } |
| 603 | 603 |
| 604 bool RenderWidgetHostViewGuest::IsRenderWidgetHostViewGuest() { | 604 bool RenderWidgetHostViewGuest::IsRenderWidgetHostViewGuest() { |
| 605 return true; | 605 return true; |
| 606 } | 606 } |
| 607 | 607 |
| 608 void RenderWidgetHostViewGuest::OnHandleInputEvent( | 608 void RenderWidgetHostViewGuest::OnHandleInputEvent( |
| 609 RenderWidgetHostImpl* embedder, | 609 RenderWidgetHostImpl* embedder, |
| 610 int browser_plugin_instance_id, | 610 int browser_plugin_instance_id, |
| 611 const blink::WebInputEvent* event) { | 611 const blink::WebInputEvent* event) { |
| 612 // WebMouseWheelEvents go into a queue, and may not be forwarded to the | 612 // WebMouseWheelEvents go into a queue, and may not be forwarded to the |
| 613 // renderer until after this method goes out of scope. Therefore we need to | 613 // renderer until after this method goes out of scope. Therefore we need to |
| 614 // explicitly remove the additional device scale factor from the coordinates | 614 // explicitly remove the additional device scale factor from the coordinates |
| 615 // before allowing the event to be queued. | 615 // before allowing the event to be queued. |
| 616 if (IsUseZoomForDSFEnabled() && | 616 if (IsUseZoomForDSFEnabled() && |
| 617 event->type == blink::WebInputEvent::MouseWheel) { | 617 event->type() == blink::WebInputEvent::MouseWheel) { |
| 618 blink::WebMouseWheelEvent rescaled_event = | 618 blink::WebMouseWheelEvent rescaled_event = |
| 619 *static_cast<const blink::WebMouseWheelEvent*>(event); | 619 *static_cast<const blink::WebMouseWheelEvent*>(event); |
| 620 rescaled_event.x /= current_device_scale_factor(); | 620 rescaled_event.x /= current_device_scale_factor(); |
| 621 rescaled_event.y /= current_device_scale_factor(); | 621 rescaled_event.y /= current_device_scale_factor(); |
| 622 rescaled_event.deltaX /= current_device_scale_factor(); | 622 rescaled_event.deltaX /= current_device_scale_factor(); |
| 623 rescaled_event.deltaY /= current_device_scale_factor(); | 623 rescaled_event.deltaY /= current_device_scale_factor(); |
| 624 rescaled_event.wheelTicksX /= current_device_scale_factor(); | 624 rescaled_event.wheelTicksX /= current_device_scale_factor(); |
| 625 rescaled_event.wheelTicksY /= current_device_scale_factor(); | 625 rescaled_event.wheelTicksY /= current_device_scale_factor(); |
| 626 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); | 626 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); |
| 627 host_->ForwardWheelEventWithLatencyInfo(rescaled_event, latency_info); | 627 host_->ForwardWheelEventWithLatencyInfo(rescaled_event, latency_info); |
| 628 return; | 628 return; |
| 629 } | 629 } |
| 630 | 630 |
| 631 ScopedInputScaleDisabler disable(host_, current_device_scale_factor()); | 631 ScopedInputScaleDisabler disable(host_, current_device_scale_factor()); |
| 632 if (blink::WebInputEvent::isMouseEventType(event->type)) { | 632 if (blink::WebInputEvent::isMouseEventType(event->type())) { |
| 633 // The mouse events for BrowserPlugin are modified by all | 633 // The mouse events for BrowserPlugin are modified by all |
| 634 // the CSS transforms applied on the <object> and embedder. As a result of | 634 // the CSS transforms applied on the <object> and embedder. As a result of |
| 635 // this, the coordinates passed on to the guest renderer are potentially | 635 // this, the coordinates passed on to the guest renderer are potentially |
| 636 // incorrect to determine the position of the context menu(they are not the | 636 // incorrect to determine the position of the context menu(they are not the |
| 637 // actual X, Y of the window). As a hack, we report the last location of a | 637 // actual X, Y of the window). As a hack, we report the last location of a |
| 638 // right mouse up to the BrowserPluginGuest to inform it of the next | 638 // right mouse up to the BrowserPluginGuest to inform it of the next |
| 639 // potential location for context menu (BUG=470087). | 639 // potential location for context menu (BUG=470087). |
| 640 // TODO(ekaramad): Find a better and more fundamental solution. Could the | 640 // TODO(ekaramad): Find a better and more fundamental solution. Could the |
| 641 // ContextMenuParams be based on global X, Y? | 641 // ContextMenuParams be based on global X, Y? |
| 642 const blink::WebMouseEvent& mouse_event = | 642 const blink::WebMouseEvent& mouse_event = |
| 643 static_cast<const blink::WebMouseEvent&>(*event); | 643 static_cast<const blink::WebMouseEvent&>(*event); |
| 644 // A MouseDown on the ButtonRight could suggest a ContextMenu. | 644 // A MouseDown on the ButtonRight could suggest a ContextMenu. |
| 645 if (guest_ && mouse_event.type == blink::WebInputEvent::MouseDown && | 645 if (guest_ && mouse_event.type() == blink::WebInputEvent::MouseDown && |
| 646 mouse_event.button == blink::WebPointerProperties::Button::Right) | 646 mouse_event.button == blink::WebPointerProperties::Button::Right) |
| 647 guest_->SetContextMenuPosition( | 647 guest_->SetContextMenuPosition( |
| 648 gfx::Point(mouse_event.globalX - GetViewBounds().x(), | 648 gfx::Point(mouse_event.globalX - GetViewBounds().x(), |
| 649 mouse_event.globalY - GetViewBounds().y())); | 649 mouse_event.globalY - GetViewBounds().y())); |
| 650 host_->ForwardMouseEvent(mouse_event); | 650 host_->ForwardMouseEvent(mouse_event); |
| 651 return; | 651 return; |
| 652 } | 652 } |
| 653 | 653 |
| 654 if (event->type == blink::WebInputEvent::MouseWheel) { | 654 if (event->type() == blink::WebInputEvent::MouseWheel) { |
| 655 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); | 655 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); |
| 656 host_->ForwardWheelEventWithLatencyInfo( | 656 host_->ForwardWheelEventWithLatencyInfo( |
| 657 *static_cast<const blink::WebMouseWheelEvent*>(event), latency_info); | 657 *static_cast<const blink::WebMouseWheelEvent*>(event), latency_info); |
| 658 return; | 658 return; |
| 659 } | 659 } |
| 660 | 660 |
| 661 if (blink::WebInputEvent::isKeyboardEventType(event->type)) { | 661 if (blink::WebInputEvent::isKeyboardEventType(event->type())) { |
| 662 if (!embedder->GetLastKeyboardEvent()) | 662 if (!embedder->GetLastKeyboardEvent()) |
| 663 return; | 663 return; |
| 664 NativeWebKeyboardEvent keyboard_event(*embedder->GetLastKeyboardEvent()); | 664 NativeWebKeyboardEvent keyboard_event(*embedder->GetLastKeyboardEvent()); |
| 665 host_->ForwardKeyboardEvent(keyboard_event); | 665 host_->ForwardKeyboardEvent(keyboard_event); |
| 666 return; | 666 return; |
| 667 } | 667 } |
| 668 | 668 |
| 669 if (blink::WebInputEvent::isTouchEventType(event->type)) { | 669 if (blink::WebInputEvent::isTouchEventType(event->type())) { |
| 670 if (event->type == blink::WebInputEvent::TouchStart && | 670 if (event->type() == blink::WebInputEvent::TouchStart && |
| 671 !embedder->GetView()->HasFocus()) { | 671 !embedder->GetView()->HasFocus()) { |
| 672 embedder->GetView()->Focus(); | 672 embedder->GetView()->Focus(); |
| 673 } | 673 } |
| 674 ui::LatencyInfo latency_info(ui::SourceEventType::TOUCH); | 674 ui::LatencyInfo latency_info(ui::SourceEventType::TOUCH); |
| 675 host_->ForwardTouchEventWithLatencyInfo( | 675 host_->ForwardTouchEventWithLatencyInfo( |
| 676 *static_cast<const blink::WebTouchEvent*>(event), latency_info); | 676 *static_cast<const blink::WebTouchEvent*>(event), latency_info); |
| 677 return; | 677 return; |
| 678 } | 678 } |
| 679 | 679 |
| 680 if (blink::WebInputEvent::isGestureEventType(event->type)) { | 680 if (blink::WebInputEvent::isGestureEventType(event->type())) { |
| 681 const blink::WebGestureEvent& gesture_event = | 681 const blink::WebGestureEvent& gesture_event = |
| 682 *static_cast<const blink::WebGestureEvent*>(event); | 682 *static_cast<const blink::WebGestureEvent*>(event); |
| 683 | 683 |
| 684 // We don't forward inertial GestureScrollUpdates to the guest anymore | 684 // We don't forward inertial GestureScrollUpdates to the guest anymore |
| 685 // since it now receives GestureFlingStart and will have its own fling | 685 // since it now receives GestureFlingStart and will have its own fling |
| 686 // curve generating GestureScrollUpdate events for it. | 686 // curve generating GestureScrollUpdate events for it. |
| 687 // TODO(wjmaclean): Should we try to avoid creating a fling curve in the | 687 // TODO(wjmaclean): Should we try to avoid creating a fling curve in the |
| 688 // embedder renderer in this case? BrowserPlugin can return 'true' for | 688 // embedder renderer in this case? BrowserPlugin can return 'true' for |
| 689 // handleInputEvent() on a GestureFlingStart, and we could use this as | 689 // handleInputEvent() on a GestureFlingStart, and we could use this as |
| 690 // a signal to let the guest handle the fling, though we'd need to be | 690 // a signal to let the guest handle the fling, though we'd need to be |
| 691 // sure other plugins would behave appropriately (i.e. return 'false'). | 691 // sure other plugins would behave appropriately (i.e. return 'false'). |
| 692 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate && | 692 if (gesture_event.type() == blink::WebInputEvent::GestureScrollUpdate && |
| 693 gesture_event.data.scrollUpdate.inertialPhase == | 693 gesture_event.data.scrollUpdate.inertialPhase == |
| 694 blink::WebGestureEvent::MomentumPhase) { | 694 blink::WebGestureEvent::MomentumPhase) { |
| 695 return; | 695 return; |
| 696 } | 696 } |
| 697 host_->ForwardGestureEvent(gesture_event); | 697 host_->ForwardGestureEvent(gesture_event); |
| 698 return; | 698 return; |
| 699 } | 699 } |
| 700 } | 700 } |
| 701 | 701 |
| 702 } // namespace content | 702 } // namespace content |
| OLD | NEW |