Bug 235866 - add xulelement.builder.refresh and dynamically respond to changes in the datsources="" attribute. r+sr=bryner

This commit is contained in:
bsmedberg%covad.net 2004-03-05 04:32:55 +00:00
parent c990ee123c
commit ebcffc4232
3 changed files with 69 additions and 19 deletions

View File

@ -23,6 +23,7 @@
* Chris Waterson <waterson@netscape.com>
* Ben Goodger <ben@netscape.com>
* Jan Varga <varga@nixcorp.com>
* Benjamin Smedberg <bsmedberg@covad.net>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -48,7 +49,7 @@ interface nsIXULBuilderListener;
[ptr] native nsIContent_ptr(nsIContent);
[scriptable, uuid(fb744f8e-1dd1-11b2-a5d7-935c9ab60602)]
[scriptable, uuid(9da147a7-5854-49e3-a397-22ecdd93e96d)]
interface nsIXULTemplateBuilder : nsISupports
{
/**
@ -67,6 +68,15 @@ interface nsIXULTemplateBuilder : nsISupports
*/
void rebuild();
/**
* Reload any of our RDF datasources that support nsIRDFRemoteDatasource.
*
* @note This is a temporary hack so that remote-XUL authors can
* reload remote datasources. When RDF becomes remote-scriptable,
* this will no longer be necessary.
*/
void refresh();
/**
* Called to initialize a XUL content builder on a particular root
* element. This element presumably has a ``datasources''

View File

@ -88,6 +88,7 @@
#include "nsIScriptGlobalObject.h"
#include "nsIServiceManager.h"
#include "nsISecurityCheckedComponent.h"
#include "nsISimpleEnumerator.h"
#include "nsISupportsArray.h"
#include "nsITimer.h"
#include "nsIURL.h"
@ -243,12 +244,48 @@ nsXULTemplateBuilder::Rebuild()
return rv;
}
NS_IMETHODIMP
nsXULTemplateBuilder::Refresh()
{
nsresult rv;
nsCOMPtr<nsISimpleEnumerator> dslist;
rv = mDB->GetDataSources(getter_AddRefs(dslist));
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasMore;
nsCOMPtr<nsISupports> next;
nsCOMPtr<nsIRDFRemoteDataSource> rds;
while(NS_SUCCEEDED(dslist->HasMoreElements(&hasMore)) && hasMore) {
dslist->GetNext(getter_AddRefs(next));
if (next && (rds = do_QueryInterface(next))) {
rds->Refresh(PR_FALSE);
}
}
return Rebuild();
}
NS_IMETHODIMP
nsXULTemplateBuilder::Init(nsIContent* aElement)
{
NS_PRECONDITION(aElement, "null ptr");
mRoot = aElement;
return LoadDataSources();
nsCOMPtr<nsIDocument> doc = mRoot->GetDocument();
NS_ASSERTION(doc, "element has no document");
if (! doc)
return NS_ERROR_UNEXPECTED;
nsresult rv = LoadDataSources(doc);
if (NS_SUCCEEDED(rv)) {
// Add ourselves as a document observer
doc->AddObserver(this);
}
return rv;
}
NS_IMETHODIMP
@ -289,11 +326,20 @@ nsXULTemplateBuilder::AttributeChanged(nsIDocument *aDocument,
nsIAtom* aAttribute,
PRInt32 aModType)
{
// Check for a change to the 'ref' attribute on an atom, in which
// case we may need to nuke and rebuild the entire content model
// beneath the element.
if ((aAttribute == nsXULAtoms::ref) && (aContent == mRoot))
Rebuild();
if (aContent == mRoot) {
// Check for a change to the 'ref' attribute on an atom, in which
// case we may need to nuke and rebuild the entire content model
// beneath the element.
if (aAttribute == nsXULAtoms::ref)
Rebuild();
// Check for a change to the 'datasources' attribute. If so, setup
// mDB by parsing the vew value and rebuild.
else if (aAttribute == nsXULAtoms::datasources) {
LoadDataSources(aDocument);
Rebuild();
}
}
}
void
@ -609,11 +655,9 @@ nsXULTemplateBuilder::OnEndUpdateBatch(nsIRDFDataSource* aDataSource)
//
nsresult
nsXULTemplateBuilder::LoadDataSources()
nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
{
NS_PRECONDITION(mRoot != nsnull, "not initialized");
if (! mRoot)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
@ -621,6 +665,10 @@ nsXULTemplateBuilder::LoadDataSources()
if (mCache)
mCache = nsnull;
if (mDB) {
mDB->RemoveObserver(this);
}
// create a database for the builder
mDB = do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "composite-datasource");
@ -640,11 +688,6 @@ nsXULTemplateBuilder::LoadDataSources()
if (allowneg == NS_LITERAL_STRING("false"))
mDB->SetAllowNegativeAssertions(PR_FALSE);
nsCOMPtr<nsIDocument> doc = mRoot->GetDocument();
NS_ASSERTION(doc, "element has no document");
if (! doc)
return NS_ERROR_UNEXPECTED;
// Grab the doc's principal...
nsIPrincipal *docPrincipal = doc->GetPrincipal();
if (!docPrincipal)
@ -768,9 +811,6 @@ nsXULTemplateBuilder::LoadDataSources()
// Add ourselves as a datasource observer
mDB->AddObserver(this);
// Add ourselves as a document observer
doc->AddObserver(this);
return NS_OK;
}

View File

@ -240,7 +240,7 @@ public:
void* aClosure);
nsresult
LoadDataSources();
LoadDataSources(nsIDocument* aDoc);
nsresult
InitHTMLTemplateRoot();