content/xul/templates/src/nsContentTestNode.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 "nsContentTestNode.h"
michael@0 7 #include "nsIRDFResource.h"
michael@0 8 #include "nsIAtom.h"
michael@0 9 #include "nsIDOMElement.h"
michael@0 10 #include "nsXULContentUtils.h"
michael@0 11 #include "nsIXULTemplateResult.h"
michael@0 12 #include "nsIXULTemplateBuilder.h"
michael@0 13 #include "nsXULTemplateQueryProcessorRDF.h"
michael@0 14
michael@0 15 #include "prlog.h"
michael@0 16 #ifdef PR_LOGGING
michael@0 17 extern PRLogModuleInfo* gXULTemplateLog;
michael@0 18 #endif
michael@0 19
michael@0 20 nsContentTestNode::nsContentTestNode(nsXULTemplateQueryProcessorRDF* aProcessor,
michael@0 21 nsIAtom* aRefVariable)
michael@0 22 : TestNode(nullptr),
michael@0 23 mProcessor(aProcessor),
michael@0 24 mDocument(nullptr),
michael@0 25 mRefVariable(aRefVariable),
michael@0 26 mTag(nullptr)
michael@0 27 {
michael@0 28 #ifdef PR_LOGGING
michael@0 29 if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
michael@0 30 nsAutoString tag(NS_LITERAL_STRING("(none)"));
michael@0 31 if (mTag)
michael@0 32 mTag->ToString(tag);
michael@0 33
michael@0 34 nsAutoString refvar(NS_LITERAL_STRING("(none)"));
michael@0 35 if (aRefVariable)
michael@0 36 aRefVariable->ToString(refvar);
michael@0 37
michael@0 38 PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
michael@0 39 ("nsContentTestNode[%p]: ref-var=%s tag=%s",
michael@0 40 this, NS_ConvertUTF16toUTF8(refvar).get(),
michael@0 41 NS_ConvertUTF16toUTF8(tag).get()));
michael@0 42 }
michael@0 43 #endif
michael@0 44 }
michael@0 45
michael@0 46 nsresult
michael@0 47 nsContentTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
michael@0 48 bool* aCantHandleYet) const
michael@0 49
michael@0 50 {
michael@0 51 if (aCantHandleYet)
michael@0 52 *aCantHandleYet = false;
michael@0 53 return NS_OK;
michael@0 54 }
michael@0 55
michael@0 56 nsresult
michael@0 57 nsContentTestNode::Constrain(InstantiationSet& aInstantiations)
michael@0 58 {
michael@0 59 // contrain the matches to those that have matched in the template builder
michael@0 60
michael@0 61 nsIXULTemplateBuilder* builder = mProcessor->GetBuilder();
michael@0 62 if (!builder) {
michael@0 63 aInstantiations.Clear();
michael@0 64 return NS_OK;
michael@0 65 }
michael@0 66
michael@0 67 nsresult rv;
michael@0 68
michael@0 69 InstantiationSet::Iterator last = aInstantiations.Last();
michael@0 70 for (InstantiationSet::Iterator inst = aInstantiations.First(); inst != last; ++inst) {
michael@0 71
michael@0 72 nsCOMPtr<nsIRDFNode> refValue;
michael@0 73 bool hasRefBinding = inst->mAssignments.GetAssignmentFor(mRefVariable,
michael@0 74 getter_AddRefs(refValue));
michael@0 75 if (hasRefBinding) {
michael@0 76 nsCOMPtr<nsIRDFResource> refResource = do_QueryInterface(refValue);
michael@0 77 if (refResource) {
michael@0 78 bool generated;
michael@0 79 rv = builder->HasGeneratedContent(refResource, mTag, &generated);
michael@0 80 if (NS_FAILED(rv)) return rv;
michael@0 81
michael@0 82 if (generated)
michael@0 83 continue;
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 aInstantiations.Erase(inst--);
michael@0 88 }
michael@0 89
michael@0 90 return NS_OK;
michael@0 91 }

mercurial