darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 24 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 25 | #ifndef RENDER_BOX_H |
| 26 | #define RENDER_BOX_H |
| 27 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 28 | #include "loader.h" |
| 29 | #include "RenderLayer.h" |
| 30 | |
| 31 | namespace WebCore { |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 32 | class CachedResource; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 33 | |
| 34 | enum WidthType { Width, MinWidth, MaxWidth }; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 35 | |
| 36 | class RenderBox : public RenderObject |
| 37 | { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 38 | public: |
eseidel | 4e52462 | 2006-05-31 17:25:30 +0000 | [diff] [blame] | 39 | RenderBox(Node*); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 40 | virtual ~RenderBox(); |
| 41 | |
eseidel | 4e52462 | 2006-05-31 17:25:30 +0000 | [diff] [blame] | 42 | virtual const char* renderName() const { return "RenderBox"; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 43 | |
eseidel | 4e52462 | 2006-05-31 17:25:30 +0000 | [diff] [blame] | 44 | virtual void setStyle(RenderStyle*); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 45 | 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 | |
adele | 8040761 | 2006-07-28 05:13:24 +0000 | [diff] [blame] | 91 | virtual void position(InlineBox*); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 92 | |
| 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; |
eseidel | 4e52462 | 2006-05-31 17:25:30 +0000 | [diff] [blame] | 99 | virtual void setInlineBoxWrapper(InlineBox*); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 100 | 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 | |
ddkilzer | e9da8db | 2006-06-24 15:09:21 +0000 | [diff] [blame] | 116 | bool stretchesToViewHeight() const { return style()->htmlHacks() && style()->height().isAuto() && |
| 117 | !isFloatingOrPositioned() && (isRoot() || isBody()); } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 118 | // 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. |
adele | bb66f95 | 2006-06-01 05:35:28 +0000 | [diff] [blame] | 120 | bool sizesToIntrinsicWidth(WidthType) const; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 121 | |
adele | bb66f95 | 2006-06-01 05:35:28 +0000 | [diff] [blame] | 122 | int calcWidthUsing(WidthType, int cw); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 123 | int calcHeightUsing(const Length& height); |
adele | c1116ca | 2006-06-01 05:28:13 +0000 | [diff] [blame] | 124 | int calcReplacedWidthUsing(Length width) const; |
| 125 | int calcReplacedHeightUsing(Length height) const; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 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& h) const; |
| 134 | |
| 135 | void calcVerticalMargins(); |
| 136 | |
antti | adff99d | 2006-06-13 23:19:33 +0000 | [diff] [blame] | 137 | int relativePositionOffsetX() const; |
| 138 | int relativePositionOffsetY() const; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 139 | |
| 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 | |
| 153 | protected: |
| 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); |
harrison | 8049a9c | 2006-07-11 02:02:11 +0000 | [diff] [blame] | 159 | #if PLATFORM(MAC) |
| 160 | void paintCustomHighlight(int tx, int ty, const AtomicString& type, bool behindText); |
| 161 | #endif |
| 162 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 163 | void outlineBox(GraphicsContext*, int _tx, int _ty, const char *color = "red"); |
| 164 | |
ddkilzer | fb5e6ee | 2006-06-04 22:41:35 +0000 | [diff] [blame] | 165 | int containingBlockWidthForPositioned(const RenderObject* containingBlock) const; |
| 166 | int containingBlockHeightForPositioned(const RenderObject* containingBlock) const; |
| 167 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 168 | void calcAbsoluteHorizontal(); |
| 169 | void calcAbsoluteVertical(); |
darin | aa85730 | 2006-05-18 16:53:35 +0000 | [diff] [blame] | 170 | void calcAbsoluteHorizontalValues(Length width, const RenderObject* cb, TextDirection containerDirection, |
ap | bcb495f | 2006-05-13 14:58:24 +0000 | [diff] [blame] | 171 | 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 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 182 | 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 | |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 224 | } //namespace |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 225 | |
| 226 | #endif |