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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "txExpr.h" |
michael@0 | 7 | #include "nsIAtom.h" |
michael@0 | 8 | #include "txIXPathContext.h" |
michael@0 | 9 | #include "txXPathTreeWalker.h" |
michael@0 | 10 | |
michael@0 | 11 | bool txNodeTypeTest::matches(const txXPathNode& aNode, |
michael@0 | 12 | txIMatchContext* aContext) |
michael@0 | 13 | { |
michael@0 | 14 | switch (mNodeType) { |
michael@0 | 15 | case COMMENT_TYPE: |
michael@0 | 16 | { |
michael@0 | 17 | return txXPathNodeUtils::isComment(aNode); |
michael@0 | 18 | } |
michael@0 | 19 | case TEXT_TYPE: |
michael@0 | 20 | { |
michael@0 | 21 | return txXPathNodeUtils::isText(aNode) && |
michael@0 | 22 | !aContext->isStripSpaceAllowed(aNode); |
michael@0 | 23 | } |
michael@0 | 24 | case PI_TYPE: |
michael@0 | 25 | { |
michael@0 | 26 | return txXPathNodeUtils::isProcessingInstruction(aNode) && |
michael@0 | 27 | (!mNodeName || |
michael@0 | 28 | txXPathNodeUtils::localNameEquals(aNode, mNodeName)); |
michael@0 | 29 | } |
michael@0 | 30 | case NODE_TYPE: |
michael@0 | 31 | { |
michael@0 | 32 | return !txXPathNodeUtils::isText(aNode) || |
michael@0 | 33 | !aContext->isStripSpaceAllowed(aNode); |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | return true; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | txNodeTest::NodeTestType |
michael@0 | 40 | txNodeTypeTest::getType() |
michael@0 | 41 | { |
michael@0 | 42 | return NODETYPE_TEST; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | /* |
michael@0 | 46 | * Returns the default priority of this txNodeTest |
michael@0 | 47 | */ |
michael@0 | 48 | double txNodeTypeTest::getDefaultPriority() |
michael@0 | 49 | { |
michael@0 | 50 | return mNodeName ? 0 : -0.5; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | bool |
michael@0 | 54 | txNodeTypeTest::isSensitiveTo(Expr::ContextSensitivity aContext) |
michael@0 | 55 | { |
michael@0 | 56 | return !!(aContext & Expr::NODE_CONTEXT); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | #ifdef TX_TO_STRING |
michael@0 | 60 | void |
michael@0 | 61 | txNodeTypeTest::toString(nsAString& aDest) |
michael@0 | 62 | { |
michael@0 | 63 | switch (mNodeType) { |
michael@0 | 64 | case COMMENT_TYPE: |
michael@0 | 65 | aDest.Append(NS_LITERAL_STRING("comment()")); |
michael@0 | 66 | break; |
michael@0 | 67 | case TEXT_TYPE: |
michael@0 | 68 | aDest.Append(NS_LITERAL_STRING("text()")); |
michael@0 | 69 | break; |
michael@0 | 70 | case PI_TYPE: |
michael@0 | 71 | aDest.AppendLiteral("processing-instruction("); |
michael@0 | 72 | if (mNodeName) { |
michael@0 | 73 | nsAutoString str; |
michael@0 | 74 | mNodeName->ToString(str); |
michael@0 | 75 | aDest.Append(char16_t('\'')); |
michael@0 | 76 | aDest.Append(str); |
michael@0 | 77 | aDest.Append(char16_t('\'')); |
michael@0 | 78 | } |
michael@0 | 79 | aDest.Append(char16_t(')')); |
michael@0 | 80 | break; |
michael@0 | 81 | case NODE_TYPE: |
michael@0 | 82 | aDest.Append(NS_LITERAL_STRING("node()")); |
michael@0 | 83 | break; |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | #endif |