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, 2009 Apple Inc. All rights reserved.
      5  * Copyright (C) 2010 Google Inc. All rights reserved.
      6  *
      7  * This library is free software; you can redistribute it and/or
      8  * modify it under the terms of the GNU Library General Public
      9  * License as published by the Free Software Foundation; either
     10  * version 2 of the License, or (at your option) any later version.
     11  *
     12  * This library is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  * Library General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU Library General Public License
     18  * along with this library; see the file COPYING.LIB.  If not, write to
     19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     20  * Boston, MA 02110-1301, USA.
     21  *
     22  */
     23 
     24 #ifndef RenderBoxModelObject_h
     25 #define RenderBoxModelObject_h
     26 
     27 #include "core/rendering/RenderLayerModelObject.h"
     28 #include "core/rendering/style/ShadowData.h"
     29 #include "platform/geometry/LayoutRect.h"
     30 
     31 namespace blink {
     32 
     33 // Modes for some of the line-related functions.
     34 enum LinePositionMode { PositionOnContainingLine, PositionOfInteriorLineBoxes };
     35 enum LineDirectionMode { HorizontalLine, VerticalLine };
     36 typedef unsigned BorderEdgeFlags;
     37 
     38 enum BackgroundBleedAvoidance {
     39     BackgroundBleedNone,
     40     BackgroundBleedShrinkBackground,
     41     BackgroundBleedClipBackground,
     42     BackgroundBleedBackgroundOverBorder
     43 };
     44 
     45 enum ContentChangeType {
     46     ImageChanged,
     47     CanvasChanged,
     48     CanvasContextChanged
     49 };
     50 
     51 class RenderTextFragment;
     52 class BackgroundImageGeometry;
     53 
     54 // This class is the base for all objects that adhere to the CSS box model as described
     55 // at http://www.w3.org/TR/CSS21/box.html
     56 
     57 class RenderBoxModelObject : public RenderLayerModelObject {
     58 public:
     59     RenderBoxModelObject(ContainerNode*);
     60     virtual ~RenderBoxModelObject();
     61 
     62     LayoutSize relativePositionOffset() const;
     63     LayoutSize relativePositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? relativePositionOffset() : relativePositionOffset().transposedSize(); }
     64 
     65     LayoutSize offsetForInFlowPosition() const;
     66 
     67     // IE extensions. Used to calculate offsetWidth/Height.  Overridden by inlines (RenderFlow)
     68     // to return the remaining width on a given line (and the height of a single line).
     69     virtual LayoutUnit offsetLeft() const;
     70     virtual LayoutUnit offsetTop() const;
     71     virtual LayoutUnit offsetWidth() const = 0;
     72     virtual LayoutUnit offsetHeight() const = 0;
     73 
     74     int pixelSnappedOffsetLeft() const { return roundToInt(offsetLeft()); }
     75     int pixelSnappedOffsetTop() const { return roundToInt(offsetTop()); }
     76     virtual int pixelSnappedOffsetWidth() const;
     77     virtual int pixelSnappedOffsetHeight() const;
     78 
     79     virtual void updateFromStyle() OVERRIDE;
     80 
     81     // This will work on inlines to return the bounding box of all of the lines' border boxes.
     82     virtual IntRect borderBoundingBox() const = 0;
     83 
     84     // These return the CSS computed padding values.
     85     LayoutUnit computedCSSPaddingTop() const { return computedCSSPadding(style()->paddingTop()); }
     86     LayoutUnit computedCSSPaddingBottom() const { return computedCSSPadding(style()->paddingBottom()); }
     87     LayoutUnit computedCSSPaddingLeft() const { return computedCSSPadding(style()->paddingLeft()); }
     88     LayoutUnit computedCSSPaddingRight() const { return computedCSSPadding(style()->paddingRight()); }
     89     LayoutUnit computedCSSPaddingBefore() const { return computedCSSPadding(style()->paddingBefore()); }
     90     LayoutUnit computedCSSPaddingAfter() const { return computedCSSPadding(style()->paddingAfter()); }
     91     LayoutUnit computedCSSPaddingStart() const { return computedCSSPadding(style()->paddingStart()); }
     92     LayoutUnit computedCSSPaddingEnd() const { return computedCSSPadding(style()->paddingEnd()); }
     93 
     94     // These functions are used during layout. Table cells
     95     // override them to include some extra intrinsic padding.
     96     virtual LayoutUnit paddingTop() const { return computedCSSPaddingTop(); }
     97     virtual LayoutUnit paddingBottom() const { return computedCSSPaddingBottom(); }
     98     virtual LayoutUnit paddingLeft() const { return computedCSSPaddingLeft(); }
     99     virtual LayoutUnit paddingRight() const { return computedCSSPaddingRight(); }
    100     virtual LayoutUnit paddingBefore() const { return computedCSSPaddingBefore(); }
    101     virtual LayoutUnit paddingAfter() const { return computedCSSPaddingAfter(); }
    102     virtual LayoutUnit paddingStart() const { return computedCSSPaddingStart(); }
    103     virtual LayoutUnit paddingEnd() const { return computedCSSPaddingEnd(); }
    104 
    105     virtual int borderTop() const { return style()->borderTopWidth(); }
    106     virtual int borderBottom() const { return style()->borderBottomWidth(); }
    107     virtual int borderLeft() const { return style()->borderLeftWidth(); }
    108     virtual int borderRight() const { return style()->borderRightWidth(); }
    109     virtual int borderBefore() const { return style()->borderBeforeWidth(); }
    110     virtual int borderAfter() const { return style()->borderAfterWidth(); }
    111     virtual int borderStart() const { return style()->borderStartWidth(); }
    112     virtual int borderEnd() const { return style()->borderEndWidth(); }
    113 
    114     int borderWidth() const { return borderLeft() + borderRight(); }
    115     int borderHeight() const { return borderTop() + borderBottom(); }
    116 
    117     LayoutUnit borderAndPaddingStart() const { return borderStart() + paddingStart(); }
    118     LayoutUnit borderAndPaddingBefore() const { return borderBefore() + paddingBefore(); }
    119     LayoutUnit borderAndPaddingAfter() const { return borderAfter() + paddingAfter(); }
    120 
    121     LayoutUnit borderAndPaddingHeight() const { return borderTop() + borderBottom() + paddingTop() + paddingBottom(); }
    122     LayoutUnit borderAndPaddingWidth() const { return borderLeft() + borderRight() + paddingLeft() + paddingRight(); }
    123     LayoutUnit borderAndPaddingLogicalHeight() const { return borderAndPaddingBefore() + borderAndPaddingAfter(); }
    124     LayoutUnit borderAndPaddingLogicalWidth() const { return borderStart() + borderEnd() + paddingStart() + paddingEnd(); }
    125     LayoutUnit borderAndPaddingLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() + paddingLeft() : borderTop() + paddingTop(); }
    126 
    127 
    128     LayoutUnit borderLogicalLeft() const { return style()->isHorizontalWritingMode() ? borderLeft() : borderTop(); }
    129     LayoutUnit borderLogicalRight() const { return style()->isHorizontalWritingMode() ? borderRight() : borderBottom(); }
    130     LayoutUnit borderLogicalWidth() const { return borderStart() + borderEnd(); }
    131     LayoutUnit borderLogicalHeight() const { return borderBefore() + borderAfter(); }
    132 
    133     LayoutUnit paddingLogicalLeft() const { return style()->isHorizontalWritingMode() ? paddingLeft() : paddingTop(); }
    134     LayoutUnit paddingLogicalRight() const { return style()->isHorizontalWritingMode() ? paddingRight() : paddingBottom(); }
    135     LayoutUnit paddingLogicalWidth() const { return paddingStart() + paddingEnd(); }
    136     LayoutUnit paddingLogicalHeight() const { return paddingBefore() + paddingAfter(); }
    137 
    138     virtual LayoutUnit marginTop() const = 0;
    139     virtual LayoutUnit marginBottom() const = 0;
    140     virtual LayoutUnit marginLeft() const = 0;
    141     virtual LayoutUnit marginRight() const = 0;
    142     virtual LayoutUnit marginBefore(const RenderStyle* otherStyle = 0) const = 0;
    143     virtual LayoutUnit marginAfter(const RenderStyle* otherStyle = 0) const = 0;
    144     virtual LayoutUnit marginStart(const RenderStyle* otherStyle = 0) const = 0;
    145     virtual LayoutUnit marginEnd(const RenderStyle* otherStyle = 0) const = 0;
    146     LayoutUnit marginHeight() const { return marginTop() + marginBottom(); }
    147     LayoutUnit marginWidth() const { return marginLeft() + marginRight(); }
    148     LayoutUnit marginLogicalHeight() const { return marginBefore() + marginAfter(); }
    149     LayoutUnit marginLogicalWidth() const { return marginStart() + marginEnd(); }
    150 
    151     bool hasInlineDirectionBordersPaddingOrMargin() const { return hasInlineDirectionBordersOrPadding() || marginStart()|| marginEnd(); }
    152     bool hasInlineDirectionBordersOrPadding() const { return borderStart() || borderEnd() || paddingStart()|| paddingEnd(); }
    153 
    154     virtual LayoutUnit containingBlockLogicalWidthForContent() const;
    155 
    156     virtual void childBecameNonInline(RenderObject* /*child*/) { }
    157 
    158     virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox* = 0) const;
    159 
    160     // Overridden by subclasses to determine line height and baseline position.
    161     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
    162     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
    163 
    164     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
    165     virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE;
    166 
    167     virtual void setSelectionState(SelectionState) OVERRIDE;
    168 
    169     void contentChanged(ContentChangeType);
    170     bool hasAcceleratedCompositing() const;
    171 
    172     virtual void computeLayerHitTestRects(LayerHitTestRects&) const OVERRIDE;
    173 
    174 protected:
    175     virtual void willBeDestroyed() OVERRIDE;
    176 
    177     LayoutPoint adjustedPositionRelativeToOffsetParent(const LayoutPoint&) const;
    178 
    179     bool calculateHasBoxDecorations() const;
    180 
    181     RenderBoxModelObject* continuation() const;
    182     void setContinuation(RenderBoxModelObject*);
    183 
    184     LayoutRect localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset);
    185 
    186     bool hasAutoHeightOrContainingBlockWithAutoHeight() const;
    187 
    188 public:
    189 
    190     // For RenderBlocks and RenderInlines with m_style->styleType() == FIRST_LETTER, this tracks their remaining text fragments
    191     RenderTextFragment* firstLetterRemainingText() const;
    192     void setFirstLetterRemainingText(RenderTextFragment*);
    193 
    194     // These functions are only used internally to manipulate the render tree structure via remove/insert/appendChildNode.
    195     // Since they are typically called only to move objects around within anonymous blocks (which only have layers in
    196     // the case of column spans), the default for fullRemoveInsert is false rather than true.
    197     void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, bool fullRemoveInsert = false);
    198     void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, bool fullRemoveInsert = false)
    199     {
    200         moveChildTo(toBoxModelObject, child, 0, fullRemoveInsert);
    201     }
    202     void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, bool fullRemoveInsert = false)
    203     {
    204         moveAllChildrenTo(toBoxModelObject, 0, fullRemoveInsert);
    205     }
    206     void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* beforeChild, bool fullRemoveInsert = false)
    207     {
    208         moveChildrenTo(toBoxModelObject, slowFirstChild(), 0, beforeChild, fullRemoveInsert);
    209     }
    210     // Move all of the kids from |startChild| up to but excluding |endChild|. 0 can be passed as the |endChild| to denote
    211     // that all the kids from |startChild| onwards should be moved.
    212     void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, bool fullRemoveInsert = false)
    213     {
    214         moveChildrenTo(toBoxModelObject, startChild, endChild, 0, fullRemoveInsert);
    215     }
    216     void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, bool fullRemoveInsert = false);
    217 
    218     enum ScaleByEffectiveZoomOrNot { ScaleByEffectiveZoom, DoNotScaleByEffectiveZoom };
    219     IntSize calculateImageIntrinsicDimensions(StyleImage*, const IntSize& scaledPositioningAreaSize, ScaleByEffectiveZoomOrNot) const;
    220 
    221 private:
    222     LayoutUnit computedCSSPadding(const Length&) const;
    223     virtual bool isBoxModelObject() const OVERRIDE FINAL { return true; }
    224 };
    225 
    226 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBoxModelObject, isBoxModelObject());
    227 
    228 } // namespace blink
    229 
    230 #endif // RenderBoxModelObject_h
    231