1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB.  If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef RenderBox_h
24#define RenderBox_h
25
26#include "RenderBoxModelObject.h"
27#include "RenderOverflow.h"
28#include "ScrollTypes.h"
29#if ENABLE(CSS_SHAPES)
30#include "ShapeOutsideInfo.h"
31#endif
32
33namespace WebCore {
34
35class RenderBoxRegionInfo;
36class RenderRegion;
37struct PaintInfo;
38
39enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
40enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
41enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
42
43enum ShouldComputePreferred { ComputeActual, ComputePreferred };
44
45class RenderBox : public RenderBoxModelObject {
46public:
47    explicit RenderBox(ContainerNode*);
48    virtual ~RenderBox();
49
50    // hasAutoZIndex only returns true if the element is positioned or a flex-item since
51    // position:static elements that are not flex-items get their z-index coerced to auto.
52    virtual bool requiresLayer() const OVERRIDE { return isRoot() || isPositioned() || createsGroup() || hasClipPath() || hasOverflowClip() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex() || isFloatingWithShapeOutside(); }
53
54    virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
55
56    // Use this with caution! No type checking is done!
57    RenderBox* firstChildBox() const;
58    RenderBox* lastChildBox() const;
59
60    LayoutUnit x() const { return m_frameRect.x(); }
61    LayoutUnit y() const { return m_frameRect.y(); }
62    LayoutUnit width() const { return m_frameRect.width(); }
63    LayoutUnit height() const { return m_frameRect.height(); }
64
65    int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
66    int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
67
68    // These represent your location relative to your container as a physical offset.
69    // In layout related methods you almost always want the logical location (e.g. x() and y()).
70    LayoutUnit top() const { return topLeftLocation().y(); }
71    LayoutUnit left() const { return topLeftLocation().x(); }
72
73    void setX(LayoutUnit x) { m_frameRect.setX(x); }
74    void setY(LayoutUnit y) { m_frameRect.setY(y); }
75    void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
76    void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
77
78    LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
79    LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
80    LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
81    LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
82    LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
83    LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
84
85    LayoutUnit constrainLogicalWidthInRegionByMinMax(LayoutUnit, LayoutUnit, RenderBlock*, RenderRegion* = 0) const;
86    LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit) const;
87    LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit) const;
88
89    int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
90    int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
91
92    void setLogicalLeft(LayoutUnit left)
93    {
94        if (style()->isHorizontalWritingMode())
95            setX(left);
96        else
97            setY(left);
98    }
99    void setLogicalTop(LayoutUnit top)
100    {
101        if (style()->isHorizontalWritingMode())
102            setY(top);
103        else
104            setX(top);
105    }
106    void setLogicalLocation(const LayoutPoint& location)
107    {
108        if (style()->isHorizontalWritingMode())
109            setLocation(location);
110        else
111            setLocation(location.transposedPoint());
112    }
113    void setLogicalWidth(LayoutUnit size)
114    {
115        if (style()->isHorizontalWritingMode())
116            setWidth(size);
117        else
118            setHeight(size);
119    }
120    void setLogicalHeight(LayoutUnit size)
121    {
122        if (style()->isHorizontalWritingMode())
123            setHeight(size);
124        else
125            setWidth(size);
126    }
127    void setLogicalSize(const LayoutSize& size)
128    {
129        if (style()->isHorizontalWritingMode())
130            setSize(size);
131        else
132            setSize(size.transposedSize());
133    }
134
135    LayoutPoint location() const { return m_frameRect.location(); }
136    LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
137    LayoutSize size() const { return m_frameRect.size(); }
138    IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
139
140    void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
141
142    void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
143    void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
144
145    LayoutRect frameRect() const { return m_frameRect; }
146    IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
147    void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
148
149    LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
150    LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
151    IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
152    virtual IntRect borderBoundingBox() const { return pixelSnappedBorderBoxRect(); }
153
154    // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
155    LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
156    // The content box in absolute coords. Ignores transforms.
157    IntRect absoluteContentBox() const;
158    // The content box converted to absolute coords (taking transforms into account).
159    FloatQuad absoluteContentQuad() const;
160
161    // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
162    // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
163    LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
164
165    // Bounds of the outline box in absolute coords. Respects transforms
166    virtual LayoutRect outlineBoundsForRepaint(const RenderLayerModelObject* /*repaintContainer*/, const RenderGeometryMap*) const OVERRIDE;
167    virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint&);
168
169    // Use this with caution! No type checking is done!
170    RenderBox* previousSiblingBox() const;
171    RenderBox* nextSiblingBox() const;
172    RenderBox* parentBox() const;
173
174    // Visual and layout overflow are in the coordinate space of the box.  This means that they aren't purely physical directions.
175    // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
176    // respectively are flipped when compared to their physical counterparts.  For example minX is on the left in vertical-lr,
177    // but it is on the right in vertical-rl.
178    LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : clientBoxRect(); }
179    LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
180    LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
181
182    virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
183    LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
184    LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
185
186    LayoutRect overflowRectForPaintRejection() const;
187
188    void addLayoutOverflow(const LayoutRect&);
189    void addVisualOverflow(const LayoutRect&);
190
191    void addVisualEffectOverflow();
192    void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
193    void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
194
195    void updateLayerTransform();
196
197    LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
198    LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
199    LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
200    LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
201
202    // IE extensions. Used to calculate offsetWidth/Height.  Overridden by inlines (RenderFlow)
203    // to return the remaining width on a given line (and the height of a single line).
204    virtual LayoutUnit offsetWidth() const { return width(); }
205    virtual LayoutUnit offsetHeight() const { return height(); }
206
207    virtual int pixelSnappedOffsetWidth() const OVERRIDE;
208    virtual int pixelSnappedOffsetHeight() const OVERRIDE;
209
210    // More IE extensions.  clientWidth and clientHeight represent the interior of an object
211    // excluding border and scrollbar.  clientLeft/Top are just the borderLeftWidth and borderTopWidth.
212    LayoutUnit clientLeft() const { return borderLeft(); }
213    LayoutUnit clientTop() const { return borderTop(); }
214    LayoutUnit clientWidth() const;
215    LayoutUnit clientHeight() const;
216    LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
217    LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
218    LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
219    LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
220
221    int pixelSnappedClientWidth() const;
222    int pixelSnappedClientHeight() const;
223
224    // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
225    // object has overflow:hidden/scroll/auto specified and also has overflow.
226    // scrollLeft/Top return the current scroll position.  These methods are virtual so that objects like
227    // textareas can scroll shadow content (but pretend that they are the objects that are
228    // scrolling).
229    virtual int scrollLeft() const;
230    virtual int scrollTop() const;
231    virtual int scrollWidth() const;
232    virtual int scrollHeight() const;
233    virtual void setScrollLeft(int);
234    virtual void setScrollTop(int);
235
236    virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
237    virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
238    virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
239    virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
240    void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
241    void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
242    void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
243    void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
244
245    virtual LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
246    virtual LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
247
248    virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
249    virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
250    virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE
251    {
252        const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
253        return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
254    }
255    virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE
256    {
257        const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
258        return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
259    }
260    void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
261    void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
262    void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
263    {
264        const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
265        m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
266    }
267    void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
268    {
269        const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
270        m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
271    }
272
273    // The following five functions are used to implement collapsing margins.
274    // All objects know their maximal positive and negative margins.  The
275    // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
276    // For a non-collapsing box, such as a leaf element, this formula will simply return
277    // the margin of the element.  Blocks override the maxMarginBefore and maxMarginAfter
278    // methods.
279    enum MarginSign { PositiveMargin, NegativeMargin };
280    virtual bool isSelfCollapsingBlock() const { return false; }
281    virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
282    virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
283
284    virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
285    virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
286
287    LayoutRect reflectionBox() const;
288    int reflectionOffset() const;
289    // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
290    LayoutRect reflectedRect(const LayoutRect&) const;
291
292    virtual void layout();
293    virtual void paint(PaintInfo&, const LayoutPoint&);
294    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
295
296    virtual LayoutUnit minPreferredLogicalWidth() const;
297    virtual LayoutUnit maxPreferredLogicalWidth() const;
298
299    // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
300    // the border-box height/width like the regular height/width accessors on RenderBox.
301    // Right now, these are different than contentHeight/contentWidth because they still
302    // include the scrollbar height/width.
303    LayoutUnit overrideLogicalContentWidth() const;
304    LayoutUnit overrideLogicalContentHeight() const;
305    bool hasOverrideHeight() const;
306    bool hasOverrideWidth() const;
307    void setOverrideLogicalContentHeight(LayoutUnit);
308    void setOverrideLogicalContentWidth(LayoutUnit);
309    void clearOverrideSize();
310    void clearOverrideLogicalContentHeight();
311    void clearOverrideLogicalContentWidth();
312
313    LayoutUnit overrideContainingBlockContentLogicalWidth() const;
314    LayoutUnit overrideContainingBlockContentLogicalHeight() const;
315    bool hasOverrideContainingBlockLogicalWidth() const;
316    bool hasOverrideContainingBlockLogicalHeight() const;
317    void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
318    void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
319    void clearContainingBlockOverrideSize();
320    void clearOverrideContainingBlockContentLogicalHeight();
321
322    virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const;
323
324    LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
325    LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
326    LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
327    LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
328
329    struct ComputedMarginValues {
330        ComputedMarginValues()
331            : m_before(0)
332            , m_after(0)
333            , m_start(0)
334            , m_end(0)
335        {
336        }
337        LayoutUnit m_before;
338        LayoutUnit m_after;
339        LayoutUnit m_start;
340        LayoutUnit m_end;
341    };
342    struct LogicalExtentComputedValues {
343        LogicalExtentComputedValues()
344            : m_extent(0)
345            , m_position(0)
346        {
347        }
348
349        LayoutUnit m_extent;
350        LayoutUnit m_position;
351        ComputedMarginValues m_margins;
352    };
353    // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
354    // of the containing block.
355    void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
356
357    // Used to resolve margins in the containing block's block-flow direction.
358    void computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
359    void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
360
361    enum RenderBoxRegionInfoFlags { CacheRenderBoxRegionInfo, DoNotCacheRenderBoxRegionInfo };
362    LayoutRect borderBoxRectInRegion(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
363    void clearRenderBoxRegionInfo();
364    virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
365
366    void positionLineBox(InlineBox*);
367
368    virtual InlineBox* createInlineBox();
369    void dirtyLineBoxes(bool fullLayout);
370
371    // For inline replaced elements, this function returns the inline box that owns us.  Enables
372    // the replaced RenderObject to quickly determine what line it is contained on and to easily
373    // iterate over structures on the line.
374    InlineBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
375    void setInlineBoxWrapper(InlineBox* boxWrapper) { m_inlineBoxWrapper = boxWrapper; }
376    void deleteLineBoxWrapper();
377
378    virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
379    virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const OVERRIDE;
380    void repaintDuringLayoutIfMoved(const LayoutRect&);
381    virtual void repaintOverhangingFloats(bool paintAllDescendants);
382
383    virtual LayoutUnit containingBlockLogicalWidthForContent() const;
384    LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
385
386    LayoutUnit containingBlockLogicalWidthForContentInRegion(RenderRegion*) const;
387    LayoutUnit containingBlockAvailableLineWidthInRegion(RenderRegion*) const;
388    LayoutUnit perpendicularContainingBlockLogicalHeight() const;
389
390    virtual void updateLogicalWidth();
391    virtual void updateLogicalHeight();
392    virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
393
394    RenderBoxRegionInfo* renderBoxRegionInfo(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
395    void computeLogicalWidthInRegion(LogicalExtentComputedValues&, RenderRegion* = 0) const;
396
397    bool stretchesToViewport() const
398    {
399        return document()->inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isRoot() || isBody()) && !document()->shouldDisplaySeamlesslyWithParent() && !isInline();
400    }
401
402    virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
403    LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
404    LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
405
406    // Whether or not the element shrinks to its intrinsic width (rather than filling the width
407    // of a containing block).  HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
408    bool sizesLogicalWidthToFitContent(SizeType) const;
409
410    LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlock* cb, RenderRegion*) const;
411
412    LayoutUnit computeLogicalWidthInRegionUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock, RenderRegion*) const;
413    LayoutUnit computeLogicalHeightUsing(const Length& height) const;
414    LayoutUnit computeContentLogicalHeight(const Length& height) const;
415    LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height) const;
416    LayoutUnit computeReplacedLogicalWidthUsing(Length width) const;
417    LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred  = ComputeActual) const;
418    LayoutUnit computeReplacedLogicalHeightUsing(Length height) const;
419    LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
420
421    virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred  = ComputeActual) const;
422    virtual LayoutUnit computeReplacedLogicalHeight() const;
423
424    static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
425    LayoutUnit computePercentageLogicalHeight(const Length& height) const;
426
427    // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
428    virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
429    virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
430    LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
431
432    // There are a few cases where we need to refer specifically to the available physical width and available physical height.
433    // Relative positioning is one of those cases, since left/top offsets are physical.
434    LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
435    LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
436
437    virtual int verticalScrollbarWidth() const;
438    int horizontalScrollbarHeight() const;
439    int instrinsicScrollbarLogicalWidth() const;
440    int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
441    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
442    virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
443    bool canBeScrolledAndHasScrollableArea() const;
444    virtual bool canBeProgramaticallyScrolled() const;
445    virtual void autoscroll(const IntPoint&);
446    bool canAutoscroll() const;
447    IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
448    static RenderBox* findAutoscrollable(RenderObject*);
449    virtual void stopAutoscroll() { }
450    virtual void panScroll(const IntPoint&);
451
452    bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
453    bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
454    bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
455    bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
456    bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
457    bool usesCompositedScrolling() const;
458
459    bool hasUnsplittableScrollingOverflow() const;
460    bool isUnsplittableForPagination() const;
461
462    virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0);
463
464    virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
465    LayoutRect clipRect(const LayoutPoint& location, RenderRegion*);
466    virtual bool hasControlClip() const { return false; }
467    virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
468    bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset);
469    void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
470
471    virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
472    virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
473    virtual void paintMask(PaintInfo&, const LayoutPoint&);
474    virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
475
476    // Called when a positioned object moves but doesn't necessarily change size.  A simplified layout is attempted
477    // that just updates the object's position. If the size does change, the object remains dirty.
478    bool tryLayoutDoingPositionedMovementOnly()
479    {
480        LayoutUnit oldWidth = width();
481        updateLogicalWidth();
482        // If we shrink to fit our width may have changed, so we still need full layout.
483        if (oldWidth != width())
484            return false;
485        updateLogicalHeight();
486        return true;
487    }
488
489    LayoutRect maskClipRect();
490
491    virtual VisiblePosition positionForPoint(const LayoutPoint&);
492
493    void removeFloatingOrPositionedChildFromBlockLists();
494
495    RenderLayer* enclosingFloatPaintingLayer() const;
496
497    virtual int firstLineBoxBaseline() const { return -1; }
498    virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
499
500    bool shrinkToAvoidFloats() const;
501    virtual bool avoidsFloats() const;
502
503    virtual void markForPaginationRelayoutIfNeeded() { }
504
505    bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
506
507    bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
508    bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
509
510    virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
511    virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
512
513    virtual LayoutUnit offsetLeft() const OVERRIDE;
514    virtual LayoutUnit offsetTop() const OVERRIDE;
515
516    LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
517    LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
518    LayoutPoint flipForWritingMode(const LayoutPoint&) const;
519    LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
520    LayoutSize flipForWritingMode(const LayoutSize&) const;
521    void flipForWritingMode(LayoutRect&) const;
522    FloatPoint flipForWritingMode(const FloatPoint&) const;
523    void flipForWritingMode(FloatRect&) const;
524    // These represent your location relative to your container as a physical offset.
525    // In layout related methods you almost always want the logical location (e.g. x() and y()).
526    LayoutPoint topLeftLocation() const;
527    LayoutSize topLeftLocationOffset() const;
528
529    LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
530    LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
531    LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
532    LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
533
534    RenderOverflow* hasRenderOverflow() const { return m_overflow.get(); }
535    bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
536
537    virtual bool needsPreferredWidthsRecalculation() const;
538    virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */, bool& /* isPercentageIntrinsicSize */) const { }
539
540    IntSize scrolledContentOffset() const;
541    LayoutSize cachedSizeForOverflowClip() const;
542    void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
543
544    virtual bool hasRelativeDimensions() const;
545    virtual bool hasRelativeLogicalHeight() const;
546    virtual bool hasViewportPercentageLogicalHeight() const;
547
548    bool hasHorizontalLayoutOverflow() const
549    {
550        if (RenderOverflow* overflow = hasRenderOverflow()) {
551            LayoutRect layoutOverflowRect = overflow->layoutOverflowRect();
552            flipForWritingMode(layoutOverflowRect);
553            return layoutOverflowRect.x() < x() || layoutOverflowRect.maxX() > x() + logicalWidth();
554        }
555
556        return false;
557    }
558
559    bool hasVerticalLayoutOverflow() const
560    {
561        if (RenderOverflow* overflow = hasRenderOverflow()) {
562            LayoutRect layoutOverflowRect = overflow->layoutOverflowRect();
563            flipForWritingMode(layoutOverflowRect);
564            return layoutOverflowRect.y() < y() || layoutOverflowRect.maxY() > y() + logicalHeight();
565        }
566
567        return false;
568    }
569
570    virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
571    {
572        ASSERT_NOT_REACHED();
573        return 0;
574    }
575
576    bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
577
578#if ENABLE(CSS_SHAPES)
579    ShapeOutsideInfo* shapeOutsideInfo() const
580    {
581        return isFloatingWithShapeOutside() && ShapeOutsideInfo::isEnabledFor(this) ? ShapeOutsideInfo::info(this) : 0;
582    }
583#endif
584
585protected:
586    virtual void willBeDestroyed();
587
588    virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
589    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
590    virtual void updateFromStyle() OVERRIDE;
591
592    // Returns false if it could not cheaply compute the extent (e.g. fixed background), in which case the returned rect may be incorrect.
593    bool getBackgroundPaintedExtent(LayoutRect&) const;
594    virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
595    virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
596
597    void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
598
599    void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderObject* backgroundObject);
600    void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
601
602    void paintMaskImages(const PaintInfo&, const LayoutRect&);
603
604    BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
605    bool backgroundHasOpaqueTopLayer() const;
606
607#if PLATFORM(MAC)
608    void paintCustomHighlight(const LayoutPoint&, const AtomicString& type, bool behindText);
609#endif
610
611    void computePositionedLogicalWidth(LogicalExtentComputedValues&, RenderRegion* = 0) const;
612
613    LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
614
615    virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
616
617    virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
618    virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject*, RenderGeometryMap&) const OVERRIDE;
619    virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const;
620
621    void paintRootBoxFillLayers(const PaintInfo&);
622
623    RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
624
625private:
626#if ENABLE(CSS_SHAPES)
627    void updateShapeOutsideInfoAfterStyleChange(const ShapeValue* shapeOutside, const ShapeValue* oldShapeOutside);
628#endif
629
630    bool fixedElementLaysOutRelativeToFrame(Frame*, FrameView*) const;
631
632    bool includeVerticalScrollbarSize() const;
633    bool includeHorizontalScrollbarSize() const;
634
635    // Returns true if we did a full repaint
636    bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground);
637
638    bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
639
640    LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, RenderRegion* = 0, bool checkForPerpendicularWritingMode = true) const;
641    LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
642
643    LayoutUnit viewLogicalHeightForPercentages() const;
644
645    void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
646    void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
647                                            LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
648                                            Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
649                                            LogicalExtentComputedValues&) const;
650    void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
651                                             LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
652                                             Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
653                                             LogicalExtentComputedValues&) const;
654
655    void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
656    void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
657
658    LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
659    LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
660
661    virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
662
663    // This function calculates the minimum and maximum preferred widths for an object.
664    // These values are used in shrink-to-fit layout systems.
665    // These include tables, positioned objects, floats and flexible boxes.
666    virtual void computePreferredLogicalWidths() { setPreferredLogicalWidthsDirty(false); }
667
668    virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE { return frameRect(); }
669
670private:
671    // The width/height of the contents + borders + padding.  The x/y location is relative to our container (which is not always our parent).
672    LayoutRect m_frameRect;
673
674protected:
675    LayoutBoxExtent m_marginBox;
676
677    // The preferred logical width of the element if it were to break its lines at every possible opportunity.
678    LayoutUnit m_minPreferredLogicalWidth;
679
680    // The preferred logical width of the element if it never breaks any lines at all.
681    LayoutUnit m_maxPreferredLogicalWidth;
682
683    // For inline replaced elements, the inline box that owns us.
684    InlineBox* m_inlineBoxWrapper;
685
686    // Our overflow information.
687    OwnPtr<RenderOverflow> m_overflow;
688
689private:
690    // Used to store state between styleWillChange and styleDidChange
691    static bool s_hadOverflowClip;
692};
693
694inline RenderBox* toRenderBox(RenderObject* object)
695{
696    ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isBox());
697    return static_cast<RenderBox*>(object);
698}
699
700inline const RenderBox* toRenderBox(const RenderObject* object)
701{
702    ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isBox());
703    return static_cast<const RenderBox*>(object);
704}
705
706// This will catch anyone doing an unnecessary cast.
707void toRenderBox(const RenderBox*);
708
709inline RenderBox* RenderBox::previousSiblingBox() const
710{
711    return toRenderBox(previousSibling());
712}
713
714inline RenderBox* RenderBox::nextSiblingBox() const
715{
716    return toRenderBox(nextSibling());
717}
718
719inline RenderBox* RenderBox::parentBox() const
720{
721    return toRenderBox(parent());
722}
723
724inline RenderBox* RenderBox::firstChildBox() const
725{
726    return toRenderBox(firstChild());
727}
728
729inline RenderBox* RenderBox::lastChildBox() const
730{
731    return toRenderBox(lastChild());
732}
733
734} // namespace WebCore
735
736#endif // RenderBox_h
737