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, 2009, 2010 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef ContainerNode_h
25 #define ContainerNode_h
33 typedef void (*NodeCallback)(Node*, unsigned);
36 template<class GenericNode, class GenericNodeContainer>
37 void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
40 class ContainerNode : public Node {
42 virtual ~ContainerNode();
44 Node* firstChild() const { return m_firstChild; }
45 Node* lastChild() const { return m_lastChild; }
47 bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false);
48 bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false);
49 bool removeChild(Node* child, ExceptionCode&);
50 bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false);
52 // These methods are only used during parsing.
53 // They don't send DOM mutation events or handle reparenting.
54 // However, arbitrary code may be run by beforeload handlers.
55 void parserAddChild(PassRefPtr<Node>);
56 void parserRemoveChild(Node*);
57 void parserInsertBefore(PassRefPtr<Node> newChild, Node* refChild);
59 bool hasChildNodes() const { return m_firstChild; }
60 virtual void attach();
61 virtual void detach();
62 virtual void willRemove();
63 virtual LayoutRect getRect() const;
64 virtual void setFocus(bool = true);
65 virtual void setActive(bool active = true, bool pause = false);
66 virtual void setHovered(bool = true);
67 unsigned childNodeCount() const;
68 Node* childNode(unsigned index) const;
70 virtual void insertedIntoDocument();
71 virtual void removedFromDocument();
72 virtual void insertedIntoTree(bool deep);
73 virtual void removedFromTree(bool deep);
74 virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
76 // FIXME: It's not good to have two functions with such similar names, especially public functions.
77 // How do removeChildren and removeAllChildren differ?
78 void removeChildren();
79 void removeAllChildren();
80 void takeAllChildrenFrom(ContainerNode*);
82 void cloneChildNodes(ContainerNode* clone);
84 bool dispatchBeforeLoadEvent(const String& sourceURL);
86 virtual void scheduleSetNeedsStyleRecalc(StyleChangeType = FullStyleChange);
88 static void queuePostAttachCallback(NodeCallback, Node*, unsigned = 0);
89 static bool postAttachCallbacksAreSuspended();
92 ContainerNode(Document*, ConstructionType = CreateContainer);
94 void suspendPostAttachCallbacks();
95 void resumePostAttachCallbacks();
97 template<class GenericNode, class GenericNodeContainer>
98 friend void appendChildToContainer(GenericNode* child, GenericNodeContainer* container);
100 template<class GenericNode, class GenericNodeContainer>
101 friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
103 void setFirstChild(Node* child) { m_firstChild = child; }
104 void setLastChild(Node* child) { m_lastChild = child; }
107 void removeBetween(Node* previousChild, Node* nextChild, Node* oldChild);
108 void insertBeforeCommon(Node* nextChild, Node* oldChild);
110 static void dispatchPostAttachCallbacks();
112 bool getUpperLeftCorner(FloatPoint&) const;
113 bool getLowerRightCorner(FloatPoint&) const;
119 inline ContainerNode* toContainerNode(Node* node)
121 ASSERT(!node || node->isContainerNode());
122 return static_cast<ContainerNode*>(node);
125 inline const ContainerNode* toContainerNode(const Node* node)
127 ASSERT(!node || node->isContainerNode());
128 return static_cast<const ContainerNode*>(node);
131 // This will catch anyone doing an unnecessary cast.
132 void toContainerNode(const ContainerNode*);
134 inline ContainerNode::ContainerNode(Document* document, ConstructionType type)
135 : Node(document, type)
141 inline unsigned Node::childNodeCount() const
143 if (!isContainerNode())
145 return toContainerNode(this)->childNodeCount();
148 inline Node* Node::childNode(unsigned index) const
150 if (!isContainerNode())
152 return toContainerNode(this)->childNode(index);
155 inline Node* Node::firstChild() const
157 if (!isContainerNode())
159 return toContainerNode(this)->firstChild();
162 inline Node* Node::lastChild() const
164 if (!isContainerNode())
166 return toContainerNode(this)->lastChild();
169 } // namespace WebCore
171 #endif // ContainerNode_h