2 * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Intel Corporation. All rights reserved.
5 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
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>
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.
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.
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
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.
45 #ifndef RenderLayerClipper_h
46 #define RenderLayerClipper_h
48 #include "core/rendering/ClipRectsCache.h"
49 #include "core/rendering/RenderBox.h"
55 enum ShouldRespectOverflowClip {
60 class ClipRectsContext {
62 ClipRectsContext(const RenderLayer* root, ClipRectsCacheSlot slot, OverlayScrollbarSizeRelevancy relevancy = IgnoreOverlayScrollbarSize, const LayoutSize& accumulation = LayoutSize())
64 , scrollbarRelevancy(relevancy)
66 , subPixelAccumulation(accumulation)
67 , respectOverflowClip(RespectOverflowClip)
71 void setIgnoreOverflowClip()
73 ASSERT(!usesCache() || cacheSlot == PaintingClipRects);
74 ASSERT(respectOverflowClip == RespectOverflowClip);
75 cacheSlot = PaintingClipRectsIgnoringOverflowClip;
76 respectOverflowClip = IgnoreOverflowClip;
79 bool usesCache() const
81 return cacheSlot != UncachedClipRects;
84 const RenderLayer* const rootLayer;
85 const OverlayScrollbarSizeRelevancy scrollbarRelevancy;
88 friend class RenderLayerClipper;
90 ClipRectsCacheSlot cacheSlot;
91 LayoutSize subPixelAccumulation;
92 ShouldRespectOverflowClip respectOverflowClip;
95 class RenderLayerClipper {
96 WTF_MAKE_NONCOPYABLE(RenderLayerClipper);
98 explicit RenderLayerClipper(RenderLayerModelObject&);
100 void clearClipRectsIncludingDescendants();
101 void clearClipRectsIncludingDescendants(ClipRectsCacheSlot);
103 LayoutRect childrenClipRect() const; // Returns the foreground clip rect of the layer in the document's coordinate space.
104 LayoutRect localClipRect() const; // Returns the background clip rect of the layer in the local coordinate space.
106 ClipRects* getClipRects(const ClipRectsContext&) const;
108 ClipRect backgroundClipRect(const ClipRectsContext&) const;
110 // This method figures out our layerBounds in coordinates relative to
111 // |rootLayer|. It also computes our background and foreground clip rects
112 // for painting/event handling.
113 // Pass offsetFromRoot if known.
114 void calculateRects(const ClipRectsContext&, const LayoutRect& paintDirtyRect, LayoutRect& layerBounds,
115 ClipRect& backgroundRect, ClipRect& foregroundRect, ClipRect& outlineRect, const LayoutPoint* offsetFromRoot = 0) const;
118 void calculateClipRects(const ClipRectsContext&, ClipRects&) const;
120 ClipRects* clipRectsIfCached(const ClipRectsContext&) const;
121 ClipRects* storeClipRectsInCache(const ClipRectsContext&, ClipRects* parentClipRects, const ClipRects&) const;
123 // cachedClipRects looks buggy: It doesn't check whether context.rootLayer and entry.root match.
124 // FIXME: Move callers to clipRectsIfCached, which does the proper checks.
125 ClipRects* cachedClipRects(const ClipRectsContext& context) const
127 return m_cache ? m_cache->get(context.cacheSlot).clipRects.get() : 0;
130 void getOrCalculateClipRects(const ClipRectsContext&, ClipRects&) const;
132 RenderLayer* clippingRootForPainting() const;
134 ClipRectsCache& cache() const
137 m_cache = adoptPtr(new ClipRectsCache);
141 // FIXME: Could this be a RenderBox?
142 RenderLayerModelObject& m_renderer;
143 mutable OwnPtr<ClipRectsCache> m_cache;
148 #endif // RenderLayerClipper_h