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 * Copyright (C) 2010 Google Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24 #ifndef RenderBoxModelObject_h
25 #define RenderBoxModelObject_h
26
27 #include "RenderObject.h"
28 #include "ShadowData.h"
29
30 namespace WebCore {
31
32 // Modes for some of the line-related functions.
33 enum LinePositionMode { PositionOnContainingLine, PositionOfInteriorLineBoxes };
34 enum LineDirectionMode { HorizontalLine, VerticalLine };
35 typedef unsigned BorderEdgeFlags;
36
37 // This class is the base for all objects that adhere to the CSS box model as described
38 // at http://www.w3.org/TR/CSS21/box.html
39
40 class RenderBoxModelObject : public RenderObject {
41 public:
42 RenderBoxModelObject(Node*);
43 virtual ~RenderBoxModelObject();
44
45 virtual void destroy();
46
47 int relativePositionOffsetX() const;
48 int relativePositionOffsetY() const;
relativePositionOffset()49 IntSize relativePositionOffset() const { return IntSize(relativePositionOffsetX(), relativePositionOffsetY()); }
relativePositionLogicalOffset()50 IntSize relativePositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? relativePositionOffset() : relativePositionOffset().transposedSize(); }
51
52 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
53 // to return the remaining width on a given line (and the height of a single line).
54 virtual int offsetLeft() const;
55 virtual int offsetTop() const;
56 virtual int offsetWidth() const = 0;
57 virtual int offsetHeight() const = 0;
58
59 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
60 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
61 virtual void updateBoxModelInfoFromStyle();
62
63 bool hasSelfPaintingLayer() const;
layer()64 RenderLayer* layer() const { return m_layer; }
requiresLayer()65 virtual bool requiresLayer() const { return isRoot() || isPositioned() || isRelPositioned() || isTransparent() || hasOverflowClip() || hasTransform() || hasMask() || hasReflection() || style()->specifiesColumns(); }
66
67 // This will work on inlines to return the bounding box of all of the lines' border boxes.
68 virtual IntRect borderBoundingBox() const = 0;
69
70 // Virtual since table cells override
71 virtual int paddingTop(bool includeIntrinsicPadding = true) const;
72 virtual int paddingBottom(bool includeIntrinsicPadding = true) const;
73 virtual int paddingLeft(bool includeIntrinsicPadding = true) const;
74 virtual int paddingRight(bool includeIntrinsicPadding = true) const;
75 virtual int paddingBefore(bool includeIntrinsicPadding = true) const;
76 virtual int paddingAfter(bool includeIntrinsicPadding = true) const;
77 virtual int paddingStart(bool includeIntrinsicPadding = true) const;
78 virtual int paddingEnd(bool includeIntrinsicPadding = true) const;
79
borderTop()80 virtual int borderTop() const { return style()->borderTopWidth(); }
borderBottom()81 virtual int borderBottom() const { return style()->borderBottomWidth(); }
borderLeft()82 virtual int borderLeft() const { return style()->borderLeftWidth(); }
borderRight()83 virtual int borderRight() const { return style()->borderRightWidth(); }
borderBefore()84 virtual int borderBefore() const { return style()->borderBeforeWidth(); }
borderAfter()85 virtual int borderAfter() const { return style()->borderAfterWidth(); }
borderStart()86 virtual int borderStart() const { return style()->borderStartWidth(); }
borderEnd()87 virtual int borderEnd() const { return style()->borderEndWidth(); }
88
borderAndPaddingHeight()89 int borderAndPaddingHeight() const { return borderTop() + borderBottom() + paddingTop() + paddingBottom(); }
borderAndPaddingWidth()90 int borderAndPaddingWidth() const { return borderLeft() + borderRight() + paddingLeft() + paddingRight(); }
borderAndPaddingLogicalHeight()91 int borderAndPaddingLogicalHeight() const { return borderBefore() + borderAfter() + paddingBefore() + paddingAfter(); }
borderAndPaddingLogicalWidth()92 int borderAndPaddingLogicalWidth() const { return borderStart() + borderEnd() + paddingStart() + paddingEnd(); }
borderAndPaddingLogicalLeft()93 int borderAndPaddingLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
94
borderAndPaddingStart()95 int borderAndPaddingStart() const { return borderStart() + paddingStart(); }
borderLogicalLeft()96 int borderLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() : borderTop(); }
borderLogicalRight()97 int borderLogicalRight() const { return style()->isHorizontalWritingMode() ? borderRight() : borderBottom(); }
98
99 virtual int marginTop() const = 0;
100 virtual int marginBottom() const = 0;
101 virtual int marginLeft() const = 0;
102 virtual int marginRight() const = 0;
103 virtual int marginBefore() const = 0;
104 virtual int marginAfter() const = 0;
105 virtual int marginStart() const = 0;
106 virtual int marginEnd() const = 0;
107
hasInlineDirectionBordersPaddingOrMargin()108 bool hasInlineDirectionBordersPaddingOrMargin() const { return hasInlineDirectionBordersOrPadding() || marginStart()|| marginEnd(); }
hasInlineDirectionBordersOrPadding()109 bool hasInlineDirectionBordersOrPadding() const { return borderStart() || borderEnd() || paddingStart()|| paddingEnd(); }
110
111 virtual int containingBlockLogicalWidthForContent() const;
112
childBecameNonInline(RenderObject *)113 virtual void childBecameNonInline(RenderObject* /*child*/) { }
114
115 void paintBorder(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true);
116 bool paintNinePieceImage(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, const NinePieceImage&, CompositeOperator = CompositeSourceOver);
117 void paintBoxShadow(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, ShadowStyle, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true);
118 void paintFillLayerExtended(const PaintInfo&, const Color&, const FillLayer*, int tx, int ty, int width, int height, InlineFlowBox* = 0, int inlineBoxWidth = 0, int inlineBoxHeight = 0, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
119
120 // Overridden by subclasses to determine line height and baseline position.
121 virtual int lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
122 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
123
124 // Called by RenderObject::destroy() (and RenderWidget::destroy()) and is the only way layers should ever be destroyed
125 void destroyLayer();
126
127 void highQualityRepaintTimerFired(Timer<RenderBoxModelObject>*);
128
129 virtual void setSelectionState(SelectionState s);
130 protected:
131 void calculateBackgroundImageGeometry(const FillLayer*, int tx, int ty, int w, int h, IntRect& destRect, IntPoint& phase, IntSize& tileSize);
132
133 bool shouldPaintAtLowQuality(GraphicsContext*, Image*, const void*, const IntSize&);
134
135 RenderBoxModelObject* continuation() const;
136 void setContinuation(RenderBoxModelObject*);
137
138 private:
isBoxModelObject()139 virtual bool isBoxModelObject() const { return true; }
140
141 IntSize calculateFillTileSize(const FillLayer*, IntSize scaledSize) const;
142
143 RoundedIntRect getBackgroundRoundedRect(const IntRect&, InlineFlowBox*, int inlineBoxWidth, int inlineBoxHeight,
144 bool includeLogicalLeftEdge, bool includeLogicalRightEdge);
145
146 void clipBorderSidePolygon(GraphicsContext*, const RoundedIntRect& outerBorder, const RoundedIntRect& innerBorder,
147 BoxSide, bool firstEdgeMatches, bool secondEdgeMatches);
148 void paintOneBorderSide(GraphicsContext*, const RenderStyle*, const RoundedIntRect& outerBorder, const RoundedIntRect& innerBorder,
149 const IntRect& sideRect, BoxSide, BoxSide adjacentSide1, BoxSide adjacentSide2, const class BorderEdge[],
150 const Path*, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor = 0);
151 void paintTranslucentBorderSides(GraphicsContext*, const RenderStyle*, const RoundedIntRect& outerBorder, const RoundedIntRect& innerBorder,
152 const class BorderEdge[], bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias = false);
153 void paintBorderSides(GraphicsContext*, const RenderStyle*, const RoundedIntRect& outerBorder, const RoundedIntRect& innerBorder,
154 const class BorderEdge[], BorderEdgeFlags, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias = false, const Color* overrideColor = 0);
155 void drawBoxSideFromPath(GraphicsContext*, const IntRect&, const Path&, const class BorderEdge[],
156 float thickness, float drawThickness, BoxSide, const RenderStyle*,
157 Color, EBorderStyle, bool includeLogicalLeftEdge, bool includeLogicalRightEdge);
158
159 friend class RenderView;
160
161 RenderLayer* m_layer;
162
163 // Used to store state between styleWillChange and styleDidChange
164 static bool s_wasFloating;
165 static bool s_hadLayer;
166 static bool s_layerWasSelfPainting;
167 };
168
toRenderBoxModelObject(RenderObject * object)169 inline RenderBoxModelObject* toRenderBoxModelObject(RenderObject* object)
170 {
171 ASSERT(!object || object->isBoxModelObject());
172 return static_cast<RenderBoxModelObject*>(object);
173 }
174
toRenderBoxModelObject(const RenderObject * object)175 inline const RenderBoxModelObject* toRenderBoxModelObject(const RenderObject* object)
176 {
177 ASSERT(!object || object->isBoxModelObject());
178 return static_cast<const RenderBoxModelObject*>(object);
179 }
180
181 // This will catch anyone doing an unnecessary cast.
182 void toRenderBoxModelObject(const RenderBoxModelObject*);
183
184 } // namespace WebCore
185
186 #endif // RenderBoxModelObject_h
187