1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2001 Dirk Mueller (mueller (at) kde.org) 5 * Copyright (C) 2004, 2005, 2006, 2007, 2009 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 virtual ~ContainerNode(); 42 43 Node* firstChild() const { return m_firstChild; } 44 Node* lastChild() const { return m_lastChild; } 45 46 virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false); 47 virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false); 48 virtual bool removeChild(Node* child, ExceptionCode&); 49 virtual bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false); 50 51 virtual ContainerNode* addChild(PassRefPtr<Node>); 52 bool hasChildNodes() const { return m_firstChild; } 53 virtual void attach(); 54 virtual void detach(); 55 virtual void willRemove(); 56 virtual IntRect getRect() const; 57 virtual void setFocus(bool = true); 58 virtual void setActive(bool active = true, bool pause = false); 59 virtual void setHovered(bool = true); 60 unsigned childNodeCount() const; 61 Node* childNode(unsigned index) const; 62 63 virtual void insertedIntoDocument(); 64 virtual void removedFromDocument(); 65 virtual void insertedIntoTree(bool deep); 66 virtual void removedFromTree(bool deep); 67 virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 68 69 virtual bool removeChildren(); 70 71 void removeAllChildren(); 72 73 void cloneChildNodes(ContainerNode* clone); 74 75 bool dispatchBeforeLoadEvent(const String& sourceURL); 76 77 protected: 78 ContainerNode(Document*, ConstructionType = CreateContainer); 79 80 static void queuePostAttachCallback(NodeCallback, Node*); 81 void suspendPostAttachCallbacks(); 82 void resumePostAttachCallbacks(); 83 84 template<class GenericNode, class GenericNodeContainer> 85 friend void appendChildToContainer(GenericNode* child, GenericNodeContainer* container); 86 87 template<class GenericNode, class GenericNodeContainer> 88 friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container); 89 90 void setFirstChild(Node* child) { m_firstChild = child; } 91 void setLastChild(Node* child) { m_lastChild = child; } 92 93 private: 94 static void dispatchPostAttachCallbacks(); 95 96 bool getUpperLeftCorner(FloatPoint&) const; 97 bool getLowerRightCorner(FloatPoint&) const; 98 99 Node* m_firstChild; 100 Node* m_lastChild; 101 }; 102 103 inline ContainerNode::ContainerNode(Document* document, ConstructionType type) 104 : Node(document, type) 105 , m_firstChild(0) 106 , m_lastChild(0) 107 { 108 } 109 110 inline unsigned Node::containerChildNodeCount() const 111 { 112 ASSERT(isContainerNode()); 113 return static_cast<const ContainerNode*>(this)->childNodeCount(); 114 } 115 116 inline Node* Node::containerChildNode(unsigned index) const 117 { 118 ASSERT(isContainerNode()); 119 return static_cast<const ContainerNode*>(this)->childNode(index); 120 } 121 122 inline Node* Node::containerFirstChild() const 123 { 124 ASSERT(isContainerNode()); 125 return static_cast<const ContainerNode*>(this)->firstChild(); 126 } 127 128 inline Node* Node::containerLastChild() const 129 { 130 ASSERT(isContainerNode()); 131 return static_cast<const ContainerNode*>(this)->lastChild(); 132 } 133 134 } // namespace WebCore 135 136 #endif // ContainerNode_h 137