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