summaryrefslogtreecommitdiffstats
path: root/dom/xslt/xpath/txNameTest.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/xslt/xpath/txNameTest.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/xslt/xpath/txNameTest.cpp')
-rw-r--r--dom/xslt/xpath/txNameTest.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/dom/xslt/xpath/txNameTest.cpp b/dom/xslt/xpath/txNameTest.cpp
new file mode 100644
index 000000000..bad043282
--- /dev/null
+++ b/dom/xslt/xpath/txNameTest.cpp
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "txExpr.h"
+#include "nsIAtom.h"
+#include "nsGkAtoms.h"
+#include "txXPathTreeWalker.h"
+#include "txIXPathContext.h"
+
+txNameTest::txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, int32_t aNSID,
+ uint16_t aNodeType)
+ :mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID),
+ mNodeType(aNodeType)
+{
+ if (aPrefix == nsGkAtoms::_empty)
+ mPrefix = nullptr;
+ NS_ASSERTION(aLocalName, "txNameTest without a local name?");
+ NS_ASSERTION(aNodeType == txXPathNodeType::DOCUMENT_NODE ||
+ aNodeType == txXPathNodeType::ELEMENT_NODE ||
+ aNodeType == txXPathNodeType::ATTRIBUTE_NODE,
+ "Go fix txNameTest::matches");
+}
+
+bool txNameTest::matches(const txXPathNode& aNode, txIMatchContext* aContext)
+{
+ if ((mNodeType == txXPathNodeType::ELEMENT_NODE &&
+ !txXPathNodeUtils::isElement(aNode)) ||
+ (mNodeType == txXPathNodeType::ATTRIBUTE_NODE &&
+ !txXPathNodeUtils::isAttribute(aNode)) ||
+ (mNodeType == txXPathNodeType::DOCUMENT_NODE &&
+ !txXPathNodeUtils::isRoot(aNode))) {
+ return false;
+ }
+
+ // Totally wild?
+ if (mLocalName == nsGkAtoms::_asterisk && !mPrefix)
+ return true;
+
+ // Compare namespaces
+ if (mNamespace != txXPathNodeUtils::getNamespaceID(aNode)
+ && !(mNamespace == kNameSpaceID_None &&
+ txXPathNodeUtils::isHTMLElementInHTMLDocument(aNode))
+ )
+ return false;
+
+ // Name wild?
+ if (mLocalName == nsGkAtoms::_asterisk)
+ return true;
+
+ // Compare local-names
+ return txXPathNodeUtils::localNameEquals(aNode, mLocalName);
+}
+
+/*
+ * Returns the default priority of this txNodeTest
+ */
+double txNameTest::getDefaultPriority()
+{
+ if (mLocalName == nsGkAtoms::_asterisk) {
+ if (!mPrefix)
+ return -0.5;
+ return -0.25;
+ }
+ return 0;
+}
+
+txNodeTest::NodeTestType
+txNameTest::getType()
+{
+ return NAME_TEST;
+}
+
+bool
+txNameTest::isSensitiveTo(Expr::ContextSensitivity aContext)
+{
+ return !!(aContext & Expr::NODE_CONTEXT);
+}
+
+#ifdef TX_TO_STRING
+void
+txNameTest::toString(nsAString& aDest)
+{
+ if (mPrefix) {
+ nsAutoString prefix;
+ mPrefix->ToString(prefix);
+ aDest.Append(prefix);
+ aDest.Append(char16_t(':'));
+ }
+ nsAutoString localName;
+ mLocalName->ToString(localName);
+ aDest.Append(localName);
+}
+#endif