• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "IntRect.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 : public Noncopyable {
41 public:
42     RenderOverflow(const IntRect& defaultRect = IntRect())
43         : m_topLayoutOverflow(defaultRect.y())
44         , m_bottomLayoutOverflow(defaultRect.bottom())
45         , m_leftLayoutOverflow(defaultRect.x())
46         , m_rightLayoutOverflow(defaultRect.right())
47         , m_topVisualOverflow(defaultRect.y())
48         , m_bottomVisualOverflow(defaultRect.bottom())
49         , m_leftVisualOverflow(defaultRect.x())
50         , m_rightVisualOverflow(defaultRect.right())
51     {
52     }
53 
topLayoutOverflow()54     int topLayoutOverflow() const { return m_topLayoutOverflow; }
bottomLayoutOverflow()55     int bottomLayoutOverflow() const { return m_bottomLayoutOverflow; }
leftLayoutOverflow()56     int leftLayoutOverflow() const { return m_leftLayoutOverflow; }
rightLayoutOverflow()57     int rightLayoutOverflow() const { return m_rightLayoutOverflow; }
58     IntRect layoutOverflowRect() const;
59 
topVisualOverflow()60     int topVisualOverflow() const { return m_topVisualOverflow; }
bottomVisualOverflow()61     int bottomVisualOverflow() const { return m_bottomVisualOverflow; }
leftVisualOverflow()62     int leftVisualOverflow() const { return m_leftVisualOverflow; }
rightVisualOverflow()63     int rightVisualOverflow() const { return m_rightVisualOverflow; }
64     IntRect visualOverflowRect() const;
65 
66     IntRect visibleOverflowRect() const;
67 
setTopLayoutOverflow(int overflow)68     void setTopLayoutOverflow(int overflow) { m_topLayoutOverflow = overflow; }
setBottomLayoutOverflow(int overflow)69     void setBottomLayoutOverflow(int overflow) { m_bottomLayoutOverflow = overflow; }
setLeftLayoutOverflow(int overflow)70     void setLeftLayoutOverflow(int overflow) { m_leftLayoutOverflow = overflow; }
setRightLayoutOverflow(int overflow)71     void setRightLayoutOverflow(int overflow) { m_rightLayoutOverflow = overflow; }
72 
setTopVisualOverflow(int overflow)73     void setTopVisualOverflow(int overflow) { m_topVisualOverflow = overflow; }
setBottomVisualOverflow(int overflow)74     void setBottomVisualOverflow(int overflow) { m_bottomVisualOverflow = overflow; }
setLeftVisualOverflow(int overflow)75     void setLeftVisualOverflow(int overflow) { m_leftVisualOverflow = overflow; }
setRightVisualOverflow(int overflow)76     void setRightVisualOverflow(int overflow) { m_rightVisualOverflow = overflow; }
77 
78     void move(int dx, int dy);
79 
80     void addLayoutOverflow(const IntRect&);
81     void addVisualOverflow(const IntRect&);
82 
83     void resetLayoutOverflow(const IntRect& defaultRect);
84 
85 private:
86     int m_topLayoutOverflow;
87     int m_bottomLayoutOverflow;
88     int m_leftLayoutOverflow;
89     int m_rightLayoutOverflow;
90 
91     int m_topVisualOverflow;
92     int m_bottomVisualOverflow;
93     int m_leftVisualOverflow;
94     int m_rightVisualOverflow;
95 };
96 
layoutOverflowRect()97 inline IntRect RenderOverflow::layoutOverflowRect() const
98 {
99     return IntRect(m_leftLayoutOverflow, m_topLayoutOverflow, m_rightLayoutOverflow - m_leftLayoutOverflow, m_bottomLayoutOverflow - m_topLayoutOverflow);
100 }
101 
visualOverflowRect()102 inline IntRect RenderOverflow::visualOverflowRect() const
103 {
104     return IntRect(m_leftVisualOverflow, m_topVisualOverflow, m_rightVisualOverflow - m_leftVisualOverflow, m_bottomVisualOverflow - m_topVisualOverflow);
105 }
106 
visibleOverflowRect()107 inline IntRect RenderOverflow::visibleOverflowRect() const
108 {
109     IntRect combinedRect(layoutOverflowRect());
110     combinedRect.unite(visualOverflowRect());
111     return combinedRect;
112 }
113 
move(int dx,int dy)114 inline void RenderOverflow::move(int dx, int dy)
115 {
116     m_topLayoutOverflow += dy;
117     m_bottomLayoutOverflow += dy;
118     m_leftLayoutOverflow += dx;
119     m_rightLayoutOverflow += dx;
120 
121     m_topVisualOverflow += dy;
122     m_bottomVisualOverflow += dy;
123     m_leftVisualOverflow += dx;
124     m_rightVisualOverflow += dx;
125 }
126 
addLayoutOverflow(const IntRect & rect)127 inline void RenderOverflow::addLayoutOverflow(const IntRect& rect)
128 {
129     m_topLayoutOverflow = std::min(rect.y(), m_topLayoutOverflow);
130     m_bottomLayoutOverflow = std::max(rect.bottom(), m_bottomLayoutOverflow);
131     m_leftLayoutOverflow = std::min(rect.x(), m_leftLayoutOverflow);
132     m_rightLayoutOverflow = std::max(rect.right(), m_rightLayoutOverflow);
133 }
134 
addVisualOverflow(const IntRect & rect)135 inline void RenderOverflow::addVisualOverflow(const IntRect& rect)
136 {
137     m_topVisualOverflow = std::min(rect.y(), m_topVisualOverflow);
138     m_bottomVisualOverflow = std::max(rect.bottom(), m_bottomVisualOverflow);
139     m_leftVisualOverflow = std::min(rect.x(), m_leftVisualOverflow);
140     m_rightVisualOverflow = std::max(rect.right(), m_rightVisualOverflow);
141 }
142 
resetLayoutOverflow(const IntRect & rect)143 inline void RenderOverflow::resetLayoutOverflow(const IntRect& rect)
144 {
145     m_topLayoutOverflow = rect.y();
146     m_bottomLayoutOverflow = rect.bottom();
147     m_leftLayoutOverflow = rect.x();
148     m_rightLayoutOverflow = rect.right();
149 }
150 
151 } // namespace WebCore
152 
153 #endif // RenderOverflow_h
154