layout/base/nsQuoteList.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/base/nsQuoteList.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +// vim:cindent:ts=2:et:sw=2:
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/* implementation of quotes for the CSS 'content' property */
    1.11 +
    1.12 +#include "nsQuoteList.h"
    1.13 +#include "nsReadableUtils.h"
    1.14 +#include "nsIContent.h"
    1.15 +
    1.16 +bool
    1.17 +nsQuoteNode::InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame,
    1.18 +                           nsIFrame* aTextFrame)
    1.19 +{
    1.20 +  nsGenConNode::InitTextFrame(aList, aPseudoFrame, aTextFrame);
    1.21 +
    1.22 +  nsQuoteList* quoteList = static_cast<nsQuoteList*>(aList);
    1.23 +  bool dirty = false;
    1.24 +  quoteList->Insert(this);
    1.25 +  if (quoteList->IsLast(this))
    1.26 +    quoteList->Calc(this);
    1.27 +  else
    1.28 +    dirty = true;
    1.29 +
    1.30 +  // Don't set up text for 'no-open-quote' and 'no-close-quote'.
    1.31 +  if (IsRealQuote()) {
    1.32 +    aTextFrame->GetContent()->SetText(*Text(), false);
    1.33 +  }
    1.34 +  return dirty;
    1.35 +}
    1.36 +
    1.37 +const nsString*
    1.38 +nsQuoteNode::Text()
    1.39 +{
    1.40 +  NS_ASSERTION(mType == eStyleContentType_OpenQuote ||
    1.41 +               mType == eStyleContentType_CloseQuote,
    1.42 +               "should only be called when mText should be non-null");
    1.43 +  const nsStyleQuotes* styleQuotes = mPseudoFrame->StyleQuotes();
    1.44 +  int32_t quotesCount = styleQuotes->QuotesCount(); // 0 if 'quotes:none'
    1.45 +  int32_t quoteDepth = Depth();
    1.46 +
    1.47 +  // Reuse the last pair when the depth is greater than the number of
    1.48 +  // pairs of quotes.  (Also make 'quotes: none' and close-quote from
    1.49 +  // a depth of 0 equivalent for the next test.)
    1.50 +  if (quoteDepth >= quotesCount)
    1.51 +    quoteDepth = quotesCount - 1;
    1.52 +
    1.53 +  const nsString *result;
    1.54 +  if (quoteDepth == -1) {
    1.55 +    // close-quote from a depth of 0 or 'quotes: none' (we want a node
    1.56 +    // with the empty string so dynamic changes are easier to handle)
    1.57 +    result = & EmptyString();
    1.58 +  } else {
    1.59 +    result = eStyleContentType_OpenQuote == mType
    1.60 +               ? styleQuotes->OpenQuoteAt(quoteDepth)
    1.61 +               : styleQuotes->CloseQuoteAt(quoteDepth);
    1.62 +  }
    1.63 +  return result;
    1.64 +}
    1.65 +
    1.66 +void
    1.67 +nsQuoteList::Calc(nsQuoteNode* aNode)
    1.68 +{
    1.69 +  if (aNode == FirstNode()) {
    1.70 +    aNode->mDepthBefore = 0;
    1.71 +  } else {
    1.72 +    aNode->mDepthBefore = Prev(aNode)->DepthAfter();
    1.73 +  }
    1.74 +}
    1.75 +
    1.76 +void
    1.77 +nsQuoteList::RecalcAll()
    1.78 +{
    1.79 +  nsQuoteNode *node = FirstNode();
    1.80 +  if (!node)
    1.81 +    return;
    1.82 +
    1.83 +  do {
    1.84 +    int32_t oldDepth = node->mDepthBefore;
    1.85 +    Calc(node);
    1.86 +
    1.87 +    if (node->mDepthBefore != oldDepth && node->mText && node->IsRealQuote())
    1.88 +      node->mText->SetData(*node->Text());
    1.89 +
    1.90 +    // Next node
    1.91 +    node = Next(node);
    1.92 +  } while (node != FirstNode());
    1.93 +}
    1.94 +
    1.95 +#ifdef DEBUG
    1.96 +void
    1.97 +nsQuoteList::PrintChain()
    1.98 +{
    1.99 +  printf("Chain: \n");
   1.100 +  if (!FirstNode()) {
   1.101 +    return;
   1.102 +  }
   1.103 +  nsQuoteNode* node = FirstNode();
   1.104 +  do {
   1.105 +    printf("  %p %d - ", static_cast<void*>(node), node->mDepthBefore);
   1.106 +    switch(node->mType) {
   1.107 +        case (eStyleContentType_OpenQuote):
   1.108 +          printf("open");
   1.109 +          break;
   1.110 +        case (eStyleContentType_NoOpenQuote):
   1.111 +          printf("noOpen");
   1.112 +          break;
   1.113 +        case (eStyleContentType_CloseQuote):
   1.114 +          printf("close");
   1.115 +          break;
   1.116 +        case (eStyleContentType_NoCloseQuote):
   1.117 +          printf("noClose");
   1.118 +          break;
   1.119 +        default:
   1.120 +          printf("unknown!!!");
   1.121 +    }
   1.122 +    printf(" %d - %d,", node->Depth(), node->DepthAfter());
   1.123 +    if (node->mText) {
   1.124 +      nsAutoString data;
   1.125 +      node->mText->GetData(data);
   1.126 +      printf(" \"%s\",", NS_ConvertUTF16toUTF8(data).get());
   1.127 +    }
   1.128 +    printf("\n");
   1.129 +    node = Next(node);
   1.130 +  } while (node != FirstNode());
   1.131 +}
   1.132 +#endif

mercurial