Merge "[CherryPick] Refactoring: Move the content of HTMLInputElement::subtreeHasChan...
[framework/web/webkit-efl.git] / Source / WebCore / page / FrameTree.h
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef FrameTree_h
21 #define FrameTree_h
22
23 #include <wtf/NotFound.h>
24 #include <wtf/text/AtomicString.h>
25
26 namespace WebCore {
27
28     class Frame;
29     class TreeScope;
30
31     class FrameTree {
32         WTF_MAKE_NONCOPYABLE(FrameTree);
33     public:
34         const static unsigned invalidCount = static_cast<unsigned>(WTF::notFound);
35
36         FrameTree(Frame* thisFrame, Frame* parentFrame) 
37             : m_thisFrame(thisFrame)
38             , m_parent(parentFrame)
39             , m_previousSibling(0)
40             , m_lastChild(0)
41             , m_scopedChildCount(invalidCount)
42         {
43         }
44
45         ~FrameTree();
46
47         const AtomicString& name() const { return m_name; }
48         const AtomicString& uniqueName() const { return m_uniqueName; }
49         void setName(const AtomicString&);
50         void clearName();
51         Frame* parent() const;
52         void setParent(Frame* parent) { m_parent = parent; }
53         
54         Frame* nextSibling() const { return m_nextSibling.get(); }
55         Frame* previousSibling() const { return m_previousSibling; }
56         Frame* firstChild() const { return m_firstChild.get(); }
57         Frame* lastChild() const { return m_lastChild; }
58
59         bool isDescendantOf(const Frame* ancestor) const;
60         Frame* traverseNext(const Frame* stayWithin = 0) const;
61         Frame* traverseNextWithWrap(bool) const;
62         Frame* traversePreviousWithWrap(bool) const;
63         
64         void appendChild(PassRefPtr<Frame>);
65         bool transferChild(PassRefPtr<Frame>);
66         void detachFromParent() { m_parent = 0; }
67         void removeChild(Frame*);
68
69         Frame* child(unsigned index) const;
70         Frame* child(const AtomicString& name) const;
71         Frame* find(const AtomicString& name) const;
72         unsigned childCount() const;
73
74         AtomicString uniqueChildName(const AtomicString& requestedName) const;
75
76         Frame* top() const;
77
78         Frame* scopedChild(unsigned index) const;
79         Frame* scopedChild(const AtomicString& name) const;
80         unsigned scopedChildCount() const;
81
82     private:
83         Frame* deepLastChild() const;
84         void actuallyAppendChild(PassRefPtr<Frame>);
85
86         bool scopedBy(TreeScope*) const;
87         Frame* scopedChild(unsigned index, TreeScope*) const;
88         Frame* scopedChild(const AtomicString& name, TreeScope*) const;
89         unsigned scopedChildCount(TreeScope*) const;
90
91         Frame* m_thisFrame;
92
93         Frame* m_parent;
94         AtomicString m_name; // The actual frame name (may be empty).
95         AtomicString m_uniqueName;
96
97         // FIXME: use ListRefPtr?
98         RefPtr<Frame> m_nextSibling;
99         Frame* m_previousSibling;
100         RefPtr<Frame> m_firstChild;
101         Frame* m_lastChild;
102         mutable unsigned m_scopedChildCount;
103     };
104
105 } // namespace WebCore
106
107 #ifndef NDEBUG
108 // Outside the WebCore namespace for ease of invocation from gdb.
109 void showFrameTree(const WebCore::Frame*);
110 #endif
111
112 #endif // FrameTree_h