]>
Commit | Line | Data |
---|---|---|
a90939db JF |
1 | /* |
2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | |
3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) | |
4 | * Copyright (C) 2003, 2006, 2007, 2009 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 RenderBoxModelObject_h | |
24 | #define RenderBoxModelObject_h | |
25 | ||
26 | #include "RenderObject.h" | |
27 | ||
28 | namespace WebCore { | |
29 | ||
30 | // Values for vertical alignment. | |
31 | const int PositionTop = -0x7fffffff; | |
32 | const int PositionBottom = 0x7fffffff; | |
33 | const int PositionUndefined = 0x80000000; | |
34 | ||
35 | // This class is the base for all objects that adhere to the CSS box model as described | |
36 | // at http://www.w3.org/TR/CSS21/box.html | |
37 | ||
38 | class RenderBoxModelObject : public RenderObject { | |
39 | public: | |
40 | RenderBoxModelObject(Node*); | |
41 | virtual ~RenderBoxModelObject(); | |
42 | ||
43 | virtual void destroy(); | |
44 | ||
45 | int relativePositionOffsetX() const; | |
46 | int relativePositionOffsetY() const; | |
47 | IntSize relativePositionOffset() const { return IntSize(relativePositionOffsetX(), relativePositionOffsetY()); } | |
48 | ||
49 | // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow) | |
50 | // to return the remaining width on a given line (and the height of a single line). | |
51 | virtual int offsetLeft() const; | |
52 | virtual int offsetTop() const; | |
53 | virtual int offsetWidth() const = 0; | |
54 | virtual int offsetHeight() const = 0; | |
55 | ||
56 | virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle); | |
57 | virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); | |
58 | virtual void updateBoxModelInfoFromStyle(); | |
59 | ||
60 | bool hasSelfPaintingLayer() const; | |
61 | RenderLayer* layer() const { return m_layer; } | |
62 | virtual bool requiresLayer() const { return isRoot() || isPositioned() || isRelPositioned() || isTransparent() || hasOverflowClip() || hasTransform() || hasMask() || hasReflection(); } | |
63 | ||
64 | // This will work on inlines to return the bounding box of all of the lines' border boxes. | |
65 | virtual IntRect borderBoundingBox() const = 0; | |
66 | ||
67 | // Virtual since table cells override | |
68 | virtual int paddingTop(bool includeIntrinsicPadding = true) const; | |
69 | virtual int paddingBottom(bool includeIntrinsicPadding = true) const; | |
70 | virtual int paddingLeft(bool includeIntrinsicPadding = true) const; | |
71 | virtual int paddingRight(bool includeIntrinsicPadding = true) const; | |
72 | ||
73 | virtual int borderTop() const { return style()->borderTopWidth(); } | |
74 | virtual int borderBottom() const { return style()->borderBottomWidth(); } | |
75 | virtual int borderLeft() const { return style()->borderLeftWidth(); } | |
76 | virtual int borderRight() const { return style()->borderRightWidth(); } | |
77 | ||
78 | virtual int marginTop() const = 0; | |
79 | virtual int marginBottom() const = 0; | |
80 | virtual int marginLeft() const = 0; | |
81 | virtual int marginRight() const = 0; | |
82 | ||
83 | bool hasHorizontalBordersPaddingOrMargin() const { return hasHorizontalBordersOrPadding() || marginLeft() != 0 || marginRight() != 0; } | |
84 | bool hasHorizontalBordersOrPadding() const { return borderLeft() != 0 || borderRight() != 0 || paddingLeft() != 0 || paddingRight() != 0; } | |
85 | ||
86 | virtual int containingBlockWidthForContent() const; | |
87 | ||
88 | virtual void childBecameNonInline(RenderObject* /*child*/) { } | |
89 | ||
90 | void paintBorder(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, bool begin = true, bool end = true); | |
91 | bool paintNinePieceImage(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, const NinePieceImage&, CompositeOperator = CompositeSourceOver); | |
92 | void paintBoxShadow(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, bool begin = true, bool end = true); | |
93 | virtual void paintFillLayerExtended(const PaintInfo&, const Color&, const FillLayer*, int clipY, int clipHeight, | |
94 | int tx, int ty, int width, int height, InlineFlowBox* = 0, CompositeOperator = CompositeSourceOver); | |
95 | ||
96 | // The difference between this inline's baseline position and the line's baseline position. | |
97 | int verticalPosition(bool firstLine) const; | |
98 | ||
99 | protected: | |
100 | void calculateBackgroundImageGeometry(const FillLayer*, int tx, int ty, int w, int h, IntRect& destRect, IntPoint& phase, IntSize& tileSize); | |
101 | IntSize calculateBackgroundSize(const FillLayer*, int scaledWidth, int scaledHeight) const; | |
102 | ||
103 | private: | |
104 | virtual bool isBoxModelObject() const { return true; } | |
105 | friend class RenderView; | |
106 | ||
107 | RenderLayer* m_layer; | |
108 | ||
109 | // Used to store state between styleWillChange and styleDidChange | |
110 | static bool s_wasFloating; | |
111 | }; | |
112 | ||
113 | inline RenderBoxModelObject* toRenderBoxModelObject(RenderObject* o) | |
114 | { | |
115 | ASSERT(!o || o->isBoxModelObject()); | |
116 | return static_cast<RenderBoxModelObject*>(o); | |
117 | } | |
118 | ||
119 | inline const RenderBoxModelObject* toRenderBoxModelObject(const RenderObject* o) | |
120 | { | |
121 | ASSERT(!o || o->isBoxModelObject()); | |
122 | return static_cast<const RenderBoxModelObject*>(o); | |
123 | } | |
124 | ||
125 | // This will catch anyone doing an unnecessary cast. | |
126 | void toRenderBoxModelObject(const RenderBox*); | |
127 | ||
128 | } // namespace WebCore | |
129 | ||
130 | #endif // RenderBoxModelObject_h |