2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
28 #include "EventTarget.h"
30 #include "RenderStyleConstants.h"
31 #include "ScriptWrappable.h"
32 #include "TreeShared.h"
33 #include <wtf/Forward.h>
34 #include <wtf/ListHashSet.h>
49 class DynamicNodeList;
64 class PlatformKeyboardEvent;
65 class PlatformMouseEvent;
66 class PlatformWheelEvent;
68 class RegisteredEventListener;
71 class RenderBoxModelObject;
76 typedef int ExceptionCode;
78 const int nodeStyleChangeShift = 25;
80 // SyntheticStyleChange means that we need to go through the entire style change logic even though
81 // no style property has actually changed. It is used to restructure the tree when, for instance,
82 // RenderLayers are created or destroyed due to animation changes.
83 enum StyleChangeType {
85 InlineStyleChange = 1 << nodeStyleChangeShift,
86 FullStyleChange = 2 << nodeStyleChangeShift,
87 SyntheticStyleChange = 3 << nodeStyleChangeShift
90 class Node : public EventTarget, public TreeShared<ContainerNode>, public ScriptWrappable {
91 friend class Document;
97 CDATA_SECTION_NODE = 4,
98 ENTITY_REFERENCE_NODE = 5,
100 PROCESSING_INSTRUCTION_NODE = 7,
103 DOCUMENT_TYPE_NODE = 10,
104 DOCUMENT_FRAGMENT_NODE = 11,
106 XPATH_NAMESPACE_NODE = 13
108 enum DocumentPosition {
109 DOCUMENT_POSITION_EQUIVALENT = 0x00,
110 DOCUMENT_POSITION_DISCONNECTED = 0x01,
111 DOCUMENT_POSITION_PRECEDING = 0x02,
112 DOCUMENT_POSITION_FOLLOWING = 0x04,
113 DOCUMENT_POSITION_CONTAINS = 0x08,
114 DOCUMENT_POSITION_CONTAINED_BY = 0x10,
115 DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20,
118 static bool isSupported(const String& feature, const String& version);
120 static void startIgnoringLeaks();
121 static void stopIgnoringLeaks();
123 static void dumpStatistics();
125 enum StyleChange { NoChange, NoInherit, Inherit, Detach, Force };
126 static StyleChange diff(const RenderStyle*, const RenderStyle*);
130 // DOM methods & attributes for Node
132 bool hasTagName(const QualifiedName&) const;
133 bool hasLocalName(const AtomicString&) const;
134 virtual String nodeName() const = 0;
135 virtual String nodeValue() const;
136 virtual void setNodeValue(const String&, ExceptionCode&);
137 virtual NodeType nodeType() const = 0;
138 ContainerNode* parentNode() const;
139 Element* parentElement() const;
140 Node* previousSibling() const { return m_previous; }
141 Node* nextSibling() const { return m_next; }
142 PassRefPtr<NodeList> childNodes();
143 Node* firstChild() const;
144 Node* lastChild() const;
145 bool hasAttributes() const;
146 NamedNodeMap* attributes() const;
148 virtual KURL baseURI() const;
150 void getSubresourceURLs(ListHashSet<KURL>&) const;
152 // These should all actually return a node, but this is only important for language bindings,
153 // which will already know and hold a ref on the right node to return. Returning bool allows
154 // these methods to be more efficient since they don't need to return a ref
155 bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false);
156 bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false);
157 bool removeChild(Node* child, ExceptionCode&);
158 bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false);
160 void remove(ExceptionCode&);
161 bool hasChildNodes() const { return firstChild(); }
162 virtual PassRefPtr<Node> cloneNode(bool deep) = 0;
163 const AtomicString& localName() const { return virtualLocalName(); }
164 const AtomicString& namespaceURI() const { return virtualNamespaceURI(); }
165 const AtomicString& prefix() const { return virtualPrefix(); }
166 virtual void setPrefix(const AtomicString&, ExceptionCode&);
169 bool isSameNode(Node* other) const { return this == other; }
170 bool isEqualNode(Node*) const;
171 bool isDefaultNamespace(const AtomicString& namespaceURI) const;
172 String lookupPrefix(const AtomicString& namespaceURI) const;
173 String lookupNamespaceURI(const String& prefix) const;
174 String lookupNamespacePrefix(const AtomicString& namespaceURI, const Element* originalElement) const;
176 String textContent(bool convertBRsToNewlines = false) const;
177 void setTextContent(const String&, ExceptionCode&);
179 Node* lastDescendant() const;
180 Node* firstDescendant() const;
182 // Other methods (not part of DOM)
184 bool isElementNode() const { return getFlag(IsElementFlag); }
185 bool isContainerNode() const { return getFlag(IsContainerFlag); }
186 bool isTextNode() const { return getFlag(IsTextFlag); }
188 bool isHTMLElement() const { return getFlag(IsHTMLFlag); }
190 bool isSVGElement() const { return getFlag(IsSVGFlag); }
193 virtual bool isWMLElement() const { return false; }
195 static bool isWMLElement() { return false; }
198 virtual bool isMediaControlElement() const { return false; }
199 bool isStyledElement() const { return getFlag(IsStyledElementFlag); }
200 virtual bool isFrameOwnerElement() const { return false; }
201 virtual bool isAttributeNode() const { return false; }
202 bool isCommentNode() const { return getFlag(IsCommentFlag); }
203 virtual bool isCharacterDataNode() const { return false; }
204 bool isDocumentNode() const;
205 bool isShadowRoot() const { return getFlag(IsShadowRootFlag); }
206 Node* shadowAncestorNode();
207 Node* shadowTreeRootNode();
208 bool isInShadowTree();
209 // Node's parent or shadow tree host.
210 ContainerNode* parentOrHostNode() const;
211 // Use when it's guaranteed to that shadowHost is 0.
212 ContainerNode* parentNodeGuaranteedHostFree() const;
214 Element* shadowHost() const;
215 void setShadowHost(Element*);
217 bool selfOrAncestorHasDirAutoAttribute() const { return getFlag(SelfOrAncestorHasDirAutoFlag); }
218 void setSelfOrAncestorHasDirAutoAttribute(bool flag) { setFlag(flag, SelfOrAncestorHasDirAutoFlag); }
220 // Returns the enclosing event parent node (or self) that, when clicked, would trigger a navigation.
221 Node* enclosingLinkEventParentOrSelf();
223 bool isBlockFlow() const;
224 bool isBlockFlowOrBlockTable() const;
226 // These low-level calls give the caller responsibility for maintaining the integrity of the tree.
227 void setPreviousSibling(Node* previous) { m_previous = previous; }
228 void setNextSibling(Node* next) { m_next = next; }
230 // FIXME: These two functions belong in editing -- "atomic node" is an editing concept.
231 Node* previousNodeConsideringAtomicNodes() const;
232 Node* nextNodeConsideringAtomicNodes() const;
234 // Returns the next leaf node or 0 if there are no more.
235 // Delivers leaf nodes as if the whole DOM tree were a linear chain of its leaf nodes.
236 // Uses an editing-specific concept of what a leaf node is, and should probably be moved
237 // out of the Node class into an editing-specific source file.
238 Node* nextLeafNode() const;
240 // Returns the previous leaf node or 0 if there are no more.
241 // Delivers leaf nodes as if the whole DOM tree were a linear chain of its leaf nodes.
242 // Uses an editing-specific concept of what a leaf node is, and should probably be moved
243 // out of the Node class into an editing-specific source file.
244 Node* previousLeafNode() const;
246 // enclosingBlockFlowElement() is deprecated. Use enclosingBlock instead.
247 Element* enclosingBlockFlowElement() const;
249 Element* rootEditableElement() const;
251 bool inSameContainingBlockFlowElement(Node*);
253 // FIXME: All callers of this function are almost certainly wrong!
254 virtual void deprecatedParserAddChild(PassRefPtr<Node>);
256 // Called by the parser when this element's close tag is reached,
257 // signaling that all child tags have been parsed and added.
258 // This is needed for <applet> and <object> elements, which can't lay themselves out
259 // until they know all of their nested <param>s. [Radar 3603191, 4040848].
260 // Also used for script elements and some SVG elements for similar purposes,
261 // but making parsing a special case in this respect should be avoided if possible.
262 virtual void finishParsingChildren() { }
263 virtual void beginParsingChildren() { }
265 // Called on the focused node right before dispatching an unload event.
266 virtual void aboutToUnload() { }
268 // For <link> and <style> elements.
269 virtual bool sheetLoaded() { return true; }
271 bool hasID() const { return getFlag(HasIDFlag); }
272 bool hasClass() const { return getFlag(HasClassFlag); }
273 bool active() const { return getFlag(IsActiveFlag); }
274 bool inActiveChain() const { return getFlag(InActiveChainFlag); }
275 bool inDetach() const { return getFlag(InDetachFlag); }
276 bool hovered() const { return getFlag(IsHoveredFlag); }
277 bool focused() const { return hasRareData() ? rareDataFocused() : false; }
278 bool attached() const { return getFlag(IsAttachedFlag); }
279 void setAttached() { setFlag(IsAttachedFlag); }
280 bool needsStyleRecalc() const { return styleChangeType() != NoStyleChange; }
281 StyleChangeType styleChangeType() const { return static_cast<StyleChangeType>(m_nodeFlags & StyleChangeMask); }
282 bool childNeedsStyleRecalc() const { return getFlag(ChildNeedsStyleRecalcFlag); }
283 bool isLink() const { return getFlag(IsLinkFlag); }
285 void setHasID(bool f) { setFlag(f, HasIDFlag); }
286 void setHasClass(bool f) { setFlag(f, HasClassFlag); }
287 void setChildNeedsStyleRecalc() { setFlag(ChildNeedsStyleRecalcFlag); }
288 void clearChildNeedsStyleRecalc() { clearFlag(ChildNeedsStyleRecalcFlag); }
289 void setInDocument() { setFlag(InDocumentFlag); }
290 void clearInDocument() { clearFlag(InDocumentFlag); }
292 void setInActiveChain() { setFlag(InActiveChainFlag); }
293 void clearInActiveChain() { clearFlag(InActiveChainFlag); }
295 void setNeedsStyleRecalc(StyleChangeType changeType = FullStyleChange);
296 void clearNeedsStyleRecalc() { m_nodeFlags &= ~StyleChangeMask; }
298 void setIsLink(bool f) { setFlag(f, IsLinkFlag); }
299 void setIsLink() { setFlag(IsLinkFlag); }
300 void clearIsLink() { clearFlag(IsLinkFlag); }
302 enum ShouldSetAttached {
306 void lazyAttach(ShouldSetAttached = SetAttached);
308 virtual void setFocus(bool = true);
309 virtual void setActive(bool f = true, bool /*pause*/ = false) { setFlag(f, IsActiveFlag); }
310 virtual void setHovered(bool f = true) { setFlag(f, IsHoveredFlag); }
312 virtual short tabIndex() const;
314 // Whether this kind of node can receive focus by default. Most nodes are
315 // not focusable but some elements, such as form controls and links, are.
316 virtual bool supportsFocus() const;
317 // Whether the node can actually be focused.
318 virtual bool isFocusable() const;
319 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
320 virtual bool isMouseFocusable() const;
323 // Objective-C extensions
324 bool isContentEditable() const { return rendererIsEditable(Editable); }
326 bool rendererIsEditable() const { return rendererIsEditable(Editable); }
327 bool rendererIsRichlyEditable() const { return rendererIsEditable(RichlyEditable); }
328 virtual bool shouldUseInputMethod() const;
329 virtual IntRect getRect() const;
330 IntRect renderRect(bool* isReplaced);
332 // Returns true if the node has a non-empty bounding box in layout.
333 // This does not 100% guarantee the user can see it, but is pretty close.
334 // Note: This method only works properly after layout has occurred.
335 bool hasNonEmptyBoundingBox() const;
337 virtual void recalcStyle(StyleChange = NoChange) { }
339 unsigned nodeIndex() const;
341 // Returns the DOM ownerDocument attribute. This method never returns NULL, except in the case
342 // of (1) a Document node or (2) a DocumentType node that is not used with any Document yet.
343 virtual Document* ownerDocument() const;
345 // Returns the document associated with this node. This method never returns NULL, except in the case
346 // of a DocumentType node that is not used with any Document yet. A Document node returns itself.
347 Document* document() const
350 ASSERT(m_document || (nodeType() == DOCUMENT_TYPE_NODE && !inDocument()));
354 // Do not use this method to change the document of a node until after the node has been
355 // removed from its previous document.
356 void setDocument(Document*);
358 // Used by the basic DOM methods (e.g., appendChild()).
359 void setDocumentRecursively(Document*);
361 // Returns true if this node is associated with a document and is in its associated document's
362 // node tree, false otherwise.
363 bool inDocument() const
365 ASSERT(m_document || !getFlag(InDocumentFlag));
366 return getFlag(InDocumentFlag);
369 bool isReadOnlyNode() const { return nodeType() == ENTITY_REFERENCE_NODE; }
370 virtual bool childTypeAllowed(NodeType) { return false; }
371 unsigned childNodeCount() const;
372 Node* childNode(unsigned index) const;
374 // Does a pre-order traversal of the tree to find the next node after this one.
375 // This uses the same order that tags appear in the source file. If the stayWithin
376 // argument is non-null, the traversal will stop once the specified node is reached.
377 // This can be used to restrict traversal to a particular sub-tree.
378 Node* traverseNextNode(const Node* stayWithin = 0) const;
380 // Like traverseNextNode, but skips children and starts with the next sibling.
381 Node* traverseNextSibling(const Node* stayWithin = 0) const;
383 // Does a reverse pre-order traversal to find the node that comes before the current one in document order
384 Node* traversePreviousNode(const Node* stayWithin = 0) const;
386 // Like traverseNextNode, but visits parents after their children.
387 Node* traverseNextNodePostOrder() const;
389 // Like traversePreviousNode, but visits parents before their children.
390 Node* traversePreviousNodePostOrder(const Node* stayWithin = 0) const;
391 Node* traversePreviousSiblingPostOrder(const Node* stayWithin = 0) const;
393 void checkSetPrefix(const AtomicString& prefix, ExceptionCode&);
394 bool isDescendantOf(const Node*) const;
395 bool contains(const Node*) const;
396 bool containsIncludingShadowDOM(Node*);
398 // This method is used to do strict error-checking when adding children via
399 // the public DOM API (e.g., appendChild()).
400 void checkAddChild(Node* newChild, ExceptionCode&); // Error-checking when adding via the DOM API
402 void checkReplaceChild(Node* newChild, Node* oldChild, ExceptionCode&);
403 virtual bool canReplaceChild(Node* newChild, Node* oldChild);
405 // Used to determine whether range offsets use characters or node indices.
406 virtual bool offsetInCharacters() const;
407 // Number of DOM 16-bit units contained in node. Note that rendered text length can be different - e.g. because of
408 // css-transform:capitalize breaking up precomposed characters and ligatures.
409 virtual int maxCharacterOffset() const;
411 // FIXME: We should try to find a better location for these methods.
412 virtual bool canSelectAll() const { return false; }
413 virtual void selectAll() { }
415 // Whether or not a selection can be started in this object
416 virtual bool canStartSelection() const;
418 // Getting points into and out of screen space
419 FloatPoint convertToPage(const FloatPoint&) const;
420 FloatPoint convertFromPage(const FloatPoint&) const;
422 // -----------------------------------------------------------------------------
423 // Integration with rendering tree
425 RenderObject* renderer() const { return m_renderer; }
426 RenderObject* nextRenderer();
427 RenderObject* previousRenderer();
428 void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
430 // Use these two methods with caution.
431 RenderBox* renderBox() const;
432 RenderBoxModelObject* renderBoxModelObject() const;
434 // Attaches this node to the rendering tree. This calculates the style to be applied to the node and creates an
435 // appropriate RenderObject which will be inserted into the tree (except when the style has display: none). This
436 // makes the node visible in the FrameView.
437 virtual void attach();
439 // Detaches the node from the rendering tree, making it invisible in the rendered view. This method will remove
440 // the node's rendering object from the rendering tree and delete it.
441 virtual void detach();
443 virtual void willRemove();
444 void createRendererIfNeeded();
445 PassRefPtr<RenderStyle> styleForRenderer();
446 virtual bool rendererIsNeeded(RenderStyle*);
447 virtual bool childShouldCreateRenderer(Node*) const { return true; }
448 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
450 // Wrapper for nodes that don't have a renderer, but still cache the style (like HTMLOptionElement).
451 RenderStyle* renderStyle() const;
452 virtual void setRenderStyle(PassRefPtr<RenderStyle>);
454 RenderStyle* computedStyle(PseudoId pseudoElementSpecifier = NOPSEUDO) { return virtualComputedStyle(pseudoElementSpecifier); }
456 // -----------------------------------------------------------------------------
457 // Notification of document structure changes
459 // Notifies the node that it has been inserted into the document. This is called during document parsing, and also
460 // when a node is added through the DOM methods insertBefore(), appendChild() or replaceChild(). Note that this only
461 // happens when the node becomes part of the document tree, i.e. only when the document is actually an ancestor of
462 // the node. The call happens _after_ the node has been added to the tree.
464 // This is similar to the DOMNodeInsertedIntoDocument DOM event, but does not require the overhead of event
466 virtual void insertedIntoDocument();
468 // Notifies the node that it is no longer part of the document tree, i.e. when the document is no longer an ancestor
471 // This is similar to the DOMNodeRemovedFromDocument DOM event, but does not require the overhead of event
472 // dispatching, and is called _after_ the node is removed from the tree.
473 virtual void removedFromDocument();
475 // These functions are called whenever you are connected or disconnected from a tree. That tree may be the main
476 // document tree, or it could be another disconnected tree. Override these functions to do any work that depends
477 // on connectedness to some ancestor (e.g., an ancestor <form> for example).
478 virtual void insertedIntoTree(bool /*deep*/) { }
479 virtual void removedFromTree(bool /*deep*/) { }
481 // Notifies the node that it's list of children have changed (either by adding or removing child nodes), or a child
482 // node that is of the type CDATA_SECTION_NODE, TEXT_NODE or COMMENT_NODE has changed its value.
483 virtual void childrenChanged(bool /*changedByParser*/ = false, Node* /*beforeChange*/ = 0, Node* /*afterChange*/ = 0, int /*childCountDelta*/ = 0) { }
486 virtual void formatForDebugger(char* buffer, unsigned length) const;
488 void showNode(const char* prefix = "") const;
489 void showTreeForThis() const;
490 void showTreeAndMark(const Node* markedNode1, const char* markedLabel1, const Node* markedNode2 = 0, const char* markedLabel2 = 0) const;
493 void registerDynamicNodeList(DynamicNodeList*);
494 void unregisterDynamicNodeList(DynamicNodeList*);
495 void notifyNodeListsChildrenChanged();
496 void notifyLocalNodeListsChildrenChanged();
497 void notifyNodeListsAttributeChanged();
498 void notifyLocalNodeListsAttributeChanged();
499 void notifyLocalNodeListsLabelChanged();
500 void removeCachedClassNodeList(ClassNodeList*, const String&);
501 void removeCachedNameNodeList(NameNodeList*, const String&);
502 void removeCachedTagNodeList(TagNodeList*, const QualifiedName&);
503 void removeCachedLabelsNodeList(DynamicNodeList*);
505 PassRefPtr<NodeList> getElementsByTagName(const AtomicString&);
506 PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName);
507 PassRefPtr<NodeList> getElementsByName(const String& elementName);
508 PassRefPtr<NodeList> getElementsByClassName(const String& classNames);
510 PassRefPtr<Element> querySelector(const String& selectors, ExceptionCode&);
511 PassRefPtr<NodeList> querySelectorAll(const String& selectors, ExceptionCode&);
513 unsigned short compareDocumentPosition(Node*);
515 virtual Node* toNode() { return this; }
517 virtual InputElement* toInputElement();
519 virtual ScriptExecutionContext* scriptExecutionContext() const;
521 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
522 virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
524 // Handlers to do/undo actions on the target node before an event is dispatched to it and after the event
525 // has been dispatched. The data pointer is handed back by the preDispatch and passed to postDispatch.
526 virtual void* preDispatchEventHandler(Event*) { return 0; }
527 virtual void postDispatchEventHandler(Event*, void* /*dataFromPreDispatch*/) { }
529 using EventTarget::dispatchEvent;
530 bool dispatchEvent(PassRefPtr<Event>);
531 void dispatchScopedEvent(PassRefPtr<Event>);
533 virtual void handleLocalEvents(Event*);
535 void dispatchSubtreeModifiedEvent();
536 void dispatchUIEvent(const AtomicString& eventType, int detail, PassRefPtr<Event> underlyingEvent);
537 bool dispatchKeyEvent(const PlatformKeyboardEvent&);
538 void dispatchWheelEvent(PlatformWheelEvent&);
539 bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Node* relatedTarget = 0);
540 bool dispatchMouseEvent(const AtomicString& eventType, int button, int clickCount,
541 int pageX, int pageY, int screenX, int screenY,
542 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
543 bool isSimulated, Node* relatedTarget, PassRefPtr<Event> underlyingEvent);
544 void dispatchSimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<Event> underlyingEvent);
545 void dispatchSimulatedClick(PassRefPtr<Event> underlyingEvent, bool sendMouseEvents = false, bool showPressedLook = true);
547 virtual void dispatchFocusEvent();
548 virtual void dispatchBlurEvent();
549 virtual void dispatchChangeEvents();
550 virtual void dispatchInputEvents();
552 // Perform the default action for an event.
553 virtual void defaultEventHandler(Event*);
555 // Used for disabled form elements; if true, prevents mouse events from being dispatched
556 // to event listeners, and prevents DOMActivate events from being sent at all.
557 virtual bool disabled() const;
559 using TreeShared<ContainerNode>::ref;
560 using TreeShared<ContainerNode>::deref;
562 virtual EventTargetData* eventTargetData();
563 virtual EventTargetData* ensureEventTargetData();
566 void markCachedNodeLists(JSC::MarkStack& markStack, JSC::JSGlobalData& globalData)
568 // NodeLists may be present. If so, they need to be marked.
572 markCachedNodeListsSlow(markStack, globalData);
579 IsCommentFlag = 1 << 1,
580 IsContainerFlag = 1 << 2,
581 IsElementFlag = 1 << 3,
582 IsStyledElementFlag = 1 << 4,
586 HasClassFlag = 1 << 8,
587 IsAttachedFlag = 1 << 9,
588 ChildNeedsStyleRecalcFlag = 1 << 10,
589 InDocumentFlag = 1 << 11,
590 IsLinkFlag = 1 << 12,
591 IsActiveFlag = 1 << 13,
592 IsHoveredFlag = 1 << 14,
593 InActiveChainFlag = 1 << 15,
594 InDetachFlag = 1 << 16,
595 HasRareDataFlag = 1 << 17,
596 IsShadowRootFlag = 1 << 18,
598 // These bits are used by derived classes, pulled up here so they can
599 // be stored in the same memory word as the Node bits above.
600 IsParsingChildrenFinishedFlag = 1 << 19, // Element
601 IsStyleAttributeValidFlag = 1 << 20, // StyledElement
602 IsSynchronizingStyleAttributeFlag = 1 << 21, // StyledElement
604 AreSVGAttributesValidFlag = 1 << 22, // Element
605 IsSynchronizingSVGAttributesFlag = 1 << 23, // SVGElement
606 HasSVGRareDataFlag = 1 << 24, // SVGElement
609 StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1),
611 SelfOrAncestorHasDirAutoFlag = 1 << 27,
614 DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag | AreSVGAttributesValidFlag
616 DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag
622 bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
623 void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); }
624 void setFlag(NodeFlags mask) const { m_nodeFlags |= mask; }
625 void clearFlag(NodeFlags mask) const { m_nodeFlags &= ~mask; }
628 enum ConstructionType {
629 CreateOther = DefaultNodeFlags,
630 CreateText = DefaultNodeFlags | IsTextFlag,
631 CreateComment = DefaultNodeFlags | IsCommentFlag,
632 CreateContainer = DefaultNodeFlags | IsContainerFlag,
633 CreateElement = CreateContainer | IsElementFlag,
634 CreateStyledElement = CreateElement | IsStyledElementFlag,
635 CreateHTMLElement = CreateStyledElement | IsHTMLFlag,
636 CreateSVGElement = CreateStyledElement | IsSVGFlag,
638 Node(Document*, ConstructionType);
640 virtual void willMoveToNewOwnerDocument();
641 virtual void didMoveToNewOwnerDocument();
643 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const { }
644 void setTabIndexExplicitly(short);
645 void clearTabIndexExplicitly();
647 bool hasRareData() const { return getFlag(HasRareDataFlag); }
649 NodeRareData* rareData() const;
650 NodeRareData* ensureRareData();
654 void markCachedNodeListsSlow(JSC::MarkStack&, JSC::JSGlobalData&);
657 enum EditableLevel { Editable, RichlyEditable };
658 bool rendererIsEditable(EditableLevel) const;
660 void setStyleChange(StyleChangeType);
662 // Used to share code between lazyAttach and setNeedsStyleRecalc.
663 void markAncestorsWithChildNeedsStyleRecalc();
665 RenderObject* createRendererAndStyle();
667 virtual void refEventTarget();
668 virtual void derefEventTarget();
670 virtual NodeRareData* createRareData();
671 bool rareDataFocused() const;
673 virtual RenderStyle* nonRendererRenderStyle() const;
675 virtual const AtomicString& virtualPrefix() const;
676 virtual const AtomicString& virtualLocalName() const;
677 virtual const AtomicString& virtualNamespaceURI() const;
678 virtual RenderStyle* virtualComputedStyle(PseudoId = NOPSEUDO);
680 Element* ancestorElement() const;
682 // Use Node::parentNode as the consistent way of querying a parent node.
683 // This method is made private to ensure a compiler error on call sites that
684 // don't follow this rule.
685 using TreeShared<ContainerNode>::parent;
687 void trackForDebugging();
689 Document* m_document;
692 RenderObject* m_renderer;
693 mutable uint32_t m_nodeFlags;
696 bool isParsingChildrenFinished() const { return getFlag(IsParsingChildrenFinishedFlag); }
697 void setIsParsingChildrenFinished() { setFlag(IsParsingChildrenFinishedFlag); }
698 void clearIsParsingChildrenFinished() { clearFlag(IsParsingChildrenFinishedFlag); }
699 bool isStyleAttributeValid() const { return getFlag(IsStyleAttributeValidFlag); }
700 void setIsStyleAttributeValid(bool f) { setFlag(f, IsStyleAttributeValidFlag); }
701 void setIsStyleAttributeValid() const { setFlag(IsStyleAttributeValidFlag); }
702 void clearIsStyleAttributeValid() { clearFlag(IsStyleAttributeValidFlag); }
703 bool isSynchronizingStyleAttribute() const { return getFlag(IsSynchronizingStyleAttributeFlag); }
704 void setIsSynchronizingStyleAttribute(bool f) { setFlag(f, IsSynchronizingStyleAttributeFlag); }
705 void setIsSynchronizingStyleAttribute() const { setFlag(IsSynchronizingStyleAttributeFlag); }
706 void clearIsSynchronizingStyleAttribute() const { clearFlag(IsSynchronizingStyleAttributeFlag); }
709 bool areSVGAttributesValid() const { return getFlag(AreSVGAttributesValidFlag); }
710 void setAreSVGAttributesValid() const { setFlag(AreSVGAttributesValidFlag); }
711 void clearAreSVGAttributesValid() { clearFlag(AreSVGAttributesValidFlag); }
712 bool isSynchronizingSVGAttributes() const { return getFlag(IsSynchronizingSVGAttributesFlag); }
713 void setIsSynchronizingSVGAttributes() const { setFlag(IsSynchronizingSVGAttributesFlag); }
714 void clearIsSynchronizingSVGAttributes() const { clearFlag(IsSynchronizingSVGAttributesFlag); }
715 bool hasRareSVGData() const { return getFlag(HasSVGRareDataFlag); }
716 void setHasRareSVGData() { setFlag(HasSVGRareDataFlag); }
717 void clearHasRareSVGData() { clearFlag(HasSVGRareDataFlag); }
721 // Used in Node::addSubresourceAttributeURLs() and in addSubresourceStyleURLs()
722 inline void addSubresourceURL(ListHashSet<KURL>& urls, const KURL& url)
728 inline ContainerNode* Node::parentNode() const
730 return getFlag(IsShadowRootFlag) ? 0 : parent();
733 inline ContainerNode* Node::parentOrHostNode() const
738 inline ContainerNode* Node::parentNodeGuaranteedHostFree() const
740 ASSERT(!getFlag(IsShadowRootFlag));
741 return parentOrHostNode();
747 // Outside the WebCore namespace for ease of invocation from gdb.
748 void showTree(const WebCore::Node*);