blob: 4059c1e53873d04012784650cabe2d23485b7977 [file] [log] [blame]
darinb9481ed2006-03-20 02:57:59 +00001/*
2 * This file is part of the DOM implementation for KDE.
3 *
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * Copyright (C) 2003 Apple Computer, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 *
23 */
darin36d11362006-04-11 16:30:21 +000024
darinb9481ed2006-03-20 02:57:59 +000025#ifndef RENDER_BOX_H
26#define RENDER_BOX_H
27
darinb9481ed2006-03-20 02:57:59 +000028#include "loader.h"
29#include "RenderLayer.h"
30
31namespace WebCore {
darine775cf72006-07-09 22:48:56 +000032 class CachedResource;
darinb9481ed2006-03-20 02:57:59 +000033
34 enum WidthType { Width, MinWidth, MaxWidth };
darinb9481ed2006-03-20 02:57:59 +000035
36class RenderBox : public RenderObject
37{
darinb9481ed2006-03-20 02:57:59 +000038public:
eseidel4e524622006-05-31 17:25:30 +000039 RenderBox(Node*);
darinb9481ed2006-03-20 02:57:59 +000040 virtual ~RenderBox();
41
eseidel4e524622006-05-31 17:25:30 +000042 virtual const char* renderName() const { return "RenderBox"; }
darinb9481ed2006-03-20 02:57:59 +000043
eseidel4e524622006-05-31 17:25:30 +000044 virtual void setStyle(RenderStyle*);
darinb9481ed2006-03-20 02:57:59 +000045 virtual void paint(PaintInfo& i, int _tx, int _ty);
46 virtual bool nodeAtPoint(NodeInfo& i, int _x, int _y, int _tx, int _ty, HitTestAction hitTestAction);
47
48 virtual void destroy();
49
50 virtual int minWidth() const { return m_minWidth; }
51 virtual int maxWidth() const { return m_maxWidth; }
52
53 virtual int contentWidth() const;
54 virtual int contentHeight() const;
55
56 virtual int overrideSize() const { return m_overrideSize; }
57 virtual int overrideWidth() const;
58 virtual int overrideHeight() const;
59 virtual void setOverrideSize(int s) { m_overrideSize = s; }
60
61 virtual bool absolutePosition(int &xPos, int &yPos, bool f = false);
62
63 virtual void setPos( int xPos, int yPos );
64
65 virtual int xPos() const { return m_x; }
66 virtual int yPos() const { return m_y; }
67 virtual int width() const;
68 virtual int height() const;
69
70 virtual int marginTop() const { return m_marginTop; }
71 virtual int marginBottom() const { return m_marginBottom; }
72 virtual int marginLeft() const { return m_marginLeft; }
73 virtual int marginRight() const { return m_marginRight; }
74
75 virtual void setWidth( int width ) { m_width = width; }
76 virtual void setHeight( int height ) { m_height = height; }
77
78 virtual IntRect borderBox() const { return IntRect(0, -borderTopExtra(), width(), height() + borderTopExtra() + borderBottomExtra()); }
79
80 int calcBorderBoxWidth(int w) const;
81 int calcBorderBoxHeight(int h) const;
82 int calcContentBoxWidth(int w) const;
83 int calcContentBoxHeight(int h) const;
84
85 // This method is now public so that centered objects like tables that are
86 // shifted right by left-aligned floats can recompute their left and
87 // right margins (so that they can remain centered after being
88 // shifted. -dwh
89 void calcHorizontalMargins(const Length& ml, const Length& mr, int cw);
90
adele80407612006-07-28 05:13:24 +000091 virtual void position(InlineBox*);
darinb9481ed2006-03-20 02:57:59 +000092
93 virtual void dirtyLineBoxes(bool fullLayout, bool isRootLineBox=false);
94
95 // For inline replaced elements, this function returns the inline box that owns us. Enables
96 // the replaced RenderObject to quickly determine what line it is contained on and to easily
97 // iterate over structures on the line.
98 virtual InlineBox* inlineBoxWrapper() const;
eseidel4e524622006-05-31 17:25:30 +000099 virtual void setInlineBoxWrapper(InlineBox*);
darinb9481ed2006-03-20 02:57:59 +0000100 virtual void deleteLineBoxWrapper();
101
102 virtual int lowestPosition(bool includeOverflowInterior=true, bool includeSelf=true) const;
103 virtual int rightmostPosition(bool includeOverflowInterior=true, bool includeSelf=true) const;
104 virtual int leftmostPosition(bool includeOverflowInterior=true, bool includeSelf=true) const;
105
106 virtual IntRect getAbsoluteRepaintRect();
107 virtual void computeAbsoluteRepaintRect(IntRect& r, bool f=false);
108
109 virtual void repaintDuringLayoutIfMoved(int oldX, int oldY);
110
111 virtual int containingBlockWidth() const;
112
113 virtual void calcWidth();
114 virtual void calcHeight();
115
ddkilzere9da8db2006-06-24 15:09:21 +0000116 bool stretchesToViewHeight() const { return style()->htmlHacks() && style()->height().isAuto() &&
117 !isFloatingOrPositioned() && (isRoot() || isBody()); }
darinb9481ed2006-03-20 02:57:59 +0000118 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
119 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
adelebb66f952006-06-01 05:35:28 +0000120 bool sizesToIntrinsicWidth(WidthType) const;
darinb9481ed2006-03-20 02:57:59 +0000121
adelebb66f952006-06-01 05:35:28 +0000122 int calcWidthUsing(WidthType, int cw);
darinb9481ed2006-03-20 02:57:59 +0000123 int calcHeightUsing(const Length& height);
adelec1116ca2006-06-01 05:28:13 +0000124 int calcReplacedWidthUsing(Length width) const;
125 int calcReplacedHeightUsing(Length height) const;
darinb9481ed2006-03-20 02:57:59 +0000126
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& h) const;
134
135 void calcVerticalMargins();
136
anttiadff99d2006-06-13 23:19:33 +0000137 int relativePositionOffsetX() const;
138 int relativePositionOffsetY() const;
darinb9481ed2006-03-20 02:57:59 +0000139
140 virtual RenderLayer* layer() const { return m_layer; }
141
142 virtual IntRect caretRect(int offset, EAffinity affinity = UPSTREAM, int *extraWidthToEndOfLine = 0);
143
144 virtual void paintBackgroundExtended(GraphicsContext*, const Color& c, const BackgroundLayer* bgLayer, int clipy, int cliph,
145 int _tx, int _ty, int w, int height,
146 int bleft, int bright, int pleft, int pright);
147
148 virtual void setStaticX(int staticX);
149 virtual void setStaticY(int staticY);
150 virtual int staticX() const { return m_staticX; }
151 virtual int staticY() const { return m_staticY; }
152
153protected:
154 virtual void paintBoxDecorations(PaintInfo& i, int _tx, int _ty);
155 void paintRootBoxDecorations(PaintInfo& i, int _tx, int _ty);
156
157 void paintBackgrounds(GraphicsContext*, const Color&, const BackgroundLayer*, int clipy, int cliph, int _tx, int _ty, int w, int h);
158 void paintBackground(GraphicsContext*, const Color&, const BackgroundLayer*, int clipy, int cliph, int _tx, int _ty, int w, int h);
harrison8049a9c2006-07-11 02:02:11 +0000159#if PLATFORM(MAC)
160 void paintCustomHighlight(int tx, int ty, const AtomicString& type, bool behindText);
161#endif
162
darinb9481ed2006-03-20 02:57:59 +0000163 void outlineBox(GraphicsContext*, int _tx, int _ty, const char *color = "red");
164
ddkilzerfb5e6ee2006-06-04 22:41:35 +0000165 int containingBlockWidthForPositioned(const RenderObject* containingBlock) const;
166 int containingBlockHeightForPositioned(const RenderObject* containingBlock) const;
167
darinb9481ed2006-03-20 02:57:59 +0000168 void calcAbsoluteHorizontal();
169 void calcAbsoluteVertical();
darinaa857302006-05-18 16:53:35 +0000170 void calcAbsoluteHorizontalValues(Length width, const RenderObject* cb, TextDirection containerDirection,
apbcb495f2006-05-13 14:58:24 +0000171 const int containerWidth, const int bordersPlusPadding,
172 const Length left, const Length right, const Length marginLeft, const Length marginRight,
173 int& widthValue, int& marginLeftValue, int& marginRightValue, int& xPos);
174 void calcAbsoluteVerticalValues(Length height, const RenderObject* cb,
175 const int containerHeight, const int bordersPlusPadding,
176 const Length top, const Length bottom, const Length marginTop, const Length marginBottom,
177 int& heightValue, int& marginTopValue, int& marginBottomValue, int& yPos);
178
179 void calcAbsoluteVerticalReplaced();
180 void calcAbsoluteHorizontalReplaced();
181
darinb9481ed2006-03-20 02:57:59 +0000182 virtual IntRect getOverflowClipRect(int tx, int ty);
183 virtual IntRect getClipRect(int tx, int ty);
184
185 // the actual height of the contents + borders + padding
186 int m_height;
187
188 int m_y;
189
190 int m_x;
191 int m_width;
192
193 int m_marginTop;
194 int m_marginBottom;
195
196 int m_marginLeft;
197 int m_marginRight;
198
199 /*
200 * the minimum width the element needs, to be able to render
201 * it's content without clipping
202 */
203 int m_minWidth;
204 /* The maximum width the element can fill horizontally
205 * ( = the width of the element with line breaking disabled)
206 */
207 int m_maxWidth;
208
209 // Used by flexible boxes when flexing this element.
210 int m_overrideSize;
211
212 // Cached normal flow values for absolute positioned elements with static left/top values.
213 int m_staticX;
214 int m_staticY;
215
216 // A pointer to our layer if we have one. Currently only positioned elements
217 // and floaters have layers.
218 RenderLayer* m_layer;
219
220 // For inline replaced elements, the inline box that owns us.
221 InlineBox* m_inlineBoxWrapper;
222};
223
darin36d11362006-04-11 16:30:21 +0000224} //namespace
darinb9481ed2006-03-20 02:57:59 +0000225
226#endif