Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2014 Opera Software ASA. All rights reserved. | 3 * Copyright (C) 2014 Opera Software ASA. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 #include "web/ChromeClientImpl.h" | 105 #include "web/ChromeClientImpl.h" |
| 106 #include "web/WebDataSourceImpl.h" | 106 #include "web/WebDataSourceImpl.h" |
| 107 #include "web/WebInputEventConversion.h" | 107 #include "web/WebInputEventConversion.h" |
| 108 #include "web/WebLocalFrameImpl.h" | 108 #include "web/WebLocalFrameImpl.h" |
| 109 #include "web/WebViewImpl.h" | 109 #include "web/WebViewImpl.h" |
| 110 | 110 |
| 111 namespace blink { | 111 namespace blink { |
| 112 | 112 |
| 113 // Public methods -------------------------------------------------------------- | 113 // Public methods -------------------------------------------------------------- |
| 114 | 114 |
| 115 void WebPluginContainerImpl::SetFrameRect(const IntRect& frame_rect) { | 115 void WebPluginContainerImpl::SetParent(FrameView* parent) { |
| 116 FrameViewBase::SetFrameRect(frame_rect); | 116 DCHECK(!parent || !parent_); |
| 117 bool old_parent_visible = parent_ && parent_->IsVisible(); | |
| 118 bool new_parent_visible = parent && parent->IsVisible(); | |
| 119 // Update visibility if plugin is visible and parent visibility changes. | |
|
dcheng
2017/04/12 00:06:39
Can the parent change visibility without changing
joelhockey
2017/04/12 04:33:00
I'm pretty sure that yes, parent can change vis.
| |
| 120 if (visible_ && web_plugin_ && (new_parent_visible != old_parent_visible)) | |
| 121 web_plugin_->UpdateVisibility(new_parent_visible); | |
| 122 parent_ = parent; | |
| 123 } | |
| 124 | |
| 125 FrameView* WebPluginContainerImpl::Parent() const { | |
| 126 return parent_; | |
| 117 } | 127 } |
| 118 | 128 |
| 119 void WebPluginContainerImpl::UpdateAllLifecyclePhases() { | 129 void WebPluginContainerImpl::UpdateAllLifecyclePhases() { |
| 120 if (!web_plugin_) | 130 if (!web_plugin_) |
| 121 return; | 131 return; |
| 122 | 132 |
| 123 web_plugin_->UpdateAllLifecyclePhases(); | 133 web_plugin_->UpdateAllLifecyclePhases(); |
| 124 } | 134 } |
| 125 | 135 |
| 126 void WebPluginContainerImpl::Paint(GraphicsContext& context, | 136 void WebPluginContainerImpl::Paint(GraphicsContext& context, |
| 127 const CullRect& cull_rect) const { | 137 const CullRect& cull_rect) const { |
| 128 if (!Parent()) | 138 if (!parent_) |
| 129 return; | 139 return; |
| 130 | 140 |
| 131 // Don't paint anything if the plugin doesn't intersect. | 141 // Don't paint anything if the plugin doesn't intersect. |
| 132 if (!cull_rect.IntersectsCullRect(FrameRect())) | 142 if (!cull_rect.IntersectsCullRect(frame_rect_)) |
| 133 return; | 143 return; |
| 134 | 144 |
| 135 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && web_layer_) { | 145 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && web_layer_) { |
| 136 // With Slimming Paint v2, composited plugins should have their layers | 146 // With Slimming Paint v2, composited plugins should have their layers |
| 137 // inserted rather than invoking WebPlugin::paint. | 147 // inserted rather than invoking WebPlugin::paint. |
| 138 RecordForeignLayer(context, *element_->GetLayoutObject(), | 148 RecordForeignLayer(context, *element_->GetLayoutObject(), |
| 139 DisplayItem::kForeignLayerPlugin, web_layer_, Location(), | 149 DisplayItem::kForeignLayerPlugin, web_layer_, |
| 140 size()); | 150 frame_rect_.Location(), frame_rect_.size()); |
| 141 return; | 151 return; |
| 142 } | 152 } |
| 143 | 153 |
| 144 if (LayoutObjectDrawingRecorder::UseCachedDrawingIfPossible( | 154 if (LayoutObjectDrawingRecorder::UseCachedDrawingIfPossible( |
| 145 context, *element_->GetLayoutObject(), DisplayItem::Type::kWebPlugin)) | 155 context, *element_->GetLayoutObject(), DisplayItem::Type::kWebPlugin)) |
| 146 return; | 156 return; |
| 147 | 157 |
| 148 LayoutObjectDrawingRecorder drawing_recorder( | 158 LayoutObjectDrawingRecorder drawing_recorder( |
| 149 context, *element_->GetLayoutObject(), DisplayItem::Type::kWebPlugin, | 159 context, *element_->GetLayoutObject(), DisplayItem::Type::kWebPlugin, |
| 150 cull_rect.rect_); | 160 cull_rect.rect_); |
| 151 context.Save(); | 161 context.Save(); |
| 152 | 162 |
| 153 DCHECK(Parent()->IsFrameView()); | |
| 154 FrameView* view = ToFrameView(Parent()); | |
| 155 | |
| 156 // The plugin is positioned in the root frame's coordinates, so it needs to | 163 // The plugin is positioned in the root frame's coordinates, so it needs to |
| 157 // be painted in them too. | 164 // be painted in them too. |
| 158 IntPoint origin = view->ContentsToRootFrame(IntPoint(0, 0)); | 165 IntPoint origin = parent_->ContentsToRootFrame(IntPoint(0, 0)); |
| 159 context.Translate(static_cast<float>(-origin.X()), | 166 context.Translate(static_cast<float>(-origin.X()), |
| 160 static_cast<float>(-origin.Y())); | 167 static_cast<float>(-origin.Y())); |
| 161 | 168 |
| 162 WebCanvas* canvas = context.Canvas(); | 169 WebCanvas* canvas = context.Canvas(); |
| 163 | 170 |
| 164 IntRect window_rect = view->ContentsToRootFrame(cull_rect.rect_); | 171 IntRect window_rect = parent_->ContentsToRootFrame(cull_rect.rect_); |
| 165 web_plugin_->Paint(canvas, window_rect); | 172 web_plugin_->Paint(canvas, window_rect); |
| 166 | 173 |
| 167 context.Restore(); | 174 context.Restore(); |
| 168 } | 175 } |
| 169 | 176 |
| 170 void WebPluginContainerImpl::InvalidateRect(const IntRect& rect) { | 177 void WebPluginContainerImpl::InvalidateRect(const IntRect& rect) { |
| 171 if (!Parent()) | 178 if (!parent_) |
| 172 return; | 179 return; |
| 173 | 180 |
| 174 LayoutBox* layout_object = ToLayoutBox(element_->GetLayoutObject()); | 181 LayoutBox* layout_object = ToLayoutBox(element_->GetLayoutObject()); |
| 175 if (!layout_object) | 182 if (!layout_object) |
| 176 return; | 183 return; |
| 177 | 184 |
| 178 IntRect dirty_rect = rect; | 185 IntRect dirty_rect = rect; |
| 179 dirty_rect.Move( | 186 dirty_rect.Move( |
| 180 (layout_object->BorderLeft() + layout_object->PaddingLeft()).ToInt(), | 187 (layout_object->BorderLeft() + layout_object->PaddingLeft()).ToInt(), |
| 181 (layout_object->BorderTop() + layout_object->PaddingTop()).ToInt()); | 188 (layout_object->BorderTop() + layout_object->PaddingTop()).ToInt()); |
| 182 | 189 |
| 183 pending_invalidation_rect_.Unite(dirty_rect); | 190 pending_invalidation_rect_.Unite(dirty_rect); |
| 184 | 191 |
| 185 layout_object->SetMayNeedPaintInvalidation(); | 192 layout_object->SetMayNeedPaintInvalidation(); |
| 186 } | 193 } |
| 187 | 194 |
| 188 void WebPluginContainerImpl::SetFocused(bool focused, WebFocusType focus_type) { | 195 void WebPluginContainerImpl::SetFocused(bool focused, WebFocusType focus_type) { |
| 189 web_plugin_->UpdateFocus(focused, focus_type); | 196 web_plugin_->UpdateFocus(focused, focus_type); |
| 190 } | 197 } |
| 191 | 198 |
| 192 void WebPluginContainerImpl::Show() { | 199 void WebPluginContainerImpl::Show() { |
| 193 SetSelfVisible(true); | 200 visible_ = true; |
| 194 web_plugin_->UpdateVisibility(true); | 201 web_plugin_->UpdateVisibility(true); |
| 195 | |
| 196 FrameViewBase::Show(); | |
| 197 } | 202 } |
| 198 | 203 |
| 199 void WebPluginContainerImpl::Hide() { | 204 void WebPluginContainerImpl::Hide() { |
| 200 SetSelfVisible(false); | 205 visible_ = false; |
| 201 web_plugin_->UpdateVisibility(false); | 206 web_plugin_->UpdateVisibility(false); |
| 202 | |
| 203 FrameViewBase::Hide(); | |
| 204 } | 207 } |
| 205 | 208 |
| 206 void WebPluginContainerImpl::HandleEvent(Event* event) { | 209 void WebPluginContainerImpl::HandleEvent(Event* event) { |
| 207 // The events we pass are defined at: | 210 // The events we pass are defined at: |
| 208 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/structur es5.html#1000000 | 211 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/structur es5.html#1000000 |
| 209 // Don't take the documentation as truth, however. There are many cases | 212 // Don't take the documentation as truth, however. There are many cases |
| 210 // where mozilla behaves differently than the spec. | 213 // where mozilla behaves differently than the spec. |
| 211 if (event->IsMouseEvent()) | 214 if (event->IsMouseEvent()) |
| 212 HandleMouseEvent(ToMouseEvent(event)); | 215 HandleMouseEvent(ToMouseEvent(event)); |
| 213 else if (event->IsWheelEvent()) | 216 else if (event->IsWheelEvent()) |
| 214 HandleWheelEvent(ToWheelEvent(event)); | 217 HandleWheelEvent(ToWheelEvent(event)); |
| 215 else if (event->IsKeyboardEvent()) | 218 else if (event->IsKeyboardEvent()) |
| 216 HandleKeyboardEvent(ToKeyboardEvent(event)); | 219 HandleKeyboardEvent(ToKeyboardEvent(event)); |
| 217 else if (event->IsTouchEvent()) | 220 else if (event->IsTouchEvent()) |
| 218 HandleTouchEvent(ToTouchEvent(event)); | 221 HandleTouchEvent(ToTouchEvent(event)); |
| 219 else if (event->IsGestureEvent()) | 222 else if (event->IsGestureEvent()) |
| 220 HandleGestureEvent(ToGestureEvent(event)); | 223 HandleGestureEvent(ToGestureEvent(event)); |
| 221 else if (event->IsDragEvent() && web_plugin_->CanProcessDrag()) | 224 else if (event->IsDragEvent() && web_plugin_->CanProcessDrag()) |
| 222 HandleDragEvent(ToDragEvent(event)); | 225 HandleDragEvent(ToDragEvent(event)); |
| 223 | 226 |
| 224 // FIXME: it would be cleaner if FrameViewBase::handleEvent returned | 227 // FIXME: it would be cleaner if FrameViewBase::handleEvent returned |
| 225 // true/false and HTMLPluginElement called setDefaultHandled or | 228 // true/false and HTMLPluginElement called setDefaultHandled or |
| 226 // defaultEventHandler. | 229 // defaultEventHandler. |
| 227 if (!event->DefaultHandled()) | 230 if (!event->DefaultHandled()) |
| 228 element_->Node::DefaultEventHandler(event); | 231 element_->Node::DefaultEventHandler(event); |
| 229 } | 232 } |
| 230 | 233 |
| 231 void WebPluginContainerImpl::FrameRectsChanged() { | 234 void WebPluginContainerImpl::FrameRectsChanged() { |
| 232 FrameViewBase::FrameRectsChanged(); | |
| 233 ReportGeometry(); | 235 ReportGeometry(); |
| 234 } | 236 } |
| 235 | 237 |
| 236 void WebPluginContainerImpl::GeometryMayHaveChanged() { | 238 void WebPluginContainerImpl::GeometryMayHaveChanged() { |
| 237 FrameViewBase::GeometryMayHaveChanged(); | |
| 238 ReportGeometry(); | 239 ReportGeometry(); |
| 239 } | 240 } |
| 240 | 241 |
| 241 void WebPluginContainerImpl::EventListenersRemoved() { | 242 void WebPluginContainerImpl::EventListenersRemoved() { |
| 242 // We're no longer registered to receive touch events, so don't try to remove | 243 // We're no longer registered to receive touch events, so don't try to remove |
| 243 // the touch event handlers in our destructor. | 244 // the touch event handlers in our destructor. |
| 244 touch_event_request_type_ = kTouchEventRequestTypeNone; | 245 touch_event_request_type_ = kTouchEventRequestTypeNone; |
| 245 } | 246 } |
| 246 | 247 |
| 247 void WebPluginContainerImpl::SetParentVisible(bool parent_visible) { | |
| 248 // We override this function to make sure that geometry updates are sent | |
| 249 // over to the plugin. For e.g. when a plugin is instantiated it does not | |
| 250 // have a valid parent. As a result the first geometry update from webkit | |
| 251 // is ignored. This function is called when the plugin eventually gets a | |
| 252 // parent. | |
| 253 | |
| 254 if (IsParentVisible() == parent_visible) | |
| 255 return; // No change. | |
| 256 | |
| 257 FrameViewBase::SetParentVisible(parent_visible); | |
| 258 if (!IsSelfVisible()) | |
| 259 return; // This widget has explicitely been marked as not visible. | |
| 260 | |
| 261 if (web_plugin_) | |
| 262 web_plugin_->UpdateVisibility(IsVisible()); | |
| 263 } | |
| 264 | |
| 265 void WebPluginContainerImpl::SetPlugin(WebPlugin* plugin) { | 248 void WebPluginContainerImpl::SetPlugin(WebPlugin* plugin) { |
| 266 if (plugin == web_plugin_) | 249 if (plugin == web_plugin_) |
| 267 return; | 250 return; |
| 268 | 251 |
| 269 element_->ResetInstance(); | 252 element_->ResetInstance(); |
| 270 web_plugin_ = plugin; | 253 web_plugin_ = plugin; |
| 271 is_disposed_ = false; | 254 is_disposed_ = false; |
| 272 } | 255 } |
| 273 | 256 |
| 274 float WebPluginContainerImpl::DeviceScaleFactor() { | 257 float WebPluginContainerImpl::DeviceScaleFactor() { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 element_->DispatchEvent(event); | 389 element_->DispatchEvent(event); |
| 407 } | 390 } |
| 408 | 391 |
| 409 void WebPluginContainerImpl::EnqueueMessageEvent( | 392 void WebPluginContainerImpl::EnqueueMessageEvent( |
| 410 const WebDOMMessageEvent& event) { | 393 const WebDOMMessageEvent& event) { |
| 411 static_cast<Event*>(event)->SetTarget(element_); | 394 static_cast<Event*>(event)->SetTarget(element_); |
| 412 element_->GetExecutionContext()->GetEventQueue()->EnqueueEvent(event); | 395 element_->GetExecutionContext()->GetEventQueue()->EnqueueEvent(event); |
| 413 } | 396 } |
| 414 | 397 |
| 415 void WebPluginContainerImpl::Invalidate() { | 398 void WebPluginContainerImpl::Invalidate() { |
| 416 FrameViewBase::Invalidate(); | 399 InvalidateRect(IntRect(0, 0, frame_rect_.Width(), frame_rect_.Height())); |
| 417 } | 400 } |
| 418 | 401 |
| 419 void WebPluginContainerImpl::InvalidateRect(const WebRect& rect) { | 402 void WebPluginContainerImpl::InvalidateRect(const WebRect& rect) { |
| 420 InvalidateRect(static_cast<IntRect>(rect)); | 403 InvalidateRect(static_cast<IntRect>(rect)); |
| 421 } | 404 } |
| 422 | 405 |
| 423 void WebPluginContainerImpl::ScrollRect(const WebRect& rect) { | 406 void WebPluginContainerImpl::ScrollRect(const WebRect& rect) { |
| 424 InvalidateRect(rect); | 407 InvalidateRect(rect); |
| 425 } | 408 } |
| 426 | 409 |
| 427 void WebPluginContainerImpl::ScheduleAnimation() { | 410 void WebPluginContainerImpl::ScheduleAnimation() { |
| 428 if (auto* frame_view = element_->GetDocument().View()) | 411 if (auto* frame_view = element_->GetDocument().View()) |
| 429 frame_view->ScheduleAnimation(); | 412 frame_view->ScheduleAnimation(); |
| 430 } | 413 } |
| 431 | 414 |
| 432 void WebPluginContainerImpl::ReportGeometry() { | 415 void WebPluginContainerImpl::ReportGeometry() { |
| 433 // We cannot compute geometry without a parent or layoutObject. | 416 // We cannot compute geometry without a parent or layoutObject. |
| 434 if (!Parent() || !element_ || !element_->GetLayoutObject() || !web_plugin_) | 417 if (!parent_ || !element_ || !element_->GetLayoutObject() || !web_plugin_) |
| 435 return; | 418 return; |
| 436 | 419 |
| 437 IntRect window_rect, clip_rect, unobscured_rect; | 420 IntRect window_rect, clip_rect, unobscured_rect; |
| 438 Vector<IntRect> cut_out_rects; | 421 Vector<IntRect> cut_out_rects; |
| 439 CalculateGeometry(window_rect, clip_rect, unobscured_rect, cut_out_rects); | 422 CalculateGeometry(window_rect, clip_rect, unobscured_rect, cut_out_rects); |
| 440 web_plugin_->UpdateGeometry(window_rect, clip_rect, unobscured_rect, | 423 web_plugin_->UpdateGeometry(window_rect, clip_rect, unobscured_rect, |
| 441 cut_out_rects, IsVisible()); | 424 cut_out_rects, visible_); |
| 442 } | 425 } |
| 443 | 426 |
| 444 v8::Local<v8::Object> WebPluginContainerImpl::V8ObjectForElement() { | 427 v8::Local<v8::Object> WebPluginContainerImpl::V8ObjectForElement() { |
| 445 LocalFrame* frame = element_->GetDocument().GetFrame(); | 428 LocalFrame* frame = element_->GetDocument().GetFrame(); |
| 446 if (!frame) | 429 if (!frame) |
| 447 return v8::Local<v8::Object>(); | 430 return v8::Local<v8::Object>(); |
| 448 | 431 |
| 449 if (!element_->GetDocument().CanExecuteScripts(kNotAboutToExecuteScript)) | 432 if (!element_->GetDocument().CanExecuteScripts(kNotAboutToExecuteScript)) |
| 450 return v8::Local<v8::Object>(); | 433 return v8::Local<v8::Object>(); |
| 451 | 434 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 // we might be being disposed because the frame has already be deleted and | 495 // we might be being disposed because the frame has already be deleted and |
| 513 // then something else dropped the | 496 // then something else dropped the |
| 514 // last reference to the this object. | 497 // last reference to the this object. |
| 515 if (is_disposed_ || !element_) | 498 if (is_disposed_ || !element_) |
| 516 return false; | 499 return false; |
| 517 | 500 |
| 518 LocalFrame* frame = element_->GetDocument().GetFrame(); | 501 LocalFrame* frame = element_->GetDocument().GetFrame(); |
| 519 if (!frame) | 502 if (!frame) |
| 520 return false; | 503 return false; |
| 521 | 504 |
| 522 IntRect document_rect(X() + rect.x, Y() + rect.y, rect.width, rect.height); | 505 IntRect document_rect(frame_rect_.X() + rect.x, frame_rect_.Y() + rect.y, |
| 506 rect.width, rect.height); | |
| 523 // hitTestResultAtPoint() takes a padding rectangle. | 507 // hitTestResultAtPoint() takes a padding rectangle. |
| 524 // FIXME: We'll be off by 1 when the width or height is even. | 508 // FIXME: We'll be off by 1 when the width or height is even. |
| 525 LayoutPoint center = document_rect.Center(); | 509 LayoutPoint center = document_rect.Center(); |
| 526 // Make the rect we're checking (the point surrounded by padding rects) | 510 // Make the rect we're checking (the point surrounded by padding rects) |
| 527 // contained inside the requested rect. (Note that -1/2 is 0.) | 511 // contained inside the requested rect. (Note that -1/2 is 0.) |
| 528 LayoutSize padding((document_rect.Width() - 1) / 2, | 512 LayoutSize padding((document_rect.Width() - 1) / 2, |
| 529 (document_rect.Height() - 1) / 2); | 513 (document_rect.Height() - 1) / 2); |
| 530 HitTestResult result = frame->GetEventHandler().HitTestResultAtPoint( | 514 HitTestResult result = frame->GetEventHandler().HitTestResultAtPoint( |
| 531 center, | 515 center, |
| 532 HitTestRequest::kReadOnly | HitTestRequest::kActive | | 516 HitTestRequest::kReadOnly | HitTestRequest::kActive | |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 EventHandlerRegistry::kWheelEventBlocking); | 551 EventHandlerRegistry::kWheelEventBlocking); |
| 568 else | 552 else |
| 569 registry.DidRemoveEventHandler(*element_, | 553 registry.DidRemoveEventHandler(*element_, |
| 570 EventHandlerRegistry::kWheelEventBlocking); | 554 EventHandlerRegistry::kWheelEventBlocking); |
| 571 } | 555 } |
| 572 | 556 |
| 573 wants_wheel_events_ = wants_wheel_events; | 557 wants_wheel_events_ = wants_wheel_events; |
| 574 if (Page* page = element_->GetDocument().GetPage()) { | 558 if (Page* page = element_->GetDocument().GetPage()) { |
| 575 if (ScrollingCoordinator* scrolling_coordinator = | 559 if (ScrollingCoordinator* scrolling_coordinator = |
| 576 page->GetScrollingCoordinator()) { | 560 page->GetScrollingCoordinator()) { |
| 577 if (Parent() && Parent()->IsFrameView()) | 561 if (parent_) |
| 578 scrolling_coordinator->NotifyGeometryChanged(); | 562 scrolling_coordinator->NotifyGeometryChanged(); |
| 579 } | 563 } |
| 580 } | 564 } |
| 581 } | 565 } |
| 582 | 566 |
| 583 WebPoint WebPluginContainerImpl::RootFrameToLocalPoint( | 567 WebPoint WebPluginContainerImpl::RootFrameToLocalPoint( |
| 584 const WebPoint& point_in_root_frame) { | 568 const WebPoint& point_in_root_frame) { |
| 585 FrameView* view = ToFrameView(Parent()); | 569 if (!parent_) |
| 586 if (!view) | |
| 587 return point_in_root_frame; | 570 return point_in_root_frame; |
| 588 WebPoint point_in_content = view->RootFrameToContents(point_in_root_frame); | 571 WebPoint point_in_content = parent_->RootFrameToContents(point_in_root_frame); |
| 589 return RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal( | 572 return RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal( |
| 590 FloatPoint(point_in_content), kUseTransforms)); | 573 FloatPoint(point_in_content), kUseTransforms)); |
| 591 } | 574 } |
| 592 | 575 |
| 593 WebPoint WebPluginContainerImpl::LocalToRootFramePoint( | 576 WebPoint WebPluginContainerImpl::LocalToRootFramePoint( |
| 594 const WebPoint& point_in_local) { | 577 const WebPoint& point_in_local) { |
| 595 FrameView* view = ToFrameView(Parent()); | 578 if (!parent_) |
| 596 if (!view) | |
| 597 return point_in_local; | 579 return point_in_local; |
| 598 IntPoint absolute_point = | 580 IntPoint absolute_point = |
| 599 RoundedIntPoint(element_->GetLayoutObject()->LocalToAbsolute( | 581 RoundedIntPoint(element_->GetLayoutObject()->LocalToAbsolute( |
| 600 FloatPoint(point_in_local), kUseTransforms)); | 582 FloatPoint(point_in_local), kUseTransforms)); |
| 601 return view->ContentsToRootFrame(absolute_point); | 583 return parent_->ContentsToRootFrame(absolute_point); |
| 602 } | 584 } |
| 603 | 585 |
| 604 void WebPluginContainerImpl::DidReceiveResponse( | 586 void WebPluginContainerImpl::DidReceiveResponse( |
| 605 const ResourceResponse& response) { | 587 const ResourceResponse& response) { |
| 606 // Make sure that the plugin receives window geometry before data, or else | 588 // Make sure that the plugin receives window geometry before data, or else |
| 607 // plugins misbehave. | 589 // plugins misbehave. |
| 608 FrameRectsChanged(); | 590 FrameRectsChanged(); |
| 609 | 591 |
| 610 WrappedResourceResponse url_response(response); | 592 WrappedResourceResponse url_response(response); |
| 611 web_plugin_->DidReceiveResponse(url_response); | 593 web_plugin_->DidReceiveResponse(url_response); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 // Private methods ------------------------------------------------------------- | 647 // Private methods ------------------------------------------------------------- |
| 666 | 648 |
| 667 WebPluginContainerImpl::WebPluginContainerImpl(HTMLPlugInElement* element, | 649 WebPluginContainerImpl::WebPluginContainerImpl(HTMLPlugInElement* element, |
| 668 WebPlugin* web_plugin) | 650 WebPlugin* web_plugin) |
| 669 : ContextClient(element->GetDocument().GetFrame()), | 651 : ContextClient(element->GetDocument().GetFrame()), |
| 670 element_(element), | 652 element_(element), |
| 671 web_plugin_(web_plugin), | 653 web_plugin_(web_plugin), |
| 672 web_layer_(nullptr), | 654 web_layer_(nullptr), |
| 673 touch_event_request_type_(kTouchEventRequestTypeNone), | 655 touch_event_request_type_(kTouchEventRequestTypeNone), |
| 674 wants_wheel_events_(false), | 656 wants_wheel_events_(false), |
| 657 visible_(false), | |
| 675 is_disposed_(false) {} | 658 is_disposed_(false) {} |
| 676 | 659 |
| 677 WebPluginContainerImpl::~WebPluginContainerImpl() { | 660 WebPluginContainerImpl::~WebPluginContainerImpl() { |
| 678 // The plugin container must have been disposed of by now. | 661 // The plugin container must have been disposed of by now. |
| 679 DCHECK(!web_plugin_); | 662 DCHECK(!web_plugin_); |
| 680 } | 663 } |
| 681 | 664 |
| 682 void WebPluginContainerImpl::Dispose() { | 665 void WebPluginContainerImpl::Dispose() { |
| 683 is_disposed_ = true; | 666 is_disposed_ = true; |
| 684 | 667 |
| 685 RequestTouchEventType(kTouchEventRequestTypeNone); | 668 RequestTouchEventType(kTouchEventRequestTypeNone); |
| 686 SetWantsWheelEvents(false); | 669 SetWantsWheelEvents(false); |
| 687 | 670 |
| 688 if (web_plugin_) { | 671 if (web_plugin_) { |
| 689 CHECK(web_plugin_->Container() == this); | 672 CHECK(web_plugin_->Container() == this); |
| 690 web_plugin_->Destroy(); | 673 web_plugin_->Destroy(); |
| 691 web_plugin_ = nullptr; | 674 web_plugin_ = nullptr; |
| 692 } | 675 } |
| 693 | 676 |
| 694 if (web_layer_) { | 677 if (web_layer_) { |
| 695 GraphicsLayer::UnregisterContentsLayer(web_layer_); | 678 GraphicsLayer::UnregisterContentsLayer(web_layer_); |
| 696 web_layer_ = nullptr; | 679 web_layer_ = nullptr; |
| 697 } | 680 } |
| 698 } | 681 } |
| 699 | 682 |
| 700 DEFINE_TRACE(WebPluginContainerImpl) { | 683 DEFINE_TRACE(WebPluginContainerImpl) { |
| 684 visitor->Trace(parent_); | |
| 701 visitor->Trace(element_); | 685 visitor->Trace(element_); |
| 702 ContextClient::Trace(visitor); | 686 ContextClient::Trace(visitor); |
| 703 PluginView::Trace(visitor); | 687 PluginView::Trace(visitor); |
| 704 } | 688 } |
| 705 | 689 |
| 706 void WebPluginContainerImpl::HandleMouseEvent(MouseEvent* event) { | 690 void WebPluginContainerImpl::HandleMouseEvent(MouseEvent* event) { |
| 707 DCHECK(Parent()->IsFrameView()); | |
| 708 | |
| 709 // We cache the parent FrameView here as the plugin widget could be deleted | 691 // We cache the parent FrameView here as the plugin widget could be deleted |
| 710 // in the call to HandleEvent. See http://b/issue?id=1362948 | 692 // in the call to HandleEvent. See http://b/issue?id=1362948 |
| 711 FrameView* parent_view = ToFrameView(Parent()); | 693 FrameView* parent_view = parent_; |
| 712 | 694 |
| 713 WebMouseEventBuilder transformed_event( | 695 WebMouseEventBuilder transformed_event( |
| 714 ToFrameView(Parent()), LayoutItem(element_->GetLayoutObject()), *event); | 696 Parent(), LayoutItem(element_->GetLayoutObject()), *event); |
| 715 if (transformed_event.GetType() == WebInputEvent::kUndefined) | 697 if (transformed_event.GetType() == WebInputEvent::kUndefined) |
| 716 return; | 698 return; |
| 717 | 699 |
| 718 if (event->type() == EventTypeNames::mousedown) | 700 if (event->type() == EventTypeNames::mousedown) |
| 719 FocusPlugin(); | 701 FocusPlugin(); |
| 720 | 702 |
| 721 WebCursorInfo cursor_info; | 703 WebCursorInfo cursor_info; |
| 722 if (web_plugin_ && | 704 if (web_plugin_ && |
| 723 web_plugin_->HandleInputEvent(transformed_event, cursor_info) != | 705 web_plugin_->HandleInputEvent(transformed_event, cursor_info) != |
| 724 WebInputEventResult::kNotHandled) | 706 WebInputEventResult::kNotHandled) |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 749 drag_status = kWebDragStatusDrop; | 731 drag_status = kWebDragStatusDrop; |
| 750 | 732 |
| 751 if (drag_status == kWebDragStatusUnknown) | 733 if (drag_status == kWebDragStatusUnknown) |
| 752 return; | 734 return; |
| 753 | 735 |
| 754 DataTransfer* data_transfer = event->getDataTransfer(); | 736 DataTransfer* data_transfer = event->getDataTransfer(); |
| 755 WebDragData drag_data = data_transfer->GetDataObject()->ToWebDragData(); | 737 WebDragData drag_data = data_transfer->GetDataObject()->ToWebDragData(); |
| 756 WebDragOperationsMask drag_operation_mask = | 738 WebDragOperationsMask drag_operation_mask = |
| 757 static_cast<WebDragOperationsMask>(data_transfer->SourceOperation()); | 739 static_cast<WebDragOperationsMask>(data_transfer->SourceOperation()); |
| 758 WebPoint drag_screen_location(event->screenX(), event->screenY()); | 740 WebPoint drag_screen_location(event->screenX(), event->screenY()); |
| 759 WebPoint drag_location(event->AbsoluteLocation().X() - Location().X(), | 741 WebPoint drag_location( |
| 760 event->AbsoluteLocation().Y() - Location().Y()); | 742 event->AbsoluteLocation().X() - frame_rect_.Location().X(), |
| 743 event->AbsoluteLocation().Y() - frame_rect_.Location().Y()); | |
| 761 | 744 |
| 762 web_plugin_->HandleDragStatusUpdate(drag_status, drag_data, | 745 web_plugin_->HandleDragStatusUpdate(drag_status, drag_data, |
| 763 drag_operation_mask, drag_location, | 746 drag_operation_mask, drag_location, |
| 764 drag_screen_location); | 747 drag_screen_location); |
| 765 } | 748 } |
| 766 | 749 |
| 767 void WebPluginContainerImpl::HandleWheelEvent(WheelEvent* event) { | 750 void WebPluginContainerImpl::HandleWheelEvent(WheelEvent* event) { |
| 768 WebFloatPoint absolute_root_frame_location = | 751 WebFloatPoint absolute_root_frame_location = |
| 769 event->NativeEvent().PositionInRootFrame(); | 752 event->NativeEvent().PositionInRootFrame(); |
| 770 IntPoint local_point = | 753 IntPoint local_point = |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 876 WebInputEventResult::kNotHandled) { | 859 WebInputEventResult::kNotHandled) { |
| 877 event->SetDefaultHandled(); | 860 event->SetDefaultHandled(); |
| 878 return; | 861 return; |
| 879 } | 862 } |
| 880 | 863 |
| 881 // FIXME: Can a plugin change the cursor from a touch-event callback? | 864 // FIXME: Can a plugin change the cursor from a touch-event callback? |
| 882 } | 865 } |
| 883 | 866 |
| 884 void WebPluginContainerImpl::SynthesizeMouseEventIfPossible(TouchEvent* event) { | 867 void WebPluginContainerImpl::SynthesizeMouseEventIfPossible(TouchEvent* event) { |
| 885 WebMouseEventBuilder web_event( | 868 WebMouseEventBuilder web_event( |
| 886 ToFrameView(Parent()), LayoutItem(element_->GetLayoutObject()), *event); | 869 Parent(), LayoutItem(element_->GetLayoutObject()), *event); |
| 887 if (web_event.GetType() == WebInputEvent::kUndefined) | 870 if (web_event.GetType() == WebInputEvent::kUndefined) |
| 888 return; | 871 return; |
| 889 | 872 |
| 890 WebCursorInfo cursor_info; | 873 WebCursorInfo cursor_info; |
| 891 if (web_plugin_->HandleInputEvent(web_event, cursor_info) != | 874 if (web_plugin_->HandleInputEvent(web_event, cursor_info) != |
| 892 WebInputEventResult::kNotHandled) | 875 WebInputEventResult::kNotHandled) |
| 893 event->SetDefaultHandled(); | 876 event->SetDefaultHandled(); |
| 894 } | 877 } |
| 895 | 878 |
| 896 void WebPluginContainerImpl::FocusPlugin() { | 879 void WebPluginContainerImpl::FocusPlugin() { |
| 897 LocalFrame& containing_frame = ToFrameView(Parent())->GetFrame(); | 880 LocalFrame& containing_frame = parent_->GetFrame(); |
| 898 if (Page* current_page = containing_frame.GetPage()) | 881 if (Page* current_page = containing_frame.GetPage()) |
| 899 current_page->GetFocusController().SetFocusedElement(element_, | 882 current_page->GetFocusController().SetFocusedElement(element_, |
| 900 &containing_frame); | 883 &containing_frame); |
| 901 else | 884 else |
| 902 containing_frame.GetDocument()->SetFocusedElement( | 885 containing_frame.GetDocument()->SetFocusedElement( |
| 903 element_, FocusParams(SelectionBehaviorOnFocus::kNone, | 886 element_, FocusParams(SelectionBehaviorOnFocus::kNone, |
| 904 kWebFocusTypeNone, nullptr)); | 887 kWebFocusTypeNone, nullptr)); |
| 905 } | 888 } |
| 906 | 889 |
| 907 void WebPluginContainerImpl::IssuePaintInvalidations() { | 890 void WebPluginContainerImpl::IssuePaintInvalidations() { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 929 unclipped_int_local_rect = IntRect(); | 912 unclipped_int_local_rect = IntRect(); |
| 930 return; | 913 return; |
| 931 } | 914 } |
| 932 | 915 |
| 933 LayoutView* root_view = element_->GetDocument().View()->GetLayoutView(); | 916 LayoutView* root_view = element_->GetDocument().View()->GetLayoutView(); |
| 934 while (root_view->GetFrame()->OwnerLayoutObject()) | 917 while (root_view->GetFrame()->OwnerLayoutObject()) |
| 935 root_view = root_view->GetFrame()->OwnerLayoutObject()->View(); | 918 root_view = root_view->GetFrame()->OwnerLayoutObject()->View(); |
| 936 | 919 |
| 937 LayoutBox* box = ToLayoutBox(owner_element->GetLayoutObject()); | 920 LayoutBox* box = ToLayoutBox(owner_element->GetLayoutObject()); |
| 938 | 921 |
| 939 // Note: frameRect() for this plugin is equal to contentBoxRect, mapped to the | 922 // Note: FrameRect() for this plugin is equal to contentBoxRect, mapped to the |
| 940 // containing view space, and rounded off. | 923 // containing view space, and rounded off. |
| 941 // See LayoutPart.cpp::updateGeometryInternal. To remove the lossy | 924 // See LayoutPart.cpp::updateGeometryInternal. To remove the lossy |
| 942 // effect of rounding off, use contentBoxRect directly. | 925 // effect of rounding off, use contentBoxRect directly. |
| 943 LayoutRect unclipped_absolute_rect(box->ContentBoxRect()); | 926 LayoutRect unclipped_absolute_rect(box->ContentBoxRect()); |
| 944 box->MapToVisualRectInAncestorSpace(root_view, unclipped_absolute_rect); | 927 box->MapToVisualRectInAncestorSpace(root_view, unclipped_absolute_rect); |
| 945 | 928 |
| 946 // The frameRect is already in absolute space of the local frame to the | 929 // The frameRect is already in absolute space of the local frame to the |
| 947 // plugin. | 930 // plugin. |
| 948 window_rect = FrameRect(); | 931 window_rect = frame_rect_; |
| 949 // Map up to the root frame. | 932 // Map up to the root frame. |
| 950 LayoutRect layout_window_rect = | 933 LayoutRect layout_window_rect = |
| 951 LayoutRect(element_->GetDocument() | 934 LayoutRect(element_->GetDocument() |
| 952 .View() | 935 .View() |
| 953 ->GetLayoutViewItem() | 936 ->GetLayoutViewItem() |
| 954 .LocalToAbsoluteQuad(FloatQuad(FloatRect(FrameRect())), | 937 .LocalToAbsoluteQuad(FloatQuad(FloatRect(frame_rect_)), |
| 955 kTraverseDocumentBoundaries) | 938 kTraverseDocumentBoundaries) |
| 956 .BoundingBox()); | 939 .BoundingBox()); |
| 957 // Finally, adjust for scrolling of the root frame, which the above does not | 940 // Finally, adjust for scrolling of the root frame, which the above does not |
| 958 // take into account. | 941 // take into account. |
| 959 layout_window_rect.MoveBy(-root_view->ViewRect().Location()); | 942 layout_window_rect.MoveBy(-root_view->ViewRect().Location()); |
| 960 window_rect = PixelSnappedIntRect(layout_window_rect); | 943 window_rect = PixelSnappedIntRect(layout_window_rect); |
| 961 | 944 |
| 962 LayoutRect layout_clipped_local_rect = unclipped_absolute_rect; | 945 LayoutRect layout_clipped_local_rect = unclipped_absolute_rect; |
| 963 LayoutRect unclipped_layout_local_rect = layout_clipped_local_rect; | 946 LayoutRect unclipped_layout_local_rect = layout_clipped_local_rect; |
| 964 layout_clipped_local_rect.Intersect( | 947 layout_clipped_local_rect.Intersect( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 988 // FIXME: Can we just check m_element->document().isActive() ? | 971 // FIXME: Can we just check m_element->document().isActive() ? |
| 989 if (!element_->GetLayoutObject() | 972 if (!element_->GetLayoutObject() |
| 990 ->GetDocument() | 973 ->GetDocument() |
| 991 .GetLayoutViewItem() | 974 .GetLayoutViewItem() |
| 992 .IsNull()) { | 975 .IsNull()) { |
| 993 // Take our element and get the clip rect from the enclosing layer and | 976 // Take our element and get the clip rect from the enclosing layer and |
| 994 // frame view. | 977 // frame view. |
| 995 ComputeClipRectsForPlugin(element_, window_rect, clip_rect, | 978 ComputeClipRectsForPlugin(element_, window_rect, clip_rect, |
| 996 unobscured_rect); | 979 unobscured_rect); |
| 997 } | 980 } |
| 998 GetPluginOcclusions(element_, this->Parent(), FrameRect(), cut_out_rects); | 981 GetPluginOcclusions(element_, parent_, frame_rect_, cut_out_rects); |
| 999 // Convert to the plugin position. | 982 // Convert to the plugin position. |
| 1000 for (size_t i = 0; i < cut_out_rects.size(); i++) | 983 for (size_t i = 0; i < cut_out_rects.size(); i++) |
| 1001 cut_out_rects[i].Move(-FrameRect().X(), -FrameRect().Y()); | 984 cut_out_rects[i].Move(-frame_rect_.X(), -frame_rect_.Y()); |
| 1002 } | 985 } |
| 1003 | 986 |
| 1004 } // namespace blink | 987 } // namespace blink |
| OLD | NEW |