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