initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderOverflow.h
1 /*
2  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #ifndef RenderOverflow_h
22 #define RenderOverflow_h
23
24 #include "LayoutTypes.h"
25
26 namespace WebCore
27 {
28 // RenderOverflow is a class for tracking content that spills out of a box.  This class is used by RenderBox and
29 // InlineFlowBox.
30 //
31 // There are two types of overflow: layout overflow (which is expected to be reachable via scrolling mechanisms) and
32 // visual overflow (which is not expected to be reachable via scrolling mechanisms).
33 //
34 // Layout overflow examples include other boxes that spill out of our box,  For example, in the inline case a tall image
35 // could spill out of a line box. 
36     
37 // Examples of visual overflow are shadows, text stroke (and eventually outline and border-image).
38
39 // This object is allocated only when some of these fields have non-default values in the owning box.
40 class RenderOverflow {
41     WTF_MAKE_NONCOPYABLE(RenderOverflow); WTF_MAKE_FAST_ALLOCATED;
42 public:
43     RenderOverflow(const LayoutRect& layoutRect, const LayoutRect& visualRect) 
44         : m_minYLayoutOverflow(layoutRect.y())
45         , m_maxYLayoutOverflow(layoutRect.maxY())
46         , m_minXLayoutOverflow(layoutRect.x())
47         , m_maxXLayoutOverflow(layoutRect.maxX())
48         , m_minYVisualOverflow(visualRect.y())
49         , m_maxYVisualOverflow(visualRect.maxY())
50         , m_minXVisualOverflow(visualRect.x())
51         , m_maxXVisualOverflow(visualRect.maxX())
52     {
53     }
54    
55     LayoutUnit minYLayoutOverflow() const { return m_minYLayoutOverflow; }
56     LayoutUnit maxYLayoutOverflow() const { return m_maxYLayoutOverflow; }
57     LayoutUnit minXLayoutOverflow() const { return m_minXLayoutOverflow; }
58     LayoutUnit maxXLayoutOverflow() const { return m_maxXLayoutOverflow; }
59     LayoutRect layoutOverflowRect() const;
60
61     LayoutUnit minYVisualOverflow() const { return m_minYVisualOverflow; }
62     LayoutUnit maxYVisualOverflow() const { return m_maxYVisualOverflow; }
63     LayoutUnit minXVisualOverflow() const { return m_minXVisualOverflow; }
64     LayoutUnit maxXVisualOverflow() const { return m_maxXVisualOverflow; }
65     LayoutRect visualOverflowRect() const;
66
67     void setMinYLayoutOverflow(LayoutUnit overflow) { m_minYLayoutOverflow = overflow; }
68     void setMaxYLayoutOverflow(LayoutUnit overflow) { m_maxYLayoutOverflow = overflow; }
69     void setMinXLayoutOverflow(LayoutUnit overflow) { m_minXLayoutOverflow = overflow; }
70     void setMaxXLayoutOverflow(LayoutUnit overflow) { m_maxXLayoutOverflow = overflow; }
71     
72     void setMinYVisualOverflow(LayoutUnit overflow) { m_minYVisualOverflow = overflow; }
73     void setMaxYVisualOverflow(LayoutUnit overflow) { m_maxYVisualOverflow = overflow; }
74     void setMinXVisualOverflow(LayoutUnit overflow) { m_minXVisualOverflow = overflow; }
75     void setMaxXVisualOverflow(LayoutUnit overflow) { m_maxXVisualOverflow = overflow; }
76     
77     void move(LayoutUnit dx, LayoutUnit dy);
78     
79     void addLayoutOverflow(const LayoutRect&);
80     void addVisualOverflow(const LayoutRect&);
81
82     void setLayoutOverflow(const LayoutRect&);
83     void setVisualOverflow(const LayoutRect&);
84
85     void resetLayoutOverflow(const LayoutRect& defaultRect);
86
87 private:
88     LayoutUnit m_minYLayoutOverflow;
89     LayoutUnit m_maxYLayoutOverflow;
90     LayoutUnit m_minXLayoutOverflow;
91     LayoutUnit m_maxXLayoutOverflow;
92
93     LayoutUnit m_minYVisualOverflow;
94     LayoutUnit m_maxYVisualOverflow;
95     LayoutUnit m_minXVisualOverflow;
96     LayoutUnit m_maxXVisualOverflow;
97 };
98
99 inline LayoutRect RenderOverflow::layoutOverflowRect() const
100 {
101     return LayoutRect(m_minXLayoutOverflow, m_minYLayoutOverflow, m_maxXLayoutOverflow - m_minXLayoutOverflow, m_maxYLayoutOverflow - m_minYLayoutOverflow);
102 }
103
104 inline LayoutRect RenderOverflow::visualOverflowRect() const
105 {
106     return LayoutRect(m_minXVisualOverflow, m_minYVisualOverflow, m_maxXVisualOverflow - m_minXVisualOverflow, m_maxYVisualOverflow - m_minYVisualOverflow);
107 }
108
109 inline void RenderOverflow::move(LayoutUnit dx, LayoutUnit dy)
110 {
111     m_minYLayoutOverflow += dy;
112     m_maxYLayoutOverflow += dy;
113     m_minXLayoutOverflow += dx;
114     m_maxXLayoutOverflow += dx;
115     
116     m_minYVisualOverflow += dy;
117     m_maxYVisualOverflow += dy;
118     m_minXVisualOverflow += dx;
119     m_maxXVisualOverflow += dx;
120 }
121
122 inline void RenderOverflow::addLayoutOverflow(const LayoutRect& rect)
123 {
124     m_minYLayoutOverflow = std::min(rect.y(), m_minYLayoutOverflow);
125     m_maxYLayoutOverflow = std::max(rect.maxY(), m_maxYLayoutOverflow);
126     m_minXLayoutOverflow = std::min(rect.x(), m_minXLayoutOverflow);
127     m_maxXLayoutOverflow = std::max(rect.maxX(), m_maxXLayoutOverflow);
128 }
129
130 inline void RenderOverflow::addVisualOverflow(const LayoutRect& rect)
131 {
132     m_minYVisualOverflow = std::min(rect.y(), m_minYVisualOverflow);
133     m_maxYVisualOverflow = std::max(rect.maxY(), m_maxYVisualOverflow);
134     m_minXVisualOverflow = std::min(rect.x(), m_minXVisualOverflow);
135     m_maxXVisualOverflow = std::max(rect.maxX(), m_maxXVisualOverflow);
136 }
137
138 inline void RenderOverflow::setLayoutOverflow(const LayoutRect& rect)
139 {
140     m_minYLayoutOverflow = rect.y();
141     m_maxYLayoutOverflow = rect.maxY();
142     m_minXLayoutOverflow = rect.x();
143     m_maxXLayoutOverflow = rect.maxX();
144 }
145
146 inline void RenderOverflow::setVisualOverflow(const LayoutRect& rect)
147 {
148     m_minYVisualOverflow = rect.y();
149     m_maxYVisualOverflow = rect.maxY();
150     m_minXVisualOverflow = rect.x();
151     m_maxXVisualOverflow = rect.maxX();
152 }
153
154 inline void RenderOverflow::resetLayoutOverflow(const LayoutRect& rect)
155 {
156     m_minYLayoutOverflow = rect.y();
157     m_maxYLayoutOverflow = rect.maxY();
158     m_minXLayoutOverflow = rect.x();
159     m_maxXLayoutOverflow = rect.maxX();
160 }
161
162 } // namespace WebCore
163
164 #endif // RenderOverflow_h