Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / layout / base / nsGenConList.h
blob52c779f9b1dad65b763184488299c89ddb61796f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Esben Mose Hansen.
20 * Contributor(s):
21 * Esben Mose Hansen <esben@oek.dk> (original author)
22 * L. David Baron <dbaron@dbaron.org>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* base class for nsCounterList and nsQuoteList */
40 #ifndef nsGenConList_h___
41 #define nsGenConList_h___
43 #include "nsIFrame.h"
44 #include "nsStyleStruct.h"
45 #include "prclist.h"
46 #include "nsIDOMCharacterData.h"
47 #include "nsCSSPseudoElements.h"
49 class nsGenConList;
51 struct nsGenConNode : public PRCList {
52 // The wrapper frame for all of the pseudo-element's content. This
53 // frame generally has useful style data and has the
54 // NS_FRAME_GENERATED_CONTENT bit set (so we use it to track removal),
55 // but does not necessarily for |nsCounterChangeNode|s.
56 nsIFrame* mPseudoFrame;
58 // Index within the list of things specified by the 'content' property,
59 // which is needed to do 'content: open-quote open-quote' correctly,
60 // and needed for similar cases for counters.
61 const PRInt32 mContentIndex;
63 // null for 'content:no-open-quote', 'content:no-close-quote' and for
64 // counter nodes for increments and resets (rather than uses)
65 nsCOMPtr<nsIDOMCharacterData> mText;
67 nsGenConNode(PRInt32 aContentIndex)
68 : mPseudoFrame(nsnull)
69 , mContentIndex(aContentIndex)
73 /**
74 * Finish initializing the generated content node once we know the
75 * relevant text frame. This must be called just after
76 * the textframe has been initialized. This need not be called at all
77 * for nodes that don't generate text. This will generally set the
78 * mPseudoFrame, insert the node into aList, and set aTextFrame up
79 * with the correct text.
80 * @param aList the list the node belongs to
81 * @param aPseudoFrame the :before or :after frame
82 * @param aTextFrame the textframe where the node contents will render
83 * @return true iff this marked the list dirty
85 virtual PRBool InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame,
86 nsIFrame* aTextFrame)
88 mPseudoFrame = aPseudoFrame;
89 CheckFrameAssertions();
90 return PR_FALSE;
93 virtual ~nsGenConNode() {} // XXX Avoid, perhaps?
95 protected:
96 void CheckFrameAssertions() {
97 NS_ASSERTION(mContentIndex <
98 PRInt32(mPseudoFrame->GetStyleContent()->ContentCount()),
99 "index out of range");
100 // We allow negative values of mContentIndex for 'counter-reset' and
101 // 'counter-increment'.
103 NS_ASSERTION(mContentIndex < 0 ||
104 mPseudoFrame->GetStyleContext()->GetPseudo() ==
105 nsCSSPseudoElements::before ||
106 mPseudoFrame->GetStyleContext()->GetPseudo() ==
107 nsCSSPseudoElements::after,
108 "not :before/:after generated content and not counter change");
109 NS_ASSERTION(mContentIndex < 0 ||
110 mPseudoFrame->GetStateBits() & NS_FRAME_GENERATED_CONTENT,
111 "not generated content and not counter change");
115 class nsGenConList {
116 protected:
117 nsGenConNode* mFirstNode;
118 PRUint32 mSize;
119 public:
120 nsGenConList() : mFirstNode(nsnull), mSize(0) {}
121 ~nsGenConList() { Clear(); }
122 void Clear();
123 static nsGenConNode* Next(nsGenConNode* aNode) {
124 return static_cast<nsGenConNode*>(PR_NEXT_LINK(aNode));
126 static nsGenConNode* Prev(nsGenConNode* aNode) {
127 return static_cast<nsGenConNode*>(PR_PREV_LINK(aNode));
129 void Insert(nsGenConNode* aNode);
130 // returns whether any nodes have been destroyed
131 PRBool DestroyNodesFor(nsIFrame* aFrame); //destroy all nodes with aFrame as parent
133 // Return true if |aNode1| is after |aNode2|.
134 static PRBool NodeAfter(const nsGenConNode* aNode1,
135 const nsGenConNode* aNode2);
137 void Remove(nsGenConNode* aNode) { PR_REMOVE_LINK(aNode); mSize--; }
138 PRBool IsLast(nsGenConNode* aNode) { return (Next(aNode) == mFirstNode); }
141 #endif /* nsGenConList_h___ */