#ifndef Node_h
#define Node_h
#include "DeprecatedString.h"
#include "DocPtr.h"
#include "PlatformString.h"
#include "TreeShared.h"
#include <wtf/Assertions.h>
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassRefPtr.h>
namespace WebCore {
class AtomicString;
class ContainerNode;
class Document;
class DynamicNodeList;
class Element;
class Event;
class EventListener;
class IntRect;
class KeyboardEvent;
class NamedAttrMap;
class NodeList;
class PlatformKeyboardEvent;
class PlatformMouseEvent;
class PlatformWheelEvent;
class QualifiedName;
class RegisteredEventListener;
class RenderArena;
class RenderObject;
class RenderStyle;
class TextStream;
struct NodeListsNodeData;
typedef int ExceptionCode;
enum StyleChangeType { NoStyleChange, InlineStyleChange, FullStyleChange };
class Node : public TreeShared<Node> {
friend class Document;
public:
enum NodeType {
ELEMENT_NODE = 1,
ATTRIBUTE_NODE = 2,
TEXT_NODE = 3,
CDATA_SECTION_NODE = 4,
ENTITY_REFERENCE_NODE = 5,
ENTITY_NODE = 6,
PROCESSING_INSTRUCTION_NODE = 7,
COMMENT_NODE = 8,
DOCUMENT_NODE = 9,
DOCUMENT_TYPE_NODE = 10,
DOCUMENT_FRAGMENT_NODE = 11,
NOTATION_NODE = 12,
XPATH_NAMESPACE_NODE = 13
};
static bool isSupported(const String& feature, const String& version);
static void startIgnoringLeaks();
static void stopIgnoringLeaks();
Node(Document*);
virtual ~Node();
bool hasTagName(const QualifiedName& name) const { return virtualHasTagName(name); }
virtual String nodeName() const = 0;
virtual String nodeValue() const;
virtual void setNodeValue(const String&, ExceptionCode&);
virtual NodeType nodeType() const = 0;
Node* parentNode() const { return parent(); }
Node* parentElement() const { return parent(); } Node* previousSibling() const { return m_previous; }
Node* nextSibling() const { return m_next; }
virtual PassRefPtr<NodeList> childNodes();
Node* firstChild() const { return virtualFirstChild(); }
Node* lastChild() const { return virtualLastChild(); }
virtual bool hasAttributes() const;
virtual NamedAttrMap* attributes() const;
virtual String baseURI() const;
virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&);
virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&);
virtual bool removeChild(Node* child, ExceptionCode&);
virtual bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&);
virtual void remove(ExceptionCode&);
virtual bool hasChildNodes() const;
virtual PassRefPtr<Node> cloneNode(bool deep) = 0;
virtual const AtomicString& localName() const;
virtual const AtomicString& namespaceURI() const;
virtual const AtomicString& prefix() const;
virtual void setPrefix(const AtomicString&, ExceptionCode&);
void normalize();
bool isSameNode(Node* other) const { return this == other; }
bool isEqualNode(Node*) const;
bool isDefaultNamespace(const String& namespaceURI) const;
String lookupPrefix(const String& namespaceURI) const;
String lookupNamespaceURI(const String& prefix) const;
String lookupNamespacePrefix(const String& namespaceURI, const Element* originalElement) const;
String textContent(bool convertBRsToNewlines = false) const;
void setTextContent(const String&, ExceptionCode&);
Node* lastDescendant() const;
Node* firstDescendant() const;
virtual bool isElementNode() const { return false; }
virtual bool isHTMLElement() const { return false; }
#if ENABLE(SVG)
virtual
#endif
bool isSVGElement() const { return false; }
virtual bool isStyledElement() const { return false; }
virtual bool isFrameOwnerElement() const { return false; }
virtual bool isAttributeNode() const { return false; }
virtual bool isTextNode() const { return false; }
virtual bool isCommentNode() const { return false; }
virtual bool isCharacterDataNode() const { return false; }
virtual bool isDocumentNode() const { return false; }
virtual bool isEventTargetNode() const { return false; }
virtual bool isShadowNode() const { return false; }
virtual Node* shadowParentNode() { return 0; }
Node* shadowAncestorNode();
virtual Node* eventParentNode() { return parentNode(); }
bool isBlockFlow() const;
bool isBlockFlowOrBlockTable() const;
virtual bool isMalformed() { return false; }
virtual void setMalformed(bool malformed) { }
void setPreviousSibling(Node* previous) { m_previous = previous; }
void setNextSibling(Node* next) { m_next = next; }
Node* previousNodeConsideringAtomicNodes() const;
Node* nextNodeConsideringAtomicNodes() const;
Node* nextLeafNode() const;
Node* previousLeafNode() const;
bool isEditableBlock() const;
Element* enclosingBlockFlowElement() const;
Element* enclosingBlockFlowOrTableElement() const;
Element* enclosingInlineElement() const;
Element* rootEditableElement() const;
bool inSameContainingBlockFlowElement(Node*);
virtual ContainerNode* addChild(PassRefPtr<Node>);
virtual void finishParsingChildren() { }
virtual void beginParsingChildren() { }
virtual void aboutToUnload() { }
virtual bool sheetLoaded() { return true; }
bool hasID() const { return m_hasId; }
bool hasClass() const { return m_hasClass; }
bool active() const { return m_active; }
bool inActiveChain() const { return m_inActiveChain; }
bool inDetach() const { return m_inDetach; }
bool hovered() const { return m_hovered; }
bool focused() const { return m_focused; }
bool attached() const { return m_attached; }
void setAttached(bool b = true) { m_attached = b; }
bool changed() const { return m_styleChange != NoStyleChange; }
StyleChangeType styleChangeType() const { return static_cast<StyleChangeType>(m_styleChange); }
bool hasChangedChild() const { return m_hasChangedChild; }
bool isLink() const { return m_isLink; }
void setHasID(bool b = true) { m_hasId = b; }
void setHasClass(bool b = true) { m_hasClass = b; }
void setHasChangedChild( bool b = true ) { m_hasChangedChild = b; }
void setInDocument(bool b = true) { m_inDocument = b; }
void setInActiveChain(bool b = true) { m_inActiveChain = b; }
void setChanged(StyleChangeType changeType = FullStyleChange);
virtual void setFocus(bool b = true) { m_focused = b; }
virtual void setActive(bool b = true, bool pause=false) { m_active = b; }
virtual void setHovered(bool b = true) { m_hovered = b; }
short tabIndex() const { return m_tabIndex; }
void setTabIndex(short i) { m_tabIndex = i; }
virtual bool supportsFocus() const { return isFocusable(); }
virtual bool isFocusable() const;
virtual bool isKeyboardFocusable(KeyboardEvent*) const;
virtual bool isMouseFocusable() const;
virtual bool isControl() const { return false; } virtual bool isEnabled() const { return true; }
virtual bool isChecked() const { return false; }
virtual bool isIndeterminate() const { return false; }
virtual bool isReadOnlyControl() const { return false; }
virtual bool isContentEditable() const;
virtual bool isContentRichlyEditable() const;
virtual bool shouldUseInputMethod() const;
virtual IntRect getRect() const;
enum StyleChange { NoChange, NoInherit, Inherit, Detach, Force };
virtual void recalcStyle(StyleChange = NoChange) { }
StyleChange diff(RenderStyle*, RenderStyle*) const;
unsigned nodeIndex() const;
virtual Document* ownerDocument() const;
Document* document() const
{
ASSERT(this);
ASSERT(m_document || nodeType() == DOCUMENT_TYPE_NODE && !inDocument());
return m_document.get();
}
void setDocument(Document*);
bool inDocument() const
{
ASSERT(m_document || !m_inDocument);
return m_inDocument;
}
virtual bool isReadOnlyNode();
virtual bool childTypeAllowed(NodeType) { return false; }
virtual unsigned childNodeCount() const;
virtual Node* childNode(unsigned index) const;
Node* traverseNextNode(const Node* stayWithin = 0) const;
Node* traverseNextSibling(const Node* stayWithin = 0) const;
Node* traversePreviousNode(const Node * stayWithin = 0) const;
Node* traversePreviousNodePostOrder(const Node *stayWithin = 0) const;
Node* previousEditable() const;
Node* nextEditable() const;
Node* nextEditable(int offset) const;
RenderObject* renderer() const { return m_renderer; }
RenderObject* nextRenderer();
RenderObject* previousRenderer();
void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
void checkSetPrefix(const AtomicString& prefix, ExceptionCode&);
bool isDescendantOf(const Node*) const;
void checkAddChild(Node* newChild, ExceptionCode&); virtual bool childAllowed(Node* newChild);
void checkReplaceChild(Node* newChild, Node* oldChild, ExceptionCode&);
virtual bool canReplaceChild(Node* newChild, Node* oldChild);
virtual bool offsetInCharacters() const;
virtual int maxCharacterOffset() const;
virtual bool canSelectAll() const { return false; }
virtual void selectAll() { }
virtual bool canStartSelection() const;
#ifndef NDEBUG
virtual void dump(TextStream*, DeprecatedString indent = "") const;
#endif
virtual void attach();
virtual void detach();
virtual void willRemove();
void createRendererIfNeeded();
virtual RenderStyle* styleForRenderer(RenderObject* parent);
virtual bool rendererIsNeeded(RenderStyle*);
#if ENABLE(SVG)
virtual bool childShouldCreateRenderer(Node*) const { return true; }
#endif
virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
virtual RenderStyle* renderStyle() const;
virtual void setRenderStyle(RenderStyle*);
virtual RenderStyle* computedStyle();
virtual void insertedIntoDocument();
virtual void removedFromDocument();
virtual void insertedIntoTree(bool deep) { }
virtual void removedFromTree(bool deep) { }
virtual void childrenChanged(bool changedByParser = false) {};
virtual String toString() const = 0;
#ifndef NDEBUG
virtual void formatForDebugger(char* buffer, unsigned length) const;
void showNode(const char* prefix = "") const;
void showTreeForThis() const;
void showTreeAndMark(const Node* markedNode1, const char* markedLabel1, const Node* markedNode2 = 0, const char* markedLabel2 = 0) const;
#endif
void registerDynamicNodeList(DynamicNodeList*);
void unregisterDynamicNodeList(DynamicNodeList*);
void notifyNodeListsChildrenChanged();
void notifyLocalNodeListsChildrenChanged();
void notifyNodeListsAttributeChanged();
void notifyLocalNodeListsAttributeChanged();
PassRefPtr<NodeList> getElementsByTagName(const String&);
PassRefPtr<NodeList> getElementsByTagNameNS(const String& namespaceURI, const String& localName);
PassRefPtr<NodeList> getElementsByName(const String& elementName);
PassRefPtr<NodeList> getElementsByClassName(const String& classNames);
PassRefPtr<Element> querySelector(const String& selectors, ExceptionCode&);
PassRefPtr<NodeList> querySelectorAll(const String& selectors, ExceptionCode&);
private: DocPtr<Document> m_document;
Node* m_previous;
Node* m_next;
RenderObject* m_renderer;
protected:
virtual void willMoveToNewOwnerDocument() { }
virtual void didMoveToNewOwnerDocument() { }
OwnPtr<NodeListsNodeData> m_nodeLists;
short m_tabIndex;
bool m_hasId : 1;
bool m_hasClass : 1;
bool m_attached : 1;
unsigned m_styleChange : 2;
bool m_hasChangedChild : 1;
bool m_inDocument : 1;
bool m_isLink : 1;
bool m_attrWasSpecifiedOrElementHasRareData : 1; bool m_focused : 1;
bool m_active : 1;
bool m_hovered : 1;
bool m_inActiveChain : 1;
bool m_inDetach : 1;
bool m_dispatchingSimulatedEvent : 1;
public:
bool m_inSubtreeMark : 1;
private:
Element* ancestorElement() const;
virtual Node* virtualFirstChild() const;
virtual Node* virtualLastChild() const;
virtual bool virtualHasTagName(const QualifiedName&) const;
};
}
#ifndef NDEBUG
void showTree(const WebCore::Node*);
#endif
#endif