Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "nsContentTestNode.h"
7 : #include "nsIRDFResource.h"
8 : #include "nsIAtom.h"
9 : #include "nsIDOMElement.h"
10 : #include "nsXULContentUtils.h"
11 : #include "nsIXULTemplateResult.h"
12 : #include "nsIXULTemplateBuilder.h"
13 : #include "nsXULTemplateQueryProcessorRDF.h"
14 :
15 : #include "mozilla/Logging.h"
16 :
17 : using mozilla::LogLevel;
18 :
19 : extern mozilla::LazyLogModule gXULTemplateLog;
20 :
21 0 : nsContentTestNode::nsContentTestNode(nsXULTemplateQueryProcessorRDF* aProcessor,
22 0 : nsIAtom* aRefVariable)
23 : : TestNode(nullptr),
24 : mProcessor(aProcessor),
25 : mDocument(nullptr),
26 : mRefVariable(aRefVariable),
27 0 : mTag(nullptr)
28 : {
29 0 : if (MOZ_LOG_TEST(gXULTemplateLog, LogLevel::Debug)) {
30 0 : nsAutoString tag(NS_LITERAL_STRING("(none)"));
31 0 : if (mTag)
32 0 : mTag->ToString(tag);
33 :
34 0 : nsAutoString refvar(NS_LITERAL_STRING("(none)"));
35 0 : if (aRefVariable)
36 0 : aRefVariable->ToString(refvar);
37 :
38 0 : MOZ_LOG(gXULTemplateLog, LogLevel::Debug,
39 : ("nsContentTestNode[%p]: ref-var=%s tag=%s",
40 : this, NS_ConvertUTF16toUTF8(refvar).get(),
41 : NS_ConvertUTF16toUTF8(tag).get()));
42 : }
43 0 : }
44 :
45 : nsresult
46 0 : nsContentTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
47 : bool* aCantHandleYet) const
48 :
49 : {
50 0 : if (aCantHandleYet)
51 0 : *aCantHandleYet = false;
52 0 : return NS_OK;
53 : }
54 :
55 : nsresult
56 0 : nsContentTestNode::Constrain(InstantiationSet& aInstantiations)
57 : {
58 : // contrain the matches to those that have matched in the template builder
59 :
60 0 : nsIXULTemplateBuilder* builder = mProcessor->GetBuilder();
61 0 : if (!builder) {
62 0 : aInstantiations.Clear();
63 0 : return NS_OK;
64 : }
65 :
66 : nsresult rv;
67 :
68 0 : InstantiationSet::Iterator last = aInstantiations.Last();
69 0 : for (InstantiationSet::Iterator inst = aInstantiations.First(); inst != last; ++inst) {
70 :
71 0 : nsCOMPtr<nsIRDFNode> refValue;
72 0 : bool hasRefBinding = inst->mAssignments.GetAssignmentFor(mRefVariable,
73 0 : getter_AddRefs(refValue));
74 0 : if (hasRefBinding) {
75 0 : nsCOMPtr<nsIRDFResource> refResource = do_QueryInterface(refValue);
76 0 : if (refResource) {
77 : bool generated;
78 0 : rv = builder->HasGeneratedContent(refResource, mTag, &generated);
79 0 : if (NS_FAILED(rv)) return rv;
80 :
81 0 : if (generated)
82 0 : continue;
83 : }
84 : }
85 :
86 0 : aInstantiations.Erase(inst--);
87 : }
88 :
89 0 : return NS_OK;
90 : }
|