Back to index

lightning-sunbird  0.9+nobinonly
nsQuoteList.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Esben Mose Hansen.
00019  *
00020  * Contributor(s):
00021  *   Esben Mose Hansen <esben@oek.dk> (original author)
00022  *   L. David Baron <dbaron@dbaron.org>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsQuoteList_h___
00038 #define nsQuoteList_h___
00039 
00040 #include "nsGenConList.h"
00041 
00042 struct nsQuoteNode : public nsGenConNode {
00043   // open-quote, close-quote, no-open-quote, or no-close-quote
00044   const nsStyleContentType mType;
00045 
00046   // Quote depth before this quote, which is always non-negative.
00047   PRInt32 mDepthBefore;
00048 
00049 
00050   nsQuoteNode(nsStyleContentType& aType, nsIFrame* aPseudoFrame,
00051               PRUint32 aContentIndex)
00052     : nsGenConNode(aPseudoFrame, aContentIndex)
00053     , mType(aType)
00054     , mDepthBefore(0)
00055   {
00056     NS_ASSERTION(aType == eStyleContentType_OpenQuote ||
00057                  aType == eStyleContentType_CloseQuote ||
00058                  aType == eStyleContentType_NoOpenQuote ||
00059                  aType == eStyleContentType_NoCloseQuote,
00060                  "incorrect type");
00061     NS_ASSERTION(aContentIndex >= 0, "out of range");
00062   }
00063 
00064   // is this 'open-quote' or 'no-open-quote'?
00065   PRBool IsOpenQuote() {
00066     return mType == eStyleContentType_OpenQuote ||
00067            mType == eStyleContentType_NoOpenQuote;
00068   }
00069 
00070   // is this 'close-quote' or 'no-close-quote'?
00071   PRBool IsCloseQuote() {
00072     return !IsOpenQuote();
00073   }
00074 
00075   // is this 'open-quote' or 'close-quote'?
00076   PRBool IsRealQuote() {
00077     return mType == eStyleContentType_OpenQuote ||
00078            mType == eStyleContentType_CloseQuote;
00079   }
00080 
00081   // is this 'no-open-quote' or 'no-close-quote'?
00082   PRBool IsHiddenQuote() {
00083     return !IsRealQuote();
00084   }
00085 
00086   // Depth of the quote for *this* node.  Either non-negative or -1.
00087   // -1 means this is a closing quote that tried to decrement the
00088   // counter below zero (which means no quote should be rendered).
00089   PRInt32 Depth() {
00090     return IsOpenQuote() ? mDepthBefore : mDepthBefore - 1;
00091   }
00092 
00093   // always non-negative
00094   PRInt32 DepthAfter() {
00095     return IsOpenQuote() ? mDepthBefore + 1
00096                          : (mDepthBefore == 0 ? 0 : mDepthBefore - 1);
00097   }
00098 
00099   // The text that should be displayed for this quote.
00100   const nsString* Text();
00101 };
00102 
00103 class nsQuoteList : public nsGenConList {
00104 private:
00105   nsQuoteNode* FirstNode() { return NS_STATIC_CAST(nsQuoteNode*, mFirstNode); }
00106 public:
00107   // assign the correct |mDepthBefore| value to a node that has been inserted
00108   // Should be called immediately after calling |Insert|.
00109   void Calc(nsQuoteNode* aNode);
00110 
00111   nsQuoteNode* Next(nsQuoteNode* aNode) {
00112     return NS_STATIC_CAST(nsQuoteNode*, nsGenConList::Next(aNode));
00113   }
00114   nsQuoteNode* Prev(nsQuoteNode* aNode) {
00115     return NS_STATIC_CAST(nsQuoteNode*, nsGenConList::Prev(aNode));
00116   }
00117   
00118   void RecalcAll();
00119 #ifdef DEBUG
00120   void PrintChain();
00121 #endif
00122 };
00123 
00124 #endif /* nsQuoteList_h___ */