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 Apple Inc. All rights reserved.
6 *
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.
11 *
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.
16 *
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.
21 *
22 */
23
24 #ifndef ContainerNode_h
25 #define ContainerNode_h
26
27 #include "Node.h"
28 #include "FloatPoint.h"
29
30 namespace WebCore {
31
32 typedef void (*NodeCallback)(Node*);
33
34 namespace Private {
35 template<class GenericNode, class GenericNodeContainer>
36 void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
37 };
38
39 class ContainerNode : public Node {
40 public:
41 ContainerNode(Document*, bool isElement = false);
42 virtual ~ContainerNode();
43
firstChild()44 Node* firstChild() const { return m_firstChild; }
lastChild()45 Node* lastChild() const { return m_lastChild; }
46
47 virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false);
48 virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false);
49 virtual bool removeChild(Node* child, ExceptionCode&);
50 virtual bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false);
51
52 virtual ContainerNode* addChild(PassRefPtr<Node>);
hasChildNodes()53 bool hasChildNodes() const { return m_firstChild; }
54 virtual void attach();
55 virtual void detach();
56 virtual void willRemove();
57 virtual IntRect getRect() const;
58 virtual void setFocus(bool = true);
59 virtual void setActive(bool active = true, bool pause = false);
60 virtual void setHovered(bool = true);
61 unsigned childNodeCount() const;
62 Node* childNode(unsigned index) const;
63
64 virtual void insertedIntoDocument();
65 virtual void removedFromDocument();
66 virtual void insertedIntoTree(bool deep);
67 virtual void removedFromTree(bool deep);
68 virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
69
70 virtual bool removeChildren();
71
72 void removeAllChildren();
73
74 void cloneChildNodes(ContainerNode* clone);
75
76 protected:
77 static void queuePostAttachCallback(NodeCallback, Node*);
78 void suspendPostAttachCallbacks();
79 void resumePostAttachCallbacks();
80
81 template<class GenericNode, class GenericNodeContainer>
82 friend void appendChildToContainer(GenericNode* child, GenericNodeContainer* container);
83
84 template<class GenericNode, class GenericNodeContainer>
85 friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
86
setFirstChild(Node * child)87 void setFirstChild(Node* child) { m_firstChild = child; }
setLastChild(Node * child)88 void setLastChild(Node* child) { m_lastChild = child; }
89
90 private:
91 static void dispatchPostAttachCallbacks();
92
93 bool getUpperLeftCorner(FloatPoint&) const;
94 bool getLowerRightCorner(FloatPoint&) const;
95
96 Node* m_firstChild;
97 Node* m_lastChild;
98 };
99
ContainerNode(Document * document,bool isElement)100 inline ContainerNode::ContainerNode(Document* document, bool isElement)
101 : Node(document, isElement, true)
102 , m_firstChild(0)
103 , m_lastChild(0)
104 {
105 }
106
containerChildNodeCount()107 inline unsigned Node::containerChildNodeCount() const
108 {
109 ASSERT(isContainerNode());
110 return static_cast<const ContainerNode*>(this)->childNodeCount();
111 }
112
containerChildNode(unsigned index)113 inline Node* Node::containerChildNode(unsigned index) const
114 {
115 ASSERT(isContainerNode());
116 return static_cast<const ContainerNode*>(this)->childNode(index);
117 }
118
containerFirstChild()119 inline Node* Node::containerFirstChild() const
120 {
121 ASSERT(isContainerNode());
122 return static_cast<const ContainerNode*>(this)->firstChild();
123 }
124
containerLastChild()125 inline Node* Node::containerLastChild() const
126 {
127 ASSERT(isContainerNode());
128 return static_cast<const ContainerNode*>(this)->lastChild();
129 }
130
131 } // namespace WebCore
132
133 #endif // ContainerNode_h
134