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 * 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 RenderBoxModelObject_h 24 #define RenderBoxModelObject_h 25 26 #include "RenderObject.h" 27 28 namespace WebCore { 29 30 // Values for vertical alignment. 31 const int PositionTop = -0x7fffffff; 32 const int PositionBottom = 0x7fffffff; 33 const int PositionUndefined = 0x80000000; 34 35 // This class is the base for all objects that adhere to the CSS box model as described 36 // at http://www.w3.org/TR/CSS21/box.html 37 38 class RenderBoxModelObject : public RenderObject { 39 public: 40 RenderBoxModelObject(Node*); 41 virtual ~RenderBoxModelObject(); 42 43 virtual void destroy(); 44 45 int relativePositionOffsetX() const; 46 int relativePositionOffsetY() const; 47 IntSize relativePositionOffset() const { return IntSize(relativePositionOffsetX(), relativePositionOffsetY()); } 48 49 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow) 50 // to return the remaining width on a given line (and the height of a single line). 51 virtual int offsetLeft() const; 52 virtual int offsetTop() const; 53 virtual int offsetWidth() const = 0; 54 virtual int offsetHeight() const = 0; 55 56 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle); 57 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); 58 virtual void updateBoxModelInfoFromStyle(); 59 60 bool hasSelfPaintingLayer() const; 61 RenderLayer* layer() const { return m_layer; } 62 virtual bool requiresLayer() const { return isRoot() || isPositioned() || isRelPositioned() || isTransparent() || hasOverflowClip() || hasTransform() || hasMask() || hasReflection(); } 63 64 // This will work on inlines to return the bounding box of all of the lines' border boxes. 65 virtual IntRect borderBoundingBox() const = 0; 66 67 // Virtual since table cells override 68 virtual int paddingTop(bool includeIntrinsicPadding = true) const; 69 virtual int paddingBottom(bool includeIntrinsicPadding = true) const; 70 virtual int paddingLeft(bool includeIntrinsicPadding = true) const; 71 virtual int paddingRight(bool includeIntrinsicPadding = true) const; 72 73 virtual int borderTop() const { return style()->borderTopWidth(); } 74 virtual int borderBottom() const { return style()->borderBottomWidth(); } 75 virtual int borderLeft() const { return style()->borderLeftWidth(); } 76 virtual int borderRight() const { return style()->borderRightWidth(); } 77 78 virtual int marginTop() const = 0; 79 virtual int marginBottom() const = 0; 80 virtual int marginLeft() const = 0; 81 virtual int marginRight() const = 0; 82 83 bool hasHorizontalBordersPaddingOrMargin() const { return hasHorizontalBordersOrPadding() || marginLeft() != 0 || marginRight() != 0; } 84 bool hasHorizontalBordersOrPadding() const { return borderLeft() != 0 || borderRight() != 0 || paddingLeft() != 0 || paddingRight() != 0; } 85 86 virtual int containingBlockWidthForContent() const; 87 88 virtual void childBecameNonInline(RenderObject* /*child*/) { } 89 90 void paintBorder(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, bool begin = true, bool end = true); 91 bool paintNinePieceImage(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, const NinePieceImage&, CompositeOperator = CompositeSourceOver); 92 void paintBoxShadow(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, ShadowStyle, bool begin = true, bool end = true); 93 void paintFillLayerExtended(const PaintInfo&, const Color&, const FillLayer*, int tx, int ty, int width, int height, InlineFlowBox* = 0, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0); 94 95 // The difference between this inline's baseline position and the line's baseline position. 96 int verticalPosition(bool firstLine) const; 97 98 // Called by RenderObject::destroy() (and RenderWidget::destroy()) and is the only way layers should ever be destroyed 99 void destroyLayer(); 100 101 void highQualityRepaintTimerFired(Timer<RenderBoxModelObject>*); 102 103 protected: 104 void calculateBackgroundImageGeometry(const FillLayer*, int tx, int ty, int w, int h, IntRect& destRect, IntPoint& phase, IntSize& tileSize); 105 106 private: 107 virtual bool isBoxModelObject() const { return true; } 108 109 IntSize calculateFillTileSize(const FillLayer*, IntSize scaledSize) const; 110 111 friend class RenderView; 112 113 RenderLayer* m_layer; 114 115 // Used to store state between styleWillChange and styleDidChange 116 static bool s_wasFloating; 117 static bool s_hadLayer; 118 static bool s_layerWasSelfPainting; 119 }; 120 121 inline RenderBoxModelObject* toRenderBoxModelObject(RenderObject* object) 122 { 123 ASSERT(!object || object->isBoxModelObject()); 124 return static_cast<RenderBoxModelObject*>(object); 125 } 126 127 inline const RenderBoxModelObject* toRenderBoxModelObject(const RenderObject* object) 128 { 129 ASSERT(!object || object->isBoxModelObject()); 130 return static_cast<const RenderBoxModelObject*>(object); 131 } 132 133 // This will catch anyone doing an unnecessary cast. 134 void toRenderBoxModelObject(const RenderBoxModelObject*); 135 136 } // namespace WebCore 137 138 #endif // RenderBoxModelObject_h 139