/src/3rdparty/webkit/Source/WebCore/dom/ContainerNode.h

https://bitbucket.org/ultra_iter/qt-vtl · C Header · 175 lines · 107 code · 36 blank · 32 comment · 6 complexity · f326387d9bf739cf978a178869fe2cb7 MD5 · raw file

  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, 2009, 2010 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. #ifndef ContainerNode_h
  24. #define ContainerNode_h
  25. #include "Node.h"
  26. namespace WebCore {
  27. class FloatPoint;
  28. typedef void (*NodeCallback)(Node*);
  29. namespace Private {
  30. template<class GenericNode, class GenericNodeContainer>
  31. void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
  32. };
  33. class ContainerNode : public Node {
  34. public:
  35. virtual ~ContainerNode();
  36. Node* firstChild() const { return m_firstChild; }
  37. Node* lastChild() const { return m_lastChild; }
  38. bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false);
  39. bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false);
  40. bool removeChild(Node* child, ExceptionCode&);
  41. bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false);
  42. // These methods are only used during parsing.
  43. // They don't send DOM mutation events or handle reparenting.
  44. // However, arbitrary code may be run by beforeload handlers.
  45. void parserAddChild(PassRefPtr<Node>);
  46. void parserRemoveChild(Node*);
  47. void parserInsertBefore(PassRefPtr<Node> newChild, Node* refChild);
  48. bool hasChildNodes() const { return m_firstChild; }
  49. virtual void attach();
  50. virtual void detach();
  51. virtual void willRemove();
  52. virtual IntRect getRect() const;
  53. virtual void setFocus(bool = true);
  54. virtual void setActive(bool active = true, bool pause = false);
  55. virtual void setHovered(bool = true);
  56. unsigned childNodeCount() const;
  57. Node* childNode(unsigned index) const;
  58. virtual void insertedIntoDocument();
  59. virtual void removedFromDocument();
  60. virtual void insertedIntoTree(bool deep);
  61. virtual void removedFromTree(bool deep);
  62. virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
  63. // FIXME: It's not good to have two functions with such similar names, especially public functions.
  64. // How do removeChildren and removeAllChildren differ?
  65. void removeChildren();
  66. void removeAllChildren();
  67. void takeAllChildrenFrom(ContainerNode*);
  68. void cloneChildNodes(ContainerNode* clone);
  69. bool dispatchBeforeLoadEvent(const String& sourceURL);
  70. static void queuePostAttachCallback(NodeCallback, Node*);
  71. static bool postAttachCallbacksAreSuspended();
  72. protected:
  73. ContainerNode(Document*, ConstructionType = CreateContainer);
  74. void suspendPostAttachCallbacks();
  75. void resumePostAttachCallbacks();
  76. template<class GenericNode, class GenericNodeContainer>
  77. friend void appendChildToContainer(GenericNode* child, GenericNodeContainer* container);
  78. template<class GenericNode, class GenericNodeContainer>
  79. friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
  80. void setFirstChild(Node* child) { m_firstChild = child; }
  81. void setLastChild(Node* child) { m_lastChild = child; }
  82. private:
  83. // Never call this function directly. If you're trying to call this
  84. // function, your code is either wrong or you're supposed to call
  85. // parserAddChild. Please do not call parserAddChild unless you are the
  86. // parser!
  87. virtual void deprecatedParserAddChild(PassRefPtr<Node>);
  88. void removeBetween(Node* previousChild, Node* nextChild, Node* oldChild);
  89. void insertBeforeCommon(Node* nextChild, Node* oldChild);
  90. static void dispatchPostAttachCallbacks();
  91. bool getUpperLeftCorner(FloatPoint&) const;
  92. bool getLowerRightCorner(FloatPoint&) const;
  93. Node* m_firstChild;
  94. Node* m_lastChild;
  95. };
  96. inline ContainerNode* toContainerNode(Node* node)
  97. {
  98. ASSERT(!node || node->isContainerNode());
  99. return static_cast<ContainerNode*>(node);
  100. }
  101. inline const ContainerNode* toContainerNode(const Node* node)
  102. {
  103. ASSERT(!node || node->isContainerNode());
  104. return static_cast<const ContainerNode*>(node);
  105. }
  106. // This will catch anyone doing an unnecessary cast.
  107. void toContainerNode(const ContainerNode*);
  108. inline ContainerNode::ContainerNode(Document* document, ConstructionType type)
  109. : Node(document, type)
  110. , m_firstChild(0)
  111. , m_lastChild(0)
  112. {
  113. }
  114. inline unsigned Node::childNodeCount() const
  115. {
  116. if (!isContainerNode())
  117. return 0;
  118. return toContainerNode(this)->childNodeCount();
  119. }
  120. inline Node* Node::childNode(unsigned index) const
  121. {
  122. if (!isContainerNode())
  123. return 0;
  124. return toContainerNode(this)->childNode(index);
  125. }
  126. inline Node* Node::firstChild() const
  127. {
  128. if (!isContainerNode())
  129. return 0;
  130. return toContainerNode(this)->firstChild();
  131. }
  132. inline Node* Node::lastChild() const
  133. {
  134. if (!isContainerNode())
  135. return 0;
  136. return toContainerNode(this)->lastChild();
  137. }
  138. } // namespace WebCore
  139. #endif // ContainerNode_h