summaryrefslogtreecommitdiffstats
path: root/dom/xul/templates/nsXULTemplateResultRDF.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/xul/templates/nsXULTemplateResultRDF.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/xul/templates/nsXULTemplateResultRDF.cpp')
-rw-r--r--dom/xul/templates/nsXULTemplateResultRDF.cpp208
1 files changed, 208 insertions, 0 deletions
diff --git a/dom/xul/templates/nsXULTemplateResultRDF.cpp b/dom/xul/templates/nsXULTemplateResultRDF.cpp
new file mode 100644
index 000000000..9d53bab7d
--- /dev/null
+++ b/dom/xul/templates/nsXULTemplateResultRDF.cpp
@@ -0,0 +1,208 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsXULTemplateResultRDF.h"
+#include "nsXULContentUtils.h"
+
+// XXXndeakin for some reason, making this class have classinfo breaks trees.
+//#include "nsIDOMClassInfo.h"
+
+NS_IMPL_CYCLE_COLLECTION(nsXULTemplateResultRDF, mQuery)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULTemplateResultRDF)
+ NS_INTERFACE_MAP_ENTRY(nsIXULTemplateResult)
+ NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULTemplateResultRDF)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULTemplateResultRDF)
+
+nsXULTemplateResultRDF::nsXULTemplateResultRDF(nsIRDFResource* aNode)
+ : mQuery(nullptr),
+ mNode(aNode)
+{
+}
+
+nsXULTemplateResultRDF::nsXULTemplateResultRDF(nsRDFQuery* aQuery,
+ const Instantiation& aInst,
+ nsIRDFResource *aNode)
+ : mQuery(aQuery),
+ mNode(aNode),
+ mInst(aInst)
+{
+}
+
+nsXULTemplateResultRDF::~nsXULTemplateResultRDF()
+{
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::GetIsContainer(bool* aIsContainer)
+{
+ *aIsContainer = false;
+
+ if (mNode) {
+ nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
+ if (processor)
+ return processor->CheckContainer(mNode, aIsContainer);
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::GetIsEmpty(bool* aIsEmpty)
+{
+ *aIsEmpty = true;
+
+ if (mNode) {
+ nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
+ if (processor)
+ return processor->CheckEmpty(mNode, aIsEmpty);
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::GetMayProcessChildren(bool* aMayProcessChildren)
+{
+ // RDF always allows recursion
+ *aMayProcessChildren = true;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::GetId(nsAString& aId)
+{
+ if (! mNode)
+ return NS_ERROR_FAILURE;
+
+ const char* uri;
+ mNode->GetValueConst(&uri);
+
+ CopyUTF8toUTF16(uri, aId);
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::GetResource(nsIRDFResource** aResource)
+{
+ *aResource = mNode;
+ NS_IF_ADDREF(*aResource);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::GetType(nsAString& aType)
+{
+ aType.Truncate();
+
+ nsresult rv = NS_OK;
+
+ nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
+ if (processor) {
+ bool found;
+ rv = processor->CheckIsSeparator(mNode, &found);
+ if (NS_SUCCEEDED(rv) && found)
+ aType.AssignLiteral("separator");
+ }
+
+ return rv;
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::GetBindingFor(nsIAtom* aVar, nsAString& aValue)
+{
+ nsCOMPtr<nsIRDFNode> val;
+ GetAssignment(aVar, getter_AddRefs(val));
+
+ return nsXULContentUtils::GetTextForNode(val, aValue);
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::GetBindingObjectFor(nsIAtom* aVar, nsISupports** aValue)
+{
+ GetAssignment(aVar, (nsIRDFNode **)aValue);
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::RuleMatched(nsISupports* aQuery, nsIDOMNode* aRuleNode)
+{
+ // when a rule matches, set the bindings that must be used.
+ nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
+ if (processor) {
+ RDFBindingSet* bindings = processor->GetBindingsForRule(aRuleNode);
+ if (bindings) {
+ nsresult rv = mBindingValues.SetBindingSet(bindings);
+ if (NS_FAILED(rv))
+ return rv;
+
+ bindings->AddDependencies(mNode, this);
+ }
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXULTemplateResultRDF::HasBeenRemoved()
+{
+ // when a result is no longer used, clean up the dependencies and
+ // memory elements that refer to it
+ mBindingValues.RemoveDependencies(mNode, this);
+
+ nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
+ if (processor)
+ processor->RemoveMemoryElements(mInst, this);
+
+ return NS_OK;
+}
+
+
+void
+nsXULTemplateResultRDF::GetAssignment(nsIAtom* aVar, nsIRDFNode** aValue)
+{
+ // look up a variable in the assignments map
+ *aValue = nullptr;
+ mInst.mAssignments.GetAssignmentFor(aVar, aValue);
+
+ // if not found, look up the variable in the bindings
+ if (! *aValue)
+ mBindingValues.GetAssignmentFor(this, aVar, aValue);
+}
+
+
+bool
+nsXULTemplateResultRDF::SyncAssignments(nsIRDFResource* aSubject,
+ nsIRDFResource* aPredicate,
+ nsIRDFNode* aTarget)
+{
+ // synchronize the bindings when an assertion is added or removed
+ RDFBindingSet* bindingset = mBindingValues.GetBindingSet();
+ if (bindingset) {
+ return bindingset->SyncAssignments(aSubject, aPredicate, aTarget,
+ (aSubject == mNode) ? mQuery->GetMemberVariable() : nullptr,
+ this, mBindingValues);
+ }
+
+ return false;
+}
+
+bool
+nsXULTemplateResultRDF::HasMemoryElement(const MemoryElement& aMemoryElement)
+{
+ MemoryElementSet::ConstIterator last = mInst.mSupport.Last();
+ for (MemoryElementSet::ConstIterator element = mInst.mSupport.First();
+ element != last; ++element) {
+ if ((*element).Equals(aMemoryElement))
+ return true;
+ }
+
+ return false;
+}