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