Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: third_party/WebKit/Source/web/WebPluginContainerImpl.cpp

Issue 2814643003: Remove FrameViewBase as base class of PluginView. (Closed)
Patch Set: Address final comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/web/WebPluginContainerImpl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (!parent || !parent->IsVisible())
118 SetParentVisible(false);
119 parent_ = parent;
120 if (parent && parent->IsVisible())
121 SetParentVisible(true);
117 } 122 }
118 123
119 void WebPluginContainerImpl::UpdateAllLifecyclePhases() { 124 void WebPluginContainerImpl::UpdateAllLifecyclePhases() {
120 if (!web_plugin_) 125 if (!web_plugin_)
121 return; 126 return;
122 127
123 web_plugin_->UpdateAllLifecyclePhases(); 128 web_plugin_->UpdateAllLifecyclePhases();
124 } 129 }
125 130
126 void WebPluginContainerImpl::Paint(GraphicsContext& context, 131 void WebPluginContainerImpl::Paint(GraphicsContext& context,
127 const CullRect& cull_rect) const { 132 const CullRect& cull_rect) const {
128 if (!Parent()) 133 if (!parent_)
129 return; 134 return;
130 135
131 // Don't paint anything if the plugin doesn't intersect. 136 // Don't paint anything if the plugin doesn't intersect.
132 if (!cull_rect.IntersectsCullRect(FrameRect())) 137 if (!cull_rect.IntersectsCullRect(frame_rect_))
133 return; 138 return;
134 139
135 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && web_layer_) { 140 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && web_layer_) {
136 // With Slimming Paint v2, composited plugins should have their layers 141 // With Slimming Paint v2, composited plugins should have their layers
137 // inserted rather than invoking WebPlugin::paint. 142 // inserted rather than invoking WebPlugin::paint.
138 RecordForeignLayer(context, *element_->GetLayoutObject(), 143 RecordForeignLayer(context, *element_->GetLayoutObject(),
139 DisplayItem::kForeignLayerPlugin, web_layer_, Location(), 144 DisplayItem::kForeignLayerPlugin, web_layer_,
140 Size()); 145 frame_rect_.Location(), frame_rect_.Size());
141 return; 146 return;
142 } 147 }
143 148
144 if (LayoutObjectDrawingRecorder::UseCachedDrawingIfPossible( 149 if (LayoutObjectDrawingRecorder::UseCachedDrawingIfPossible(
145 context, *element_->GetLayoutObject(), DisplayItem::Type::kWebPlugin)) 150 context, *element_->GetLayoutObject(), DisplayItem::Type::kWebPlugin))
146 return; 151 return;
147 152
148 LayoutObjectDrawingRecorder drawing_recorder( 153 LayoutObjectDrawingRecorder drawing_recorder(
149 context, *element_->GetLayoutObject(), DisplayItem::Type::kWebPlugin, 154 context, *element_->GetLayoutObject(), DisplayItem::Type::kWebPlugin,
150 cull_rect.rect_); 155 cull_rect.rect_);
151 context.Save(); 156 context.Save();
152 157
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 158 // The plugin is positioned in the root frame's coordinates, so it needs to
157 // be painted in them too. 159 // be painted in them too.
158 IntPoint origin = view->ContentsToRootFrame(IntPoint(0, 0)); 160 IntPoint origin = parent_->ContentsToRootFrame(IntPoint(0, 0));
159 context.Translate(static_cast<float>(-origin.X()), 161 context.Translate(static_cast<float>(-origin.X()),
160 static_cast<float>(-origin.Y())); 162 static_cast<float>(-origin.Y()));
161 163
162 WebCanvas* canvas = context.Canvas(); 164 WebCanvas* canvas = context.Canvas();
163 165
164 IntRect window_rect = view->ContentsToRootFrame(cull_rect.rect_); 166 IntRect window_rect = parent_->ContentsToRootFrame(cull_rect.rect_);
165 web_plugin_->Paint(canvas, window_rect); 167 web_plugin_->Paint(canvas, window_rect);
166 168
167 context.Restore(); 169 context.Restore();
168 } 170 }
169 171
170 void WebPluginContainerImpl::InvalidateRect(const IntRect& rect) { 172 void WebPluginContainerImpl::InvalidateRect(const IntRect& rect) {
171 if (!Parent()) 173 if (!parent_)
172 return; 174 return;
173 175
174 LayoutBox* layout_object = ToLayoutBox(element_->GetLayoutObject()); 176 LayoutBox* layout_object = ToLayoutBox(element_->GetLayoutObject());
175 if (!layout_object) 177 if (!layout_object)
176 return; 178 return;
177 179
178 IntRect dirty_rect = rect; 180 IntRect dirty_rect = rect;
179 dirty_rect.Move( 181 dirty_rect.Move(
180 (layout_object->BorderLeft() + layout_object->PaddingLeft()).ToInt(), 182 (layout_object->BorderLeft() + layout_object->PaddingLeft()).ToInt(),
181 (layout_object->BorderTop() + layout_object->PaddingTop()).ToInt()); 183 (layout_object->BorderTop() + layout_object->PaddingTop()).ToInt());
182 184
183 pending_invalidation_rect_.Unite(dirty_rect); 185 pending_invalidation_rect_.Unite(dirty_rect);
184 186
185 layout_object->SetMayNeedPaintInvalidation(); 187 layout_object->SetMayNeedPaintInvalidation();
186 } 188 }
187 189
188 void WebPluginContainerImpl::SetFocused(bool focused, WebFocusType focus_type) { 190 void WebPluginContainerImpl::SetFocused(bool focused, WebFocusType focus_type) {
189 web_plugin_->UpdateFocus(focused, focus_type); 191 web_plugin_->UpdateFocus(focused, focus_type);
190 } 192 }
191 193
192 void WebPluginContainerImpl::Show() { 194 void WebPluginContainerImpl::Show() {
193 SetSelfVisible(true); 195 self_visible_ = true;
194 web_plugin_->UpdateVisibility(true); 196 web_plugin_->UpdateVisibility(true);
195
196 FrameViewBase::Show();
197 } 197 }
198 198
199 void WebPluginContainerImpl::Hide() { 199 void WebPluginContainerImpl::Hide() {
200 SetSelfVisible(false); 200 self_visible_ = false;
201 web_plugin_->UpdateVisibility(false); 201 web_plugin_->UpdateVisibility(false);
202
203 FrameViewBase::Hide();
204 } 202 }
205 203
206 void WebPluginContainerImpl::HandleEvent(Event* event) { 204 void WebPluginContainerImpl::HandleEvent(Event* event) {
207 // The events we pass are defined at: 205 // The events we pass are defined at:
208 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/structur es5.html#1000000 206 // 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 207 // Don't take the documentation as truth, however. There are many cases
210 // where mozilla behaves differently than the spec. 208 // where mozilla behaves differently than the spec.
211 if (event->IsMouseEvent()) 209 if (event->IsMouseEvent())
212 HandleMouseEvent(ToMouseEvent(event)); 210 HandleMouseEvent(ToMouseEvent(event));
213 else if (event->IsWheelEvent()) 211 else if (event->IsWheelEvent())
214 HandleWheelEvent(ToWheelEvent(event)); 212 HandleWheelEvent(ToWheelEvent(event));
215 else if (event->IsKeyboardEvent()) 213 else if (event->IsKeyboardEvent())
216 HandleKeyboardEvent(ToKeyboardEvent(event)); 214 HandleKeyboardEvent(ToKeyboardEvent(event));
217 else if (event->IsTouchEvent()) 215 else if (event->IsTouchEvent())
218 HandleTouchEvent(ToTouchEvent(event)); 216 HandleTouchEvent(ToTouchEvent(event));
219 else if (event->IsGestureEvent()) 217 else if (event->IsGestureEvent())
220 HandleGestureEvent(ToGestureEvent(event)); 218 HandleGestureEvent(ToGestureEvent(event));
221 else if (event->IsDragEvent() && web_plugin_->CanProcessDrag()) 219 else if (event->IsDragEvent() && web_plugin_->CanProcessDrag())
222 HandleDragEvent(ToDragEvent(event)); 220 HandleDragEvent(ToDragEvent(event));
223 221
224 // FIXME: it would be cleaner if FrameViewBase::handleEvent returned 222 // FIXME: it would be cleaner if FrameViewBase::handleEvent returned
225 // true/false and HTMLPluginElement called setDefaultHandled or 223 // true/false and HTMLPluginElement called setDefaultHandled or
226 // defaultEventHandler. 224 // defaultEventHandler.
227 if (!event->DefaultHandled()) 225 if (!event->DefaultHandled())
228 element_->Node::DefaultEventHandler(event); 226 element_->Node::DefaultEventHandler(event);
229 } 227 }
230 228
231 void WebPluginContainerImpl::FrameRectsChanged() { 229 void WebPluginContainerImpl::FrameRectsChanged() {
232 FrameViewBase::FrameRectsChanged();
233 ReportGeometry(); 230 ReportGeometry();
234 } 231 }
235 232
236 void WebPluginContainerImpl::GeometryMayHaveChanged() { 233 void WebPluginContainerImpl::GeometryMayHaveChanged() {
237 FrameViewBase::GeometryMayHaveChanged();
238 ReportGeometry(); 234 ReportGeometry();
239 } 235 }
240 236
241 void WebPluginContainerImpl::EventListenersRemoved() { 237 void WebPluginContainerImpl::EventListenersRemoved() {
242 // We're no longer registered to receive touch events, so don't try to remove 238 // We're no longer registered to receive touch events, so don't try to remove
243 // the touch event handlers in our destructor. 239 // the touch event handlers in our destructor.
244 touch_event_request_type_ = kTouchEventRequestTypeNone; 240 touch_event_request_type_ = kTouchEventRequestTypeNone;
245 } 241 }
246 242
247 void WebPluginContainerImpl::SetParentVisible(bool parent_visible) { 243 void WebPluginContainerImpl::SetParentVisible(bool parent_visible) {
248 // We override this function to make sure that geometry updates are sent 244 // 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 245 // 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 246 // 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 247 // is ignored. This function is called when the plugin eventually gets a
252 // parent. 248 // parent.
253 249
254 if (IsParentVisible() == parent_visible) 250 if (parent_visible_ == parent_visible)
255 return; // No change. 251 return; // No change.
256 252
257 FrameViewBase::SetParentVisible(parent_visible); 253 parent_visible_ = parent_visible;
258 if (!IsSelfVisible()) 254 if (!self_visible_)
259 return; // This widget has explicitely been marked as not visible. 255 return; // This widget has explicitely been marked as not visible.
260 256
261 if (web_plugin_) 257 if (web_plugin_)
262 web_plugin_->UpdateVisibility(IsVisible()); 258 web_plugin_->UpdateVisibility(parent_visible_ && self_visible_);
263 } 259 }
264 260
265 void WebPluginContainerImpl::SetPlugin(WebPlugin* plugin) { 261 void WebPluginContainerImpl::SetPlugin(WebPlugin* plugin) {
266 if (plugin == web_plugin_) 262 if (plugin == web_plugin_)
267 return; 263 return;
268 264
269 element_->ResetInstance(); 265 element_->ResetInstance();
270 web_plugin_ = plugin; 266 web_plugin_ = plugin;
271 is_disposed_ = false; 267 is_disposed_ = false;
272 } 268 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 element_->DispatchEvent(event); 402 element_->DispatchEvent(event);
407 } 403 }
408 404
409 void WebPluginContainerImpl::EnqueueMessageEvent( 405 void WebPluginContainerImpl::EnqueueMessageEvent(
410 const WebDOMMessageEvent& event) { 406 const WebDOMMessageEvent& event) {
411 static_cast<Event*>(event)->SetTarget(element_); 407 static_cast<Event*>(event)->SetTarget(element_);
412 element_->GetExecutionContext()->GetEventQueue()->EnqueueEvent(event); 408 element_->GetExecutionContext()->GetEventQueue()->EnqueueEvent(event);
413 } 409 }
414 410
415 void WebPluginContainerImpl::Invalidate() { 411 void WebPluginContainerImpl::Invalidate() {
416 FrameViewBase::Invalidate(); 412 InvalidateRect(IntRect(0, 0, frame_rect_.Width(), frame_rect_.Height()));
417 } 413 }
418 414
419 void WebPluginContainerImpl::InvalidateRect(const WebRect& rect) { 415 void WebPluginContainerImpl::InvalidateRect(const WebRect& rect) {
420 InvalidateRect(static_cast<IntRect>(rect)); 416 InvalidateRect(static_cast<IntRect>(rect));
421 } 417 }
422 418
423 void WebPluginContainerImpl::ScrollRect(const WebRect& rect) { 419 void WebPluginContainerImpl::ScrollRect(const WebRect& rect) {
424 InvalidateRect(rect); 420 InvalidateRect(rect);
425 } 421 }
426 422
427 void WebPluginContainerImpl::ScheduleAnimation() { 423 void WebPluginContainerImpl::ScheduleAnimation() {
428 if (auto* frame_view = element_->GetDocument().View()) 424 if (auto* frame_view = element_->GetDocument().View())
429 frame_view->ScheduleAnimation(); 425 frame_view->ScheduleAnimation();
430 } 426 }
431 427
432 void WebPluginContainerImpl::ReportGeometry() { 428 void WebPluginContainerImpl::ReportGeometry() {
433 // We cannot compute geometry without a parent or layoutObject. 429 // We cannot compute geometry without a parent or layoutObject.
434 if (!Parent() || !element_ || !element_->GetLayoutObject() || !web_plugin_) 430 if (!parent_ || !element_ || !element_->GetLayoutObject() || !web_plugin_)
435 return; 431 return;
436 432
437 IntRect window_rect, clip_rect, unobscured_rect; 433 IntRect window_rect, clip_rect, unobscured_rect;
438 Vector<IntRect> cut_out_rects; 434 Vector<IntRect> cut_out_rects;
439 CalculateGeometry(window_rect, clip_rect, unobscured_rect, cut_out_rects); 435 CalculateGeometry(window_rect, clip_rect, unobscured_rect, cut_out_rects);
440 web_plugin_->UpdateGeometry(window_rect, clip_rect, unobscured_rect, 436 web_plugin_->UpdateGeometry(window_rect, clip_rect, unobscured_rect,
441 cut_out_rects, IsVisible()); 437 cut_out_rects, self_visible_);
442 } 438 }
443 439
444 v8::Local<v8::Object> WebPluginContainerImpl::V8ObjectForElement() { 440 v8::Local<v8::Object> WebPluginContainerImpl::V8ObjectForElement() {
445 LocalFrame* frame = element_->GetDocument().GetFrame(); 441 LocalFrame* frame = element_->GetDocument().GetFrame();
446 if (!frame) 442 if (!frame)
447 return v8::Local<v8::Object>(); 443 return v8::Local<v8::Object>();
448 444
449 if (!element_->GetDocument().CanExecuteScripts(kNotAboutToExecuteScript)) 445 if (!element_->GetDocument().CanExecuteScripts(kNotAboutToExecuteScript))
450 return v8::Local<v8::Object>(); 446 return v8::Local<v8::Object>();
451 447
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // we might be being disposed because the frame has already be deleted and 508 // we might be being disposed because the frame has already be deleted and
513 // then something else dropped the 509 // then something else dropped the
514 // last reference to the this object. 510 // last reference to the this object.
515 if (is_disposed_ || !element_) 511 if (is_disposed_ || !element_)
516 return false; 512 return false;
517 513
518 LocalFrame* frame = element_->GetDocument().GetFrame(); 514 LocalFrame* frame = element_->GetDocument().GetFrame();
519 if (!frame) 515 if (!frame)
520 return false; 516 return false;
521 517
522 IntRect document_rect(X() + rect.x, Y() + rect.y, rect.width, rect.height); 518 IntRect document_rect(frame_rect_.X() + rect.x, frame_rect_.Y() + rect.y,
519 rect.width, rect.height);
523 // hitTestResultAtPoint() takes a padding rectangle. 520 // hitTestResultAtPoint() takes a padding rectangle.
524 // FIXME: We'll be off by 1 when the width or height is even. 521 // FIXME: We'll be off by 1 when the width or height is even.
525 LayoutPoint center = document_rect.Center(); 522 LayoutPoint center = document_rect.Center();
526 // Make the rect we're checking (the point surrounded by padding rects) 523 // Make the rect we're checking (the point surrounded by padding rects)
527 // contained inside the requested rect. (Note that -1/2 is 0.) 524 // contained inside the requested rect. (Note that -1/2 is 0.)
528 LayoutSize padding((document_rect.Width() - 1) / 2, 525 LayoutSize padding((document_rect.Width() - 1) / 2,
529 (document_rect.Height() - 1) / 2); 526 (document_rect.Height() - 1) / 2);
530 HitTestResult result = frame->GetEventHandler().HitTestResultAtPoint( 527 HitTestResult result = frame->GetEventHandler().HitTestResultAtPoint(
531 center, 528 center,
532 HitTestRequest::kReadOnly | HitTestRequest::kActive | 529 HitTestRequest::kReadOnly | HitTestRequest::kActive |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 EventHandlerRegistry::kWheelEventBlocking); 564 EventHandlerRegistry::kWheelEventBlocking);
568 else 565 else
569 registry.DidRemoveEventHandler(*element_, 566 registry.DidRemoveEventHandler(*element_,
570 EventHandlerRegistry::kWheelEventBlocking); 567 EventHandlerRegistry::kWheelEventBlocking);
571 } 568 }
572 569
573 wants_wheel_events_ = wants_wheel_events; 570 wants_wheel_events_ = wants_wheel_events;
574 if (Page* page = element_->GetDocument().GetPage()) { 571 if (Page* page = element_->GetDocument().GetPage()) {
575 if (ScrollingCoordinator* scrolling_coordinator = 572 if (ScrollingCoordinator* scrolling_coordinator =
576 page->GetScrollingCoordinator()) { 573 page->GetScrollingCoordinator()) {
577 if (Parent() && Parent()->IsFrameView()) 574 if (parent_)
578 scrolling_coordinator->NotifyGeometryChanged(); 575 scrolling_coordinator->NotifyGeometryChanged();
579 } 576 }
580 } 577 }
581 } 578 }
582 579
583 WebPoint WebPluginContainerImpl::RootFrameToLocalPoint( 580 WebPoint WebPluginContainerImpl::RootFrameToLocalPoint(
584 const WebPoint& point_in_root_frame) { 581 const WebPoint& point_in_root_frame) {
585 FrameView* view = ToFrameView(Parent()); 582 if (!parent_)
586 if (!view)
587 return point_in_root_frame; 583 return point_in_root_frame;
588 WebPoint point_in_content = view->RootFrameToContents(point_in_root_frame); 584 WebPoint point_in_content = parent_->RootFrameToContents(point_in_root_frame);
589 return RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal( 585 return RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal(
590 FloatPoint(point_in_content), kUseTransforms)); 586 FloatPoint(point_in_content), kUseTransforms));
591 } 587 }
592 588
593 WebPoint WebPluginContainerImpl::LocalToRootFramePoint( 589 WebPoint WebPluginContainerImpl::LocalToRootFramePoint(
594 const WebPoint& point_in_local) { 590 const WebPoint& point_in_local) {
595 FrameView* view = ToFrameView(Parent()); 591 if (!parent_)
596 if (!view)
597 return point_in_local; 592 return point_in_local;
598 IntPoint absolute_point = 593 IntPoint absolute_point =
599 RoundedIntPoint(element_->GetLayoutObject()->LocalToAbsolute( 594 RoundedIntPoint(element_->GetLayoutObject()->LocalToAbsolute(
600 FloatPoint(point_in_local), kUseTransforms)); 595 FloatPoint(point_in_local), kUseTransforms));
601 return view->ContentsToRootFrame(absolute_point); 596 return parent_->ContentsToRootFrame(absolute_point);
602 } 597 }
603 598
604 void WebPluginContainerImpl::DidReceiveResponse( 599 void WebPluginContainerImpl::DidReceiveResponse(
605 const ResourceResponse& response) { 600 const ResourceResponse& response) {
606 // Make sure that the plugin receives window geometry before data, or else 601 // Make sure that the plugin receives window geometry before data, or else
607 // plugins misbehave. 602 // plugins misbehave.
608 FrameRectsChanged(); 603 FrameRectsChanged();
609 604
610 WrappedResourceResponse url_response(response); 605 WrappedResourceResponse url_response(response);
611 web_plugin_->DidReceiveResponse(url_response); 606 web_plugin_->DidReceiveResponse(url_response);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 // Private methods ------------------------------------------------------------- 660 // Private methods -------------------------------------------------------------
666 661
667 WebPluginContainerImpl::WebPluginContainerImpl(HTMLPlugInElement* element, 662 WebPluginContainerImpl::WebPluginContainerImpl(HTMLPlugInElement* element,
668 WebPlugin* web_plugin) 663 WebPlugin* web_plugin)
669 : ContextClient(element->GetDocument().GetFrame()), 664 : ContextClient(element->GetDocument().GetFrame()),
670 element_(element), 665 element_(element),
671 web_plugin_(web_plugin), 666 web_plugin_(web_plugin),
672 web_layer_(nullptr), 667 web_layer_(nullptr),
673 touch_event_request_type_(kTouchEventRequestTypeNone), 668 touch_event_request_type_(kTouchEventRequestTypeNone),
674 wants_wheel_events_(false), 669 wants_wheel_events_(false),
670 self_visible_(false),
671 parent_visible_(false),
675 is_disposed_(false) {} 672 is_disposed_(false) {}
676 673
677 WebPluginContainerImpl::~WebPluginContainerImpl() { 674 WebPluginContainerImpl::~WebPluginContainerImpl() {
678 // The plugin container must have been disposed of by now. 675 // The plugin container must have been disposed of by now.
679 DCHECK(!web_plugin_); 676 DCHECK(!web_plugin_);
680 } 677 }
681 678
682 void WebPluginContainerImpl::Dispose() { 679 void WebPluginContainerImpl::Dispose() {
683 is_disposed_ = true; 680 is_disposed_ = true;
684 681
685 RequestTouchEventType(kTouchEventRequestTypeNone); 682 RequestTouchEventType(kTouchEventRequestTypeNone);
686 SetWantsWheelEvents(false); 683 SetWantsWheelEvents(false);
687 684
688 if (web_plugin_) { 685 if (web_plugin_) {
689 CHECK(web_plugin_->Container() == this); 686 CHECK(web_plugin_->Container() == this);
690 web_plugin_->Destroy(); 687 web_plugin_->Destroy();
691 web_plugin_ = nullptr; 688 web_plugin_ = nullptr;
692 } 689 }
693 690
694 if (web_layer_) { 691 if (web_layer_) {
695 GraphicsLayer::UnregisterContentsLayer(web_layer_); 692 GraphicsLayer::UnregisterContentsLayer(web_layer_);
696 web_layer_ = nullptr; 693 web_layer_ = nullptr;
697 } 694 }
698 } 695 }
699 696
700 DEFINE_TRACE(WebPluginContainerImpl) { 697 DEFINE_TRACE(WebPluginContainerImpl) {
698 visitor->Trace(parent_);
701 visitor->Trace(element_); 699 visitor->Trace(element_);
702 ContextClient::Trace(visitor); 700 ContextClient::Trace(visitor);
703 PluginView::Trace(visitor); 701 PluginView::Trace(visitor);
704 } 702 }
705 703
706 void WebPluginContainerImpl::HandleMouseEvent(MouseEvent* event) { 704 void WebPluginContainerImpl::HandleMouseEvent(MouseEvent* event) {
707 DCHECK(Parent()->IsFrameView());
708
709 // We cache the parent FrameView here as the plugin widget could be deleted 705 // 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 706 // in the call to HandleEvent. See http://b/issue?id=1362948
711 FrameView* parent_view = ToFrameView(Parent()); 707 FrameView* parent_view = parent_;
712 708
713 // TODO(dtapuska): Move WebMouseEventBuilder into the anonymous namespace 709 // TODO(dtapuska): Move WebMouseEventBuilder into the anonymous namespace
714 // in this class. 710 // in this class.
715 WebMouseEventBuilder transformed_event( 711 WebMouseEventBuilder transformed_event(
716 ToFrameView(Parent()), LayoutItem(element_->GetLayoutObject()), *event); 712 parent_, LayoutItem(element_->GetLayoutObject()), *event);
717 if (transformed_event.GetType() == WebInputEvent::kUndefined) 713 if (transformed_event.GetType() == WebInputEvent::kUndefined)
718 return; 714 return;
719 715
720 if (event->type() == EventTypeNames::mousedown) 716 if (event->type() == EventTypeNames::mousedown)
721 FocusPlugin(); 717 FocusPlugin();
722 718
723 WebCursorInfo cursor_info; 719 WebCursorInfo cursor_info;
724 if (web_plugin_ && 720 if (web_plugin_ &&
725 web_plugin_->HandleInputEvent(transformed_event, cursor_info) != 721 web_plugin_->HandleInputEvent(transformed_event, cursor_info) !=
726 WebInputEventResult::kNotHandled) 722 WebInputEventResult::kNotHandled)
(...skipping 24 matching lines...) Expand all
751 drag_status = kWebDragStatusDrop; 747 drag_status = kWebDragStatusDrop;
752 748
753 if (drag_status == kWebDragStatusUnknown) 749 if (drag_status == kWebDragStatusUnknown)
754 return; 750 return;
755 751
756 DataTransfer* data_transfer = event->getDataTransfer(); 752 DataTransfer* data_transfer = event->getDataTransfer();
757 WebDragData drag_data = data_transfer->GetDataObject()->ToWebDragData(); 753 WebDragData drag_data = data_transfer->GetDataObject()->ToWebDragData();
758 WebDragOperationsMask drag_operation_mask = 754 WebDragOperationsMask drag_operation_mask =
759 static_cast<WebDragOperationsMask>(data_transfer->SourceOperation()); 755 static_cast<WebDragOperationsMask>(data_transfer->SourceOperation());
760 WebPoint drag_screen_location(event->screenX(), event->screenY()); 756 WebPoint drag_screen_location(event->screenX(), event->screenY());
761 WebPoint drag_location(event->AbsoluteLocation().X() - Location().X(), 757 WebPoint drag_location(
762 event->AbsoluteLocation().Y() - Location().Y()); 758 event->AbsoluteLocation().X() - frame_rect_.Location().X(),
759 event->AbsoluteLocation().Y() - frame_rect_.Location().Y());
763 760
764 web_plugin_->HandleDragStatusUpdate(drag_status, drag_data, 761 web_plugin_->HandleDragStatusUpdate(drag_status, drag_data,
765 drag_operation_mask, drag_location, 762 drag_operation_mask, drag_location,
766 drag_screen_location); 763 drag_screen_location);
767 } 764 }
768 765
769 void WebPluginContainerImpl::HandleWheelEvent(WheelEvent* event) { 766 void WebPluginContainerImpl::HandleWheelEvent(WheelEvent* event) {
770 WebFloatPoint absolute_location = event->NativeEvent().PositionInRootFrame(); 767 WebFloatPoint absolute_location = event->NativeEvent().PositionInRootFrame();
771 768
772 FrameView* view = ToFrameView(Parent());
773 // Translate the root frame position to content coordinates. 769 // Translate the root frame position to content coordinates.
774 if (view) { 770 if (parent_) {
775 absolute_location = view->RootFrameToContents(absolute_location); 771 absolute_location = parent_->RootFrameToContents(absolute_location);
776 } 772 }
777 773
778 IntPoint local_point = 774 IntPoint local_point =
779 RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal( 775 RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal(
780 absolute_location, kUseTransforms)); 776 absolute_location, kUseTransforms));
781 WebMouseWheelEvent translated_event = event->NativeEvent().FlattenTransform(); 777 WebMouseWheelEvent translated_event = event->NativeEvent().FlattenTransform();
782 translated_event.SetPositionInWidget(local_point.X(), local_point.Y()); 778 translated_event.SetPositionInWidget(local_point.X(), local_point.Y());
783 779
784 WebCursorInfo cursor_info; 780 WebCursorInfo cursor_info;
785 if (web_plugin_->HandleInputEvent(translated_event, cursor_info) != 781 if (web_plugin_->HandleInputEvent(translated_event, cursor_info) !=
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 case kTouchEventRequestTypeRaw: { 827 case kTouchEventRequestTypeRaw: {
832 if (!event->NativeEvent()) 828 if (!event->NativeEvent())
833 return; 829 return;
834 830
835 if (event->type() == EventTypeNames::touchstart) 831 if (event->type() == EventTypeNames::touchstart)
836 FocusPlugin(); 832 FocusPlugin();
837 833
838 WebTouchEvent transformed_event = 834 WebTouchEvent transformed_event =
839 event->NativeEvent()->FlattenTransform(); 835 event->NativeEvent()->FlattenTransform();
840 836
841 FrameView* view = ToFrameView(Parent());
842
843 for (unsigned i = 0; i < transformed_event.touches_length; ++i) { 837 for (unsigned i = 0; i < transformed_event.touches_length; ++i) {
844 WebFloatPoint absolute_location = transformed_event.touches[i].position; 838 WebFloatPoint absolute_location = transformed_event.touches[i].position;
845 839
846 // Translate the root frame position to content coordinates. 840 // Translate the root frame position to content coordinates.
847 if (view) { 841 if (parent_) {
848 absolute_location = view->RootFrameToContents(absolute_location); 842 absolute_location = parent_->RootFrameToContents(absolute_location);
849 } 843 }
850 844
851 IntPoint local_point = 845 IntPoint local_point =
852 RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal( 846 RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal(
853 absolute_location, kUseTransforms)); 847 absolute_location, kUseTransforms));
854 transformed_event.touches[i].position.x = local_point.X(); 848 transformed_event.touches[i].position.x = local_point.X();
855 transformed_event.touches[i].position.y = local_point.Y(); 849 transformed_event.touches[i].position.y = local_point.Y();
856 } 850 }
857 851
858 WebCursorInfo cursor_info; 852 WebCursorInfo cursor_info;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 WebInputEventResult::kNotHandled) { 885 WebInputEventResult::kNotHandled) {
892 event->SetDefaultHandled(); 886 event->SetDefaultHandled();
893 return; 887 return;
894 } 888 }
895 889
896 // FIXME: Can a plugin change the cursor from a touch-event callback? 890 // FIXME: Can a plugin change the cursor from a touch-event callback?
897 } 891 }
898 892
899 void WebPluginContainerImpl::SynthesizeMouseEventIfPossible(TouchEvent* event) { 893 void WebPluginContainerImpl::SynthesizeMouseEventIfPossible(TouchEvent* event) {
900 WebMouseEventBuilder web_event( 894 WebMouseEventBuilder web_event(
901 ToFrameView(Parent()), LayoutItem(element_->GetLayoutObject()), *event); 895 parent_, LayoutItem(element_->GetLayoutObject()), *event);
902 if (web_event.GetType() == WebInputEvent::kUndefined) 896 if (web_event.GetType() == WebInputEvent::kUndefined)
903 return; 897 return;
904 898
905 WebCursorInfo cursor_info; 899 WebCursorInfo cursor_info;
906 if (web_plugin_->HandleInputEvent(web_event, cursor_info) != 900 if (web_plugin_->HandleInputEvent(web_event, cursor_info) !=
907 WebInputEventResult::kNotHandled) 901 WebInputEventResult::kNotHandled)
908 event->SetDefaultHandled(); 902 event->SetDefaultHandled();
909 } 903 }
910 904
911 void WebPluginContainerImpl::FocusPlugin() { 905 void WebPluginContainerImpl::FocusPlugin() {
912 LocalFrame& containing_frame = ToFrameView(Parent())->GetFrame(); 906 LocalFrame& containing_frame = parent_->GetFrame();
913 if (Page* current_page = containing_frame.GetPage()) 907 if (Page* current_page = containing_frame.GetPage())
914 current_page->GetFocusController().SetFocusedElement(element_, 908 current_page->GetFocusController().SetFocusedElement(element_,
915 &containing_frame); 909 &containing_frame);
916 else 910 else
917 containing_frame.GetDocument()->SetFocusedElement( 911 containing_frame.GetDocument()->SetFocusedElement(
918 element_, FocusParams(SelectionBehaviorOnFocus::kNone, 912 element_, FocusParams(SelectionBehaviorOnFocus::kNone,
919 kWebFocusTypeNone, nullptr)); 913 kWebFocusTypeNone, nullptr));
920 } 914 }
921 915
922 void WebPluginContainerImpl::IssuePaintInvalidations() { 916 void WebPluginContainerImpl::IssuePaintInvalidations() {
(...skipping 21 matching lines...) Expand all
944 unclipped_int_local_rect = IntRect(); 938 unclipped_int_local_rect = IntRect();
945 return; 939 return;
946 } 940 }
947 941
948 LayoutView* root_view = element_->GetDocument().View()->GetLayoutView(); 942 LayoutView* root_view = element_->GetDocument().View()->GetLayoutView();
949 while (root_view->GetFrame()->OwnerLayoutObject()) 943 while (root_view->GetFrame()->OwnerLayoutObject())
950 root_view = root_view->GetFrame()->OwnerLayoutObject()->View(); 944 root_view = root_view->GetFrame()->OwnerLayoutObject()->View();
951 945
952 LayoutBox* box = ToLayoutBox(owner_element->GetLayoutObject()); 946 LayoutBox* box = ToLayoutBox(owner_element->GetLayoutObject());
953 947
954 // Note: frameRect() for this plugin is equal to contentBoxRect, mapped to the 948 // Note: FrameRect() for this plugin is equal to contentBoxRect, mapped to the
955 // containing view space, and rounded off. 949 // containing view space, and rounded off.
956 // See LayoutPart.cpp::updateGeometryInternal. To remove the lossy 950 // See LayoutPart.cpp::updateGeometryInternal. To remove the lossy
957 // effect of rounding off, use contentBoxRect directly. 951 // effect of rounding off, use contentBoxRect directly.
958 LayoutRect unclipped_absolute_rect(box->ContentBoxRect()); 952 LayoutRect unclipped_absolute_rect(box->ContentBoxRect());
959 box->MapToVisualRectInAncestorSpace(root_view, unclipped_absolute_rect); 953 box->MapToVisualRectInAncestorSpace(root_view, unclipped_absolute_rect);
960 954
961 // The frameRect is already in absolute space of the local frame to the 955 // The frameRect is already in absolute space of the local frame to the
962 // plugin. 956 // plugin.
963 window_rect = FrameRect(); 957 window_rect = frame_rect_;
964 // Map up to the root frame. 958 // Map up to the root frame.
965 LayoutRect layout_window_rect = 959 LayoutRect layout_window_rect =
966 LayoutRect(element_->GetDocument() 960 LayoutRect(element_->GetDocument()
967 .View() 961 .View()
968 ->GetLayoutViewItem() 962 ->GetLayoutViewItem()
969 .LocalToAbsoluteQuad(FloatQuad(FloatRect(FrameRect())), 963 .LocalToAbsoluteQuad(FloatQuad(FloatRect(frame_rect_)),
970 kTraverseDocumentBoundaries) 964 kTraverseDocumentBoundaries)
971 .BoundingBox()); 965 .BoundingBox());
972 // Finally, adjust for scrolling of the root frame, which the above does not 966 // Finally, adjust for scrolling of the root frame, which the above does not
973 // take into account. 967 // take into account.
974 layout_window_rect.MoveBy(-root_view->ViewRect().Location()); 968 layout_window_rect.MoveBy(-root_view->ViewRect().Location());
975 window_rect = PixelSnappedIntRect(layout_window_rect); 969 window_rect = PixelSnappedIntRect(layout_window_rect);
976 970
977 LayoutRect layout_clipped_local_rect = unclipped_absolute_rect; 971 LayoutRect layout_clipped_local_rect = unclipped_absolute_rect;
978 LayoutRect unclipped_layout_local_rect = layout_clipped_local_rect; 972 LayoutRect unclipped_layout_local_rect = layout_clipped_local_rect;
979 layout_clipped_local_rect.Intersect( 973 layout_clipped_local_rect.Intersect(
(...skipping 23 matching lines...) Expand all
1003 // FIXME: Can we just check m_element->document().isActive() ? 997 // FIXME: Can we just check m_element->document().isActive() ?
1004 if (!element_->GetLayoutObject() 998 if (!element_->GetLayoutObject()
1005 ->GetDocument() 999 ->GetDocument()
1006 .GetLayoutViewItem() 1000 .GetLayoutViewItem()
1007 .IsNull()) { 1001 .IsNull()) {
1008 // Take our element and get the clip rect from the enclosing layer and 1002 // Take our element and get the clip rect from the enclosing layer and
1009 // frame view. 1003 // frame view.
1010 ComputeClipRectsForPlugin(element_, window_rect, clip_rect, 1004 ComputeClipRectsForPlugin(element_, window_rect, clip_rect,
1011 unobscured_rect); 1005 unobscured_rect);
1012 } 1006 }
1013 GetPluginOcclusions(element_, this->Parent(), FrameRect(), cut_out_rects); 1007 GetPluginOcclusions(element_, parent_, frame_rect_, cut_out_rects);
1014 // Convert to the plugin position. 1008 // Convert to the plugin position.
1015 for (size_t i = 0; i < cut_out_rects.size(); i++) 1009 for (size_t i = 0; i < cut_out_rects.size(); i++)
1016 cut_out_rects[i].Move(-FrameRect().X(), -FrameRect().Y()); 1010 cut_out_rects[i].Move(-frame_rect_.X(), -frame_rect_.Y());
1017 } 1011 }
1018 1012
1019 } // namespace blink 1013 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebPluginContainerImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698