1/*
2 * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef ClipRects_h
27#define ClipRects_h
28
29#include "core/rendering/ClipRect.h"
30
31namespace blink {
32
33class ClipRects {
34    WTF_MAKE_FAST_ALLOCATED;
35public:
36    static PassRefPtr<ClipRects> create()
37    {
38        return adoptRef(new ClipRects);
39    }
40
41    static PassRefPtr<ClipRects> create(const ClipRects& other)
42    {
43        return adoptRef(new ClipRects(other));
44    }
45
46    ClipRects()
47        : m_refCnt(1)
48        , m_fixed(0)
49    {
50    }
51
52    void reset(const LayoutRect& r)
53    {
54        m_overflowClipRect = r;
55        m_fixedClipRect = r;
56        m_posClipRect = r;
57        m_fixed = 0;
58    }
59
60    const ClipRect& overflowClipRect() const { return m_overflowClipRect; }
61    void setOverflowClipRect(const ClipRect& r) { m_overflowClipRect = r; }
62
63    const ClipRect& fixedClipRect() const { return m_fixedClipRect; }
64    void setFixedClipRect(const ClipRect&r) { m_fixedClipRect = r; }
65
66    const ClipRect& posClipRect() const { return m_posClipRect; }
67    void setPosClipRect(const ClipRect& r) { m_posClipRect = r; }
68
69    bool fixed() const { return static_cast<bool>(m_fixed); }
70    void setFixed(bool fixed) { m_fixed = fixed ? 1 : 0; }
71
72    void ref() { m_refCnt++; }
73    void deref()
74    {
75        if (!--m_refCnt)
76            delete this;
77    }
78
79    bool operator==(const ClipRects& other) const
80    {
81        return m_overflowClipRect == other.overflowClipRect()
82            && m_fixedClipRect == other.fixedClipRect()
83            && m_posClipRect == other.posClipRect()
84            && fixed() == other.fixed();
85    }
86
87    ClipRects& operator=(const ClipRects& other)
88    {
89        m_overflowClipRect = other.overflowClipRect();
90        m_fixedClipRect = other.fixedClipRect();
91        m_posClipRect = other.posClipRect();
92        m_fixed = other.fixed();
93        return *this;
94    }
95
96private:
97    ClipRects(const LayoutRect& r)
98        : m_overflowClipRect(r)
99        , m_fixedClipRect(r)
100        , m_posClipRect(r)
101        , m_refCnt(1)
102        , m_fixed(0)
103    {
104    }
105
106    ClipRects(const ClipRects& other)
107        : m_overflowClipRect(other.overflowClipRect())
108        , m_fixedClipRect(other.fixedClipRect())
109        , m_posClipRect(other.posClipRect())
110        , m_refCnt(1)
111        , m_fixed(other.fixed())
112    {
113    }
114
115    ClipRect m_overflowClipRect;
116    ClipRect m_fixedClipRect;
117    ClipRect m_posClipRect;
118    unsigned m_refCnt : 31;
119    unsigned m_fixed : 1;
120};
121
122} // namespace blink
123
124#endif // ClipRects_h
125