18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *           (C) 1999 Antti Koivisto (koivisto@kde.org)
48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *           (C) 2001 Dirk Mueller (mueller@kde.org)
5a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserved.
68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is free software; you can redistribute it and/or
88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modify it under the terms of the GNU Library General Public
98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * License as published by the Free Software Foundation; either
108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * version 2 of the License, or (at your option) any later version.
118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is distributed in the hope that it will be useful,
138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * but WITHOUT ANY WARRANTY; without even the implied warranty of
148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Library General Public License for more details.
168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * You should have received a copy of the GNU Library General Public License
188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * along with this library; see the file COPYING.LIB.  If not, write to
198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Boston, MA 02110-1301, USA.
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef ContainerNode_h
258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#define ContainerNode_h
268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
278f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include "Node.h"
288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
30a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
31a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass FloatPoint;
328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projecttypedef void (*NodeCallback)(Node*);
348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace Private {
368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    template<class GenericNode, class GenericNodeContainer>
378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project};
398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
408f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianclass ContainerNode : public Node {
418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic:
428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual ~ContainerNode();
438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Node* firstChild() const { return m_firstChild; }
458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Node* lastChild() const { return m_lastChild; }
468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
47a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false);
48a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false);
49a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    bool removeChild(Node* child, ExceptionCode&);
50a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false);
518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
52e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    // These methods are only used during parsing.
53e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    // They don't send DOM mutation events or handle reparenting.
54e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    // However, arbitrary code may be run by beforeload handlers.
55e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    void parserAddChild(PassRefPtr<Node>);
56e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    void parserRemoveChild(Node*);
57e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    void parserInsertBefore(PassRefPtr<Node> newChild, Node* refChild);
58ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool hasChildNodes() const { return m_firstChild; }
608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void attach();
618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void detach();
628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void willRemove();
638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual IntRect getRect() const;
648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void setFocus(bool = true);
658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void setActive(bool active = true, bool pause = false);
668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void setHovered(bool = true);
678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    unsigned childNodeCount() const;
688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Node* childNode(unsigned index) const;
698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void insertedIntoDocument();
718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void removedFromDocument();
728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void insertedIntoTree(bool deep);
738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void removedFromTree(bool deep);
748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
76a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // FIXME: It's not good to have two functions with such similar names, especially public functions.
77a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // How do removeChildren and removeAllChildren differ?
78a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    void removeChildren();
798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void removeAllChildren();
805ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen    void takeAllChildrenFrom(ContainerNode*);
818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void cloneChildNodes(ContainerNode* clone);
83231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
84231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    bool dispatchBeforeLoadEvent(const String& sourceURL);
858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
86e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    static void queuePostAttachCallback(NodeCallback, Node*);
87e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    static bool postAttachCallbacksAreSuspended();
88e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprotected:
90231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    ContainerNode(Document*, ConstructionType = CreateContainer);
91231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
928f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    void suspendPostAttachCallbacks();
938f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    void resumePostAttachCallbacks();
948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    template<class GenericNode, class GenericNodeContainer>
968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    friend void appendChildToContainer(GenericNode* child, GenericNodeContainer* container);
978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    template<class GenericNode, class GenericNodeContainer>
998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void setFirstChild(Node* child) { m_firstChild = child; }
1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void setLastChild(Node* child) { m_lastChild = child; }
103ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprivate:
105e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    // Never call this function directly.  If you're trying to call this
106e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    // function, your code is either wrong or you're supposed to call
107e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    // parserAddChild.  Please do not call parserAddChild unless you are the
108e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    // parser!
109e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    virtual void deprecatedParserAddChild(PassRefPtr<Node>);
110e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
111e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    void removeBetween(Node* previousChild, Node* nextChild, Node* oldChild);
112e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    void insertBeforeCommon(Node* nextChild, Node* oldChild);
113ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    static void dispatchPostAttachCallbacks();
115ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
116635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    bool getUpperLeftCorner(FloatPoint&) const;
117635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    bool getLowerRightCorner(FloatPoint&) const;
1188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Node* m_firstChild;
1208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Node* m_lastChild;
1218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project};
1228f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
123a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochinline ContainerNode* toContainerNode(Node* node)
124a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{
125a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    ASSERT(!node || node->isContainerNode());
126a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return static_cast<ContainerNode*>(node);
127a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch}
128a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
129a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochinline const ContainerNode* toContainerNode(const Node* node)
130a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{
131a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    ASSERT(!node || node->isContainerNode());
132a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return static_cast<const ContainerNode*>(node);
133a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch}
134a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
135a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch// This will catch anyone doing an unnecessary cast.
136a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvoid toContainerNode(const ContainerNode*);
137a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
138231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockinline ContainerNode::ContainerNode(Document* document, ConstructionType type)
139231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    : Node(document, type)
1408f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    , m_firstChild(0)
1418f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    , m_lastChild(0)
1428f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian{
1438f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian}
1448f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
145a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochinline unsigned Node::childNodeCount() const
1468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
147a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    if (!isContainerNode())
148a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        return 0;
149a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return toContainerNode(this)->childNodeCount();
1508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
152a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochinline Node* Node::childNode(unsigned index) const
1538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
154a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    if (!isContainerNode())
155a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        return 0;
156a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return toContainerNode(this)->childNode(index);
1578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
159a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochinline Node* Node::firstChild() const
1608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
161a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    if (!isContainerNode())
162a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        return 0;
163a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return toContainerNode(this)->firstChild();
1648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
166a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochinline Node* Node::lastChild() const
1678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
168a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    if (!isContainerNode())
169a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        return 0;
170a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return toContainerNode(this)->lastChild();
1718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore
1748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif // ContainerNode_h
176