📄 render_object.h
字号:
/* * This file is part of the html renderer for KDE. * * Copyright (C) 2000 Lars Knoll (knoll@kde.org) * (C) 2000 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */#ifndef render_object_h#define render_object_h#include <qcolor.h>#include <qrect.h>#include <assert.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"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/* * The painting of a layer occurs in three distinct phases. Each phase involves * a recursive descent into the layer's render objects. The first phase is the background phase. * The backgrounds and borders of all blocks are painted. Inlines are not painted at all. * Floats must paint above block backgrounds but entirely below inline content that can overlap them. * In the foreground phase, all inlines are fully painted. Inline replaced elements will get all * three phases invoked on them during this phase. */typedef enum { PaintActionElementBackground = 0, PaintActionChildBackground, PaintActionChildBackgrounds, PaintActionFloat, PaintActionForeground, PaintActionOutline, PaintActionSelection, PaintActionCollapsedTableBorders} PaintAction;typedef enum { HitTestAll = 0, HitTestSelfOnly = 1, HitTestChildrenOnly = 2} 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;/** * Base Class for all rendering tree objects. */class RenderObject : public CachedObjectClient{public: // Anonymous objects should pass the document as their node, and they will then automatically be // marked as anonymous in the constructor. 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; } // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline // children. virtual RenderBlock* firstLineBlock() const; virtual void updateFirstLetter(); // Called when an object that was floating or positioned becomes a normal flow object // again. We have to make sure the render tree updates as needed to accommodate the new // normal flow object. void handleDynamicFloatPositionChange(); // This function is a convenience helper for creating an anonymous block that inherits its // style from this RenderObject. RenderBlock* createAnonymousBlock(); // Whether or not a positioned element requires normal flow x/y to be computed // to determine its position. bool hasStaticX() const; bool hasStaticY() const; virtual void setStaticX(int staticX) {}; virtual void setStaticY(int staticY) {}; // RenderObject tree manipulation ////////////////////////////////////////// virtual bool canHaveChildren() const; virtual void addChild(RenderObject *newChild, RenderObject *beforeChild = 0); virtual void removeChild(RenderObject *oldChild); // raw tree manipulation virtual RenderObject* removeChildNode(RenderObject* child); virtual void appendChildNode(RenderObject* child); virtual void insertChildNode(RenderObject* child, RenderObject* before); //////////////////////////////////////////private: ////////////////////////////////////////// // Helper functions. Dangerous to use! void setPreviousSibling(RenderObject *previous) { m_previous = previous; } void setNextSibling(RenderObject *next) { m_next = next; } void setParent(RenderObject *parent) { m_parent = parent; } ////////////////////////////////////////// QRect absoluteBoundingBoxRect(); 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); // Overloaded new operator. Derived classes must override operator new // in order to allocate out of the RenderArena. void* operator new(size_t sz, RenderArena* renderArena) throw(); // Overridden to prevent the normal delete from being called. void operator delete(void* ptr, size_t sz); private: // The normal operator new is disallowed on all render objects. void* operator new(size_t sz) throw(); public: RenderArena* renderArena() const; // some helper functions... 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; } // absolute or fixed positioning bool isRelPositioned() const { return m_relPositioned; } // relative positioning bool isText() const { return m_isText; } bool isInline() const { return m_inline; } // inline object bool isCompact() const { return style()->display() == COMPACT; } // compact object bool isRunIn() const { return style()->display() == RUN_IN; } // run-in object bool mouseInside() const; bool isDragging() const; bool isReplaced() const { return m_replaced; } // a "replaced" element (see CSS) 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 isSelectionBorder() const { return m_isSelectionBorder; } bool recalcMinMax() const { return m_recalcMinMax; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -