From 12171c55aa6408a4925f9ff81daaeb8b96bd257f Mon Sep 17 00:00:00 2001 From: "enndeakin%sympatico.ca" Date: Mon, 27 Mar 2006 13:53:27 +0000 Subject: [PATCH] bug 330660, when constraining, skip underspecified items and do them later. This make certain more complex templates update properly. r+sr=bz git-svn-id: svn://10.0.0.236/trunk@193035 18797224-902f-48f8-a5cc-f745e15eee43 --- .../xul/templates/src/nsContentTestNode.cpp | 6 +++++- .../xul/templates/src/nsContentTestNode.h | 4 ++-- .../templates/src/nsRDFConInstanceTestNode.cpp | 6 +++++- .../templates/src/nsRDFConInstanceTestNode.h | 3 ++- .../templates/src/nsRDFConMemberTestNode.cpp | 14 +++++++++++--- .../xul/templates/src/nsRDFConMemberTestNode.h | 3 ++- .../templates/src/nsRDFPropertyTestNode.cpp | 16 ++++++++++++---- .../xul/templates/src/nsRDFPropertyTestNode.h | 3 ++- .../xul/templates/src/nsRuleNetwork.cpp | 18 ++++++++++++++---- .../content/xul/templates/src/nsRuleNetwork.h | 8 ++++++-- 10 files changed, 61 insertions(+), 20 deletions(-) diff --git a/mozilla/content/xul/templates/src/nsContentTestNode.cpp b/mozilla/content/xul/templates/src/nsContentTestNode.cpp index 76ac6ad8d74..2a9b05c90b5 100644 --- a/mozilla/content/xul/templates/src/nsContentTestNode.cpp +++ b/mozilla/content/xul/templates/src/nsContentTestNode.cpp @@ -79,8 +79,12 @@ nsContentTestNode::nsContentTestNode(nsXULTemplateQueryProcessorRDF* aProcessor, } nsresult -nsContentTestNode::FilterInstantiations(InstantiationSet& aInstantiations) const +nsContentTestNode::FilterInstantiations(InstantiationSet& aInstantiations, + PRBool* aCantHandleYet) const + { + if (aCantHandleYet) + *aCantHandleYet = PR_FALSE; return NS_OK; } diff --git a/mozilla/content/xul/templates/src/nsContentTestNode.h b/mozilla/content/xul/templates/src/nsContentTestNode.h index 48b41beaa95..98b88ed060e 100644 --- a/mozilla/content/xul/templates/src/nsContentTestNode.h +++ b/mozilla/content/xul/templates/src/nsContentTestNode.h @@ -58,8 +58,8 @@ public: nsContentTestNode(nsXULTemplateQueryProcessorRDF* aProcessor, nsIAtom* aContentVariable); - virtual nsresult - FilterInstantiations(InstantiationSet& aInstantiations) const; + virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations, + PRBool* aCantHandleYet) const; nsresult Constrain(InstantiationSet& aInstantiations); diff --git a/mozilla/content/xul/templates/src/nsRDFConInstanceTestNode.cpp b/mozilla/content/xul/templates/src/nsRDFConInstanceTestNode.cpp index fe6c5d8cdf1..453e9a495b2 100644 --- a/mozilla/content/xul/templates/src/nsRDFConInstanceTestNode.cpp +++ b/mozilla/content/xul/templates/src/nsRDFConInstanceTestNode.cpp @@ -107,10 +107,14 @@ nsRDFConInstanceTestNode::nsRDFConInstanceTestNode(TestNode* aParent, } nsresult -nsRDFConInstanceTestNode::FilterInstantiations(InstantiationSet& aInstantiations) const +nsRDFConInstanceTestNode::FilterInstantiations(InstantiationSet& aInstantiations, + PRBool* aCantHandleYet) const { nsresult rv; + if (aCantHandleYet) + *aCantHandleYet = PR_FALSE; + nsCOMPtr rdfc = do_GetService("@mozilla.org/rdf/container-utils;1"); diff --git a/mozilla/content/xul/templates/src/nsRDFConInstanceTestNode.h b/mozilla/content/xul/templates/src/nsRDFConInstanceTestNode.h index 74b4a72d5b8..05ef3e87992 100644 --- a/mozilla/content/xul/templates/src/nsRDFConInstanceTestNode.h +++ b/mozilla/content/xul/templates/src/nsRDFConInstanceTestNode.h @@ -61,7 +61,8 @@ public: Test aContainer, Test aEmpty); - virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations) const; + virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations, + PRBool* aCantHandleYet) const; virtual PRBool CanPropagate(nsIRDFResource* aSource, diff --git a/mozilla/content/xul/templates/src/nsRDFConMemberTestNode.cpp b/mozilla/content/xul/templates/src/nsRDFConMemberTestNode.cpp index 70877199c30..d5dbe1be2d5 100644 --- a/mozilla/content/xul/templates/src/nsRDFConMemberTestNode.cpp +++ b/mozilla/content/xul/templates/src/nsRDFConMemberTestNode.cpp @@ -98,11 +98,15 @@ nsRDFConMemberTestNode::nsRDFConMemberTestNode(TestNode* aParent, } nsresult -nsRDFConMemberTestNode::FilterInstantiations(InstantiationSet& aInstantiations) const +nsRDFConMemberTestNode::FilterInstantiations(InstantiationSet& aInstantiations, + PRBool* aCantHandleYet) const { // XXX Uh, factor me, please! nsresult rv; + if (aCantHandleYet) + *aCantHandleYet = PR_FALSE; + nsCOMPtr rdfc = do_GetService("@mozilla.org/rdf/container-utils;1"); @@ -476,8 +480,12 @@ nsRDFConMemberTestNode::FilterInstantiations(InstantiationSet& aInstantiations) if (! hasContainerBinding && ! hasMemberBinding) { // Neither container nor member assignment! - NS_ERROR("can't do open ended queries like that!"); - return NS_ERROR_UNEXPECTED; + if (!aCantHandleYet) { + return NS_ERROR_UNEXPECTED; + } + + *aCantHandleYet = PR_TRUE; + return NS_OK; } // finally, remove the "under specified" instantiation. diff --git a/mozilla/content/xul/templates/src/nsRDFConMemberTestNode.h b/mozilla/content/xul/templates/src/nsRDFConMemberTestNode.h index f49ed93c7c5..b21fd06df59 100644 --- a/mozilla/content/xul/templates/src/nsRDFConMemberTestNode.h +++ b/mozilla/content/xul/templates/src/nsRDFConMemberTestNode.h @@ -57,7 +57,8 @@ public: nsIAtom* aContainerVariable, nsIAtom* aMemberVariable); - virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations) const; + virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations, + PRBool* aCantHandleYet) const; virtual PRBool CanPropagate(nsIRDFResource* aSource, diff --git a/mozilla/content/xul/templates/src/nsRDFPropertyTestNode.cpp b/mozilla/content/xul/templates/src/nsRDFPropertyTestNode.cpp index a35b1983cd0..5989e6e58b7 100644 --- a/mozilla/content/xul/templates/src/nsRDFPropertyTestNode.cpp +++ b/mozilla/content/xul/templates/src/nsRDFPropertyTestNode.cpp @@ -151,10 +151,14 @@ nsRDFPropertyTestNode::nsRDFPropertyTestNode(TestNode* aParent, nsresult -nsRDFPropertyTestNode::FilterInstantiations(InstantiationSet& aInstantiations) const +nsRDFPropertyTestNode::FilterInstantiations(InstantiationSet& aInstantiations, + PRBool* aCantHandleYet) const { nsresult rv; + if (aCantHandleYet) + *aCantHandleYet = PR_FALSE; + nsIRDFDataSource* ds = mProcessor->GetDataSource(); InstantiationSet::Iterator last = aInstantiations.Last(); @@ -333,9 +337,13 @@ nsRDFPropertyTestNode::FilterInstantiations(InstantiationSet& aInstantiations) c aInstantiations.Erase(inst--); } else { - // Neither source nor target assignment! - NS_ERROR("can't do open ended queries like that!"); - return NS_ERROR_UNEXPECTED; + if (!aCantHandleYet) { + // Neither source nor target assignment! + return NS_ERROR_UNEXPECTED; + } + + *aCantHandleYet = PR_TRUE; + return NS_OK; } } diff --git a/mozilla/content/xul/templates/src/nsRDFPropertyTestNode.h b/mozilla/content/xul/templates/src/nsRDFPropertyTestNode.h index 832e1084deb..0999cc3d66c 100644 --- a/mozilla/content/xul/templates/src/nsRDFPropertyTestNode.h +++ b/mozilla/content/xul/templates/src/nsRDFPropertyTestNode.h @@ -75,7 +75,8 @@ public: nsIRDFResource* aProperty, nsIRDFNode* aTarget); - virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations) const; + virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations, + PRBool* aCantHandleYet) const; virtual PRBool CanPropagate(nsIRDFResource* aSource, diff --git a/mozilla/content/xul/templates/src/nsRuleNetwork.cpp b/mozilla/content/xul/templates/src/nsRuleNetwork.cpp index 79def402608..ce452e9583a 100644 --- a/mozilla/content/xul/templates/src/nsRuleNetwork.cpp +++ b/mozilla/content/xul/templates/src/nsRuleNetwork.cpp @@ -337,7 +337,7 @@ TestNode::Propagate(InstantiationSet& aInstantiations, aTakenInstantiations = PR_FALSE; - nsresult rv = FilterInstantiations(aInstantiations); + nsresult rv = FilterInstantiations(aInstantiations, nsnull); if (NS_FAILED(rv)) return rv; @@ -390,17 +390,27 @@ TestNode::Constrain(InstantiationSet& aInstantiations) PR_LOG(gXULTemplateLog, PR_LOG_DEBUG, ("TestNode[%p]: Constrain() begin", this)); - rv = FilterInstantiations(aInstantiations); + // if the cantHandleYet flag is set by FilterInstantiations, + // there isn't enough information yet available to fill in. + // For this, continue the constrain all the way to the top + // and then call FilterInstantiations again afterwards. This + // should fill in any missing information. + PRBool cantHandleYet = PR_FALSE; + rv = FilterInstantiations(aInstantiations, &cantHandleYet); if (NS_FAILED(rv)) return rv; - if (mParent && ! aInstantiations.Empty()) { - // if we still have instantiations, then ride 'em on up to the + if ((mParent && ! aInstantiations.Empty()) || cantHandleYet) { + // if we still have instantiations, or if the instantiations + // could not be filled in yet, then ride 'em on up to the // parent to narrow them. PR_LOG(gXULTemplateLog, PR_LOG_DEBUG, ("TestNode[%p]: Constrain() passing to parent %p", this, mParent)); rv = mParent->Constrain(aInstantiations); + + if (NS_SUCCEEDED(rv) && cantHandleYet) + rv = FilterInstantiations(aInstantiations, nsnull); } else { PR_LOG(gXULTemplateLog, PR_LOG_DEBUG, diff --git a/mozilla/content/xul/templates/src/nsRuleNetwork.h b/mozilla/content/xul/templates/src/nsRuleNetwork.h index c55a506b4e8..e553a589f8d 100644 --- a/mozilla/content/xul/templates/src/nsRuleNetwork.h +++ b/mozilla/content/xul/templates/src/nsRuleNetwork.h @@ -868,10 +868,14 @@ public: * those which do pass the test node's test. * * @param aInstantiations the set of instantiations to be - * filtered + * filtered + * @param aCantHandleYet [out] true if the instantiations do not contain + * enough information to constrain the data. May be null if this + * isn't important to the caller. * @return NS_OK if no errors occurred. */ - virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations) const = 0; + virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations, + PRBool* aCantHandleYet) const = 0; //XXX probably better named "ApplyConstraints" or "Discrminiate" or something /**