Line data Source code
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/. */
6 :
7 : /* implementation of quotes for the CSS 'content' property */
8 :
9 : #include "nsQuoteList.h"
10 : #include "nsReadableUtils.h"
11 : #include "nsIContent.h"
12 :
13 : bool
14 0 : nsQuoteNode::InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame,
15 : nsIFrame* aTextFrame)
16 : {
17 0 : nsGenConNode::InitTextFrame(aList, aPseudoFrame, aTextFrame);
18 :
19 0 : nsQuoteList* quoteList = static_cast<nsQuoteList*>(aList);
20 0 : bool dirty = false;
21 0 : quoteList->Insert(this);
22 0 : if (quoteList->IsLast(this))
23 0 : quoteList->Calc(this);
24 : else
25 0 : dirty = true;
26 :
27 : // Don't set up text for 'no-open-quote' and 'no-close-quote'.
28 0 : if (IsRealQuote()) {
29 0 : aTextFrame->GetContent()->SetText(*Text(), false);
30 : }
31 0 : return dirty;
32 : }
33 :
34 : const nsString*
35 0 : nsQuoteNode::Text()
36 : {
37 0 : NS_ASSERTION(mType == eStyleContentType_OpenQuote ||
38 : mType == eStyleContentType_CloseQuote,
39 : "should only be called when mText should be non-null");
40 : const nsStyleQuoteValues::QuotePairArray& quotePairs =
41 0 : mPseudoFrame->StyleList()->GetQuotePairs();
42 0 : int32_t quotesCount = quotePairs.Length(); // 0 if 'quotes:none'
43 0 : int32_t quoteDepth = Depth();
44 :
45 : // Reuse the last pair when the depth is greater than the number of
46 : // pairs of quotes. (Also make 'quotes: none' and close-quote from
47 : // a depth of 0 equivalent for the next test.)
48 0 : if (quoteDepth >= quotesCount)
49 0 : quoteDepth = quotesCount - 1;
50 :
51 : const nsString* result;
52 0 : if (quoteDepth == -1) {
53 : // close-quote from a depth of 0 or 'quotes: none' (we want a node
54 : // with the empty string so dynamic changes are easier to handle)
55 0 : result = &EmptyString();
56 : } else {
57 0 : result = eStyleContentType_OpenQuote == mType
58 0 : ? "ePairs[quoteDepth].first
59 0 : : "ePairs[quoteDepth].second;
60 : }
61 0 : return result;
62 : }
63 :
64 : void
65 0 : nsQuoteList::Calc(nsQuoteNode* aNode)
66 : {
67 0 : if (aNode == FirstNode()) {
68 0 : aNode->mDepthBefore = 0;
69 : } else {
70 0 : aNode->mDepthBefore = Prev(aNode)->DepthAfter();
71 : }
72 0 : }
73 :
74 : void
75 0 : nsQuoteList::RecalcAll()
76 : {
77 0 : for (nsQuoteNode* node = FirstNode(); node; node = Next(node)) {
78 0 : int32_t oldDepth = node->mDepthBefore;
79 0 : Calc(node);
80 :
81 0 : if (node->mDepthBefore != oldDepth && node->mText && node->IsRealQuote())
82 0 : node->mText->SetData(*node->Text());
83 : }
84 0 : }
85 :
86 : #ifdef DEBUG
87 : void
88 0 : nsQuoteList::PrintChain()
89 : {
90 0 : printf("Chain: \n");
91 0 : for (nsQuoteNode* node = FirstNode(); node; node = Next(node)) {
92 0 : printf(" %p %d - ", static_cast<void*>(node), node->mDepthBefore);
93 0 : switch(node->mType) {
94 : case (eStyleContentType_OpenQuote):
95 0 : printf("open");
96 0 : break;
97 : case (eStyleContentType_NoOpenQuote):
98 0 : printf("noOpen");
99 0 : break;
100 : case (eStyleContentType_CloseQuote):
101 0 : printf("close");
102 0 : break;
103 : case (eStyleContentType_NoCloseQuote):
104 0 : printf("noClose");
105 0 : break;
106 : default:
107 0 : printf("unknown!!!");
108 : }
109 0 : printf(" %d - %d,", node->Depth(), node->DepthAfter());
110 0 : if (node->mText) {
111 0 : nsAutoString data;
112 0 : node->mText->GetData(data);
113 0 : printf(" \"%s\",", NS_ConvertUTF16toUTF8(data).get());
114 : }
115 0 : printf("\n");
116 : }
117 0 : }
118 : #endif
|