Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:cindent:ts=2:et:sw=2:
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/. */
7 /* implementation of quotes for the CSS 'content' property */
9 #include "nsQuoteList.h"
10 #include "nsReadableUtils.h"
11 #include "nsIContent.h"
13 bool
14 nsQuoteNode::InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame,
15 nsIFrame* aTextFrame)
16 {
17 nsGenConNode::InitTextFrame(aList, aPseudoFrame, aTextFrame);
19 nsQuoteList* quoteList = static_cast<nsQuoteList*>(aList);
20 bool dirty = false;
21 quoteList->Insert(this);
22 if (quoteList->IsLast(this))
23 quoteList->Calc(this);
24 else
25 dirty = true;
27 // Don't set up text for 'no-open-quote' and 'no-close-quote'.
28 if (IsRealQuote()) {
29 aTextFrame->GetContent()->SetText(*Text(), false);
30 }
31 return dirty;
32 }
34 const nsString*
35 nsQuoteNode::Text()
36 {
37 NS_ASSERTION(mType == eStyleContentType_OpenQuote ||
38 mType == eStyleContentType_CloseQuote,
39 "should only be called when mText should be non-null");
40 const nsStyleQuotes* styleQuotes = mPseudoFrame->StyleQuotes();
41 int32_t quotesCount = styleQuotes->QuotesCount(); // 0 if 'quotes:none'
42 int32_t quoteDepth = Depth();
44 // Reuse the last pair when the depth is greater than the number of
45 // pairs of quotes. (Also make 'quotes: none' and close-quote from
46 // a depth of 0 equivalent for the next test.)
47 if (quoteDepth >= quotesCount)
48 quoteDepth = quotesCount - 1;
50 const nsString *result;
51 if (quoteDepth == -1) {
52 // close-quote from a depth of 0 or 'quotes: none' (we want a node
53 // with the empty string so dynamic changes are easier to handle)
54 result = & EmptyString();
55 } else {
56 result = eStyleContentType_OpenQuote == mType
57 ? styleQuotes->OpenQuoteAt(quoteDepth)
58 : styleQuotes->CloseQuoteAt(quoteDepth);
59 }
60 return result;
61 }
63 void
64 nsQuoteList::Calc(nsQuoteNode* aNode)
65 {
66 if (aNode == FirstNode()) {
67 aNode->mDepthBefore = 0;
68 } else {
69 aNode->mDepthBefore = Prev(aNode)->DepthAfter();
70 }
71 }
73 void
74 nsQuoteList::RecalcAll()
75 {
76 nsQuoteNode *node = FirstNode();
77 if (!node)
78 return;
80 do {
81 int32_t oldDepth = node->mDepthBefore;
82 Calc(node);
84 if (node->mDepthBefore != oldDepth && node->mText && node->IsRealQuote())
85 node->mText->SetData(*node->Text());
87 // Next node
88 node = Next(node);
89 } while (node != FirstNode());
90 }
92 #ifdef DEBUG
93 void
94 nsQuoteList::PrintChain()
95 {
96 printf("Chain: \n");
97 if (!FirstNode()) {
98 return;
99 }
100 nsQuoteNode* node = FirstNode();
101 do {
102 printf(" %p %d - ", static_cast<void*>(node), node->mDepthBefore);
103 switch(node->mType) {
104 case (eStyleContentType_OpenQuote):
105 printf("open");
106 break;
107 case (eStyleContentType_NoOpenQuote):
108 printf("noOpen");
109 break;
110 case (eStyleContentType_CloseQuote):
111 printf("close");
112 break;
113 case (eStyleContentType_NoCloseQuote):
114 printf("noClose");
115 break;
116 default:
117 printf("unknown!!!");
118 }
119 printf(" %d - %d,", node->Depth(), node->DepthAfter());
120 if (node->mText) {
121 nsAutoString data;
122 node->mText->GetData(data);
123 printf(" \"%s\",", NS_ConvertUTF16toUTF8(data).get());
124 }
125 printf("\n");
126 node = Next(node);
127 } while (node != FirstNode());
128 }
129 #endif