Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderBoxModelObject.h
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 WebCore {
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     BackgroundBleedUseTransparencyLayer,
42     BackgroundBleedBackgroundOverBorder
43 };
44
45 enum ContentChangeType {
46     ImageChanged,
47     MaskImageChanged,
48     CanvasChanged,
49     CanvasPixelsChanged,
50     VideoChanged,
51     FullScreenChanged
52 };
53
54 class KeyframeList;
55 class RenderTextFragment;
56 class StickyPositionViewportConstraints;
57
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
60
61 class RenderBoxModelObject : public RenderLayerModelObject {
62 public:
63     RenderBoxModelObject(ContainerNode*);
64     virtual ~RenderBoxModelObject();
65
66     LayoutSize relativePositionOffset() const;
67     LayoutSize relativePositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? relativePositionOffset() : relativePositionOffset().transposedSize(); }
68
69     void computeStickyPositionConstraints(StickyPositionViewportConstraints&, const FloatRect& constrainingRect) const;
70     LayoutSize stickyPositionOffset() const;
71     LayoutSize stickyPositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? stickyPositionOffset() : stickyPositionOffset().transposedSize(); }
72
73     LayoutSize offsetForInFlowPosition() const;
74
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;
81
82     int pixelSnappedOffsetLeft() const { return roundToInt(offsetLeft()); }
83     int pixelSnappedOffsetTop() const { return roundToInt(offsetTop()); }
84     virtual int pixelSnappedOffsetWidth() const;
85     virtual int pixelSnappedOffsetHeight() const;
86
87     virtual void updateFromStyle() OVERRIDE;
88
89     virtual LayerType layerTypeRequired() const OVERRIDE
90     {
91         if (isRoot() || isPositioned() || createsGroup() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns())
92             return NormalLayer;
93
94         return NoLayer;
95     }
96
97     // This will work on inlines to return the bounding box of all of the lines' border boxes.
98     virtual IntRect borderBoundingBox() const = 0;
99
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()); }
109
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(); }
120
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(); }
129
130     LayoutUnit borderAndPaddingStart() const { return borderStart() + paddingStart(); }
131     LayoutUnit borderAndPaddingBefore() const { return borderBefore() + paddingBefore(); }
132     LayoutUnit borderAndPaddingAfter() const { return borderAfter() + paddingAfter(); }
133
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(); }
139
140
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(); }
145
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(); }
150
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(); }
163
164     bool hasInlineDirectionBordersPaddingOrMargin() const { return hasInlineDirectionBordersOrPadding() || marginStart()|| marginEnd(); }
165     bool hasInlineDirectionBordersOrPadding() const { return borderStart() || borderEnd() || paddingStart()|| paddingEnd(); }
166
167     virtual LayoutUnit containingBlockLogicalWidthForContent() const;
168
169     virtual void childBecameNonInline(RenderObject* /*child*/) { }
170
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);
175
176     virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox* = 0) const;
177
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;
181
182     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
183     virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE;
184
185     void highQualityRepaintTimerFired(Timer<RenderBoxModelObject>*);
186
187     virtual void setSelectionState(SelectionState) OVERRIDE;
188
189     void contentChanged(ContentChangeType);
190     bool hasAcceleratedCompositing() const;
191
192     virtual void computeLayerHitTestRects(LayerHitTestRects&) const OVERRIDE;
193
194 protected:
195     virtual void willBeDestroyed() OVERRIDE;
196
197     class BackgroundImageGeometry {
198     public:
199         IntPoint destOrigin() const { return m_destOrigin; }
200         void setDestOrigin(const IntPoint& destOrigin)
201         {
202             m_destOrigin = destOrigin;
203         }
204
205         IntRect destRect() const { return m_destRect; }
206         void setDestRect(const IntRect& destRect)
207         {
208             m_destRect = destRect;
209         }
210
211         // Returns the phase relative to the destination rectangle.
212         IntPoint relativePhase() const;
213
214         IntPoint phase() const { return m_phase; }
215         void setPhase(const IntPoint& phase)
216         {
217             m_phase = phase;
218         }
219
220         IntSize tileSize() const { return m_tileSize; }
221         void setTileSize(const IntSize& tileSize)
222         {
223             m_tileSize = tileSize;
224         }
225
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)
230         {
231             m_repeatSpacing = repeatSpacing;
232         }
233
234         void setPhaseX(int x) { m_phase.setX(x); }
235         void setPhaseY(int y) { m_phase.setY(y); }
236
237         void setNoRepeatX(int xOffset);
238         void setNoRepeatY(int yOffset);
239
240         void useFixedAttachment(const IntPoint& attachmentPoint);
241
242         void clip(const IntRect&);
243     private:
244         IntRect m_destRect;
245         IntPoint m_destOrigin;
246         IntPoint m_phase;
247         IntSize m_tileSize;
248         IntSize m_repeatSpacing;
249     };
250
251     LayoutPoint adjustedPositionRelativeToOffsetParent(const LayoutPoint&) const;
252
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;
259
260     bool shouldPaintAtLowQuality(GraphicsContext*, Image*, const void*, const LayoutSize&);
261
262     RenderBoxModelObject* continuation() const;
263     void setContinuation(RenderBoxModelObject*);
264
265     LayoutRect localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset);
266
267     static bool shouldAntialiasLines(GraphicsContext*);
268
269     static void clipRoundedInnerRect(GraphicsContext*, const LayoutRect&, const RoundedRect& clipRect);
270
271     bool hasAutoHeightOrContainingBlockWithAutoHeight() const;
272
273 public:
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*);
277
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)
283     {
284         moveChildTo(toBoxModelObject, child, 0, fullRemoveInsert);
285     }
286     void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, bool fullRemoveInsert = false)
287     {
288         moveAllChildrenTo(toBoxModelObject, 0, fullRemoveInsert);
289     }
290     void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* beforeChild, bool fullRemoveInsert = false)
291     {
292         moveChildrenTo(toBoxModelObject, firstChild(), 0, beforeChild, fullRemoveInsert);
293     }
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)
297     {
298         moveChildrenTo(toBoxModelObject, startChild, endChild, 0, fullRemoveInsert);
299     }
300     void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, bool fullRemoveInsert = false);
301
302 private:
303     LayoutUnit computedCSSPadding(Length) const;
304     virtual bool isBoxModelObject() const OVERRIDE FINAL { return true; }
305
306     virtual LayoutRect frameRectForStickyPositioning() const = 0;
307
308     IntSize calculateFillTileSize(const FillLayer*, const IntSize& scaledPositioningAreaSize) const;
309
310     enum ScaleByEffectiveZoomOrNot { ScaleByEffectiveZoom, DoNotScaleByEffectiveZoom };
311     IntSize calculateImageIntrinsicDimensions(StyleImage*, const IntSize& scaledPositioningAreaSize, ScaleByEffectiveZoomOrNot) const;
312
313     RoundedRect getBackgroundRoundedRect(const LayoutRect&, InlineFlowBox*, LayoutUnit inlineBoxWidth, LayoutUnit inlineBoxHeight,
314         bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const;
315
316     bool fixedBackgroundPaintsInLocalCoordinates() const;
317
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);
332 };
333
334 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBoxModelObject, isBoxModelObject());
335
336 } // namespace WebCore
337
338 #endif // RenderBoxModelObject_h