Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderLayerClipper.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 RenderLayerClipper_h
46 #define RenderLayerClipper_h
47
48 #include "core/rendering/ClipRect.h"
49 #include "core/rendering/RenderBox.h" // For OverlayScrollbarSizeRelevancy.
50
51 namespace WebCore {
52
53 class RenderLayer;
54
55 struct ClipRectsContext {
56     ClipRectsContext(const RenderLayer* inRootLayer, ClipRectsType inClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, ShouldRespectOverflowClip inRespectOverflowClip = RespectOverflowClip, const LayoutSize& inSubPixelAccumulation = LayoutSize())
57         : rootLayer(inRootLayer)
58         , clipRectsType(inClipRectsType)
59         , overlayScrollbarSizeRelevancy(inOverlayScrollbarSizeRelevancy)
60         , respectOverflowClip(inRespectOverflowClip)
61         , subPixelAccumulation(inSubPixelAccumulation)
62     { }
63     const RenderLayer* rootLayer;
64     ClipRectsType clipRectsType;
65     OverlayScrollbarSizeRelevancy overlayScrollbarSizeRelevancy;
66     ShouldRespectOverflowClip respectOverflowClip;
67     LayoutSize subPixelAccumulation;
68 };
69
70 class RenderLayerClipper {
71     WTF_MAKE_NONCOPYABLE(RenderLayerClipper);
72 public:
73     RenderLayerClipper(RenderLayerModelObject* renderer)
74     : m_renderer(renderer)
75     {
76     }
77
78     ClipRects* clipRects(const ClipRectsContext& context) const
79     {
80         ASSERT(context.clipRectsType < NumCachedClipRectsTypes);
81         return m_clipRectsCache ? m_clipRectsCache->getClipRects(context.clipRectsType, context.respectOverflowClip).get() : 0;
82     }
83
84     // Compute and cache clip rects computed with the given layer as the root
85     void updateClipRects(const ClipRectsContext&);
86
87     void clearClipRectsIncludingDescendants(ClipRectsType typeToClear = AllClipRectTypes);
88     void clearClipRects(ClipRectsType typeToClear = AllClipRectTypes);
89
90     LayoutRect childrenClipRect() const; // Returns the foreground clip rect of the layer in the document's coordinate space.
91     LayoutRect selfClipRect() const; // Returns the background clip rect of the layer in the document's coordinate space.
92     LayoutRect localClipRect() const; // Returns the background clip rect of the layer in the local coordinate space.
93
94     ClipRect backgroundClipRect(const ClipRectsContext&) const;
95
96     // FIXME: The following functions should be private.
97
98     // This method figures out our layerBounds in coordinates relative to
99     // |rootLayer}. It also computes our background and foreground clip rects
100     // for painting/event handling.
101     // Pass offsetFromRoot if known.
102     void calculateRects(const ClipRectsContext&, const LayoutRect& paintDirtyRect, LayoutRect& layerBounds,
103         ClipRect& backgroundRect, ClipRect& foregroundRect, ClipRect& outlineRect, const LayoutPoint* offsetFromRoot = 0) const;
104
105     // Compute and return the clip rects. If useCached is true, will used previously computed clip rects on ancestors
106     // (rather than computing them all from scratch up the parent chain).
107     void calculateClipRects(const ClipRectsContext&, ClipRects&) const;
108
109 private:
110     void parentClipRects(const ClipRectsContext&, ClipRects&) const;
111
112     // The layer relative to which clipping rects for this layer are computed.
113     RenderLayer* clippingRootForPainting() const;
114
115     // FIXME: Could this be a RenderBox?
116     RenderLayerModelObject* m_renderer;
117
118     OwnPtr<ClipRectsCache> m_clipRectsCache;
119 };
120
121 } // namespace WebCore
122
123 #endif // RenderLayerClipper_h