00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef render_object_h
00026 #define render_object_h
00027
00028 #include <qcolor.h>
00029 #include <qrect.h>
00030 #include <assert.h>
00031
00032 #include "misc/khtmllayout.h"
00033 #include "misc/loader_client.h"
00034 #include "misc/helper.h"
00035 #include "rendering/render_style.h"
00036
00037 class QPainter;
00038 class QTextStream;
00039 class CSSStyle;
00040 class KHTMLView;
00041
00042 #ifndef NDEBUG
00043 #define KHTMLAssert( x ) if( !(x) ) { \
00044 const RenderObject *o = this; while( o->parent() ) o = o->parent(); \
00045 o->printTree(); \
00046 qDebug(" this object = %p", (void*) this ); \
00047 assert( false ); \
00048 }
00049 #else
00050 #define KHTMLAssert( x )
00051 #endif
00052
00053 namespace DOM {
00054 class HTMLAreaElementImpl;
00055 class DOMString;
00056 class NodeImpl;
00057 class ElementImpl;
00058 class EventImpl;
00059 }
00060
00061 namespace khtml {
00062 class RenderFlow;
00063 class RenderStyle;
00064 class RenderTable;
00065 class CachedObject;
00066 class RenderRoot;
00067 class RenderText;
00068 class RenderFrameSet;
00069
00073 class RenderObject : public CachedObjectClient
00074 {
00075 public:
00076
00077 RenderObject(DOM::NodeImpl* node);
00078 virtual ~RenderObject();
00079
00080 RenderObject *parent() const { return m_parent; }
00081
00082 RenderObject *previousSibling() const { return m_previous; }
00083 RenderObject *nextSibling() const { return m_next; }
00084
00085 virtual RenderObject *firstChild() const { return 0; }
00086 virtual RenderObject *lastChild() const { return 0; }
00087
00088
00089 RenderObject *objectBelow() const;
00090 RenderObject *objectAbove() const;
00091
00092
00094 virtual void addChild(RenderObject *newChild, RenderObject *beforeChild = 0);
00095 void removeChild(RenderObject *oldChild);
00096
00097
00098 virtual RenderObject* removeChildNode(RenderObject* child);
00099 virtual void appendChildNode(RenderObject* child);
00100 virtual void insertChildNode(RenderObject* child, RenderObject* before);
00102
00103 private:
00105
00106 void setPreviousSibling(RenderObject *previous) { m_previous = previous; }
00107 void setNextSibling(RenderObject *next) { m_next = next; }
00108 void setParent(RenderObject *parent) { m_parent = parent; }
00110
00111 public:
00112 virtual const char *renderName() const { return "RenderObject"; }
00113 #ifndef NDEBUG
00114 QString information() const;
00115 virtual void printTree(int indent=0) const;
00116 virtual void dump(QTextStream *stream, QString ind = "") const;
00117 #endif
00118
00119 static RenderObject *createObject(DOM::NodeImpl* node, RenderStyle* style);
00120
00121
00122 virtual bool childrenInline() const { return false; }
00123 virtual bool isRendered() const { return false; }
00124 virtual bool isFlow() const { return false; }
00125
00126 virtual bool isListItem() const { return false; }
00127 virtual bool isRoot() const { return false; }
00128 virtual bool isBR() const { return false; }
00129 virtual bool isHtml() const { return false; }
00130 virtual bool isTableCell() const { return false; }
00131 virtual bool isTableRow() const { return false; }
00132 virtual bool isTableSection() const { return false; }
00133 virtual bool isTableCol() const { return false; }
00134 virtual bool isTable() const { return false; }
00135 virtual bool isWidget() const { return false; }
00136 virtual bool isBody() const { return false; }
00137 virtual bool isFormElement() const { return false; }
00138 virtual bool isFrameSet() const { return false; }
00139 virtual bool isApplet() const { return false; }
00140
00141 bool isAnonymousBox() const { return m_isAnonymous; }
00142 void setIsAnonymousBox(bool b) { m_isAnonymous = b; }
00143
00144 bool isFloating() const { return m_floating; }
00145 bool isPositioned() const { return m_positioned; }
00146 bool isRelPositioned() const { return m_relPositioned; }
00147 bool isText() const { return m_isText; }
00148 bool isInline() const { return m_inline; }
00149 bool mouseInside() const { return m_mouseInside; }
00150 bool isReplaced() const { return m_replaced; }
00151 bool hasSpecialObjects() const { return m_paintSpecial; }
00152 bool layouted() const { return m_layouted; }
00153 bool minMaxKnown() const{ return m_minMaxKnown; }
00154 bool overhangingContents() const { return m_overhangingContents; }
00155 bool hasFirstLine() const { return m_hasFirstLine; }
00156 bool isSelectionBorder() const { return m_isSelectionBorder; }
00157 bool recalcMinMax() const { return m_recalcMinMax; }
00158
00159 RenderRoot* root() const;
00160
00161 DOM::NodeImpl* element() const { return m_node; }
00162
00167 RenderObject *container() const;
00168
00169 void setOverhangingContents(bool p=true);
00170 void setLayouted() {
00171 m_layouted = true;
00172 }
00173 void setLayouted(bool b) {
00174 m_layouted = b;
00175 if(!b) {
00176 RenderObject *o = m_parent;
00177 RenderObject *root = this;
00178 while( o ) {
00179 o->m_layouted = false;
00180 root = o;
00181 o = o->m_parent;
00182 }
00183 root->scheduleRelayout();
00184 }
00185 }
00186 void setLayoutedLocal(bool b) {
00187 m_layouted = b;
00188 }
00189 void setMinMaxKnown(bool b=true) {
00190 m_minMaxKnown = b;
00191 if ( !b ) {
00192 RenderObject *o = this;
00193 RenderObject *root = this;
00194 while( o ) {
00195 o->m_recalcMinMax = true;
00196 root = o;
00197 o = o->m_parent;
00198 }
00199 }
00200 }
00201 void setPositioned(bool b=true) { m_positioned = b; }
00202 void setRelPositioned(bool b=true) { m_relPositioned = b; }
00203 void setFloating(bool b=true) { m_floating = b; }
00204 void setInline(bool b=true) { m_inline = b; }
00205 void setMouseInside(bool b=true) { m_mouseInside = b; }
00206 void setSpecialObjects(bool b=true) { m_paintSpecial = b; }
00207 void setRenderText() { m_isText = true; }
00208 void setReplaced(bool b=true) { m_replaced = b; }
00209 void setIsSelectionBorder(bool b=true) { m_isSelectionBorder = b; }
00210
00211 void scheduleRelayout();
00212
00213
00214 virtual short lineHeight( bool firstLine ) const;
00215
00216
00217 virtual short verticalPositionHint( bool firstLine ) const;
00218
00219 virtual short baselinePosition( bool firstLine ) const;
00220
00221
00222
00223
00224
00225 virtual void paint( QPainter *p, int x, int y, int w, int h, int tx, int ty);
00226
00227 virtual void paintObject( QPainter *, int , int ,
00228 int , int , int , int ) {}
00229 void paintBorder(QPainter *p, int _tx, int _ty, int w, int h, const RenderStyle* style, bool begin=true, bool end=true);
00230 void paintOutline(QPainter *p, int _tx, int _ty, int w, int h, const RenderStyle* style);
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 virtual void calcMinMaxWidth() { }
00247
00248
00249
00250
00251 void recalcMinMaxWidths();
00252
00253
00254
00255
00256
00257 virtual void calcWidth() {}
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 virtual void layout() = 0;
00270
00271
00272
00273 virtual void updateFromElement() {};
00274
00275
00276 virtual void close() { }
00277
00278 virtual int availableHeight() const { return 0; }
00279
00280
00281
00282
00283 class NodeInfo
00284 {
00285 friend class RenderImage;
00286 friend class RenderFlow;
00287 friend class RenderText;
00288 friend class RenderObject;
00289 friend class RenderFrameSet;
00290 friend class DOM::HTMLAreaElementImpl;
00291 public:
00292 NodeInfo(bool readonly, bool active)
00293 : m_innerNode(0), m_innerURLElement(0), m_readonly(readonly), m_active(active)
00294 { }
00295
00296 DOM::NodeImpl* innerNode() const { return m_innerNode; }
00297 DOM::NodeImpl* URLElement() const { return m_innerURLElement; }
00298 bool readonly() const { return m_readonly; }
00299 bool active() const { return m_active; }
00300
00301 private:
00302 void setInnerNode(DOM::NodeImpl* n) { m_innerNode = n; }
00303 void setURLElement(DOM::NodeImpl* n) { m_innerURLElement = n; }
00304
00305 DOM::NodeImpl* m_innerNode;
00306 DOM::NodeImpl* m_innerURLElement;
00307 bool m_readonly;
00308 bool m_active;
00309 };
00310
00311 virtual FindSelectionResult checkSelectionPoint( int _x, int _y, int _tx, int _ty,
00312 DOM::NodeImpl*&, int & offset );
00313 virtual bool nodeAtPoint(NodeInfo& info, int x, int y, int tx, int ty);
00314
00315
00316 virtual void setStyle(RenderStyle *style);
00317
00318
00319 RenderObject *containingBlock() const;
00320
00321
00322 virtual short containingBlockWidth() const;
00323
00324 virtual int containingBlockHeight() const;
00325
00326
00327 virtual short contentWidth() const { return 0; }
00328 virtual int contentHeight() const { return 0; }
00329
00330
00331 virtual short intrinsicWidth() const { return 0; }
00332 virtual int intrinsicHeight() const { return 0; }
00333
00334
00335 virtual void setPos( int , int ) { }
00336 virtual void setWidth( int ) { }
00337 virtual void setHeight( int ) { }
00338
00339 virtual int xPos() const { return 0; }
00340 virtual int yPos() const { return 0; }
00341
00342
00343 virtual bool absolutePosition(int &, int &, bool fixed = false);
00344
00345
00346 virtual short width() const { return 0; }
00347 virtual int height() const { return 0; }
00348
00349 virtual short marginTop() const { return 0; }
00350 virtual short marginBottom() const { return 0; }
00351 virtual short marginLeft() const { return 0; }
00352 virtual short marginRight() const { return 0; }
00353
00354 int paddingTop() const;
00355 int paddingBottom() const;
00356 int paddingLeft() const;
00357 int paddingRight() const;
00358
00359 int borderTop() const { return style()->borderTopWidth(); }
00360 int borderBottom() const { return style()->borderBottomWidth(); }
00361 int borderLeft() const { return style()->borderLeftWidth(); }
00362 int borderRight() const { return style()->borderRightWidth(); }
00363
00364 virtual short minWidth() const { return 0; }
00365 virtual short maxWidth() const { return 0; }
00366
00367 RenderStyle* style() const { return m_style; }
00368 RenderStyle* style( bool firstLine ) const {
00369 RenderStyle *s = m_style;
00370 if( firstLine && hasFirstLine() ) {
00371 RenderStyle *pseudoStyle = style()->getPseudoStyle(RenderStyle::FIRST_LINE);
00372 if ( pseudoStyle )
00373 s = pseudoStyle;
00374 }
00375 return s;
00376 }
00377
00378 enum BorderSide {
00379 BSTop, BSBottom, BSLeft, BSRight
00380 };
00381 void drawBorder(QPainter *p, int x1, int y1, int x2, int y2, BorderSide s,
00382 QColor c, const QColor& textcolor, EBorderStyle style,
00383 int adjbw1, int adjbw2, bool invalidisInvert = false);
00384
00385
00386 virtual void repaint() { if(m_parent) m_parent->repaint(); }
00387 virtual void repaintRectangle(int x, int y, int w, int h, bool f=false);
00388
00389 virtual unsigned int length() const { return 1; }
00390
00391 virtual bool isHidden() const { return isFloating() || isPositioned(); }
00392
00393
00394 bool isSpecial() const { return (isFloating() || isPositioned()); };
00395 virtual bool containsSpecial() { return false; }
00396 virtual bool hasOverhangingFloats() { return false; }
00397
00398
00399 virtual void position(int, int, int, int, int, bool, bool, int) {}
00400
00401 enum SelectionState {
00402 SelectionNone,
00403 SelectionStart,
00404 SelectionInside,
00405 SelectionEnd,
00406 SelectionBoth
00407 };
00408
00409 virtual SelectionState selectionState() const { return SelectionNone;}
00410 virtual void setSelectionState(SelectionState) {}
00411
00412 virtual void cursorPos(int , int &, int &, int &);
00413
00414
00415
00416
00417 virtual int lowestPosition() const {return 0;}
00418
00419 virtual int rightmostPosition() const {return 0;}
00420
00421
00422
00423
00424 virtual void calcVerticalMargins() {}
00425 void removeFromSpecialObjects();
00426
00427 virtual void detach();
00428
00429 const QFont &font(bool firstLine) const {
00430 return style( firstLine )->font();
00431 }
00432
00433 const QFontMetrics &fontMetrics(bool firstLine) const {
00434 return style( firstLine )->fontMetrics();
00435 }
00436 protected:
00437 virtual void selectionStartEnd(int& spos, int& epos);
00438
00439 virtual void paintBoxDecorations(QPainter* , int , int ,
00440 int , int , int , int ) {}
00441
00442 virtual QRect viewRect() const;
00443 void remove() {
00444 removeFromSpecialObjects();
00445
00446 if ( parent() )
00447
00448 parent()->removeChild(this);
00449 }
00450
00451 void invalidateVerticalPositions();
00452 short getVerticalPosition( bool firstLine ) const;
00453
00454 virtual void removeLeftoverAnonymousBoxes();
00455
00456 private:
00457 RenderStyle* m_style;
00458 DOM::NodeImpl* m_node;
00459 RenderObject *m_parent;
00460 RenderObject *m_previous;
00461 RenderObject *m_next;
00462
00463 short m_verticalPosition;
00464
00465 bool m_layouted : 1;
00466 bool m_unused : 1;
00467 bool m_minMaxKnown : 1;
00468 bool m_floating : 1;
00469
00470 bool m_positioned : 1;
00471 bool m_overhangingContents : 1;
00472 bool m_relPositioned : 1;
00473 bool m_paintSpecial : 1;
00474
00475 bool m_isAnonymous : 1;
00476 bool m_recalcMinMax : 1;
00477 bool m_isText : 1;
00478 bool m_inline : 1;
00479
00480 bool m_replaced : 1;
00481 bool m_mouseInside : 1;
00482 bool m_hasFirstLine : 1;
00483 bool m_isSelectionBorder : 1;
00484
00485
00486 friend class RenderListItem;
00487 friend class RenderContainer;
00488 friend class RenderRoot;
00489 };
00490
00491
00492 enum VerticalPositionHint {
00493 PositionTop = -0x4000,
00494 PositionBottom = 0x4000,
00495 PositionUndefined = 0x3fff
00496 };
00497
00498 }
00499 #endif