michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsContentTestNode.h" michael@0: #include "nsIRDFResource.h" michael@0: #include "nsIAtom.h" michael@0: #include "nsIDOMElement.h" michael@0: #include "nsXULContentUtils.h" michael@0: #include "nsIXULTemplateResult.h" michael@0: #include "nsIXULTemplateBuilder.h" michael@0: #include "nsXULTemplateQueryProcessorRDF.h" michael@0: michael@0: #include "prlog.h" michael@0: #ifdef PR_LOGGING michael@0: extern PRLogModuleInfo* gXULTemplateLog; michael@0: #endif michael@0: michael@0: nsContentTestNode::nsContentTestNode(nsXULTemplateQueryProcessorRDF* aProcessor, michael@0: nsIAtom* aRefVariable) michael@0: : TestNode(nullptr), michael@0: mProcessor(aProcessor), michael@0: mDocument(nullptr), michael@0: mRefVariable(aRefVariable), michael@0: mTag(nullptr) michael@0: { michael@0: #ifdef PR_LOGGING michael@0: if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) { michael@0: nsAutoString tag(NS_LITERAL_STRING("(none)")); michael@0: if (mTag) michael@0: mTag->ToString(tag); michael@0: michael@0: nsAutoString refvar(NS_LITERAL_STRING("(none)")); michael@0: if (aRefVariable) michael@0: aRefVariable->ToString(refvar); michael@0: michael@0: PR_LOG(gXULTemplateLog, PR_LOG_DEBUG, michael@0: ("nsContentTestNode[%p]: ref-var=%s tag=%s", michael@0: this, NS_ConvertUTF16toUTF8(refvar).get(), michael@0: NS_ConvertUTF16toUTF8(tag).get())); michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: nsresult michael@0: nsContentTestNode::FilterInstantiations(InstantiationSet& aInstantiations, michael@0: bool* aCantHandleYet) const michael@0: michael@0: { michael@0: if (aCantHandleYet) michael@0: *aCantHandleYet = false; michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsContentTestNode::Constrain(InstantiationSet& aInstantiations) michael@0: { michael@0: // contrain the matches to those that have matched in the template builder michael@0: michael@0: nsIXULTemplateBuilder* builder = mProcessor->GetBuilder(); michael@0: if (!builder) { michael@0: aInstantiations.Clear(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult rv; michael@0: michael@0: InstantiationSet::Iterator last = aInstantiations.Last(); michael@0: for (InstantiationSet::Iterator inst = aInstantiations.First(); inst != last; ++inst) { michael@0: michael@0: nsCOMPtr refValue; michael@0: bool hasRefBinding = inst->mAssignments.GetAssignmentFor(mRefVariable, michael@0: getter_AddRefs(refValue)); michael@0: if (hasRefBinding) { michael@0: nsCOMPtr refResource = do_QueryInterface(refValue); michael@0: if (refResource) { michael@0: bool generated; michael@0: rv = builder->HasGeneratedContent(refResource, mTag, &generated); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: if (generated) michael@0: continue; michael@0: } michael@0: } michael@0: michael@0: aInstantiations.Erase(inst--); michael@0: } michael@0: michael@0: return NS_OK; michael@0: }