• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/rendering/RenderLayerModelObject.h"
28 #include "core/rendering/style/ShadowData.h"
29 #include "platform/geometry/LayoutRect.h"
30 
31 namespace blink {
32 
33 // Modes for some of the line-related functions.
34 enum LinePositionMode { PositionOnContainingLine, PositionOfInteriorLineBoxes };
35 enum LineDirectionMode { HorizontalLine, VerticalLine };
36 typedef unsigned BorderEdgeFlags;
37 
38 enum BackgroundBleedAvoidance {
39     BackgroundBleedNone,
40     BackgroundBleedShrinkBackground,
41     BackgroundBleedClipBackground,
42     BackgroundBleedBackgroundOverBorder
43 };
44 
45 enum ContentChangeType {
46     ImageChanged,
47     CanvasChanged,
48     CanvasContextChanged
49 };
50 
51 class RenderTextFragment;
52 class BackgroundImageGeometry;
53 
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
56 
57 class RenderBoxModelObject : public RenderLayerModelObject {
58 public:
59     RenderBoxModelObject(ContainerNode*);
60     virtual ~RenderBoxModelObject();
61 
62     LayoutSize relativePositionOffset() const;
relativePositionLogicalOffset()63     LayoutSize relativePositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? relativePositionOffset() : relativePositionOffset().transposedSize(); }
64 
65     LayoutSize offsetForInFlowPosition() const;
66 
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;
73 
pixelSnappedOffsetLeft()74     int pixelSnappedOffsetLeft() const { return roundToInt(offsetLeft()); }
pixelSnappedOffsetTop()75     int pixelSnappedOffsetTop() const { return roundToInt(offsetTop()); }
76     virtual int pixelSnappedOffsetWidth() const;
77     virtual int pixelSnappedOffsetHeight() const;
78 
79     virtual void updateFromStyle() OVERRIDE;
80 
81     // This will work on inlines to return the bounding box of all of the lines' border boxes.
82     virtual IntRect borderBoundingBox() const = 0;
83 
84     // These return the CSS computed padding values.
computedCSSPaddingTop()85     LayoutUnit computedCSSPaddingTop() const { return computedCSSPadding(style()->paddingTop()); }
computedCSSPaddingBottom()86     LayoutUnit computedCSSPaddingBottom() const { return computedCSSPadding(style()->paddingBottom()); }
computedCSSPaddingLeft()87     LayoutUnit computedCSSPaddingLeft() const { return computedCSSPadding(style()->paddingLeft()); }
computedCSSPaddingRight()88     LayoutUnit computedCSSPaddingRight() const { return computedCSSPadding(style()->paddingRight()); }
computedCSSPaddingBefore()89     LayoutUnit computedCSSPaddingBefore() const { return computedCSSPadding(style()->paddingBefore()); }
computedCSSPaddingAfter()90     LayoutUnit computedCSSPaddingAfter() const { return computedCSSPadding(style()->paddingAfter()); }
computedCSSPaddingStart()91     LayoutUnit computedCSSPaddingStart() const { return computedCSSPadding(style()->paddingStart()); }
computedCSSPaddingEnd()92     LayoutUnit computedCSSPaddingEnd() const { return computedCSSPadding(style()->paddingEnd()); }
93 
94     // These functions are used during layout. Table cells
95     // override them to include some extra intrinsic padding.
paddingTop()96     virtual LayoutUnit paddingTop() const { return computedCSSPaddingTop(); }
paddingBottom()97     virtual LayoutUnit paddingBottom() const { return computedCSSPaddingBottom(); }
paddingLeft()98     virtual LayoutUnit paddingLeft() const { return computedCSSPaddingLeft(); }
paddingRight()99     virtual LayoutUnit paddingRight() const { return computedCSSPaddingRight(); }
paddingBefore()100     virtual LayoutUnit paddingBefore() const { return computedCSSPaddingBefore(); }
paddingAfter()101     virtual LayoutUnit paddingAfter() const { return computedCSSPaddingAfter(); }
paddingStart()102     virtual LayoutUnit paddingStart() const { return computedCSSPaddingStart(); }
paddingEnd()103     virtual LayoutUnit paddingEnd() const { return computedCSSPaddingEnd(); }
104 
borderTop()105     virtual int borderTop() const { return style()->borderTopWidth(); }
borderBottom()106     virtual int borderBottom() const { return style()->borderBottomWidth(); }
borderLeft()107     virtual int borderLeft() const { return style()->borderLeftWidth(); }
borderRight()108     virtual int borderRight() const { return style()->borderRightWidth(); }
borderBefore()109     virtual int borderBefore() const { return style()->borderBeforeWidth(); }
borderAfter()110     virtual int borderAfter() const { return style()->borderAfterWidth(); }
borderStart()111     virtual int borderStart() const { return style()->borderStartWidth(); }
borderEnd()112     virtual int borderEnd() const { return style()->borderEndWidth(); }
113 
borderWidth()114     int borderWidth() const { return borderLeft() + borderRight(); }
borderHeight()115     int borderHeight() const { return borderTop() + borderBottom(); }
116 
borderAndPaddingStart()117     LayoutUnit borderAndPaddingStart() const { return borderStart() + paddingStart(); }
borderAndPaddingBefore()118     LayoutUnit borderAndPaddingBefore() const { return borderBefore() + paddingBefore(); }
borderAndPaddingAfter()119     LayoutUnit borderAndPaddingAfter() const { return borderAfter() + paddingAfter(); }
120 
borderAndPaddingHeight()121     LayoutUnit borderAndPaddingHeight() const { return borderTop() + borderBottom() + paddingTop() + paddingBottom(); }
borderAndPaddingWidth()122     LayoutUnit borderAndPaddingWidth() const { return borderLeft() + borderRight() + paddingLeft() + paddingRight(); }
borderAndPaddingLogicalHeight()123     LayoutUnit borderAndPaddingLogicalHeight() const { return borderAndPaddingBefore() + borderAndPaddingAfter(); }
borderAndPaddingLogicalWidth()124     LayoutUnit borderAndPaddingLogicalWidth() const { return borderStart() + borderEnd() + paddingStart() + paddingEnd(); }
borderAndPaddingLogicalLeft()125     LayoutUnit borderAndPaddingLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
126 
127 
borderLogicalLeft()128     LayoutUnit borderLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() : borderTop(); }
borderLogicalRight()129     LayoutUnit borderLogicalRight() const { return style()->isHorizontalWritingMode() ? borderRight() : borderBottom(); }
borderLogicalWidth()130     LayoutUnit borderLogicalWidth() const { return borderStart() + borderEnd(); }
borderLogicalHeight()131     LayoutUnit borderLogicalHeight() const { return borderBefore() + borderAfter(); }
132 
paddingLogicalLeft()133     LayoutUnit paddingLogicalLeft() const { return style()->isHorizontalWritingMode() ? paddingLeft() : paddingTop(); }
paddingLogicalRight()134     LayoutUnit paddingLogicalRight() const { return style()->isHorizontalWritingMode() ? paddingRight() : paddingBottom(); }
paddingLogicalWidth()135     LayoutUnit paddingLogicalWidth() const { return paddingStart() + paddingEnd(); }
paddingLogicalHeight()136     LayoutUnit paddingLogicalHeight() const { return paddingBefore() + paddingAfter(); }
137 
138     virtual LayoutUnit marginTop() const = 0;
139     virtual LayoutUnit marginBottom() const = 0;
140     virtual LayoutUnit marginLeft() const = 0;
141     virtual LayoutUnit marginRight() const = 0;
142     virtual LayoutUnit marginBefore(const RenderStyle* otherStyle = 0) const = 0;
143     virtual LayoutUnit marginAfter(const RenderStyle* otherStyle = 0) const = 0;
144     virtual LayoutUnit marginStart(const RenderStyle* otherStyle = 0) const = 0;
145     virtual LayoutUnit marginEnd(const RenderStyle* otherStyle = 0) const = 0;
marginHeight()146     LayoutUnit marginHeight() const { return marginTop() + marginBottom(); }
marginWidth()147     LayoutUnit marginWidth() const { return marginLeft() + marginRight(); }
marginLogicalHeight()148     LayoutUnit marginLogicalHeight() const { return marginBefore() + marginAfter(); }
marginLogicalWidth()149     LayoutUnit marginLogicalWidth() const { return marginStart() + marginEnd(); }
150 
hasInlineDirectionBordersPaddingOrMargin()151     bool hasInlineDirectionBordersPaddingOrMargin() const { return hasInlineDirectionBordersOrPadding() || marginStart()|| marginEnd(); }
hasInlineDirectionBordersOrPadding()152     bool hasInlineDirectionBordersOrPadding() const { return borderStart() || borderEnd() || paddingStart()|| paddingEnd(); }
153 
154     virtual LayoutUnit containingBlockLogicalWidthForContent() const;
155 
childBecameNonInline(RenderObject *)156     virtual void childBecameNonInline(RenderObject* /*child*/) { }
157 
158     virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox* = 0) const;
159 
160     // Overridden by subclasses to determine line height and baseline position.
161     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
162     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
163 
164     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
165     virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE;
166 
167     virtual void setSelectionState(SelectionState) OVERRIDE;
168 
169     void contentChanged(ContentChangeType);
170     bool hasAcceleratedCompositing() const;
171 
172     virtual void computeLayerHitTestRects(LayerHitTestRects&) const OVERRIDE;
173 
174 protected:
175     virtual void willBeDestroyed() OVERRIDE;
176 
177     LayoutPoint adjustedPositionRelativeToOffsetParent(const LayoutPoint&) const;
178 
179     bool calculateHasBoxDecorations() const;
180 
181     RenderBoxModelObject* continuation() const;
182     void setContinuation(RenderBoxModelObject*);
183 
184     LayoutRect localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset);
185 
186     bool hasAutoHeightOrContainingBlockWithAutoHeight() const;
187 
188 public:
189 
190     // For RenderBlocks and RenderInlines with m_style->styleType() == FIRST_LETTER, this tracks their remaining text fragments
191     RenderTextFragment* firstLetterRemainingText() const;
192     void setFirstLetterRemainingText(RenderTextFragment*);
193 
194     // These functions are only used internally to manipulate the render tree structure via remove/insert/appendChildNode.
195     // Since they are typically called only to move objects around within anonymous blocks (which only have layers in
196     // the case of column spans), the default for fullRemoveInsert is false rather than true.
197     void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, bool fullRemoveInsert = false);
198     void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, bool fullRemoveInsert = false)
199     {
200         moveChildTo(toBoxModelObject, child, 0, fullRemoveInsert);
201     }
202     void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, bool fullRemoveInsert = false)
203     {
204         moveAllChildrenTo(toBoxModelObject, 0, fullRemoveInsert);
205     }
206     void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* beforeChild, bool fullRemoveInsert = false)
207     {
208         moveChildrenTo(toBoxModelObject, slowFirstChild(), 0, beforeChild, fullRemoveInsert);
209     }
210     // Move all of the kids from |startChild| up to but excluding |endChild|. 0 can be passed as the |endChild| to denote
211     // that all the kids from |startChild| onwards should be moved.
212     void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, bool fullRemoveInsert = false)
213     {
214         moveChildrenTo(toBoxModelObject, startChild, endChild, 0, fullRemoveInsert);
215     }
216     void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, bool fullRemoveInsert = false);
217 
218     enum ScaleByEffectiveZoomOrNot { ScaleByEffectiveZoom, DoNotScaleByEffectiveZoom };
219     IntSize calculateImageIntrinsicDimensions(StyleImage*, const IntSize& scaledPositioningAreaSize, ScaleByEffectiveZoomOrNot) const;
220 
221 private:
222     LayoutUnit computedCSSPadding(const Length&) const;
isBoxModelObject()223     virtual bool isBoxModelObject() const OVERRIDE FINAL { return true; }
224 };
225 
226 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBoxModelObject, isBoxModelObject());
227 
228 } // namespace blink
229 
230 #endif // RenderBoxModelObject_h
231