• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved.
3  * Copyright (C) 2013 Intel Corporation. All rights reserved.
4  *
5  * Portions are Copyright (C) 1998 Netscape Communications Corporation.
6  *
7  * Other contributors:
8  *   Robert O'Callahan <roc+@cs.cmu.edu>
9  *   David Baron <dbaron@fas.harvard.edu>
10  *   Christian Biesinger <cbiesinger@web.de>
11  *   Randall Jesup <rjesup@wgate.com>
12  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
13  *   Josh Soref <timeless@mac.com>
14  *   Boris Zbarsky <bzbarsky@mit.edu>
15  *
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2.1 of the License, or (at your option) any later version.
20  *
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this library; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
29  *
30  * Alternatively, the contents of this file may be used under the terms
31  * of either the Mozilla Public License Version 1.1, found at
32  * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
33  * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
34  * (the "GPL"), in which case the provisions of the MPL or the GPL are
35  * applicable instead of those above.  If you wish to allow use of your
36  * version of this file only under the terms of one of those two
37  * licenses (the MPL or the GPL) and not to allow others to use your
38  * version of this file under the LGPL, indicate your decision by
39  * deletingthe provisions above and replace them with the notice and
40  * other provisions required by the MPL or the GPL, as the case may be.
41  * If you do not delete the provisions above, a recipient may use your
42  * version of this file under any of the LGPL, the MPL or the GPL.
43  */
44 
45 #ifndef RenderLayer_h
46 #define RenderLayer_h
47 
48 #include "core/rendering/CompositedLayerMappingPtr.h"
49 #include "core/rendering/CompositingReasons.h"
50 #include "core/rendering/LayerPaintingInfo.h"
51 #include "core/rendering/PaintInfo.h"
52 #include "core/rendering/RenderBox.h"
53 #include "core/rendering/RenderLayerClipper.h"
54 #include "core/rendering/RenderLayerFilterInfo.h"
55 #include "core/rendering/RenderLayerReflectionInfo.h"
56 #include "core/rendering/RenderLayerRepainter.h"
57 #include "core/rendering/RenderLayerScrollableArea.h"
58 #include "core/rendering/RenderLayerStackingNode.h"
59 #include "core/rendering/RenderLayerStackingNodeIterator.h"
60 #include "wtf/OwnPtr.h"
61 
62 namespace WebCore {
63 
64 class FilterEffectRenderer;
65 class FilterOperations;
66 class HitTestRequest;
67 class HitTestResult;
68 class HitTestingTransformState;
69 class PlatformEvent;
70 class RenderFlowThread;
71 class RenderGeometryMap;
72 class CompositedLayerMapping;
73 class RenderLayerCompositor;
74 class RenderReplica;
75 class RenderScrollbarPart;
76 class RenderStyle;
77 class RenderView;
78 class Scrollbar;
79 class TransformationMatrix;
80 
81 enum BorderRadiusClippingRule { IncludeSelfForBorderRadius, DoNotIncludeSelfForBorderRadius };
82 
83 class RenderLayer {
84 public:
85     friend class RenderReplica;
86     // FIXME: Needed until we move all the necessary bits to the new class.
87     friend class RenderLayerStackingNode;
88     // FIXME: Needed until we move all the necessary bits to the new class.
89     friend class RenderLayerScrollableArea;
90 
91     RenderLayer(RenderLayerModelObject*);
92     ~RenderLayer();
93 
94     String debugName() const;
95 
renderer()96     RenderLayerModelObject* renderer() const { return m_renderer; }
renderBox()97     RenderBox* renderBox() const { return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0; }
parent()98     RenderLayer* parent() const { return m_parent; }
previousSibling()99     RenderLayer* previousSibling() const { return m_previous; }
nextSibling()100     RenderLayer* nextSibling() const { return m_next; }
firstChild()101     RenderLayer* firstChild() const { return m_first; }
lastChild()102     RenderLayer* lastChild() const { return m_last; }
103 
104     void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0);
105     RenderLayer* removeChild(RenderLayer*);
106 
107     void removeOnlyThisLayer();
108     void insertOnlyThisLayer();
109 
110     void styleChanged(StyleDifference, const RenderStyle* oldStyle);
111 
isSelfPaintingLayer()112     bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; }
113 
114     bool cannotBlitToWindow() const;
115 
116     bool isTransparent() const;
117     RenderLayer* transparentPaintingAncestor();
118     void beginTransparencyLayers(GraphicsContext*, const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, PaintBehavior);
119 
isReflection()120     bool isReflection() const { return renderer()->isReplica(); }
reflectionInfo()121     RenderLayerReflectionInfo* reflectionInfo() { return m_reflectionInfo.get(); }
reflectionInfo()122     const RenderLayerReflectionInfo* reflectionInfo() const { return m_reflectionInfo.get(); }
123 
root()124     const RenderLayer* root() const
125     {
126         const RenderLayer* curr = this;
127         while (curr->parent())
128             curr = curr->parent();
129         return curr;
130     }
131 
location()132     const LayoutPoint& location() const { return m_topLeft; }
setLocation(const LayoutPoint & p)133     void setLocation(const LayoutPoint& p) { m_topLeft = p; }
134 
size()135     const IntSize& size() const { return m_layerSize; }
setSize(const IntSize & size)136     void setSize(const IntSize& size) { m_layerSize = size; }
137 
rect()138     LayoutRect rect() const { return LayoutRect(location(), size()); }
139 
isRootLayer()140     bool isRootLayer() const { return m_isRootLayer; }
141 
142     RenderLayerCompositor* compositor() const;
143 
144     // Notification from the renderer that its content changed (e.g. current frame of image changed).
145     // Allows updates of layer content without repainting.
146     void contentChanged(ContentChangeType);
147 
148     bool canRender3DTransforms() const;
149 
150     enum UpdateLayerPositionsFlag {
151         CheckForRepaint = 1 << 0,
152         NeedsFullRepaintInBacking = 1 << 1,
153         IsCompositingUpdateRoot = 1 << 2,
154         UpdateCompositingLayers = 1 << 3,
155         UpdatePagination = 1 << 4
156     };
157     typedef unsigned UpdateLayerPositionsFlags;
158     static const UpdateLayerPositionsFlags defaultFlags = CheckForRepaint | IsCompositingUpdateRoot | UpdateCompositingLayers;
159 
160     void updateLayerPositionsAfterLayout(const RenderLayer* rootLayer, UpdateLayerPositionsFlags);
161 
162     void updateLayerPositionsAfterOverflowScroll();
163     void updateLayerPositionsAfterDocumentScroll();
164 
isPaginated()165     bool isPaginated() const { return m_isPaginated; }
enclosingPaginationLayer()166     RenderLayer* enclosingPaginationLayer() const { return m_enclosingPaginationLayer; }
167 
168     void updateTransform();
169 
170     void updateBlendMode();
171 
offsetForInFlowPosition()172     const LayoutSize& offsetForInFlowPosition() const { return m_offsetForInFlowPosition; }
173 
174     void addBlockSelectionGapsBounds(const LayoutRect&);
175     void clearBlockSelectionGapsBounds();
176     void repaintBlockSelectionGaps();
177     bool hasBlockSelectionGapBounds() const;
178 
stackingNode()179     RenderLayerStackingNode* stackingNode() { return m_stackingNode.get(); }
stackingNode()180     const RenderLayerStackingNode* stackingNode() const { return m_stackingNode.get(); }
181 
subtreeIsInvisible()182     bool subtreeIsInvisible() const { return !hasVisibleContent() && !hasVisibleDescendant(); }
183 
184     // FIXME: We should ASSERT(!m_visibleContentStatusDirty) here, but see https://bugs.webkit.org/show_bug.cgi?id=71044
185     // ditto for hasVisibleDescendant(), see https://bugs.webkit.org/show_bug.cgi?id=71277
hasVisibleContent()186     bool hasVisibleContent() const { return m_hasVisibleContent; }
hasVisibleDescendant()187     bool hasVisibleDescendant() const { return m_hasVisibleDescendant; }
188 
189     void setHasVisibleContent();
190     void dirtyVisibleContentStatus();
191 
192     bool hasBoxDecorationsOrBackground() const;
193     bool hasVisibleBoxDecorations() const;
194     // Returns true if this layer has visible content (ignoring any child layers).
195     bool isVisuallyNonEmpty() const;
196     // True if this layer container renderers that paint.
197     bool hasNonEmptyChildRenderers() const;
198 
199     // FIXME: We should ASSERT(!m_hasSelfPaintingLayerDescendantDirty); here but we hit the same bugs as visible content above.
200     // Part of the issue is with subtree relayout: we don't check if our ancestors have some descendant flags dirty, missing some updates.
hasSelfPaintingLayerDescendant()201     bool hasSelfPaintingLayerDescendant() const { return m_hasSelfPaintingLayerDescendant; }
202 
203     // FIXME: We should ASSERT(!m_hasOutOfFlowPositionedDescendantDirty) here. See above.
hasOutOfFlowPositionedDescendant()204     bool hasOutOfFlowPositionedDescendant() const { return m_hasOutOfFlowPositionedDescendant; }
205 
setHasOutOfFlowPositionedDescendant(bool hasDescendant)206     void setHasOutOfFlowPositionedDescendant(bool hasDescendant) { m_hasOutOfFlowPositionedDescendant = hasDescendant; }
setHasOutOfFlowPositionedDescendantDirty(bool dirty)207     void setHasOutOfFlowPositionedDescendantDirty(bool dirty) { m_hasOutOfFlowPositionedDescendantDirty = dirty; }
208 
childLayerHasBlendMode()209     bool childLayerHasBlendMode() const { ASSERT(!m_childLayerHasBlendModeStatusDirty); return m_childLayerHasBlendMode; }
210 
hasUnclippedDescendant()211     bool hasUnclippedDescendant() const { return m_hasUnclippedDescendant; }
setHasUnclippedDescendant(bool hasDescendant)212     void setHasUnclippedDescendant(bool hasDescendant) { m_hasUnclippedDescendant = hasDescendant; }
213     void updateHasUnclippedDescendant();
isUnclippedDescendant()214     bool isUnclippedDescendant() const { return m_isUnclippedDescendant; }
215 
hasVisibleNonLayerContent()216     bool hasVisibleNonLayerContent() const { return m_hasVisibleNonLayerContent; }
217     void updateHasVisibleNonLayerContent();
218 
219     // Gets the nearest enclosing positioned ancestor layer (also includes
220     // the <html> layer and the root layer).
221     RenderLayer* enclosingPositionedAncestor() const;
222 
223     // Returns the nearest enclosing layer that is scrollable.
224     RenderLayer* enclosingScrollableLayer() const;
225 
226     // The layer relative to which clipping rects for this layer are computed.
227     RenderLayer* clippingRootForPainting() const;
228 
229     // Enclosing compositing layer; if includeSelf is true, may return this.
230     RenderLayer* enclosingCompositingLayer(bool includeSelf = true) const;
231     RenderLayer* enclosingCompositingLayerForRepaint(bool includeSelf = true) const;
232     // Ancestor compositing layer, excluding this.
ancestorCompositingLayer()233     RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(false); }
234 
235     // Ancestor composited scrolling layer at or above our containing block.
236     RenderLayer* ancestorCompositedScrollingLayer() const;
237 
238     // Ancestor scrolling layer at or above our containing block.
239     RenderLayer* ancestorScrollingLayer() const;
240 
241     RenderLayer* enclosingFilterLayer(bool includeSelf = true) const;
242     RenderLayer* enclosingFilterRepaintLayer() const;
243     bool hasAncestorWithFilterOutsets() const;
244 
canUseConvertToLayerCoords()245     bool canUseConvertToLayerCoords() const
246     {
247         // These RenderObjects have an impact on their layers without the renderers knowing about it.
248         return !renderer()->hasColumns() && !renderer()->hasTransform() && !renderer()->isSVGRoot();
249     }
250 
251     void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntPoint& location) const;
252     void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntRect&) const;
253     void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint& location) const;
254     void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect&) const;
255 
256     // The two main functions that use the layer system.  The paint method
257     // paints the layers that intersect the damage rect from back to
258     // front.  The hitTest method looks for mouse events by walking
259     // layers that intersect the point from front to back.
260     void paint(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior = PaintBehaviorNormal, RenderObject* paintingRoot = 0,
261         RenderRegion* = 0, PaintLayerFlags = 0);
262     bool hitTest(const HitTestRequest&, HitTestResult&);
263     bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&);
264     void paintOverlayScrollbars(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior, RenderObject* paintingRoot = 0);
265 
266     // This method figures out our layerBounds in coordinates relative to
267     // |rootLayer}.  It also computes our background and foreground clip rects
268     // for painting/event handling.
269     // Pass offsetFromRoot if known.
270     void calculateRects(const ClipRectsContext&, const LayoutRect& paintDirtyRect, LayoutRect& layerBounds,
271         ClipRect& backgroundRect, ClipRect& foregroundRect, ClipRect& outlineRect, const LayoutPoint* offsetFromRoot = 0) const;
272 
273     LayoutRect childrenClipRect() const; // Returns the foreground clip rect of the layer in the document's coordinate space.
274     LayoutRect selfClipRect() const; // Returns the background clip rect of the layer in the document's coordinate space.
275     LayoutRect localClipRect() const; // Returns the background clip rect of the layer in the local coordinate space.
276 
277     // Pass offsetFromRoot if known.
278     bool intersectsDamageRect(const LayoutRect& layerBounds, const LayoutRect& damageRect, const RenderLayer* rootLayer, const LayoutPoint* offsetFromRoot = 0) const;
279 
280     enum CalculateLayerBoundsFlag {
281         IncludeSelfTransform = 1 << 0,
282         UseLocalClipRectIfPossible = 1 << 1,
283         IncludeLayerFilterOutsets = 1 << 2,
284         ExcludeHiddenDescendants = 1 << 3,
285         DontConstrainForMask = 1 << 4,
286         IncludeCompositedDescendants = 1 << 5,
287         UseFragmentBoxes = 1 << 6,
288         PretendLayerHasOwnBacking = 1 << 7,
289         DefaultCalculateLayerBoundsFlags =  IncludeSelfTransform | UseLocalClipRectIfPossible | IncludeLayerFilterOutsets | UseFragmentBoxes
290     };
291     typedef unsigned CalculateLayerBoundsFlags;
292 
293     // Bounding box relative to some ancestor layer. Pass offsetFromRoot if known.
294     LayoutRect boundingBox(const RenderLayer* rootLayer, CalculateLayerBoundsFlags = 0, const LayoutPoint* offsetFromRoot = 0) const;
295     // Bounding box in the coordinates of this layer.
296     LayoutRect localBoundingBox(CalculateLayerBoundsFlags = 0) const;
297     // Pixel snapped bounding box relative to the root.
298     IntRect absoluteBoundingBox() const;
299 
300     // Bounds used for layer overlap testing in RenderLayerCompositor.
overlapBounds()301     LayoutRect overlapBounds() const { return overlapBoundsIncludeChildren() ? calculateLayerBounds(this) : localBoundingBox(); }
302 
303     // If true, this layer's children are included in its bounds for overlap testing.
304     // We can't rely on the children's positions if this layer has a filter that could have moved the children's pixels around.
overlapBoundsIncludeChildren()305     bool overlapBoundsIncludeChildren() const { return hasFilter() && renderer()->style()->filter().hasFilterThatMovesPixels(); }
306 
307     // Can pass offsetFromRoot if known.
308     IntRect calculateLayerBounds(const RenderLayer* ancestorLayer, const LayoutPoint* offsetFromRoot = 0, CalculateLayerBoundsFlags = DefaultCalculateLayerBoundsFlags) const;
309 
310     // WARNING: This method returns the offset for the parent as this is what updateLayerPositions expects.
311     LayoutPoint computeOffsetFromRoot(bool& hasLayerOffset) const;
312 
staticInlinePosition()313     LayoutUnit staticInlinePosition() const { return m_staticInlinePosition; }
staticBlockPosition()314     LayoutUnit staticBlockPosition() const { return m_staticBlockPosition; }
315 
setStaticInlinePosition(LayoutUnit position)316     void setStaticInlinePosition(LayoutUnit position) { m_staticInlinePosition = position; }
setStaticBlockPosition(LayoutUnit position)317     void setStaticBlockPosition(LayoutUnit position) { m_staticBlockPosition = position; }
318 
hasTransform()319     bool hasTransform() const { return renderer()->hasTransform(); }
320     // Note that this transform has the transform-origin baked in.
transform()321     TransformationMatrix* transform() const { return m_transform.get(); }
322     // currentTransform computes a transform which takes accelerated animations into account. The
323     // resulting transform has transform-origin baked in. If the layer does not have a transform,
324     // returns the identity matrix.
325     TransformationMatrix currentTransform(RenderStyle::ApplyTransformOrigin = RenderStyle::IncludeTransformOrigin) const;
326     TransformationMatrix renderableTransform(PaintBehavior) const;
327 
328     // Get the perspective transform, which is applied to transformed sublayers.
329     // Returns true if the layer has a -webkit-perspective.
330     // Note that this transform has the perspective-origin baked in.
331     TransformationMatrix perspectiveTransform() const;
332     FloatPoint perspectiveOrigin() const;
preserves3D()333     bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
has3DTransform()334     bool has3DTransform() const { return m_transform && !m_transform->isAffine(); }
335 
336     void filterNeedsRepaint();
hasFilter()337     bool hasFilter() const { return renderer()->hasFilter(); }
338 
339     bool hasBlendMode() const;
paintsWithBlendMode()340     bool paintsWithBlendMode() const { return hasBlendMode() && compositingState() != PaintsIntoOwnBacking; }
341 
342     void* operator new(size_t);
343     // Only safe to call from RenderLayerModelObject::destroyLayer()
344     void operator delete(void*);
345 
346     CompositingState compositingState() const;
347 
compositedLayerMapping()348     CompositedLayerMappingPtr compositedLayerMapping() const { return m_compositedLayerMapping.get(); }
349     CompositedLayerMappingPtr ensureCompositedLayerMapping();
350 
351     // NOTE: If you are using hasCompositedLayerMapping to determine the state of compositing for this layer,
352     // (and not just to do bookkeeping related to the mapping like, say, allocating or deallocating a mapping),
353     // then you may have incorrect logic. Use compositingState() instead.
hasCompositedLayerMapping()354     bool hasCompositedLayerMapping() const { return m_compositedLayerMapping.get(); }
355     void clearCompositedLayerMapping(bool layerBeingDestroyed = false);
356 
groupedMapping()357     CompositedLayerMapping* groupedMapping() const { return m_groupedMapping; }
setGroupedMapping(CompositedLayerMapping * groupedMapping)358     void setGroupedMapping(CompositedLayerMapping* groupedMapping) { m_groupedMapping = groupedMapping; }
359 
360     bool hasCompositedMask() const;
361     bool hasCompositedClippingMask() const;
needsCompositedScrolling()362     bool needsCompositedScrolling() const { return m_scrollableArea && m_scrollableArea->needsCompositedScrolling(); }
363 
364     bool clipsCompositingDescendantsWithBorderRadius() const;
365 
366     RenderLayer* scrollParent() const;
367     RenderLayer* clipParent() const;
368 
369     bool needsCompositingLayersRebuiltForClip(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
370     bool needsCompositingLayersRebuiltForOverflow(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
371     bool needsCompositingLayersRebuiltForFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle, bool didPaintWithFilters) const;
372     bool needsCompositingLayersRebuiltForBlending(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
373 
paintsWithTransparency(PaintBehavior paintBehavior)374     bool paintsWithTransparency(PaintBehavior paintBehavior) const
375     {
376         return isTransparent() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || compositingState() != PaintsIntoOwnBacking);
377     }
378 
379     bool paintsWithTransform(PaintBehavior) const;
380 
381     // Returns true if background phase is painted opaque in the given rect.
382     // The query rect is given in local coordinates.
383     bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
384 
containsDirtyOverlayScrollbars()385     bool containsDirtyOverlayScrollbars() const { return m_containsDirtyOverlayScrollbars; }
setContainsDirtyOverlayScrollbars(bool dirtyScrollbars)386     void setContainsDirtyOverlayScrollbars(bool dirtyScrollbars) { m_containsDirtyOverlayScrollbars = dirtyScrollbars; }
387 
388     bool isCSSCustomFilterEnabled() const;
389 
390     FilterOperations computeFilterOperations(const RenderStyle*);
391     bool paintsWithFilters() const;
392     bool requiresFullLayerImageForFilters() const;
filterRenderer()393     FilterEffectRenderer* filterRenderer() const
394     {
395         RenderLayerFilterInfo* filterInfo = this->filterInfo();
396         return filterInfo ? filterInfo->renderer() : 0;
397     }
398 
filterInfo()399     RenderLayerFilterInfo* filterInfo() const { return hasFilterInfo() ? RenderLayerFilterInfo::filterInfoForRenderLayer(this) : 0; }
ensureFilterInfo()400     RenderLayerFilterInfo* ensureFilterInfo() { return RenderLayerFilterInfo::createFilterInfoForRenderLayerIfNeeded(this); }
removeFilterInfoIfNeeded()401     void removeFilterInfoIfNeeded()
402     {
403         if (hasFilterInfo())
404             RenderLayerFilterInfo::removeFilterInfoForRenderLayer(this);
405     }
406 
hasFilterInfo()407     bool hasFilterInfo() const { return m_hasFilterInfo; }
setHasFilterInfo(bool hasFilterInfo)408     void setHasFilterInfo(bool hasFilterInfo) { m_hasFilterInfo = hasFilterInfo; }
409 
410     void updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle);
411 
412     Node* enclosingElement() const;
413 
414     bool isInTopLayer() const;
415     bool isInTopLayerSubtree() const;
416 
417     enum ViewportConstrainedNotCompositedReason {
418         NoNotCompositedReason,
419         NotCompositedForBoundsOutOfView,
420         NotCompositedForNonViewContainer,
421         NotCompositedForNoVisibleContent,
422         NotCompositedForUnscrollableAncestors,
423     };
424 
setViewportConstrainedNotCompositedReason(ViewportConstrainedNotCompositedReason reason)425     void setViewportConstrainedNotCompositedReason(ViewportConstrainedNotCompositedReason reason) { m_compositingProperties.viewportConstrainedNotCompositedReason = reason; }
viewportConstrainedNotCompositedReason()426     ViewportConstrainedNotCompositedReason viewportConstrainedNotCompositedReason() const { return static_cast<ViewportConstrainedNotCompositedReason>(m_compositingProperties.viewportConstrainedNotCompositedReason); }
427 
isOutOfFlowRenderFlowThread()428     bool isOutOfFlowRenderFlowThread() const { return renderer()->isOutOfFlowRenderFlowThread(); }
429 
430     bool scrollsWithRespectTo(const RenderLayer*) const;
431 
432     void addLayerHitTestRects(LayerHitTestRects&) const;
433 
434     // FIXME: This should probably return a ScrollableArea but a lot of internal methods are mistakenly exposed.
scrollableArea()435     RenderLayerScrollableArea* scrollableArea() const { return m_scrollableArea.get(); }
repainter()436     RenderLayerRepainter& repainter() { return m_repainter; }
clipper()437     RenderLayerClipper& clipper() { return m_clipper; }
438 
isPositionedContainer()439     inline bool isPositionedContainer() const
440     {
441         // FIXME: This is not in sync with containingBlock.
442         // RenderObject::canContainFixedPositionedObject() should probably be used
443         // instead.
444         RenderLayerModelObject* layerRenderer = renderer();
445         return isRootLayer() || layerRenderer->isPositioned() || hasTransform();
446     }
447 
448     void paintLayer(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
449 
450     PassOwnPtr<Vector<FloatRect> > collectTrackedRepaintRects() const;
451 
setOffsetFromSquashingLayerOrigin(IntSize offset)452     void setOffsetFromSquashingLayerOrigin(IntSize offset) { m_compositingProperties.offsetFromSquashingLayerOrigin = offset; }
offsetFromSquashingLayerOrigin()453     IntSize offsetFromSquashingLayerOrigin() const { return m_compositingProperties.offsetFromSquashingLayerOrigin; }
454 
455 private:
456     bool hasOverflowControls() const;
457 
setIsUnclippedDescendant(bool isUnclippedDescendant)458     void setIsUnclippedDescendant(bool isUnclippedDescendant) { m_isUnclippedDescendant = isUnclippedDescendant; }
459 
460     void setAncestorChainHasSelfPaintingLayerDescendant();
461     void dirtyAncestorChainHasSelfPaintingLayerDescendantStatus();
462 
463     void setAncestorChainHasOutOfFlowPositionedDescendant();
464     void dirtyAncestorChainHasOutOfFlowPositionedDescendantStatus();
465 
466     bool acceleratedCompositingForOverflowScrollEnabled() const;
467     // FIXME: This is a temporary flag and should be removed once accelerated
468     // overflow scroll is ready (crbug.com/254111).
469     bool compositorDrivenAcceleratedScrollingEnabled() const;
470 
471     void clipToRect(RenderLayer* rootLayer, GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&,
472                     BorderRadiusClippingRule = IncludeSelfForBorderRadius);
473     void restoreClip(GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&);
474 
475     void updateSelfPaintingLayer();
476     void updateVisibilityAfterStyleChange(const RenderStyle* oldStyle);
477 
478     void updateOutOfFlowPositioned(const RenderStyle* oldStyle);
479 
480     void didUpdateNeedsCompositedScrolling();
481 
482     // Returns true if the position changed.
483     bool updateLayerPosition();
484 
485     void updateLayerPositions(RenderGeometryMap* = 0, UpdateLayerPositionsFlags = defaultFlags);
486 
487     enum UpdateLayerPositionsAfterScrollFlag {
488         NoFlag = 0,
489         IsOverflowScroll = 1 << 0,
490         HasSeenViewportConstrainedAncestor = 1 << 1,
491         HasSeenAncestorWithOverflowClip = 1 << 2,
492         HasChangedAncestor = 1 << 3
493     };
494     typedef unsigned UpdateLayerPositionsAfterScrollFlags;
495     void updateLayerPositionsAfterScroll(RenderGeometryMap*, UpdateLayerPositionsAfterScrollFlags = NoFlag);
496 
setNextSibling(RenderLayer * next)497     void setNextSibling(RenderLayer* next) { m_next = next; }
setPreviousSibling(RenderLayer * prev)498     void setPreviousSibling(RenderLayer* prev) { m_previous = prev; }
499     void setParent(RenderLayer* parent);
setFirstChild(RenderLayer * first)500     void setFirstChild(RenderLayer* first) { m_first = first; }
setLastChild(RenderLayer * last)501     void setLastChild(RenderLayer* last) { m_last = last; }
502 
renderBoxLocation()503     LayoutPoint renderBoxLocation() const { return renderer()->isBox() ? toRenderBox(renderer())->location() : LayoutPoint(); }
504 
505     void paintLayerContentsAndReflection(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
506     void paintLayerByApplyingTransform(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const LayoutPoint& translationOffset = LayoutPoint());
507     void paintLayerContents(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
508     void paintChildren(unsigned childrenToVisit, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
509     void paintPaginatedChildLayer(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
510     void paintChildLayerIntoColumns(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
511 
512     void collectFragments(LayerFragments&, const RenderLayer* rootLayer, RenderRegion*, const LayoutRect& dirtyRect,
513         ClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize,
514         ShouldRespectOverflowClip = RespectOverflowClip, const LayoutPoint* offsetFromRoot = 0, const LayoutRect* layerBoundingBox = 0);
515     void updatePaintingInfoForFragments(LayerFragments&, const LayerPaintingInfo&, PaintLayerFlags, bool shouldPaintContent, const LayoutPoint* offsetFromRoot);
516     void paintBackgroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
517         const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
518     void paintForegroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
519         const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer,
520         bool selectionOnly, bool forceBlackText);
521     void paintForegroundForFragmentsWithPhase(PaintPhase, const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
522     void paintOutlineForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
523     void paintOverflowControlsForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&);
524     void paintMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
525     void paintChildClippingMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
526     void paintTransformedLayerIntoFragments(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
527 
528     RenderLayer* hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest& request, HitTestResult& result,
529                               const LayoutRect& hitTestRect, const HitTestLocation&, bool appliedTransform,
530                               const HitTestingTransformState* transformState = 0, double* zOffset = 0);
531     RenderLayer* hitTestLayerByApplyingTransform(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
532         const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0,
533         const LayoutPoint& translationOffset = LayoutPoint());
534     RenderLayer* hitTestChildren(ChildrenIteration, RenderLayer* rootLayer, const HitTestRequest&, HitTestResult&,
535                              const LayoutRect& hitTestRect, const HitTestLocation&,
536                              const HitTestingTransformState* transformState, double* zOffsetForDescendants, double* zOffset,
537                              const HitTestingTransformState* unflattenedTransformState, bool depthSortDescendants);
538     RenderLayer* hitTestPaginatedChildLayer(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
539                                             const LayoutRect& hitTestRect, const HitTestLocation&,
540                                             const HitTestingTransformState* transformState, double* zOffset);
541     RenderLayer* hitTestChildLayerColumns(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
542                                           const LayoutRect& hitTestRect, const HitTestLocation&,
543                                           const HitTestingTransformState* transformState, double* zOffset,
544                                           const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
545 
546     PassRefPtr<HitTestingTransformState> createLocalTransformState(RenderLayer* rootLayer, RenderLayer* containerLayer,
547                             const LayoutRect& hitTestRect, const HitTestLocation&,
548                             const HitTestingTransformState* containerTransformState,
549                             const LayoutPoint& translationOffset = LayoutPoint()) const;
550 
551     bool hitTestContents(const HitTestRequest&, HitTestResult&, const LayoutRect& layerBounds, const HitTestLocation&, HitTestFilter) const;
552     bool hitTestContentsForFragments(const LayerFragments&, const HitTestRequest&, HitTestResult&, const HitTestLocation&, HitTestFilter, bool& insideClipRect) const;
553     RenderLayer* hitTestTransformedLayerInFragments(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
554         const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0);
555 
556     bool childBackgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
557 
558     bool shouldBeSelfPaintingLayer() const;
559 
560 private:
561     // FIXME: We should only create the stacking node if needed.
requiresStackingNode()562     bool requiresStackingNode() const { return true; }
563     void updateStackingNode();
564 
565     void updateReflectionInfo(const RenderStyle*);
566 
567     // FIXME: We could lazily allocate our ScrollableArea based on style properties ('overflow', ...)
568     // but for now, we are always allocating it for RenderBox as it's safer.
requiresScrollableArea()569     bool requiresScrollableArea() const { return renderBox(); }
570     void updateScrollableArea();
571 
572     // Returns true our scrollable area is in the FrameView's collection of scrollable areas. This can
573     // only happen if we're both scrollable, and we do in fact overflow.
574     bool scrollsOverflow() const;
575 
576     void dirtyAncestorChainVisibleDescendantStatus();
577     void setAncestorChainHasVisibleDescendant();
578 
579     void dirtyAncestorChainBlendedDescendantStatus();
580     void setAncestorChainBlendedDescendant();
581 
582     void updateDescendantDependentFlags();
583 
584     // This flag is computed by RenderLayerCompositor, which knows more about 3d hierarchies than we do.
setHas3DTransformedDescendant(bool b)585     void setHas3DTransformedDescendant(bool b) { m_has3DTransformedDescendant = b; }
has3DTransformedDescendant()586     bool has3DTransformedDescendant() const { return m_has3DTransformedDescendant; }
587 
588     void dirty3DTransformedDescendantStatus();
589     // Both updates the status, and returns true if descendants of this have 3d.
590     bool update3DTransformedDescendantStatus();
591 
592     void updateOrRemoveFilterClients();
593     void updateOrRemoveFilterEffectRenderer();
594 
595     void parentClipRects(const ClipRectsContext&, ClipRects&) const;
596     ClipRect backgroundClipRect(const ClipRectsContext&) const;
597 
598     LayoutRect paintingExtent(const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, PaintBehavior);
599 
600     RenderLayer* enclosingTransformedAncestor() const;
601 
602     void updatePagination();
603 
604     // FIXME: Temporary. Remove when new columns come online.
605     bool useRegionBasedColumns() const;
606 
hasCompositingDescendant()607     bool hasCompositingDescendant() const { return m_compositingProperties.hasCompositingDescendant; }
setHasCompositingDescendant(bool b)608     void setHasCompositingDescendant(bool b)  { m_compositingProperties.hasCompositingDescendant = b; }
609 
hasNonCompositedChild()610     bool hasNonCompositedChild() const { return m_compositingProperties.hasNonCompositedChild; }
setHasNonCompositedChild(bool b)611     void setHasNonCompositedChild(bool b)  { m_compositingProperties.hasNonCompositedChild = b; }
612 
shouldIsolateCompositedDescendants()613     bool shouldIsolateCompositedDescendants() const { return m_compositingProperties.shouldIsolateCompositedDescendants; }
setShouldIsolateCompositedDescendants(bool b)614     void setShouldIsolateCompositedDescendants(bool b)  { m_compositingProperties.shouldIsolateCompositedDescendants = b; }
615 
setCompositingReasons(CompositingReasons reasons)616     void setCompositingReasons(CompositingReasons reasons) { m_compositingProperties.compositingReasons = reasons; }
compositingReasons()617     CompositingReasons compositingReasons() const { return m_compositingProperties.compositingReasons; }
618 
619     friend class CompositedLayerMapping;
620     friend class RenderLayerCompositor;
621     friend class RenderLayerModelObject;
622 
623 protected:
624     unsigned m_isSelfPaintingLayer : 1;
625 
626     // If have no self-painting descendants, we don't have to walk our children during painting. This can lead to
627     // significant savings, especially if the tree has lots of non-self-painting layers grouped together (e.g. table cells).
628     unsigned m_hasSelfPaintingLayerDescendant : 1;
629     unsigned m_hasSelfPaintingLayerDescendantDirty : 1;
630 
631     unsigned m_hasOutOfFlowPositionedDescendant : 1;
632     unsigned m_hasOutOfFlowPositionedDescendantDirty : 1;
633 
634     // This is true if we have an out-of-flow positioned descendant whose
635     // containing block is our ancestor. If this is the case, the descendant
636     // may fall outside of our clip preventing things like opting into
637     // composited scrolling (which causes clipping of all descendants).
638     unsigned m_hasUnclippedDescendant : 1;
639 
640     unsigned m_isUnclippedDescendant : 1;
641 
642     const unsigned m_isRootLayer : 1;
643 
644     unsigned m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether
645                                  // we ended up painting this layer or any descendants (and therefore need to
646                                  // blend).
647 
648     unsigned m_childLayerHasBlendMode : 1;
649     unsigned m_childLayerHasBlendModeStatusDirty : 1;
650 
651     unsigned m_visibleContentStatusDirty : 1;
652     unsigned m_hasVisibleContent : 1;
653     unsigned m_visibleDescendantStatusDirty : 1;
654     unsigned m_hasVisibleDescendant : 1;
655 
656     unsigned m_hasVisibleNonLayerContent : 1;
657 
658     unsigned m_isPaginated : 1; // If we think this layer is split by a multi-column ancestor, then this bit will be set.
659 
660     unsigned m_3DTransformedDescendantStatusDirty : 1;
661     // Set on a stacking context layer that has 3D descendants anywhere
662     // in a preserves3D hierarchy. Hint to do 3D-aware hit testing.
663     unsigned m_has3DTransformedDescendant : 1;
664 
665     unsigned m_containsDirtyOverlayScrollbars : 1;
666 
667     // This is an optimization added for <table>.
668     // Currently cells do not need to update their repaint rectangles when scrolling. This also
669     // saves a lot of time when scrolling on a table.
670     const unsigned m_canSkipRepaintRectsUpdateOnScroll : 1;
671 
672     unsigned m_hasFilterInfo : 1;
673 
674     blink::WebBlendMode m_blendMode;
675 
676     RenderLayerModelObject* m_renderer;
677 
678     RenderLayer* m_parent;
679     RenderLayer* m_previous;
680     RenderLayer* m_next;
681     RenderLayer* m_first;
682     RenderLayer* m_last;
683 
684     // Our current relative position offset.
685     LayoutSize m_offsetForInFlowPosition;
686 
687     // Our (x,y) coordinates are in our parent layer's coordinate space.
688     LayoutPoint m_topLeft;
689 
690     // The layer's width/height
691     IntSize m_layerSize;
692 
693     // Cached normal flow values for absolute positioned elements with static left/top values.
694     LayoutUnit m_staticInlinePosition;
695     LayoutUnit m_staticBlockPosition;
696 
697     OwnPtr<TransformationMatrix> m_transform;
698 
699     // Pointer to the enclosing RenderLayer that caused us to be paginated. It is 0 if we are not paginated.
700     RenderLayer* m_enclosingPaginationLayer;
701 
702     // Properties that are computed while updating compositing layers. These values may be dirty/invalid if
703     // compositing status is not up-to-date before using them.
704     struct CompositingProperties {
CompositingPropertiesCompositingProperties705         CompositingProperties()
706             : hasCompositingDescendant(false)
707             , hasNonCompositedChild(false)
708             , shouldIsolateCompositedDescendants(false)
709             , viewportConstrainedNotCompositedReason(NoNotCompositedReason)
710             , compositingReasons(CompositingReasonNone)
711         { }
712 
713         // Used only while determining what layers should be composited. Applies to the tree of z-order lists.
714         bool hasCompositingDescendant : 1;
715 
716         // Applies to the real render layer tree (i.e., the tree determined by the layer's parent and children and
717         // as opposed to the tree formed by the z-order and normal flow lists).
718         bool hasNonCompositedChild : 1;
719 
720         // Should be for stacking contexts having unisolated blending descendants.
721         bool shouldIsolateCompositedDescendants : 1;
722 
723         // The reason, if any exists, that a fixed-position layer is chosen not to be composited.
724         unsigned viewportConstrainedNotCompositedReason : 2;
725 
726         // Once computed, indicates all that a layer needs to become composited using the CompositingReasons enum bitfield.
727         CompositingReasons compositingReasons;
728 
729         // Used for invalidating this layer's contents on the squashing GraphicsLayer.
730         IntSize offsetFromSquashingLayerOrigin;
731     };
732 
733     CompositingProperties m_compositingProperties;
734 
735 private:
736     enum CompositedScrollingHistogramBuckets {
737         IsScrollableAreaBucket = 0,
738         NeedsToBeStackingContainerBucket = 1,
739         WillUseCompositedScrollingBucket = 2,
740         CompositedScrollingHistogramMax = 3
741     };
742 
743     IntRect m_blockSelectionGapsBounds;
744 
745     OwnPtr<CompositedLayerMapping> m_compositedLayerMapping;
746     OwnPtr<RenderLayerScrollableArea> m_scrollableArea;
747 
748     CompositedLayerMapping* m_groupedMapping;
749 
750     RenderLayerRepainter m_repainter;
751     RenderLayerClipper m_clipper; // FIXME: Lazily allocate?
752     OwnPtr<RenderLayerStackingNode> m_stackingNode;
753     OwnPtr<RenderLayerReflectionInfo> m_reflectionInfo;
754 };
755 
756 } // namespace WebCore
757 
758 #ifndef NDEBUG
759 // Outside the WebCore namespace for ease of invocation from gdb.
760 void showLayerTree(const WebCore::RenderLayer*);
761 void showLayerTree(const WebCore::RenderObject*);
762 #endif
763 
764 #endif // RenderLayer_h
765