1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/xul/templates/src/nsContentTestNode.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsContentTestNode.h" 1.10 +#include "nsIRDFResource.h" 1.11 +#include "nsIAtom.h" 1.12 +#include "nsIDOMElement.h" 1.13 +#include "nsXULContentUtils.h" 1.14 +#include "nsIXULTemplateResult.h" 1.15 +#include "nsIXULTemplateBuilder.h" 1.16 +#include "nsXULTemplateQueryProcessorRDF.h" 1.17 + 1.18 +#include "prlog.h" 1.19 +#ifdef PR_LOGGING 1.20 +extern PRLogModuleInfo* gXULTemplateLog; 1.21 +#endif 1.22 + 1.23 +nsContentTestNode::nsContentTestNode(nsXULTemplateQueryProcessorRDF* aProcessor, 1.24 + nsIAtom* aRefVariable) 1.25 + : TestNode(nullptr), 1.26 + mProcessor(aProcessor), 1.27 + mDocument(nullptr), 1.28 + mRefVariable(aRefVariable), 1.29 + mTag(nullptr) 1.30 +{ 1.31 +#ifdef PR_LOGGING 1.32 + if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) { 1.33 + nsAutoString tag(NS_LITERAL_STRING("(none)")); 1.34 + if (mTag) 1.35 + mTag->ToString(tag); 1.36 + 1.37 + nsAutoString refvar(NS_LITERAL_STRING("(none)")); 1.38 + if (aRefVariable) 1.39 + aRefVariable->ToString(refvar); 1.40 + 1.41 + PR_LOG(gXULTemplateLog, PR_LOG_DEBUG, 1.42 + ("nsContentTestNode[%p]: ref-var=%s tag=%s", 1.43 + this, NS_ConvertUTF16toUTF8(refvar).get(), 1.44 + NS_ConvertUTF16toUTF8(tag).get())); 1.45 + } 1.46 +#endif 1.47 +} 1.48 + 1.49 +nsresult 1.50 +nsContentTestNode::FilterInstantiations(InstantiationSet& aInstantiations, 1.51 + bool* aCantHandleYet) const 1.52 + 1.53 +{ 1.54 + if (aCantHandleYet) 1.55 + *aCantHandleYet = false; 1.56 + return NS_OK; 1.57 +} 1.58 + 1.59 +nsresult 1.60 +nsContentTestNode::Constrain(InstantiationSet& aInstantiations) 1.61 +{ 1.62 + // contrain the matches to those that have matched in the template builder 1.63 + 1.64 + nsIXULTemplateBuilder* builder = mProcessor->GetBuilder(); 1.65 + if (!builder) { 1.66 + aInstantiations.Clear(); 1.67 + return NS_OK; 1.68 + } 1.69 + 1.70 + nsresult rv; 1.71 + 1.72 + InstantiationSet::Iterator last = aInstantiations.Last(); 1.73 + for (InstantiationSet::Iterator inst = aInstantiations.First(); inst != last; ++inst) { 1.74 + 1.75 + nsCOMPtr<nsIRDFNode> refValue; 1.76 + bool hasRefBinding = inst->mAssignments.GetAssignmentFor(mRefVariable, 1.77 + getter_AddRefs(refValue)); 1.78 + if (hasRefBinding) { 1.79 + nsCOMPtr<nsIRDFResource> refResource = do_QueryInterface(refValue); 1.80 + if (refResource) { 1.81 + bool generated; 1.82 + rv = builder->HasGeneratedContent(refResource, mTag, &generated); 1.83 + if (NS_FAILED(rv)) return rv; 1.84 + 1.85 + if (generated) 1.86 + continue; 1.87 + } 1.88 + } 1.89 + 1.90 + aInstantiations.Erase(inst--); 1.91 + } 1.92 + 1.93 + return NS_OK; 1.94 +}