Bug 86755. Get rid of nsIRDFContentModelBuilder interface, move methods to nsIXULTemplateBuilder; rename |SetRootContent| to |init|. nsXULOutlinerBuilder now implements |init|, allowing us to initialize it with a database, so that we don't have to wait around until frames get created. r=varga@utcru.sc, sr=hyatt

This commit is contained in:
waterson%netscape.com 2002-01-24 21:30:22 +00:00
parent 2b73f18d2a
commit c824244342
14 changed files with 158 additions and 266 deletions

View File

@ -114,7 +114,6 @@ class nsIDocumentLoaderFactory;
#ifdef MOZ_XUL
#include "nsIRDFContentModelBuilder.h"
#include "nsIXULContentSink.h"
#include "nsIXULDocument.h"
#include "nsIXULPopupListener.h"
@ -125,6 +124,12 @@ class nsIDocumentLoaderFactory;
#include "nsXULAtoms.h"
#include "nsXULContentUtils.h"
#include "nsXULElement.h"
extern NS_IMETHODIMP
NS_NewXULContentBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
extern NS_IMETHODIMP
NS_NewXULOutlinerBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
#endif
#ifdef MOZ_SVG

View File

@ -91,7 +91,6 @@
#include "nsIPresShell.h"
#include "nsIPrincipal.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIScriptContext.h"
@ -3543,13 +3542,8 @@ nsXULElement::EnsureContentsGenerated(void) const
if (xulele) {
nsCOMPtr<nsIXULTemplateBuilder> builder;
xulele->GetBuilder(getter_AddRefs(builder));
if (builder) {
nsCOMPtr<nsIRDFContentModelBuilder> contentBuilder =
do_QueryInterface(builder);
if (contentBuilder)
return contentBuilder->CreateContents(NS_STATIC_CAST(nsIStyledContent*, unconstThis));
}
if (builder)
return builder->CreateContents(NS_STATIC_CAST(nsIStyledContent*, unconstThis));
}
nsCOMPtr<nsIContent> parent;

View File

@ -103,7 +103,6 @@
#include "nsIPrivateDOMEvent.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContainerUtils.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIRDFNode.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFService.h"
@ -6377,12 +6376,13 @@ nsXULDocument::CheckTemplateBuilder(nsIContent* aElement)
if (xblService)
xblService->ResolveTag(aElement, &nameSpaceID, getter_AddRefs(baseTag));
// By default, we build content for outliner and then we attach
// the outliner content view.
// Flag "dont-build-content" is used to identify that we shouldn't build
// content and just attach the outliner builder view.
if ((nameSpaceID == kNameSpaceID_XUL) &&
(baseTag.get() == nsXULAtoms::outliner)) {
// By default, we build content for an outliner and then we attach
// the outliner content view. However, if the `dont-build-content'
// flag is set, then we we'll attach an outliner builder which
// directly implements the outliner view.
// XXXwaterson maybe we should do the latter by default: it ought
// to reduce the footprint a great deal.
if ((nameSpaceID == kNameSpaceID_XUL) && (baseTag == nsXULAtoms::outliner)) {
nsAutoString flags;
aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::flags, flags);
if (flags.Find(NS_LITERAL_STRING("dont-build-content").get()) >= 0) {
@ -6392,6 +6392,8 @@ nsXULDocument::CheckTemplateBuilder(nsIContent* aElement)
if (! builder)
return NS_ERROR_FAILURE;
builder->Init(aElement);
// Because the outliner box object won't be created until the
// frame is available, we need to tuck the template builder
// away in the binding manager so there's at least one
@ -6400,14 +6402,21 @@ nsXULDocument::CheckTemplateBuilder(nsIContent* aElement)
if (xuldoc)
xuldoc->SetTemplateBuilderFor(aElement, builder);
// Force an <outlinerchildren> to be created if one isn't
// there already: this is the only way to create an
// <outlinerbody> for the rdfliner.
nsCOMPtr<nsIContent> bodyContent;
nsXULContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, nsXULAtoms::outlinerchildren, getter_AddRefs(bodyContent));
if (!bodyContent) {
nsXULContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL,
nsXULAtoms::outlinerchildren,
getter_AddRefs(bodyContent));
if (! bodyContent) {
nsCOMPtr<nsIDOMDocument> domdoc = do_QueryInterface(doc);
if (domdoc) {
nsCOMPtr<nsIDOMElement> bodyElement;
domdoc->CreateElement(NS_LITERAL_STRING("outlinerchildren"),
getter_AddRefs(bodyElement));
bodyContent = do_QueryInterface(bodyElement);
aElement->AppendChildTo(bodyContent, PR_FALSE, PR_TRUE);
}
@ -6417,13 +6426,14 @@ nsXULDocument::CheckTemplateBuilder(nsIContent* aElement)
}
}
nsCOMPtr<nsIRDFContentModelBuilder> builder
// Create and initialize a content builder.
nsCOMPtr<nsIXULTemplateBuilder> builder
= do_CreateInstance("@mozilla.org/xul/xul-template-builder;1");
if (! builder)
return NS_ERROR_FAILURE;
builder->SetRootContent(aElement);
builder->Init(aElement);
nsCOMPtr<nsIXULContent> xulcontent = do_QueryInterface(aElement);
if (xulcontent) {

View File

@ -1,3 +1,2 @@
nsIRDFContentModelBuilder.h

View File

@ -33,9 +33,5 @@ XPIDLSRCS = \
nsIXULTemplateBuilder.idl \
$(NULL)
EXPORTS = \
nsIRDFContentModelBuilder.h \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -30,9 +30,5 @@ XPIDLSRCS= \
.\nsIXULTemplateBuilder.idl \
$(NULL)
EXPORTS = \
.\nsIRDFContentModelBuilder.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@ -1,84 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
A content model builder interface. An object that implements this
interface is associated with an nsIXULDocument object to construct
an NGLayout content model.
*/
#ifndef nsIRDFContentModelBuilder_h__
#define nsIRDFContentModelBuilder_h__
#include "nsISupports.h"
class nsIContent;
// {541AFCB0-A9A3-11d2-8EC5-00805F29F370}
#define NS_IRDFCONTENTMODELBUILDER_IID \
{ 0x541afcb0, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFContentModelBuilder : public nsISupports
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IRDFCONTENTMODELBUILDER_IID; return iid; }
/**
* Called to initialize a XUL content builder on a particular root
* element. This element presumably has a ``datasources''
* attribute, which the builder will parse to set up the template
* builder's datasources.
*/
NS_IMETHOD SetRootContent(nsIContent* aElement) = 0;
/**
* Invoked lazily by a XUL element that needs its child content
* built.
*/
NS_IMETHOD CreateContents(nsIContent* aElement) = 0;
};
extern NS_IMETHODIMP
NS_NewXULContentBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
extern NS_IMETHODIMP
NS_NewXULOutlinerBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
#endif // nsIRDFContentModelBuilder_h__

View File

@ -43,6 +43,8 @@
#include "nsIRDFCompositeDataSource.idl"
#include "nsIRDFResource.idl"
[ptr] native nsIContent_ptr(nsIContent);
[scriptable, uuid(fb744f8e-1dd1-11b2-a5d7-935c9ab60602)]
interface nsIXULTemplateBuilder : nsISupports
{
@ -61,6 +63,20 @@ interface nsIXULTemplateBuilder : nsISupports
* Force the template builder to rebuild its content.
*/
void rebuild();
/**
* Called to initialize a XUL content builder on a particular root
* element. This element presumably has a ``datasources''
* attribute, which the builder will parse to set up the template
* builder's datasources.
*/
[noscript] void init(in nsIContent_ptr aElement);
/**
* Invoked lazily by a XUL element that needs its child content
* built.
*/
[noscript] void createContents(in nsIContent_ptr aElement);
};
/**

View File

@ -47,7 +47,6 @@
#include "nsIElementFactory.h"
#include "nsINodeInfo.h"
#include "nsIPrincipal.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIServiceManager.h"
#include "nsITextContent.h"
#include "nsIXULContent.h"
@ -127,17 +126,11 @@ IsElementInBuilder(nsIContent *aContent, nsIXULTemplateBuilder *aBuilder)
// nsXULContentBuilder
//
class nsXULContentBuilder : public nsXULTemplateBuilder,
public nsIRDFContentModelBuilder
class nsXULContentBuilder : public nsXULTemplateBuilder
{
public:
NS_DECL_ISUPPORTS_INHERITED
// nsIXULTemplateBuilder interface
NS_IMETHOD Rebuild();
// nsIRDFContentModelBuilder interface
NS_IMETHOD SetRootContent(nsIContent* aElement);
NS_IMETHOD CreateContents(nsIContent* aElement);
// nsIDocumentObserver interface
@ -316,9 +309,6 @@ nsIXULSortService* nsXULContentBuilder::gXULSortService;
nsIElementFactory* nsXULContentBuilder::gHTMLElementFactory;
nsIElementFactory* nsXULContentBuilder::gXMLElementFactory;
NS_IMPL_ISUPPORTS_INHERITED1(nsXULContentBuilder, nsXULTemplateBuilder,
nsIRDFContentModelBuilder)
NS_IMETHODIMP
NS_NewXULContentBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult)
{
@ -1758,24 +1748,6 @@ nsXULContentBuilder::Rebuild()
return Rebuild(mRoot);
}
//----------------------------------------------------------------------
//
// nsIRDFContentModelBuilder methods
//
NS_IMETHODIMP
nsXULContentBuilder::SetRootContent(nsIContent* aElement)
{
NS_PRECONDITION(aElement, "null ptr");
if (! aElement)
return NS_ERROR_NULL_POINTER;
mRoot = aElement;
return LoadDataSources();
}
NS_IMETHODIMP
nsXULContentBuilder::CreateContents(nsIContent* aElement)
{

View File

@ -637,76 +637,63 @@ nsXULOutlinerBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, nsAStri
NS_IMETHODIMP
nsXULOutlinerBuilder::SetOutliner(nsIOutlinerBoxObject* outliner)
{
NS_PRECONDITION(mRoot, "not initialized");
mBoxObject = outliner;
// XXX seems like there's some frame churn going on here, so we'll
// only try to grab the root element if we don't have it
// already. (It better not change!)
nsCOMPtr<nsIDocument> doc;
mRoot->GetDocument(*getter_AddRefs(doc));
NS_ASSERTION(doc, "element has no document");
if (!doc)
return NS_ERROR_UNEXPECTED;
if (! mRoot) {
// Get our root element
nsCOMPtr<nsIBoxObject> boxObject = do_QueryInterface(mBoxObject);
nsCOMPtr<nsIDOMElement> element;
boxObject->GetElement(getter_AddRefs(element));
// Grab the doc's principal...
nsCOMPtr<nsIPrincipal> docPrincipal;
nsresult rv = doc->GetPrincipal(getter_AddRefs(docPrincipal));
if (NS_FAILED(rv))
return rv;
mRoot = do_QueryInterface(element);
PRBool isTrusted = PR_FALSE;
rv = IsSystemPrincipal(docPrincipal.get(), &isTrusted);
if (NS_SUCCEEDED(rv) && isTrusted) {
// Get the datasource we intend to use to remember open state.
nsAutoString datasourceStr;
mRoot->GetAttr(kNameSpaceID_None, nsXULAtoms::statedatasource, datasourceStr);
LoadDataSources();
nsCOMPtr<nsIDocument> doc;
mRoot->GetDocument(*getter_AddRefs(doc));
NS_ASSERTION(doc, "element has no document");
if (!doc)
return NS_ERROR_UNEXPECTED;
// Grab the doc's principal...
nsCOMPtr<nsIPrincipal> docPrincipal;
nsresult rv = doc->GetPrincipal(getter_AddRefs(docPrincipal));
if (NS_FAILED(rv))
return rv;
PRBool isTrusted = PR_FALSE;
rv = IsSystemPrincipal(docPrincipal.get(), &isTrusted);
if (NS_SUCCEEDED(rv) && isTrusted) {
// Get the datasource we intend to use to remember open state.
nsAutoString datasourceStr;
mRoot->GetAttr(kNameSpaceID_None, nsXULAtoms::statedatasource, datasourceStr);
// since we are trusted, use the user specified datasource
// if non specified, use localstore, which gives us
// persistence across sessions
if (!datasourceStr.IsEmpty()) {
gRDFService->GetDataSource(NS_ConvertUCS2toUTF8(datasourceStr).get(),
getter_AddRefs(mPersistStateStore));
}
else {
gRDFService->GetDataSource("rdf:local-store",
getter_AddRefs(mPersistStateStore));
}
// since we are trusted, use the user specified datasource
// if non specified, use localstore, which gives us
// persistence across sessions
if (! datasourceStr.IsEmpty()) {
gRDFService->GetDataSource(NS_ConvertUCS2toUTF8(datasourceStr).get(),
getter_AddRefs(mPersistStateStore));
}
// Either no specific datasource was specified, or we failed
// to get one because we are not trusted.
//
// XXX if it were possible to ``write an arbitrary datasource
// back'', then we could also allow an untrusted document to
// use a statedatasource from the same codebase.
if (! mPersistStateStore) {
mPersistStateStore =
do_CreateInstance("@mozilla.org/rdf/datasource;1?name=in-memory-datasource");
else {
gRDFService->GetDataSource("rdf:local-store",
getter_AddRefs(mPersistStateStore));
}
NS_ASSERTION(mPersistStateStore, "failed to get a persistent state store");
if (! mPersistStateStore)
return NS_ERROR_FAILURE;
Rebuild();
EnsureSortVariables();
if (mSortVariable)
SortSubtree(mRows.GetRoot());
}
// Either no specific datasource was specified, or we failed
// to get one because we are not trusted.
//
// XXX if it were possible to ``write an arbitrary datasource
// back'', then we could also allow an untrusted document to
// use a statedatasource from the same codebase.
if (! mPersistStateStore) {
mPersistStateStore =
do_CreateInstance("@mozilla.org/rdf/datasource;1?name=in-memory-datasource");
}
NS_ASSERTION(mPersistStateStore, "failed to get a persistent state store");
if (! mPersistStateStore)
return NS_ERROR_FAILURE;
Rebuild();
EnsureSortVariables();
if (mSortVariable)
SortSubtree(mRows.GetRoot());
return NS_OK;
}

View File

@ -52,7 +52,6 @@
#include "nsIDOMNode.h"
#include "nsIDocument.h"
#include "nsINameSpaceManager.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFObserver.h"

View File

@ -79,7 +79,6 @@
#include "nsINameSpaceManager.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContainerUtils.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIXULDocument.h"
#include "nsIXULTemplateBuilder.h"
#include "nsIRDFNode.h"
@ -272,6 +271,20 @@ nsXULTemplateBuilder::GetDatabase(nsIRDFCompositeDataSource** aResult)
return NS_OK;
}
NS_IMETHODIMP
nsXULTemplateBuilder::Init(nsIContent* aElement)
{
NS_PRECONDITION(aElement, "null ptr");
mRoot = aElement;
return LoadDataSources();
}
NS_IMETHODIMP
nsXULTemplateBuilder::CreateContents(nsIContent* aElement)
{
return NS_OK;
}
//----------------------------------------------------------------------
//
// nsIDocumentOberver interface

View File

@ -95,6 +95,8 @@ public:
NS_IMETHOD GetRoot(nsIDOMElement** aResult);
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aResult);
NS_IMETHOD Rebuild() = 0; // must be implemented by subclasses
NS_IMETHOD Init(nsIContent* aElement);
NS_IMETHOD CreateContents(nsIContent* aElement);
// nsISecurityCheckedComponent
NS_DECL_NSISECURITYCHECKEDCOMPONENT

View File

@ -637,76 +637,63 @@ nsXULOutlinerBuilder::GetCellText(PRInt32 aRow, const PRUnichar* aColID, nsAStri
NS_IMETHODIMP
nsXULOutlinerBuilder::SetOutliner(nsIOutlinerBoxObject* outliner)
{
NS_PRECONDITION(mRoot, "not initialized");
mBoxObject = outliner;
// XXX seems like there's some frame churn going on here, so we'll
// only try to grab the root element if we don't have it
// already. (It better not change!)
nsCOMPtr<nsIDocument> doc;
mRoot->GetDocument(*getter_AddRefs(doc));
NS_ASSERTION(doc, "element has no document");
if (!doc)
return NS_ERROR_UNEXPECTED;
if (! mRoot) {
// Get our root element
nsCOMPtr<nsIBoxObject> boxObject = do_QueryInterface(mBoxObject);
nsCOMPtr<nsIDOMElement> element;
boxObject->GetElement(getter_AddRefs(element));
// Grab the doc's principal...
nsCOMPtr<nsIPrincipal> docPrincipal;
nsresult rv = doc->GetPrincipal(getter_AddRefs(docPrincipal));
if (NS_FAILED(rv))
return rv;
mRoot = do_QueryInterface(element);
PRBool isTrusted = PR_FALSE;
rv = IsSystemPrincipal(docPrincipal.get(), &isTrusted);
if (NS_SUCCEEDED(rv) && isTrusted) {
// Get the datasource we intend to use to remember open state.
nsAutoString datasourceStr;
mRoot->GetAttr(kNameSpaceID_None, nsXULAtoms::statedatasource, datasourceStr);
LoadDataSources();
nsCOMPtr<nsIDocument> doc;
mRoot->GetDocument(*getter_AddRefs(doc));
NS_ASSERTION(doc, "element has no document");
if (!doc)
return NS_ERROR_UNEXPECTED;
// Grab the doc's principal...
nsCOMPtr<nsIPrincipal> docPrincipal;
nsresult rv = doc->GetPrincipal(getter_AddRefs(docPrincipal));
if (NS_FAILED(rv))
return rv;
PRBool isTrusted = PR_FALSE;
rv = IsSystemPrincipal(docPrincipal.get(), &isTrusted);
if (NS_SUCCEEDED(rv) && isTrusted) {
// Get the datasource we intend to use to remember open state.
nsAutoString datasourceStr;
mRoot->GetAttr(kNameSpaceID_None, nsXULAtoms::statedatasource, datasourceStr);
// since we are trusted, use the user specified datasource
// if non specified, use localstore, which gives us
// persistence across sessions
if (!datasourceStr.IsEmpty()) {
gRDFService->GetDataSource(NS_ConvertUCS2toUTF8(datasourceStr).get(),
getter_AddRefs(mPersistStateStore));
}
else {
gRDFService->GetDataSource("rdf:local-store",
getter_AddRefs(mPersistStateStore));
}
// since we are trusted, use the user specified datasource
// if non specified, use localstore, which gives us
// persistence across sessions
if (! datasourceStr.IsEmpty()) {
gRDFService->GetDataSource(NS_ConvertUCS2toUTF8(datasourceStr).get(),
getter_AddRefs(mPersistStateStore));
}
// Either no specific datasource was specified, or we failed
// to get one because we are not trusted.
//
// XXX if it were possible to ``write an arbitrary datasource
// back'', then we could also allow an untrusted document to
// use a statedatasource from the same codebase.
if (! mPersistStateStore) {
mPersistStateStore =
do_CreateInstance("@mozilla.org/rdf/datasource;1?name=in-memory-datasource");
else {
gRDFService->GetDataSource("rdf:local-store",
getter_AddRefs(mPersistStateStore));
}
NS_ASSERTION(mPersistStateStore, "failed to get a persistent state store");
if (! mPersistStateStore)
return NS_ERROR_FAILURE;
Rebuild();
EnsureSortVariables();
if (mSortVariable)
SortSubtree(mRows.GetRoot());
}
// Either no specific datasource was specified, or we failed
// to get one because we are not trusted.
//
// XXX if it were possible to ``write an arbitrary datasource
// back'', then we could also allow an untrusted document to
// use a statedatasource from the same codebase.
if (! mPersistStateStore) {
mPersistStateStore =
do_CreateInstance("@mozilla.org/rdf/datasource;1?name=in-memory-datasource");
}
NS_ASSERTION(mPersistStateStore, "failed to get a persistent state store");
if (! mPersistStateStore)
return NS_ERROR_FAILURE;
Rebuild();
EnsureSortVariables();
if (mSortVariable)
SortSubtree(mRows.GetRoot());
return NS_OK;
}