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