1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
7 /* implementation of quotes for the CSS 'content' property */
9 #ifndef nsQuoteList_h___
10 #define nsQuoteList_h___
12 #include "mozilla/Attributes.h"
13 #include "nsGenConList.h"
17 class ContainStyleScope
;
19 } // namespace mozilla
21 struct nsQuoteNode
: public nsGenConNode
{
22 // open-quote, close-quote, no-open-quote, or no-close-quote
23 const StyleContentType mType
;
25 // Quote depth before this quote, which is always non-negative.
28 nsQuoteNode(StyleContentType aType
, uint32_t aContentIndex
)
29 : nsGenConNode(aContentIndex
), mType(aType
), mDepthBefore(0) {
30 NS_ASSERTION(aType
== StyleContentType::OpenQuote
||
31 aType
== StyleContentType::CloseQuote
||
32 aType
== StyleContentType::NoOpenQuote
||
33 aType
== StyleContentType::NoCloseQuote
,
35 NS_ASSERTION(aContentIndex
<= INT32_MAX
, "out of range");
38 virtual bool InitTextFrame(nsGenConList
* aList
, nsIFrame
* aPseudoFrame
,
39 nsIFrame
* aTextFrame
) override
;
41 // is this 'open-quote' or 'no-open-quote'?
43 return mType
== StyleContentType::OpenQuote
||
44 mType
== StyleContentType::NoOpenQuote
;
47 // is this 'close-quote' or 'no-close-quote'?
48 bool IsCloseQuote() { return !IsOpenQuote(); }
50 // is this 'open-quote' or 'close-quote'?
52 return mType
== StyleContentType::OpenQuote
||
53 mType
== StyleContentType::CloseQuote
;
56 // Depth of the quote for *this* node. Either non-negative or -1.
57 // -1 means this is a closing quote that tried to decrement the
58 // counter below zero (which means no quote should be rendered).
59 int32_t Depth() { return IsOpenQuote() ? mDepthBefore
: mDepthBefore
- 1; }
61 // always non-negative
62 int32_t DepthAfter() {
63 return IsOpenQuote() ? mDepthBefore
+ 1
64 : (mDepthBefore
== 0 ? 0 : mDepthBefore
- 1);
67 // The text that should be displayed for this quote.
71 class nsQuoteList
: public nsGenConList
{
73 nsQuoteNode
* FirstNode() {
74 return static_cast<nsQuoteNode
*>(mList
.getFirst());
78 explicit nsQuoteList(mozilla::ContainStyleScope
* aScope
) : mScope(aScope
) {}
80 // assign the correct |mDepthBefore| value to a node that has been inserted
81 // Should be called immediately after calling |Insert|.
82 void Calc(nsQuoteNode
* aNode
);
84 nsQuoteNode
* Next(nsQuoteNode
* aNode
) {
85 return static_cast<nsQuoteNode
*>(nsGenConList::Next(aNode
));
87 nsQuoteNode
* Prev(nsQuoteNode
* aNode
) {
88 return static_cast<nsQuoteNode
*>(nsGenConList::Prev(aNode
));
97 mozilla::ContainStyleScope
* mScope
;
100 #endif /* nsQuoteList_h___ */