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