content/xul/templates/src/nsInstantiationNode.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsInstantiationNode.h"
michael@0 7 #include "nsTemplateRule.h"
michael@0 8 #include "nsXULTemplateQueryProcessorRDF.h"
michael@0 9
michael@0 10 #include "prlog.h"
michael@0 11 #ifdef PR_LOGGING
michael@0 12 extern PRLogModuleInfo* gXULTemplateLog;
michael@0 13 #endif
michael@0 14
michael@0 15 nsInstantiationNode::nsInstantiationNode(nsXULTemplateQueryProcessorRDF* aProcessor,
michael@0 16 nsRDFQuery* aQuery)
michael@0 17 : mProcessor(aProcessor),
michael@0 18 mQuery(aQuery)
michael@0 19 {
michael@0 20 #ifdef PR_LOGGING
michael@0 21 PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
michael@0 22 ("nsInstantiationNode[%p] query=%p", this, aQuery));
michael@0 23 #endif
michael@0 24
michael@0 25 MOZ_COUNT_CTOR(nsInstantiationNode);
michael@0 26 }
michael@0 27
michael@0 28
michael@0 29 nsInstantiationNode::~nsInstantiationNode()
michael@0 30 {
michael@0 31 MOZ_COUNT_DTOR(nsInstantiationNode);
michael@0 32 }
michael@0 33
michael@0 34 nsresult
michael@0 35 nsInstantiationNode::Propagate(InstantiationSet& aInstantiations,
michael@0 36 bool aIsUpdate, bool& aTakenInstantiations)
michael@0 37 {
michael@0 38 // In update mode, iterate through the results and call the template
michael@0 39 // builder to update them. In non-update mode, cache them in the processor
michael@0 40 // to be used during processing. The results are cached in the processor
michael@0 41 // so that the simple rules are only computed once. In this situation, all
michael@0 42 // data for all queries are calculated at once.
michael@0 43 nsresult rv = NS_OK;
michael@0 44
michael@0 45 aTakenInstantiations = false;
michael@0 46
michael@0 47 if (aIsUpdate) {
michael@0 48 // Iterate through newly added keys to determine which rules fired.
michael@0 49 //
michael@0 50 // XXXwaterson Unfortunately, this could also lead to retractions;
michael@0 51 // e.g., (container ?a ^empty false) could become "unmatched". How
michael@0 52 // to track those?
michael@0 53 nsCOMPtr<nsIDOMNode> querynode;
michael@0 54 mQuery->GetQueryNode(getter_AddRefs(querynode));
michael@0 55
michael@0 56 InstantiationSet::ConstIterator last = aInstantiations.Last();
michael@0 57 for (InstantiationSet::ConstIterator inst = aInstantiations.First(); inst != last; ++inst) {
michael@0 58 nsAssignmentSet assignments = inst->mAssignments;
michael@0 59
michael@0 60 nsCOMPtr<nsIRDFNode> node;
michael@0 61 assignments.GetAssignmentFor(mQuery->mMemberVariable,
michael@0 62 getter_AddRefs(node));
michael@0 63 if (node) {
michael@0 64 nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(node);
michael@0 65 if (resource) {
michael@0 66 nsRefPtr<nsXULTemplateResultRDF> nextresult =
michael@0 67 new nsXULTemplateResultRDF(mQuery, *inst, resource);
michael@0 68 if (! nextresult)
michael@0 69 return NS_ERROR_OUT_OF_MEMORY;
michael@0 70
michael@0 71 rv = mProcessor->AddMemoryElements(*inst, nextresult);
michael@0 72 if (NS_FAILED(rv))
michael@0 73 return rv;
michael@0 74
michael@0 75 mProcessor->GetBuilder()->AddResult(nextresult, querynode);
michael@0 76 }
michael@0 77 }
michael@0 78 }
michael@0 79 }
michael@0 80 else {
michael@0 81 nsresult rv = mQuery->SetCachedResults(mProcessor, aInstantiations);
michael@0 82 if (NS_SUCCEEDED(rv))
michael@0 83 aTakenInstantiations = true;
michael@0 84 }
michael@0 85
michael@0 86 return rv;
michael@0 87 }

mercurial