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