#ifndef DOM_NodeImpl_h_
#define DOM_NodeImpl_h_
#include "DocPtr.h"
#include "PlatformString.h"
#include "DeprecatedString.h"
#include <wtf/Assertions.h>
#include <wtf/HashSet.h>
#include <wtf/PassRefPtr.h>
namespace WebCore {
class AtomicString;
class ContainerNode;
class DeprecatedStringList;
class Document;
class Element;
class Event;
class EventListener;
class IntRect;
class NamedAttrMap;
class NodeList;
class PlatformKeyboardEvent;
class PlatformMouseEvent;
class PlatformWheelEvent;
class QualifiedName;
class RegisteredEventListener;
class RenderArena;
class RenderObject;
class RenderStyle;
class TextStream;
class HTMLElement;
typedef int ExceptionCode;
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
};
Node(Document*);
virtual ~Node();
virtual bool hasTagName(const QualifiedName&) const { return false; }
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* previousSibling() const { return m_previous; }
Node* nextSibling() const { return m_next; }
virtual PassRefPtr<NodeList> childNodes();
virtual Node* firstChild() const;
virtual Node* lastChild() const;
virtual bool hasAttributes() const;
virtual NamedAttrMap* attributes() 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();
static bool isSupported(const String& feature, const String& version);
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 SVG_SUPPORT
virtual bool isSVGElement() const { return false; }
#endif
virtual bool isStyledElement() const { return false; }
virtual bool isAttributeNode() const { return false; }
virtual bool isTextNode() const { return false; }
virtual bool isCommentNode() 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();
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 inSameRootEditableElement(Node*);
bool inSameContainingBlockFlowElement(Node*);
virtual ContainerNode* addChild(PassRefPtr<Node>);
virtual void closeRenderer() { }
virtual void aboutToUnload() { }
virtual void sheetLoaded() { }
bool hasID() const { return m_hasId; }
bool hasClass() const { return m_hasClass; }
bool hasStyle() const { return m_hasStyle; }
bool active() const { return m_active; }
bool inActiveChain() const { return m_inActiveChain; }
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_changed; }
bool hasChangedChild() const { return m_hasChangedChild; }
bool isLink() const { return m_isLink; }
bool styleElement() const { return m_styleElement; }
bool implicitNode() const { return m_implicit; }
void setHasID(bool b = true) { m_hasId = b; }
void setHasClass(bool b = true) { m_hasClass = b; }
void setHasStyle(bool b = true) { m_hasStyle = 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(bool b = true);
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; }
unsigned short tabIndex() const { return m_tabIndex; }
void setTabIndex(unsigned short i) { m_tabIndex = i; }
virtual bool supportsFocus() const { return isFocusable(); }
virtual bool isFocusable() const;
virtual bool isKeyboardFocusable() 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 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(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 isAncestor(const Node*) const;
void checkAddChild(Node* newChild, ExceptionCode&); virtual bool childAllowed(Node* newChild);
virtual bool offsetInCharacters() const;
virtual int maxOffset() const;
virtual int caretMinOffset() const;
virtual int caretMaxOffset() const;
virtual unsigned caretMaxRenderedOffset() const;
virtual int previousOffset(int current) const;
virtual int nextOffset(int current) 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 SVG_SUPPORT
virtual bool childShouldCreateRenderer(Node*) const { return true; }
#endif
virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
virtual RenderStyle* renderStyle() const;
virtual void setRenderStyle(RenderStyle*);
virtual void insertedIntoDocument();
virtual void removedFromDocument();
virtual void insertedIntoTree(bool deep) { }
virtual void removedFromTree(bool deep) { }
virtual void childrenChanged();
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 registerNodeList(NodeList*);
void unregisterNodeList(NodeList*);
void notifyNodeListsChildrenChanged();
void notifyLocalNodeListsChildrenChanged();
void notifyNodeListsAttributeChanged();
void notifyLocalNodeListsAttributeChanged();
PassRefPtr<NodeList> getElementsByTagName(const String&);
PassRefPtr<NodeList> getElementsByTagNameNS(const String& namespaceURI, const String& localName);
virtual bool willRespondToMouseMoveEvents();
virtual bool willRespondToMouseWheelEvents();
virtual bool willRespondToMouseClickEvents();
private: DocPtr<Document> m_document;
Node* m_previous;
Node* m_next;
RenderObject* m_renderer;
protected:
typedef HashSet<NodeList*> NodeListSet;
NodeListSet* m_nodeLists;
unsigned short m_tabIndex : 15;
bool m_hasTabIndex : 1;
bool m_hasId : 1;
bool m_hasClass : 1;
bool m_hasStyle : 1;
bool m_attached : 1;
bool m_changed : 1;
bool m_hasChangedChild : 1;
bool m_inDocument : 1;
bool m_isLink : 1;
bool m_specified : 1; bool m_focused : 1;
bool m_active : 1;
bool m_hovered : 1;
bool m_inActiveChain : 1;
bool m_styleElement : 1; bool m_implicit : 1;
bool m_inDetach : 1;
private:
Element* ancestorElement() const;
};
}
#ifndef NDEBUG
void showTree(const WebCore::Node*);
#endif
#endif