| 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 "base/bind_helpers.h" | 5 #include "base/bind_helpers.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/surfaces/surface.h" | 9 #include "cc/surfaces/surface.h" |
| 10 #include "cc/surfaces/surface_factory.h" | 10 #include "cc/surfaces/surface_factory.h" |
| 11 #include "cc/surfaces/surface_manager.h" | 11 #include "cc/surfaces/surface_manager.h" |
| 12 #include "cc/surfaces/surface_sequence.h" | 12 #include "cc/surfaces/surface_sequence.h" |
| 13 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 13 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 14 #include "content/browser/compositor/surface_utils.h" | 14 #include "content/browser/compositor/surface_utils.h" |
| 15 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 15 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
| 16 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 17 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 18 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| 17 #include "content/common/browser_plugin/browser_plugin_messages.h" | 19 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 18 #include "content/common/frame_messages.h" | 20 #include "content/common/frame_messages.h" |
| 19 #include "content/common/gpu/gpu_messages.h" | 21 #include "content/common/gpu/gpu_messages.h" |
| 20 #include "content/common/input/web_touch_event_traits.h" | 22 #include "content/common/input/web_touch_event_traits.h" |
| 21 #include "content/common/view_messages.h" | 23 #include "content/common/view_messages.h" |
| 22 #include "content/common/webplugin_geometry.h" | 24 #include "content/common/webplugin_geometry.h" |
| 23 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 24 #include "skia/ext/platform_canvas.h" | 26 #include "skia/ext/platform_canvas.h" |
| 25 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 27 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 26 | 28 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 49 } // namespace | 51 } // namespace |
| 50 | 52 |
| 51 RenderWidgetHostViewGuest::RenderWidgetHostViewGuest( | 53 RenderWidgetHostViewGuest::RenderWidgetHostViewGuest( |
| 52 RenderWidgetHost* widget_host, | 54 RenderWidgetHost* widget_host, |
| 53 BrowserPluginGuest* guest, | 55 BrowserPluginGuest* guest, |
| 54 base::WeakPtr<RenderWidgetHostViewBase> platform_view) | 56 base::WeakPtr<RenderWidgetHostViewBase> platform_view) |
| 55 : RenderWidgetHostViewChildFrame(widget_host), | 57 : RenderWidgetHostViewChildFrame(widget_host), |
| 56 // |guest| is NULL during test. | 58 // |guest| is NULL during test. |
| 57 guest_(guest ? guest->AsWeakPtr() : base::WeakPtr<BrowserPluginGuest>()), | 59 guest_(guest ? guest->AsWeakPtr() : base::WeakPtr<BrowserPluginGuest>()), |
| 58 platform_view_(platform_view) { | 60 platform_view_(platform_view) { |
| 59 #if defined(USE_AURA) | |
| 60 gesture_recognizer_.reset(ui::GestureRecognizer::Create()); | |
| 61 gesture_recognizer_->AddGestureEventHelper(this); | |
| 62 #endif // defined(USE_AURA) | |
| 63 } | 61 } |
| 64 | 62 |
| 65 RenderWidgetHostViewGuest::~RenderWidgetHostViewGuest() { | 63 RenderWidgetHostViewGuest::~RenderWidgetHostViewGuest() { |
| 66 #if defined(USE_AURA) | |
| 67 gesture_recognizer_->RemoveGestureEventHelper(this); | |
| 68 #endif // defined(USE_AURA) | |
| 69 } | 64 } |
| 70 | 65 |
| 71 bool RenderWidgetHostViewGuest::OnMessageReceivedFromEmbedder( | 66 bool RenderWidgetHostViewGuest::OnMessageReceivedFromEmbedder( |
| 72 const IPC::Message& message, | 67 const IPC::Message& message, |
| 73 RenderWidgetHostImpl* embedder) { | 68 RenderWidgetHostImpl* embedder) { |
| 74 bool handled = true; | 69 bool handled = true; |
| 75 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(RenderWidgetHostViewGuest, message, | 70 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(RenderWidgetHostViewGuest, message, |
| 76 embedder) | 71 embedder) |
| 77 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, | 72 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, |
| 78 OnHandleInputEvent) | 73 OnHandleInputEvent) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 121 |
| 127 bool RenderWidgetHostViewGuest::HasFocus() const { | 122 bool RenderWidgetHostViewGuest::HasFocus() const { |
| 128 if (!guest_) | 123 if (!guest_) |
| 129 return false; | 124 return false; |
| 130 return guest_->focused(); | 125 return guest_->focused(); |
| 131 } | 126 } |
| 132 | 127 |
| 133 #if defined(USE_AURA) | 128 #if defined(USE_AURA) |
| 134 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent( | 129 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent( |
| 135 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { | 130 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { |
| 136 // TODO(fsamuel): Currently we will only take this codepath if the guest has | 131 /* |
| 137 // requested touch events. A better solution is to always forward touchpresses | 132 TouchEventWithLatencyInfo touch_in_guest_coords(touch.event, touch.latency); |
| 138 // to the embedder process to target a BrowserPlugin, and then route all | 133 // Convert coordinates to something suitable for the embedder. |
| 139 // subsequent touch points of that touchdown to the appropriate guest until | 134 for (unsigned i = 0; i < touch_in_guest_coords.event.touchesLength; ++i) { |
| 140 // that touch point is released. | 135 blink::WebTouchPoint& touch_point = touch_in_guest_coords.event.touches[i]; |
| 141 ScopedVector<ui::TouchEvent> events; | 136 gfx::PointF guest_point(touch_point.position.x, touch_point.position.y); |
| 142 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events, LOCAL_COORDINATES)) | 137 gfx::PointF converted_point = guest_->GetScreenCoordinates(guest_point); |
| 143 return; | 138 touch_point.position.x = converted_point.x(); |
| 144 | 139 touch_point.position.y = converted_point.y(); |
| 145 ui::EventResult result = (ack_result == | |
| 146 INPUT_EVENT_ACK_STATE_CONSUMED) ? ui::ER_HANDLED : ui::ER_UNHANDLED; | |
| 147 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(), | |
| 148 end = events.end(); iter != end; ++iter) { | |
| 149 if (!gesture_recognizer_->ProcessTouchEventPreDispatch(*iter, this)) | |
| 150 continue; | |
| 151 | |
| 152 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | |
| 153 gestures.reset(gesture_recognizer_->AckTouchEvent( | |
| 154 (*iter)->unique_event_id(), result, this)); | |
| 155 ProcessGestures(gestures.get()); | |
| 156 } | 140 } |
| 141 */ |
| 142 GetOwnerRenderWidgetHostView()->ProcessAckedTouchEvent(touch, ack_result); |
| 157 } | 143 } |
| 158 #endif | 144 #endif |
| 159 | 145 |
| 146 void RenderWidgetHostViewGuest::ProcessTouchEvent( |
| 147 const blink::WebTouchEvent& event, |
| 148 const ui::LatencyInfo& latency) { |
| 149 host_->ForwardTouchEventWithLatencyInfo(event, latency); |
| 150 } |
| 151 |
| 160 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const { | 152 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const { |
| 161 if (!guest_) | 153 if (!guest_) |
| 162 return gfx::Rect(); | 154 return gfx::Rect(); |
| 163 | 155 |
| 164 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView(); | 156 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView(); |
| 165 gfx::Rect embedder_bounds; | 157 gfx::Rect embedder_bounds; |
| 166 if (rwhv) | 158 if (rwhv) |
| 167 embedder_bounds = rwhv->GetViewBounds(); | 159 embedder_bounds = rwhv->GetViewBounds(); |
| 168 return gfx::Rect( | 160 return gfx::Rect( |
| 169 guest_->GetScreenCoordinates(embedder_bounds.origin()), size_); | 161 guest_->GetScreenCoordinates(embedder_bounds.origin()), size_); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // When not using surfaces, the frame just gets proxied to | 209 // When not using surfaces, the frame just gets proxied to |
| 218 // the embedder's renderer to be composited. | 210 // the embedder's renderer to be composited. |
| 219 if (!frame->delegated_frame_data || !use_surfaces_) { | 211 if (!frame->delegated_frame_data || !use_surfaces_) { |
| 220 guest_->SwapCompositorFrame(output_surface_id, | 212 guest_->SwapCompositorFrame(output_surface_id, |
| 221 host_->GetProcess()->GetID(), | 213 host_->GetProcess()->GetID(), |
| 222 host_->GetRoutingID(), | 214 host_->GetRoutingID(), |
| 223 frame.Pass()); | 215 frame.Pass()); |
| 224 return; | 216 return; |
| 225 } | 217 } |
| 226 | 218 |
| 219 if (!has_started_rendering_) { |
| 220 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { |
| 221 host_->delegate()->GetInputEventRouter()->AddSurfaceIdNamespaceOwner( |
| 222 GetSurfaceIdNamespace(), this); |
| 223 } |
| 224 has_started_rendering_ = true; |
| 225 } |
| 226 |
| 227 cc::RenderPass* root_pass = | 227 cc::RenderPass* root_pass = |
| 228 frame->delegated_frame_data->render_pass_list.back(); | 228 frame->delegated_frame_data->render_pass_list.back(); |
| 229 | 229 |
| 230 gfx::Size frame_size = root_pass->output_rect.size(); | 230 gfx::Size frame_size = root_pass->output_rect.size(); |
| 231 float scale_factor = frame->metadata.device_scale_factor; | 231 float scale_factor = frame->metadata.device_scale_factor; |
| 232 | 232 |
| 233 // Check whether we need to recreate the cc::Surface, which means the child | 233 // Check whether we need to recreate the cc::Surface, which means the child |
| 234 // frame renderer has changed its output surface, or size, or scale factor. | 234 // frame renderer has changed its output surface, or size, or scale factor. |
| 235 if (output_surface_id != last_output_surface_id_ && surface_factory_) { | 235 if (output_surface_id != last_output_surface_id_ && surface_factory_) { |
| 236 surface_factory_->Destroy(surface_id_); | 236 surface_factory_->Destroy(surface_id_); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 return NULL; | 544 return NULL; |
| 545 } | 545 } |
| 546 #endif | 546 #endif |
| 547 | 547 |
| 548 void RenderWidgetHostViewGuest::DestroyGuestView() { | 548 void RenderWidgetHostViewGuest::DestroyGuestView() { |
| 549 host_->SetView(NULL); | 549 host_->SetView(NULL); |
| 550 host_ = NULL; | 550 host_ = NULL; |
| 551 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 551 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 552 } | 552 } |
| 553 | 553 |
| 554 bool RenderWidgetHostViewGuest::CanDispatchToConsumer( | |
| 555 ui::GestureConsumer* consumer) { | |
| 556 CHECK_EQ(static_cast<RenderWidgetHostViewGuest*>(consumer), this); | |
| 557 return true; | |
| 558 } | |
| 559 | |
| 560 void RenderWidgetHostViewGuest::DispatchGestureEvent( | |
| 561 ui::GestureEvent* event) { | |
| 562 ForwardGestureEventToRenderer(event); | |
| 563 } | |
| 564 | |
| 565 void RenderWidgetHostViewGuest::DispatchCancelTouchEvent( | |
| 566 ui::TouchEvent* event) { | |
| 567 if (!host_) | |
| 568 return; | |
| 569 | |
| 570 blink::WebTouchEvent cancel_event; | |
| 571 // TODO(rbyers): This event has no touches in it. Don't we need to know what | |
| 572 // touches are currently active in order to cancel them all properly? | |
| 573 WebTouchEventTraits::ResetType(blink::WebInputEvent::TouchCancel, | |
| 574 event->time_stamp().InSecondsF(), | |
| 575 &cancel_event); | |
| 576 | |
| 577 host_->ForwardTouchEventWithLatencyInfo(cancel_event, *event->latency()); | |
| 578 } | |
| 579 | |
| 580 bool RenderWidgetHostViewGuest::ForwardGestureEventToRenderer( | 554 bool RenderWidgetHostViewGuest::ForwardGestureEventToRenderer( |
| 581 ui::GestureEvent* gesture) { | 555 ui::GestureEvent* gesture) { |
| 582 #if defined(USE_AURA) | 556 #if defined(USE_AURA) |
| 583 if (!host_) | 557 if (!host_) |
| 584 return false; | 558 return false; |
| 585 | 559 |
| 586 if ((gesture->type() == ui::ET_GESTURE_PINCH_BEGIN || | 560 if ((gesture->type() == ui::ET_GESTURE_PINCH_BEGIN || |
| 587 gesture->type() == ui::ET_GESTURE_PINCH_UPDATE || | 561 gesture->type() == ui::ET_GESTURE_PINCH_UPDATE || |
| 588 gesture->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) { | 562 gesture->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) { |
| 589 return true; | 563 return true; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate && | 691 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate && |
| 718 gesture_event.data.scrollUpdate.inertial) { | 692 gesture_event.data.scrollUpdate.inertial) { |
| 719 return; | 693 return; |
| 720 } | 694 } |
| 721 host_->ForwardGestureEvent(gesture_event); | 695 host_->ForwardGestureEvent(gesture_event); |
| 722 return; | 696 return; |
| 723 } | 697 } |
| 724 } | 698 } |
| 725 | 699 |
| 726 } // namespace content | 700 } // namespace content |
| OLD | NEW |