2 * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved.
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@web.de>
10 * Randall Jesup <rjesup@wgate.com>
11 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
12 * Josh Soref <timeless@mac.com>
13 * Boris Zbarsky <bzbarsky@mit.edu>
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 * Alternatively, the contents of this file may be used under the terms
30 * of either the Mozilla Public License Version 1.1, found at
31 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
32 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
33 * (the "GPL"), in which case the provisions of the MPL or the GPL are
34 * applicable instead of those above. If you wish to allow use of your
35 * version of this file only under the terms of one of those two
36 * licenses (the MPL or the GPL) and not to allow others to use your
37 * version of this file under the LGPL, indicate your decision by
38 * deletingthe provisions above and replace them with the notice and
39 * other provisions required by the MPL or the GPL, as the case may be.
40 * If you do not delete the provisions above, a recipient may use your
41 * version of this file under any of the LGPL, the MPL or the GPL.
47 #include "GraphicsLayer.h"
48 #include "PaintInfo.h"
49 #include "RenderBox.h"
50 #include "RenderPtr.h"
51 #include "ScrollableArea.h"
56 class FilterEffectRenderer;
57 class FilterEffectRendererHelper;
58 class FilterOperations;
61 class HitTestingTransformState;
62 class RenderFlowThread;
63 class RenderGeometryMap;
64 class RenderLayerBacking;
65 class RenderLayerCompositor;
67 class RenderNamedFlowFragment;
69 class RenderScrollbarPart;
73 class TransformationMatrix;
75 enum BorderRadiusClippingRule { IncludeSelfForBorderRadius, DoNotIncludeSelfForBorderRadius };
76 enum IncludeSelfOrNot { IncludeSelf, ExcludeSelf };
81 NeedsFullRepaintForPositionedMovementLayout
87 : m_affectedByRadius(false)
91 ClipRect(const LayoutRect& rect)
93 , m_affectedByRadius(false)
97 const LayoutRect& rect() const { return m_rect; }
98 void setRect(const LayoutRect& rect) { m_rect = rect; }
100 bool affectedByRadius() const { return m_affectedByRadius; }
101 void setAffectedByRadius(bool affectedByRadius) { m_affectedByRadius = affectedByRadius; }
103 bool operator==(const ClipRect& other) const { return rect() == other.rect() && affectedByRadius() == other.affectedByRadius(); }
104 bool operator!=(const ClipRect& other) const { return rect() != other.rect() || affectedByRadius() != other.affectedByRadius(); }
105 bool operator!=(const LayoutRect& otherRect) const { return rect() != otherRect; }
107 void intersect(const LayoutRect& other) { m_rect.intersect(other); }
108 void intersect(const ClipRect& other)
110 m_rect.intersect(other.rect());
111 if (other.affectedByRadius())
112 m_affectedByRadius = true;
114 void move(LayoutUnit x, LayoutUnit y) { m_rect.move(x, y); }
115 void move(const LayoutSize& size) { m_rect.move(size); }
116 void moveBy(const LayoutPoint& point) { m_rect.moveBy(point); }
118 bool isEmpty() const { return m_rect.isEmpty(); }
119 bool intersects(const LayoutRect& rect) const { return m_rect.intersects(rect); }
120 bool intersects(const HitTestLocation&) const;
122 void inflateX(LayoutUnit dx) { m_rect.inflateX(dx); }
123 void inflateY(LayoutUnit dy) { m_rect.inflateY(dy); }
124 void inflate(LayoutUnit d) { inflateX(d); inflateY(d); }
128 bool m_affectedByRadius;
131 inline ClipRect intersection(const ClipRect& a, const ClipRect& b)
139 WTF_MAKE_FAST_ALLOCATED;
141 static PassRefPtr<ClipRects> create()
143 return adoptRef(new ClipRects);
146 static PassRefPtr<ClipRects> create(const ClipRects& other)
148 return adoptRef(new ClipRects(other));
157 void reset(const LayoutRect& r)
159 m_overflowClipRect = r;
165 const ClipRect& overflowClipRect() const { return m_overflowClipRect; }
166 void setOverflowClipRect(const ClipRect& r) { m_overflowClipRect = r; }
168 const ClipRect& fixedClipRect() const { return m_fixedClipRect; }
169 void setFixedClipRect(const ClipRect&r) { m_fixedClipRect = r; }
171 const ClipRect& posClipRect() const { return m_posClipRect; }
172 void setPosClipRect(const ClipRect& r) { m_posClipRect = r; }
174 bool fixed() const { return m_fixed; }
175 void setFixed(bool fixed) { m_fixed = fixed; }
177 void ref() { m_refCnt++; }
184 bool operator==(const ClipRects& other) const
186 return m_overflowClipRect == other.overflowClipRect() &&
187 m_fixedClipRect == other.fixedClipRect() &&
188 m_posClipRect == other.posClipRect() &&
189 m_fixed == other.fixed();
192 ClipRects& operator=(const ClipRects& other)
194 m_overflowClipRect = other.overflowClipRect();
195 m_fixedClipRect = other.fixedClipRect();
196 m_posClipRect = other.posClipRect();
197 m_fixed = other.fixed();
202 ClipRects(const LayoutRect& r)
203 : m_overflowClipRect(r)
211 ClipRects(const ClipRects& other)
212 : m_overflowClipRect(other.overflowClipRect())
213 , m_fixedClipRect(other.fixedClipRect())
214 , m_posClipRect(other.posClipRect())
216 , m_fixed(other.fixed())
220 ClipRect m_overflowClipRect;
221 ClipRect m_fixedClipRect;
222 ClipRect m_posClipRect;
223 unsigned m_refCnt : 31;
228 PaintingClipRects, // Relative to painting ancestor. Used for painting.
229 RootRelativeClipRects, // Relative to the ancestor treated as the root (e.g. transformed layer). Used for hit testing.
230 AbsoluteClipRects, // Relative to the RenderView's layer. Used for compositing overlap testing.
231 NumCachedClipRectsTypes,
236 enum ShouldRespectOverflowClip {
241 enum ShouldApplyRootOffsetToFragments {
242 ApplyRootOffsetToFragments,
243 IgnoreRootOffsetForFragments
246 struct ClipRectsCache {
247 WTF_MAKE_FAST_ALLOCATED;
252 for (int i = 0; i < NumCachedClipRectsTypes; ++i) {
253 m_clipRectsRoot[i] = 0;
254 m_scrollbarRelevancy[i] = IgnoreOverlayScrollbarSize;
259 PassRefPtr<ClipRects> getClipRects(ClipRectsType clipRectsType, ShouldRespectOverflowClip respectOverflow) { return m_clipRects[getIndex(clipRectsType, respectOverflow)]; }
260 void setClipRects(ClipRectsType clipRectsType, ShouldRespectOverflowClip respectOverflow, PassRefPtr<ClipRects> clipRects) { m_clipRects[getIndex(clipRectsType, respectOverflow)] = clipRects; }
263 const RenderLayer* m_clipRectsRoot[NumCachedClipRectsTypes];
264 OverlayScrollbarSizeRelevancy m_scrollbarRelevancy[NumCachedClipRectsTypes];
268 int getIndex(ClipRectsType clipRectsType, ShouldRespectOverflowClip respectOverflow)
270 int index = static_cast<int>(clipRectsType);
271 if (respectOverflow == RespectOverflowClip)
272 index += static_cast<int>(NumCachedClipRectsTypes);
276 RefPtr<ClipRects> m_clipRects[NumCachedClipRectsTypes * 2];
279 struct LayerFragment {
282 : shouldPaintContent(false)
283 , hasBoundingBox(false)
286 void setRects(const LayoutRect& bounds, const ClipRect& background, const ClipRect& foreground, const ClipRect& outline, const LayoutRect* bbox)
288 layerBounds = bounds;
289 backgroundRect = background;
290 foregroundRect = foreground;
291 outlineRect = outline;
294 hasBoundingBox = true;
298 void moveBy(const LayoutPoint& offset)
300 layerBounds.moveBy(offset);
301 backgroundRect.moveBy(offset);
302 foregroundRect.moveBy(offset);
303 outlineRect.moveBy(offset);
304 paginationClip.moveBy(offset);
305 boundingBox.moveBy(offset);
308 void intersect(const LayoutRect& rect)
310 backgroundRect.intersect(rect);
311 foregroundRect.intersect(rect);
312 outlineRect.intersect(rect);
313 boundingBox.intersect(rect);
316 bool shouldPaintContent;
318 LayoutRect layerBounds;
319 ClipRect backgroundRect;
320 ClipRect foregroundRect;
321 ClipRect outlineRect;
322 LayoutRect boundingBox;
324 // Unique to paginated fragments. The physical translation to apply to shift the layer when painting/hit-testing.
325 LayoutSize paginationOffset;
327 // Also unique to paginated fragments. An additional clip that applies to the layer. It is in layer-local
328 // (physical) coordinates.
329 LayoutRect paginationClip;
332 typedef Vector<LayerFragment, 1> LayerFragments;
334 class RenderLayer final : public ScrollableArea {
335 WTF_MAKE_FAST_ALLOCATED;
337 friend class RenderReplica;
339 explicit RenderLayer(RenderLayerModelObject&);
340 virtual ~RenderLayer();
343 // Called before the renderer's widget (if any) has been nulled out.
344 void willBeDestroyed();
348 RenderLayerModelObject& renderer() const { return m_renderer; }
349 RenderBox* renderBox() const { return is<RenderBox>(renderer()) ? &downcast<RenderBox>(renderer()) : nullptr; }
350 RenderLayer* parent() const { return m_parent; }
351 RenderLayer* previousSibling() const { return m_previous; }
352 RenderLayer* nextSibling() const { return m_next; }
353 RenderLayer* firstChild() const { return m_first; }
354 RenderLayer* lastChild() const { return m_last; }
356 void addChild(RenderLayer* newChild, RenderLayer* beforeChild = nullptr);
357 RenderLayer* removeChild(RenderLayer*);
359 void removeOnlyThisLayer();
360 void insertOnlyThisLayer();
362 void repaintIncludingDescendants();
364 // Indicate that the layer contents need to be repainted. Only has an effect
365 // if layer compositing is being used.
366 void setBackingNeedsRepaint(GraphicsLayer::ShouldClipToLayer = GraphicsLayer::ClipToLayer);
368 // The rect is in the coordinate space of the layer's render object.
369 void setBackingNeedsRepaintInRect(const LayoutRect&, GraphicsLayer::ShouldClipToLayer = GraphicsLayer::ClipToLayer);
370 void repaintIncludingNonCompositingDescendants(RenderLayerModelObject* repaintContainer);
372 void styleChanged(StyleDifference, const RenderStyle* oldStyle);
374 RenderMarquee* marquee() const { return m_marquee.get(); }
376 bool isNormalFlowOnly() const { return m_isNormalFlowOnly; }
377 bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; }
379 bool cannotBlitToWindow() const;
381 bool isTransparent() const { return renderer().isTransparent() || renderer().hasMask(); }
383 bool hasReflection() const { return renderer().hasReflection(); }
384 bool isReflection() const { return renderer().isReplica(); }
385 RenderReplica* reflection() const { return m_reflection.get(); }
386 RenderLayer* reflectionLayer() const;
388 const RenderLayer* root() const
390 const RenderLayer* curr = this;
391 while (curr->parent())
392 curr = curr->parent();
396 const LayoutPoint& location() const { return m_topLeft; }
397 void setLocation(const LayoutPoint& p) { m_topLeft = p; }
399 const IntSize& size() const { return m_layerSize; }
400 void setSize(const IntSize& size) { m_layerSize = size; }
402 LayoutRect rect() const { return LayoutRect(location(), size()); }
404 int scrollWidth() const;
405 int scrollHeight() const;
407 void panScrollFromPoint(const IntPoint&);
409 enum ScrollOffsetClamping {
410 ScrollOffsetUnclamped,
414 // Scrolling methods for layers that can scroll their overflow.
415 void scrollByRecursively(const IntSize&, ScrollOffsetClamping = ScrollOffsetUnclamped, ScrollableArea** scrolledArea = nullptr);
416 void scrollToOffset(const IntSize&, ScrollOffsetClamping = ScrollOffsetUnclamped);
417 void scrollToXOffset(int x, ScrollOffsetClamping clamp = ScrollOffsetUnclamped) { scrollToOffset(IntSize(x, scrollYOffset()), clamp); }
418 void scrollToYOffset(int y, ScrollOffsetClamping clamp = ScrollOffsetUnclamped) { scrollToOffset(IntSize(scrollXOffset(), y), clamp); }
420 int scrollXOffset() const { return m_scrollOffset.width() + scrollOrigin().x(); }
421 int scrollYOffset() const { return m_scrollOffset.height() + scrollOrigin().y(); }
422 IntSize scrollOffset() const { return IntSize(scrollXOffset(), scrollYOffset()); }
423 IntSize scrollableContentsSize() const;
425 void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
427 LayoutRect getRectToExpose(const LayoutRect& visibleRect, const LayoutRect& visibleRectRelativeToDocument, const LayoutRect& exposeRect, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
429 bool scrollsOverflow() const;
430 bool hasScrollbars() const { return m_hBar || m_vBar; }
431 void setHasHorizontalScrollbar(bool);
432 void setHasVerticalScrollbar(bool);
434 PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
435 void destroyScrollbar(ScrollbarOrientation);
437 bool hasHorizontalScrollbar() const { return horizontalScrollbar(); }
438 bool hasVerticalScrollbar() const { return verticalScrollbar(); }
440 // ScrollableArea overrides
441 virtual Scrollbar* horizontalScrollbar() const override { return m_hBar.get(); }
442 virtual Scrollbar* verticalScrollbar() const override { return m_vBar.get(); }
443 virtual ScrollableArea* enclosingScrollableArea() const override;
444 virtual bool isScrollableOrRubberbandable() override;
445 virtual bool hasScrollableOrRubberbandableAncestor() override;
446 #if ENABLE(CSS_SCROLL_SNAP)
447 virtual void updateSnapOffsets() override;
451 #if ENABLE(TOUCH_EVENTS)
452 virtual bool handleTouchEvent(const PlatformTouchEvent&) override;
453 virtual bool isTouchScrollable() const override { return true; }
455 virtual bool isOverflowScroll() const override { return true; }
457 virtual void didStartScroll() override;
458 virtual void didEndScroll() override;
459 virtual void didUpdateScroll() override;
460 virtual void setIsUserScroll(bool isUserScroll) override { m_inUserScroll = isUserScroll; }
462 bool isInUserScroll() const { return m_inUserScroll; }
464 bool requiresScrollBoundsOriginUpdate() const { return m_requiresScrollBoundsOriginUpdate; }
465 void setRequiresScrollBoundsOriginUpdate(bool requiresUpdate = true) { m_requiresScrollBoundsOriginUpdate = requiresUpdate; }
467 // Returns true when the layer could do touch scrolling, but doesn't look at whether there is actually scrollable overflow.
468 bool hasAcceleratedTouchScrolling() const;
469 // Returns true when there is actually scrollable overflow (requires layout to be up-to-date).
470 bool hasTouchScrollableOverflow() const;
473 int verticalScrollbarWidth(OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
474 int horizontalScrollbarHeight(OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
476 bool hasOverflowControls() const;
477 bool isPointInResizeControl(const IntPoint& absolutePoint) const;
478 bool hitTestOverflowControls(HitTestResult&, const IntPoint& localPoint);
479 IntSize offsetFromResizeCorner(const IntPoint& absolutePoint) const;
481 void paintOverflowControls(GraphicsContext*, const IntPoint&, const IntRect& damageRect, bool paintingOverlayControls = false);
482 void paintScrollCorner(GraphicsContext*, const IntPoint&, const IntRect& damageRect);
483 void paintResizer(GraphicsContext*, const LayoutPoint&, const LayoutRect& damageRect);
485 void updateScrollInfoAfterLayout();
487 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1);
488 void autoscroll(const IntPoint&);
490 bool canResize() const;
491 void resize(const PlatformMouseEvent&, const LayoutSize&);
492 bool inResizeMode() const { return m_inResizeMode; }
493 void setInResizeMode(bool b) { m_inResizeMode = b; }
495 bool isRootLayer() const { return m_isRootLayer; }
497 RenderLayerCompositor& compositor() const;
499 // Notification from the renderer that its content changed (e.g. current frame of image changed).
500 // Allows updates of layer content without repainting.
501 void contentChanged(ContentChangeType);
503 bool canRender3DTransforms() const;
505 enum UpdateLayerPositionsFlag {
506 CheckForRepaint = 1 << 0,
507 NeedsFullRepaintInBacking = 1 << 1,
508 IsCompositingUpdateRoot = 1 << 2,
509 UpdateCompositingLayers = 1 << 3,
510 UpdatePagination = 1 << 4,
511 SeenTransformedLayer = 1 << 5,
512 Seen3DTransformedLayer = 1 << 6
514 typedef unsigned UpdateLayerPositionsFlags;
515 static const UpdateLayerPositionsFlags defaultFlags = CheckForRepaint | IsCompositingUpdateRoot | UpdateCompositingLayers;
517 void updateLayerPositionsAfterLayout(const RenderLayer* rootLayer, UpdateLayerPositionsFlags);
519 void updateLayerPositionsAfterOverflowScroll();
520 void updateLayerPositionsAfterDocumentScroll();
522 void positionNewlyCreatedOverflowControls();
524 bool hasCompositedLayerInEnclosingPaginationChain() const;
525 enum PaginationInclusionMode { ExcludeCompositedPaginatedLayers, IncludeCompositedPaginatedLayers };
526 RenderLayer* enclosingPaginationLayer(PaginationInclusionMode mode) const
528 if (mode == ExcludeCompositedPaginatedLayers && hasCompositedLayerInEnclosingPaginationChain())
530 return m_enclosingPaginationLayer;
533 void updateTransform();
535 #if ENABLE(CSS_COMPOSITING)
536 void updateBlendMode();
539 const LayoutSize& offsetForInFlowPosition() const { return m_offsetForInFlowPosition; }
541 void clearClipRectsIncludingDescendants(ClipRectsType typeToClear = AllClipRectTypes);
542 void clearClipRects(ClipRectsType typeToClear = AllClipRectTypes);
544 void addBlockSelectionGapsBounds(const LayoutRect&);
545 void clearBlockSelectionGapsBounds();
546 void repaintBlockSelectionGaps();
548 // A stacking context is a layer that has a non-auto z-index.
549 bool isStackingContext() const { return isStackingContext(&renderer().style()); }
551 // A stacking container can have z-order lists. All stacking contexts are
552 // stacking containers, but the converse is not true. Layers that use
553 // composited scrolling are stacking containers, but they may not
554 // necessarily be stacking contexts.
555 bool isStackingContainer() const { return isStackingContext() || needsCompositedScrolling(); }
557 // Gets the enclosing stacking container for this layer, excluding this
559 RenderLayer* stackingContainer() const;
561 // Gets the enclosing stacking container for this layer, possibly the layer
562 // itself, if it is a stacking container.
563 RenderLayer* enclosingStackingContainer() { return isStackingContainer() ? this : stackingContainer(); }
565 void dirtyZOrderLists();
566 void dirtyStackingContainerZOrderLists();
568 Vector<RenderLayer*>* posZOrderList() const
570 ASSERT(!m_zOrderListsDirty);
571 ASSERT(isStackingContainer() || !m_posZOrderList);
572 return m_posZOrderList.get();
575 bool hasNegativeZOrderList() const { return negZOrderList() && negZOrderList()->size(); }
577 Vector<RenderLayer*>* negZOrderList() const
579 ASSERT(!m_zOrderListsDirty);
580 ASSERT(isStackingContainer() || !m_negZOrderList);
581 return m_negZOrderList.get();
584 void dirtyNormalFlowList();
585 Vector<RenderLayer*>* normalFlowList() const { ASSERT(!m_normalFlowListDirty); return m_normalFlowList.get(); }
587 // Update our normal and z-index lists.
588 void updateLayerListsIfNeeded();
590 // Update the normal and z-index lists of our descendants.
591 void updateDescendantsLayerListsIfNeeded(bool recursive);
593 // FIXME: We should ASSERT(!m_visibleContentStatusDirty) here, but see https://bugs.webkit.org/show_bug.cgi?id=71044
594 // ditto for hasVisibleDescendant(), see https://bugs.webkit.org/show_bug.cgi?id=71277
595 bool hasVisibleContent() const { return m_hasVisibleContent; }
596 bool hasVisibleDescendant() const { return m_hasVisibleDescendant; }
598 void setHasVisibleContent();
599 void dirtyVisibleContentStatus();
601 bool hasBoxDecorationsOrBackground() const;
602 bool hasVisibleBoxDecorations() const;
603 // Returns true if this layer has visible content (ignoring any child layers).
604 bool isVisuallyNonEmpty() const;
605 // True if this layer container renderers that paint.
606 bool hasNonEmptyChildRenderers() const;
608 // FIXME: We should ASSERT(!m_hasSelfPaintingLayerDescendantDirty); here but we hit the same bugs as visible content above.
609 // Part of the issue is with subtree relayout: we don't check if our ancestors have some descendant flags dirty, missing some updates.
610 bool hasSelfPaintingLayerDescendant() const { return m_hasSelfPaintingLayerDescendant; }
612 // This returns true if we have an out of flow positioned descendant whose
613 // containing block is not a descendant of ours. If this is true, we cannot
614 // automatically opt into composited scrolling since this out of flow
615 // positioned descendant would become clipped by us, possibly altering the
616 // rendering of the page.
617 // FIXME: We should ASSERT(!m_hasOutOfFlowPositionedDescendantDirty); here but we may hit the same bugs as visible content above.
618 bool hasOutOfFlowPositionedDescendant() const { return m_hasOutOfFlowPositionedDescendant; }
620 // Gets the nearest enclosing positioned ancestor layer (also includes
621 // the <html> layer and the root layer).
622 RenderLayer* enclosingPositionedAncestor() const;
624 // Returns the nearest enclosing layer that is scrollable.
625 RenderLayer* enclosingScrollableLayer() const;
627 // The layer relative to which clipping rects for this layer are computed.
628 RenderLayer* clippingRootForPainting() const;
630 RenderLayer* enclosingOverflowClipLayer(IncludeSelfOrNot) const;
632 // Enclosing compositing layer; if includeSelf is true, may return this.
633 RenderLayer* enclosingCompositingLayer(IncludeSelfOrNot = IncludeSelf) const;
634 RenderLayer* enclosingCompositingLayerForRepaint(IncludeSelfOrNot = IncludeSelf) const;
635 // Ancestor compositing layer, excluding this.
636 RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(ExcludeSelf); }
638 RenderLayer* enclosingFilterLayer(IncludeSelfOrNot = IncludeSelf) const;
639 RenderLayer* enclosingFilterRepaintLayer() const;
640 void setFilterBackendNeedsRepaintingInRect(const LayoutRect&);
641 bool hasAncestorWithFilterOutsets() const;
643 bool canUseConvertToLayerCoords() const
645 // These RenderObject have an impact on their layers' without them knowing about it.
646 return !renderer().hasTransform() && !renderer().isSVGRoot();
649 // FIXME: adjustForColumns allows us to position compositing layers in columns correctly, but eventually they need to be split across columns too.
650 enum ColumnOffsetAdjustment { DontAdjustForColumns, AdjustForColumns };
651 void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntPoint& location, ColumnOffsetAdjustment adjustForColumns = DontAdjustForColumns) const;
652 LayoutPoint convertToLayerCoords(const RenderLayer* ancestorLayer, const LayoutPoint&, ColumnOffsetAdjustment adjustForColumns = DontAdjustForColumns) const;
653 LayoutSize offsetFromAncestor(const RenderLayer*) const;
655 int zIndex() const { return renderer().style().zIndex(); }
657 enum PaintLayerFlag {
658 PaintLayerHaveTransparency = 1,
659 PaintLayerAppliedTransform = 1 << 1,
660 PaintLayerTemporaryClipRects = 1 << 2,
661 PaintLayerPaintingReflection = 1 << 3,
662 PaintLayerPaintingOverlayScrollbars = 1 << 4,
663 PaintLayerPaintingCompositingBackgroundPhase = 1 << 5,
664 PaintLayerPaintingCompositingForegroundPhase = 1 << 6,
665 PaintLayerPaintingCompositingMaskPhase = 1 << 7,
666 PaintLayerPaintingCompositingScrollingPhase = 1 << 8,
667 PaintLayerPaintingOverflowContents = 1 << 9,
668 PaintLayerPaintingRootBackgroundOnly = 1 << 10,
669 PaintLayerPaintingSkipRootBackground = 1 << 11,
670 PaintLayerPaintingCompositingAllPhases = (PaintLayerPaintingCompositingBackgroundPhase | PaintLayerPaintingCompositingForegroundPhase | PaintLayerPaintingCompositingMaskPhase)
673 typedef unsigned PaintLayerFlags;
675 // The two main functions that use the layer system. The paint method
676 // paints the layers that intersect the damage rect from back to
677 // front. The hitTest method looks for mouse events by walking
678 // layers that intersect the point from front to back.
679 void paint(GraphicsContext*, const LayoutRect& damageRect, const LayoutSize& subpixelAccumulation = LayoutSize(), PaintBehavior = PaintBehaviorNormal,
680 RenderObject* subtreePaintRoot = nullptr, PaintLayerFlags = 0);
681 bool hitTest(const HitTestRequest&, HitTestResult&);
682 bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&);
683 void paintOverlayScrollbars(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior, RenderObject* subtreePaintRoot = nullptr);
685 void paintNamedFlowThreadInsideRegion(GraphicsContext*, RenderNamedFlowFragment*, LayoutRect, LayoutPoint, PaintBehavior = PaintBehaviorNormal, PaintLayerFlags = 0);
687 struct ClipRectsContext {
688 ClipRectsContext(const RenderLayer* inRootLayer, ClipRectsType inClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, ShouldRespectOverflowClip inRespectOverflowClip = RespectOverflowClip)
689 : rootLayer(inRootLayer)
690 , clipRectsType(inClipRectsType)
691 , overlayScrollbarSizeRelevancy(inOverlayScrollbarSizeRelevancy)
692 , respectOverflowClip(inRespectOverflowClip)
694 const RenderLayer* rootLayer;
695 ClipRectsType clipRectsType;
696 OverlayScrollbarSizeRelevancy overlayScrollbarSizeRelevancy;
697 ShouldRespectOverflowClip respectOverflowClip;
700 // This method figures out our layerBounds in coordinates relative to
701 // |rootLayer}. It also computes our background and foreground clip rects
702 // for painting/event handling.
703 // Pass offsetFromRoot if known.
704 void calculateRects(const ClipRectsContext&, const LayoutRect& paintDirtyRect, LayoutRect& layerBounds,
705 ClipRect& backgroundRect, ClipRect& foregroundRect, ClipRect& outlineRect, const LayoutSize& offsetFromRoot) const;
707 // Compute and cache clip rects computed with the given layer as the root
708 void updateClipRects(const ClipRectsContext&);
709 // Compute and return the clip rects. If useCached is true, will used previously computed clip rects on ancestors
710 // (rather than computing them all from scratch up the parent chain).
711 void calculateClipRects(const ClipRectsContext&, ClipRects&) const;
713 ClipRects* clipRects(const ClipRectsContext& context) const
715 ASSERT(context.clipRectsType < NumCachedClipRectsTypes);
716 return m_clipRectsCache ? m_clipRectsCache->getClipRects(context.clipRectsType, context.respectOverflowClip).get() : 0;
719 LayoutRect childrenClipRect() const; // Returns the foreground clip rect of the layer in the document's coordinate space.
720 LayoutRect selfClipRect() const; // Returns the background clip rect of the layer in the document's coordinate space.
721 LayoutRect localClipRect(bool& clipExceedsBounds) const; // Returns the background clip rect of the layer in the local coordinate space.
723 // Pass offsetFromRoot if known.
724 bool intersectsDamageRect(const LayoutRect& layerBounds, const LayoutRect& damageRect, const RenderLayer* rootLayer, const LayoutSize& offsetFromRoot, const LayoutRect* cachedBoundingBox = nullptr) const;
726 enum CalculateLayerBoundsFlag {
727 IncludeSelfTransform = 1 << 0,
728 UseLocalClipRectIfPossible = 1 << 1,
729 IncludeLayerFilterOutsets = 1 << 2,
730 ExcludeHiddenDescendants = 1 << 3,
731 DontConstrainForMask = 1 << 4,
732 IncludeCompositedDescendants = 1 << 5,
733 UseFragmentBoxesExcludingCompositing = 1 << 6,
734 UseFragmentBoxesIncludingCompositing = 1 << 7,
735 DefaultCalculateLayerBoundsFlags = IncludeSelfTransform | UseLocalClipRectIfPossible | IncludeLayerFilterOutsets | UseFragmentBoxesExcludingCompositing
737 typedef unsigned CalculateLayerBoundsFlags;
739 // Bounding box relative to some ancestor layer. Pass offsetFromRoot if known.
740 LayoutRect boundingBox(const RenderLayer* rootLayer, const LayoutSize& offsetFromRoot = LayoutSize(), CalculateLayerBoundsFlags = 0) const;
741 // Bounding box in the coordinates of this layer.
742 LayoutRect localBoundingBox(CalculateLayerBoundsFlags = 0) const;
743 // Deprecated: Pixel snapped bounding box relative to the root.
744 WEBCORE_EXPORT IntRect absoluteBoundingBox() const;
745 // Device pixel snapped bounding box relative to the root. absoluteBoundingBox() callers will be directed to this.
746 FloatRect absoluteBoundingBoxForPainting() const;
748 // Bounds used for layer overlap testing in RenderLayerCompositor.
749 LayoutRect overlapBounds() const { return overlapBoundsIncludeChildren() ? calculateLayerBounds(this, LayoutSize()) : localBoundingBox(); }
751 // If true, this layer's children are included in its bounds for overlap testing.
752 // We can't rely on the children's positions if this layer has a filter that could have moved the children's pixels around.
753 bool overlapBoundsIncludeChildren() const { return hasFilter() && renderer().style().filter().hasFilterThatMovesPixels(); }
755 // Can pass offsetFromRoot if known.
756 LayoutRect calculateLayerBounds(const RenderLayer* ancestorLayer, const LayoutSize& offsetFromRoot, CalculateLayerBoundsFlags = DefaultCalculateLayerBoundsFlags) const;
758 // Return a cached repaint rect, computed relative to the layer renderer's containerForRepaint.
759 LayoutRect repaintRect() const { return m_repaintRect; }
760 LayoutRect repaintRectIncludingNonCompositingDescendants() const;
762 void setRepaintStatus(RepaintStatus status) { m_repaintStatus = status; }
764 LayoutUnit staticInlinePosition() const { return m_staticInlinePosition; }
765 LayoutUnit staticBlockPosition() const { return m_staticBlockPosition; }
767 void setStaticInlinePosition(LayoutUnit position) { m_staticInlinePosition = position; }
768 void setStaticBlockPosition(LayoutUnit position) { m_staticBlockPosition = position; }
771 bool adjustForIOSCaretWhenScrolling() const { return m_adjustForIOSCaretWhenScrolling; }
772 void setAdjustForIOSCaretWhenScrolling(bool adjustForIOSCaretWhenScrolling) { m_adjustForIOSCaretWhenScrolling = adjustForIOSCaretWhenScrolling; }
775 bool hasTransform() const { return renderer().hasTransform(); }
776 // Note that this transform has the transform-origin baked in.
777 TransformationMatrix* transform() const { return m_transform.get(); }
778 // currentTransform computes a transform which takes accelerated animations into account. The
779 // resulting transform has transform-origin baked in. If the layer does not have a transform,
780 // returns the identity matrix.
781 TransformationMatrix currentTransform(RenderStyle::ApplyTransformOrigin = RenderStyle::IncludeTransformOrigin) const;
782 TransformationMatrix renderableTransform(PaintBehavior) const;
784 // Get the perspective transform, which is applied to transformed sublayers.
785 // Returns true if the layer has a -webkit-perspective.
786 // Note that this transform has the perspective-origin baked in.
787 TransformationMatrix perspectiveTransform() const;
788 FloatPoint perspectiveOrigin() const;
789 bool preserves3D() const { return renderer().style().transformStyle3D() == TransformStyle3DPreserve3D; }
790 bool has3DTransform() const { return m_transform && !m_transform->isAffine(); }
792 virtual void filterNeedsRepaint();
793 bool hasFilter() const { return renderer().hasFilter(); }
795 #if ENABLE(CSS_COMPOSITING)
796 bool hasBlendMode() const { return renderer().hasBlendMode(); }
797 BlendMode blendMode() const { return static_cast<BlendMode>(m_blendMode); }
799 bool isolatesCompositedBlending() const { return m_hasNotIsolatedCompositedBlendingDescendants && isStackingContext(); }
800 bool hasNotIsolatedCompositedBlendingDescendants() const { return m_hasNotIsolatedCompositedBlendingDescendants; }
801 void setHasNotIsolatedCompositedBlendingDescendants(bool hasNotIsolatedCompositedBlendingDescendants)
803 m_hasNotIsolatedCompositedBlendingDescendants = hasNotIsolatedCompositedBlendingDescendants;
806 bool isolatesBlending() const { return hasNotIsolatedBlendingDescendants() && isStackingContext(); }
808 // FIXME: We should ASSERT(!m_hasNotIsolatedBlendingDescendantsStatusDirty); here but we hit the same bugs as visible content above.
809 bool hasNotIsolatedBlendingDescendants() const { return m_hasNotIsolatedBlendingDescendants; }
810 bool hasNotIsolatedBlendingDescendantsStatusDirty() const { return m_hasNotIsolatedBlendingDescendantsStatusDirty; }
812 bool hasBlendMode() const { return false; }
813 bool isolatesCompositedBlending() const { return false; }
814 bool isolatesBlending() const { return false; }
815 bool hasNotIsolatedBlendingDescendantsStatusDirty() const { return false; }
818 bool isComposited() const { return m_backing != 0; }
819 bool hasCompositingDescendant() const { return m_hasCompositingDescendant; }
820 bool hasCompositedMask() const;
821 RenderLayerBacking* backing() const { return m_backing.get(); }
822 RenderLayerBacking* ensureBacking();
823 void clearBacking(bool layerBeingDestroyed = false);
824 virtual GraphicsLayer* layerForScrolling() const override;
825 virtual GraphicsLayer* layerForHorizontalScrollbar() const override;
826 virtual GraphicsLayer* layerForVerticalScrollbar() const override;
827 virtual GraphicsLayer* layerForScrollCorner() const override;
828 virtual bool usesCompositedScrolling() const override;
829 WEBCORE_EXPORT bool needsCompositedScrolling() const;
831 bool paintsWithTransparency(PaintBehavior paintBehavior) const
833 return (isTransparent() || hasBlendMode() || (isolatesBlending() && !renderer().isRoot())) && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || !isComposited());
836 bool paintsWithTransform(PaintBehavior) const;
838 // Returns true if background phase is painted opaque in the given rect.
839 // The query rect is given in local coordinates.
840 bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
842 bool containsDirtyOverlayScrollbars() const { return m_containsDirtyOverlayScrollbars; }
843 void setContainsDirtyOverlayScrollbars(bool dirtyScrollbars) { m_containsDirtyOverlayScrollbars = dirtyScrollbars; }
845 bool paintsWithFilters() const;
846 bool requiresFullLayerImageForFilters() const;
847 FilterEffectRenderer* filterRenderer() const;
850 bool layerListMutationAllowed() const { return m_layerListMutationAllowed; }
851 void setLayerListMutationAllowed(bool flag) { m_layerListMutationAllowed = flag; }
854 Element* enclosingElement() const;
856 enum ViewportConstrainedNotCompositedReason {
857 NoNotCompositedReason,
858 NotCompositedForBoundsOutOfView,
859 NotCompositedForNonViewContainer,
860 NotCompositedForNoVisibleContent,
863 void setViewportConstrainedNotCompositedReason(ViewportConstrainedNotCompositedReason reason) { m_viewportConstrainedNotCompositedReason = reason; }
864 ViewportConstrainedNotCompositedReason viewportConstrainedNotCompositedReason() const { return static_cast<ViewportConstrainedNotCompositedReason>(m_viewportConstrainedNotCompositedReason); }
866 bool isRenderFlowThread() const { return renderer().isRenderFlowThread(); }
867 bool isOutOfFlowRenderFlowThread() const { return renderer().isOutOfFlowRenderFlowThread(); }
868 bool isInsideFlowThread() const { return renderer().flowThreadState() != RenderObject::NotInsideFlowThread; }
869 bool isInsideOutOfFlowThread() const { return renderer().flowThreadState() == RenderObject::InsideOutOfFlowThread; }
870 bool isDirtyRenderFlowThread() const
872 ASSERT(isRenderFlowThread());
873 return m_zOrderListsDirty || m_normalFlowListDirty;
876 bool isFlowThreadCollectingGraphicsLayersUnderRegions() const;
878 RenderLayer* enclosingFlowThreadAncestor() const;
881 enum CollectLayersBehavior { StopAtStackingContexts, StopAtStackingContainers };
883 struct LayerPaintingInfo {
884 LayerPaintingInfo(RenderLayer* inRootLayer, const LayoutRect& inDirtyRect, PaintBehavior inPaintBehavior, const LayoutSize& inSubpixelAccumulation, RenderObject* inSubtreePaintRoot = nullptr, OverlapTestRequestMap* inOverlapTestRequests = nullptr)
885 : rootLayer(inRootLayer)
886 , subtreePaintRoot(inSubtreePaintRoot)
887 , paintDirtyRect(inDirtyRect)
888 , subpixelAccumulation(inSubpixelAccumulation)
889 , overlapTestRequests(inOverlapTestRequests)
890 , paintBehavior(inPaintBehavior)
891 , clipToDirtyRect(true)
893 RenderLayer* rootLayer;
894 RenderObject* subtreePaintRoot; // only paint descendants of this object
895 LayoutRect paintDirtyRect; // relative to rootLayer;
896 LayoutSize subpixelAccumulation;
897 OverlapTestRequestMap* overlapTestRequests; // May be null.
898 PaintBehavior paintBehavior;
899 bool clipToDirtyRect;
902 void updateZOrderLists();
903 void rebuildZOrderLists();
904 void rebuildZOrderLists(CollectLayersBehavior, std::unique_ptr<Vector<RenderLayer*>>&, std::unique_ptr<Vector<RenderLayer*>>&);
905 void clearZOrderLists();
907 void updateNormalFlowList();
909 // Non-auto z-index always implies stacking context here, because StyleResolver::adjustRenderStyle already adjusts z-index
910 // based on positioning and other criteria.
911 bool isStackingContext(const RenderStyle* style) const { return !style->hasAutoZIndex() || isRootLayer(); }
913 bool isDirtyStackingContainer() const { return m_zOrderListsDirty && isStackingContainer(); }
915 void setAncestorChainHasSelfPaintingLayerDescendant();
916 void dirtyAncestorChainHasSelfPaintingLayerDescendantStatus();
918 bool acceleratedCompositingForOverflowScrollEnabled() const;
919 void updateDescendantsAreContiguousInStackingOrder();
920 void updateDescendantsAreContiguousInStackingOrderRecursive(const HashMap<const RenderLayer*, int>&, int& minIndex, int& maxIndex, int& count, bool firstIteration);
922 void computeRepaintRects(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap* = nullptr);
923 void computeRepaintRectsIncludingDescendants();
924 void clearRepaintRects();
926 void clipToRect(const LayerPaintingInfo&, GraphicsContext*, const ClipRect&, BorderRadiusClippingRule = IncludeSelfForBorderRadius);
927 void restoreClip(GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&);
929 bool shouldRepaintAfterLayout() const;
931 void updateSelfPaintingLayer();
932 void updateStackingContextsAfterStyleChange(const RenderStyle* oldStyle);
934 void updateScrollbarsAfterStyleChange(const RenderStyle* oldStyle);
935 void updateScrollbarsAfterLayout();
937 void setAncestorChainHasOutOfFlowPositionedDescendant(RenderBlock* containingBlock);
938 void dirtyAncestorChainHasOutOfFlowPositionedDescendantStatus();
939 void updateOutOfFlowPositioned(const RenderStyle* oldStyle);
941 void updateNeedsCompositedScrolling();
943 // Returns true if the position changed.
944 bool updateLayerPosition();
946 void updateLayerPositions(RenderGeometryMap* = nullptr, UpdateLayerPositionsFlags = defaultFlags);
948 enum UpdateLayerPositionsAfterScrollFlag {
950 IsOverflowScroll = 1 << 0,
951 HasSeenViewportConstrainedAncestor = 1 << 1,
952 HasSeenAncestorWithOverflowClip = 1 << 2,
953 HasChangedAncestor = 1 << 3
955 typedef unsigned UpdateLayerPositionsAfterScrollFlags;
956 void updateLayerPositionsAfterScroll(RenderGeometryMap*, UpdateLayerPositionsAfterScrollFlags = NoFlag);
958 friend IntSize RenderBox::scrolledContentOffset() const;
959 IntSize scrolledContentOffset() const { return m_scrollOffset; }
961 IntSize clampScrollOffset(const IntSize&) const;
963 RenderLayer* enclosingPaginationLayerInSubtree(const RenderLayer* rootLayer, PaginationInclusionMode) const;
965 void setNextSibling(RenderLayer* next) { m_next = next; }
966 void setPreviousSibling(RenderLayer* prev) { m_previous = prev; }
967 void setParent(RenderLayer* parent);
968 void setFirstChild(RenderLayer* first) { m_first = first; }
969 void setLastChild(RenderLayer* last) { m_last = last; }
971 LayoutPoint renderBoxLocation() const { return is<RenderBox>(renderer()) ? downcast<RenderBox>(renderer()).location() : LayoutPoint(); }
973 void collectLayers(bool includeHiddenLayers, CollectLayersBehavior, std::unique_ptr<Vector<RenderLayer*>>&, std::unique_ptr<Vector<RenderLayer*>>&);
975 void updateCompositingAndLayerListsIfNeeded();
977 bool setupFontSubpixelQuantization(GraphicsContext*, bool& didQuantizeFonts);
978 bool setupClipPath(GraphicsContext*, const LayerPaintingInfo&, const LayoutSize& offsetFromRoot, LayoutRect& rootRelativeBounds, bool& rootRelativeBoundsComputed);
980 std::unique_ptr<FilterEffectRendererHelper> setupFilters(GraphicsContext*, LayerPaintingInfo&, PaintLayerFlags, const LayoutSize& offsetFromRoot, LayoutRect& rootRelativeBounds, bool& rootRelativeBoundsComputed);
981 GraphicsContext* applyFilters(FilterEffectRendererHelper*, GraphicsContext* originalContext, LayerPaintingInfo&, LayerFragments&);
983 void paintLayer(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
984 void paintFixedLayersInNamedFlows(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
985 void paintLayerContentsAndReflection(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
986 void paintLayerByApplyingTransform(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const LayoutSize& translationOffset = LayoutSize());
987 void paintLayerContents(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
988 void paintList(Vector<RenderLayer*>*, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
990 void collectFragments(LayerFragments&, const RenderLayer* rootLayer, const LayoutRect& dirtyRect,
991 PaginationInclusionMode,
992 ClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy, ShouldRespectOverflowClip, const LayoutSize& offsetFromRoot,
993 const LayoutRect* layerBoundingBox = nullptr, ShouldApplyRootOffsetToFragments = IgnoreRootOffsetForFragments);
994 void updatePaintingInfoForFragments(LayerFragments&, const LayerPaintingInfo&, PaintLayerFlags, bool shouldPaintContent, const LayoutSize& offsetFromRoot);
995 void paintBackgroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
996 const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
997 void paintForegroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
998 const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer,
1000 void paintForegroundForFragmentsWithPhase(PaintPhase, const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
1001 void paintOutlineForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
1002 void paintOverflowControlsForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&);
1003 void paintMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
1004 void paintTransformedLayerIntoFragments(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
1006 RenderLayer* transparentPaintingAncestor();
1007 void beginTransparencyLayers(GraphicsContext*, const LayerPaintingInfo&, const LayoutRect& dirtyRect);
1009 RenderLayer* hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest& request, HitTestResult& result,
1010 const LayoutRect& hitTestRect, const HitTestLocation&, bool appliedTransform,
1011 const HitTestingTransformState* = nullptr, double* zOffset = nullptr);
1012 RenderLayer* hitTestLayerByApplyingTransform(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
1013 const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = nullptr, double* zOffset = nullptr,
1014 const LayoutSize& translationOffset = LayoutSize());
1015 RenderLayer* hitTestList(Vector<RenderLayer*>*, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
1016 const LayoutRect& hitTestRect, const HitTestLocation&,
1017 const HitTestingTransformState*, double* zOffsetForDescendants, double* zOffset,
1018 const HitTestingTransformState* unflattenedTransformState, bool depthSortDescendants);
1020 RenderLayer* hitTestFixedLayersInNamedFlows(RenderLayer* rootLayer,
1021 const HitTestRequest&, HitTestResult&,
1022 const LayoutRect& hitTestRect, const HitTestLocation&,
1023 const HitTestingTransformState*,
1024 double* zOffsetForDescendants, double* zOffset,
1025 const HitTestingTransformState* unflattenedTransformState,
1026 bool depthSortDescendants);
1028 PassRefPtr<HitTestingTransformState> createLocalTransformState(RenderLayer* rootLayer, RenderLayer* containerLayer,
1029 const LayoutRect& hitTestRect, const HitTestLocation&,
1030 const HitTestingTransformState* containerTransformState,
1031 const LayoutSize& translationOffset = LayoutSize()) const;
1033 bool hitTestContents(const HitTestRequest&, HitTestResult&, const LayoutRect& layerBounds, const HitTestLocation&, HitTestFilter) const;
1034 bool hitTestContentsForFragments(const LayerFragments&, const HitTestRequest&, HitTestResult&, const HitTestLocation&, HitTestFilter, bool& insideClipRect) const;
1035 bool hitTestResizerInFragments(const LayerFragments&, const HitTestLocation&) const;
1036 RenderLayer* hitTestTransformedLayerInFragments(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
1037 const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = nullptr, double* zOffset = nullptr);
1039 bool listBackgroundIsKnownToBeOpaqueInRect(const Vector<RenderLayer*>*, const LayoutRect&) const;
1041 void computeScrollDimensions();
1042 bool hasHorizontalOverflow() const;
1043 bool hasVerticalOverflow() const;
1044 bool hasScrollableHorizontalOverflow() const;
1045 bool hasScrollableVerticalOverflow() const;
1047 bool showsOverflowControls() const;
1049 bool shouldBeNormalFlowOnly() const;
1051 bool shouldBeSelfPaintingLayer() const;
1053 virtual int scrollPosition(Scrollbar*) const override;
1055 // ScrollableArea interface
1056 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) override;
1057 virtual void invalidateScrollCornerRect(const IntRect&) override;
1058 virtual bool isActive() const override;
1059 virtual bool isScrollCornerVisible() const override;
1060 virtual IntRect scrollCornerRect() const override;
1061 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const override;
1062 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const override;
1063 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const override;
1064 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const override;
1065 virtual int scrollSize(ScrollbarOrientation) const override;
1066 virtual void setScrollOffset(const IntPoint&) override;
1067 virtual IntPoint scrollPosition() const override;
1068 virtual IntPoint minimumScrollPosition() const override;
1069 virtual IntPoint maximumScrollPosition() const override;
1070 virtual IntRect visibleContentRectInternal(VisibleContentRectIncludesScrollbars, VisibleContentRectBehavior) const override;
1071 virtual IntSize visibleSize() const override;
1072 virtual IntSize contentsSize() const override;
1073 virtual IntSize overhangAmount() const override;
1074 virtual IntPoint lastKnownMousePosition() const override;
1075 virtual bool isHandlingWheelEvent() const override;
1076 virtual bool shouldSuspendScrollAnimations() const override;
1077 virtual IntRect scrollableAreaBoundingBox() const override;
1078 virtual bool isRubberBandInProgress() const override;
1079 virtual bool updatesScrollLayerPositionOnMainThread() const override { return true; }
1080 virtual bool forceUpdateScrollbarsOnMainThreadForPerformanceTesting() const override;
1083 void registerAsTouchEventListenerForScrolling();
1084 void unregisterAsTouchEventListenerForScrolling();
1087 // Rectangle encompassing the scroll corner and resizer rect.
1088 LayoutRect scrollCornerAndResizerRect() const;
1090 // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
1091 void scrollTo(int, int);
1092 void updateCompositingLayersAfterScroll();
1094 IntSize scrollbarOffset(const Scrollbar*) const;
1096 void updateScrollableAreaSet(bool hasOverflow);
1098 void dirtyAncestorChainVisibleDescendantStatus();
1099 void setAncestorChainHasVisibleDescendant();
1101 void updateDescendantDependentFlags(HashSet<const RenderObject*>* outOfFlowDescendantContainingBlocks = nullptr);
1103 bool has3DTransformedDescendant() const { return m_has3DTransformedDescendant; }
1105 bool hasTransformedAncestor() const { return m_hasTransformedAncestor; }
1106 bool has3DTransformedAncestor() const { return m_has3DTransformedAncestor; }
1108 void dirty3DTransformedDescendantStatus();
1109 // Both updates the status, and returns true if descendants of this have 3d.
1110 bool update3DTransformedDescendantStatus();
1112 void createReflection();
1113 void removeReflection();
1115 PassRef<RenderStyle> createReflectionStyle();
1116 bool paintingInsideReflection() const { return m_paintingInsideReflection; }
1117 void setPaintingInsideReflection(bool b) { m_paintingInsideReflection = b; }
1119 void updateOrRemoveFilterClients();
1120 void updateOrRemoveFilterEffectRenderer();
1122 #if ENABLE(CSS_COMPOSITING)
1123 void updateAncestorChainHasBlendingDescendants();
1124 void dirtyAncestorChainHasBlendingDescendants();
1127 void parentClipRects(const ClipRectsContext&, ClipRects&) const;
1128 ClipRect backgroundClipRect(const ClipRectsContext&) const;
1130 RenderLayer* enclosingTransformedAncestor() const;
1132 // Convert a point in absolute coords into layer coords, taking transforms into account
1133 LayoutPoint absoluteToContents(const LayoutPoint&) const;
1135 void positionOverflowControls(const IntSize&);
1136 void updateScrollCornerStyle();
1137 void updateResizerStyle();
1139 void drawPlatformResizerImage(GraphicsContext*, const LayoutRect& resizerCornerRect);
1141 void updatePagination();
1143 void setHasCompositingDescendant(bool b) { m_hasCompositingDescendant = b; }
1145 enum class IndirectCompositingReason {
1150 GraphicalEffect, // opacity, mask, filter, transform etc.
1155 void setIndirectCompositingReason(IndirectCompositingReason reason) { m_indirectCompositingReason = static_cast<unsigned>(reason); }
1156 IndirectCompositingReason indirectCompositingReason() const { return static_cast<IndirectCompositingReason>(m_indirectCompositingReason); }
1157 bool mustCompositeForIndirectReasons() const { return m_indirectCompositingReason; }
1159 // Returns true if z ordering would not change if this layer were a stacking container.
1160 bool canBeStackingContainer() const;
1162 friend class RenderLayerBacking;
1163 friend class RenderLayerCompositor;
1164 friend class RenderLayerModelObject;
1166 LayoutUnit overflowTop() const;
1167 LayoutUnit overflowBottom() const;
1168 LayoutUnit overflowLeft() const;
1169 LayoutUnit overflowRight() const;
1171 IntRect rectForHorizontalScrollbar(const IntRect& borderBoxRect) const;
1172 IntRect rectForVerticalScrollbar(const IntRect& borderBoxRect) const;
1174 LayoutUnit verticalScrollbarStart(int minX, int maxX) const;
1175 LayoutUnit horizontalScrollbarStart(int minX) const;
1177 bool overflowControlsIntersectRect(const IntRect& localRect) const;
1179 RenderLayer* hitTestFlowThreadIfRegionForFragments(const LayerFragments&, RenderLayer*, const HitTestRequest&, HitTestResult&,
1180 const LayoutRect&, const HitTestLocation&,
1181 const HitTestingTransformState*, double* zOffsetForDescendants,
1182 double* zOffset, const HitTestingTransformState* unflattenedTransformState, bool depthSortDescendants);
1183 void paintFlowThreadIfRegionForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
1184 bool mapLayerClipRectsToFragmentationLayer(ClipRects&) const;
1186 RenderNamedFlowFragment* currentRenderNamedFlowFragment() const;
1189 // The bitfields are up here so they will fall into the padding from ScrollableArea on 64-bit.
1191 // Keeps track of whether the layer is currently resizing, so events can cause resizing to start and stop.
1192 bool m_inResizeMode : 1;
1194 bool m_scrollDimensionsDirty : 1;
1195 bool m_zOrderListsDirty : 1;
1196 bool m_normalFlowListDirty: 1;
1197 bool m_isNormalFlowOnly : 1;
1199 bool m_isSelfPaintingLayer : 1;
1201 // If have no self-painting descendants, we don't have to walk our children during painting. This can lead to
1202 // significant savings, especially if the tree has lots of non-self-painting layers grouped together (e.g. table cells).
1203 bool m_hasSelfPaintingLayerDescendant : 1;
1204 bool m_hasSelfPaintingLayerDescendantDirty : 1;
1206 // If we have no out of flow positioned descendants and no non-descendant
1207 // appears between our descendants in stacking order, then we may become a
1208 // stacking context.
1209 bool m_hasOutOfFlowPositionedDescendant : 1;
1210 bool m_hasOutOfFlowPositionedDescendantDirty : 1;
1212 bool m_needsCompositedScrolling : 1;
1214 // If this is true, then no non-descendant appears between any of our
1215 // descendants in stacking order. This is one of the requirements of being
1216 // able to safely become a stacking context.
1217 bool m_descendantsAreContiguousInStackingOrder : 1;
1219 const bool m_isRootLayer : 1;
1221 bool m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether
1222 // we ended up painting this layer or any descendants (and therefore need to
1224 bool m_paintingInsideReflection : 1; // A state bit tracking if we are painting inside a replica.
1225 bool m_inOverflowRelayout : 1;
1226 unsigned m_repaintStatus : 2; // RepaintStatus
1228 bool m_visibleContentStatusDirty : 1;
1229 bool m_hasVisibleContent : 1;
1230 bool m_visibleDescendantStatusDirty : 1;
1231 bool m_hasVisibleDescendant : 1;
1233 bool m_3DTransformedDescendantStatusDirty : 1;
1234 bool m_has3DTransformedDescendant : 1; // Set on a stacking context layer that has 3D descendants anywhere
1235 // in a preserves3D hierarchy. Hint to do 3D-aware hit testing.
1236 bool m_hasCompositingDescendant : 1; // In the z-order tree.
1238 bool m_hasTransformedAncestor : 1;
1239 bool m_has3DTransformedAncestor : 1;
1241 unsigned m_indirectCompositingReason : 3;
1242 unsigned m_viewportConstrainedNotCompositedReason : 2;
1245 bool m_adjustForIOSCaretWhenScrolling : 1;
1246 #if ENABLE(IOS_TOUCH_EVENTS)
1247 bool m_registeredAsTouchEventListenerForScrolling : 1;
1249 bool m_inUserScroll : 1;
1250 bool m_requiresScrollBoundsOriginUpdate : 1;
1253 bool m_containsDirtyOverlayScrollbars : 1;
1254 bool m_updatingMarqueePosition : 1;
1256 #if !ASSERT_DISABLED
1257 bool m_layerListMutationAllowed : 1;
1260 bool m_hasFilterInfo : 1;
1262 #if ENABLE(CSS_COMPOSITING)
1263 unsigned m_blendMode : 5;
1264 bool m_hasNotIsolatedCompositedBlendingDescendants : 1;
1265 bool m_hasNotIsolatedBlendingDescendants : 1;
1266 bool m_hasNotIsolatedBlendingDescendantsStatusDirty : 1;
1269 RenderLayerModelObject& m_renderer;
1271 RenderLayer* m_parent;
1272 RenderLayer* m_previous;
1273 RenderLayer* m_next;
1274 RenderLayer* m_first;
1275 RenderLayer* m_last;
1277 LayoutRect m_repaintRect; // Cached repaint rects. Used by layout.
1278 LayoutRect m_outlineBox;
1280 // Our current relative position offset.
1281 LayoutSize m_offsetForInFlowPosition;
1283 // Our (x,y) coordinates are in our parent layer's coordinate space.
1284 LayoutPoint m_topLeft;
1286 // The layer's width/height
1287 IntSize m_layerSize;
1289 // This is the (scroll) offset from scrollOrigin().
1290 IntSize m_scrollOffset;
1292 // The width/height of our scrolled area.
1293 LayoutSize m_scrollSize;
1295 // For layers with overflow, we have a pair of scrollbars.
1296 RefPtr<Scrollbar> m_hBar;
1297 RefPtr<Scrollbar> m_vBar;
1299 // For layers that establish stacking contexts, m_posZOrderList holds a sorted list of all the
1300 // descendant layers within the stacking context that have z-indices of 0 or greater
1301 // (auto will count as 0). m_negZOrderList holds descendants within our stacking context with negative
1303 std::unique_ptr<Vector<RenderLayer*>> m_posZOrderList;
1304 std::unique_ptr<Vector<RenderLayer*>> m_negZOrderList;
1306 // This list contains child layers that cannot create stacking contexts. For now it is just
1307 // overflow layers, but that may change in the future.
1308 std::unique_ptr<Vector<RenderLayer*>> m_normalFlowList;
1310 std::unique_ptr<ClipRectsCache> m_clipRectsCache;
1312 IntPoint m_cachedOverlayScrollbarOffset;
1314 std::unique_ptr<RenderMarquee> m_marquee; // Used by layers with overflow:marquee
1316 // Cached normal flow values for absolute positioned elements with static left/top values.
1317 LayoutUnit m_staticInlinePosition;
1318 LayoutUnit m_staticBlockPosition;
1320 std::unique_ptr<TransformationMatrix> m_transform;
1322 // May ultimately be extended to many replicas (with their own paint order).
1323 RenderPtr<RenderReplica> m_reflection;
1325 // Renderers to hold our custom scroll corner and resizer.
1326 RenderPtr<RenderScrollbarPart> m_scrollCorner;
1327 RenderPtr<RenderScrollbarPart> m_resizer;
1329 // Pointer to the enclosing RenderLayer that caused us to be paginated. It is 0 if we are not paginated.
1330 RenderLayer* m_enclosingPaginationLayer;
1332 IntRect m_blockSelectionGapsBounds;
1334 std::unique_ptr<RenderLayerBacking> m_backing;
1339 inline void RenderLayer::clearZOrderLists()
1341 ASSERT(!isStackingContainer());
1343 m_posZOrderList = nullptr;
1344 m_negZOrderList = nullptr;
1347 inline void RenderLayer::updateZOrderLists()
1349 if (!m_zOrderListsDirty)
1352 if (!isStackingContainer()) {
1354 m_zOrderListsDirty = false;
1358 rebuildZOrderLists();
1361 #if !ASSERT_DISABLED
1362 class LayerListMutationDetector {
1364 LayerListMutationDetector(RenderLayer* layer)
1366 , m_previousMutationAllowedState(layer->layerListMutationAllowed())
1368 m_layer->setLayerListMutationAllowed(false);
1371 ~LayerListMutationDetector()
1373 m_layer->setLayerListMutationAllowed(m_previousMutationAllowedState);
1377 RenderLayer* m_layer;
1378 bool m_previousMutationAllowedState;
1382 void makeMatrixRenderable(TransformationMatrix&, bool has3DRendering);
1384 } // namespace WebCore
1387 // Outside the WebCore namespace for ease of invocation from gdb.
1388 void showLayerTree(const WebCore::RenderLayer*);
1389 void showLayerTree(const WebCore::RenderObject*);
1392 #endif // RenderLayer_h