File indexing completed on 2025-02-02 14:13:08
0001 /* 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) 0005 * (C) 1999 Antti Koivisto (koivisto@kde.org) 0006 * (C) 2002-2003 Apple Computer, Inc. 0007 * 0008 * This library is free software; you can redistribute it and/or 0009 * modify it under the terms of the GNU Library General Public 0010 * License as published by the Free Software Foundation; either 0011 * version 2 of the License, or (at your option) any later version. 0012 * 0013 * This library is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 * Library General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU Library General Public License 0019 * along with this library; see the file COPYING.LIB. If not, write to 0020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 * 0023 */ 0024 #ifndef RENDER_BOX_H 0025 #define RENDER_BOX_H 0026 0027 #include "render_container.h" 0028 0029 namespace khtml 0030 { 0031 0032 enum WidthType { Width, MinWidth, MaxWidth }; 0033 enum HeightType { Height, MinHeight, MaxHeight }; 0034 0035 class RenderBlock; 0036 class RenderTableCell; 0037 0038 class RenderBox : public RenderContainer 0039 { 0040 friend class RenderTableCell; 0041 0042 // combines ElemImpl & PosElImpl (all rendering objects are positioned) 0043 // should contain all border and padding handling 0044 0045 public: 0046 RenderBox(DOM::NodeImpl *node); 0047 virtual ~RenderBox(); 0048 0049 const char *renderName() const override 0050 { 0051 return "RenderBox"; 0052 } 0053 bool isBox() const override 0054 { 0055 return true; 0056 } 0057 0058 void setStyle(RenderStyle *style) override; 0059 void paint(PaintInfo &i, int _tx, int _ty) override; 0060 0061 void close() override; 0062 0063 InlineBox *createInlineBox(bool makePlaceHolderBox, bool isRootLineBox) override; 0064 void deleteInlineBoxes(RenderArena *arena = nullptr) override; 0065 void dirtyInlineBoxes(bool fullLayout, bool isRootLineBox = false) override; 0066 void removeInlineBox(InlineBox *_box) override 0067 { 0068 if (m_placeHolderBox == _box) { 0069 m_placeHolderBox = nullptr; 0070 } 0071 } 0072 0073 void removeChild(RenderObject *) override; 0074 0075 void detach() override; 0076 0077 short minWidth() const override 0078 { 0079 return m_minWidth; 0080 } 0081 int maxWidth() const override 0082 { 0083 return m_maxWidth; 0084 } 0085 0086 short contentWidth() const override; 0087 int contentHeight() const override; 0088 0089 bool absolutePosition(int &xPos, int &yPos, bool f = false) const override; 0090 0091 void setPos(int xPos, int yPos) override; 0092 0093 int xPos() const override 0094 { 0095 return m_x; 0096 } 0097 int yPos() const override 0098 { 0099 return m_y; 0100 } 0101 short width() const override; 0102 int height() const override; 0103 0104 short marginTop() const override 0105 { 0106 return m_marginTop; 0107 } 0108 short marginBottom() const override 0109 { 0110 return m_marginBottom; 0111 } 0112 short marginLeft() const override 0113 { 0114 return m_marginLeft; 0115 } 0116 short marginRight() const override 0117 { 0118 return m_marginRight; 0119 } 0120 0121 void setWidth(int width) override; 0122 void setHeight(int height) override; 0123 0124 void position(InlineBox *box, int from, int len, bool reverse) override; 0125 0126 int highestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const override; 0127 int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const override; 0128 int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const override; 0129 int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const override; 0130 0131 void repaint(Priority p = NormalPriority) override; 0132 0133 void repaintRectangle(int x, int y, int w, int h, Priority p = NormalPriority, bool f = false) override; 0134 0135 short containingBlockWidth(RenderObject *providedCB = nullptr) const override; 0136 void relativePositionOffset(int &tx, int &ty) const; 0137 0138 void calcWidth() override; 0139 void calcHeight() override; 0140 0141 virtual short calcReplacedWidth() const; 0142 virtual int calcReplacedHeight() const; 0143 0144 int availableHeight() const override; 0145 virtual int availableWidth() const; 0146 0147 void calcVerticalMargins() override; 0148 0149 RenderLayer *layer() const override 0150 { 0151 return m_layer; 0152 } 0153 0154 void setStaticX(short staticX); 0155 void setStaticY(int staticY); 0156 int staticX() const 0157 { 0158 return m_staticX; 0159 } 0160 int staticY() const 0161 { 0162 return m_staticY; 0163 } 0164 0165 void caretPos(int offset, int flags, int &_x, int &_y, int &width, int &height) const override; 0166 0167 void calcHorizontalMargins(const Length &ml, const Length &mr, int cw); 0168 RenderBlock *createAnonymousBlock(); 0169 0170 int pageTopAfter(int y) const override; 0171 int crossesPageBreak(int t, int b) const override; 0172 0173 bool handleEvent(const DOM::EventImpl &ev) override; 0174 0175 int calcBoxWidth(int w) const; 0176 int calcBoxHeight(int h) const; 0177 virtual int calcContentWidth(int w) const; 0178 virtual int calcContentHeight(int h) const; 0179 0180 InlineBox *placeHolderBox() 0181 { 0182 return m_placeHolderBox; 0183 } 0184 void setPlaceHolderBox(InlineBox *placeHolder) 0185 { 0186 m_placeHolderBox = placeHolder; /* assert !m_placeHolderBox */ 0187 } 0188 QRect getFixedBackgroundImageRect(const BackgroundLayer *bglayer, int &sx, int &sy, int &scaledImageWidth, int &scaledImageHeight); 0189 0190 protected: 0191 int calcWidthUsing(WidthType widthType, int cw, LengthType &lengthType); 0192 int calcHeightUsing(const Length &height); 0193 int calcReplacedWidthUsing(WidthType widthType) const; 0194 int calcReplacedHeightUsing(HeightType heightType) const; 0195 int calcPercentageHeight(const Length &height) const; 0196 int availableHeightUsing(const Length &h) const; 0197 int availableWidthUsing(const Length &w) const; 0198 int calcImplicitContentHeight() const; 0199 bool hasImplicitHeight() const 0200 { 0201 return isPositioned() && !style()->top().isAuto() && !style()->bottom().isAuto(); 0202 } 0203 0204 protected: 0205 void paintBoxDecorations(PaintInfo &paintInfo, int _tx, int _ty) override; 0206 void paintRootBoxDecorations(PaintInfo &paintInfo, int _tx, int _ty); 0207 0208 void paintAllBackgrounds(QPainter *p, const QColor &c, const BackgroundLayer *bgLayer, QRect clipr, int _tx, int _ty, int w, int h); 0209 virtual void paintOneBackground(QPainter *p, const QColor &c, const BackgroundLayer *bgLayer, QRect clipr, int _tx, int _ty, int w, int h); 0210 virtual void paintBackgroundExtended(QPainter * /*p*/, const QColor & /*c*/, const BackgroundLayer * /*bgLayer*/, 0211 QRect clipr, int /*_tx*/, int /*_ty*/, 0212 int /*w*/, int /*height*/, int /*bleft*/, int /*bright*/, int /*pleft*/, int /*pright*/, 0213 int /*btop*/, int /*bbottom*/, int /*ptop*/, int /*pbottom*/) override; 0214 void outlineBox(QPainter *p, int _tx, int _ty, const char *color = "red"); 0215 0216 void calcAbsoluteHorizontal(); 0217 void calcAbsoluteVertical(); 0218 void calcAbsoluteHorizontalValues(Length width, const RenderObject *cb, EDirection containerDirection, 0219 const int containerWidth, const int bordersPlusPadding, 0220 const Length left, const Length right, const Length marginLeft, const Length marginRight, 0221 short &widthValue, short &marginLeftValue, short &marginRightValue, short &xPos); 0222 void calcAbsoluteVerticalValues(Length height, const RenderObject *cb, 0223 const int containerHeight, const int bordersPlusPadding, 0224 const Length top, const Length bottom, const Length marginTop, const Length marginBottom, 0225 int &heightValue, short &marginTopValue, short &marginBottomValue, int &yPos); 0226 0227 void calcAbsoluteVerticalReplaced(); 0228 void calcAbsoluteHorizontalReplaced(); 0229 0230 QPainterPath borderRadiusClipPath(const BackgroundLayer *bgLayer, int _tx, int _ty, int w, int h, 0231 int borderLeft, int borderRight, int borderTop, int borderBottom, 0232 int paddingLeft, int paddingRight, int paddingTop, int paddingBottom) const; 0233 QRect overflowClipRect(int tx, int ty) override; 0234 QRect clipRect(int tx, int ty) override; 0235 0236 void restructureParentFlow(); 0237 void detachRemainingChildren(); 0238 0239 // the actual height of the contents + borders + padding (border-box) 0240 int m_height; 0241 int m_y; 0242 0243 short m_width; 0244 short m_x; 0245 0246 short m_marginTop; 0247 short m_marginBottom; 0248 0249 short m_marginLeft; 0250 short m_marginRight; 0251 0252 /* 0253 * the minimum width the element needs, to be able to render 0254 * its content without clipping 0255 */ 0256 short m_minWidth; 0257 /* The maximum width the element can fill horizontally 0258 * ( = the width of the element with line breaking disabled) 0259 */ 0260 int m_maxWidth; 0261 0262 // Cached normal flow values for absolute positioned elements with static left/top values. 0263 short m_staticX; 0264 int m_staticY; 0265 0266 RenderLayer *m_layer; 0267 0268 /* A box used to represent this object on a line 0269 * when its inner content isn't contextually relevant 0270 * (e.g replaced or positioned elements) 0271 */ 0272 InlineBox *m_placeHolderBox; 0273 }; 0274 0275 } //namespace 0276 0277 #endif