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 BackgroundBleedClipBackground,
42 BackgroundBleedBackgroundOverBorder
45 enum ContentChangeType {
51 class RenderTextFragment;
52 class BackgroundImageGeometry;
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 RenderLayerModelObject {
59 RenderBoxModelObject(ContainerNode*);
60 virtual ~RenderBoxModelObject();
62 LayoutSize relativePositionOffset() const;
63 LayoutSize relativePositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? relativePositionOffset() : relativePositionOffset().transposedSize(); }
65 LayoutSize offsetForInFlowPosition() const;
67 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
68 // to return the remaining width on a given line (and the height of a single line).
69 virtual LayoutUnit offsetLeft() const;
70 virtual LayoutUnit offsetTop() const;
71 virtual LayoutUnit offsetWidth() const = 0;
72 virtual LayoutUnit offsetHeight() const = 0;
74 int pixelSnappedOffsetLeft() const { return roundToInt(offsetLeft()); }
75 int pixelSnappedOffsetTop() const { return roundToInt(offsetTop()); }
76 virtual int pixelSnappedOffsetWidth() const;
77 virtual int pixelSnappedOffsetHeight() const;
79 virtual void updateFromStyle() override;
81 // This will work on inlines to return the bounding box of all of the lines' border boxes.
82 virtual IntRect borderBoundingBox() const = 0;
84 // These return the CSS computed padding values.
85 LayoutUnit computedCSSPaddingTop() const { return computedCSSPadding(style()->paddingTop()); }
86 LayoutUnit computedCSSPaddingBottom() const { return computedCSSPadding(style()->paddingBottom()); }
87 LayoutUnit computedCSSPaddingLeft() const { return computedCSSPadding(style()->paddingLeft()); }
88 LayoutUnit computedCSSPaddingRight() const { return computedCSSPadding(style()->paddingRight()); }
89 LayoutUnit computedCSSPaddingBefore() const { return computedCSSPadding(style()->paddingBefore()); }
90 LayoutUnit computedCSSPaddingAfter() const { return computedCSSPadding(style()->paddingAfter()); }
91 LayoutUnit computedCSSPaddingStart() const { return computedCSSPadding(style()->paddingStart()); }
92 LayoutUnit computedCSSPaddingEnd() const { return computedCSSPadding(style()->paddingEnd()); }
94 // These functions are used during layout. Table cells
95 // override them to include some extra intrinsic padding.
96 virtual LayoutUnit paddingTop() const { return computedCSSPaddingTop(); }
97 virtual LayoutUnit paddingBottom() const { return computedCSSPaddingBottom(); }
98 virtual LayoutUnit paddingLeft() const { return computedCSSPaddingLeft(); }
99 virtual LayoutUnit paddingRight() const { return computedCSSPaddingRight(); }
100 virtual LayoutUnit paddingBefore() const { return computedCSSPaddingBefore(); }
101 virtual LayoutUnit paddingAfter() const { return computedCSSPaddingAfter(); }
102 virtual LayoutUnit paddingStart() const { return computedCSSPaddingStart(); }
103 virtual LayoutUnit paddingEnd() const { return computedCSSPaddingEnd(); }
105 virtual int borderTop() const { return style()->borderTopWidth(); }
106 virtual int borderBottom() const { return style()->borderBottomWidth(); }
107 virtual int borderLeft() const { return style()->borderLeftWidth(); }
108 virtual int borderRight() const { return style()->borderRightWidth(); }
109 virtual int borderBefore() const { return style()->borderBeforeWidth(); }
110 virtual int borderAfter() const { return style()->borderAfterWidth(); }
111 virtual int borderStart() const { return style()->borderStartWidth(); }
112 virtual int borderEnd() const { return style()->borderEndWidth(); }
114 int borderWidth() const { return borderLeft() + borderRight(); }
115 int borderHeight() const { return borderTop() + borderBottom(); }
117 LayoutUnit borderAndPaddingStart() const { return borderStart() + paddingStart(); }
118 LayoutUnit borderAndPaddingBefore() const { return borderBefore() + paddingBefore(); }
119 LayoutUnit borderAndPaddingAfter() const { return borderAfter() + paddingAfter(); }
121 LayoutUnit borderAndPaddingHeight() const { return borderTop() + borderBottom() + paddingTop() + paddingBottom(); }
122 LayoutUnit borderAndPaddingWidth() const { return borderLeft() + borderRight() + paddingLeft() + paddingRight(); }
123 LayoutUnit borderAndPaddingLogicalHeight() const { return borderAndPaddingBefore() + borderAndPaddingAfter(); }
124 LayoutUnit borderAndPaddingLogicalWidth() const { return borderStart() + borderEnd() + paddingStart() + paddingEnd(); }
125 LayoutUnit borderAndPaddingLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
128 LayoutUnit borderLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() : borderTop(); }
130 LayoutUnit paddingLogicalWidth() const { return paddingStart() + paddingEnd(); }
131 LayoutUnit paddingLogicalHeight() const { return paddingBefore() + paddingAfter(); }
133 virtual LayoutUnit marginTop() const = 0;
134 virtual LayoutUnit marginBottom() const = 0;
135 virtual LayoutUnit marginLeft() const = 0;
136 virtual LayoutUnit marginRight() const = 0;
137 virtual LayoutUnit marginBefore(const RenderStyle* otherStyle = 0) const = 0;
138 virtual LayoutUnit marginAfter(const RenderStyle* otherStyle = 0) const = 0;
139 virtual LayoutUnit marginStart(const RenderStyle* otherStyle = 0) const = 0;
140 virtual LayoutUnit marginEnd(const RenderStyle* otherStyle = 0) const = 0;
141 LayoutUnit marginHeight() const { return marginTop() + marginBottom(); }
142 LayoutUnit marginWidth() const { return marginLeft() + marginRight(); }
143 LayoutUnit marginLogicalHeight() const { return marginBefore() + marginAfter(); }
144 LayoutUnit marginLogicalWidth() const { return marginStart() + marginEnd(); }
146 bool hasInlineDirectionBordersPaddingOrMargin() const { return hasInlineDirectionBordersOrPadding() || marginStart()|| marginEnd(); }
147 bool hasInlineDirectionBordersOrPadding() const { return borderStart() || borderEnd() || paddingStart()|| paddingEnd(); }
149 virtual LayoutUnit containingBlockLogicalWidthForContent() const;
151 virtual void childBecameNonInline(RenderObject* /*child*/) { }
153 virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox* = 0) const;
155 // Overridden by subclasses to determine line height and baseline position.
156 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
157 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
159 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override;
160 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const override;
162 virtual void setSelectionState(SelectionState) override;
164 void contentChanged(ContentChangeType);
165 bool hasAcceleratedCompositing() const;
167 virtual void computeLayerHitTestRects(LayerHitTestRects&) const override;
170 virtual void willBeDestroyed() override;
172 LayoutPoint adjustedPositionRelativeToOffsetParent(const LayoutPoint&) const;
174 bool calculateHasBoxDecorations() const;
176 RenderBoxModelObject* continuation() const;
177 void setContinuation(RenderBoxModelObject*);
179 LayoutRect localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset);
181 bool hasAutoHeightOrContainingBlockWithAutoHeight() const;
185 // For RenderBlocks and RenderInlines with m_style->styleType() == FIRST_LETTER, this tracks their remaining text fragments
186 RenderTextFragment* firstLetterRemainingText() const;
187 void setFirstLetterRemainingText(RenderTextFragment*);
189 // These functions are only used internally to manipulate the render tree structure via remove/insert/appendChildNode.
190 // Since they are typically called only to move objects around within anonymous blocks (which only have layers in
191 // the case of column spans), the default for fullRemoveInsert is false rather than true.
192 void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, bool fullRemoveInsert = false);
193 void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, bool fullRemoveInsert = false)
195 moveChildTo(toBoxModelObject, child, 0, fullRemoveInsert);
197 void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, bool fullRemoveInsert = false)
199 moveAllChildrenTo(toBoxModelObject, 0, fullRemoveInsert);
201 void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* beforeChild, bool fullRemoveInsert = false)
203 moveChildrenTo(toBoxModelObject, slowFirstChild(), 0, beforeChild, fullRemoveInsert);
205 // Move all of the kids from |startChild| up to but excluding |endChild|. 0 can be passed as the |endChild| to denote
206 // that all the kids from |startChild| onwards should be moved.
207 void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, bool fullRemoveInsert = false)
209 moveChildrenTo(toBoxModelObject, startChild, endChild, 0, fullRemoveInsert);
211 void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, bool fullRemoveInsert = false);
213 enum ScaleByEffectiveZoomOrNot { ScaleByEffectiveZoom, DoNotScaleByEffectiveZoom };
214 IntSize calculateImageIntrinsicDimensions(StyleImage*, const IntSize& scaledPositioningAreaSize, ScaleByEffectiveZoomOrNot) const;
217 LayoutUnit computedCSSPadding(const Length&) const;
218 virtual bool isBoxModelObject() const override final { return true; }
221 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBoxModelObject, isBoxModelObject());
225 #endif // RenderBoxModelObject_h