• 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 "platform/geometry/LayoutRect.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:
RenderOverflow(const LayoutRect & layoutRect,const LayoutRect & visualRect)43     RenderOverflow(const LayoutRect& layoutRect, const LayoutRect& visualRect)
44         : m_layoutOverflow(layoutRect)
45         , m_visualOverflow(visualRect)
46     {
47     }
48 
layoutOverflowRect()49     const LayoutRect layoutOverflowRect() const { return m_layoutOverflow; }
visualOverflowRect()50     const LayoutRect visualOverflowRect() const { return m_visualOverflow; }
contentsVisualOverflowRect()51     LayoutRect contentsVisualOverflowRect() const { return m_contentsVisualOverflow; }
52 
setMinYLayoutOverflow(LayoutUnit overflow)53     void setMinYLayoutOverflow(LayoutUnit overflow) { m_layoutOverflow.setY(overflow); }
setMaxYLayoutOverflow(LayoutUnit overflow)54     void setMaxYLayoutOverflow(LayoutUnit overflow) { m_layoutOverflow.setHeight(overflow - m_layoutOverflow.y()); }
setMinXLayoutOverflow(LayoutUnit overflow)55     void setMinXLayoutOverflow(LayoutUnit overflow) { m_layoutOverflow.setX(overflow); }
setMaxXLayoutOverflow(LayoutUnit overflow)56     void setMaxXLayoutOverflow(LayoutUnit overflow) { m_layoutOverflow.setWidth(overflow - m_layoutOverflow.x()); }
57 
setMinYVisualOverflow(LayoutUnit overflow)58     void setMinYVisualOverflow(LayoutUnit overflow) { m_visualOverflow.setY(overflow); }
setMaxYVisualOverflow(LayoutUnit overflow)59     void setMaxYVisualOverflow(LayoutUnit overflow) { m_visualOverflow.setHeight(overflow - m_layoutOverflow.y()); }
setMinXVisualOverflow(LayoutUnit overflow)60     void setMinXVisualOverflow(LayoutUnit overflow) { m_visualOverflow.setX(overflow); }
setMaxXVisualOverflow(LayoutUnit overflow)61     void setMaxXVisualOverflow(LayoutUnit overflow) { m_visualOverflow.setWidth(overflow - m_layoutOverflow.x()); }
62 
63     void move(LayoutUnit dx, LayoutUnit dy);
64 
65     void addLayoutOverflow(const LayoutRect&);
66     void addVisualOverflow(const LayoutRect&);
addContentsVisualOverflow(const LayoutRect & rect)67     void addContentsVisualOverflow(const LayoutRect& rect) { m_contentsVisualOverflow.unite(rect); }
68 
69     void setLayoutOverflow(const LayoutRect&);
70     void setVisualOverflow(const LayoutRect&);
71 
layoutClientAfterEdge()72     LayoutUnit layoutClientAfterEdge() const { return m_layoutClientAfterEdge; }
setLayoutClientAfterEdge(LayoutUnit clientAfterEdge)73     void setLayoutClientAfterEdge(LayoutUnit clientAfterEdge) { m_layoutClientAfterEdge = clientAfterEdge; }
74 
75 private:
76     LayoutRect m_layoutOverflow;
77     LayoutRect m_visualOverflow;
78     LayoutRect m_contentsVisualOverflow;
79 
80     LayoutUnit m_layoutClientAfterEdge;
81 };
82 
move(LayoutUnit dx,LayoutUnit dy)83 inline void RenderOverflow::move(LayoutUnit dx, LayoutUnit dy)
84 {
85     m_layoutOverflow.move(dx, dy);
86     m_visualOverflow.move(dx, dy);
87     m_contentsVisualOverflow.move(dx, dy);
88 }
89 
addLayoutOverflow(const LayoutRect & rect)90 inline void RenderOverflow::addLayoutOverflow(const LayoutRect& rect)
91 {
92     LayoutUnit maxX = std::max(rect.maxX(), m_layoutOverflow.maxX());
93     LayoutUnit maxY = std::max(rect.maxY(), m_layoutOverflow.maxY());
94     LayoutUnit minX = std::min(rect.x(), m_layoutOverflow.x());
95     LayoutUnit minY = std::min(rect.y(), m_layoutOverflow.y());
96     // In case the width/height is larger than LayoutUnit can represent, fix the right/bottom edge and shift the top/left ones
97     m_layoutOverflow.setWidth(maxX - minX);
98     m_layoutOverflow.setHeight(maxY - minY);
99     m_layoutOverflow.setX(maxX - m_layoutOverflow.width());
100     m_layoutOverflow.setY(maxY - m_layoutOverflow.height());
101 }
102 
addVisualOverflow(const LayoutRect & rect)103 inline void RenderOverflow::addVisualOverflow(const LayoutRect& rect)
104 {
105     LayoutUnit maxX = std::max(rect.maxX(), m_visualOverflow.maxX());
106     LayoutUnit maxY = std::max(rect.maxY(), m_visualOverflow.maxY());
107     m_visualOverflow.setX(std::min(rect.x(), m_visualOverflow.x()));
108     m_visualOverflow.setY(std::min(rect.y(), m_visualOverflow.y()));
109     m_visualOverflow.setWidth(maxX - m_visualOverflow.x());
110     m_visualOverflow.setHeight(maxY - m_visualOverflow.y());
111 }
112 
setLayoutOverflow(const LayoutRect & rect)113 inline void RenderOverflow::setLayoutOverflow(const LayoutRect& rect)
114 {
115     m_layoutOverflow = rect;
116 }
117 
setVisualOverflow(const LayoutRect & rect)118 inline void RenderOverflow::setVisualOverflow(const LayoutRect& rect)
119 {
120     m_visualOverflow = rect;
121 }
122 
123 } // namespace WebCore
124 
125 #endif // RenderOverflow_h
126