|
1 /* |
|
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. |
|
5 * |
|
6 * This library is free software; you can redistribute it and/or |
|
7 * modify it under the terms of the GNU Library General Public |
|
8 * License as published by the Free Software Foundation; either |
|
9 * version 2 of the License, or (at your option) any later version. |
|
10 * |
|
11 * This library is distributed in the hope that it will be useful, |
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 * Library General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU Library General Public License |
|
17 * along with this library; see the file COPYING.LIB. If not, write to |
|
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
19 * Boston, MA 02110-1301, USA. |
|
20 * |
|
21 */ |
|
22 |
|
23 #ifndef RenderBox_h |
|
24 #define RenderBox_h |
|
25 |
|
26 #include "RenderObject.h" |
|
27 |
|
28 namespace WebCore { |
|
29 |
|
30 enum WidthType { Width, MinWidth, MaxWidth }; |
|
31 |
|
32 class RenderBox : public RenderObject { |
|
33 public: |
|
34 RenderBox(Node*); |
|
35 virtual ~RenderBox(); |
|
36 |
|
37 virtual const char* renderName() const { return "RenderBox"; } |
|
38 |
|
39 virtual void setStyle(RenderStyle*); |
|
40 virtual void paint(PaintInfo&, int tx, int ty); |
|
41 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); |
|
42 |
|
43 virtual void destroy(); |
|
44 |
|
45 virtual int minPrefWidth() const; |
|
46 virtual int maxPrefWidth() const; |
|
47 |
|
48 virtual int overrideSize() const; |
|
49 virtual int overrideWidth() const; |
|
50 virtual int overrideHeight() const; |
|
51 virtual void setOverrideSize(int); |
|
52 |
|
53 virtual bool absolutePosition(int& x, int& y, bool fixed = false) const; |
|
54 |
|
55 virtual int xPos() const { return m_x; } |
|
56 virtual int yPos() const { return m_y; } |
|
57 virtual void setPos(int x, int y); |
|
58 |
|
59 virtual int width() const { return m_width; } |
|
60 virtual int height() const { return m_height; } |
|
61 virtual void setWidth(int width) { m_width = width; } |
|
62 virtual void setHeight(int height) { m_height = height; } |
|
63 |
|
64 virtual int marginTop() const { return m_marginTop; } |
|
65 virtual int marginBottom() const { return m_marginBottom; } |
|
66 virtual int marginLeft() const { return m_marginLeft; } |
|
67 virtual int marginRight() const { return m_marginRight; } |
|
68 |
|
69 virtual IntRect borderBox() const { return IntRect(0, -borderTopExtra(), width(), height() + borderTopExtra() + borderBottomExtra()); } |
|
70 |
|
71 int calcBorderBoxWidth(int width) const; |
|
72 int calcBorderBoxHeight(int height) const; |
|
73 int calcContentBoxWidth(int width) const; |
|
74 int calcContentBoxHeight(int height) const; |
|
75 |
|
76 virtual void borderFitAdjust(int& x, int& w) const {}; // Shrink the box in which the border paints if border-fit is set. |
|
77 |
|
78 // This method is now public so that centered objects like tables that are |
|
79 // shifted right by left-aligned floats can recompute their left and |
|
80 // right margins (so that they can remain centered after being |
|
81 // shifted. -dwh |
|
82 void calcHorizontalMargins(const Length& marginLeft, const Length& marginRight, int containerWidth); |
|
83 |
|
84 virtual void position(InlineBox*); |
|
85 |
|
86 virtual void dirtyLineBoxes(bool fullLayout, bool isRootLineBox = false); |
|
87 |
|
88 // For inline replaced elements, this function returns the inline box that owns us. Enables |
|
89 // the replaced RenderObject to quickly determine what line it is contained on and to easily |
|
90 // iterate over structures on the line. |
|
91 virtual InlineBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; } |
|
92 virtual void setInlineBoxWrapper(InlineBox* boxWrapper) { m_inlineBoxWrapper = boxWrapper; } |
|
93 virtual void deleteLineBoxWrapper(); |
|
94 |
|
95 virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const; |
|
96 virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const; |
|
97 virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const; |
|
98 |
|
99 virtual IntRect absoluteClippedOverflowRect(); |
|
100 virtual void computeAbsoluteRepaintRect(IntRect&, bool fixed = false); |
|
101 IntSize offsetForPositionedInContainer(RenderObject*) const; |
|
102 |
|
103 virtual void repaintDuringLayoutIfMoved(const IntRect&); |
|
104 |
|
105 virtual int containingBlockWidth() const; |
|
106 |
|
107 virtual void calcWidth(); |
|
108 virtual void calcHeight(); |
|
109 |
|
110 bool stretchesToViewHeight() const |
|
111 { |
|
112 return style()->htmlHacks() && style()->height().isAuto() && !isFloatingOrPositioned() && (isRoot() || isBody()); |
|
113 } |
|
114 |
|
115 virtual IntSize intrinsicSize() const { return IntSize(); } |
|
116 |
|
117 // Whether or not the element shrinks to its intrinsic width (rather than filling the width |
|
118 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this. |
|
119 bool sizesToIntrinsicWidth(WidthType) const; |
|
120 virtual bool stretchesToMinIntrinsicWidth() const { return false; } |
|
121 |
|
122 int calcWidthUsing(WidthType, int containerWidth); |
|
123 int calcHeightUsing(const Length& height); |
|
124 int calcReplacedWidthUsing(Length width) const; |
|
125 int calcReplacedHeightUsing(Length height) const; |
|
126 |
|
127 virtual int calcReplacedWidth() const; |
|
128 virtual int calcReplacedHeight() const; |
|
129 |
|
130 int calcPercentageHeight(const Length& height); |
|
131 |
|
132 virtual int availableHeight() const; |
|
133 int availableHeightUsing(const Length&) const; |
|
134 |
|
135 void calcVerticalMargins(); |
|
136 |
|
137 int relativePositionOffsetX() const; |
|
138 int relativePositionOffsetY() const; |
|
139 |
|
140 virtual RenderLayer* layer() const { return m_layer; } |
|
141 |
|
142 virtual IntRect caretRect(int offset, EAffinity = UPSTREAM, int* extraWidthToEndOfLine = 0); |
|
143 |
|
144 virtual void paintBackgroundExtended(GraphicsContext*, const Color&, const BackgroundLayer*, int clipY, int clipHeight, |
|
145 int tx, int ty, int width, int height, bool includeLeftEdge = true, bool includeRightEdge = true); |
|
146 |
|
147 virtual int staticX() const; |
|
148 virtual int staticY() const; |
|
149 virtual void setStaticX(int staticX); |
|
150 virtual void setStaticY(int staticY); |
|
151 |
|
152 virtual IntRect getOverflowClipRect(int tx, int ty); |
|
153 virtual IntRect getClipRect(int tx, int ty); |
|
154 |
|
155 virtual void paintBoxDecorations(PaintInfo&, int tx, int ty); |
|
156 virtual void imageChanged(CachedImage*); |
|
157 |
|
158 protected: |
|
159 void paintBackground(GraphicsContext*, const Color&, const BackgroundLayer*, int clipY, int clipHeight, int tx, int ty, int width, int height); |
|
160 #if PLATFORM(MAC) |
|
161 void paintCustomHighlight(int tx, int ty, const AtomicString& type, bool behindText); |
|
162 #endif |
|
163 |
|
164 void calcAbsoluteHorizontal(); |
|
165 |
|
166 private: |
|
167 void paintRootBoxDecorations(PaintInfo&, int tx, int ty); |
|
168 |
|
169 void calculateBackgroundImageGeometry(const BackgroundLayer*, int tx, int ty, int w, int h, IntRect& destRect, IntPoint& phase, IntSize& tileSize); |
|
170 void paintBackgrounds(GraphicsContext*, const Color&, const BackgroundLayer*, int clipY, int clipHeight, int tx, int ty, int width, int height); |
|
171 |
|
172 int containingBlockWidthForPositioned(const RenderObject* containingBlock) const; |
|
173 int containingBlockHeightForPositioned(const RenderObject* containingBlock) const; |
|
174 |
|
175 void calcAbsoluteVertical(); |
|
176 void calcAbsoluteHorizontalValues(Length width, const RenderObject* cb, TextDirection containerDirection, |
|
177 int containerWidth, int bordersPlusPadding, |
|
178 Length left, Length right, Length marginLeft, Length marginRight, |
|
179 int& widthValue, int& marginLeftValue, int& marginRightValue, int& xPos); |
|
180 void calcAbsoluteVerticalValues(Length height, const RenderObject* cb, |
|
181 int containerHeight, int bordersPlusPadding, |
|
182 Length top, Length bottom, Length marginTop, Length marginBottom, |
|
183 int& heightValue, int& marginTopValue, int& marginBottomValue, int& yPos); |
|
184 |
|
185 void calcAbsoluteVerticalReplaced(); |
|
186 void calcAbsoluteHorizontalReplaced(); |
|
187 |
|
188 // This function calculates the minimum and maximum preferred widths for an object. |
|
189 // These values are used in shrink-to-fit layout systems. |
|
190 // These include tables, positioned objects, floats and flexible boxes. |
|
191 virtual void calcPrefWidths() = 0; |
|
192 |
|
193 protected: |
|
194 // The width/height of the contents + borders + padding. |
|
195 int m_width; |
|
196 int m_height; |
|
197 |
|
198 int m_x; |
|
199 int m_y; |
|
200 |
|
201 int m_marginLeft; |
|
202 int m_marginRight; |
|
203 int m_marginTop; |
|
204 int m_marginBottom; |
|
205 |
|
206 // The preferred width of the element if it were to break its lines at every possible opportunity. |
|
207 int m_minPrefWidth; |
|
208 |
|
209 // The preferred width of the element if it never breaks any lines at all. |
|
210 int m_maxPrefWidth; |
|
211 |
|
212 // A pointer to our layer if we have one. |
|
213 RenderLayer* m_layer; |
|
214 |
|
215 // For inline replaced elements, the inline box that owns us. |
|
216 InlineBox* m_inlineBoxWrapper; |
|
217 }; |
|
218 |
|
219 } // namespace WebCore |
|
220 |
|
221 #endif // RenderBox_h |