root/trunk/WebCore/dom/Node.h

Revision 51162, 26.4 KB (checked in by mjs@apple.com, 3 days ago)

2009-11-18 Maciej Stachowiak < mjs@apple.com>

Reviewed by Oliver Hunt.

Fix REGRESSION (r47022): Performance of DocumentFragment.appendChild is 1000x slower sometimes
 https://bugs.webkit.org/show_bug.cgi?id=31237


Also speeds up Dromaeo DOM Core tests by 1.31x.

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