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 "EditingBoundary.h"
29 #include "EventTarget.h"
31 #include "LayoutTypes.h"
32 #include "MemoryInstrumentation.h"
33 #include "MutationObserver.h"
34 #include "RenderStyleConstants.h"
35 #include "ScriptWrappable.h"
36 #include "TreeShared.h"
37 #include <wtf/Forward.h>
38 #include <wtf/ListHashSet.h>
39 #include <wtf/text/AtomicString.h>
48 // This needs to be here because Document.h also depends on it.
49 #define DUMP_NODE_STATISTICS 0
56 class DOMSettableTokenList;
58 class DynamicSubtreeNodeList;
62 class EventDispatchMediator;
66 class HTMLInputElement;
73 class NodeListsNodeData;
75 class NodeRenderingContext;
76 class PlatformKeyboardEvent;
77 class PlatformMouseEvent;
78 class PlatformWheelEvent;
81 class RegisteredEventListener;
84 class RenderBoxModelObject;
92 class HTMLPropertiesCollection;
95 typedef int ExceptionCode;
97 const int nodeStyleChangeShift = 20;
99 // SyntheticStyleChange means that we need to go through the entire style change logic even though
100 // no style property has actually changed. It is used to restructure the tree when, for instance,
101 // RenderLayers are created or destroyed due to animation changes.
102 enum StyleChangeType {
104 InlineStyleChange = 1 << nodeStyleChangeShift,
105 FullStyleChange = 2 << nodeStyleChangeShift,
106 SyntheticStyleChange = 3 << nodeStyleChangeShift
109 class Node : public EventTarget, public ScriptWrappable, public TreeShared<Node, ContainerNode> {
110 friend class Document;
111 friend class TreeScope;
112 friend class TreeScopeAdopter;
119 CDATA_SECTION_NODE = 4,
120 ENTITY_REFERENCE_NODE = 5,
122 PROCESSING_INSTRUCTION_NODE = 7,
125 DOCUMENT_TYPE_NODE = 10,
126 DOCUMENT_FRAGMENT_NODE = 11,
128 XPATH_NAMESPACE_NODE = 13,
130 enum DocumentPosition {
131 DOCUMENT_POSITION_EQUIVALENT = 0x00,
132 DOCUMENT_POSITION_DISCONNECTED = 0x01,
133 DOCUMENT_POSITION_PRECEDING = 0x02,
134 DOCUMENT_POSITION_FOLLOWING = 0x04,
135 DOCUMENT_POSITION_CONTAINS = 0x08,
136 DOCUMENT_POSITION_CONTAINED_BY = 0x10,
137 DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20,
140 static bool isSupported(const String& feature, const String& version);
142 static void startIgnoringLeaks();
143 static void stopIgnoringLeaks();
145 static void dumpStatistics();
147 enum StyleChange { NoChange, NoInherit, Inherit, Detach, Force };
148 static StyleChange diff(const RenderStyle*, const RenderStyle*, Document*);
152 // DOM methods & attributes for Node
154 bool hasTagName(const QualifiedName&) const;
155 bool hasLocalName(const AtomicString&) const;
156 virtual String nodeName() const = 0;
157 virtual String nodeValue() const;
158 virtual void setNodeValue(const String&, ExceptionCode&);
159 virtual NodeType nodeType() const = 0;
160 ContainerNode* parentNode() const;
161 Element* parentElement() const;
162 Node* previousSibling() const { return m_previous; }
163 Node* nextSibling() const { return m_next; }
164 PassRefPtr<NodeList> childNodes();
165 Node* firstChild() const;
166 Node* lastChild() const;
167 bool hasAttributes() const;
168 NamedNodeMap* attributes() const;
170 virtual KURL baseURI() const;
172 void getSubresourceURLs(ListHashSet<KURL>&) const;
174 // These should all actually return a node, but this is only important for language bindings,
175 // which will already know and hold a ref on the right node to return. Returning bool allows
176 // these methods to be more efficient since they don't need to return a ref
177 bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false);
178 bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false);
179 bool removeChild(Node* child, ExceptionCode&);
180 bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false);
182 void remove(ExceptionCode&);
183 bool hasChildNodes() const { return firstChild(); }
184 virtual PassRefPtr<Node> cloneNode(bool deep) = 0;
185 const AtomicString& localName() const { return virtualLocalName(); }
186 const AtomicString& namespaceURI() const { return virtualNamespaceURI(); }
187 const AtomicString& prefix() const { return virtualPrefix(); }
188 virtual void setPrefix(const AtomicString&, ExceptionCode&);
191 bool isSameNode(Node* other) const { return this == other; }
192 bool isEqualNode(Node*) const;
193 bool isDefaultNamespace(const AtomicString& namespaceURI) const;
194 String lookupPrefix(const AtomicString& namespaceURI) const;
195 String lookupNamespaceURI(const String& prefix) const;
196 String lookupNamespacePrefix(const AtomicString& namespaceURI, const Element* originalElement) const;
198 String textContent(bool convertBRsToNewlines = false) const;
199 void setTextContent(const String&, ExceptionCode&);
201 Node* lastDescendant() const;
202 Node* firstDescendant() const;
204 virtual bool isActiveNode() const { return false; }
206 // Other methods (not part of DOM)
208 bool isElementNode() const { return getFlag(IsElementFlag); }
209 bool isContainerNode() const { return getFlag(IsContainerFlag); }
210 bool isTextNode() const { return getFlag(IsTextFlag); }
211 bool isHTMLElement() const { return getFlag(IsHTMLFlag); }
212 bool isSVGElement() const { return getFlag(IsSVGFlag); }
214 virtual bool isMediaControlElement() const { return false; }
215 virtual bool isMediaControls() const { return false; }
216 bool isStyledElement() const { return getFlag(IsStyledElementFlag); }
217 virtual bool isAttributeNode() const { return false; }
218 virtual bool isCharacterDataNode() const { return false; }
219 virtual bool isFrameOwnerElement() const { return false; }
220 bool isDocumentNode() const;
221 bool isShadowRoot() const { return getFlag(IsShadowRootFlag); }
222 bool inNamedFlow() const { return getFlag(InNamedFlowFlag); }
223 bool hasAttrList() const { return getFlag(HasAttrListFlag); }
224 bool hasCustomCallbacks() const { return getFlag(HasCustomCallbacksFlag); }
226 Node* shadowAncestorNode() const;
227 ShadowRoot* shadowRoot() const;
228 ShadowRoot* youngestShadowRoot() const;
230 // Returns 0, a child of ShadowRoot, or a legacy shadow root.
231 Node* nonBoundaryShadowTreeRootNode();
232 bool isInShadowTree() const;
233 // Node's parent, shadow tree host.
234 ContainerNode* parentOrHostNode() const;
235 Element* parentOrHostElement() const;
236 void setParentOrHostNode(ContainerNode*);
237 Node* highestAncestor() const;
239 // Use when it's guaranteed to that shadowHost is 0.
240 ContainerNode* parentNodeGuaranteedHostFree() const;
241 // Returns the parent node, but 0 if the parent node is a ShadowRoot.
242 ContainerNode* nonShadowBoundaryParentNode() const;
244 bool selfOrAncestorHasDirAutoAttribute() const { return getFlag(SelfOrAncestorHasDirAutoFlag); }
245 void setSelfOrAncestorHasDirAutoAttribute(bool flag) { setFlag(flag, SelfOrAncestorHasDirAutoFlag); }
247 // Returns the enclosing event parent node (or self) that, when clicked, would trigger a navigation.
248 Node* enclosingLinkEventParentOrSelf();
250 bool isBlockFlow() const;
251 bool isBlockFlowOrBlockTable() const;
253 // These low-level calls give the caller responsibility for maintaining the integrity of the tree.
254 void setPreviousSibling(Node* previous) { m_previous = previous; }
255 void setNextSibling(Node* next) { m_next = next; }
257 virtual bool canContainRangeEndPoint() const { return false; }
259 // FIXME: These two functions belong in editing -- "atomic node" is an editing concept.
260 Node* previousNodeConsideringAtomicNodes() const;
261 Node* nextNodeConsideringAtomicNodes() const;
263 // Returns the next leaf node or 0 if there are no more.
264 // Delivers leaf nodes as if the whole DOM tree were a linear chain of its leaf nodes.
265 // Uses an editing-specific concept of what a leaf node is, and should probably be moved
266 // out of the Node class into an editing-specific source file.
267 Node* nextLeafNode() const;
269 // Returns the previous leaf node or 0 if there are no more.
270 // Delivers leaf nodes as if the whole DOM tree were a linear chain of its leaf nodes.
271 // Uses an editing-specific concept of what a leaf node is, and should probably be moved
272 // out of the Node class into an editing-specific source file.
273 Node* previousLeafNode() const;
275 // enclosingBlockFlowElement() is deprecated. Use enclosingBlock instead.
276 Element* enclosingBlockFlowElement() const;
278 bool isRootEditableElement() const;
279 Element* rootEditableElement() const;
280 Element* rootEditableElement(EditableType) const;
282 bool inSameContainingBlockFlowElement(Node*);
284 // Called by the parser when this element's close tag is reached,
285 // signaling that all child tags have been parsed and added.
286 // This is needed for <applet> and <object> elements, which can't lay themselves out
287 // until they know all of their nested <param>s. [Radar 3603191, 4040848].
288 // Also used for script elements and some SVG elements for similar purposes,
289 // but making parsing a special case in this respect should be avoided if possible.
290 virtual void finishParsingChildren() { }
291 virtual void beginParsingChildren() { }
293 // Called on the focused node right before dispatching an unload event.
294 virtual void aboutToUnload() { }
296 // For <link> and <style> elements.
297 virtual bool sheetLoaded() { return true; }
298 virtual void notifyLoadedSheetAndAllCriticalSubresources(bool /* error loading subresource */) { }
299 virtual void startLoadingDynamicSheet() { ASSERT_NOT_REACHED(); }
301 bool attributeStyleDirty() const { return getFlag(AttributeStyleDirtyFlag); }
302 bool hasName() const { return getFlag(HasNameFlag); }
304 bool hasClass() const;
306 bool active() const { return getFlag(IsActiveFlag); }
307 bool inActiveChain() const { return getFlag(InActiveChainFlag); }
308 bool hovered() const { return getFlag(IsHoveredFlag); }
309 bool focused() const { return hasRareData() ? rareDataFocused() : false; }
310 bool attached() const { return getFlag(IsAttachedFlag); }
311 void setAttached() { setFlag(IsAttachedFlag); }
312 bool needsStyleRecalc() const { return styleChangeType() != NoStyleChange; }
313 StyleChangeType styleChangeType() const { return static_cast<StyleChangeType>(m_nodeFlags & StyleChangeMask); }
314 bool childNeedsStyleRecalc() const { return getFlag(ChildNeedsStyleRecalcFlag); }
315 bool isLink() const { return getFlag(IsLinkFlag); }
317 void setAttributeStyleDirty() { setFlag(AttributeStyleDirtyFlag); }
318 void clearAttributeStyleDirty() { clearFlag(AttributeStyleDirtyFlag); }
320 void setHasName(bool f) { setFlag(f, HasNameFlag); }
321 void setChildNeedsStyleRecalc() { setFlag(ChildNeedsStyleRecalcFlag); }
322 void clearChildNeedsStyleRecalc() { clearFlag(ChildNeedsStyleRecalcFlag); }
324 void setInActiveChain() { setFlag(InActiveChainFlag); }
325 void clearInActiveChain() { clearFlag(InActiveChainFlag); }
327 void setNeedsStyleRecalc(StyleChangeType changeType = FullStyleChange);
328 void clearNeedsStyleRecalc() { m_nodeFlags &= ~StyleChangeMask; }
329 virtual void scheduleSetNeedsStyleRecalc(StyleChangeType changeType = FullStyleChange) { setNeedsStyleRecalc(changeType); }
331 void setIsLink(bool f) { setFlag(f, IsLinkFlag); }
332 void setIsLink() { setFlag(IsLinkFlag); }
333 void clearIsLink() { clearFlag(IsLinkFlag); }
335 void setInNamedFlow() { setFlag(InNamedFlowFlag); }
336 void clearInNamedFlow() { clearFlag(InNamedFlowFlag); }
338 void setHasAttrList() { setFlag(HasAttrListFlag); }
339 void clearHasAttrList() { clearFlag(HasAttrListFlag); }
341 enum ShouldSetAttached {
345 void lazyAttach(ShouldSetAttached = SetAttached);
347 virtual void setFocus(bool = true);
348 virtual void setActive(bool f = true, bool /*pause*/ = false) { setFlag(f, IsActiveFlag); }
349 virtual void setHovered(bool f = true) { setFlag(f, IsHoveredFlag); }
351 virtual short tabIndex() const;
353 // Whether this kind of node can receive focus by default. Most nodes are
354 // not focusable but some elements, such as form controls and links, are.
355 virtual bool supportsFocus() const;
356 // Whether the node can actually be focused.
357 virtual bool isFocusable() const;
358 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
359 virtual bool isMouseFocusable() const;
360 virtual Node* focusDelegate();
362 bool isContentEditable();
363 bool isContentRichlyEditable();
367 bool rendererIsEditable(EditableType editableType = ContentIsEditable) const
369 switch (editableType) {
370 case ContentIsEditable:
371 return rendererIsEditable(Editable);
372 case HasEditableAXRole:
373 return isEditableToAccessibility(Editable);
375 ASSERT_NOT_REACHED();
379 bool rendererIsRichlyEditable(EditableType editableType = ContentIsEditable) const
381 switch (editableType) {
382 case ContentIsEditable:
383 return rendererIsEditable(RichlyEditable);
384 case HasEditableAXRole:
385 return isEditableToAccessibility(RichlyEditable);
387 ASSERT_NOT_REACHED();
391 virtual bool shouldUseInputMethod();
392 virtual LayoutRect getRect() const;
393 IntRect getPixelSnappedRect() const { return pixelSnappedIntRect(getRect()); }
394 LayoutRect renderRect(bool* isReplaced);
395 IntRect pixelSnappedRenderRect(bool* isReplaced) { return pixelSnappedIntRect(renderRect(isReplaced)); }
397 // Returns true if the node has a non-empty bounding box in layout.
398 // This does not 100% guarantee the user can see it, but is pretty close.
399 // Note: This method only works properly after layout has occurred.
400 bool hasNonEmptyBoundingBox() const;
402 unsigned nodeIndex() const;
404 // Returns the DOM ownerDocument attribute. This method never returns NULL, except in the case
405 // of (1) a Document node or (2) a DocumentType node that is not used with any Document yet.
406 Document* ownerDocument() const;
408 // Returns the document associated with this node. This method never returns NULL, except in the case
409 // of a DocumentType node that is not used with any Document yet. A Document node returns itself.
410 Document* document() const
413 // FIXME: below ASSERT is useful, but prevents the use of document() in the constructor or destructor
414 // due to the virtual function call to nodeType().
415 ASSERT(m_document || (nodeType() == DOCUMENT_TYPE_NODE && !inDocument()));
419 TreeScope* treeScope() const;
421 // Returns true if this node is associated with a document and is in its associated document's
422 // node tree, false otherwise.
423 bool inDocument() const
425 ASSERT(m_document || !getFlag(InDocumentFlag));
426 return getFlag(InDocumentFlag);
429 bool isReadOnlyNode() const { return nodeType() == ENTITY_REFERENCE_NODE; }
430 virtual bool childTypeAllowed(NodeType) const { return false; }
431 unsigned childNodeCount() const;
432 Node* childNode(unsigned index) const;
434 // Does a pre-order traversal of the tree to find the next node after this one.
435 // This uses the same order that tags appear in the source file. If the stayWithin
436 // argument is non-null, the traversal will stop once the specified node is reached.
437 // This can be used to restrict traversal to a particular sub-tree.
438 Node* traverseNextNode() const;
439 Node* traverseNextNode(const Node* stayWithin) const;
441 // Like traverseNextNode, but skips children and starts with the next sibling.
442 Node* traverseNextSibling() const;
443 Node* traverseNextSibling(const Node* stayWithin) const;
445 // Does a reverse pre-order traversal to find the node that comes before the current one in document order
446 Node* traversePreviousNode(const Node* stayWithin = 0) const;
448 // Like traversePreviousNode, but skips children and starts with the next sibling.
449 Node* traversePreviousSibling(const Node* stayWithin = 0) const;
451 // Like traverseNextNode, but visits parents after their children.
452 Node* traverseNextNodePostOrder() const;
454 // Like traversePreviousNode, but visits parents before their children.
455 Node* traversePreviousNodePostOrder(const Node* stayWithin = 0) const;
456 Node* traversePreviousSiblingPostOrder(const Node* stayWithin = 0) const;
458 void checkSetPrefix(const AtomicString& prefix, ExceptionCode&);
459 bool isDescendantOf(const Node*) const;
460 bool contains(const Node*) const;
461 bool containsIncludingShadowDOM(Node*);
463 // This method is used to do strict error-checking when adding children via
464 // the public DOM API (e.g., appendChild()).
465 void checkAddChild(Node* newChild, ExceptionCode&); // Error-checking when adding via the DOM API
467 void checkReplaceChild(Node* newChild, Node* oldChild, ExceptionCode&);
468 virtual bool canReplaceChild(Node* newChild, Node* oldChild);
470 // Used to determine whether range offsets use characters or node indices.
471 virtual bool offsetInCharacters() const;
472 // Number of DOM 16-bit units contained in node. Note that rendered text length can be different - e.g. because of
473 // css-transform:capitalize breaking up precomposed characters and ligatures.
474 virtual int maxCharacterOffset() const;
476 // Whether or not a selection can be started in this object
477 virtual bool canStartSelection() const;
479 // Getting points into and out of screen space
480 FloatPoint convertToPage(const FloatPoint&) const;
481 FloatPoint convertFromPage(const FloatPoint&) const;
483 // -----------------------------------------------------------------------------
484 // Integration with rendering tree
486 RenderObject* renderer() const { return m_renderer; }
487 void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
489 // Use these two methods with caution.
490 RenderBox* renderBox() const;
491 RenderBoxModelObject* renderBoxModelObject() const;
493 // Attaches this node to the rendering tree. This calculates the style to be applied to the node and creates an
494 // appropriate RenderObject which will be inserted into the tree (except when the style has display: none). This
495 // makes the node visible in the FrameView.
496 virtual void attach();
498 // Detaches the node from the rendering tree, making it invisible in the rendered view. This method will remove
499 // the node's rendering object from the rendering tree and delete it.
500 virtual void detach();
503 bool inDetach() const;
507 void reattachIfAttached();
508 void createRendererIfNeeded();
509 virtual bool rendererIsNeeded(const NodeRenderingContext&);
510 virtual bool childShouldCreateRenderer(const NodeRenderingContext&) const { return true; }
511 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
512 ContainerNode* parentNodeForRenderingAndStyle();
514 // Wrapper for nodes that don't have a renderer, but still cache the style (like HTMLOptionElement).
515 RenderStyle* renderStyle() const;
516 virtual void setRenderStyle(PassRefPtr<RenderStyle>);
518 RenderStyle* computedStyle(PseudoId pseudoElementSpecifier = NOPSEUDO) { return virtualComputedStyle(pseudoElementSpecifier); }
520 // -----------------------------------------------------------------------------
521 // Notification of document structure changes (see ContainerNode.h for more notification methods)
523 // At first, WebKit notifies the node that it has been inserted into the document. This is called during document parsing, and also
524 // when a node is added through the DOM methods insertBefore(), appendChild() or replaceChild(). The call happens _after_ the node has been added to the tree.
525 // This is similar to the DOMNodeInsertedIntoDocument DOM event, but does not require the overhead of event
528 // WebKit notifies this callback regardless if the subtree of the node is a document tree or a floating subtree.
529 // Implementation can determine the type of subtree by seeing insertionPoint->inDocument().
530 // For a performance reason, notifications are delivered only to ContainerNode subclasses if the insertionPoint is out of document.
532 // There are another callback named didNotifyDescendantInsertions(), which is called after all the descendant is notified.
533 // Only a few subclasses actually need this. To utilize this, the node should return InsertionShouldCallDidNotifyDescendantInsertions
534 // from insrtedInto().
536 enum InsertionNotificationRequest {
538 InsertionShouldCallDidNotifyDescendantInsertions
541 virtual InsertionNotificationRequest insertedInto(ContainerNode* insertionPoint);
542 virtual void didNotifyDescendantInsertions(ContainerNode*) { }
544 // Notifies the node that it is no longer part of the tree.
546 // This is a dual of insertedInto(), and is similar to the DOMNodeRemovedFromDocument DOM event, but does not require the overhead of event
547 // dispatching, and is called _after_ the node is removed from the tree.
549 virtual void removedFrom(ContainerNode* insertionPoint);
552 virtual void formatForDebugger(char* buffer, unsigned length) const;
554 void showNode(const char* prefix = "") const;
555 void showTreeForThis() const;
556 void showNodePathForThis() const;
557 void showTreeAndMark(const Node* markedNode1, const char* markedLabel1, const Node* markedNode2 = 0, const char* markedLabel2 = 0) const;
558 void showTreeForThisAcrossFrame() const;
561 void invalidateNodeListCachesInAncestors(const QualifiedName* attrName = 0, Element* attributeOwnerElement = 0);
562 NodeListsNodeData* nodeLists();
563 void removeCachedChildNodeList();
565 PassRefPtr<NodeList> getElementsByTagName(const AtomicString&);
566 PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName);
567 PassRefPtr<NodeList> getElementsByName(const String& elementName);
568 PassRefPtr<NodeList> getElementsByClassName(const String& classNames);
569 PassRefPtr<RadioNodeList> radioNodeList(const AtomicString&);
571 PassRefPtr<Element> querySelector(const AtomicString& selectors, ExceptionCode&);
572 PassRefPtr<NodeList> querySelectorAll(const AtomicString& selectors, ExceptionCode&);
574 unsigned short compareDocumentPosition(Node*);
576 virtual Node* toNode();
577 virtual HTMLInputElement* toInputElement();
579 virtual const AtomicString& interfaceName() const;
580 virtual ScriptExecutionContext* scriptExecutionContext() const;
582 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
583 virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
585 // Handlers to do/undo actions on the target node before an event is dispatched to it and after the event
586 // has been dispatched. The data pointer is handed back by the preDispatch and passed to postDispatch.
587 virtual void* preDispatchEventHandler(Event*) { return 0; }
588 virtual void postDispatchEventHandler(Event*, void* /*dataFromPreDispatch*/) { }
590 using EventTarget::dispatchEvent;
591 bool dispatchEvent(PassRefPtr<Event>);
592 void dispatchScopedEvent(PassRefPtr<Event>);
593 void dispatchScopedEventDispatchMediator(PassRefPtr<EventDispatchMediator>);
595 virtual void handleLocalEvents(Event*);
597 void dispatchRegionLayoutUpdateEvent();
599 void dispatchSubtreeModifiedEvent();
600 bool dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEvent);
601 void dispatchFocusInEvent(const AtomicString& eventType, PassRefPtr<Node> oldFocusedNode);
602 void dispatchFocusOutEvent(const AtomicString& eventType, PassRefPtr<Node> newFocusedNode);
604 bool dispatchKeyEvent(const PlatformKeyboardEvent&);
605 bool dispatchWheelEvent(const PlatformWheelEvent&);
606 bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Node* relatedTarget = 0);
607 void dispatchSimulatedClick(PassRefPtr<Event> underlyingEvent, bool sendMouseEvents = false, bool showPressedLook = true);
608 bool dispatchBeforeLoadEvent(const String& sourceURL);
610 virtual void dispatchFocusEvent(PassRefPtr<Node> oldFocusedNode);
611 virtual void dispatchBlurEvent(PassRefPtr<Node> newFocusedNode);
612 virtual void dispatchChangeEvent();
613 virtual void dispatchInputEvent();
615 // Perform the default action for an event.
616 virtual void defaultEventHandler(Event*);
618 // Used for disabled form elements; if true, prevents mouse events from being dispatched
619 // to event listeners, and prevents DOMActivate events from being sent at all.
620 virtual bool disabled() const;
622 using TreeShared<Node, ContainerNode>::ref;
623 using TreeShared<Node, ContainerNode>::deref;
625 virtual EventTargetData* eventTargetData();
626 virtual EventTargetData* ensureEventTargetData();
628 #if ENABLE(MICRODATA)
629 DOMSettableTokenList* itemProp();
630 DOMSettableTokenList* itemRef();
631 DOMSettableTokenList* itemType();
634 #if ENABLE(MUTATION_OBSERVERS)
635 void getRegisteredMutationObserversOfType(HashMap<MutationObserver*, MutationRecordDeliveryOptions>&, MutationObserver::MutationType, const QualifiedName* attributeName);
636 MutationObserverRegistration* registerMutationObserver(PassRefPtr<MutationObserver>);
637 void unregisterMutationObserver(MutationObserverRegistration*);
638 void registerTransientMutationObserver(MutationObserverRegistration*);
639 void unregisterTransientMutationObserver(MutationObserverRegistration*);
640 void notifyMutationObserversNodeWillDetach();
641 #endif // ENABLE(MUTATION_OBSERVERS)
643 #if ENABLE(STYLE_SCOPED)
644 void registerScopedHTMLStyleChild();
645 void unregisterScopedHTMLStyleChild();
647 bool hasScopedHTMLStyleChild() const;
648 size_t numberOfScopedHTMLStyleChildren() const;
650 virtual void reportMemoryUsage(MemoryObjectInfo*) const;
655 IsContainerFlag = 1 << 1,
656 IsElementFlag = 1 << 2,
657 IsStyledElementFlag = 1 << 3,
660 IsAttachedFlag = 1 << 6,
661 ChildNeedsStyleRecalcFlag = 1 << 7,
662 InDocumentFlag = 1 << 8,
664 IsActiveFlag = 1 << 10,
665 IsHoveredFlag = 1 << 11,
666 InActiveChainFlag = 1 << 12,
667 HasRareDataFlag = 1 << 13,
668 IsShadowRootFlag = 1 << 14,
670 // These bits are used by derived classes, pulled up here so they can
671 // be stored in the same memory word as the Node bits above.
672 IsParsingChildrenFinishedFlag = 1 << 15, // Element
673 IsStyleAttributeValidFlag = 1 << 16, // StyledElement
675 AreSVGAttributesValidFlag = 1 << 17, // Element
676 IsSynchronizingSVGAttributesFlag = 1 << 18, // SVGElement
677 HasSVGRareDataFlag = 1 << 19, // SVGElement
680 StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1),
682 SelfOrAncestorHasDirAutoFlag = 1 << 22,
684 HasNameFlag = 1 << 23,
686 AttributeStyleDirtyFlag = 1 << 24,
689 DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag | AreSVGAttributesValidFlag,
691 DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag,
693 InNamedFlowFlag = 1 << 26,
694 HasAttrListFlag = 1 << 27,
695 HasCustomCallbacksFlag = 1 << 28
700 bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
701 void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); }
702 void setFlag(NodeFlags mask) const { m_nodeFlags |= mask; }
703 void clearFlag(NodeFlags mask) const { m_nodeFlags &= ~mask; }
706 enum ConstructionType {
707 CreateOther = DefaultNodeFlags,
708 CreateText = DefaultNodeFlags | IsTextFlag,
709 CreateContainer = DefaultNodeFlags | IsContainerFlag,
710 CreateElement = CreateContainer | IsElementFlag,
711 CreateShadowRoot = CreateContainer | IsShadowRootFlag,
712 CreateStyledElement = CreateElement | IsStyledElementFlag,
713 CreateHTMLElement = CreateStyledElement | IsHTMLFlag,
714 CreateFrameOwnerElement = CreateHTMLElement | HasCustomCallbacksFlag,
715 CreateSVGElement = CreateStyledElement | IsSVGFlag,
716 CreateDocument = CreateContainer | InDocumentFlag
718 Node(Document*, ConstructionType);
720 virtual void didMoveToNewDocument(Document* oldDocument);
722 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const { }
723 void setTabIndexExplicitly(short);
724 void clearTabIndexExplicitly();
726 bool hasRareData() const { return getFlag(HasRareDataFlag); }
728 NodeRareData* rareData() const;
729 NodeRareData* ensureRareData();
730 void clearRareData();
732 void setHasCustomCallbacks() { setFlag(true, HasCustomCallbacksFlag); }
735 friend class TreeShared<Node, ContainerNode>;
737 void removedLastRef();
739 // These API should be only used for a tree scope migration.
740 // setTreeScope() returns NodeRareData to save extra nodeRareData() invocations on the caller site.
741 NodeRareData* setTreeScope(TreeScope*);
742 void setDocument(Document*);
744 enum EditableLevel { Editable, RichlyEditable };
745 bool rendererIsEditable(EditableLevel) const;
746 bool isEditableToAccessibility(EditableLevel) const;
748 void setStyleChange(StyleChangeType);
750 // Used to share code between lazyAttach and setNeedsStyleRecalc.
751 void markAncestorsWithChildNeedsStyleRecalc();
753 virtual void refEventTarget();
754 virtual void derefEventTarget();
756 virtual OwnPtr<NodeRareData> createRareData();
757 bool rareDataFocused() const;
759 virtual RenderStyle* nonRendererRenderStyle() const;
761 virtual const AtomicString& virtualPrefix() const;
762 virtual const AtomicString& virtualLocalName() const;
763 virtual const AtomicString& virtualNamespaceURI() const;
764 virtual RenderStyle* virtualComputedStyle(PseudoId = NOPSEUDO);
766 Element* ancestorElement() const;
768 Node* traverseNextAncestorSibling() const;
769 Node* traverseNextAncestorSibling(const Node* stayWithin) const;
771 // Use Node::parentNode as the consistent way of querying a parent node.
772 // This method is made private to ensure a compiler error on call sites that
773 // don't follow this rule.
774 using TreeShared<Node, ContainerNode>::parent;
775 using TreeShared<Node, ContainerNode>::setParent;
777 void trackForDebugging();
779 #if ENABLE(MUTATION_OBSERVERS)
780 Vector<OwnPtr<MutationObserverRegistration> >* mutationObserverRegistry();
781 HashSet<MutationObserverRegistration*>* transientMutationObserverRegistry();
782 void collectMatchingObserversForMutation(HashMap<MutationObserver*, MutationRecordDeliveryOptions>&, Node* fromNode, MutationObserver::MutationType, const QualifiedName* attributeName);
785 mutable uint32_t m_nodeFlags;
786 Document* m_document;
789 RenderObject* m_renderer;
792 bool isStyleAttributeValid() const { return getFlag(IsStyleAttributeValidFlag); }
793 void setIsStyleAttributeValid(bool f) { setFlag(f, IsStyleAttributeValidFlag); }
794 void setIsStyleAttributeValid() const { setFlag(IsStyleAttributeValidFlag); }
795 void clearIsStyleAttributeValid() { clearFlag(IsStyleAttributeValidFlag); }
798 bool isParsingChildrenFinished() const { return getFlag(IsParsingChildrenFinishedFlag); }
799 void setIsParsingChildrenFinished() { setFlag(IsParsingChildrenFinishedFlag); }
800 void clearIsParsingChildrenFinished() { clearFlag(IsParsingChildrenFinishedFlag); }
803 bool areSVGAttributesValid() const { return getFlag(AreSVGAttributesValidFlag); }
804 void setAreSVGAttributesValid() const { setFlag(AreSVGAttributesValidFlag); }
805 void clearAreSVGAttributesValid() { clearFlag(AreSVGAttributesValidFlag); }
806 bool isSynchronizingSVGAttributes() const { return getFlag(IsSynchronizingSVGAttributesFlag); }
807 void setIsSynchronizingSVGAttributes() const { setFlag(IsSynchronizingSVGAttributesFlag); }
808 void clearIsSynchronizingSVGAttributes() const { clearFlag(IsSynchronizingSVGAttributesFlag); }
809 bool hasSVGRareData() const { return getFlag(HasSVGRareDataFlag); }
810 void setHasSVGRareData() { setFlag(HasSVGRareDataFlag); }
811 void clearHasSVGRareData() { clearFlag(HasSVGRareDataFlag); }
814 #if ENABLE(MICRODATA)
815 void setItemProp(const String&);
816 void setItemRef(const String&);
817 void setItemType(const String&);
821 // Used in Node::addSubresourceAttributeURLs() and in addSubresourceStyleURLs()
822 inline void addSubresourceURL(ListHashSet<KURL>& urls, const KURL& url)
828 inline ContainerNode* Node::parentNode() const
830 return getFlag(IsShadowRootFlag) ? 0 : parent();
833 inline void Node::setParentOrHostNode(ContainerNode* parent)
838 inline ContainerNode* Node::parentOrHostNode() const
843 inline ContainerNode* Node::parentNodeGuaranteedHostFree() const
845 ASSERT(!getFlag(IsShadowRootFlag));
846 return parentOrHostNode();
849 inline void Node::reattach()
856 inline void Node::reattachIfAttached()
865 // Outside the WebCore namespace for ease of invocation from gdb.
866 void showTree(const WebCore::Node*);
867 void showNodePath(const WebCore::Node*);