1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* base class for nsCounterList and nsQuoteList */
8 #ifndef nsGenConList_h___
9 #define nsGenConList_h___
12 #include "nsStyleStruct.h"
14 #include "nsCSSPseudoElements.h"
15 #include "nsTextNode.h"
19 struct nsGenConNode
: public PRCList
{
20 // The wrapper frame for all of the pseudo-element's content. This
21 // frame generally has useful style data and has the
22 // NS_FRAME_GENERATED_CONTENT bit set (so we use it to track removal),
23 // but does not necessarily for |nsCounterChangeNode|s.
24 nsIFrame
* mPseudoFrame
;
26 // Index within the list of things specified by the 'content' property,
27 // which is needed to do 'content: open-quote open-quote' correctly,
28 // and needed for similar cases for counters.
29 const int32_t mContentIndex
;
31 // null for 'content:no-open-quote', 'content:no-close-quote' and for
32 // counter nodes for increments and resets (rather than uses)
33 nsRefPtr
<nsTextNode
> mText
;
35 explicit nsGenConNode(int32_t aContentIndex
)
36 : mPseudoFrame(nullptr)
37 , mContentIndex(aContentIndex
)
42 * Finish initializing the generated content node once we know the
43 * relevant text frame. This must be called just after
44 * the textframe has been initialized. This need not be called at all
45 * for nodes that don't generate text. This will generally set the
46 * mPseudoFrame, insert the node into aList, and set aTextFrame up
47 * with the correct text.
48 * @param aList the list the node belongs to
49 * @param aPseudoFrame the :before or :after frame
50 * @param aTextFrame the textframe where the node contents will render
51 * @return true iff this marked the list dirty
53 virtual bool InitTextFrame(nsGenConList
* aList
, nsIFrame
* aPseudoFrame
,
56 mPseudoFrame
= aPseudoFrame
;
57 CheckFrameAssertions();
61 virtual ~nsGenConNode() {} // XXX Avoid, perhaps?
64 void CheckFrameAssertions() {
65 NS_ASSERTION(mContentIndex
<
66 int32_t(mPseudoFrame
->StyleContent()->ContentCount()),
67 "index out of range");
68 // We allow negative values of mContentIndex for 'counter-reset' and
69 // 'counter-increment'.
71 NS_ASSERTION(mContentIndex
< 0 ||
72 mPseudoFrame
->StyleContext()->GetPseudo() ==
73 nsCSSPseudoElements::before
||
74 mPseudoFrame
->StyleContext()->GetPseudo() ==
75 nsCSSPseudoElements::after
,
76 "not :before/:after generated content and not counter change");
77 NS_ASSERTION(mContentIndex
< 0 ||
78 mPseudoFrame
->GetStateBits() & NS_FRAME_GENERATED_CONTENT
,
79 "not generated content and not counter change");
85 nsGenConNode
* mFirstNode
;
88 nsGenConList() : mFirstNode(nullptr), mSize(0) {}
89 ~nsGenConList() { Clear(); }
91 static nsGenConNode
* Next(nsGenConNode
* aNode
) {
92 return static_cast<nsGenConNode
*>(PR_NEXT_LINK(aNode
));
94 static nsGenConNode
* Prev(nsGenConNode
* aNode
) {
95 return static_cast<nsGenConNode
*>(PR_PREV_LINK(aNode
));
97 void Insert(nsGenConNode
* aNode
);
98 // returns whether any nodes have been destroyed
99 bool DestroyNodesFor(nsIFrame
* aFrame
); //destroy all nodes with aFrame as parent
101 // Return true if |aNode1| is after |aNode2|.
102 static bool NodeAfter(const nsGenConNode
* aNode1
,
103 const nsGenConNode
* aNode2
);
105 void Remove(nsGenConNode
* aNode
) { PR_REMOVE_LINK(aNode
); mSize
--; }
106 bool IsLast(nsGenConNode
* aNode
) { return (Next(aNode
) == mFirstNode
); }
109 #endif /* nsGenConList_h___ */