|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef FrameChildList_h_ |
|
8 #define FrameChildList_h_ |
|
9 |
|
10 #include "nsFrameList.h" |
|
11 #include "nsTArray.h" |
|
12 |
|
13 class nsIFrame; |
|
14 |
|
15 namespace mozilla { |
|
16 namespace layout { |
|
17 |
|
18 // enum FrameChildListID lives in nsFrameList.h to solve circular dependencies. |
|
19 |
|
20 #ifdef DEBUG_FRAME_DUMP |
|
21 extern const char* ChildListName(FrameChildListID aListID); |
|
22 #endif |
|
23 |
|
24 class FrameChildListIDs { |
|
25 friend class FrameChildListIterator; |
|
26 public: |
|
27 FrameChildListIDs() : mIDs(0) {} |
|
28 FrameChildListIDs(const FrameChildListIDs& aOther) : mIDs(aOther.mIDs) {} |
|
29 FrameChildListIDs(FrameChildListID aListID) : mIDs(aListID) {} |
|
30 |
|
31 FrameChildListIDs operator|(FrameChildListIDs aOther) const { |
|
32 return FrameChildListIDs(mIDs | aOther.mIDs); |
|
33 } |
|
34 FrameChildListIDs& operator|=(FrameChildListIDs aOther) { |
|
35 mIDs |= aOther.mIDs; |
|
36 return *this; |
|
37 } |
|
38 bool operator==(FrameChildListIDs aOther) const { |
|
39 return mIDs == aOther.mIDs; |
|
40 } |
|
41 bool operator!=(FrameChildListIDs aOther) const { |
|
42 return !(*this == aOther); |
|
43 } |
|
44 bool Contains(FrameChildListIDs aOther) const { |
|
45 return (mIDs & aOther.mIDs) == aOther.mIDs; |
|
46 } |
|
47 |
|
48 protected: |
|
49 FrameChildListIDs(uint32_t aIDs) : mIDs(aIDs) {} |
|
50 uint32_t mIDs; |
|
51 }; |
|
52 |
|
53 class FrameChildList { |
|
54 public: |
|
55 FrameChildList(const nsFrameList& aList, FrameChildListID aID) |
|
56 : mList(aList), mID(aID) {} |
|
57 nsFrameList mList; |
|
58 FrameChildListID mID; |
|
59 }; |
|
60 |
|
61 /** |
|
62 * A class to iterate frame child lists. |
|
63 */ |
|
64 class MOZ_STACK_CLASS FrameChildListArrayIterator { |
|
65 public: |
|
66 FrameChildListArrayIterator(const nsTArray<FrameChildList>& aLists) |
|
67 : mLists(aLists), mCurrentIndex(0) {} |
|
68 bool IsDone() const { return mCurrentIndex >= mLists.Length(); } |
|
69 FrameChildListID CurrentID() const { |
|
70 NS_ASSERTION(!IsDone(), "CurrentID(): iterator at end"); |
|
71 return mLists[mCurrentIndex].mID; |
|
72 } |
|
73 const nsFrameList& CurrentList() const { |
|
74 NS_ASSERTION(!IsDone(), "CurrentList(): iterator at end"); |
|
75 return mLists[mCurrentIndex].mList; |
|
76 } |
|
77 void Next() { |
|
78 NS_ASSERTION(!IsDone(), "Next(): iterator at end"); |
|
79 ++mCurrentIndex; |
|
80 } |
|
81 |
|
82 protected: |
|
83 const nsTArray<FrameChildList>& mLists; |
|
84 uint32_t mCurrentIndex; |
|
85 }; |
|
86 |
|
87 /** |
|
88 * A class for retrieving a frame's child lists and iterate them. |
|
89 */ |
|
90 class MOZ_STACK_CLASS FrameChildListIterator |
|
91 : public FrameChildListArrayIterator { |
|
92 public: |
|
93 FrameChildListIterator(const nsIFrame* aFrame); |
|
94 |
|
95 protected: |
|
96 nsAutoTArray<FrameChildList,4> mLists; |
|
97 }; |
|
98 |
|
99 inline mozilla::layout::FrameChildListIDs |
|
100 operator|(mozilla::layout::FrameChildListID aLeftOp, |
|
101 mozilla::layout::FrameChildListID aRightOp) |
|
102 { |
|
103 return mozilla::layout::FrameChildListIDs(aLeftOp) | |
|
104 mozilla::layout::FrameChildListIDs(aRightOp); |
|
105 } |
|
106 |
|
107 inline mozilla::layout::FrameChildListIDs |
|
108 operator|(mozilla::layout::FrameChildListID aLeftOp, |
|
109 mozilla::layout::FrameChildListIDs aRightOp) |
|
110 { |
|
111 return mozilla::layout::FrameChildListIDs(aLeftOp) | aRightOp; |
|
112 } |
|
113 |
|
114 } // namespace layout |
|
115 } // namespace mozilla |
|
116 |
|
117 inline void nsFrameList::AppendIfNonempty( |
|
118 nsTArray<mozilla::layout::FrameChildList>* aLists, |
|
119 mozilla::layout::FrameChildListID aListID) const |
|
120 { |
|
121 if (NotEmpty()) { |
|
122 aLists->AppendElement(mozilla::layout::FrameChildList(*this, aListID)); |
|
123 } |
|
124 } |
|
125 |
|
126 #endif /* !defined(FrameChildList_h_) */ |