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