michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* implementation of quotes for the CSS 'content' property */ michael@0: michael@0: #ifndef nsQuoteList_h___ michael@0: #define nsQuoteList_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsGenConList.h" michael@0: michael@0: struct nsQuoteNode : public nsGenConNode { michael@0: // open-quote, close-quote, no-open-quote, or no-close-quote michael@0: const nsStyleContentType mType; michael@0: michael@0: // Quote depth before this quote, which is always non-negative. michael@0: int32_t mDepthBefore; michael@0: michael@0: nsQuoteNode(nsStyleContentType& aType, uint32_t aContentIndex) michael@0: : nsGenConNode(aContentIndex) michael@0: , mType(aType) michael@0: , mDepthBefore(0) michael@0: { michael@0: NS_ASSERTION(aType == eStyleContentType_OpenQuote || michael@0: aType == eStyleContentType_CloseQuote || michael@0: aType == eStyleContentType_NoOpenQuote || michael@0: aType == eStyleContentType_NoCloseQuote, michael@0: "incorrect type"); michael@0: NS_ASSERTION(aContentIndex <= INT32_MAX, "out of range"); michael@0: } michael@0: michael@0: virtual bool InitTextFrame(nsGenConList* aList, michael@0: nsIFrame* aPseudoFrame, nsIFrame* aTextFrame) MOZ_OVERRIDE; michael@0: michael@0: // is this 'open-quote' or 'no-open-quote'? michael@0: bool IsOpenQuote() { michael@0: return mType == eStyleContentType_OpenQuote || michael@0: mType == eStyleContentType_NoOpenQuote; michael@0: } michael@0: michael@0: // is this 'close-quote' or 'no-close-quote'? michael@0: bool IsCloseQuote() { michael@0: return !IsOpenQuote(); michael@0: } michael@0: michael@0: // is this 'open-quote' or 'close-quote'? michael@0: bool IsRealQuote() { michael@0: return mType == eStyleContentType_OpenQuote || michael@0: mType == eStyleContentType_CloseQuote; michael@0: } michael@0: michael@0: // Depth of the quote for *this* node. Either non-negative or -1. michael@0: // -1 means this is a closing quote that tried to decrement the michael@0: // counter below zero (which means no quote should be rendered). michael@0: int32_t Depth() { michael@0: return IsOpenQuote() ? mDepthBefore : mDepthBefore - 1; michael@0: } michael@0: michael@0: // always non-negative michael@0: int32_t DepthAfter() { michael@0: return IsOpenQuote() ? mDepthBefore + 1 michael@0: : (mDepthBefore == 0 ? 0 : mDepthBefore - 1); michael@0: } michael@0: michael@0: // The text that should be displayed for this quote. michael@0: const nsString* Text(); michael@0: }; michael@0: michael@0: class nsQuoteList : public nsGenConList { michael@0: private: michael@0: nsQuoteNode* FirstNode() { return static_cast(mFirstNode); } michael@0: public: michael@0: // assign the correct |mDepthBefore| value to a node that has been inserted michael@0: // Should be called immediately after calling |Insert|. michael@0: void Calc(nsQuoteNode* aNode); michael@0: michael@0: nsQuoteNode* Next(nsQuoteNode* aNode) { michael@0: return static_cast(nsGenConList::Next(aNode)); michael@0: } michael@0: nsQuoteNode* Prev(nsQuoteNode* aNode) { michael@0: return static_cast(nsGenConList::Prev(aNode)); michael@0: } michael@0: michael@0: void RecalcAll(); michael@0: #ifdef DEBUG michael@0: void PrintChain(); michael@0: #endif michael@0: }; michael@0: michael@0: #endif /* nsQuoteList_h___ */