|
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/. */ |
|
5 |
|
6 /* implementation of quotes for the CSS 'content' property */ |
|
7 |
|
8 #ifndef nsQuoteList_h___ |
|
9 #define nsQuoteList_h___ |
|
10 |
|
11 #include "mozilla/Attributes.h" |
|
12 #include "nsGenConList.h" |
|
13 |
|
14 struct nsQuoteNode : public nsGenConNode { |
|
15 // open-quote, close-quote, no-open-quote, or no-close-quote |
|
16 const nsStyleContentType mType; |
|
17 |
|
18 // Quote depth before this quote, which is always non-negative. |
|
19 int32_t mDepthBefore; |
|
20 |
|
21 nsQuoteNode(nsStyleContentType& aType, uint32_t aContentIndex) |
|
22 : nsGenConNode(aContentIndex) |
|
23 , mType(aType) |
|
24 , mDepthBefore(0) |
|
25 { |
|
26 NS_ASSERTION(aType == eStyleContentType_OpenQuote || |
|
27 aType == eStyleContentType_CloseQuote || |
|
28 aType == eStyleContentType_NoOpenQuote || |
|
29 aType == eStyleContentType_NoCloseQuote, |
|
30 "incorrect type"); |
|
31 NS_ASSERTION(aContentIndex <= INT32_MAX, "out of range"); |
|
32 } |
|
33 |
|
34 virtual bool InitTextFrame(nsGenConList* aList, |
|
35 nsIFrame* aPseudoFrame, nsIFrame* aTextFrame) MOZ_OVERRIDE; |
|
36 |
|
37 // is this 'open-quote' or 'no-open-quote'? |
|
38 bool IsOpenQuote() { |
|
39 return mType == eStyleContentType_OpenQuote || |
|
40 mType == eStyleContentType_NoOpenQuote; |
|
41 } |
|
42 |
|
43 // is this 'close-quote' or 'no-close-quote'? |
|
44 bool IsCloseQuote() { |
|
45 return !IsOpenQuote(); |
|
46 } |
|
47 |
|
48 // is this 'open-quote' or 'close-quote'? |
|
49 bool IsRealQuote() { |
|
50 return mType == eStyleContentType_OpenQuote || |
|
51 mType == eStyleContentType_CloseQuote; |
|
52 } |
|
53 |
|
54 // Depth of the quote for *this* node. Either non-negative or -1. |
|
55 // -1 means this is a closing quote that tried to decrement the |
|
56 // counter below zero (which means no quote should be rendered). |
|
57 int32_t Depth() { |
|
58 return IsOpenQuote() ? mDepthBefore : mDepthBefore - 1; |
|
59 } |
|
60 |
|
61 // always non-negative |
|
62 int32_t DepthAfter() { |
|
63 return IsOpenQuote() ? mDepthBefore + 1 |
|
64 : (mDepthBefore == 0 ? 0 : mDepthBefore - 1); |
|
65 } |
|
66 |
|
67 // The text that should be displayed for this quote. |
|
68 const nsString* Text(); |
|
69 }; |
|
70 |
|
71 class nsQuoteList : public nsGenConList { |
|
72 private: |
|
73 nsQuoteNode* FirstNode() { return static_cast<nsQuoteNode*>(mFirstNode); } |
|
74 public: |
|
75 // assign the correct |mDepthBefore| value to a node that has been inserted |
|
76 // Should be called immediately after calling |Insert|. |
|
77 void Calc(nsQuoteNode* aNode); |
|
78 |
|
79 nsQuoteNode* Next(nsQuoteNode* aNode) { |
|
80 return static_cast<nsQuoteNode*>(nsGenConList::Next(aNode)); |
|
81 } |
|
82 nsQuoteNode* Prev(nsQuoteNode* aNode) { |
|
83 return static_cast<nsQuoteNode*>(nsGenConList::Prev(aNode)); |
|
84 } |
|
85 |
|
86 void RecalcAll(); |
|
87 #ifdef DEBUG |
|
88 void PrintChain(); |
|
89 #endif |
|
90 }; |
|
91 |
|
92 #endif /* nsQuoteList_h___ */ |