2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "txExpr.h"
|
|
|
|
#include "nsIAtom.h"
|
2011-09-19 13:07:17 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "txXPathTreeWalker.h"
|
|
|
|
#include "txIXPathContext.h"
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
txNameTest::txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, int32_t aNSID,
|
|
|
|
uint16_t aNodeType)
|
2007-03-22 10:30:00 -07:00
|
|
|
:mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID),
|
|
|
|
mNodeType(aNodeType)
|
|
|
|
{
|
2011-09-19 13:07:17 -07:00
|
|
|
if (aPrefix == nsGkAtoms::_empty)
|
2007-03-22 10:30:00 -07:00
|
|
|
mPrefix = 0;
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool txNameTest::matches(const txXPathNode& aNode, txIMatchContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if ((mNodeType == txXPathNodeType::ELEMENT_NODE &&
|
|
|
|
!txXPathNodeUtils::isElement(aNode)) ||
|
|
|
|
(mNodeType == txXPathNodeType::ATTRIBUTE_NODE &&
|
|
|
|
!txXPathNodeUtils::isAttribute(aNode)) ||
|
|
|
|
(mNodeType == txXPathNodeType::DOCUMENT_NODE &&
|
|
|
|
!txXPathNodeUtils::isRoot(aNode))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Totally wild?
|
2011-09-19 13:07:17 -07:00
|
|
|
if (mLocalName == nsGkAtoms::_asterix && !mPrefix)
|
2011-11-10 11:26:13 -08:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Compare namespaces
|
2009-06-09 00:41:19 -07:00
|
|
|
if (mNamespace != txXPathNodeUtils::getNamespaceID(aNode)
|
|
|
|
&& !(mNamespace == kNameSpaceID_None &&
|
|
|
|
txXPathNodeUtils::isHTMLElementInHTMLDocument(aNode))
|
|
|
|
)
|
2011-11-10 11:26:13 -08:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Name wild?
|
2011-09-19 13:07:17 -07:00
|
|
|
if (mLocalName == nsGkAtoms::_asterix)
|
2011-11-10 11:26:13 -08:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Compare local-names
|
|
|
|
return txXPathNodeUtils::localNameEquals(aNode, mLocalName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the default priority of this txNodeTest
|
|
|
|
*/
|
|
|
|
double txNameTest::getDefaultPriority()
|
|
|
|
{
|
2011-09-19 13:07:17 -07:00
|
|
|
if (mLocalName == nsGkAtoms::_asterix) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mPrefix)
|
|
|
|
return -0.5;
|
|
|
|
return -0.25;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
txNodeTest::NodeTestType
|
|
|
|
txNameTest::getType()
|
|
|
|
{
|
|
|
|
return NAME_TEST;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
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);
|
2014-01-04 07:02:17 -08:00
|
|
|
aDest.Append(char16_t(':'));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
nsAutoString localName;
|
|
|
|
mLocalName->ToString(localName);
|
|
|
|
aDest.Append(localName);
|
|
|
|
}
|
|
|
|
#endif
|