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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutPart.cpp

Issue 2764313002: Move plugins to be stored in HTMLPlugInElement. (Closed)
Patch Set: Update comments about duplicating code 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Simon Hausmann <hausmann@kde.org> 3 * (C) 2000 Simon Hausmann <hausmann@kde.org>
4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) 4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de)
5 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 10 matching lines...) Expand all
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 * 22 *
23 */ 23 */
24 24
25 #include "core/layout/LayoutPart.h" 25 #include "core/layout/LayoutPart.h"
26 26
27 #include "core/dom/AXObjectCache.h" 27 #include "core/dom/AXObjectCache.h"
28 #include "core/frame/FrameView.h" 28 #include "core/frame/FrameView.h"
29 #include "core/frame/LocalFrame.h" 29 #include "core/frame/LocalFrame.h"
30 #include "core/html/HTMLFrameElementBase.h" 30 #include "core/html/HTMLFrameElementBase.h"
31 #include "core/html/HTMLPlugInElement.h"
31 #include "core/layout/HitTestResult.h" 32 #include "core/layout/HitTestResult.h"
32 #include "core/layout/LayoutAnalyzer.h" 33 #include "core/layout/LayoutAnalyzer.h"
33 #include "core/layout/LayoutView.h" 34 #include "core/layout/LayoutView.h"
34 #include "core/layout/api/LayoutAPIShim.h" 35 #include "core/layout/api/LayoutAPIShim.h"
35 #include "core/layout/api/LayoutViewItem.h" 36 #include "core/layout/api/LayoutViewItem.h"
36 #include "core/paint/PartPainter.h" 37 #include "core/paint/PartPainter.h"
37 #include "core/plugins/PluginView.h" 38 #include "core/plugins/PluginView.h"
38 39
39 namespace blink { 40 namespace blink {
40 41
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 FrameViewBase* LayoutPart::frameViewBase() const { 92 FrameViewBase* LayoutPart::frameViewBase() const {
92 // Plugin FrameViewBases are stored in their DOM node. 93 // Plugin FrameViewBases are stored in their DOM node.
93 Element* element = toElement(node()); 94 Element* element = toElement(node());
94 95
95 if (element && element->isFrameOwnerElement()) 96 if (element && element->isFrameOwnerElement())
96 return toHTMLFrameOwnerElement(element)->ownedWidget(); 97 return toHTMLFrameOwnerElement(element)->ownedWidget();
97 98
98 return nullptr; 99 return nullptr;
99 } 100 }
100 101
102 PluginView* LayoutPart::plugin() const {
103 // Plugins are stored in their DOM node.
104 return node() && isHTMLPlugInElement(node())
105 ? toHTMLPlugInElement(node())->plugin()
106 : nullptr;
107 }
108
109 FrameViewBase* LayoutPart::pluginOrFrame() const {
110 FrameViewBase* result = frameViewBase();
111 if (!result)
112 result = plugin();
113 return result;
114 }
115
101 PaintLayerType LayoutPart::layerTypeRequired() const { 116 PaintLayerType LayoutPart::layerTypeRequired() const {
102 PaintLayerType type = LayoutReplaced::layerTypeRequired(); 117 PaintLayerType type = LayoutReplaced::layerTypeRequired();
103 if (type != NoPaintLayer) 118 if (type != NoPaintLayer)
104 return type; 119 return type;
105 return ForcedPaintLayer; 120 return ForcedPaintLayer;
106 } 121 }
107 122
108 bool LayoutPart::requiresAcceleratedCompositing() const { 123 bool LayoutPart::requiresAcceleratedCompositing() const {
109 // There are two general cases in which we can return true. First, if this is 124 // There are two general cases in which we can return true. First, if this is
110 // a plugin LayoutObject and the plugin has a layer, then we need a layer. 125 // a plugin LayoutObject and the plugin has a layer, then we need a layer.
111 // Second, if this is a LayoutObject with a contentDocument and that document 126 // Second, if this is a LayoutObject with a contentDocument and that document
112 // needs a layer, then we need a layer. 127 // needs a layer, then we need a layer.
113 if (frameViewBase() && frameViewBase()->isPluginView() && 128 PluginView* pluginView = plugin();
114 toPluginView(frameViewBase())->platformLayer()) 129 if (pluginView && pluginView->platformLayer())
115 return true; 130 return true;
116 131
117 if (!node() || !node()->isFrameOwnerElement()) 132 if (!node() || !node()->isFrameOwnerElement())
118 return false; 133 return false;
119 134
120 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node()); 135 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node());
121 if (element->contentFrame() && element->contentFrame()->isRemoteFrame()) 136 if (element->contentFrame() && element->contentFrame()->isRemoteFrame())
122 return true; 137 return true;
123 138
124 if (Document* contentDocument = element->contentDocument()) { 139 if (Document* contentDocument = element->contentDocument()) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 246
232 CompositingReasons LayoutPart::additionalCompositingReasons() const { 247 CompositingReasons LayoutPart::additionalCompositingReasons() const {
233 if (requiresAcceleratedCompositing()) 248 if (requiresAcceleratedCompositing())
234 return CompositingReasonIFrame; 249 return CompositingReasonIFrame;
235 return CompositingReasonNone; 250 return CompositingReasonNone;
236 } 251 }
237 252
238 void LayoutPart::styleDidChange(StyleDifference diff, 253 void LayoutPart::styleDidChange(StyleDifference diff,
239 const ComputedStyle* oldStyle) { 254 const ComputedStyle* oldStyle) {
240 LayoutReplaced::styleDidChange(diff, oldStyle); 255 LayoutReplaced::styleDidChange(diff, oldStyle);
241 FrameViewBase* frameViewBase = this->frameViewBase(); 256 FrameViewBase* frameViewBase = this->pluginOrFrame();
242
243 if (!frameViewBase) 257 if (!frameViewBase)
244 return; 258 return;
245 259
246 // If the iframe has custom scrollbars, recalculate their style. 260 // If the iframe has custom scrollbars, recalculate their style.
247 if (frameViewBase && frameViewBase->isFrameView()) 261 if (frameViewBase->isFrameView())
248 toFrameView(frameViewBase)->recalculateCustomScrollbarStyle(); 262 toFrameView(frameViewBase)->recalculateCustomScrollbarStyle();
249 263
250 if (style()->visibility() != EVisibility::kVisible) { 264 if (style()->visibility() != EVisibility::kVisible) {
251 frameViewBase->hide(); 265 frameViewBase->hide();
252 } else { 266 } else {
253 frameViewBase->show(); 267 frameViewBase->show();
254 } 268 }
255 } 269 }
256 270
257 void LayoutPart::layout() { 271 void LayoutPart::layout() {
258 ASSERT(needsLayout()); 272 ASSERT(needsLayout());
259 LayoutAnalyzer::Scope analyzer(*this); 273 LayoutAnalyzer::Scope analyzer(*this);
260 clearNeedsLayout(); 274 clearNeedsLayout();
261 } 275 }
262 276
263 void LayoutPart::paint(const PaintInfo& paintInfo, 277 void LayoutPart::paint(const PaintInfo& paintInfo,
264 const LayoutPoint& paintOffset) const { 278 const LayoutPoint& paintOffset) const {
265 PartPainter(*this).paint(paintInfo, paintOffset); 279 PartPainter(*this).paint(paintInfo, paintOffset);
266 } 280 }
267 281
268 void LayoutPart::paintContents(const PaintInfo& paintInfo, 282 void LayoutPart::paintContents(const PaintInfo& paintInfo,
269 const LayoutPoint& paintOffset) const { 283 const LayoutPoint& paintOffset) const {
270 PartPainter(*this).paintContents(paintInfo, paintOffset); 284 PartPainter(*this).paintContents(paintInfo, paintOffset);
271 } 285 }
272 286
273 CursorDirective LayoutPart::getCursor(const LayoutPoint& point, 287 CursorDirective LayoutPart::getCursor(const LayoutPoint& point,
274 Cursor& cursor) const { 288 Cursor& cursor) const {
275 if (frameViewBase() && frameViewBase()->isPluginView()) { 289 if (plugin()) {
276 // A plugin is responsible for setting the cursor when the pointer is over 290 // A plugin is responsible for setting the cursor when the pointer is over
277 // it. 291 // it.
278 return DoNotSetCursor; 292 return DoNotSetCursor;
279 } 293 }
280 return LayoutReplaced::getCursor(point, cursor); 294 return LayoutReplaced::getCursor(point, cursor);
281 } 295 }
282 296
283 LayoutRect LayoutPart::replacedContentRect() const { 297 LayoutRect LayoutPart::replacedContentRect() const {
284 // We don't propagate sub-pixel into sub-frame layout, in other words, the 298 // We don't propagate sub-pixel into sub-frame layout, in other words, the
285 // rect is snapped at the document boundary, and sub-pixel movement could 299 // rect is snapped at the document boundary, and sub-pixel movement could
286 // cause the sub-frame to layout due to the 1px snap difference. In order to 300 // cause the sub-frame to layout due to the 1px snap difference. In order to
287 // avoid that, the size of sub-frame is rounded in advance. 301 // avoid that, the size of sub-frame is rounded in advance.
288 LayoutRect sizeRoundedRect = contentBoxRect(); 302 LayoutRect sizeRoundedRect = contentBoxRect();
289 sizeRoundedRect.setSize(LayoutSize(roundedIntSize(sizeRoundedRect.size()))); 303 sizeRoundedRect.setSize(LayoutSize(roundedIntSize(sizeRoundedRect.size())));
290 return sizeRoundedRect; 304 return sizeRoundedRect;
291 } 305 }
292 306
293 void LayoutPart::updateOnWidgetChange() { 307 void LayoutPart::updateOnWidgetChange() {
294 FrameViewBase* frameViewBase = this->frameViewBase(); 308 FrameViewBase* frameViewBase = this->pluginOrFrame();
295 if (!frameViewBase) 309 if (!frameViewBase)
296 return; 310 return;
297 311
298 if (!style()) 312 if (!style())
299 return; 313 return;
300 314
301 if (!needsLayout()) 315 if (!needsLayout())
302 updateGeometryInternal(); 316 updateGeometryInternal(*frameViewBase);
303 317
304 if (style()->visibility() != EVisibility::kVisible) { 318 if (style()->visibility() != EVisibility::kVisible) {
305 frameViewBase->hide(); 319 frameViewBase->hide();
306 } else { 320 } else {
307 frameViewBase->show(); 321 frameViewBase->show();
308 // FIXME: Why do we issue a full paint invalidation in this case, but not 322 // FIXME: Why do we issue a full paint invalidation in this case, but not
309 // the other? 323 // the other?
310 setShouldDoFullPaintInvalidation(); 324 setShouldDoFullPaintInvalidation();
311 } 325 }
312 } 326 }
313 327
314 void LayoutPart::updateGeometry() { 328 void LayoutPart::updateGeometry() {
315 FrameViewBase* frameViewBase = this->frameViewBase(); 329 FrameViewBase* frameViewBase = this->pluginOrFrame();
316 if (!frameViewBase || 330 if (!frameViewBase ||
317 !node()) // Check the node in case destroy() has been called. 331 !node()) // Check the node in case destroy() has been called.
318 return; 332 return;
319 333
320 LayoutRect newFrame = replacedContentRect(); 334 LayoutRect newFrame = replacedContentRect();
321 DCHECK(newFrame.size() == roundedIntSize(newFrame.size())); 335 DCHECK(newFrame.size() == roundedIntSize(newFrame.size()));
322 bool boundsWillChange = 336 bool boundsWillChange =
323 LayoutSize(frameViewBase->frameRect().size()) != newFrame.size(); 337 LayoutSize(frameViewBase->frameRect().size()) != newFrame.size();
324 338
325 FrameView* frameView = 339 FrameView* frameView =
326 frameViewBase->isFrameView() ? toFrameView(frameViewBase) : nullptr; 340 frameViewBase->isFrameView() ? toFrameView(frameViewBase) : nullptr;
327 341
328 // If frame bounds are changing mark the view for layout. Also check the 342 // If frame bounds are changing mark the view for layout. Also check the
329 // frame's page to make sure that the frame isn't in the process of being 343 // frame's page to make sure that the frame isn't in the process of being
330 // destroyed. If iframe scrollbars needs reconstruction from native to custom 344 // destroyed. If iframe scrollbars needs reconstruction from native to custom
331 // scrollbar, then also we need to layout the frameview. 345 // scrollbar, then also we need to layout the frameview.
332 if (frameView && frameView->frame().page() && 346 if (frameView && frameView->frame().page() &&
333 (boundsWillChange || frameView->needsScrollbarReconstruction())) 347 (boundsWillChange || frameView->needsScrollbarReconstruction()))
334 frameView->setNeedsLayout(); 348 frameView->setNeedsLayout();
335 349
336 updateGeometryInternal(); 350 updateGeometryInternal(*frameViewBase);
337 351
338 // If view needs layout, either because bounds have changed or possibly 352 // If view needs layout, either because bounds have changed or possibly
339 // indicating content size is wrong, we have to do a layout to set the right 353 // indicating content size is wrong, we have to do a layout to set the right
340 // FrameViewBase size. 354 // FrameViewBase size.
341 if (frameView && frameView->needsLayout() && frameView->frame().page()) 355 if (frameView && frameView->needsLayout() && frameView->frame().page())
342 frameView->layout(); 356 frameView->layout();
343 357
344 frameViewBase->geometryMayHaveChanged(); 358 frameViewBase->geometryMayHaveChanged();
345 } 359 }
346 360
347 void LayoutPart::updateGeometryInternal() { 361 void LayoutPart::updateGeometryInternal(FrameViewBase& frameViewBase) {
348 FrameViewBase* frameViewBase = this->frameViewBase();
349 DCHECK(frameViewBase);
350
351 // Ignore transform here, as we only care about the sub-pixel accumulation. 362 // Ignore transform here, as we only care about the sub-pixel accumulation.
352 // TODO(trchen): What about multicol? Need a LayoutBox function to query 363 // TODO(trchen): What about multicol? Need a LayoutBox function to query
353 // sub-pixel accumulation. 364 // sub-pixel accumulation.
354 LayoutPoint absoluteLocation(localToAbsolute(FloatPoint())); 365 LayoutPoint absoluteLocation(localToAbsolute(FloatPoint()));
355 LayoutRect absoluteReplacedRect = replacedContentRect(); 366 LayoutRect absoluteReplacedRect = replacedContentRect();
356 absoluteReplacedRect.moveBy(absoluteLocation); 367 absoluteReplacedRect.moveBy(absoluteLocation);
357 368
358 IntRect frameRect(IntPoint(), 369 IntRect frameRect(IntPoint(),
359 pixelSnappedIntRect(absoluteReplacedRect).size()); 370 pixelSnappedIntRect(absoluteReplacedRect).size());
360 // Normally the location of the frame rect is ignored by the painter, but 371 // Normally the location of the frame rect is ignored by the painter, but
361 // currently it is still used by a family of coordinate conversion function in 372 // currently it is still used by a family of coordinate conversion function in
362 // FrameViewBase/FrameView. This is incorrect because coordinate conversion 373 // FrameViewBase/FrameView. This is incorrect because coordinate conversion
363 // needs to take transform and into account. A few callers still use the 374 // needs to take transform and into account. A few callers still use the
364 // family of conversion function, including but not exhaustive: 375 // family of conversion function, including but not exhaustive:
365 // FrameView::updateViewportIntersectionIfNeeded() 376 // FrameView::updateViewportIntersectionIfNeeded()
366 // RemoteFrameView::frameRectsChanged(). 377 // RemoteFrameView::frameRectsChanged().
367 // WebPluginContainerImpl::reportGeometry() 378 // WebPluginContainerImpl::reportGeometry()
368 // TODO(trchen): Remove this hack once we fixed all callers. 379 // TODO(trchen): Remove this hack once we fixed all callers.
369 FloatRect absoluteBoundingBox = 380 FloatRect absoluteBoundingBox =
370 localToAbsoluteQuad(FloatRect(replacedContentRect())).boundingBox(); 381 localToAbsoluteQuad(FloatRect(replacedContentRect())).boundingBox();
371 frameRect.setLocation(roundedIntPoint(absoluteBoundingBox.location())); 382 frameRect.setLocation(roundedIntPoint(absoluteBoundingBox.location()));
372 383
373 // Why is the protector needed? 384 // Why is the protector needed?
374 RefPtr<LayoutPart> protector(this); 385 RefPtr<LayoutPart> protector(this);
375 frameViewBase->setFrameRect(frameRect); 386 frameViewBase.setFrameRect(frameRect);
376 } 387 }
377 388
378 void LayoutPart::invalidatePaintOfSubtreesIfNeeded( 389 void LayoutPart::invalidatePaintOfSubtreesIfNeeded(
379 const PaintInvalidationState& paintInvalidationState) { 390 const PaintInvalidationState& paintInvalidationState) {
380 if (frameViewBase() && frameViewBase()->isFrameView() && 391 if (frameViewBase() && frameViewBase()->isFrameView() &&
381 !isThrottledFrameView()) { 392 !isThrottledFrameView()) {
382 FrameView* childFrameView = toFrameView(frameViewBase()); 393 FrameView* childFrameView = toFrameView(frameViewBase());
383 // |childFrameView| is in another document, which could be 394 // |childFrameView| is in another document, which could be
384 // missing its LayoutView. TODO(jchaffraix): Ideally we should 395 // missing its LayoutView. TODO(jchaffraix): Ideally we should
385 // not need this code. 396 // not need this code.
(...skipping 10 matching lines...) Expand all
396 } 407 }
397 408
398 bool LayoutPart::isThrottledFrameView() const { 409 bool LayoutPart::isThrottledFrameView() const {
399 if (!frameViewBase() || !frameViewBase()->isFrameView()) 410 if (!frameViewBase() || !frameViewBase()->isFrameView())
400 return false; 411 return false;
401 const FrameView* frameView = toFrameView(frameViewBase()); 412 const FrameView* frameView = toFrameView(frameViewBase());
402 return frameView->shouldThrottleRendering(); 413 return frameView->shouldThrottleRendering();
403 } 414 }
404 415
405 } // namespace blink 416 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698