LCOV - code coverage report
Current view: directory - layout/base - nsQuoteList.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 64 0 0.0 %
Date: 2012-06-02 Functions: 5 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : // vim:cindent:ts=2:et:sw=2:
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Esben Mose Hansen.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Esben Mose Hansen <esben@oek.dk> (original author)
      23                 :  *   L. David Baron <dbaron@dbaron.org>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : /* implementation of quotes for the CSS 'content' property */
      40                 : 
      41                 : #include "nsQuoteList.h"
      42                 : #include "nsReadableUtils.h"
      43                 : 
      44                 : bool
      45               0 : nsQuoteNode::InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame,
      46                 :                            nsIFrame* aTextFrame)
      47                 : {
      48               0 :   nsGenConNode::InitTextFrame(aList, aPseudoFrame, aTextFrame);
      49                 : 
      50               0 :   nsQuoteList* quoteList = static_cast<nsQuoteList*>(aList);
      51               0 :   bool dirty = false;
      52               0 :   quoteList->Insert(this);
      53               0 :   if (quoteList->IsLast(this))
      54               0 :     quoteList->Calc(this);
      55                 :   else
      56               0 :     dirty = true;
      57                 : 
      58                 :   // Don't set up text for 'no-open-quote' and 'no-close-quote'.
      59               0 :   if (IsRealQuote()) {
      60               0 :     aTextFrame->GetContent()->SetText(*Text(), false);
      61                 :   }
      62               0 :   return dirty;
      63                 : }
      64                 : 
      65                 : const nsString*
      66               0 : nsQuoteNode::Text()
      67                 : {
      68               0 :   NS_ASSERTION(mType == eStyleContentType_OpenQuote ||
      69                 :                mType == eStyleContentType_CloseQuote,
      70                 :                "should only be called when mText should be non-null");
      71               0 :   const nsStyleQuotes* styleQuotes = mPseudoFrame->GetStyleQuotes();
      72               0 :   PRInt32 quotesCount = styleQuotes->QuotesCount(); // 0 if 'quotes:none'
      73               0 :   PRInt32 quoteDepth = Depth();
      74                 : 
      75                 :   // Reuse the last pair when the depth is greater than the number of
      76                 :   // pairs of quotes.  (Also make 'quotes: none' and close-quote from
      77                 :   // a depth of 0 equivalent for the next test.)
      78               0 :   if (quoteDepth >= quotesCount)
      79               0 :     quoteDepth = quotesCount - 1;
      80                 : 
      81                 :   const nsString *result;
      82               0 :   if (quoteDepth == -1) {
      83                 :     // close-quote from a depth of 0 or 'quotes: none' (we want a node
      84                 :     // with the empty string so dynamic changes are easier to handle)
      85               0 :     result = & EmptyString();
      86                 :   } else {
      87                 :     result = eStyleContentType_OpenQuote == mType
      88               0 :                ? styleQuotes->OpenQuoteAt(quoteDepth)
      89               0 :                : styleQuotes->CloseQuoteAt(quoteDepth);
      90                 :   }
      91               0 :   return result;
      92                 : }
      93                 : 
      94                 : void
      95               0 : nsQuoteList::Calc(nsQuoteNode* aNode)
      96                 : {
      97               0 :   if (aNode == FirstNode()) {
      98               0 :     aNode->mDepthBefore = 0;
      99                 :   } else {
     100               0 :     aNode->mDepthBefore = Prev(aNode)->DepthAfter();
     101                 :   }
     102               0 : }
     103                 : 
     104                 : void
     105               0 : nsQuoteList::RecalcAll()
     106                 : {
     107               0 :   nsQuoteNode *node = FirstNode();
     108               0 :   if (!node)
     109               0 :     return;
     110                 : 
     111               0 :   do {
     112               0 :     PRInt32 oldDepth = node->mDepthBefore;
     113               0 :     Calc(node);
     114                 : 
     115               0 :     if (node->mDepthBefore != oldDepth && node->mText && node->IsRealQuote())
     116               0 :       node->mText->SetData(*node->Text());
     117                 : 
     118                 :     // Next node
     119               0 :     node = Next(node);
     120               0 :   } while (node != FirstNode());
     121                 : }
     122                 : 
     123                 : #ifdef DEBUG
     124                 : void
     125               0 : nsQuoteList::PrintChain()
     126                 : {
     127               0 :   printf("Chain: \n");
     128               0 :   if (!FirstNode()) {
     129               0 :     return;
     130                 :   }
     131               0 :   nsQuoteNode* node = FirstNode();
     132               0 :   do {
     133               0 :     printf("  %p %d - ", static_cast<void*>(node), node->mDepthBefore);
     134               0 :     switch(node->mType) {
     135                 :         case (eStyleContentType_OpenQuote):
     136               0 :           printf("open");
     137               0 :           break;
     138                 :         case (eStyleContentType_NoOpenQuote):
     139               0 :           printf("noOpen");
     140               0 :           break;
     141                 :         case (eStyleContentType_CloseQuote):
     142               0 :           printf("close");
     143               0 :           break;
     144                 :         case (eStyleContentType_NoCloseQuote):
     145               0 :           printf("noClose");
     146               0 :           break;
     147                 :         default:
     148               0 :           printf("unknown!!!");
     149                 :     }
     150               0 :     printf(" %d - %d,", node->Depth(), node->DepthAfter());
     151               0 :     if (node->mText) {
     152               0 :       nsAutoString data;
     153               0 :       node->mText->GetData(data);
     154               0 :       printf(" \"%s\",", NS_ConvertUTF16toUTF8(data).get());
     155                 :     }
     156               0 :     printf("\n");
     157               0 :     node = Next(node);
     158               0 :   } while (node != FirstNode());
     159                 : }
     160                 : #endif

Generated by: LCOV version 1.7