Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/base/nsQuoteList.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
/* implementation of quotes for the CSS 'content' property */
8
9
#include "nsQuoteList.h"
10
#include "nsReadableUtils.h"
11
#include "nsIContent.h"
12
#include "mozilla/ErrorResult.h"
13
#include "mozilla/dom/Text.h"
14
15
using namespace mozilla;
16
17
bool
18
nsQuoteNode::InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame,
19
                           nsIFrame* aTextFrame)
20
0
{
21
0
  nsGenConNode::InitTextFrame(aList, aPseudoFrame, aTextFrame);
22
0
23
0
  nsQuoteList* quoteList = static_cast<nsQuoteList*>(aList);
24
0
  bool dirty = false;
25
0
  quoteList->Insert(this);
26
0
  if (quoteList->IsLast(this))
27
0
    quoteList->Calc(this);
28
0
  else
29
0
    dirty = true;
30
0
31
0
  // Don't set up text for 'no-open-quote' and 'no-close-quote'.
32
0
  if (IsRealQuote()) {
33
0
    aTextFrame->GetContent()->AsText()->SetText(*Text(), false);
34
0
  }
35
0
  return dirty;
36
0
}
37
38
const nsString*
39
nsQuoteNode::Text()
40
0
{
41
0
  NS_ASSERTION(mType == StyleContentType::OpenQuote ||
42
0
               mType == StyleContentType::CloseQuote,
43
0
               "should only be called when mText should be non-null");
44
0
  const nsStyleQuoteValues::QuotePairArray& quotePairs =
45
0
    mPseudoFrame->StyleList()->GetQuotePairs();
46
0
  int32_t quotesCount = quotePairs.Length(); // 0 if 'quotes:none'
47
0
  int32_t quoteDepth = Depth();
48
0
49
0
  // Reuse the last pair when the depth is greater than the number of
50
0
  // pairs of quotes.  (Also make 'quotes: none' and close-quote from
51
0
  // a depth of 0 equivalent for the next test.)
52
0
  if (quoteDepth >= quotesCount)
53
0
    quoteDepth = quotesCount - 1;
54
0
55
0
  const nsString* result;
56
0
  if (quoteDepth == -1) {
57
0
    // close-quote from a depth of 0 or 'quotes: none' (we want a node
58
0
    // with the empty string so dynamic changes are easier to handle)
59
0
    result = &EmptyString();
60
0
  } else {
61
0
    result = StyleContentType::OpenQuote == mType
62
0
               ? &quotePairs[quoteDepth].first
63
0
               : &quotePairs[quoteDepth].second;
64
0
  }
65
0
  return result;
66
0
}
67
68
void
69
nsQuoteList::Calc(nsQuoteNode* aNode)
70
0
{
71
0
  if (aNode == FirstNode()) {
72
0
    aNode->mDepthBefore = 0;
73
0
  } else {
74
0
    aNode->mDepthBefore = Prev(aNode)->DepthAfter();
75
0
  }
76
0
}
77
78
void
79
nsQuoteList::RecalcAll()
80
0
{
81
0
  for (nsQuoteNode* node = FirstNode(); node; node = Next(node)) {
82
0
    int32_t oldDepth = node->mDepthBefore;
83
0
    Calc(node);
84
0
85
0
    if (node->mDepthBefore != oldDepth && node->mText && node->IsRealQuote())
86
0
      node->mText->SetData(*node->Text(), IgnoreErrors());
87
0
  }
88
0
}
89
90
#ifdef DEBUG
91
void
92
nsQuoteList::PrintChain()
93
{
94
  printf("Chain: \n");
95
  for (nsQuoteNode* node = FirstNode(); node; node = Next(node)) {
96
    printf("  %p %d - ", static_cast<void*>(node), node->mDepthBefore);
97
    switch(node->mType) {
98
        case StyleContentType::OpenQuote:
99
          printf("open");
100
          break;
101
        case StyleContentType::NoOpenQuote:
102
          printf("noOpen");
103
          break;
104
        case StyleContentType::CloseQuote:
105
          printf("close");
106
          break;
107
        case StyleContentType::NoCloseQuote:
108
          printf("noClose");
109
          break;
110
        default:
111
          printf("unknown!!!");
112
    }
113
    printf(" %d - %d,", node->Depth(), node->DepthAfter());
114
    if (node->mText) {
115
      nsAutoString data;
116
      node->mText->GetData(data);
117
      printf(" \"%s\",", NS_ConvertUTF16toUTF8(data).get());
118
    }
119
    printf("\n");
120
  }
121
}
122
#endif