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/text/AtomicString.h" 24 25 namespace WebCore { 26 27 class Frame; 28 class TreeScope; 29 30 class FrameTree { 31 WTF_MAKE_NONCOPYABLE(FrameTree); 32 public: 33 const static unsigned invalidCount = static_cast<unsigned>(-1); 34 35 FrameTree(Frame* thisFrame, Frame* parentFrame) 36 : m_thisFrame(thisFrame) 37 , m_parent(parentFrame) 38 , m_previousSibling(0) 39 , m_lastChild(0) 40 , m_scopedChildCount(invalidCount) 41 { 42 } 43 44 ~FrameTree(); 45 46 const AtomicString& name() const { return m_name; } 47 const AtomicString& uniqueName() const { return m_uniqueName; } 48 void setName(const AtomicString&); 49 void clearName(); 50 Frame* parent() const; 51 void setParent(Frame* parent) { m_parent = parent; } 52 53 Frame* nextSibling() const { return m_nextSibling.get(); } 54 Frame* previousSibling() const { return m_previousSibling; } 55 Frame* firstChild() const { return m_firstChild.get(); } 56 Frame* lastChild() const { return m_lastChild; } 57 58 bool isDescendantOf(const Frame* ancestor) const; 59 Frame* traverseNext(const Frame* stayWithin = 0) const; 60 Frame* traverseNextWithWrap(bool) const; 61 Frame* traversePreviousWithWrap(bool) const; 62 63 void appendChild(PassRefPtr<Frame>); 64 bool transferChild(PassRefPtr<Frame>); 65 void detachFromParent() { m_parent = 0; } 66 void removeChild(Frame*); 67 68 Frame* child(unsigned index) const; 69 Frame* child(const AtomicString& name) const; 70 Frame* find(const AtomicString& name) const; 71 unsigned childCount() const; 72 73 AtomicString uniqueChildName(const AtomicString& requestedName) const; 74 75 Frame* top() const; 76 77 Frame* scopedChild(unsigned index) const; 78 Frame* scopedChild(const AtomicString& name) const; 79 unsigned scopedChildCount() const; 80 81 private: 82 Frame* deepLastChild() const; 83 void actuallyAppendChild(PassRefPtr<Frame>); 84 85 bool scopedBy(TreeScope*) const; 86 Frame* scopedChild(unsigned index, TreeScope*) const; 87 Frame* scopedChild(const AtomicString& name, TreeScope*) const; 88 unsigned scopedChildCount(TreeScope*) const; 89 90 Frame* m_thisFrame; 91 92 Frame* m_parent; 93 AtomicString m_name; // The actual frame name (may be empty). 94 AtomicString m_uniqueName; 95 96 // FIXME: use ListRefPtr? 97 RefPtr<Frame> m_nextSibling; 98 Frame* m_previousSibling; 99 RefPtr<Frame> m_firstChild; 100 Frame* m_lastChild; 101 mutable unsigned m_scopedChildCount; 102 }; 103 104 } // namespace WebCore 105 106 #ifndef NDEBUG 107 // Outside the WebCore namespace for ease of invocation from gdb. 108 void showFrameTree(const WebCore::Frame*); 109 #endif 110 111 #endif // FrameTree_h 112