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
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 "nsGkAtoms.h" |
michael@0 | 9 | #include "txXPathTreeWalker.h" |
michael@0 | 10 | #include "txIXPathContext.h" |
michael@0 | 11 | |
michael@0 | 12 | txNameTest::txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, int32_t aNSID, |
michael@0 | 13 | uint16_t aNodeType) |
michael@0 | 14 | :mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID), |
michael@0 | 15 | mNodeType(aNodeType) |
michael@0 | 16 | { |
michael@0 | 17 | if (aPrefix == nsGkAtoms::_empty) |
michael@0 | 18 | mPrefix = 0; |
michael@0 | 19 | NS_ASSERTION(aLocalName, "txNameTest without a local name?"); |
michael@0 | 20 | NS_ASSERTION(aNodeType == txXPathNodeType::DOCUMENT_NODE || |
michael@0 | 21 | aNodeType == txXPathNodeType::ELEMENT_NODE || |
michael@0 | 22 | aNodeType == txXPathNodeType::ATTRIBUTE_NODE, |
michael@0 | 23 | "Go fix txNameTest::matches"); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | bool txNameTest::matches(const txXPathNode& aNode, txIMatchContext* aContext) |
michael@0 | 27 | { |
michael@0 | 28 | if ((mNodeType == txXPathNodeType::ELEMENT_NODE && |
michael@0 | 29 | !txXPathNodeUtils::isElement(aNode)) || |
michael@0 | 30 | (mNodeType == txXPathNodeType::ATTRIBUTE_NODE && |
michael@0 | 31 | !txXPathNodeUtils::isAttribute(aNode)) || |
michael@0 | 32 | (mNodeType == txXPathNodeType::DOCUMENT_NODE && |
michael@0 | 33 | !txXPathNodeUtils::isRoot(aNode))) { |
michael@0 | 34 | return false; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | // Totally wild? |
michael@0 | 38 | if (mLocalName == nsGkAtoms::_asterix && !mPrefix) |
michael@0 | 39 | return true; |
michael@0 | 40 | |
michael@0 | 41 | // Compare namespaces |
michael@0 | 42 | if (mNamespace != txXPathNodeUtils::getNamespaceID(aNode) |
michael@0 | 43 | && !(mNamespace == kNameSpaceID_None && |
michael@0 | 44 | txXPathNodeUtils::isHTMLElementInHTMLDocument(aNode)) |
michael@0 | 45 | ) |
michael@0 | 46 | return false; |
michael@0 | 47 | |
michael@0 | 48 | // Name wild? |
michael@0 | 49 | if (mLocalName == nsGkAtoms::_asterix) |
michael@0 | 50 | return true; |
michael@0 | 51 | |
michael@0 | 52 | // Compare local-names |
michael@0 | 53 | return txXPathNodeUtils::localNameEquals(aNode, mLocalName); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | /* |
michael@0 | 57 | * Returns the default priority of this txNodeTest |
michael@0 | 58 | */ |
michael@0 | 59 | double txNameTest::getDefaultPriority() |
michael@0 | 60 | { |
michael@0 | 61 | if (mLocalName == nsGkAtoms::_asterix) { |
michael@0 | 62 | if (!mPrefix) |
michael@0 | 63 | return -0.5; |
michael@0 | 64 | return -0.25; |
michael@0 | 65 | } |
michael@0 | 66 | return 0; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | txNodeTest::NodeTestType |
michael@0 | 70 | txNameTest::getType() |
michael@0 | 71 | { |
michael@0 | 72 | return NAME_TEST; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | bool |
michael@0 | 76 | txNameTest::isSensitiveTo(Expr::ContextSensitivity aContext) |
michael@0 | 77 | { |
michael@0 | 78 | return !!(aContext & Expr::NODE_CONTEXT); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | #ifdef TX_TO_STRING |
michael@0 | 82 | void |
michael@0 | 83 | txNameTest::toString(nsAString& aDest) |
michael@0 | 84 | { |
michael@0 | 85 | if (mPrefix) { |
michael@0 | 86 | nsAutoString prefix; |
michael@0 | 87 | mPrefix->ToString(prefix); |
michael@0 | 88 | aDest.Append(prefix); |
michael@0 | 89 | aDest.Append(char16_t(':')); |
michael@0 | 90 | } |
michael@0 | 91 | nsAutoString localName; |
michael@0 | 92 | mLocalName->ToString(localName); |
michael@0 | 93 | aDest.Append(localName); |
michael@0 | 94 | } |
michael@0 | 95 | #endif |