• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 Apple Inc. All rights reserved.
6  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
7  *
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.
12  *
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.
17  *
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.
22  *
23  */
24 
25 #ifndef Node_h
26 #define Node_h
27 
28 #include "EventTarget.h"
29 #include "KURLHash.h"
30 #include "ScriptWrappable.h"
31 #include "TreeShared.h"
32 #include <wtf/ListHashSet.h>
33 
34 namespace WebCore {
35 
36 class AtomicString;
37 class Attribute;
38 class ContainerNode;
39 class Document;
40 class DynamicNodeList;
41 class Element;
42 class Event;
43 class EventListener;
44 class FloatPoint;
45 class Frame;
46 class IntRect;
47 class KeyboardEvent;
48 class NSResolver;
49 class NamedNodeMap;
50 class NodeList;
51 class NodeRareData;
52 class PlatformKeyboardEvent;
53 class PlatformMouseEvent;
54 class PlatformWheelEvent;
55 class QualifiedName;
56 class RegisteredEventListener;
57 class RenderArena;
58 class RenderBox;
59 class RenderBoxModelObject;
60 class RenderObject;
61 class RenderStyle;
62 class StringBuilder;
63 
64 typedef int ExceptionCode;
65 
66 // SyntheticStyleChange means that we need to go through the entire style change logic even though
67 // no style property has actually changed. It is used to restructure the tree when, for instance,
68 // RenderLayers are created or destroyed due to animation changes.
69 enum StyleChangeType { NoStyleChange, InlineStyleChange, FullStyleChange, SyntheticStyleChange };
70 
71 const unsigned short DOCUMENT_POSITION_EQUIVALENT = 0x00;
72 const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01;
73 const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02;
74 const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04;
75 const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08;
76 const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
77 const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;
78 
79 // this class implements nodes, which can have a parent but no children:
80 class Node : public EventTarget, public TreeShared<Node>, public ScriptWrappable {
81     friend class Document;
82 public:
83     enum NodeType {
84         ELEMENT_NODE = 1,
85         ATTRIBUTE_NODE = 2,
86         TEXT_NODE = 3,
87         CDATA_SECTION_NODE = 4,
88         ENTITY_REFERENCE_NODE = 5,
89         ENTITY_NODE = 6,
90         PROCESSING_INSTRUCTION_NODE = 7,
91         COMMENT_NODE = 8,
92         DOCUMENT_NODE = 9,
93         DOCUMENT_TYPE_NODE = 10,
94         DOCUMENT_FRAGMENT_NODE = 11,
95         NOTATION_NODE = 12,
96         XPATH_NAMESPACE_NODE = 13
97     };
98 
99     static bool isSupported(const String& feature, const String& version);
100 
101     static void startIgnoringLeaks();
102     static void stopIgnoringLeaks();
103 
104     static void dumpStatistics();
105 
106     enum StyleChange { NoChange, NoInherit, Inherit, Detach, Force };
107     static StyleChange diff(const RenderStyle*, const RenderStyle*);
108 
109     virtual ~Node();
110 
111     // DOM methods & attributes for Node
112 
113     bool hasTagName(const QualifiedName&) const;
114     virtual String nodeName() const = 0;
115     virtual String nodeValue() const;
116     virtual void setNodeValue(const String&, ExceptionCode&);
117     virtual NodeType nodeType() const = 0;
parentNode()118     Node* parentNode() const { return parent(); }
119     Element* parentElement() const;
previousSibling()120     Node* previousSibling() const { return m_previous; }
nextSibling()121     Node* nextSibling() const { return m_next; }
122     PassRefPtr<NodeList> childNodes();
firstChild()123     Node* firstChild() const { return isContainerNode() ? containerFirstChild() : 0; }
lastChild()124     Node* lastChild() const { return isContainerNode() ? containerLastChild() : 0; }
125     bool hasAttributes() const;
126     NamedNodeMap* attributes() const;
127 
128     virtual KURL baseURI() const;
129 
130     void getSubresourceURLs(ListHashSet<KURL>&) const;
131 
132     // These should all actually return a node, but this is only important for language bindings,
133     // which will already know and hold a ref on the right node to return. Returning bool allows
134     // these methods to be more efficient since they don't need to return a ref
135     virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false);
136     virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false);
137     virtual bool removeChild(Node* child, ExceptionCode&);
138     virtual bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false);
139 
140     void remove(ExceptionCode&);
hasChildNodes()141     bool hasChildNodes() const { return firstChild(); }
142     virtual PassRefPtr<Node> cloneNode(bool deep) = 0;
localName()143     const AtomicString& localName() const { return virtualLocalName(); }
namespaceURI()144     const AtomicString& namespaceURI() const { return virtualNamespaceURI(); }
prefix()145     const AtomicString& prefix() const { return virtualPrefix(); }
146     virtual void setPrefix(const AtomicString&, ExceptionCode&);
147     void normalize();
148 
isSameNode(Node * other)149     bool isSameNode(Node* other) const { return this == other; }
150     bool isEqualNode(Node*) const;
151     bool isDefaultNamespace(const AtomicString& namespaceURI) const;
152     String lookupPrefix(const AtomicString& namespaceURI) const;
153     String lookupNamespaceURI(const String& prefix) const;
154     String lookupNamespacePrefix(const AtomicString& namespaceURI, const Element* originalElement) const;
155 
156     String textContent(bool convertBRsToNewlines = false) const;
157     void setTextContent(const String&, ExceptionCode&);
158 
159     Node* lastDescendant() const;
160     Node* firstDescendant() const;
161 
162     // Other methods (not part of DOM)
163 
isElementNode()164     bool isElementNode() const { return m_isElement; }
isContainerNode()165     bool isContainerNode() const { return m_isContainer; }
isTextNode()166     bool isTextNode() const { return m_isText; }
167 
isHTMLElement()168     virtual bool isHTMLElement() const { return false; }
169 
170 #if ENABLE(SVG)
isSVGElement()171     virtual bool isSVGElement() const { return false; }
172 #else
isSVGElement()173     static bool isSVGElement() { return false; }
174 #endif
175 
176 #if ENABLE(WML)
isWMLElement()177     virtual bool isWMLElement() const { return false; }
178 #else
isWMLElement()179     static bool isWMLElement() { return false; }
180 #endif
181 
182 #if ENABLE(MATHML)
isMathMLElement()183     virtual bool isMathMLElement() const { return false; }
184 #else
isMathMLElement()185     static bool isMathMLElement() { return false; }
186 #endif
187 
188 
isMediaControlElement()189     virtual bool isMediaControlElement() const { return false; }
isStyledElement()190     virtual bool isStyledElement() const { return false; }
isFrameOwnerElement()191     virtual bool isFrameOwnerElement() const { return false; }
isAttributeNode()192     virtual bool isAttributeNode() const { return false; }
isCommentNode()193     virtual bool isCommentNode() const { return false; }
isCharacterDataNode()194     virtual bool isCharacterDataNode() const { return false; }
195     bool isDocumentNode() const;
isShadowNode()196     virtual bool isShadowNode() const { return false; }
shadowParentNode()197     virtual Node* shadowParentNode() { return 0; }
198     Node* shadowAncestorNode();
199     Node* shadowTreeRootNode();
200     bool isInShadowTree();
201 
202     // The node's parent for the purpose of event capture and bubbling.
203     virtual ContainerNode* eventParentNode();
204 
205     // Returns the enclosing event parent node (or self) that, when clicked, would trigger a navigation.
206     Node* enclosingLinkEventParentOrSelf();
207 
208     // Node ancestors when concerned about event flow
209     void eventAncestors(Vector<RefPtr<ContainerNode> > &ancestors);
210 
211     bool isBlockFlow() const;
212     bool isBlockFlowOrBlockTable() const;
213 
214     // These low-level calls give the caller responsibility for maintaining the integrity of the tree.
setPreviousSibling(Node * previous)215     void setPreviousSibling(Node* previous) { m_previous = previous; }
setNextSibling(Node * next)216     void setNextSibling(Node* next) { m_next = next; }
217 
218     // FIXME: These two functions belong in editing -- "atomic node" is an editing concept.
219     Node* previousNodeConsideringAtomicNodes() const;
220     Node* nextNodeConsideringAtomicNodes() const;
221 
222     /** (Not part of the official DOM)
223      * Returns the next leaf node.
224      *
225      * Using this function delivers leaf nodes as if the whole DOM tree were a linear chain of its leaf nodes.
226      * @return next leaf node or 0 if there are no more.
227      */
228     Node* nextLeafNode() const;
229 
230     /** (Not part of the official DOM)
231      * Returns the previous leaf node.
232      *
233      * Using this function delivers leaf nodes as if the whole DOM tree were a linear chain of its leaf nodes.
234      * @return previous leaf node or 0 if there are no more.
235      */
236     Node* previousLeafNode() const;
237 
238     bool isEditableBlock() const;
239 
240     // enclosingBlockFlowElement() is deprecated.  Use enclosingBlock instead.
241     Element* enclosingBlockFlowElement() const;
242 
243     Element* enclosingInlineElement() const;
244     Element* rootEditableElement() const;
245 
246     bool inSameContainingBlockFlowElement(Node*);
247 
248     // Used by the parser. Checks against the DTD, unlike DOM operations like appendChild().
249     // Also does not dispatch DOM mutation events.
250     // Returns the appropriate container node for future insertions as you parse, or 0 for failure.
251     virtual ContainerNode* addChild(PassRefPtr<Node>);
252 
253     // Called by the parser when this element's close tag is reached,
254     // signaling that all child tags have been parsed and added.
255     // This is needed for <applet> and <object> elements, which can't lay themselves out
256     // until they know all of their nested <param>s. [Radar 3603191, 4040848].
257     // Also used for script elements and some SVG elements for similar purposes,
258     // but making parsing a special case in this respect should be avoided if possible.
finishParsingChildren()259     virtual void finishParsingChildren() { }
beginParsingChildren()260     virtual void beginParsingChildren() { }
261 
262     // Called by the frame right before dispatching an unloadEvent. [Radar 4532113]
263     // This is needed for HTMLInputElements to tell the frame that it is done editing
264     // (sends textFieldDidEndEditing notification)
aboutToUnload()265     virtual void aboutToUnload() { }
266 
267     // For <link> and <style> elements.
sheetLoaded()268     virtual bool sheetLoaded() { return true; }
269 
hasID()270     bool hasID() const { return m_hasId; }
hasClass()271     bool hasClass() const { return m_hasClass; }
active()272     bool active() const { return m_active; }
inActiveChain()273     bool inActiveChain() const { return m_inActiveChain; }
inDetach()274     bool inDetach() const { return m_inDetach; }
hovered()275     bool hovered() const { return m_hovered; }
focused()276     bool focused() const { return hasRareData() ? rareDataFocused() : false; }
attached()277     bool attached() const { return m_attached; }
278     void setAttached(bool b = true) { m_attached = b; }
needsStyleRecalc()279     bool needsStyleRecalc() const { return m_styleChange != NoStyleChange; }
styleChangeType()280     StyleChangeType styleChangeType() const { return static_cast<StyleChangeType>(m_styleChange); }
childNeedsStyleRecalc()281     bool childNeedsStyleRecalc() const { return m_childNeedsStyleRecalc; }
isLink()282     bool isLink() const { return m_isLink; }
283     void setHasID(bool b = true) { m_hasId = b; }
284     void setHasClass(bool b = true) { m_hasClass = b; }
285     void setChildNeedsStyleRecalc(bool b = true) { m_childNeedsStyleRecalc = b; }
286     void setInDocument(bool b = true) { m_inDocument = b; }
287     void setInActiveChain(bool b = true) { m_inActiveChain = b; }
288     void setNeedsStyleRecalc(StyleChangeType changeType = FullStyleChange);
289     void setIsLink(bool b = true) { m_isLink = b; }
290 
291     void lazyAttach();
292     virtual bool canLazyAttach();
293 
294     virtual void setFocus(bool b = true);
295     virtual void setActive(bool b = true, bool /*pause*/ = false) { m_active = b; }
296     virtual void setHovered(bool b = true) { m_hovered = b; }
297 
298     virtual short tabIndex() const;
299 
300     // Whether this kind of node can receive focus by default. Most nodes are
301     // not focusable but some elements, such as form controls and links are.
302     virtual bool supportsFocus() const;
303     // Whether the node can actually be focused.
304     virtual bool isFocusable() const;
305     virtual bool isKeyboardFocusable(KeyboardEvent*) const;
306     virtual bool isMouseFocusable() const;
307 
308     virtual bool isContentEditable() const;
309     virtual bool isContentRichlyEditable() const;
310     virtual bool shouldUseInputMethod() const;
311     virtual IntRect getRect() const;
312 
313     virtual void recalcStyle(StyleChange = NoChange) { }
314 
315     unsigned nodeIndex() const;
316 
317     // Returns the DOM ownerDocument attribute. This method never returns NULL, except in the case
318     // of (1) a Document node or (2) a DocumentType node that is not used with any Document yet.
319     virtual Document* ownerDocument() const;
320 
321     // Returns the document associated with this node. This method never returns NULL, except in the case
322     // of a DocumentType node that is not used with any Document yet. A Document node returns itself.
document()323     Document* document() const
324     {
325         ASSERT(this);
326         ASSERT(m_document || (nodeType() == DOCUMENT_TYPE_NODE && !inDocument()));
327         return m_document;
328     }
329     void setDocument(Document*);
330 
331     // Returns true if this node is associated with a document and is in its associated document's
332     // node tree, false otherwise.
inDocument()333     bool inDocument() const
334     {
335         ASSERT(m_document || !m_inDocument);
336         return m_inDocument;
337     }
338 
isReadOnlyNode()339     bool isReadOnlyNode() const { return nodeType() == ENTITY_REFERENCE_NODE; }
childTypeAllowed(NodeType)340     virtual bool childTypeAllowed(NodeType) { return false; }
childNodeCount()341     unsigned childNodeCount() const { return isContainerNode() ? containerChildNodeCount() : 0; }
childNode(unsigned index)342     Node* childNode(unsigned index) const { return isContainerNode() ? containerChildNode(index) : 0; }
343 
344     /**
345      * Does a pre-order traversal of the tree to find the node next node after this one. This uses the same order that
346      * the tags appear in the source file.
347      *
348      * @param stayWithin If not null, the traversal will stop once the specified node is reached. This can be used to
349      * restrict traversal to a particular sub-tree.
350      *
351      * @return The next node, in document order
352      *
353      * see @ref traversePreviousNode()
354      */
355     Node* traverseNextNode(const Node* stayWithin = 0) const;
356 
357     // Like traverseNextNode, but skips children and starts with the next sibling.
358     Node* traverseNextSibling(const Node* stayWithin = 0) const;
359 
360     /**
361      * Does a reverse pre-order traversal to find the node that comes before the current one in document order
362      *
363      * see @ref traverseNextNode()
364      */
365     Node* traversePreviousNode(const Node * stayWithin = 0) const;
366 
367     // Like traverseNextNode, but visits parents after their children.
368     Node* traverseNextNodePostOrder() const;
369 
370     // Like traversePreviousNode, but visits parents before their children.
371     Node* traversePreviousNodePostOrder(const Node *stayWithin = 0) const;
372     Node* traversePreviousSiblingPostOrder(const Node *stayWithin = 0) const;
373 
374     /**
375      * Finds previous or next editable leaf node.
376      */
377     Node* previousEditable() const;
378     Node* nextEditable() const;
379 
renderer()380     RenderObject* renderer() const { return m_renderer; }
381     RenderObject* nextRenderer();
382     RenderObject* previousRenderer();
setRenderer(RenderObject * renderer)383     void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
384 
385     // Use these two methods with caution.
386     RenderBox* renderBox() const;
387     RenderBoxModelObject* renderBoxModelObject() const;
388 
389     void checkSetPrefix(const AtomicString& prefix, ExceptionCode&);
390     bool isDescendantOf(const Node*) const;
391     bool contains(const Node*) const;
392 
393     // These two methods are mutually exclusive.  The former is used to do strict error-checking
394     // when adding children via the public DOM API (e.g., appendChild()).  The latter is called only when parsing,
395     // to sanity-check against the DTD for error recovery.
396     void checkAddChild(Node* newChild, ExceptionCode&); // Error-checking when adding via the DOM API
397     virtual bool childAllowed(Node* newChild);          // Error-checking during parsing that checks the DTD
398 
399     void checkReplaceChild(Node* newChild, Node* oldChild, ExceptionCode&);
400     virtual bool canReplaceChild(Node* newChild, Node* oldChild);
401 
402     // Used to determine whether range offsets use characters or node indices.
403     virtual bool offsetInCharacters() const;
404     // Number of DOM 16-bit units contained in node. Note that rendered text length can be different - e.g. because of
405     // css-transform:capitalize breaking up precomposed characters and ligatures.
406     virtual int maxCharacterOffset() const;
407 
408     // FIXME: We should try to find a better location for these methods.
canSelectAll()409     virtual bool canSelectAll() const { return false; }
selectAll()410     virtual void selectAll() { }
411 
412     // Whether or not a selection can be started in this object
413     virtual bool canStartSelection() const;
414 
415     // Getting points into and out of screen space
416     FloatPoint convertToPage(const FloatPoint& p) const;
417     FloatPoint convertFromPage(const FloatPoint& p) const;
418 
419     // -----------------------------------------------------------------------------
420     // Integration with rendering tree
421 
422     /**
423      * Attaches this node to the rendering tree. This calculates the style to be applied to the node and creates an
424      * appropriate RenderObject which will be inserted into the tree (except when the style has display: none). This
425      * makes the node visible in the FrameView.
426      */
427     virtual void attach();
428 
429     /**
430      * Detaches the node from the rendering tree, making it invisible in the rendered view. This method will remove
431      * the node's rendering object from the rendering tree and delete it.
432      */
433     virtual void detach();
434 
435     virtual void willRemove();
436     void createRendererIfNeeded();
437     PassRefPtr<RenderStyle> styleForRenderer();
438     virtual bool rendererIsNeeded(RenderStyle*);
439 #if ENABLE(SVG) || ENABLE(XHTMLMP)
childShouldCreateRenderer(Node *)440     virtual bool childShouldCreateRenderer(Node*) const { return true; }
441 #endif
442     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
443 
444     // Wrapper for nodes that don't have a renderer, but still cache the style (like HTMLOptionElement).
445     RenderStyle* renderStyle() const;
446     virtual void setRenderStyle(PassRefPtr<RenderStyle>);
447 
448     virtual RenderStyle* computedStyle();
449 
450     // -----------------------------------------------------------------------------
451     // Notification of document structure changes
452 
453     /**
454      * Notifies the node that it has been inserted into the document. This is called during document parsing, and also
455      * when a node is added through the DOM methods insertBefore(), appendChild() or replaceChild(). Note that this only
456      * happens when the node becomes part of the document tree, i.e. only when the document is actually an ancestor of
457      * the node. The call happens _after_ the node has been added to the tree.
458      *
459      * This is similar to the DOMNodeInsertedIntoDocument DOM event, but does not require the overhead of event
460      * dispatching.
461      */
462     virtual void insertedIntoDocument();
463 
464     /**
465      * Notifies the node that it is no longer part of the document tree, i.e. when the document is no longer an ancestor
466      * node.
467      *
468      * This is similar to the DOMNodeRemovedFromDocument DOM event, but does not require the overhead of event
469      * dispatching, and is called _after_ the node is removed from the tree.
470      */
471     virtual void removedFromDocument();
472 
473     // These functions are called whenever you are connected or disconnected from a tree.  That tree may be the main
474     // document tree, or it could be another disconnected tree.  Override these functions to do any work that depends
475     // on connectedness to some ancestor (e.g., an ancestor <form> for example).
insertedIntoTree(bool)476     virtual void insertedIntoTree(bool /*deep*/) { }
removedFromTree(bool)477     virtual void removedFromTree(bool /*deep*/) { }
478 
479     /**
480      * Notifies the node that it's list of children have changed (either by adding or removing child nodes), or a child
481      * node that is of the type CDATA_SECTION_NODE, TEXT_NODE or COMMENT_NODE has changed its value.
482      */
483     virtual void childrenChanged(bool /*changedByParser*/ = false, Node* /*beforeChange*/ = 0, Node* /*afterChange*/ = 0, int /*childCountDelta*/ = 0) { }
484 
485 #if !defined(NDEBUG) || defined(ANDROID_DOM_LOGGING)
486     virtual void formatForDebugger(char* buffer, unsigned length) const;
487 
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;
491 #endif
492 
493     void registerDynamicNodeList(DynamicNodeList*);
494     void unregisterDynamicNodeList(DynamicNodeList*);
495     void notifyNodeListsChildrenChanged();
496     void notifyLocalNodeListsChildrenChanged();
497     void notifyNodeListsAttributeChanged();
498     void notifyLocalNodeListsAttributeChanged();
499 
500     PassRefPtr<NodeList> getElementsByTagName(const String&);
501     PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI, const String& localName);
502     PassRefPtr<NodeList> getElementsByName(const String& elementName);
503     PassRefPtr<NodeList> getElementsByClassName(const String& classNames);
504 
505     PassRefPtr<Element> querySelector(const String& selectors, ExceptionCode&);
506     PassRefPtr<NodeList> querySelectorAll(const String& selectors, ExceptionCode&);
507 
508     unsigned short compareDocumentPosition(Node*);
509 
510 #ifdef ANDROID_INSTRUMENT
511     // Overridden to prevent the normal new from being called.
512     void* operator new(size_t size);
513     void* operator new[](size_t size);
514 
515     // Overridden to prevent the normal delete from being called.
516     void operator delete(void* p, size_t size);
517     void operator delete[](void* p, size_t size);
518 
519     static size_t reportDOMNodesSize();
520 #endif
521 
toNode()522     virtual Node* toNode() { return this; }
523 
524     virtual ScriptExecutionContext* scriptExecutionContext() const;
525 
526     virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
527     virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
528 
529     // Handlers to do/undo actions on the target node before an event is dispatched to it and after the event
530     // has been dispatched.  The data pointer is handed back by the preDispatch and passed to postDispatch.
preDispatchEventHandler(Event *)531     virtual void* preDispatchEventHandler(Event*) { return 0; }
postDispatchEventHandler(Event *,void *)532     virtual void postDispatchEventHandler(Event*, void* /*dataFromPreDispatch*/) { }
533 
534     using EventTarget::dispatchEvent;
535     virtual bool dispatchEvent(PassRefPtr<Event>);
536 
537     bool dispatchGenericEvent(PassRefPtr<Event>);
538     virtual void handleLocalEvents(Event*);
539 
540     void dispatchSubtreeModifiedEvent();
541     void dispatchUIEvent(const AtomicString& eventType, int detail, PassRefPtr<Event> underlyingEvent);
542     bool dispatchKeyEvent(const PlatformKeyboardEvent&);
543     void dispatchWheelEvent(PlatformWheelEvent&);
544     bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType,
545         int clickCount = 0, Node* relatedTarget = 0);
546     bool dispatchMouseEvent(const AtomicString& eventType, int button, int clickCount,
547         int pageX, int pageY, int screenX, int screenY,
548         bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
549         bool isSimulated, Node* relatedTarget, PassRefPtr<Event> underlyingEvent);
550     void dispatchSimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<Event> underlyingEvent);
551     void dispatchSimulatedClick(PassRefPtr<Event> underlyingEvent, bool sendMouseEvents = false, bool showPressedLook = true);
552 
553     virtual void dispatchFocusEvent();
554     virtual void dispatchBlurEvent();
555 
556     /**
557      * Perform the default action for an event e.g. submitting a form
558      */
559     virtual void defaultEventHandler(Event*);
560 
561     /**
562      * Used for disabled form elements; if true, prevents mouse events from being dispatched
563      * to event listeners, and prevents DOMActivate events from being sent at all.
564      */
565     virtual bool disabled() const;
566 
567     using TreeShared<Node>::ref;
568     using TreeShared<Node>::deref;
569 
570     virtual EventTargetData* eventTargetData();
571     virtual EventTargetData* ensureEventTargetData();
572 
573 protected:
574     // CreateElementZeroRefCount is deprecated and can be removed once we convert all element
575     // classes to start with a reference count of 1.
576     enum ConstructionType { CreateContainer, CreateElement, CreateOther, CreateText, CreateElementZeroRefCount };
577     Node(Document*, ConstructionType);
578 
579     virtual void willMoveToNewOwnerDocument();
580     virtual void didMoveToNewOwnerDocument();
581 
addSubresourceAttributeURLs(ListHashSet<KURL> &)582     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const { }
583     void setTabIndexExplicitly(short);
584 
hasRareData()585     bool hasRareData() const { return m_hasRareData; }
586 #if ENABLE(SVG)
hasRareSVGData()587     bool hasRareSVGData() const { return m_hasRareSVGData; }
588 #endif
589 
590     NodeRareData* rareData() const;
591     NodeRareData* ensureRareData();
592 
593 private:
594     static bool initialRefCount(ConstructionType);
595     static bool isContainer(ConstructionType);
596     static bool isElement(ConstructionType);
597     static bool isText(ConstructionType);
598 
refEventTarget()599     virtual void refEventTarget() { ref(); }
derefEventTarget()600     virtual void derefEventTarget() { deref(); }
601 
602     void removeAllEventListenersSlowCase();
603 
604     virtual NodeRareData* createRareData();
605     Node* containerChildNode(unsigned index) const;
606     unsigned containerChildNodeCount() const;
607     Node* containerFirstChild() const;
608     Node* containerLastChild() const;
609     bool rareDataFocused() const;
610 
611     virtual RenderStyle* nonRendererRenderStyle() const;
612 
613     virtual const AtomicString& virtualPrefix() const;
614     virtual const AtomicString& virtualLocalName() const;
615     virtual const AtomicString& virtualNamespaceURI() const;
616 
617     Element* ancestorElement() const;
618 
619     void appendTextContent(bool convertBRsToNewlines, StringBuilder&) const;
620 
621     Document* m_document;
622     Node* m_previous;
623     Node* m_next;
624     RenderObject* m_renderer;
625 
626     unsigned m_styleChange : 2;
627     bool m_hasId : 1;
628     bool m_hasClass : 1;
629     bool m_attached : 1;
630     bool m_childNeedsStyleRecalc : 1;
631     bool m_inDocument : 1;
632     bool m_isLink : 1;
633     bool m_active : 1;
634     bool m_hovered : 1;
635     bool m_inActiveChain : 1;
636     bool m_inDetach : 1;
637     bool m_hasRareData : 1;
638     const bool m_isElement : 1;
639     const bool m_isContainer : 1;
640     const bool m_isText : 1;
641 
642 protected:
643     // These bits are used by derived classes, pulled up here so they can
644     // be stored in the same memory word as the Node bits above.
645 
646     bool m_parsingChildrenFinished : 1; // Element
647     mutable bool m_isStyleAttributeValid : 1; // StyledElement
648     mutable bool m_synchronizingStyleAttribute : 1; // StyledElement
649 
650 #if ENABLE(SVG)
651     mutable bool m_areSVGAttributesValid : 1; // Element
652     mutable bool m_synchronizingSVGAttributes : 1; // SVGElement
653     bool m_hasRareSVGData : 1; // SVGElement
654 #endif
655 
656     // 10 bits remaining
657 };
658 
659 // Used in Node::addSubresourceAttributeURLs() and in addSubresourceStyleURLs()
addSubresourceURL(ListHashSet<KURL> & urls,const KURL & url)660 inline void addSubresourceURL(ListHashSet<KURL>& urls, const KURL& url)
661 {
662     if (!url.isNull())
663         urls.add(url);
664 }
665 
666 } //namespace
667 
668 #ifndef NDEBUG
669 // Outside the WebCore namespace for ease of invocation from gdb.
670 void showTree(const WebCore::Node*);
671 #endif
672 
673 #endif
674