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 "core/rendering/RenderLayerModelObject.h"
28 #include "core/rendering/style/ShadowData.h"
29 #include "platform/geometry/LayoutRect.h"
33 // Modes for some of the line-related functions.
34 enum LinePositionMode { PositionOnContainingLine, PositionOfInteriorLineBoxes };
35 enum LineDirectionMode { HorizontalLine, VerticalLine };
36 typedef unsigned BorderEdgeFlags;
38 enum BackgroundBleedAvoidance {
40 BackgroundBleedShrinkBackground,
41 BackgroundBleedUseTransparencyLayer,
42 BackgroundBleedBackgroundOverBorder
45 enum ContentChangeType {
55 class RenderTextFragment;
56 class StickyPositionViewportConstraints;
58 // This class is the base for all objects that adhere to the CSS box model as described
59 // at http://www.w3.org/TR/CSS21/box.html
61 class RenderBoxModelObject : public RenderLayerModelObject {
63 RenderBoxModelObject(ContainerNode*);
64 virtual ~RenderBoxModelObject();
66 LayoutSize relativePositionOffset() const;
67 LayoutSize relativePositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? relativePositionOffset() : relativePositionOffset().transposedSize(); }
69 void computeStickyPositionConstraints(StickyPositionViewportConstraints&, const FloatRect& constrainingRect) const;
70 LayoutSize stickyPositionOffset() const;
71 LayoutSize stickyPositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? stickyPositionOffset() : stickyPositionOffset().transposedSize(); }
73 LayoutSize offsetForInFlowPosition() const;
75 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
76 // to return the remaining width on a given line (and the height of a single line).
77 virtual LayoutUnit offsetLeft() const;
78 virtual LayoutUnit offsetTop() const;
79 virtual LayoutUnit offsetWidth() const = 0;
80 virtual LayoutUnit offsetHeight() const = 0;
82 int pixelSnappedOffsetLeft() const { return roundToInt(offsetLeft()); }
83 int pixelSnappedOffsetTop() const { return roundToInt(offsetTop()); }
84 virtual int pixelSnappedOffsetWidth() const;
85 virtual int pixelSnappedOffsetHeight() const;
87 virtual void updateFromStyle() OVERRIDE;
89 virtual LayerType layerTypeRequired() const OVERRIDE
91 if (isRoot() || isPositioned() || createsGroup() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns())
97 // This will work on inlines to return the bounding box of all of the lines' border boxes.
98 virtual IntRect borderBoundingBox() const = 0;
100 // These return the CSS computed padding values.
101 LayoutUnit computedCSSPaddingTop() const { return computedCSSPadding(style()->paddingTop()); }
102 LayoutUnit computedCSSPaddingBottom() const { return computedCSSPadding(style()->paddingBottom()); }
103 LayoutUnit computedCSSPaddingLeft() const { return computedCSSPadding(style()->paddingLeft()); }
104 LayoutUnit computedCSSPaddingRight() const { return computedCSSPadding(style()->paddingRight()); }
105 LayoutUnit computedCSSPaddingBefore() const { return computedCSSPadding(style()->paddingBefore()); }
106 LayoutUnit computedCSSPaddingAfter() const { return computedCSSPadding(style()->paddingAfter()); }
107 LayoutUnit computedCSSPaddingStart() const { return computedCSSPadding(style()->paddingStart()); }
108 LayoutUnit computedCSSPaddingEnd() const { return computedCSSPadding(style()->paddingEnd()); }
110 // These functions are used during layout. Table cells
111 // override them to include some extra intrinsic padding.
112 virtual LayoutUnit paddingTop() const { return computedCSSPaddingTop(); }
113 virtual LayoutUnit paddingBottom() const { return computedCSSPaddingBottom(); }
114 virtual LayoutUnit paddingLeft() const { return computedCSSPaddingLeft(); }
115 virtual LayoutUnit paddingRight() const { return computedCSSPaddingRight(); }
116 virtual LayoutUnit paddingBefore() const { return computedCSSPaddingBefore(); }
117 virtual LayoutUnit paddingAfter() const { return computedCSSPaddingAfter(); }
118 virtual LayoutUnit paddingStart() const { return computedCSSPaddingStart(); }
119 virtual LayoutUnit paddingEnd() const { return computedCSSPaddingEnd(); }
121 virtual int borderTop() const { return style()->borderTopWidth(); }
122 virtual int borderBottom() const { return style()->borderBottomWidth(); }
123 virtual int borderLeft() const { return style()->borderLeftWidth(); }
124 virtual int borderRight() const { return style()->borderRightWidth(); }
125 virtual int borderBefore() const { return style()->borderBeforeWidth(); }
126 virtual int borderAfter() const { return style()->borderAfterWidth(); }
127 virtual int borderStart() const { return style()->borderStartWidth(); }
128 virtual int borderEnd() const { return style()->borderEndWidth(); }
130 LayoutUnit borderAndPaddingStart() const { return borderStart() + paddingStart(); }
131 LayoutUnit borderAndPaddingBefore() const { return borderBefore() + paddingBefore(); }
132 LayoutUnit borderAndPaddingAfter() const { return borderAfter() + paddingAfter(); }
134 LayoutUnit borderAndPaddingHeight() const { return borderTop() + borderBottom() + paddingTop() + paddingBottom(); }
135 LayoutUnit borderAndPaddingWidth() const { return borderLeft() + borderRight() + paddingLeft() + paddingRight(); }
136 LayoutUnit borderAndPaddingLogicalHeight() const { return borderAndPaddingBefore() + borderAndPaddingAfter(); }
137 LayoutUnit borderAndPaddingLogicalWidth() const { return borderStart() + borderEnd() + paddingStart() + paddingEnd(); }
138 LayoutUnit borderAndPaddingLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
141 LayoutUnit borderLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() : borderTop(); }
142 LayoutUnit borderLogicalRight() const { return style()->isHorizontalWritingMode() ? borderRight() : borderBottom(); }
143 LayoutUnit borderLogicalWidth() const { return borderStart() + borderEnd(); }
144 LayoutUnit borderLogicalHeight() const { return borderBefore() + borderAfter(); }
146 LayoutUnit paddingLogicalLeft() const { return style()->isHorizontalWritingMode() ? paddingLeft() : paddingTop(); }
147 LayoutUnit paddingLogicalRight() const { return style()->isHorizontalWritingMode() ? paddingRight() : paddingBottom(); }
148 LayoutUnit paddingLogicalWidth() const { return paddingStart() + paddingEnd(); }
149 LayoutUnit paddingLogicalHeight() const { return paddingBefore() + paddingAfter(); }
151 virtual LayoutUnit marginTop() const = 0;
152 virtual LayoutUnit marginBottom() const = 0;
153 virtual LayoutUnit marginLeft() const = 0;
154 virtual LayoutUnit marginRight() const = 0;
155 virtual LayoutUnit marginBefore(const RenderStyle* otherStyle = 0) const = 0;
156 virtual LayoutUnit marginAfter(const RenderStyle* otherStyle = 0) const = 0;
157 virtual LayoutUnit marginStart(const RenderStyle* otherStyle = 0) const = 0;
158 virtual LayoutUnit marginEnd(const RenderStyle* otherStyle = 0) const = 0;
159 LayoutUnit marginHeight() const { return marginTop() + marginBottom(); }
160 LayoutUnit marginWidth() const { return marginLeft() + marginRight(); }
161 LayoutUnit marginLogicalHeight() const { return marginBefore() + marginAfter(); }
162 LayoutUnit marginLogicalWidth() const { return marginStart() + marginEnd(); }
164 bool hasInlineDirectionBordersPaddingOrMargin() const { return hasInlineDirectionBordersOrPadding() || marginStart()|| marginEnd(); }
165 bool hasInlineDirectionBordersOrPadding() const { return borderStart() || borderEnd() || paddingStart()|| paddingEnd(); }
167 virtual LayoutUnit containingBlockLogicalWidthForContent() const;
169 virtual void childBecameNonInline(RenderObject* /*child*/) { }
171 void paintBorder(const PaintInfo&, const LayoutRect&, const RenderStyle*, BackgroundBleedAvoidance = BackgroundBleedNone, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true);
172 bool paintNinePieceImage(GraphicsContext*, const LayoutRect&, const RenderStyle*, const NinePieceImage&, CompositeOperator = CompositeSourceOver);
173 void paintBoxShadow(const PaintInfo&, const LayoutRect&, const RenderStyle*, ShadowStyle, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true);
174 void paintFillLayerExtended(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, InlineFlowBox* = 0, const LayoutSize& = LayoutSize(), CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
176 virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox* = 0) const;
178 // Overridden by subclasses to determine line height and baseline position.
179 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
180 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
182 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
183 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE;
185 void highQualityRepaintTimerFired(Timer<RenderBoxModelObject>*);
187 virtual void setSelectionState(SelectionState) OVERRIDE;
189 void contentChanged(ContentChangeType);
190 bool hasAcceleratedCompositing() const;
192 virtual void computeLayerHitTestRects(LayerHitTestRects&) const OVERRIDE;
195 virtual void willBeDestroyed() OVERRIDE;
197 class BackgroundImageGeometry {
199 IntPoint destOrigin() const { return m_destOrigin; }
200 void setDestOrigin(const IntPoint& destOrigin)
202 m_destOrigin = destOrigin;
205 IntRect destRect() const { return m_destRect; }
206 void setDestRect(const IntRect& destRect)
208 m_destRect = destRect;
211 // Returns the phase relative to the destination rectangle.
212 IntPoint relativePhase() const;
214 IntPoint phase() const { return m_phase; }
215 void setPhase(const IntPoint& phase)
220 IntSize tileSize() const { return m_tileSize; }
221 void setTileSize(const IntSize& tileSize)
223 m_tileSize = tileSize;
226 // Space-size represents extra width and height that may be added to
227 // the image if used as a pattern with repeat: space
228 IntSize spaceSize() const { return m_repeatSpacing; }
229 void setSpaceSize(const IntSize& repeatSpacing)
231 m_repeatSpacing = repeatSpacing;
234 void setPhaseX(int x) { m_phase.setX(x); }
235 void setPhaseY(int y) { m_phase.setY(y); }
237 void setNoRepeatX(int xOffset);
238 void setNoRepeatY(int yOffset);
240 void useFixedAttachment(const IntPoint& attachmentPoint);
242 void clip(const IntRect&);
245 IntPoint m_destOrigin;
248 IntSize m_repeatSpacing;
251 LayoutPoint adjustedPositionRelativeToOffsetParent(const LayoutPoint&) const;
253 void calculateBackgroundImageGeometry(const FillLayer*, const LayoutRect& paintRect, BackgroundImageGeometry&, RenderObject* = 0);
254 void getBorderEdgeInfo(class BorderEdge[], const RenderStyle*, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true) const;
255 bool borderObscuresBackgroundEdge(const FloatSize& contextScale) const;
256 bool borderObscuresBackground() const;
257 RoundedRect backgroundRoundedRectAdjustedForBleedAvoidance(GraphicsContext*, const LayoutRect&, BackgroundBleedAvoidance, InlineFlowBox*, const LayoutSize&, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const;
258 LayoutRect borderInnerRectAdjustedForBleedAvoidance(GraphicsContext*, const LayoutRect&, BackgroundBleedAvoidance) const;
260 bool shouldPaintAtLowQuality(GraphicsContext*, Image*, const void*, const LayoutSize&);
262 RenderBoxModelObject* continuation() const;
263 void setContinuation(RenderBoxModelObject*);
265 LayoutRect localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset);
267 static bool shouldAntialiasLines(GraphicsContext*);
269 static void clipRoundedInnerRect(GraphicsContext*, const LayoutRect&, const RoundedRect& clipRect);
271 bool hasAutoHeightOrContainingBlockWithAutoHeight() const;
274 // For RenderBlocks and RenderInlines with m_style->styleType() == FIRST_LETTER, this tracks their remaining text fragments
275 RenderTextFragment* firstLetterRemainingText() const;
276 void setFirstLetterRemainingText(RenderTextFragment*);
278 // These functions are only used internally to manipulate the render tree structure via remove/insert/appendChildNode.
279 // Since they are typically called only to move objects around within anonymous blocks (which only have layers in
280 // the case of column spans), the default for fullRemoveInsert is false rather than true.
281 void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, bool fullRemoveInsert = false);
282 void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, bool fullRemoveInsert = false)
284 moveChildTo(toBoxModelObject, child, 0, fullRemoveInsert);
286 void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, bool fullRemoveInsert = false)
288 moveAllChildrenTo(toBoxModelObject, 0, fullRemoveInsert);
290 void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* beforeChild, bool fullRemoveInsert = false)
292 moveChildrenTo(toBoxModelObject, firstChild(), 0, beforeChild, fullRemoveInsert);
294 // Move all of the kids from |startChild| up to but excluding |endChild|. 0 can be passed as the |endChild| to denote
295 // that all the kids from |startChild| onwards should be moved.
296 void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, bool fullRemoveInsert = false)
298 moveChildrenTo(toBoxModelObject, startChild, endChild, 0, fullRemoveInsert);
300 void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, bool fullRemoveInsert = false);
303 LayoutUnit computedCSSPadding(Length) const;
304 virtual bool isBoxModelObject() const OVERRIDE FINAL { return true; }
306 virtual LayoutRect frameRectForStickyPositioning() const = 0;
308 IntSize calculateFillTileSize(const FillLayer*, const IntSize& scaledPositioningAreaSize) const;
310 enum ScaleByEffectiveZoomOrNot { ScaleByEffectiveZoom, DoNotScaleByEffectiveZoom };
311 IntSize calculateImageIntrinsicDimensions(StyleImage*, const IntSize& scaledPositioningAreaSize, ScaleByEffectiveZoomOrNot) const;
313 RoundedRect getBackgroundRoundedRect(const LayoutRect&, InlineFlowBox*, LayoutUnit inlineBoxWidth, LayoutUnit inlineBoxHeight,
314 bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const;
316 bool fixedBackgroundPaintsInLocalCoordinates() const;
318 void clipBorderSidePolygon(GraphicsContext*, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
319 BoxSide, bool firstEdgeMatches, bool secondEdgeMatches);
320 void clipBorderSideForComplexInnerPath(GraphicsContext*, const RoundedRect&, const RoundedRect&, BoxSide, const class BorderEdge[]);
321 void paintOneBorderSide(GraphicsContext*, const RenderStyle*, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
322 const IntRect& sideRect, BoxSide, BoxSide adjacentSide1, BoxSide adjacentSide2, const class BorderEdge[],
323 const Path*, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor = 0);
324 void paintTranslucentBorderSides(GraphicsContext*, const RenderStyle*, const RoundedRect& outerBorder, const RoundedRect& innerBorder, const IntPoint& innerBorderAdjustment,
325 const class BorderEdge[], BorderEdgeFlags, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias = false);
326 void paintBorderSides(GraphicsContext*, const RenderStyle*, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
327 const IntPoint& innerBorderAdjustment, const class BorderEdge[], BorderEdgeFlags, BackgroundBleedAvoidance,
328 bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias = false, const Color* overrideColor = 0);
329 void drawBoxSideFromPath(GraphicsContext*, const LayoutRect&, const Path&, const class BorderEdge[],
330 float thickness, float drawThickness, BoxSide, const RenderStyle*,
331 Color, EBorderStyle, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge);
334 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBoxModelObject, isBoxModelObject());
336 } // namespace WebCore
338 #endif // RenderBoxModelObject_h