Back to index

lightning-sunbird  0.9+nobinonly
nsQuoteList.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 // vim:cindent:ts=2:et:sw=2:
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Esben Mose Hansen.
00020  *
00021  * Contributor(s):
00022  *   Esben Mose Hansen <esben@oek.dk> (original author)
00023  *   L. David Baron <dbaron@dbaron.org>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsQuoteList.h"
00040 #include "nsReadableUtils.h"
00041 
00042 const nsString*
00043 nsQuoteNode::Text()
00044 {
00045   NS_ASSERTION(mType == eStyleContentType_OpenQuote ||
00046                mType == eStyleContentType_CloseQuote,
00047                "should only be called when mText should be non-null");
00048   const nsStyleQuotes* styleQuotes = mPseudoFrame->GetStyleQuotes();
00049   PRInt32 quotesCount = styleQuotes->QuotesCount(); // 0 if 'quotes:none'
00050   PRInt32 quoteDepth = Depth();
00051 
00052   // Reuse the last pair when the depth is greater than the number of
00053   // pairs of quotes.  (Also make 'quotes: none' and close-quote from
00054   // a depth of 0 equivalent for the next test.)
00055   if (quoteDepth >= quotesCount)
00056     quoteDepth = quotesCount - 1;
00057 
00058   const nsString *result;
00059   if (quoteDepth == -1) {
00060     // close-quote from a depth of 0 or 'quotes: none' (we want a node
00061     // with the empty string so dynamic changes are easier to handle)
00062     result = & EmptyString();
00063   } else {
00064     result = eStyleContentType_OpenQuote == mType
00065                ? styleQuotes->OpenQuoteAt(quoteDepth)
00066                : styleQuotes->CloseQuoteAt(quoteDepth);
00067   }
00068   return result;
00069 }
00070 
00071 void
00072 nsQuoteList::Calc(nsQuoteNode* aNode)
00073 {
00074   if (aNode == FirstNode()) {
00075     aNode->mDepthBefore = 0;
00076   } else {
00077     aNode->mDepthBefore = Prev(aNode)->DepthAfter();
00078   }
00079 }
00080 
00081 void
00082 nsQuoteList::RecalcAll()
00083 {
00084   nsQuoteNode *node = FirstNode();
00085   if (!node)
00086     return;
00087 
00088   do {
00089     PRInt32 oldDepth = node->mDepthBefore;
00090     Calc(node);
00091 
00092     if (node->mDepthBefore != oldDepth && node->mText)
00093       node->mText->SetData(*node->Text());
00094 
00095     // Next node
00096     node = Next(node);
00097   } while (node != FirstNode());
00098 }
00099 
00100 #ifdef DEBUG
00101 void
00102 nsQuoteList::PrintChain()
00103 {
00104   printf("Chain: \n");
00105   if (!FirstNode()) {
00106     return;
00107   }
00108   nsQuoteNode* node = FirstNode();
00109   do {
00110     printf("  %p %d - ", NS_STATIC_CAST(void*, node), node->mDepthBefore);
00111     switch(node->mType) {
00112         case (eStyleContentType_OpenQuote):
00113           printf("open");
00114           break;
00115         case (eStyleContentType_NoOpenQuote):
00116           printf("noOpen");
00117           break;
00118         case (eStyleContentType_CloseQuote):
00119           printf("close");
00120           break;
00121         case (eStyleContentType_NoCloseQuote):
00122           printf("noClose");
00123           break;
00124         default:
00125           printf("unknown!!!");
00126     }
00127     printf(" %d - %d,", node->Depth(), node->DepthAfter());
00128     if (node->mText) {
00129       nsAutoString data;
00130       node->mText->GetData(data);
00131       printf(" \"%s\",", NS_ConvertUCS2toUTF8(data).get());
00132     }
00133     printf("\n");
00134     node = Next(node);
00135   } while (node != FirstNode());
00136 }
00137 #endif