#ifndef render_object_h
#define render_object_h
#include <qcolor.h>
#include <qrect.h>
#include <assert.h>
#include "editing/text_affinity.h"
#include "misc/khtmllayout.h"
#include "misc/loader_client.h"
#include "misc/helper.h"
#include "rendering/render_style.h"
#include "khtml_events.h"
#include "xml/dom_docimpl.h"
#include "visible_position.h"
#include "KWQScrollBar.h"
class QPainter;
class QTextStream;
class CSSStyle;
class KHTMLView;
class RenderArena;
#ifndef NDEBUG
#define KHTMLAssert( x ) if( !(x) ) { \
const RenderObject *o = this; while( o->parent() ) o = o->parent(); \
o->printTree(); \
qDebug(" this object = %p", this ); \
assert( false ); \
}
#else
#define KHTMLAssert( x )
#endif
typedef enum {
PaintActionBlockBackground,
PaintActionChildBlockBackground,
PaintActionChildBlockBackgrounds,
PaintActionFloat,
PaintActionForeground,
PaintActionOutline,
PaintActionSelection,
PaintActionCollapsedTableBorders
} PaintAction;
typedef enum {
HitTestAll,
HitTestSelf,
HitTestDescendants
} HitTestFilter;
typedef enum {
HitTestBlockBackground,
HitTestChildBlockBackground,
HitTestChildBlockBackgrounds,
HitTestFloat,
HitTestForeground
} HitTestAction;
namespace DOM {
class HTMLAreaElementImpl;
class DOMString;
class DocumentImpl;
class ElementImpl;
class EventImpl;
class Position;
};
namespace khtml {
class RenderFlow;
class RenderBlock;
class RenderStyle;
class RenderTable;
class CachedObject;
class RenderCanvas;
class RenderText;
class RenderFrameSet;
class RenderLayer;
class InlineBox;
class InlineFlowBox;
class CollapsedBorderValue;
#if APPLE_CHANGES
struct DashboardRegionValue
{
QString label;
QRect bounds;
QRect clip;
int type;
bool operator==(const DashboardRegionValue& o) const
{
return type == o.type && bounds == o.bounds && label == o.label;
}
};
#endif
class RenderObject : public CachedObjectClient
{
public:
RenderObject(DOM::NodeImpl* node);
virtual ~RenderObject();
RenderObject *parent() const { return m_parent; }
bool hasAncestor(const RenderObject *obj) const;
RenderObject *previousSibling() const { return m_previous; }
RenderObject *nextSibling() const { return m_next; }
virtual RenderObject *firstChild() const { return 0; }
virtual RenderObject *lastChild() const { return 0; }
RenderObject *nextRenderer() const;
RenderObject *previousRenderer() const;
RenderObject *nextEditable() const;
RenderObject *previousEditable() const;
RenderObject *firstLeafChild() const;
RenderObject *lastLeafChild() const;
virtual RenderLayer* layer() const { return 0; }
RenderLayer* enclosingLayer();
void addLayers(RenderLayer* parentLayer, RenderObject* newObject);
void removeLayers(RenderLayer* parentLayer);
void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint,
bool checkParent=true);
virtual void positionChildLayers() { }
virtual bool requiresLayer();
virtual QRect getOverflowClipRect(int tx, int ty) { return QRect(0,0,0,0); }
virtual QRect getClipRect(int tx, int ty) { return QRect(0,0,0,0); }
bool hasClip() { return isPositioned() && style()->hasClip(); }
virtual int getBaselineOfFirstLineBox() const { return -1; }
virtual RenderBlock* firstLineBlock() const;
virtual void updateFirstLetter();
void handleDynamicFloatPositionChange();
RenderBlock* createAnonymousBlock();
bool hasStaticX() const;
bool hasStaticY() const;
virtual void setStaticX(int staticX) {};
virtual void setStaticY(int staticY) {};
virtual int staticX() const { return 0; }
virtual int staticY() const { return 0; }
virtual bool canHaveChildren() const;
virtual void addChild(RenderObject *newChild, RenderObject *beforeChild = 0);
virtual void removeChild(RenderObject *oldChild);
virtual RenderObject* removeChildNode(RenderObject* child);
virtual void appendChildNode(RenderObject* child);
virtual void insertChildNode(RenderObject* child, RenderObject* before);
private:
void setPreviousSibling(RenderObject *previous) { m_previous = previous; }
void setNextSibling(RenderObject *next) { m_next = next; }
void setParent(RenderObject *parent) { m_parent = parent; }
void addAbsoluteRectForLayer(QRect& result);
public:
virtual const char *renderName() const { return "RenderObject"; }
#ifndef NDEBUG
QString information() const;
virtual void printTree(int indent=0) const;
virtual void dump(QTextStream *stream, QString ind = "") const;
#endif
static RenderObject *createObject(DOM::NodeImpl* node, RenderStyle* style);
void* operator new(size_t sz, RenderArena* renderArena) throw();
void operator delete(void* ptr, size_t sz);
private:
void* operator new(size_t sz) throw();
public:
RenderArena* renderArena() const;
virtual bool isRenderBlock() const { return false; }
virtual bool isRenderInline() const { return false; }
virtual bool isInlineFlow() const { return false; }
virtual bool isBlockFlow() const { return false; }
virtual bool isInlineBlockOrInlineTable() const { return false; }
virtual bool childrenInline() const { return false; }
virtual void setChildrenInline(bool b) { };
virtual RenderFlow* continuation() const;
virtual bool isInlineContinuation() const;
virtual bool isListItem() const { return false; }
virtual bool isListMarker() const { return false; }
virtual bool isCanvas() const { return false; }
bool isRoot() const;
bool isBody() const;
bool isHR() const;
virtual bool isBR() const { return false; }
virtual bool isTableCell() const { return false; }
virtual bool isTableRow() const { return false; }
virtual bool isTableSection() const { return false; }
virtual bool isTableCol() const { return false; }
virtual bool isTable() const { return false; }
virtual bool isWidget() const { return false; }
virtual bool isFormElement() const { return false; }
virtual bool isImage() const { return false; }
virtual bool isTextArea() const { return false; }
virtual bool isFrameSet() const { return false; }
virtual bool isApplet() const { return false; }
virtual bool isEditable() const;
bool isHTMLMarquee() const;
bool isAnonymous() const { return m_isAnonymous; }
void setIsAnonymous(bool b) { m_isAnonymous = b; }
bool isAnonymousBlock() const { return m_isAnonymous &&
style()->display() == BLOCK &&
style()->styleType() == RenderStyle::NOPSEUDO &&
!isListMarker(); }
bool isFloating() const { return m_floating; }
bool isPositioned() const { return m_positioned; } bool isRelPositioned() const { return m_relPositioned; } bool isText() const { return m_isText; }
bool isInline() const { return m_inline; } bool isCompact() const { return style()->display() == COMPACT; } bool isRunIn() const { return style()->display() == RUN_IN; } bool mouseInside() const;
bool isDragging() const;
bool isReplaced() const { return m_replaced; } bool shouldPaintBackgroundOrBorder() const { return m_paintBackground; }
bool needsLayout() const { return m_needsLayout || m_normalChildNeedsLayout || m_posChildNeedsLayout; }
bool selfNeedsLayout() const { return m_needsLayout; }
bool posChildNeedsLayout() const { return m_posChildNeedsLayout; }
bool normalChildNeedsLayout() const { return m_normalChildNeedsLayout; }
bool minMaxKnown() const{ return m_minMaxKnown; }
bool recalcMinMax() const { return m_recalcMinMax; }
bool isSelectionBorder() const;
bool hasOverflowClip() const { return m_hasOverflowClip; }
bool hasAutoScrollbars() const { return hasOverflowClip() &&
(style()->overflow() == OAUTO || style()->overflow() == OOVERLAY); }
bool scrollsOverflow() const { return hasOverflowClip() &&
(style()->overflow() == OSCROLL || hasAutoScrollbars()); }
bool includeScrollbarSize() const { return hasOverflowClip() &&
(style()->overflow() == OSCROLL || style()->overflow() == OAUTO); }
RenderStyle* getPseudoStyle(RenderStyle::PseudoId pseudo, RenderStyle* parentStyle = 0) const;
void updateDragState(bool dragOn);
RenderCanvas* canvas() const;
DOM::NodeImpl* element() const { return m_isAnonymous ? 0 : m_node; }
DOM::DocumentImpl* document() const { return m_node->getDocument(); }
void setNode(DOM::NodeImpl* node) { m_node = node; }
DOM::NodeImpl* node() const { return m_node; }
RenderObject *container() const;
virtual void markAllDescendantsWithFloatsForLayout(RenderObject* floatToRemove = 0);
void markContainingBlocksForLayout();
void setNeedsLayout(bool b, bool markParents = true);
void setChildNeedsLayout(bool b, bool markParents = true);
void setMinMaxKnown(bool b=true) {
m_minMaxKnown = b;
if ( !b ) {
RenderObject *o = this;
RenderObject *root = this;
while( o ) { o->m_recalcMinMax = true;
root = o;
o = o->m_parent;
}
}
}
void setNeedsLayoutAndMinMaxRecalc() {
setMinMaxKnown(false);
setNeedsLayout(true);
}
void setPositioned(bool b=true) { m_positioned = b; }
void setRelPositioned(bool b=true) { m_relPositioned = b; }
void setFloating(bool b=true) { m_floating = b; }
void setInline(bool b=true) { m_inline = b; }
void setMouseInside(bool b=true) { m_mouseInside = b; }
void setShouldPaintBackgroundOrBorder(bool b=true) { m_paintBackground = b; }
void setRenderText() { m_isText = true; }
void setReplaced(bool b=true) { m_replaced = b; }
void setHasOverflowClip(bool b = true) { m_hasOverflowClip = b; }
void scheduleRelayout();
void updateBackgroundImages(RenderStyle* oldStyle);
virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun=false);
virtual void dirtyLineBoxes(bool fullLayout, bool isRootLineBox=false);
virtual InlineBox* inlineBoxWrapper() const;
virtual void setInlineBoxWrapper(InlineBox* b);
void deleteLineBoxWrapper();
virtual InlineBox *inlineBox(long offset=0, EAffinity affinity = UPSTREAM);
virtual short lineHeight( bool firstLine, bool isRootLineBox=false ) const;
virtual short verticalPositionHint( bool firstLine ) const;
virtual short baselinePosition( bool firstLine, bool isRootLineBox=false ) const;
struct PaintInfo {
PaintInfo(QPainter* _p, const QRect& _r, PaintAction _phase, RenderObject *_paintingRoot)
: p(_p), r(_r), phase(_phase), paintingRoot(_paintingRoot), outlineObjects(0) {}
~PaintInfo() { delete outlineObjects; }
QPainter* p;
QRect r;
PaintAction phase;
RenderObject *paintingRoot; QPtrDict<RenderFlow>* outlineObjects; };
virtual void paint(PaintInfo& i, int tx, int ty);
void paintBorder(QPainter *p, int _tx, int _ty, int w, int h, const RenderStyle* style, bool begin=true, bool end=true);
void paintOutline(QPainter *p, int _tx, int _ty, int w, int h, const RenderStyle* style);
virtual void paintBoxDecorations(PaintInfo& i, int _tx, int _ty) {};
virtual void paintBackgroundExtended(QPainter *p, const QColor& c, const BackgroundLayer* bgLayer, int clipy, int cliph,
int _tx, int _ty, int w, int height,
int bleft, int bright) {};
virtual void calcMinMaxWidth() { }
void recalcMinMaxWidths();
virtual void calcWidth() {}
virtual void layout() = 0;
void layoutIfNeeded() { if (needsLayout()) layout(); }
virtual void updateFromElement() {};
virtual int availableHeight() const { return 0; }
bool sizesToMaxWidth() const;
#if APPLE_CHANGES
virtual void updateWidgetPositions();
QValueList<DashboardRegionValue> RenderObject::computeDashboardRegions();
void addDashboardRegions (QValueList<DashboardRegionValue>& regions);
void collectDashboardRegions (QValueList<DashboardRegionValue>& regions);
#endif
class NodeInfo
{
friend class RenderLayer;
friend class RenderImage;
friend class RenderText;
friend class RenderInline;
friend class RenderObject;
friend class RenderFrameSet;
friend class DOM::HTMLAreaElementImpl;
public:
NodeInfo(bool readonly, bool active)
: m_innerNode(0), m_innerNonSharedNode(0), m_innerURLElement(0), m_readonly(readonly), m_active(active)
{ }
DOM::NodeImpl* innerNode() const { return m_innerNode; }
DOM::NodeImpl* innerNonSharedNode() const { return m_innerNonSharedNode; }
DOM::NodeImpl* URLElement() const { return m_innerURLElement; }
bool readonly() const { return m_readonly; }
bool active() const { return m_active; }
private:
void setInnerNode(DOM::NodeImpl* n) { m_innerNode = n; }
void setInnerNonSharedNode(DOM::NodeImpl* n) { m_innerNonSharedNode = n; }
void setURLElement(DOM::NodeImpl* n) { m_innerURLElement = n; }
DOM::NodeImpl* m_innerNode;
DOM::NodeImpl* m_innerNonSharedNode;
DOM::NodeImpl* m_innerURLElement;
bool m_readonly;
bool m_active;
};
struct RepaintInfo {
RenderObject* m_object;
QRect m_repaintRect;
RepaintInfo(RenderObject* o, const QRect& r) :m_object(o), m_repaintRect(r) {}
};
bool hitTest(NodeInfo& info, int x, int y, int tx, int ty, HitTestFilter hitTestFilter = HitTestAll);
virtual bool nodeAtPoint(NodeInfo& info, int x, int y, int tx, int ty,
HitTestAction hitTestAction);
void setInnerNode(NodeInfo& info);
virtual VisiblePosition positionForCoordinates(int x, int y);
virtual void dirtyLinesFromChangedChild(RenderObject* child, bool adding = true);
virtual void setStyle(RenderStyle* style);
void setStyleInternal(RenderStyle* style);
RenderBlock *containingBlock() const;
virtual int containingBlockWidth() const;
virtual int containingBlockHeight() const;
virtual int contentWidth() const { return 0; }
virtual int contentHeight() const { return 0; }
virtual int intrinsicWidth() const { return 0; }
virtual int intrinsicHeight() const { return 0; }
virtual int overrideSize() const { return 0; }
virtual int overrideWidth() const { return 0; }
virtual int overrideHeight() const { return 0; }
virtual void setOverrideSize(int s) {}
virtual void setPos( int , int ) { }
virtual void setWidth( int ) { }
virtual void setHeight( int ) { }
virtual int xPos() const { return 0; }
virtual int yPos() const { return 0; }
virtual bool absolutePosition(int &, int &, bool fixed = false);
virtual int width() const { return 0; }
virtual int height() const { return 0; }
virtual QRect borderBox() const { return QRect(0, 0, width(), height()); }
virtual int overflowHeight(bool includeInterior=true) const { return height(); }
virtual int overflowWidth(bool includeInterior=true) const { return width(); }
virtual void setOverflowHeight(int) {}
virtual void setOverflowWidth(int) {}
virtual int overflowLeft(bool includeInterior=true) const { return 0; }
virtual int overflowTop(bool includeInterior=true) const { return 0; }
virtual QRect overflowRect(bool includeInterior=true) const { return borderBox(); }
virtual int offsetWidth() const { return width(); }
virtual int offsetHeight() const { return height(); }
virtual int offsetLeft() const;
virtual int offsetTop() const;
virtual RenderObject* offsetParent() const;
int clientWidth() const;
int clientHeight() const;
int scrollWidth() const;
int scrollHeight() const;
virtual bool scroll(KWQScrollDirection direction, KWQScrollGranularity granularity, float multiplier=1.0);
virtual bool isSelfCollapsingBlock() const { return false; }
virtual int collapsedMarginTop() const
{ return maxTopMargin(true)-maxTopMargin(false); }
virtual int collapsedMarginBottom() const
{ return maxBottomMargin(true)-maxBottomMargin(false); }
virtual bool isTopMarginQuirk() const { return false; }
virtual bool isBottomMarginQuirk() const { return false; }
virtual int maxTopMargin(bool positive) const {
if (positive)
if (marginTop() > 0)
return marginTop();
else
return 0;
else
if (marginTop() < 0)
return 0 - marginTop();
else
return 0;
}
virtual int maxBottomMargin(bool positive) const {
if (positive)
if (marginBottom() > 0)
return marginBottom();
else
return 0;
else
if (marginBottom() < 0)
return 0 - marginBottom();
else
return 0;
}
virtual int marginTop() const { return 0; }
virtual int marginBottom() const { return 0; }
virtual int marginLeft() const { return 0; }
virtual int marginRight() const { return 0; }
virtual int paddingTop() const;
virtual int paddingBottom() const;
virtual int paddingLeft() const;
virtual int paddingRight() const;
virtual int borderTop() const { return style()->borderTopWidth(); }
virtual int borderBottom() const { return style()->borderBottomWidth(); }
virtual int borderLeft() const { return style()->borderLeftWidth(); }
virtual int borderRight() const { return style()->borderRightWidth(); }
virtual void absoluteRects(QValueList<QRect>& rects, int _tx, int _ty);
QRect absoluteBoundingBoxRect();
QRect paintingRootRect(QRect& topLevelRect);
#if APPLE_CHANGES
virtual void addFocusRingRects(QPainter *painter, int _tx, int _ty);
#endif
virtual int minWidth() const { return 0; }
virtual int maxWidth() const { return 0; }
RenderStyle* style() const { return m_style; }
RenderStyle* style( bool firstLine ) const;
void getTextDecorationColors(int decorations, QColor& underline, QColor& overline,
QColor& linethrough, bool quirksMode=false);
enum BorderSide {
BSTop, BSBottom, BSLeft, BSRight
};
void drawBorder(QPainter *p, int x1, int y1, int x2, int y2, BorderSide s,
QColor c, const QColor& textcolor, EBorderStyle style,
int adjbw1, int adjbw2, bool invalidisInvert = false);
virtual void setTable(RenderTable*) {};
virtual void collectBorders(QValueList<CollapsedBorderValue>& borderStyles);
void repaint(bool immediate = false);
void repaintRectangle(const QRect& r, bool immediate = false);
bool repaintAfterLayoutIfNeeded(const QRect& oldBounds, const QRect& oldFullBounds);
virtual void repaintDuringLayoutIfMoved(int oldX, int oldY);
virtual void repaintFloatingDescendants();
virtual void repaintObjectsBeforeLayout();
bool checkForRepaintDuringLayout() const;
virtual QRect getAbsoluteRepaintRect();
QRect getAbsoluteRepaintRectWithOutline(int ow);
virtual void getAbsoluteRepaintRectIncludingFloats(QRect& bounds, QRect& boundsWithChildren);
virtual void computeAbsoluteRepaintRect(QRect& r, bool f=false);
virtual unsigned int length() const { return 1; }
bool isFloatingOrPositioned() const { return (isFloating() || isPositioned()); };
virtual bool containsFloats() { return false; }
virtual bool containsFloat(RenderObject* o) { return false; }
virtual bool hasOverhangingFloats() { return false; }
virtual QRect floatRect() const { return borderBox(); }
bool avoidsFloats() const;
bool usesLineWidth() const;
virtual void position(InlineBox*, int, int, bool) {}
int maximalOutlineSize(PaintAction p) const;
enum SelectionState {
SelectionNone, SelectionStart, SelectionInside, SelectionEnd, SelectionBoth };
virtual SelectionState selectionState() const { return SelectionNone; }
virtual void setSelectionState(SelectionState s) { if (parent()) parent()->setSelectionState(s); }
virtual QRect selectionRect() { return QRect(); }
virtual bool canBeSelectionLeaf() const { return false; }
virtual bool hasSelectedChildren() const { return false; }
bool canSelect() const;
bool shouldSelect() const;
virtual QColor selectionColor(QPainter *p) const;
virtual bool shouldPaintSelectionGaps() const { return false; }
struct SelectionInfo {
RenderObject* m_object;
QRect m_rect;
RenderObject::SelectionState m_state;
RenderObject* object() const { return m_object; }
QRect rect() const { return m_rect; }
SelectionState state() const { return m_state; }
SelectionInfo() { m_object = 0; m_state = SelectionNone; }
SelectionInfo(RenderObject* o) :m_object(o), m_rect(o->selectionRect()), m_state(o->selectionState()) {}
};
DOM::NodeImpl* draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const;
virtual QRect caretRect(int offset, EAffinity affinity = UPSTREAM, int *extraWidthToEndOfLine = 0);
virtual int lowestPosition(bool includeOverflowInterior=true, bool includeSelf=true) const { return 0; }
virtual int rightmostPosition(bool includeOverflowInterior=true, bool includeSelf=true) const { return 0; }
virtual int leftmostPosition(bool includeOverflowInterior=true, bool includeSelf=true) const { return 0; }
virtual void calcVerticalMargins() {}
void removeFromObjectLists();
bool documentBeingDestroyed() const { return !document()->renderer(); }
virtual void detach();
const QFont &font(bool firstLine) const {
return style( firstLine )->font();
}
const QFontMetrics &fontMetrics(bool firstLine) const {
return style( firstLine )->fontMetrics();
}
virtual bool isFlexibleBox() const { return false; }
virtual bool isFlexingChildren() const { return false; }
virtual bool isStretchingChildren() const { return false; }
QChar backslashAsCurrencySymbol() const;
virtual long caretMinOffset() const;
virtual long caretMaxOffset() const;
virtual unsigned long caretMaxRenderedOffset() const;
virtual long previousOffset (long current) const;
virtual long nextOffset (long current) const;
virtual void setPixmap(const QPixmap&, const QRect&, CachedImage *);
virtual void selectionStartEnd(int& spos, int& epos);
RenderObject* paintingRootForChildren(PaintInfo &i) const {
return (!i.paintingRoot || i.paintingRoot == this) ? 0 : i.paintingRoot;
}
bool shouldPaintWithinRoot(PaintInfo &i) const {
return !i.paintingRoot || i.paintingRoot == this;
}
protected:
virtual void printBoxDecorations(QPainter* , int , int ,
int , int , int , int ) {}
virtual QRect viewRect() const;
void remove();
void invalidateVerticalPositions();
short getVerticalPosition( bool firstLine ) const;
virtual void removeLeftoverAnonymousBoxes();
void arenaDelete(RenderArena *arena, void *objectBase);
private:
RenderStyle* m_style;
DOM::NodeImpl* m_node;
RenderObject *m_parent;
RenderObject *m_previous;
RenderObject *m_next;
mutable short m_verticalPosition;
bool m_needsLayout : 1;
bool m_normalChildNeedsLayout : 1;
bool m_posChildNeedsLayout : 1;
bool m_minMaxKnown : 1;
bool m_floating : 1;
bool m_positioned : 1;
bool m_relPositioned : 1;
bool m_paintBackground : 1;
bool m_isAnonymous : 1;
bool m_recalcMinMax : 1;
bool m_isText : 1;
bool m_inline : 1;
bool m_replaced : 1;
bool m_mouseInside : 1;
bool m_isDragging : 1;
bool m_hasOverflowClip : 1;
friend class RenderListItem;
friend class RenderContainer;
friend class RenderCanvas;
};
enum VerticalPositionHint {
PositionTop = -0x4000,
PositionBottom = 0x4000,
PositionUndefined = 0x3fff
};
}; #endif