Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderLayer.h
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/compositing/CompositedLayerMappingPtr.h"
49 #include "core/rendering/LayerPaintingInfo.h"
50 #include "core/rendering/RenderBox.h"
51 #include "core/rendering/RenderLayerBlendInfo.h"
52 #include "core/rendering/RenderLayerClipper.h"
53 #include "core/rendering/RenderLayerFilterInfo.h"
54 #include "core/rendering/RenderLayerReflectionInfo.h"
55 #include "core/rendering/RenderLayerRepainter.h"
56 #include "core/rendering/RenderLayerScrollableArea.h"
57 #include "core/rendering/RenderLayerStackingNode.h"
58 #include "core/rendering/RenderLayerStackingNodeIterator.h"
59 #include "platform/graphics/CompositingReasons.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 RenderFlowThread;
70 class RenderGeometryMap;
71 class CompositedLayerMapping;
72 class RenderLayerCompositor;
73 class RenderReplica;
74 class RenderStyle;
75 class TransformationMatrix;
76
77 enum BorderRadiusClippingRule { IncludeSelfForBorderRadius, DoNotIncludeSelfForBorderRadius };
78 enum IncludeSelfOrNot { IncludeSelf, ExcludeSelf };
79
80 enum CompositedScrollingHistogramBuckets {
81     IsScrollableAreaBucket = 0,
82     NeedsToBeStackingContainerBucket = 1,
83     WillUseCompositedScrollingBucket = 2,
84     CompositedScrollingHistogramMax = 3
85 };
86
87 enum CompositingQueryMode {
88     CompositingQueriesAreAllowed,
89     CompositingQueriesAreOnlyAllowedInCertainDocumentLifecyclePhases
90 };
91
92 // FIXME: remove this once the compositing query ASSERTS are no longer hit.
93 class DisableCompositingQueryAsserts {
94     WTF_MAKE_NONCOPYABLE(DisableCompositingQueryAsserts);
95 public:
96     DisableCompositingQueryAsserts();
97 private:
98     TemporaryChange<CompositingQueryMode> m_disabler;
99 };
100
101 class RenderLayer {
102     WTF_MAKE_NONCOPYABLE(RenderLayer);
103 public:
104     RenderLayer(RenderLayerModelObject*, LayerType);
105     ~RenderLayer();
106
107     String debugName() const;
108
109     RenderLayerModelObject* renderer() const { return m_renderer; }
110     RenderBox* renderBox() const { return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0; }
111     RenderLayer* parent() const { return m_parent; }
112     RenderLayer* previousSibling() const { return m_previous; }
113     RenderLayer* nextSibling() const { return m_next; }
114     RenderLayer* firstChild() const { return m_first; }
115     RenderLayer* lastChild() const { return m_last; }
116
117     const RenderLayer* compositingContainer() const;
118
119     void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0);
120     RenderLayer* removeChild(RenderLayer*);
121
122     void removeOnlyThisLayer();
123     void insertOnlyThisLayer();
124
125     void styleChanged(StyleDifference, const RenderStyle* oldStyle);
126
127     bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; }
128
129     void setLayerType(LayerType layerType) { m_layerType = layerType; }
130
131     bool cannotBlitToWindow() const;
132
133     bool isTransparent() const;
134     RenderLayer* transparentPaintingAncestor();
135     void beginTransparencyLayers(GraphicsContext*, const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, const LayoutSize& subPixelAccumulation, PaintBehavior);
136
137     bool isReflection() const { return renderer()->isReplica(); }
138     RenderLayerReflectionInfo* reflectionInfo() { return m_reflectionInfo.get(); }
139     const RenderLayerReflectionInfo* reflectionInfo() const { return m_reflectionInfo.get(); }
140
141     const RenderLayer* root() const
142     {
143         const RenderLayer* curr = this;
144         while (curr->parent())
145             curr = curr->parent();
146         return curr;
147     }
148
149     const LayoutPoint& location() const { return m_topLeft; }
150     void setLocation(const LayoutPoint& p) { m_topLeft = p; }
151
152     const IntSize& size() const { return m_layerSize; }
153     void setSize(const IntSize& size) { m_layerSize = size; }
154
155     LayoutRect rect() const { return LayoutRect(location(), size()); }
156
157     bool isRootLayer() const { return m_isRootLayer; }
158
159     RenderLayerCompositor* compositor() const;
160
161     // Notification from the renderer that its content changed (e.g. current frame of image changed).
162     // Allows updates of layer content without repainting.
163     void contentChanged(ContentChangeType);
164
165     enum UpdateLayerPositionsFlag {
166         CheckForRepaint = 1 << 0,
167         NeedsFullRepaintInBacking = 1 << 1,
168         UpdatePagination = 1 << 2,
169     };
170     typedef unsigned UpdateLayerPositionsFlags;
171
172     void updateLayerPositionsAfterLayout(const RenderLayer* rootLayer, UpdateLayerPositionsFlags);
173     void updateLayerPositionsAfterOverflowScroll();
174     void updateLayerPositionsAfterDocumentScroll();
175
176     // FIXME: Should updateLayerPositions be private?
177     void updateLayerPositions(RenderGeometryMap*, UpdateLayerPositionsFlags = CheckForRepaint);
178
179     bool isPaginated() const { return m_isPaginated; }
180     RenderLayer* enclosingPaginationLayer() const { return m_enclosingPaginationLayer; }
181
182     void updateTransform();
183     RenderLayer* renderingContextRoot();
184
185     const LayoutSize& offsetForInFlowPosition() const { return m_offsetForInFlowPosition; }
186
187     void addBlockSelectionGapsBounds(const LayoutRect&);
188     void clearBlockSelectionGapsBounds();
189     void repaintBlockSelectionGaps();
190     bool hasBlockSelectionGapBounds() const;
191
192     RenderLayerStackingNode* stackingNode() { return m_stackingNode.get(); }
193     const RenderLayerStackingNode* stackingNode() const { return m_stackingNode.get(); }
194
195     bool subtreeIsInvisible() const { return !hasVisibleContent() && !hasVisibleDescendant(); }
196
197     // FIXME: We should ASSERT(!m_visibleContentStatusDirty) here, but see https://bugs.webkit.org/show_bug.cgi?id=71044
198     // ditto for hasVisibleDescendant(), see https://bugs.webkit.org/show_bug.cgi?id=71277
199     bool hasVisibleContent() const { return m_hasVisibleContent; }
200     bool hasVisibleDescendant() const { return m_hasVisibleDescendant; }
201
202     void setHasVisibleContent();
203     void dirtyVisibleContentStatus();
204
205     bool hasBoxDecorationsOrBackground() const;
206     bool hasVisibleBoxDecorations() const;
207     // Returns true if this layer has visible content (ignoring any child layers).
208     bool isVisuallyNonEmpty() const;
209     // True if this layer container renderers that paint.
210     bool hasNonEmptyChildRenderers() const;
211
212     // FIXME: We should ASSERT(!m_hasSelfPaintingLayerDescendantDirty); here but we hit the same bugs as visible content above.
213     // Part of the issue is with subtree relayout: we don't check if our ancestors have some descendant flags dirty, missing some updates.
214     bool hasSelfPaintingLayerDescendant() const { return m_hasSelfPaintingLayerDescendant; }
215
216     // FIXME: We should ASSERT(!m_hasOutOfFlowPositionedDescendantDirty) here. See above.
217     bool hasOutOfFlowPositionedDescendant() const { return m_hasOutOfFlowPositionedDescendant; }
218
219     void setHasOutOfFlowPositionedDescendant(bool hasDescendant) { m_hasOutOfFlowPositionedDescendant = hasDescendant; }
220     void setHasOutOfFlowPositionedDescendantDirty(bool dirty) { m_hasOutOfFlowPositionedDescendantDirty = dirty; }
221
222
223     bool hasUnclippedDescendant() const { return m_hasUnclippedDescendant; }
224     void setHasUnclippedDescendant(bool hasDescendant) { m_hasUnclippedDescendant = hasDescendant; }
225     void updateHasUnclippedDescendant();
226     bool isUnclippedDescendant() const { return m_isUnclippedDescendant; }
227
228     // Will ensure that hasUnclippedDescendant and hasNonCompositiedChild are up to date.
229     void updateScrollingStateAfterCompositingChange();
230     bool hasVisibleNonLayerContent() const { return m_hasVisibleNonLayerContent; }
231     bool hasNonCompositedChild() const { ASSERT(isAllowedToQueryCompositingState()); return m_hasNonCompositedChild; }
232
233     bool usedTransparency() const { return m_usedTransparency; }
234
235     // Gets the nearest enclosing positioned ancestor layer (also includes
236     // the <html> layer and the root layer).
237     RenderLayer* enclosingPositionedAncestor() const;
238
239     RenderLayer* enclosingOverflowClipLayer(IncludeSelfOrNot = IncludeSelf) const;
240
241     // Enclosing compositing layer; if includeSelf is true, may return this.
242     RenderLayer* enclosingCompositingLayer(IncludeSelfOrNot = IncludeSelf) const;
243     RenderLayer* enclosingCompositingLayerForRepaint(IncludeSelfOrNot = IncludeSelf) const;
244     // Ancestor compositing layer, excluding this.
245     RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(ExcludeSelf); }
246
247     // Ancestor composited scrolling layer at or above our containing block.
248     RenderLayer* ancestorCompositedScrollingLayer() const;
249
250     // Ancestor scrolling layer at or above our containing block.
251     RenderLayer* ancestorScrollingLayer() const;
252
253     RenderLayer* enclosingFilterLayer(IncludeSelfOrNot = IncludeSelf) const;
254     bool hasAncestorWithFilterOutsets() const;
255
256     bool canUseConvertToLayerCoords() const
257     {
258         // These RenderObjects have an impact on their layers without the renderers knowing about it.
259         return !renderer()->hasColumns() && !renderer()->hasTransform() && !renderer()->isSVGRoot();
260     }
261
262     void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint& location) const;
263     void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect&) const;
264
265     // The two main functions that use the layer system.  The paint method
266     // paints the layers that intersect the damage rect from back to
267     // front.  The hitTest method looks for mouse events by walking
268     // layers that intersect the point from front to back.
269     // paint() assumes that the caller will clip to the bounds of damageRect if necessary.
270     void paint(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior = PaintBehaviorNormal, RenderObject* paintingRoot = 0, PaintLayerFlags = 0);
271     bool hitTest(const HitTestRequest&, HitTestResult&);
272     bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&);
273     void paintOverlayScrollbars(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior, RenderObject* paintingRoot = 0);
274
275     // Pass offsetFromRoot if known.
276     bool intersectsDamageRect(const LayoutRect& layerBounds, const LayoutRect& damageRect, const RenderLayer* rootLayer, const LayoutPoint* offsetFromRoot = 0) const;
277
278     // Bounding box relative to some ancestor layer. Pass offsetFromRoot if known.
279     LayoutRect physicalBoundingBox(const RenderLayer* ancestorLayer, const LayoutPoint* offsetFromRoot = 0) const;
280     LayoutRect physicalBoundingBoxIncludingReflectionAndStackingChildren(const RenderLayer* ancestorLayer, const LayoutPoint& offsetFromRoot) const;
281
282     // FIXME: This function is inconsistent as to whether the returned rect has been flipped for writing mode.
283     LayoutRect boundingBoxForCompositingOverlapTest() const { return overlapBoundsIncludeChildren() ? boundingBoxForCompositing() : logicalBoundingBox(); }
284
285     // If true, this layer's children are included in its bounds for overlap testing.
286     // We can't rely on the children's positions if this layer has a filter that could have moved the children's pixels around.
287     bool overlapBoundsIncludeChildren() const { return hasFilter() && renderer()->style()->filter().hasFilterThatMovesPixels(); }
288
289     enum CalculateBoundsOptions {
290         ApplyBoundsChickenEggHacks,
291         DoNotApplyBoundsChickenEggHacks,
292     };
293     LayoutRect boundingBoxForCompositing(const RenderLayer* ancestorLayer = 0, CalculateBoundsOptions = DoNotApplyBoundsChickenEggHacks) const;
294
295     LayoutUnit staticInlinePosition() const { return m_staticInlinePosition; }
296     LayoutUnit staticBlockPosition() const { return m_staticBlockPosition; }
297
298     void setStaticInlinePosition(LayoutUnit position) { m_staticInlinePosition = position; }
299     void setStaticBlockPosition(LayoutUnit position) { m_staticBlockPosition = position; }
300
301     LayoutSize subpixelAccumulation() const;
302     void setSubpixelAccumulation(const LayoutSize&);
303
304     bool hasTransform() const { return renderer()->hasTransform(); }
305     // Note that this transform has the transform-origin baked in.
306     TransformationMatrix* transform() const { return m_transform.get(); }
307     // currentTransform computes a transform which takes accelerated animations into account. The
308     // resulting transform has transform-origin baked in. If the layer does not have a transform,
309     // returns the identity matrix.
310     TransformationMatrix currentTransform(RenderStyle::ApplyTransformOrigin = RenderStyle::IncludeTransformOrigin) const;
311     TransformationMatrix renderableTransform(PaintBehavior) const;
312
313     // Get the perspective transform, which is applied to transformed sublayers.
314     // Returns true if the layer has a -webkit-perspective.
315     // Note that this transform has the perspective-origin baked in.
316     TransformationMatrix perspectiveTransform() const;
317     FloatPoint perspectiveOrigin() const;
318     bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
319     bool has3DTransform() const { return m_transform && !m_transform->isAffine(); }
320
321     // FIXME: reflections should force transform-style to be flat in the style: https://bugs.webkit.org/show_bug.cgi?id=106959
322     bool shouldPreserve3D() const { return !renderer()->hasReflection() && renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
323
324     void filterNeedsRepaint();
325     bool hasFilter() const { return renderer()->hasFilter(); }
326
327     bool paintsWithBlendMode() const;
328
329     void* operator new(size_t);
330     // Only safe to call from RenderLayerModelObject::destroyLayer()
331     void operator delete(void*);
332
333     CompositingState compositingState() const;
334
335     // This returns true if our document is in a phase of its lifestyle during which
336     // compositing state may legally be read.
337     bool isAllowedToQueryCompositingState() const;
338
339     CompositedLayerMappingPtr compositedLayerMapping() const;
340     CompositedLayerMappingPtr ensureCompositedLayerMapping();
341
342     // NOTE: If you are using hasCompositedLayerMapping to determine the state of compositing for this layer,
343     // (and not just to do bookkeeping related to the mapping like, say, allocating or deallocating a mapping),
344     // then you may have incorrect logic. Use compositingState() instead.
345     bool hasCompositedLayerMapping() const { return m_compositedLayerMapping.get(); }
346     void clearCompositedLayerMapping(bool layerBeingDestroyed = false);
347
348     CompositedLayerMapping* groupedMapping() const { return m_groupedMapping; }
349     void setGroupedMapping(CompositedLayerMapping* groupedMapping, bool layerBeingDestroyed = false);
350
351     bool hasCompositedMask() const;
352     bool hasCompositedClippingMask() const;
353     bool needsCompositedScrolling() const { return m_scrollableArea && m_scrollableArea->needsCompositedScrolling(); }
354
355     bool clipsCompositingDescendantsWithBorderRadius() const;
356
357     RenderLayer* scrollParent() const;
358     RenderLayer* clipParent() const;
359
360     bool needsCompositingLayersRebuiltForClip(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
361     bool needsCompositingLayersRebuiltForOverflow(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
362     bool needsCompositingLayersRebuiltForFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
363     bool needsCompositingLayersRebuiltForBlending(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
364
365     bool paintsWithTransparency(PaintBehavior paintBehavior) const
366     {
367         return isTransparent() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || compositingState() != PaintsIntoOwnBacking);
368     }
369
370     bool paintsWithTransform(PaintBehavior) const;
371
372     // Returns true if background phase is painted opaque in the given rect.
373     // The query rect is given in local coordinates.
374     bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
375
376     bool containsDirtyOverlayScrollbars() const { return m_containsDirtyOverlayScrollbars; }
377     void setContainsDirtyOverlayScrollbars(bool dirtyScrollbars) { m_containsDirtyOverlayScrollbars = dirtyScrollbars; }
378
379     FilterOperations computeFilterOperations(const RenderStyle*);
380     bool paintsWithFilters() const;
381     bool requiresFullLayerImageForFilters() const;
382     FilterEffectRenderer* filterRenderer() const
383     {
384         RenderLayerFilterInfo* filterInfo = this->filterInfo();
385         return filterInfo ? filterInfo->renderer() : 0;
386     }
387
388     RenderLayerFilterInfo* filterInfo() const { return hasFilterInfo() ? RenderLayerFilterInfo::filterInfoForRenderLayer(this) : 0; }
389     RenderLayerFilterInfo* ensureFilterInfo() { return RenderLayerFilterInfo::createFilterInfoForRenderLayerIfNeeded(this); }
390     void removeFilterInfoIfNeeded()
391     {
392         if (hasFilterInfo())
393             RenderLayerFilterInfo::removeFilterInfoForRenderLayer(this);
394     }
395
396     bool hasFilterInfo() const { return m_hasFilterInfo; }
397     void setHasFilterInfo(bool hasFilterInfo) { m_hasFilterInfo = hasFilterInfo; }
398
399     void updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle);
400
401     Node* enclosingElement() const;
402
403     bool isInTopLayer() const;
404
405     enum ViewportConstrainedNotCompositedReason {
406         NoNotCompositedReason = 0,
407         NotCompositedForBoundsOutOfView,
408         NotCompositedForNonViewContainer,
409         NotCompositedForNoVisibleContent,
410         NotCompositedForUnscrollableAncestors,
411         NumNotCompositedReasons,
412
413         // This is the number of bits used to store the viewport constrained not composited
414         // reasons. We define this constant since sizeof won't return the number of bits, and we
415         // shouldn't duplicate the constant.
416         ViewportConstrainedNotCompositedReasonBits = 3
417     };
418
419     void setViewportConstrainedNotCompositedReason(ViewportConstrainedNotCompositedReason reason) { m_viewportConstrainedNotCompositedReason = reason; }
420     ViewportConstrainedNotCompositedReason viewportConstrainedNotCompositedReason() const { ASSERT(isAllowedToQueryCompositingState()); return static_cast<ViewportConstrainedNotCompositedReason>(m_viewportConstrainedNotCompositedReason); }
421
422     bool isOutOfFlowRenderFlowThread() const { return renderer()->isOutOfFlowRenderFlowThread(); }
423
424     bool scrollsWithRespectTo(const RenderLayer*) const;
425
426     void addLayerHitTestRects(LayerHitTestRects&) const;
427
428     // Compute rects only for this layer
429     void computeSelfHitTestRects(LayerHitTestRects&) const;
430
431     // FIXME: This should probably return a ScrollableArea but a lot of internal methods are mistakenly exposed.
432     RenderLayerScrollableArea* scrollableArea() const { return m_scrollableArea.get(); }
433     RenderLayerRepainter& repainter() { return m_repainter; }
434     RenderLayerClipper& clipper() { return m_clipper; }
435     const RenderLayerClipper& clipper() const { return m_clipper; }
436
437     inline bool isPositionedContainer() const
438     {
439         // FIXME: This is not in sync with containingBlock.
440         // RenderObject::canContainFixedPositionedObject() should probably be used
441         // instead.
442         RenderLayerModelObject* layerRenderer = renderer();
443         return isRootLayer() || layerRenderer->isPositioned() || hasTransform();
444     }
445
446     // paintLayer() assumes that the caller will clip to the bounds of the painting dirty if necessary.
447     void paintLayer(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
448
449     PassOwnPtr<Vector<FloatRect> > collectTrackedRepaintRects() const;
450
451     RenderLayerBlendInfo& blendInfo() { return m_blendInfo; }
452
453     void setOffsetFromSquashingLayerOrigin(IntSize offset) { m_offsetFromSquashingLayerOrigin = offset; }
454     IntSize offsetFromSquashingLayerOrigin() const { ASSERT(isAllowedToQueryCompositingState()); return m_offsetFromSquashingLayerOrigin; }
455
456     bool scrollsOverflow() const;
457
458     bool hasDirectReasonsForCompositing() const { return compositingReasons() & CompositingReasonComboAllDirectReasons; }
459
460     CompositingReasons styleDeterminedCompositingReasons() const { return m_styleDeterminedCompositingReasons; }
461     void setStyleDeterminedCompositingReasons(CompositingReasons reasons) { ASSERT(reasons == (reasons & CompositingReasonComboAllStyleDeterminedReasons)); m_styleDeterminedCompositingReasons = reasons; }
462
463     class AncestorDependentProperties {
464     public:
465         AncestorDependentProperties()
466             : opacityAncestor(0)
467             , transformAncestor(0)
468             , filterAncestor(0)
469         { }
470
471         IntRect clippedAbsoluteBoundingBox;
472         const RenderLayer* opacityAncestor;
473         const RenderLayer* transformAncestor;
474         const RenderLayer* filterAncestor;
475     };
476
477     void setNeedsToUpdateAncestorDependentProperties();
478     bool childNeedsToUpdateAncestorDependantProperties() const { return m_childNeedsToUpdateAncestorDependantProperties; }
479     bool needsToUpdateAncestorDependentProperties() const { return m_needsToUpdateAncestorDependentProperties; }
480
481     void updateAncestorDependentProperties(const AncestorDependentProperties&);
482     void clearChildNeedsToUpdateAncestorDependantProperties();
483
484     const AncestorDependentProperties& ancestorDependentProperties() const { ASSERT(!m_needsToUpdateAncestorDependentProperties); return m_ancestorDependentProperties; }
485
486     bool lostGroupedMapping() const { ASSERT(isAllowedToQueryCompositingState()); return m_lostGroupedMapping; }
487     void setLostGroupedMapping(bool b) { m_lostGroupedMapping = b; }
488
489     CompositingReasons compositingReasons() const { ASSERT(isAllowedToQueryCompositingState()); return m_compositingReasons; }
490     void setCompositingReasons(CompositingReasons, CompositingReasons mask = CompositingReasonAll);
491
492     bool hasCompositingDescendant() const { ASSERT(isAllowedToQueryCompositingState()); return m_hasCompositingDescendant; }
493     void setHasCompositingDescendant(bool b)  { m_hasCompositingDescendant = b; }
494
495     bool shouldIsolateCompositedDescendants() const { ASSERT(isAllowedToQueryCompositingState()); return m_shouldIsolateCompositedDescendants; }
496     void setShouldIsolateCompositedDescendants(bool b)  { m_shouldIsolateCompositedDescendants = b; }
497
498     void updateDescendantDependentFlags();
499
500     void updateOrRemoveFilterEffectRenderer();
501
502     void updateSelfPaintingLayer();
503
504     // paintLayerContents() assumes that the caller will clip to the bounds of the painting dirty rect if necessary.
505     void paintLayerContents(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
506
507     RenderLayer* enclosingTransformedAncestor() const;
508     LayoutPoint computeOffsetFromTransformedAncestor() const;
509
510     void didUpdateNeedsCompositedScrolling();
511
512 private:
513     // Bounding box in the coordinates of this layer.
514     LayoutRect logicalBoundingBox() const;
515
516     bool hasOverflowControls() const;
517
518     void setIsUnclippedDescendant(bool isUnclippedDescendant) { m_isUnclippedDescendant = isUnclippedDescendant; }
519
520     void setAncestorChainHasSelfPaintingLayerDescendant();
521     void dirtyAncestorChainHasSelfPaintingLayerDescendantStatus();
522
523     void setAncestorChainHasOutOfFlowPositionedDescendant();
524     void dirtyAncestorChainHasOutOfFlowPositionedDescendantStatus();
525
526     void clipToRect(const LayerPaintingInfo&, GraphicsContext*, const ClipRect&, BorderRadiusClippingRule = IncludeSelfForBorderRadius);
527     void restoreClip(GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&);
528
529     void updateOutOfFlowPositioned(const RenderStyle* oldStyle);
530
531     // Returns true if the position changed.
532     bool updateLayerPosition();
533
534     enum UpdateLayerPositionsAfterScrollFlag {
535         NoFlag = 0,
536         IsOverflowScroll = 1 << 0,
537         HasSeenViewportConstrainedAncestor = 1 << 1,
538         HasSeenAncestorWithOverflowClip = 1 << 2,
539         HasChangedAncestor = 1 << 3
540     };
541     typedef unsigned UpdateLayerPositionsAfterScrollFlags;
542     void updateLayerPositionsAfterScroll(RenderGeometryMap*, UpdateLayerPositionsAfterScrollFlags = NoFlag);
543
544     void setNextSibling(RenderLayer* next) { m_next = next; }
545     void setPreviousSibling(RenderLayer* prev) { m_previous = prev; }
546     void setFirstChild(RenderLayer* first) { m_first = first; }
547     void setLastChild(RenderLayer* last) { m_last = last; }
548
549     LayoutPoint renderBoxLocation() const { return renderer()->isBox() ? toRenderBox(renderer())->location() : LayoutPoint(); }
550
551     void paintLayerContentsAndReflection(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
552     void paintLayerByApplyingTransform(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const LayoutPoint& translationOffset = LayoutPoint());
553     void paintChildren(unsigned childrenToVisit, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
554     void paintPaginatedChildLayer(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
555     void paintChildLayerIntoColumns(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
556
557     void collectFragments(LayerFragments&, const RenderLayer* rootLayer, const LayoutRect& dirtyRect,
558         ClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize,
559         ShouldRespectOverflowClip = RespectOverflowClip, const LayoutPoint* offsetFromRoot = 0,
560         const LayoutSize& subPixelAccumulation = LayoutSize(), const LayoutRect* layerBoundingBox = 0);
561     void updatePaintingInfoForFragments(LayerFragments&, const LayerPaintingInfo&, PaintLayerFlags, bool shouldPaintContent, const LayoutPoint* offsetFromRoot);
562     void paintBackgroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
563         const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
564     void paintForegroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
565         const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer,
566         bool selectionOnly, bool forceBlackText);
567     void paintForegroundForFragmentsWithPhase(PaintPhase, const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
568     void paintOutlineForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
569     void paintOverflowControlsForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&);
570     void paintMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
571     void paintChildClippingMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
572     void paintTransformedLayerIntoFragments(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
573
574     RenderLayer* hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest& request, HitTestResult& result,
575                               const LayoutRect& hitTestRect, const HitTestLocation&, bool appliedTransform,
576                               const HitTestingTransformState* transformState = 0, double* zOffset = 0);
577     RenderLayer* hitTestLayerByApplyingTransform(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
578         const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0,
579         const LayoutPoint& translationOffset = LayoutPoint());
580     RenderLayer* hitTestChildren(ChildrenIteration, RenderLayer* rootLayer, const HitTestRequest&, HitTestResult&,
581                              const LayoutRect& hitTestRect, const HitTestLocation&,
582                              const HitTestingTransformState* transformState, double* zOffsetForDescendants, double* zOffset,
583                              const HitTestingTransformState* unflattenedTransformState, bool depthSortDescendants);
584     RenderLayer* hitTestPaginatedChildLayer(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
585                                             const LayoutRect& hitTestRect, const HitTestLocation&,
586                                             const HitTestingTransformState* transformState, double* zOffset);
587     RenderLayer* hitTestChildLayerColumns(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
588                                           const LayoutRect& hitTestRect, const HitTestLocation&,
589                                           const HitTestingTransformState* transformState, double* zOffset,
590                                           const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
591
592     PassRefPtr<HitTestingTransformState> createLocalTransformState(RenderLayer* rootLayer, RenderLayer* containerLayer,
593                             const LayoutRect& hitTestRect, const HitTestLocation&,
594                             const HitTestingTransformState* containerTransformState,
595                             const LayoutPoint& translationOffset = LayoutPoint()) const;
596
597     bool hitTestContents(const HitTestRequest&, HitTestResult&, const LayoutRect& layerBounds, const HitTestLocation&, HitTestFilter) const;
598     bool hitTestContentsForFragments(const LayerFragments&, const HitTestRequest&, HitTestResult&, const HitTestLocation&, HitTestFilter, bool& insideClipRect) const;
599     RenderLayer* hitTestTransformedLayerInFragments(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
600         const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0);
601
602     bool childBackgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
603
604     bool shouldBeSelfPaintingLayer() const;
605
606     // FIXME: We should only create the stacking node if needed.
607     bool requiresStackingNode() const { return true; }
608     void updateStackingNode();
609
610     void updateReflectionInfo(const RenderStyle*);
611
612     // FIXME: We could lazily allocate our ScrollableArea based on style properties ('overflow', ...)
613     // but for now, we are always allocating it for RenderBox as it's safer.
614     bool requiresScrollableArea() const { return renderBox(); }
615     void updateScrollableArea();
616
617     void dirtyAncestorChainVisibleDescendantStatus();
618     void setAncestorChainHasVisibleDescendant();
619
620     void dirty3DTransformedDescendantStatus();
621     // Both updates the status, and returns true if descendants of this have 3d.
622     bool update3DTransformedDescendantStatus();
623
624     void updateOrRemoveFilterClients();
625
626     LayoutRect paintingExtent(const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, const LayoutSize& subPixelAccumulation, PaintBehavior);
627
628     void updatePagination();
629
630     // FIXME: Temporary. Remove when new columns come online.
631     bool useRegionBasedColumns() const;
632
633     LayerType m_layerType;
634
635     // Self-painting layer is an optimization where we avoid the heavy RenderLayer painting
636     // machinery for a RenderLayer allocated only to handle the overflow clip case.
637     // FIXME(crbug.com/332791): Self-painting layer should be merged into the overflow-only concept.
638     unsigned m_isSelfPaintingLayer : 1;
639
640     // If have no self-painting descendants, we don't have to walk our children during painting. This can lead to
641     // significant savings, especially if the tree has lots of non-self-painting layers grouped together (e.g. table cells).
642     unsigned m_hasSelfPaintingLayerDescendant : 1;
643     unsigned m_hasSelfPaintingLayerDescendantDirty : 1;
644
645     unsigned m_hasOutOfFlowPositionedDescendant : 1;
646     unsigned m_hasOutOfFlowPositionedDescendantDirty : 1;
647
648     // This is true if we have an out-of-flow positioned descendant whose
649     // containing block is our ancestor. If this is the case, the descendant
650     // may fall outside of our clip preventing things like opting into
651     // composited scrolling (which causes clipping of all descendants).
652     unsigned m_hasUnclippedDescendant : 1;
653
654     unsigned m_isUnclippedDescendant : 1;
655
656     const unsigned m_isRootLayer : 1;
657
658     unsigned m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether
659                                  // we ended up painting this layer or any descendants (and therefore need to
660                                  // blend).
661
662     unsigned m_visibleContentStatusDirty : 1;
663     unsigned m_hasVisibleContent : 1;
664     unsigned m_visibleDescendantStatusDirty : 1;
665     unsigned m_hasVisibleDescendant : 1;
666
667     unsigned m_hasVisibleNonLayerContent : 1;
668
669     unsigned m_isPaginated : 1; // If we think this layer is split by a multi-column ancestor, then this bit will be set.
670
671     unsigned m_3DTransformedDescendantStatusDirty : 1;
672     // Set on a stacking context layer that has 3D descendants anywhere
673     // in a preserves3D hierarchy. Hint to do 3D-aware hit testing.
674     unsigned m_has3DTransformedDescendant : 1;
675
676     unsigned m_containsDirtyOverlayScrollbars : 1;
677
678     // This is an optimization added for <table>.
679     // Currently cells do not need to update their repaint rectangles when scrolling. This also
680     // saves a lot of time when scrolling on a table.
681     const unsigned m_canSkipRepaintRectsUpdateOnScroll : 1;
682
683     unsigned m_hasFilterInfo : 1;
684     unsigned m_needsToUpdateAncestorDependentProperties : 1;
685     unsigned m_childNeedsToUpdateAncestorDependantProperties : 1;
686
687     // Used only while determining what layers should be composited. Applies to the tree of z-order lists.
688     unsigned m_hasCompositingDescendant : 1;
689
690     // Applies to the real render layer tree (i.e., the tree determined by the layer's parent and children and
691     // as opposed to the tree formed by the z-order and normal flow lists).
692     unsigned m_hasNonCompositedChild : 1;
693
694     // Should be for stacking contexts having unisolated blending descendants.
695     unsigned m_shouldIsolateCompositedDescendants : 1;
696
697     // True if this render layer just lost its grouped mapping due to the CompositedLayerMapping being destroyed,
698     // and we don't yet know to what graphics layer this RenderLayer will be assigned.
699     unsigned m_lostGroupedMapping : 1;
700
701     // The reason, if any exists, that a fixed-position layer is chosen not to be composited.
702     unsigned m_viewportConstrainedNotCompositedReason : ViewportConstrainedNotCompositedReasonBits;
703
704     RenderLayerModelObject* m_renderer;
705
706     RenderLayer* m_parent;
707     RenderLayer* m_previous;
708     RenderLayer* m_next;
709     RenderLayer* m_first;
710     RenderLayer* m_last;
711
712     // Our current relative position offset.
713     LayoutSize m_offsetForInFlowPosition;
714
715     // Our (x,y) coordinates are in our parent layer's coordinate space.
716     LayoutPoint m_topLeft;
717
718     // The layer's width/height
719     IntSize m_layerSize;
720
721     // Cached normal flow values for absolute positioned elements with static left/top values.
722     LayoutUnit m_staticInlinePosition;
723     LayoutUnit m_staticBlockPosition;
724
725     OwnPtr<TransformationMatrix> m_transform;
726
727     // Pointer to the enclosing RenderLayer that caused us to be paginated. It is 0 if we are not paginated.
728     RenderLayer* m_enclosingPaginationLayer;
729
730     // These compositing reasons are updated whenever style changes, not while updating compositing layers.
731     // They should not be used to infer the compositing state of this layer.
732     CompositingReasons m_styleDeterminedCompositingReasons;
733
734     // Once computed, indicates all that a layer needs to become composited using the CompositingReasons enum bitfield.
735     CompositingReasons m_compositingReasons;
736
737     // Used for invalidating this layer's contents on the squashing GraphicsLayer.
738     IntSize m_offsetFromSquashingLayerOrigin;
739
740     AncestorDependentProperties m_ancestorDependentProperties;
741
742     IntRect m_blockSelectionGapsBounds;
743
744     OwnPtr<CompositedLayerMapping> m_compositedLayerMapping;
745     OwnPtr<RenderLayerScrollableArea> m_scrollableArea;
746
747     CompositedLayerMapping* m_groupedMapping;
748
749     RenderLayerRepainter m_repainter;
750     RenderLayerClipper m_clipper; // FIXME: Lazily allocate?
751     OwnPtr<RenderLayerStackingNode> m_stackingNode;
752     OwnPtr<RenderLayerReflectionInfo> m_reflectionInfo;
753     RenderLayerBlendInfo m_blendInfo;
754
755     LayoutSize m_subpixelAccumulation; // The accumulated subpixel offset of a composited layer's composited bounds compared to absolute coordinates.
756 };
757
758 } // namespace WebCore
759
760 #ifndef NDEBUG
761 // Outside the WebCore namespace for ease of invocation from gdb.
762 void showLayerTree(const WebCore::RenderLayer*);
763 void showLayerTree(const WebCore::RenderObject*);
764 #endif
765
766 #endif // RenderLayer_h