diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
commit | 1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch) | |
tree | 4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /WebCore/dom/Node.h | |
parent | 9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff) | |
download | external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'WebCore/dom/Node.h')
-rw-r--r-- | WebCore/dom/Node.h | 190 |
1 files changed, 109 insertions, 81 deletions
diff --git a/WebCore/dom/Node.h b/WebCore/dom/Node.h index e63ec4b..a471a47 100644 --- a/WebCore/dom/Node.h +++ b/WebCore/dom/Node.h @@ -24,7 +24,6 @@ #ifndef Node_h #define Node_h -#include "DeprecatedString.h" #include "DocPtr.h" #include "PlatformString.h" #include "TreeShared.h" @@ -43,7 +42,9 @@ class Element; class Event; class EventListener; class IntRect; +class KURL; class KeyboardEvent; +class NSResolver; class NamedAttrMap; class NodeList; class PlatformKeyboardEvent; @@ -54,12 +55,20 @@ class RegisteredEventListener; class RenderArena; class RenderObject; class RenderStyle; -class TextStream; -struct NodeListsNodeData; +class StringBuilder; +class NodeRareData; typedef int ExceptionCode; -enum StyleChangeType { NoStyleChange, InlineStyleChange, FullStyleChange }; +enum StyleChangeType { NoStyleChange, InlineStyleChange, FullStyleChange, AnimationStyleChange }; + +const unsigned short DOCUMENT_POSITION_EQUIVALENT = 0x00; +const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01; +const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02; +const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04; +const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08; +const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10; +const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; // this class implements nodes, which can have a parent but no children: class Node : public TreeShared<Node> { @@ -80,18 +89,21 @@ public: NOTATION_NODE = 12, XPATH_NAMESPACE_NODE = 13 }; - + static bool isSupported(const String& feature, const String& version); static void startIgnoringLeaks(); static void stopIgnoringLeaks(); - Node(Document*); + enum StyleChange { NoChange, NoInherit, Inherit, Detach, Force }; + static StyleChange diff(RenderStyle*, RenderStyle*); + + Node(Document*, bool isElement = false, bool isContainer = false); virtual ~Node(); // DOM methods & attributes for Node - bool hasTagName(const QualifiedName& name) const { return virtualHasTagName(name); } + bool hasTagName(const QualifiedName&) const; virtual String nodeName() const = 0; virtual String nodeValue() const; virtual void setNodeValue(const String&, ExceptionCode&); @@ -101,27 +113,29 @@ public: 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; + Node* firstChild() const { return isContainerNode() ? containerFirstChild() : 0; } + Node* lastChild() const { return isContainerNode() ? containerLastChild() : 0; } + bool hasAttributes() const; + NamedAttrMap* attributes() const; - virtual String baseURI() const; + virtual KURL baseURI() const; + + void getSubresourceURLs(Vector<KURL>&) const; // These should all actually return a node, but this is only important for language bindings, // which will already know and hold a ref on the right node to return. Returning bool allows // these methods to be more efficient since they don't need to return a ref - virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&); - virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&); + virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false); + virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false); virtual bool removeChild(Node* child, ExceptionCode&); - virtual bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&); + virtual bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false); - virtual void remove(ExceptionCode&); - virtual bool hasChildNodes() const; + void remove(ExceptionCode&); + bool hasChildNodes() const { return firstChild(); } virtual PassRefPtr<Node> cloneNode(bool deep) = 0; - virtual const AtomicString& localName() const; - virtual const AtomicString& namespaceURI() const; - virtual const AtomicString& prefix() const; + const AtomicString& localName() const { return virtualLocalName(); } + const AtomicString& namespaceURI() const { return virtualNamespaceURI(); } + const AtomicString& prefix() const { return virtualPrefix(); } virtual void setPrefix(const AtomicString&, ExceptionCode&); void normalize(); @@ -140,13 +154,15 @@ public: // Other methods (not part of DOM) - virtual bool isElementNode() const { return false; } + bool isElementNode() const { return m_isElement; } + bool isContainerNode() const { return m_isContainer; } virtual bool isHTMLElement() const { return false; } #if ENABLE(SVG) - virtual + virtual bool isSVGElement() const { return false; } +#else + static bool isSVGElement() { return false; } #endif - bool isSVGElement() const { return false; } virtual bool isStyledElement() const { return false; } virtual bool isFrameOwnerElement() const { return false; } @@ -154,11 +170,13 @@ public: virtual bool isTextNode() const { return false; } virtual bool isCommentNode() const { return false; } virtual bool isCharacterDataNode() const { return false; } - virtual bool isDocumentNode() const { return false; } + bool isDocumentNode() const; virtual bool isEventTargetNode() const { return false; } virtual bool isShadowNode() const { return false; } virtual Node* shadowParentNode() { return 0; } Node* shadowAncestorNode(); + Node* shadowTreeRootNode(); + bool isInShadowTree(); // The node's parent for the purpose of event capture and bubbling. virtual Node* eventParentNode() { return parentNode(); } @@ -166,11 +184,6 @@ public: bool isBlockFlow() const; bool isBlockFlowOrBlockTable() const; - // Used by <form> elements to indicate a malformed state of some kind, typically - // used to keep from applying the bottom margin of the form. - virtual bool isMalformed() { return false; } - virtual void setMalformed(bool malformed) { } - // These low-level calls give the caller responsibility for maintaining the integrity of the tree. void setPreviousSibling(Node* previous) { m_previous = previous; } void setNextSibling(Node* next) { m_next = next; } @@ -196,8 +209,10 @@ public: Node* previousLeafNode() const; bool isEditableBlock() const; + + // enclosingBlockFlowElement() is deprecated. Use enclosingBlock instead. Element* enclosingBlockFlowElement() const; - Element* enclosingBlockFlowOrTableElement() const; + Element* enclosingInlineElement() const; Element* rootEditableElement() const; @@ -231,7 +246,7 @@ public: 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 focused() const { return hasRareData() ? rareDataFocused() : false; } bool attached() const { return m_attached; } void setAttached(bool b = true) { m_attached = b; } bool changed() const { return m_styleChange != NoStyleChange; } @@ -244,13 +259,19 @@ public: void setInDocument(bool b = true) { m_inDocument = b; } void setInActiveChain(bool b = true) { m_inActiveChain = b; } void setChanged(StyleChangeType changeType = FullStyleChange); + void setIsLink(bool b = true) { m_isLink = b; } + + bool inSubtreeMark() const { return m_inSubtreeMark; } + void setInSubtreeMark(bool b = true) { m_inSubtreeMark = b; } + + void lazyAttach(); + virtual bool canLazyAttach(); - virtual void setFocus(bool b = true) { m_focused = b; } - virtual void setActive(bool b = true, bool pause=false) { m_active = b; } + virtual void setFocus(bool b = true); + 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 short tabIndex() const; /** * Whether this node can receive the keyboard focus. @@ -265,15 +286,14 @@ public: virtual bool isChecked() const { return false; } virtual bool isIndeterminate() const { return false; } virtual bool isReadOnlyControl() const { return false; } + virtual bool isTextControl() 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; @@ -285,9 +305,9 @@ public: // of a DocumentType node that is not used with any Document yet. A Document node returns itself. Document* document() const { - ASSERT(this); - ASSERT(m_document || nodeType() == DOCUMENT_TYPE_NODE && !inDocument()); - return m_document.get(); + ASSERT(this); + ASSERT(m_document || nodeType() == DOCUMENT_TYPE_NODE && !inDocument()); + return m_document.get(); } void setDocument(Document*); @@ -295,14 +315,14 @@ public: // node tree, false otherwise. bool inDocument() const { - ASSERT(m_document || !m_inDocument); - return m_inDocument; + ASSERT(m_document || !m_inDocument); + return m_inDocument; } - - virtual bool isReadOnlyNode(); + + bool isReadOnlyNode() const { return nodeType() == ENTITY_REFERENCE_NODE; } virtual bool childTypeAllowed(NodeType) { return false; } - virtual unsigned childNodeCount() const; - virtual Node* childNode(unsigned index) const; + unsigned childNodeCount() const { return isContainerNode() ? containerChildNodeCount() : 0; } + Node* childNode(unsigned index) const { return isContainerNode() ? containerChildNode(index) : 0; } /** * Does a pre-order traversal of the tree to find the node next node after this one. This uses the same order that @@ -317,7 +337,7 @@ public: */ Node* traverseNextNode(const Node* stayWithin = 0) const; - /* Like traverseNextNode, but skips children and starts with the next sibling. */ + // Like traverseNextNode, but skips children and starts with the next sibling. Node* traverseNextSibling(const Node* stayWithin = 0) const; /** @@ -327,15 +347,18 @@ public: */ Node* traversePreviousNode(const Node * stayWithin = 0) const; - /* Like traversePreviousNode, but visits nodes before their children. */ + // Like traverseNextNode, but visits parents after their children. + Node* traverseNextNodePostOrder() const; + + // Like traversePreviousNode, but visits parents before their children. Node* traversePreviousNodePostOrder(const Node *stayWithin = 0) const; + Node* traversePreviousSiblingPostOrder(const Node *stayWithin = 0) const; /** * Finds previous or next editable leaf node. */ Node* previousEditable() const; Node* nextEditable() const; - Node* nextEditable(int offset) const; RenderObject* renderer() const { return m_renderer; } RenderObject* nextRenderer(); @@ -367,10 +390,6 @@ public: // Whether or not a selection can be started in this object virtual bool canStartSelection() const; -#ifndef NDEBUG - virtual void dump(TextStream*, DeprecatedString indent = "") const; -#endif - // ----------------------------------------------------------------------------- // Integration with rendering tree @@ -389,7 +408,7 @@ public: virtual void willRemove(); void createRendererIfNeeded(); - virtual RenderStyle* styleForRenderer(RenderObject* parent); + PassRefPtr<RenderStyle> styleForRenderer(); virtual bool rendererIsNeeded(RenderStyle*); #if ENABLE(SVG) virtual bool childShouldCreateRenderer(Node*) const { return true; } @@ -397,8 +416,8 @@ public: virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); // Wrapper for nodes that don't have a renderer, but still cache the style (like HTMLOptionElement). - virtual RenderStyle* renderStyle() const; - virtual void setRenderStyle(RenderStyle*); + RenderStyle* renderStyle() const; + virtual void setRenderStyle(PassRefPtr<RenderStyle>); virtual RenderStyle* computedStyle(); @@ -435,11 +454,9 @@ public: * Notifies the node that it's list of children have changed (either by adding or removing child nodes), or a child * node that is of the type CDATA_SECTION_NODE, TEXT_NODE or COMMENT_NODE has changed its value. */ - virtual void childrenChanged(bool changedByParser = false) {}; - - virtual String toString() const = 0; + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) {}; -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(ANDROID_DOM_LOGGING) virtual void formatForDebugger(char* buffer, unsigned length) const; void showNode(const char* prefix = "") const; @@ -462,51 +479,62 @@ public: PassRefPtr<Element> querySelector(const String& selectors, ExceptionCode&); PassRefPtr<NodeList> querySelectorAll(const String& selectors, ExceptionCode&); -private: // members - DocPtr<Document> m_document; - Node* m_previous; - Node* m_next; - RenderObject* m_renderer; + unsigned short compareDocumentPosition(Node*); protected: virtual void willMoveToNewOwnerDocument() { } virtual void didMoveToNewOwnerDocument() { } - OwnPtr<NodeListsNodeData> m_nodeLists; + virtual void getSubresourceAttributeStrings(Vector<String>&) const { } + void setTabIndexExplicitly(short); + + bool hasRareData() const { return m_hasRareData; } + + NodeRareData* rareData() const; + NodeRareData* ensureRareData(); - short m_tabIndex; +private: + virtual NodeRareData* createRareData(); + Node* containerChildNode(unsigned index) const; + unsigned containerChildNodeCount() const; + Node* containerFirstChild() const; + Node* containerLastChild() const; + bool rareDataFocused() const; + + virtual RenderStyle* nonRendererRenderStyle() const; + + virtual const AtomicString& virtualPrefix() const; + virtual const AtomicString& virtualLocalName() const; + virtual const AtomicString& virtualNamespaceURI() const; + + DocPtr<Document> m_document; + Node* m_previous; + Node* m_next; + RenderObject* m_renderer; // make sure we don't use more than 16 bits here -- adding more would increase the size of all Nodes + unsigned m_styleChange : 2; 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; // used in Attr for one thing and Element for another - 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; - // 0 bits left + bool m_hasRareData : 1; + const bool m_isElement : 1; + const bool m_isContainer : 1; + // no bits left -private: Element* ancestorElement() const; - virtual Node* virtualFirstChild() const; - virtual Node* virtualLastChild() const; - virtual bool virtualHasTagName(const QualifiedName&) const; + void appendTextContent(bool convertBRsToNewlines, StringBuilder&) const; }; - } //namespace #ifndef NDEBUG |