OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 = plugin(); | |
dcheng
2017/04/04 07:20:12
Nit: I would personally invert the order here (as
joelhockey
2017/04/04 23:39:05
Good point. Done
| |
111 if (!result) | |
112 result = frameViewBase(); | |
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 Loading... | |
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 // TODO(joelhockey): When plugin no longer inherits from FrameViewBase, maybe |
309 // make separate versions of this function for plugins and frames. | |
310 FrameViewBase* frameViewBase = this->pluginOrFrame(); | |
295 if (!frameViewBase) | 311 if (!frameViewBase) |
296 return; | 312 return; |
297 | 313 |
298 if (!style()) | 314 if (!style()) |
299 return; | 315 return; |
300 | 316 |
301 if (!needsLayout()) | 317 if (!needsLayout()) |
302 updateGeometryInternal(); | 318 updateGeometryInternal(*frameViewBase); |
303 | 319 |
304 if (style()->visibility() != EVisibility::kVisible) { | 320 if (style()->visibility() != EVisibility::kVisible) { |
305 frameViewBase->hide(); | 321 frameViewBase->hide(); |
306 } else { | 322 } else { |
307 frameViewBase->show(); | 323 frameViewBase->show(); |
308 // FIXME: Why do we issue a full paint invalidation in this case, but not | 324 // FIXME: Why do we issue a full paint invalidation in this case, but not |
309 // the other? | 325 // the other? |
310 setShouldDoFullPaintInvalidation(); | 326 setShouldDoFullPaintInvalidation(); |
311 } | 327 } |
312 } | 328 } |
313 | 329 |
314 void LayoutPart::updateGeometry() { | 330 void LayoutPart::updateGeometry() { |
315 FrameViewBase* frameViewBase = this->frameViewBase(); | 331 // TODO(joelhockey): When plugin no longer inherits from FrameViewBase, maybe |
332 // make separate versions of this function for plugins and frames. | |
dcheng
2017/04/04 07:20:12
For line 308 and here, I have a bit of concern abo
joelhockey
2017/04/04 23:39:05
I've deleted these comments. I expect right now t
| |
333 FrameViewBase* frameViewBase = this->pluginOrFrame(); | |
316 if (!frameViewBase || | 334 if (!frameViewBase || |
317 !node()) // Check the node in case destroy() has been called. | 335 !node()) // Check the node in case destroy() has been called. |
318 return; | 336 return; |
319 | 337 |
320 LayoutRect newFrame = replacedContentRect(); | 338 LayoutRect newFrame = replacedContentRect(); |
321 DCHECK(newFrame.size() == roundedIntSize(newFrame.size())); | 339 DCHECK(newFrame.size() == roundedIntSize(newFrame.size())); |
322 bool boundsWillChange = | 340 bool boundsWillChange = |
323 LayoutSize(frameViewBase->frameRect().size()) != newFrame.size(); | 341 LayoutSize(frameViewBase->frameRect().size()) != newFrame.size(); |
324 | 342 |
325 FrameView* frameView = | 343 FrameView* frameView = |
326 frameViewBase->isFrameView() ? toFrameView(frameViewBase) : nullptr; | 344 frameViewBase->isFrameView() ? toFrameView(frameViewBase) : nullptr; |
327 | 345 |
328 // If frame bounds are changing mark the view for layout. Also check the | 346 // 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 | 347 // 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 | 348 // destroyed. If iframe scrollbars needs reconstruction from native to custom |
331 // scrollbar, then also we need to layout the frameview. | 349 // scrollbar, then also we need to layout the frameview. |
332 if (frameView && frameView->frame().page() && | 350 if (frameView && frameView->frame().page() && |
333 (boundsWillChange || frameView->needsScrollbarReconstruction())) | 351 (boundsWillChange || frameView->needsScrollbarReconstruction())) |
334 frameView->setNeedsLayout(); | 352 frameView->setNeedsLayout(); |
335 | 353 |
336 updateGeometryInternal(); | 354 updateGeometryInternal(*frameViewBase); |
337 | 355 |
338 // If view needs layout, either because bounds have changed or possibly | 356 // 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 | 357 // indicating content size is wrong, we have to do a layout to set the right |
340 // FrameViewBase size. | 358 // FrameViewBase size. |
341 if (frameView && frameView->needsLayout() && frameView->frame().page()) | 359 if (frameView && frameView->needsLayout() && frameView->frame().page()) |
342 frameView->layout(); | 360 frameView->layout(); |
343 | 361 |
344 frameViewBase->geometryMayHaveChanged(); | 362 frameViewBase->geometryMayHaveChanged(); |
345 } | 363 } |
346 | 364 |
347 void LayoutPart::updateGeometryInternal() { | 365 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. | 366 // Ignore transform here, as we only care about the sub-pixel accumulation. |
352 // TODO(trchen): What about multicol? Need a LayoutBox function to query | 367 // TODO(trchen): What about multicol? Need a LayoutBox function to query |
353 // sub-pixel accumulation. | 368 // sub-pixel accumulation. |
354 LayoutPoint absoluteLocation(localToAbsolute(FloatPoint())); | 369 LayoutPoint absoluteLocation(localToAbsolute(FloatPoint())); |
355 LayoutRect absoluteReplacedRect = replacedContentRect(); | 370 LayoutRect absoluteReplacedRect = replacedContentRect(); |
356 absoluteReplacedRect.moveBy(absoluteLocation); | 371 absoluteReplacedRect.moveBy(absoluteLocation); |
357 | 372 |
358 IntRect frameRect(IntPoint(), | 373 IntRect frameRect(IntPoint(), |
359 pixelSnappedIntRect(absoluteReplacedRect).size()); | 374 pixelSnappedIntRect(absoluteReplacedRect).size()); |
360 // Normally the location of the frame rect is ignored by the painter, but | 375 // 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 | 376 // currently it is still used by a family of coordinate conversion function in |
362 // FrameViewBase/FrameView. This is incorrect because coordinate conversion | 377 // FrameViewBase/FrameView. This is incorrect because coordinate conversion |
363 // needs to take transform and into account. A few callers still use the | 378 // needs to take transform and into account. A few callers still use the |
364 // family of conversion function, including but not exhaustive: | 379 // family of conversion function, including but not exhaustive: |
365 // FrameView::updateViewportIntersectionIfNeeded() | 380 // FrameView::updateViewportIntersectionIfNeeded() |
366 // RemoteFrameView::frameRectsChanged(). | 381 // RemoteFrameView::frameRectsChanged(). |
367 // WebPluginContainerImpl::reportGeometry() | 382 // WebPluginContainerImpl::reportGeometry() |
368 // TODO(trchen): Remove this hack once we fixed all callers. | 383 // TODO(trchen): Remove this hack once we fixed all callers. |
369 FloatRect absoluteBoundingBox = | 384 FloatRect absoluteBoundingBox = |
370 localToAbsoluteQuad(FloatRect(replacedContentRect())).boundingBox(); | 385 localToAbsoluteQuad(FloatRect(replacedContentRect())).boundingBox(); |
371 frameRect.setLocation(roundedIntPoint(absoluteBoundingBox.location())); | 386 frameRect.setLocation(roundedIntPoint(absoluteBoundingBox.location())); |
372 | 387 |
373 // Why is the protector needed? | 388 // Why is the protector needed? |
374 RefPtr<LayoutPart> protector(this); | 389 RefPtr<LayoutPart> protector(this); |
375 frameViewBase->setFrameRect(frameRect); | 390 frameViewBase.setFrameRect(frameRect); |
376 } | 391 } |
377 | 392 |
378 void LayoutPart::invalidatePaintOfSubtreesIfNeeded( | 393 void LayoutPart::invalidatePaintOfSubtreesIfNeeded( |
379 const PaintInvalidationState& paintInvalidationState) { | 394 const PaintInvalidationState& paintInvalidationState) { |
380 if (frameViewBase() && frameViewBase()->isFrameView() && | 395 if (frameViewBase() && frameViewBase()->isFrameView() && |
381 !isThrottledFrameView()) { | 396 !isThrottledFrameView()) { |
382 FrameView* childFrameView = toFrameView(frameViewBase()); | 397 FrameView* childFrameView = toFrameView(frameViewBase()); |
383 // |childFrameView| is in another document, which could be | 398 // |childFrameView| is in another document, which could be |
384 // missing its LayoutView. TODO(jchaffraix): Ideally we should | 399 // missing its LayoutView. TODO(jchaffraix): Ideally we should |
385 // not need this code. | 400 // not need this code. |
(...skipping 10 matching lines...) Expand all Loading... | |
396 } | 411 } |
397 | 412 |
398 bool LayoutPart::isThrottledFrameView() const { | 413 bool LayoutPart::isThrottledFrameView() const { |
399 if (!frameViewBase() || !frameViewBase()->isFrameView()) | 414 if (!frameViewBase() || !frameViewBase()->isFrameView()) |
400 return false; | 415 return false; |
401 const FrameView* frameView = toFrameView(frameViewBase()); | 416 const FrameView* frameView = toFrameView(frameViewBase()); |
402 return frameView->shouldThrottleRendering(); | 417 return frameView->shouldThrottleRendering(); |
403 } | 418 } |
404 | 419 |
405 } // namespace blink | 420 } // namespace blink |
OLD | NEW |