Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 46 } | 48 } |
| 47 #endif // defined(USE_AURA) | 49 #endif // defined(USE_AURA) |
| 48 | 50 |
| 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), |
| 58 has_started_rendering_(false), | |
| 56 // |guest| is NULL during test. | 59 // |guest| is NULL during test. |
| 57 guest_(guest ? guest->AsWeakPtr() : base::WeakPtr<BrowserPluginGuest>()), | 60 guest_(guest ? guest->AsWeakPtr() : base::WeakPtr<BrowserPluginGuest>()), |
| 58 platform_view_(platform_view) { | 61 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 } | 62 } |
| 64 | 63 |
| 65 RenderWidgetHostViewGuest::~RenderWidgetHostViewGuest() { | 64 RenderWidgetHostViewGuest::~RenderWidgetHostViewGuest() { |
| 66 #if defined(USE_AURA) | |
| 67 gesture_recognizer_->RemoveGestureEventHelper(this); | |
| 68 #endif // defined(USE_AURA) | |
| 69 } | 65 } |
| 70 | 66 |
| 71 bool RenderWidgetHostViewGuest::OnMessageReceivedFromEmbedder( | 67 bool RenderWidgetHostViewGuest::OnMessageReceivedFromEmbedder( |
| 72 const IPC::Message& message, | 68 const IPC::Message& message, |
| 73 RenderWidgetHostImpl* embedder) { | 69 RenderWidgetHostImpl* embedder) { |
| 74 bool handled = true; | 70 bool handled = true; |
| 75 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(RenderWidgetHostViewGuest, message, | 71 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(RenderWidgetHostViewGuest, message, |
| 76 embedder) | 72 embedder) |
| 77 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, | 73 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, |
| 78 OnHandleInputEvent) | 74 OnHandleInputEvent) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 122 |
| 127 bool RenderWidgetHostViewGuest::HasFocus() const { | 123 bool RenderWidgetHostViewGuest::HasFocus() const { |
| 128 if (!guest_) | 124 if (!guest_) |
| 129 return false; | 125 return false; |
| 130 return guest_->focused(); | 126 return guest_->focused(); |
| 131 } | 127 } |
| 132 | 128 |
| 133 #if defined(USE_AURA) | 129 #if defined(USE_AURA) |
| 134 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent( | 130 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent( |
| 135 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { | 131 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { |
| 136 // TODO(fsamuel): Currently we will only take this codepath if the guest has | 132 // Since all ProcessAckedTouchEvent() uses is the event id, don't pass the |
|
tdresser
2015/11/04 19:24:17
Let's call this
TODO(tdresser):
wjmaclean
2015/11/05 14:55:46
Done.
| |
| 137 // requested touch events. A better solution is to always forward touchpresses | 133 // full event object here. https://crbug.com/550581. |
| 138 // to the embedder process to target a BrowserPlugin, and then route all | 134 GetOwnerRenderWidgetHostView()->ProcessAckedTouchEvent(touch, ack_result); |
| 139 // subsequent touch points of that touchdown to the appropriate guest until | |
| 140 // that touch point is released. | |
| 141 ScopedVector<ui::TouchEvent> events; | |
| 142 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events, LOCAL_COORDINATES)) | |
| 143 return; | |
| 144 | |
| 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 } | |
| 157 } | 135 } |
| 158 #endif | 136 #endif |
| 159 | 137 |
| 138 void RenderWidgetHostViewGuest::ProcessTouchEvent( | |
| 139 const blink::WebTouchEvent& event, | |
| 140 const ui::LatencyInfo& latency) { | |
| 141 host_->ForwardTouchEventWithLatencyInfo(event, latency); | |
| 142 } | |
| 143 | |
| 160 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const { | 144 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const { |
| 161 if (!guest_) | 145 if (!guest_) |
| 162 return gfx::Rect(); | 146 return gfx::Rect(); |
| 163 | 147 |
| 164 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView(); | 148 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView(); |
| 165 gfx::Rect embedder_bounds; | 149 gfx::Rect embedder_bounds; |
| 166 if (rwhv) | 150 if (rwhv) |
| 167 embedder_bounds = rwhv->GetViewBounds(); | 151 embedder_bounds = rwhv->GetViewBounds(); |
| 168 return gfx::Rect( | 152 return gfx::Rect( |
| 169 guest_->GetScreenCoordinates(embedder_bounds.origin()), size_); | 153 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 | 201 // When not using surfaces, the frame just gets proxied to |
| 218 // the embedder's renderer to be composited. | 202 // the embedder's renderer to be composited. |
| 219 if (!frame->delegated_frame_data || !use_surfaces_) { | 203 if (!frame->delegated_frame_data || !use_surfaces_) { |
| 220 guest_->SwapCompositorFrame(output_surface_id, | 204 guest_->SwapCompositorFrame(output_surface_id, |
| 221 host_->GetProcess()->GetID(), | 205 host_->GetProcess()->GetID(), |
| 222 host_->GetRoutingID(), | 206 host_->GetRoutingID(), |
| 223 frame.Pass()); | 207 frame.Pass()); |
| 224 return; | 208 return; |
| 225 } | 209 } |
| 226 | 210 |
| 211 if (!has_started_rendering_) { | |
| 212 // We need to register again now that we've started rendering, since when | |
| 213 // we originally registered our WebContents may not have been attached | |
| 214 // to the OuterWebContents. | |
| 215 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { | |
| 216 RenderWidgetHostInputEventRouter* event_router = | |
| 217 host_->delegate()->GetInputEventRouter(); | |
| 218 if (!event_router->is_registered(GetSurfaceIdNamespace())) | |
| 219 event_router->AddSurfaceIdNamespaceOwner(GetSurfaceIdNamespace(), this); | |
| 220 } | |
| 221 has_started_rendering_ = true; | |
| 222 } | |
| 223 | |
| 227 cc::RenderPass* root_pass = | 224 cc::RenderPass* root_pass = |
| 228 frame->delegated_frame_data->render_pass_list.back(); | 225 frame->delegated_frame_data->render_pass_list.back(); |
| 229 | 226 |
| 230 gfx::Size frame_size = root_pass->output_rect.size(); | 227 gfx::Size frame_size = root_pass->output_rect.size(); |
| 231 float scale_factor = frame->metadata.device_scale_factor; | 228 float scale_factor = frame->metadata.device_scale_factor; |
| 232 | 229 |
| 233 // Check whether we need to recreate the cc::Surface, which means the child | 230 // 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. | 231 // frame renderer has changed its output surface, or size, or scale factor. |
| 235 if (output_surface_id != last_output_surface_id_ && surface_factory_) { | 232 if (output_surface_id != last_output_surface_id_ && surface_factory_) { |
| 236 surface_factory_->Destroy(surface_id_); | 233 surface_factory_->Destroy(surface_id_); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 return NULL; | 541 return NULL; |
| 545 } | 542 } |
| 546 #endif | 543 #endif |
| 547 | 544 |
| 548 void RenderWidgetHostViewGuest::DestroyGuestView() { | 545 void RenderWidgetHostViewGuest::DestroyGuestView() { |
| 549 host_->SetView(NULL); | 546 host_->SetView(NULL); |
| 550 host_ = NULL; | 547 host_ = NULL; |
| 551 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 548 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 552 } | 549 } |
| 553 | 550 |
| 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( | 551 bool RenderWidgetHostViewGuest::ForwardGestureEventToRenderer( |
| 581 ui::GestureEvent* gesture) { | 552 ui::GestureEvent* gesture) { |
| 582 #if defined(USE_AURA) | 553 #if defined(USE_AURA) |
| 583 if (!host_) | 554 if (!host_) |
| 584 return false; | 555 return false; |
| 585 | 556 |
| 586 if ((gesture->type() == ui::ET_GESTURE_PINCH_BEGIN || | 557 if ((gesture->type() == ui::ET_GESTURE_PINCH_BEGIN || |
| 587 gesture->type() == ui::ET_GESTURE_PINCH_UPDATE || | 558 gesture->type() == ui::ET_GESTURE_PINCH_UPDATE || |
| 588 gesture->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) { | 559 gesture->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) { |
| 589 return true; | 560 return true; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate && | 688 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate && |
| 718 gesture_event.data.scrollUpdate.inertial) { | 689 gesture_event.data.scrollUpdate.inertial) { |
| 719 return; | 690 return; |
| 720 } | 691 } |
| 721 host_->ForwardGestureEvent(gesture_event); | 692 host_->ForwardGestureEvent(gesture_event); |
| 722 return; | 693 return; |
| 723 } | 694 } |
| 724 } | 695 } |
| 725 | 696 |
| 726 } // namespace content | 697 } // namespace content |
| OLD | NEW |