Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) 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 "core/platform/ScrollTypes.h"
     27 #include "core/rendering/RenderBoxModelObject.h"
     28 #include "core/rendering/RenderOverflow.h"
     29 #include "core/rendering/shapes/ShapeOutsideInfo.h"
     30 
     31 namespace WebCore {
     32 
     33 class RenderBoxRegionInfo;
     34 class RenderRegion;
     35 struct PaintInfo;
     36 
     37 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
     38 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
     39 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
     40 
     41 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
     42 
     43 enum ContentsClipBehavior { ForceContentsClip, SkipContentsClipIfPossible };
     44 
     45 class RenderBox : public RenderBoxModelObject {
     46 public:
     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, LayoutUnit offsetFromLogicalTopOfFirstPage = 0) const;
     86     LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
     87     LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) 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 OVERRIDE FINAL { 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 FINAL;
    167     virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
    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 noOverflowRect() const;
    179     LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect(); }
    180     IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); }
    181     LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); }
    182     LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
    183     LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
    184 
    185     virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
    186     LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
    187     LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
    188 
    189     LayoutRect overflowRectForPaintRejection() const;
    190 
    191     LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
    192 
    193     void addLayoutOverflow(const LayoutRect&);
    194     void addVisualOverflow(const LayoutRect&);
    195 
    196     // Clipped by the contents clip, if one exists.
    197     void addContentsVisualOverflow(const LayoutRect&);
    198 
    199     void addVisualEffectOverflow();
    200     void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
    201     void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
    202     void clearLayoutOverflow();
    203 
    204     void updateLayerTransform();
    205 
    206     LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
    207     LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
    208     LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
    209     LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
    210 
    211     // IE extensions. Used to calculate offsetWidth/Height.  Overridden by inlines (RenderFlow)
    212     // to return the remaining width on a given line (and the height of a single line).
    213     virtual LayoutUnit offsetWidth() const { return width(); }
    214     virtual LayoutUnit offsetHeight() const { return height(); }
    215 
    216     virtual int pixelSnappedOffsetWidth() const OVERRIDE FINAL;
    217     virtual int pixelSnappedOffsetHeight() const OVERRIDE FINAL;
    218 
    219     bool requiresLayoutToDetermineWidth() const;
    220     LayoutUnit fixedOffsetWidth() const;
    221 
    222     // More IE extensions.  clientWidth and clientHeight represent the interior of an object
    223     // excluding border and scrollbar.  clientLeft/Top are just the borderLeftWidth and borderTopWidth.
    224     LayoutUnit clientLeft() const { return borderLeft(); }
    225     LayoutUnit clientTop() const { return borderTop(); }
    226     LayoutUnit clientWidth() const;
    227     LayoutUnit clientHeight() const;
    228     LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
    229     LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
    230     LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
    231     LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
    232 
    233     int pixelSnappedClientWidth() const;
    234     int pixelSnappedClientHeight() const;
    235 
    236     // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
    237     // object has overflow:hidden/scroll/auto specified and also has overflow.
    238     // scrollLeft/Top return the current scroll position.  These methods are virtual so that objects like
    239     // textareas can scroll shadow content (but pretend that they are the objects that are
    240     // scrolling).
    241     virtual int scrollLeft() const;
    242     virtual int scrollTop() const;
    243     virtual int scrollWidth() const;
    244     virtual int scrollHeight() const;
    245     virtual void setScrollLeft(int);
    246     virtual void setScrollTop(int);
    247 
    248     virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
    249     virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
    250     virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
    251     virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
    252     void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
    253     void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
    254     void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
    255     void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
    256 
    257     LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
    258     LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
    259 
    260     virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
    261     virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
    262     virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
    263     {
    264         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
    265         return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
    266     }
    267     virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
    268     {
    269         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
    270         return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
    271     }
    272     void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
    273     void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
    274     void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
    275     {
    276         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
    277         m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
    278     }
    279     void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
    280     {
    281         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
    282         m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
    283     }
    284 
    285     // The following five functions are used to implement collapsing margins.
    286     // All objects know their maximal positive and negative margins.  The
    287     // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
    288     // For a non-collapsing box, such as a leaf element, this formula will simply return
    289     // the margin of the element.  Blocks override the maxMarginBefore and maxMarginAfter
    290     // methods.
    291     enum MarginSign { PositiveMargin, NegativeMargin };
    292     virtual bool isSelfCollapsingBlock() const { return false; }
    293     virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
    294     virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
    295 
    296     virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
    297     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
    298 
    299     LayoutRect reflectionBox() const;
    300     int reflectionOffset() const;
    301     // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
    302     LayoutRect reflectedRect(const LayoutRect&) const;
    303 
    304     virtual void layout();
    305     virtual void paint(PaintInfo&, const LayoutPoint&);
    306     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
    307 
    308     virtual LayoutUnit minPreferredLogicalWidth() const;
    309     virtual LayoutUnit maxPreferredLogicalWidth() const;
    310 
    311     // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
    312     // the border-box height/width like the regular height/width accessors on RenderBox.
    313     // Right now, these are different than contentHeight/contentWidth because they still
    314     // include the scrollbar height/width.
    315     LayoutUnit overrideLogicalContentWidth() const;
    316     LayoutUnit overrideLogicalContentHeight() const;
    317     bool hasOverrideHeight() const;
    318     bool hasOverrideWidth() const;
    319     void setOverrideLogicalContentHeight(LayoutUnit);
    320     void setOverrideLogicalContentWidth(LayoutUnit);
    321     void clearOverrideSize();
    322     void clearOverrideLogicalContentHeight();
    323     void clearOverrideLogicalContentWidth();
    324 
    325     LayoutUnit overrideContainingBlockContentLogicalWidth() const;
    326     LayoutUnit overrideContainingBlockContentLogicalHeight() const;
    327     bool hasOverrideContainingBlockLogicalWidth() const;
    328     bool hasOverrideContainingBlockLogicalHeight() const;
    329     void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
    330     void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
    331     void clearContainingBlockOverrideSize();
    332     void clearOverrideContainingBlockContentLogicalHeight();
    333 
    334     virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const;
    335 
    336     LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
    337     LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
    338     LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
    339     LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
    340 
    341     struct ComputedMarginValues {
    342         ComputedMarginValues()
    343             : m_before(0)
    344             , m_after(0)
    345             , m_start(0)
    346             , m_end(0)
    347         {
    348         }
    349         LayoutUnit m_before;
    350         LayoutUnit m_after;
    351         LayoutUnit m_start;
    352         LayoutUnit m_end;
    353     };
    354     struct LogicalExtentComputedValues {
    355         LogicalExtentComputedValues()
    356             : m_extent(0)
    357             , m_position(0)
    358         {
    359         }
    360 
    361         LayoutUnit m_extent;
    362         LayoutUnit m_position;
    363         ComputedMarginValues m_margins;
    364     };
    365     // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
    366     // of the containing block.
    367     void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
    368 
    369     // Used to resolve margins in the containing block's block-flow direction.
    370     void computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
    371     void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
    372 
    373     enum RenderBoxRegionInfoFlags { CacheRenderBoxRegionInfo, DoNotCacheRenderBoxRegionInfo };
    374     LayoutRect borderBoxRectInRegion(RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage = 0, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
    375     void clearRenderBoxRegionInfo();
    376 
    377     void positionLineBox(InlineBox*);
    378 
    379     virtual InlineBox* createInlineBox();
    380     void dirtyLineBoxes(bool fullLayout);
    381 
    382     // For inline replaced elements, this function returns the inline box that owns us.  Enables
    383     // the replaced RenderObject to quickly determine what line it is contained on and to easily
    384     // iterate over structures on the line.
    385     InlineBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
    386     void setInlineBoxWrapper(InlineBox*);
    387     void deleteLineBoxWrapper();
    388 
    389     virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
    390     virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const OVERRIDE;
    391     void repaintDuringLayoutIfMoved(const LayoutRect&);
    392     virtual void repaintOverhangingFloats(bool paintAllDescendants);
    393 
    394     virtual LayoutUnit containingBlockLogicalWidthForContent() const;
    395     LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
    396 
    397     LayoutUnit containingBlockLogicalWidthForContentInRegion(RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage) const;
    398     LayoutUnit containingBlockAvailableLineWidthInRegion(RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage) const;
    399     LayoutUnit perpendicularContainingBlockLogicalHeight() const;
    400 
    401     virtual void updateLogicalWidth();
    402     virtual void updateLogicalHeight();
    403     virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
    404 
    405     RenderBoxRegionInfo* renderBoxRegionInfo(RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
    406     void computeLogicalWidthInRegion(LogicalExtentComputedValues&, RenderRegion* = 0, LayoutUnit offsetFromLogicalTopOfFirstPage = 0) const;
    407 
    408     bool stretchesToViewport() const
    409     {
    410         return document()->inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isRoot() || isBody()) && !document()->shouldDisplaySeamlesslyWithParent() && !isInline();
    411     }
    412 
    413     virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
    414     LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
    415     LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
    416 
    417     // Whether or not the element shrinks to its intrinsic width (rather than filling the width
    418     // of a containing block).  HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
    419     bool sizesLogicalWidthToFitContent(SizeType) const;
    420 
    421     LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlock* cb, RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage) const;
    422 
    423     LayoutUnit computeLogicalWidthInRegionUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock, RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage) const;
    424     LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
    425     LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const;
    426     LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
    427     LayoutUnit computeReplacedLogicalWidthUsing(Length width) const;
    428     LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred  = ComputeActual) const;
    429     LayoutUnit computeReplacedLogicalHeightUsing(Length height) const;
    430     LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
    431 
    432     virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred  = ComputeActual) const;
    433     virtual LayoutUnit computeReplacedLogicalHeight() const;
    434 
    435     static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
    436     LayoutUnit computePercentageLogicalHeight(const Length& height) const;
    437 
    438     // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
    439     virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
    440     virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
    441     LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
    442 
    443     // There are a few cases where we need to refer specifically to the available physical width and available physical height.
    444     // Relative positioning is one of those cases, since left/top offsets are physical.
    445     LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
    446     LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
    447 
    448     virtual int verticalScrollbarWidth() const;
    449     int horizontalScrollbarHeight() const;
    450     int instrinsicScrollbarLogicalWidth() const;
    451     int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
    452     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
    453     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
    454     bool canBeScrolledAndHasScrollableArea() const;
    455     virtual bool canBeProgramaticallyScrolled() const;
    456     virtual void autoscroll(const IntPoint&);
    457     bool autoscrollInProgress() const;
    458     bool canAutoscroll() const;
    459     IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
    460     static RenderBox* findAutoscrollable(RenderObject*);
    461     virtual void stopAutoscroll() { }
    462     virtual void panScroll(const IntPoint&);
    463 
    464     bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
    465     bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
    466     bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
    467     bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
    468     bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
    469     bool usesCompositedScrolling() const;
    470 
    471     bool hasUnsplittableScrollingOverflow() const;
    472     bool isUnsplittableForPagination() const;
    473 
    474     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0);
    475 
    476     virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
    477     LayoutRect clipRect(const LayoutPoint& location, RenderRegion*);
    478     virtual bool hasControlClip() const { return false; }
    479     virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
    480     bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset, ContentsClipBehavior);
    481     void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
    482 
    483     virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
    484     virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
    485     virtual void paintMask(PaintInfo&, const LayoutPoint&);
    486     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
    487 
    488     // Called when a positioned object moves but doesn't necessarily change size.  A simplified layout is attempted
    489     // that just updates the object's position. If the size does change, the object remains dirty.
    490     bool tryLayoutDoingPositionedMovementOnly()
    491     {
    492         LayoutUnit oldWidth = width();
    493         updateLogicalWidth();
    494         // If we shrink to fit our width may have changed, so we still need full layout.
    495         if (oldWidth != width())
    496             return false;
    497         updateLogicalHeight();
    498         return true;
    499     }
    500 
    501     LayoutRect maskClipRect();
    502 
    503     virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
    504 
    505     void removeFloatingOrPositionedChildFromBlockLists();
    506 
    507     RenderLayer* enclosingFloatPaintingLayer() const;
    508 
    509     virtual int firstLineBoxBaseline() const { return -1; }
    510     virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
    511 
    512     bool shrinkToAvoidFloats() const;
    513     virtual bool avoidsFloats() const;
    514 
    515     virtual void markForPaginationRelayoutIfNeeded() { }
    516 
    517     bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
    518 
    519     bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
    520     bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
    521 
    522     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
    523     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
    524 
    525     virtual LayoutUnit offsetLeft() const OVERRIDE;
    526     virtual LayoutUnit offsetTop() const OVERRIDE;
    527 
    528     LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
    529     LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
    530     LayoutPoint flipForWritingMode(const LayoutPoint&) const;
    531     LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
    532     LayoutSize flipForWritingMode(const LayoutSize&) const;
    533     void flipForWritingMode(LayoutRect&) const;
    534     FloatPoint flipForWritingMode(const FloatPoint&) const;
    535     void flipForWritingMode(FloatRect&) const;
    536     // These represent your location relative to your container as a physical offset.
    537     // In layout related methods you almost always want the logical location (e.g. x() and y()).
    538     LayoutPoint topLeftLocation() const;
    539     LayoutSize topLeftLocationOffset() const;
    540 
    541     LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
    542     LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
    543     LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
    544     LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
    545 
    546     bool hasRenderOverflow() const { return m_overflow; }
    547     bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
    548 
    549     virtual bool needsPreferredWidthsRecalculation() const;
    550     virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */, bool& /* isPercentageIntrinsicSize */) const { }
    551 
    552     IntSize scrolledContentOffset() const;
    553     LayoutSize cachedSizeForOverflowClip() const;
    554     void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
    555 
    556     virtual bool hasRelativeDimensions() const;
    557     virtual bool hasRelativeLogicalHeight() const;
    558 
    559     bool hasHorizontalLayoutOverflow() const
    560     {
    561         if (!m_overflow)
    562             return false;
    563 
    564         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
    565         LayoutRect noOverflowRect = this->noOverflowRect();
    566         return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
    567     }
    568 
    569     bool hasVerticalLayoutOverflow() const
    570     {
    571         if (!m_overflow)
    572             return false;
    573 
    574         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
    575         LayoutRect noOverflowRect = this->noOverflowRect();
    576         return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
    577     }
    578 
    579     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
    580     {
    581         ASSERT_NOT_REACHED();
    582         return 0;
    583     }
    584 
    585     bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
    586 
    587     ShapeOutsideInfo* shapeOutsideInfo() const
    588     {
    589         return isFloatingWithShapeOutside() && ShapeOutsideInfo::isEnabledFor(this) ? ShapeOutsideInfo::info(this) : 0;
    590     }
    591 
    592 protected:
    593     virtual void willBeDestroyed();
    594 
    595     virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
    596     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
    597     virtual void updateFromStyle() OVERRIDE;
    598 
    599     LayoutRect backgroundPaintedExtent() const;
    600     virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
    601     virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
    602 
    603     void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
    604 
    605     void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderObject* backgroundObject);
    606     void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
    607 
    608     void paintMaskImages(const PaintInfo&, const LayoutRect&);
    609 
    610     BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
    611     bool backgroundHasOpaqueTopLayer() const;
    612 
    613     void computePositionedLogicalWidth(LogicalExtentComputedValues&, RenderRegion* = 0, LayoutUnit offsetFromLogicalTopOfFirstPage = 0) const;
    614 
    615     LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
    616     LayoutUnit computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
    617 
    618     virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
    619 
    620     virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
    621     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const;
    622 
    623     void paintRootBoxFillLayers(const PaintInfo&);
    624 
    625     RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
    626 
    627     virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const OVERRIDE;
    628     virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
    629 
    630 private:
    631     void updateShapeOutsideInfoAfterStyleChange(const ShapeValue* shapeOutside, const ShapeValue* oldShapeOutside);
    632     void updateGridPositionAfterStyleChange(const RenderStyle*);
    633 
    634     bool includeVerticalScrollbarSize() const;
    635     bool includeHorizontalScrollbarSize() const;
    636 
    637     // Returns true if we did a full repaint
    638     bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground);
    639 
    640     bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
    641 
    642     LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, RenderRegion* = 0,
    643         LayoutUnit offsetFromLogicalTopOfFirstPage = 0, bool checkForPerpendicularWritingMode = true) const;
    644     LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
    645 
    646     LayoutUnit viewLogicalHeightForPercentages() const;
    647 
    648     void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
    649     void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
    650                                             LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
    651                                             Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
    652                                             LogicalExtentComputedValues&) const;
    653     void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
    654                                              LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
    655                                              Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
    656                                              LogicalExtentComputedValues&) const;
    657 
    658     void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
    659     void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
    660 
    661     LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
    662     LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
    663 
    664     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
    665 
    666     // This function calculates the minimum and maximum preferred widths for an object.
    667     // These values are used in shrink-to-fit layout systems.
    668     // These include tables, positioned objects, floats and flexible boxes.
    669     virtual void computePreferredLogicalWidths() { setPreferredLogicalWidthsDirty(false); }
    670 
    671     virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE FINAL { return frameRect(); }
    672 
    673 private:
    674     // The width/height of the contents + borders + padding.  The x/y location is relative to our container (which is not always our parent).
    675     LayoutRect m_frameRect;
    676 
    677 protected:
    678     LayoutBoxExtent m_marginBox;
    679 
    680     // The preferred logical width of the element if it were to break its lines at every possible opportunity.
    681     LayoutUnit m_minPreferredLogicalWidth;
    682 
    683     // The preferred logical width of the element if it never breaks any lines at all.
    684     LayoutUnit m_maxPreferredLogicalWidth;
    685 
    686     // Our intrinsic height, used for min-height: min-content etc. Maintained by
    687     // updateLogicalHeight. This is logicalHeight() before it is clamped to
    688     // min/max.
    689     LayoutUnit m_intrinsicContentLogicalHeight;
    690 
    691     // For inline replaced elements, the inline box that owns us.
    692     InlineBox* m_inlineBoxWrapper;
    693 
    694     // Our overflow information.
    695     OwnPtr<RenderOverflow> m_overflow;
    696 
    697 private:
    698     // Used to store state between styleWillChange and styleDidChange
    699     static bool s_hadOverflowClip;
    700 };
    701 
    702 inline RenderBox* toRenderBox(RenderObject* object)
    703 {
    704     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isBox());
    705     return static_cast<RenderBox*>(object);
    706 }
    707 
    708 inline const RenderBox* toRenderBox(const RenderObject* object)
    709 {
    710     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isBox());
    711     return static_cast<const RenderBox*>(object);
    712 }
    713 
    714 // This will catch anyone doing an unnecessary cast.
    715 void toRenderBox(const RenderBox*);
    716 
    717 inline RenderBox* RenderBox::previousSiblingBox() const
    718 {
    719     return toRenderBox(previousSibling());
    720 }
    721 
    722 inline RenderBox* RenderBox::nextSiblingBox() const
    723 {
    724     return toRenderBox(nextSibling());
    725 }
    726 
    727 inline RenderBox* RenderBox::parentBox() const
    728 {
    729     return toRenderBox(parent());
    730 }
    731 
    732 inline RenderBox* RenderBox::firstChildBox() const
    733 {
    734     return toRenderBox(firstChild());
    735 }
    736 
    737 inline RenderBox* RenderBox::lastChildBox() const
    738 {
    739     return toRenderBox(lastChild());
    740 }
    741 
    742 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper)
    743 {
    744     if (boxWrapper) {
    745         ASSERT(!m_inlineBoxWrapper);
    746         // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues.
    747         // Otherwise, there will two line box wrappers keeping the reference to this renderer, and
    748         // only one will be notified when the renderer is getting destroyed. The second line box wrapper
    749         // will keep a stale reference.
    750         if (UNLIKELY(m_inlineBoxWrapper != 0))
    751             deleteLineBoxWrapper();
    752     }
    753 
    754     m_inlineBoxWrapper = boxWrapper;
    755 }
    756 
    757 } // namespace WebCore
    758 
    759 #endif // RenderBox_h
    760