mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Fix for bug 227003 (add ::IsContentOfType to txXPathNode, txNameTest, txNodeTypeTest). r=sicking, sr=bz.
This commit is contained in:
parent
72172ccbd5
commit
43c21802b7
@ -115,7 +115,7 @@ LocationStep::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
|
||||
}
|
||||
case FOLLOWING_AXIS:
|
||||
{
|
||||
if (walker.getNodeType() == txXPathNodeType::ATTRIBUTE_NODE) {
|
||||
if (txXPathNodeUtils::isAttribute(walker.getCurrentPosition())) {
|
||||
walker.moveToParent();
|
||||
fromDescendants(walker.getCurrentPosition(), aContext, nodes);
|
||||
}
|
||||
|
@ -189,28 +189,22 @@ NodeSetFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
|
||||
}
|
||||
case NAME:
|
||||
{
|
||||
switch (txXPathNodeUtils::getNodeType(node)) {
|
||||
case txXPathNodeType::ATTRIBUTE_NODE:
|
||||
case txXPathNodeType::ELEMENT_NODE:
|
||||
case txXPathNodeType::PROCESSING_INSTRUCTION_NODE:
|
||||
// XXX Namespace: namespaces have a name
|
||||
{
|
||||
StringResult* strRes = nsnull;
|
||||
rv = aContext->recycler()->getStringResult(&strRes);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// XXX Namespace: namespaces have a name
|
||||
if (txXPathNodeUtils::isAttribute(node) ||
|
||||
txXPathNodeUtils::isElement(node) ||
|
||||
txXPathNodeUtils::isProcessingInstruction(node)) {
|
||||
StringResult* strRes = nsnull;
|
||||
rv = aContext->recycler()->getStringResult(&strRes);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*aResult = strRes;
|
||||
txXPathNodeUtils::getNodeName(node, strRes->mValue);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
default:
|
||||
{
|
||||
aContext->recycler()->getEmptyStringResult(aResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
*aResult = strRes;
|
||||
txXPathNodeUtils::getNodeName(node, strRes->mValue);
|
||||
}
|
||||
else {
|
||||
aContext->recycler()->getEmptyStringResult(aResult);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
@ -205,12 +205,10 @@ PathExpr::evalDescendants(Expr* aStep, const txXPathNode& aNode,
|
||||
}
|
||||
|
||||
do {
|
||||
if (!(filterWS &&
|
||||
(walker.getNodeType() == txXPathNodeType::TEXT_NODE ||
|
||||
walker.getNodeType() == txXPathNodeType::CDATA_SECTION_NODE) &&
|
||||
txXPathNodeUtils::isWhitespace(walker.getCurrentPosition()))) {
|
||||
rv = evalDescendants(aStep, walker.getCurrentPosition(), aContext,
|
||||
resNodes);
|
||||
const txXPathNode& node = walker.getCurrentPosition();
|
||||
if (!(filterWS && txXPathNodeUtils::isText(node) &&
|
||||
txXPathNodeUtils::isWhitespace(node))) {
|
||||
rv = evalDescendants(aStep, node, aContext, resNodes);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
} while (walker.moveToNextSibling());
|
||||
|
@ -50,6 +50,10 @@ txNameTest::txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID,
|
||||
if (aPrefix == txXMLAtoms::_empty)
|
||||
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");
|
||||
}
|
||||
|
||||
txNameTest::~txNameTest()
|
||||
@ -58,8 +62,14 @@ txNameTest::~txNameTest()
|
||||
|
||||
PRBool txNameTest::matches(const txXPathNode& aNode, txIMatchContext* aContext)
|
||||
{
|
||||
if (txXPathNodeUtils::getNodeType(aNode) != mNodeType)
|
||||
return MB_FALSE;
|
||||
if ((mNodeType == txXPathNodeType::ELEMENT_NODE &&
|
||||
!txXPathNodeUtils::isElement(aNode)) ||
|
||||
(mNodeType == txXPathNodeType::ATTRIBUTE_NODE &&
|
||||
!txXPathNodeUtils::isAttribute(aNode)) ||
|
||||
(mNodeType == txXPathNodeType::DOCUMENT_NODE &&
|
||||
!txXPathNodeUtils::isRoot(aNode))) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// Totally wild?
|
||||
if (mLocalName == txXPathAtoms::_asterix && !mPrefix)
|
||||
@ -74,8 +84,7 @@ PRBool txNameTest::matches(const txXPathNode& aNode, txIMatchContext* aContext)
|
||||
return MB_TRUE;
|
||||
|
||||
// Compare local-names
|
||||
nsCOMPtr<nsIAtom> localName = txXPathNodeUtils::getLocalName(aNode);
|
||||
return localName == mLocalName;
|
||||
return txXPathNodeUtils::localNameEquals(aNode, mLocalName);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -61,29 +61,29 @@ void txNodeTypeTest::setNodeName(const nsAString& aName)
|
||||
PRBool txNodeTypeTest::matches(const txXPathNode& aNode,
|
||||
txIMatchContext* aContext)
|
||||
{
|
||||
PRUint16 type = txXPathNodeUtils::getNodeType(aNode);
|
||||
|
||||
switch (mNodeType) {
|
||||
case COMMENT_TYPE:
|
||||
return type == txXPathNodeType::COMMENT_NODE;
|
||||
{
|
||||
return txXPathNodeUtils::isComment(aNode);
|
||||
}
|
||||
case TEXT_TYPE:
|
||||
return (type == txXPathNodeType::TEXT_NODE ||
|
||||
type == txXPathNodeType::CDATA_SECTION_NODE) &&
|
||||
{
|
||||
return txXPathNodeUtils::isText(aNode) &&
|
||||
!aContext->isStripSpaceAllowed(aNode);
|
||||
}
|
||||
case PI_TYPE:
|
||||
if (type == txXPathNodeType::PROCESSING_INSTRUCTION_NODE) {
|
||||
nsCOMPtr<nsIAtom> localName;
|
||||
return !mNodeName ||
|
||||
((localName = txXPathNodeUtils::getLocalName(aNode)) &&
|
||||
localName == mNodeName);
|
||||
}
|
||||
return MB_FALSE;
|
||||
{
|
||||
return txXPathNodeUtils::isProcessingInstruction(aNode) &&
|
||||
(!mNodeName ||
|
||||
txXPathNodeUtils::localNameEquals(aNode, mNodeName));
|
||||
}
|
||||
case NODE_TYPE:
|
||||
return ((type != txXPathNodeType::TEXT_NODE &&
|
||||
type != txXPathNodeType::CDATA_SECTION_NODE) ||
|
||||
!aContext->isStripSpaceAllowed(aNode));
|
||||
{
|
||||
return !txXPathNodeUtils::isText(aNode) ||
|
||||
!aContext->isStripSpaceAllowed(aNode);
|
||||
}
|
||||
}
|
||||
return MB_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -45,6 +45,7 @@
|
||||
class nsIAtom;
|
||||
|
||||
#ifndef TX_EXE
|
||||
#include "nsINodeInfo.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
class txUint32Array : public nsVoidArray
|
||||
@ -113,8 +114,7 @@ public:
|
||||
static PRBool getAttr(const txXPathNode& aNode, nsIAtom* aLocalName,
|
||||
PRInt32 aNSID, nsAString& aValue);
|
||||
static already_AddRefed<nsIAtom> getLocalName(const txXPathNode& aNode);
|
||||
static void getLocalName(const txXPathNode& aNode,
|
||||
nsAString& aLocalName);
|
||||
static void getLocalName(const txXPathNode& aNode, nsAString& aLocalName);
|
||||
static void getNodeName(const txXPathNode& aNode,
|
||||
nsAString& aName);
|
||||
static PRInt32 getNamespaceID(const txXPathNode& aNode);
|
||||
@ -130,6 +130,14 @@ public:
|
||||
static void getBaseURI(const txXPathNode& aNode, nsAString& aURI);
|
||||
static PRIntn comparePosition(const txXPathNode& aNode,
|
||||
const txXPathNode& aOtherNode);
|
||||
static PRBool localNameEquals(const txXPathNode& aNode,
|
||||
nsIAtom* aLocalName);
|
||||
static PRBool isRoot(const txXPathNode& aNode);
|
||||
static PRBool isElement(const txXPathNode& aNode);
|
||||
static PRBool isAttribute(const txXPathNode& aNode);
|
||||
static PRBool isProcessingInstruction(const txXPathNode& aNode);
|
||||
static PRBool isComment(const txXPathNode& aNode);
|
||||
static PRBool isText(const txXPathNode& aNode);
|
||||
|
||||
#ifdef TX_EXE
|
||||
private:
|
||||
@ -177,12 +185,6 @@ txXPathTreeWalker::getNamespaceID() const
|
||||
return txXPathNodeUtils::getNamespaceID(mPosition);
|
||||
}
|
||||
|
||||
inline PRUint16
|
||||
txXPathTreeWalker::getNodeType() const
|
||||
{
|
||||
return txXPathNodeUtils::getNodeType(mPosition);
|
||||
}
|
||||
|
||||
inline void
|
||||
txXPathTreeWalker::appendNodeValue(nsAString& aResult) const
|
||||
{
|
||||
@ -239,4 +241,99 @@ txXPathNodeUtils::release(txXPathNode* aNode)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */
|
||||
inline PRBool
|
||||
txXPathNodeUtils::localNameEquals(const txXPathNode& aNode,
|
||||
nsIAtom* aLocalName)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
nsCOMPtr<nsIAtom> localName;
|
||||
aNode.mInner->getLocalName(getter_AddRefs(localName));
|
||||
|
||||
return localName == aLocalName;
|
||||
#else
|
||||
if (aNode.isContent()) {
|
||||
nsINodeInfo *ni = aNode.mContent->GetNodeInfo();
|
||||
if (ni) {
|
||||
return ni->Equals(aLocalName);
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAtom> localName = txXPathNodeUtils::getLocalName(aNode);
|
||||
|
||||
return localName == aLocalName;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */
|
||||
inline PRBool
|
||||
txXPathNodeUtils::isRoot(const txXPathNode& aNode)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
return aNode.mInner->getNodeType() == Node::DOCUMENT_NODE;
|
||||
#else
|
||||
return aNode.isDocument();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */
|
||||
inline PRBool
|
||||
txXPathNodeUtils::isElement(const txXPathNode& aNode)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
return aNode.mInner->getNodeType() == Node::ELEMENT_NODE;
|
||||
#else
|
||||
return aNode.isContent() &&
|
||||
aNode.mContent->IsContentOfType(nsIContent::eELEMENT);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* static */
|
||||
inline PRBool
|
||||
txXPathNodeUtils::isAttribute(const txXPathNode& aNode)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
return aNode.mInner->getNodeType() == Node::ATTRIBUTE_NODE;
|
||||
#else
|
||||
return aNode.isAttribute();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */
|
||||
inline PRBool
|
||||
txXPathNodeUtils::isProcessingInstruction(const txXPathNode& aNode)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
return aNode.mInner->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE;
|
||||
#else
|
||||
return aNode.isContent() &&
|
||||
aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */
|
||||
inline PRBool
|
||||
txXPathNodeUtils::isComment(const txXPathNode& aNode)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
return aNode.mInner->getNodeType() == Node::COMMENT_NODE;
|
||||
#else
|
||||
return aNode.isContent() &&
|
||||
aNode.mContent->IsContentOfType(nsIContent::eCOMMENT);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */
|
||||
inline PRBool
|
||||
txXPathNodeUtils::isText(const txXPathNode& aNode)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
return aNode.mInner->getNodeType() == Node::TEXT_NODE;
|
||||
#else
|
||||
return aNode.isContent() &&
|
||||
aNode.mContent->IsContentOfType(nsIContent::eTEXT);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* txXPathTreeWalker_h__ */
|
||||
|
@ -214,25 +214,16 @@ txStylesheet::findTemplate(const txXPathNode& aNode,
|
||||
#endif
|
||||
|
||||
if (!matchTemplate) {
|
||||
switch (txXPathNodeUtils::getNodeType(aNode)) {
|
||||
case txXPathNodeType::ELEMENT_NODE:
|
||||
case txXPathNodeType::DOCUMENT_NODE:
|
||||
{
|
||||
matchTemplate = mContainerTemplate;
|
||||
break;
|
||||
}
|
||||
case txXPathNodeType::ATTRIBUTE_NODE:
|
||||
case txXPathNodeType::TEXT_NODE:
|
||||
case txXPathNodeType::CDATA_SECTION_NODE:
|
||||
{
|
||||
matchTemplate = mCharactersTemplate;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
matchTemplate = mEmptyTemplate;
|
||||
break;
|
||||
}
|
||||
if (txXPathNodeUtils::isElement(aNode) ||
|
||||
txXPathNodeUtils::isRoot(aNode)) {
|
||||
matchTemplate = mContainerTemplate;
|
||||
}
|
||||
else if (txXPathNodeUtils::isAttribute(aNode) ||
|
||||
txXPathNodeUtils::isText(aNode)) {
|
||||
matchTemplate = mCharactersTemplate;
|
||||
}
|
||||
else {
|
||||
matchTemplate = mEmptyTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,21 +276,17 @@ txStylesheet::isStripSpaceAllowed(const txXPathNode& aNode, txIMatchContext* aCo
|
||||
|
||||
txXPathTreeWalker walker(aNode);
|
||||
|
||||
PRUint16 nodeType = walker.getNodeType();
|
||||
if (nodeType == txXPathNodeType::TEXT_NODE ||
|
||||
nodeType == txXPathNodeType::CDATA_SECTION_NODE) {
|
||||
if (!txXPathNodeUtils::isWhitespace(aNode) || !walker.moveToParent()) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
nodeType = walker.getNodeType();
|
||||
}
|
||||
|
||||
if (nodeType != txXPathNodeType::ELEMENT_NODE) {
|
||||
if (txXPathNodeUtils::isText(walker.getCurrentPosition()) &&
|
||||
(!txXPathNodeUtils::isWhitespace(aNode) || !walker.moveToParent())) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
const txXPathNode& node = walker.getCurrentPosition();
|
||||
|
||||
if (!txXPathNodeUtils::isElement(node)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// check Whitespace stipping handling list against given Node
|
||||
PRInt32 i;
|
||||
for (i = 0; i < frameCount; ++i) {
|
||||
|
@ -147,7 +147,8 @@ txXSLTNumber::getValueList(Expr* aValueExpr, txPattern* aCountPattern,
|
||||
if (!aCountPattern) {
|
||||
ownsCountPattern = MB_TRUE;
|
||||
txNodeTest* nodeTest = 0;
|
||||
switch (txXPathNodeUtils::getNodeType(currNode)) {
|
||||
PRUint16 nodeType = txXPathNodeUtils::getNodeType(currNode);
|
||||
switch (nodeType) {
|
||||
case txXPathNodeType::ELEMENT_NODE:
|
||||
{
|
||||
nsCOMPtr<nsIAtom> localName =
|
||||
@ -187,7 +188,7 @@ txXSLTNumber::getValueList(Expr* aValueExpr, txPattern* aCountPattern,
|
||||
// this won't match anything as we walk up the tree
|
||||
// but it's what the spec says to do
|
||||
nodeTest = new txNameTest(0, txXPathAtoms::_asterix, 0,
|
||||
txXPathNodeUtils::getNodeType(currNode));
|
||||
nodeType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ txRootPattern::~txRootPattern()
|
||||
|
||||
MBool txRootPattern::matches(const txXPathNode& aNode, txIMatchContext* aContext)
|
||||
{
|
||||
return (txXPathNodeUtils::getNodeType(aNode) == txXPathNodeType::DOCUMENT_NODE);
|
||||
return txXPathNodeUtils::isRoot(aNode);
|
||||
}
|
||||
|
||||
double txRootPattern::getDefaultPriority()
|
||||
@ -346,8 +346,8 @@ txIdPattern::~txIdPattern()
|
||||
|
||||
MBool txIdPattern::matches(const txXPathNode& aNode, txIMatchContext* aContext)
|
||||
{
|
||||
if (txXPathNodeUtils::getNodeType(aNode) != txXPathNodeType::ELEMENT_NODE) {
|
||||
return MB_FALSE;
|
||||
if (!txXPathNodeUtils::isElement(aNode)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// Get a ID attribute, if there is
|
||||
@ -480,7 +480,8 @@ MBool txStepPattern::matches(const txXPathNode& aNode, txIMatchContext* aContext
|
||||
return MB_FALSE;
|
||||
|
||||
txXPathTreeWalker walker(aNode);
|
||||
if ((!mIsAttr && walker.getNodeType() == txXPathNodeType::ATTRIBUTE_NODE) ||
|
||||
if ((!mIsAttr &&
|
||||
txXPathNodeUtils::isAttribute(walker.getCurrentPosition())) ||
|
||||
!walker.moveToParent()) {
|
||||
return MB_FALSE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user