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.
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.
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.
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.
24 #ifndef RenderBoxModelObject_h
25 #define RenderBoxModelObject_h
27 #include "RenderObject.h"
28 #include "ShadowData.h"
32 // Modes for some of the line-related functions.
33 enum LinePositionMode { PositionOnContainingLine, PositionOfInteriorLineBoxes };
34 enum LineDirectionMode { HorizontalLine, VerticalLine };
35 typedef unsigned BorderEdgeFlags;
37 enum BackgroundBleedAvoidance {
39 BackgroundBleedShrinkBackground,
40 BackgroundBleedUseTransparencyLayer
43 enum ContentChangeType {
54 // This class is the base for all objects that adhere to the CSS box model as described
55 // at http://www.w3.org/TR/CSS21/box.html
57 class RenderBoxModelObject : public RenderObject {
59 RenderBoxModelObject(Node*);
60 virtual ~RenderBoxModelObject();
62 LayoutSize relativePositionOffset() const;
63 LayoutSize relativePositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? relativePositionOffset() : relativePositionOffset().transposedSize(); }
65 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
66 // to return the remaining width on a given line (and the height of a single line).
67 virtual LayoutUnit offsetLeft() const;
68 virtual LayoutUnit offsetTop() const;
69 virtual LayoutUnit offsetWidth() const = 0;
70 virtual LayoutUnit offsetHeight() const = 0;
72 int pixelSnappedOffsetLeft() const { return roundToInt(offsetLeft()); }
73 int pixelSnappedOffsetTop() const { return roundToInt(offsetTop()); }
74 int pixelSnappedOffsetWidth() const;
75 int pixelSnappedOffsetHeight() const;
77 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
78 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
79 virtual void updateBoxModelInfoFromStyle();
81 bool hasSelfPaintingLayer() const;
82 RenderLayer* layer() const { return m_layer; }
84 virtual bool requiresLayer() const { return isRoot() || isOutOfFlowPositioned() || isRelPositioned() || isTransparent() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasMask() || hasReflection() || hasFilter() || style()->specifiesColumns(); }
86 // This will work on inlines to return the bounding box of all of the lines' border boxes.
87 virtual IntRect borderBoundingBox() const = 0;
89 // These return the CSS computed padding values.
90 LayoutUnit computedCSSPaddingTop() const;
91 LayoutUnit computedCSSPaddingBottom() const;
92 LayoutUnit computedCSSPaddingLeft() const;
93 LayoutUnit computedCSSPaddingRight() const;
94 LayoutUnit computedCSSPaddingBefore() const;
95 LayoutUnit computedCSSPaddingAfter() const;
96 LayoutUnit computedCSSPaddingStart() const;
97 LayoutUnit computedCSSPaddingEnd() const;
99 // These functions are used during layout. Table cells and the MathML
100 // code override them to include some extra intrinsic padding.
101 virtual LayoutUnit paddingTop() const { return computedCSSPaddingTop(); }
102 virtual LayoutUnit paddingBottom() const { return computedCSSPaddingBottom(); }
103 virtual LayoutUnit paddingLeft() const { return computedCSSPaddingLeft(); }
104 virtual LayoutUnit paddingRight() const { return computedCSSPaddingRight(); }
105 virtual LayoutUnit paddingBefore() const { return computedCSSPaddingBefore(); }
106 virtual LayoutUnit paddingAfter() const { return computedCSSPaddingAfter(); }
107 virtual LayoutUnit paddingStart() const { return computedCSSPaddingStart(); }
108 virtual LayoutUnit paddingEnd() const { return computedCSSPaddingEnd(); }
110 virtual int borderTop() const { return style()->borderTopWidth(); }
111 virtual int borderBottom() const { return style()->borderBottomWidth(); }
112 virtual int borderLeft() const { return style()->borderLeftWidth(); }
113 virtual int borderRight() const { return style()->borderRightWidth(); }
114 virtual int borderBefore() const { return style()->borderBeforeWidth(); }
115 virtual int borderAfter() const { return style()->borderAfterWidth(); }
116 virtual int borderStart() const { return style()->borderStartWidth(); }
117 virtual int borderEnd() const { return style()->borderEndWidth(); }
119 LayoutUnit borderAndPaddingHeight() const { return borderTop() + borderBottom() + paddingTop() + paddingBottom(); }
120 LayoutUnit borderAndPaddingWidth() const { return borderLeft() + borderRight() + paddingLeft() + paddingRight(); }
121 LayoutUnit borderAndPaddingLogicalHeight() const { return borderBefore() + borderAfter() + paddingBefore() + paddingAfter(); }
122 LayoutUnit borderAndPaddingLogicalWidth() const { return borderStart() + borderEnd() + paddingStart() + paddingEnd(); }
123 LayoutUnit borderAndPaddingLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
125 LayoutUnit borderAndPaddingStart() const { return borderStart() + paddingStart(); }
126 LayoutUnit borderLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() : borderTop(); }
127 LayoutUnit borderLogicalRight() const { return style()->isHorizontalWritingMode() ? borderRight() : borderBottom(); }
129 virtual LayoutUnit marginTop() const = 0;
130 virtual LayoutUnit marginBottom() const = 0;
131 virtual LayoutUnit marginLeft() const = 0;
132 virtual LayoutUnit marginRight() const = 0;
133 virtual LayoutUnit marginBefore(const RenderStyle* otherStyle = 0) const = 0;
134 virtual LayoutUnit marginAfter(const RenderStyle* otherStyle = 0) const = 0;
135 virtual LayoutUnit marginStart(const RenderStyle* otherStyle = 0) const = 0;
136 virtual LayoutUnit marginEnd(const RenderStyle* otherStyle = 0) const = 0;
137 LayoutUnit marginHeight() const { return marginTop() + marginBottom(); }
138 LayoutUnit marginWidth() const { return marginLeft() + marginRight(); }
140 bool hasInlineDirectionBordersPaddingOrMargin() const { return hasInlineDirectionBordersOrPadding() || marginStart()|| marginEnd(); }
141 bool hasInlineDirectionBordersOrPadding() const { return borderStart() || borderEnd() || paddingStart()|| paddingEnd(); }
143 virtual LayoutUnit containingBlockLogicalWidthForContent() const;
145 virtual void childBecameNonInline(RenderObject* /*child*/) { }
147 void paintBorder(const PaintInfo&, const LayoutRect&, const RenderStyle*, BackgroundBleedAvoidance = BackgroundBleedNone, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true);
148 bool paintNinePieceImage(GraphicsContext*, const LayoutRect&, const RenderStyle*, const NinePieceImage&, CompositeOperator = CompositeSourceOver);
149 void paintBoxShadow(const PaintInfo&, const LayoutRect&, const RenderStyle*, ShadowStyle, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true);
150 void paintFillLayerExtended(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, InlineFlowBox* = 0, const LayoutSize& = LayoutSize(), CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
152 virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox* = 0) const;
154 // Overridden by subclasses to determine line height and baseline position.
155 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
156 virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
158 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const OVERRIDE;
160 // Called by RenderObject::willBeDestroyed() and is the only way layers should ever be destroyed
163 void highQualityRepaintTimerFired(Timer<RenderBoxModelObject>*);
165 virtual void setSelectionState(SelectionState s);
167 #if USE(ACCELERATED_COMPOSITING)
168 void contentChanged(ContentChangeType);
169 bool hasAcceleratedCompositing() const;
171 bool startTransition(double, CSSPropertyID, const RenderStyle* fromStyle, const RenderStyle* toStyle);
172 void transitionPaused(double timeOffset, CSSPropertyID);
173 void transitionFinished(CSSPropertyID);
175 bool startAnimation(double timeOffset, const Animation*, const KeyframeList& keyframes);
176 void animationPaused(double timeOffset, const String& name);
177 void animationFinished(const String& name);
179 void suspendAnimations(double time = 0);
183 virtual void willBeDestroyed();
185 class BackgroundImageGeometry {
187 IntPoint destOrigin() const { return m_destOrigin; }
188 void setDestOrigin(const IntPoint& destOrigin)
190 m_destOrigin = destOrigin;
193 IntRect destRect() const { return m_destRect; }
194 void setDestRect(const IntRect& destRect)
196 m_destRect = destRect;
199 // Returns the phase relative to the destination rectangle.
200 IntPoint relativePhase() const;
202 IntPoint phase() const { return m_phase; }
203 void setPhase(const IntPoint& phase)
208 IntSize tileSize() const { return m_tileSize; }
209 void setTileSize(const IntSize& tileSize)
211 m_tileSize = tileSize;
214 void setPhaseX(int x) { m_phase.setX(x); }
215 void setPhaseY(int y) { m_phase.setY(y); }
217 void setNoRepeatX(int xOffset);
218 void setNoRepeatY(int yOffset);
220 void useFixedAttachment(const IntPoint& attachmentPoint);
222 void clip(const IntRect&);
225 IntPoint m_destOrigin;
230 LayoutPoint adjustedPositionRelativeToOffsetParent(const LayoutPoint&) const;
232 void calculateBackgroundImageGeometry(const FillLayer*, const LayoutRect& paintRect, BackgroundImageGeometry&);
233 void getBorderEdgeInfo(class BorderEdge[], const RenderStyle*, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true) const;
234 bool borderObscuresBackgroundEdge(const FloatSize& contextScale) const;
235 bool borderObscuresBackground() const;
237 bool shouldPaintAtLowQuality(GraphicsContext*, Image*, const void*, const LayoutSize&);
239 RenderBoxModelObject* continuation() const;
240 void setContinuation(RenderBoxModelObject*);
242 LayoutRect localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset);
244 static bool shouldAntialiasLines(GraphicsContext*);
247 // For RenderBlocks and RenderInlines with m_style->styleType() == FIRST_LETTER, this tracks their remaining text fragments
248 RenderObject* firstLetterRemainingText() const;
249 void setFirstLetterRemainingText(RenderObject*);
251 // These functions are only used internally to manipulate the render tree structure via remove/insert/appendChildNode.
252 // Since they are typically called only to move objects around within anonymous blocks (which only have layers in
253 // the case of column spans), the default for fullRemoveInsert is false rather than true.
254 void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, bool fullRemoveInsert = false);
255 void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, bool fullRemoveInsert = false)
257 moveChildTo(toBoxModelObject, child, 0, fullRemoveInsert);
259 void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, bool fullRemoveInsert = false)
261 moveAllChildrenTo(toBoxModelObject, 0, fullRemoveInsert);
263 void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* beforeChild, bool fullRemoveInsert = false)
265 moveChildrenTo(toBoxModelObject, firstChild(), 0, beforeChild, fullRemoveInsert);
267 // Move all of the kids from |startChild| up to but excluding |endChild|. 0 can be passed as the |endChild| to denote
268 // that all the kids from |startChild| onwards should be moved.
269 void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, bool fullRemoveInsert = false)
271 moveChildrenTo(toBoxModelObject, startChild, endChild, 0, fullRemoveInsert);
273 void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, bool fullRemoveInsert = false);
276 virtual bool isBoxModelObject() const { return true; }
278 IntSize calculateFillTileSize(const FillLayer*, const IntSize& scaledPositioningAreaSize) const;
280 enum ScaleByEffectiveZoomOrNot { ScaleByEffectiveZoom, DoNotScaleByEffectiveZoom };
281 IntSize calculateImageIntrinsicDimensions(StyleImage*, const IntSize& scaledPositioningAreaSize, ScaleByEffectiveZoomOrNot) const;
283 RoundedRect getBackgroundRoundedRect(const LayoutRect&, InlineFlowBox*, LayoutUnit inlineBoxWidth, LayoutUnit inlineBoxHeight,
284 bool includeLogicalLeftEdge, bool includeLogicalRightEdge);
286 void clipBorderSidePolygon(GraphicsContext*, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
287 BoxSide, bool firstEdgeMatches, bool secondEdgeMatches);
288 void clipBorderSideForComplexInnerPath(GraphicsContext*, const RoundedRect&, const RoundedRect&, BoxSide, const class BorderEdge[]);
289 void paintOneBorderSide(GraphicsContext*, const RenderStyle*, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
290 const IntRect& sideRect, BoxSide, BoxSide adjacentSide1, BoxSide adjacentSide2, const class BorderEdge[],
291 const Path*, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor = 0);
292 void paintTranslucentBorderSides(GraphicsContext*, const RenderStyle*, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
293 const class BorderEdge[], BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias = false);
294 void paintBorderSides(GraphicsContext*, const RenderStyle*, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
295 const class BorderEdge[], BorderEdgeFlags, BackgroundBleedAvoidance,
296 bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias = false, const Color* overrideColor = 0);
297 void drawBoxSideFromPath(GraphicsContext*, const LayoutRect&, const Path&, const class BorderEdge[],
298 float thickness, float drawThickness, BoxSide, const RenderStyle*,
299 Color, EBorderStyle, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge);
301 friend class RenderView;
303 RenderLayer* m_layer;
305 // Used to store state between styleWillChange and styleDidChange
306 static bool s_wasFloating;
307 static bool s_hadLayer;
308 static bool s_hadTransform;
309 static bool s_layerWasSelfPainting;
312 inline RenderBoxModelObject* toRenderBoxModelObject(RenderObject* object)
314 ASSERT(!object || object->isBoxModelObject());
315 return static_cast<RenderBoxModelObject*>(object);
318 inline const RenderBoxModelObject* toRenderBoxModelObject(const RenderObject* object)
320 ASSERT(!object || object->isBoxModelObject());
321 return static_cast<const RenderBoxModelObject*>(object);
324 // This will catch anyone doing an unnecessary cast.
325 void toRenderBoxModelObject(const RenderBoxModelObject*);
327 } // namespace WebCore
329 #endif // RenderBoxModelObject_h