/* -*- 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/. */ #ifndef nsXULTemplateBuilder_h__ #define nsXULTemplateBuilder_h__ #include "nsStubDocumentObserver.h" #include "nsIScriptSecurityManager.h" #include "nsIObserver.h" #include "nsIRDFCompositeDataSource.h" #include "nsIRDFContainer.h" #include "nsIRDFContainerUtils.h" #include "nsIRDFDataSource.h" #include "nsIRDFObserver.h" #include "nsIRDFService.h" #include "nsIXULTemplateBuilder.h" #include "nsCOMArray.h" #include "nsTArray.h" #include "nsDataHashtable.h" #include "nsTemplateRule.h" #include "nsTemplateMatch.h" #include "nsIXULTemplateQueryProcessor.h" #include "nsCycleCollectionParticipant.h" #include "mozilla/Logging.h" extern mozilla::LazyLogModule gXULTemplateLog; class nsIContent; class nsIObserverService; class nsIRDFCompositeDataSource; /** * An object that translates an RDF graph into a presentation using a * set of rules. */ class nsXULTemplateBuilder : public nsIXULTemplateBuilder, public nsIObserver, public nsStubDocumentObserver { void CleanUp(bool aIsFinal); void DestroyMatchMap(); public: nsXULTemplateBuilder(); nsresult InitGlobals(); /** * Clear the template builder structures. The aIsFinal flag is set to true * when the template is going away. */ virtual void Uninit(bool aIsFinal); // nsISupports interface NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULTemplateBuilder, nsIXULTemplateBuilder) // nsIXULTemplateBuilder interface NS_DECL_NSIXULTEMPLATEBUILDER // nsIObserver Interface NS_DECL_NSIOBSERVER // nsIMutationObserver NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED /** * Remove an old result and/or add a new result. This method will retrieve * the set of containers where the result could be inserted and either add * the new result to those containers, or remove the result from those * containers. UpdateResultInContainer is called for each container. * * @param aOldResult result to remove * @param aNewResult result to add * @param aQueryNode query node for new result */ nsresult UpdateResult(nsIXULTemplateResult* aOldResult, nsIXULTemplateResult* aNewResult, nsIDOMNode* aQueryNode); /** * Remove an old result and/or add a new result from a specific container. * * @param aOldResult result to remove * @param aNewResult result to add * @param aQueryNode queryset for the new result * @param aOldId id of old result * @param aNewId id of new result * @param aInsertionPoint container to remove or add result inside */ nsresult UpdateResultInContainer(nsIXULTemplateResult* aOldResult, nsIXULTemplateResult* aNewResult, nsTemplateQuerySet* aQuerySet, nsIRDFResource* aOldId, nsIRDFResource* aNewId, nsIContent* aInsertionPoint); nsresult ComputeContainmentProperties(); static bool IsTemplateElement(nsIContent* aContent); virtual nsresult RebuildAll() = 0; // must be implemented by subclasses void RunnableRebuild() { Rebuild(); } void RunnableLoadAndRebuild() { Uninit(false); // Reset results nsCOMPtr doc = mRoot ? mRoot->GetComposedDoc() : nullptr; if (doc) { bool shouldDelay; LoadDataSources(doc, &shouldDelay); if (!shouldDelay) { Rebuild(); } } } // mRoot should not be cleared until after Uninit is finished so that // generated content can be removed during uninitialization. void UninitFalse() { Uninit(false); mRoot = nullptr; } void UninitTrue() { Uninit(true); mRoot = nullptr; } /** * Find the