2 * Copyright (C) 2018 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
30 #include "LayoutPoint.h"
31 #include "LayoutRect.h"
32 #include "LayoutUnit.h"
33 #include <wtf/IsoMalloc.h>
39 WTF_MAKE_ISO_ALLOCATED(Box);
41 friend class FormattingContext;
45 LayoutRect rect() const { return m_rect; }
47 LayoutUnit top() const { return m_rect.y(); }
48 LayoutUnit left() const { return m_rect.x(); }
49 LayoutUnit bottom() const { return m_rect.maxY(); }
50 LayoutUnit right() const { return m_rect.maxX(); }
52 LayoutPoint topLeft() const { return m_rect.location(); }
53 LayoutPoint bottomRight() const { return m_rect.location(); }
55 LayoutSize size() const { return m_rect.size(); }
56 LayoutUnit width() const { return m_rect.width(); }
57 LayoutUnit height() const { return m_rect.height(); }
59 LayoutUnit marginTop() const { return m_marginTop; }
60 LayoutUnit marginLeft() const { return m_marginLeft; }
61 LayoutUnit marginBottom() const { return m_marginBottom; }
62 LayoutUnit marginRight() const { return m_marginRight; }
64 LayoutRect marginBox() const;
65 LayoutRect borderBox() const;
66 LayoutRect paddingBox() const;
67 LayoutRect contentBox() const;
69 const Box* parent() const { return m_parent; }
70 const Box* nextSibling() const { return m_parent; }
71 const Box* previousSibling() const { return m_parent; }
72 const Box* firstChild() const { return m_firstChild; }
73 const Box* lastChild() const { return m_lastChild; }
78 void setRect(const LayoutRect& rect) { m_rect = rect; }
79 void setTopLeft(const LayoutPoint& topLeft) { m_rect.setLocation(topLeft); }
80 void setTop(LayoutUnit top) { m_rect.setY(top); }
81 void setLeft(LayoutUnit left) { m_rect.setX(left); }
82 void setSize(const LayoutSize& size) { m_rect.setSize(size); }
83 void setWidth(LayoutUnit width) { m_rect.setWidth(width); }
84 void setHeight(LayoutUnit height) { m_rect.setHeight(height); }
86 void setMarginTop(LayoutUnit marginTop) { m_marginTop = marginTop; }
87 void setMarginLeft(LayoutUnit marginLeft) { m_marginLeft = marginLeft; }
88 void setMarginBottom(LayoutUnit marginBottom) { m_marginBottom = marginBottom; }
89 void setMarginRight(LayoutUnit marginRight) { m_marginRight = marginRight; }
91 void setBorderTop(LayoutUnit borderTop) { m_borderTop = borderTop; }
92 void setBorderLeft(LayoutUnit borderLeft) { m_borderLeft = borderLeft; }
93 void setBorderBottom(LayoutUnit borderBottom) { m_borderBottom = borderBottom; }
94 void setBorderRight(LayoutUnit borderRight) { m_borderRight = borderRight; }
96 void setPaddingTop(LayoutUnit paddingTop) { m_paddingTop = paddingTop; }
97 void setPaddingLeft(LayoutUnit paddingLeft) { m_paddingLeft = paddingLeft; }
98 void setPaddingBottom(LayoutUnit paddingBottom) { m_paddingBottom = paddingBottom; }
99 void setPaddingRight(LayoutUnit paddingRight) { m_paddingRight = paddingRight; }
101 void setParent(Box& parent) { m_parent = &parent; }
102 void setNextSibling(Box& nextSibling) { m_nextSibling = &nextSibling; }
103 void setPreviousSibling(Box& previousSibling) { m_previousSibling = &previousSibling; }
104 void setFirstChild(Box& firstChild) { m_firstChild = &firstChild; }
105 void setLastChild(Box& lastChild) { m_lastChild = &lastChild; }
108 LayoutUnit m_marginTop;
109 LayoutUnit m_marginLeft;
110 LayoutUnit m_marginBottom;
111 LayoutUnit m_marginRight;
113 LayoutUnit m_borderTop;
114 LayoutUnit m_borderLeft;
115 LayoutUnit m_borderBottom;
116 LayoutUnit m_borderRight;
118 LayoutUnit m_paddingTop;
119 LayoutUnit m_paddingLeft;
120 LayoutUnit m_paddingBottom;
121 LayoutUnit m_paddingRight;
123 const Box* m_parent { nullptr };
124 const Box* m_nextSibling { nullptr };
125 const Box* m_previousSibling { nullptr };
126 const Box* m_firstChild { nullptr };
127 const Box* m_lastChild { nullptr };