1998-12-24 05:07:14 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (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 Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
1999-01-05 21:57:59 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
An implementation for the nsIRDFDocument interface. This
|
|
|
|
implementation serves as the basis for generating an NGLayout
|
|
|
|
content model.
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
TO DO
|
|
|
|
|
|
|
|
1) Figure out how to get rid of the DummyListener hack.
|
|
|
|
|
1999-01-05 21:57:59 +00:00
|
|
|
*/
|
|
|
|
|
1999-02-01 22:34:51 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIArena.h"
|
|
|
|
#include "nsIContent.h"
|
1999-01-14 10:55:08 +00:00
|
|
|
#include "nsICSSParser.h"
|
|
|
|
#include "nsICSSStyleSheet.h"
|
1999-02-17 11:09:57 +00:00
|
|
|
#include "nsIDOMElementObserver.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIDOMNodeObserver.h"
|
|
|
|
#include "nsIDOMScriptObjectFactory.h"
|
|
|
|
#include "nsIDOMStyleSheetCollection.h"
|
1999-02-17 11:09:57 +00:00
|
|
|
#include "nsIDOMXULDocument.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIDTD.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIDocument.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIDocumentObserver.h"
|
1999-02-04 10:50:50 +00:00
|
|
|
#include "nsIHTMLContentContainer.h"
|
|
|
|
#include "nsIHTMLCSSStyleSheet.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIHTMLStyleSheet.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIJSScriptObject.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIParser.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
1999-01-20 01:42:13 +00:00
|
|
|
#include "nsIRDFCompositeDataSource.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIRDFContentModelBuilder.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIRDFCursor.h"
|
|
|
|
#include "nsIRDFDataSource.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIRDFDocument.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIRDFNode.h"
|
1999-01-05 03:53:15 +00:00
|
|
|
#include "nsIRDFService.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIScriptContextOwner.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIScriptObjectOwner.h"
|
1999-02-11 23:12:28 +00:00
|
|
|
#include "nsIDOMSelection.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsIStyleSheet.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsISupportsArray.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIURLGroup.h"
|
|
|
|
#include "nsIWebShell.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIXULContentSink.h"
|
1999-02-17 18:33:33 +00:00
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsIXMLContent.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsDOMCID.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsParserCIID.h"
|
1998-12-24 06:22:21 +00:00
|
|
|
#include "nsRDFCID.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsRDFDOMNodeList.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "plhash.h"
|
1999-02-03 02:48:55 +00:00
|
|
|
#include "plstr.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "rdfutil.h"
|
|
|
|
|
1999-02-23 03:31:26 +00:00
|
|
|
|
|
|
|
#include "nsILineBreakerFactory.h"
|
|
|
|
#include "nsLWBrkCIID.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
static NS_DEFINE_IID(kICSSParserIID, NS_ICSS_PARSER_IID); // XXX grr..
|
1998-12-24 05:07:14 +00:00
|
|
|
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
|
1999-02-16 19:30:04 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMScriptObjectFactoryIID, NS_IDOM_SCRIPT_OBJECT_FACTORY_IID);
|
1998-12-24 05:07:14 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
1999-02-04 10:50:50 +00:00
|
|
|
static NS_DEFINE_IID(kIHTMLContentContainerIID, NS_IHTMLCONTENTCONTAINER_IID);
|
1998-12-24 05:07:14 +00:00
|
|
|
static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID);
|
1999-03-05 00:01:26 +00:00
|
|
|
static NS_DEFINE_IID(kIHTMLCSSStyleSheetIID, NS_IHTML_CSS_STYLE_SHEET_IID);
|
1999-02-16 19:30:04 +00:00
|
|
|
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
1998-12-24 05:07:14 +00:00
|
|
|
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
|
|
|
|
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
|
|
|
|
static NS_DEFINE_IID(kIPresShellIID, NS_IPRESSHELL_IID);
|
1999-01-20 01:42:13 +00:00
|
|
|
static NS_DEFINE_IID(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID);
|
1999-02-01 22:34:51 +00:00
|
|
|
static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID);
|
1998-12-24 05:07:14 +00:00
|
|
|
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
|
|
|
static NS_DEFINE_IID(kIRDFDocumentIID, NS_IRDFDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
|
|
|
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
1999-01-05 03:53:15 +00:00
|
|
|
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
1999-02-16 19:30:04 +00:00
|
|
|
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
1999-02-11 23:12:28 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
|
1998-12-24 05:07:14 +00:00
|
|
|
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
1999-01-14 10:55:08 +00:00
|
|
|
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
1998-12-24 05:07:14 +00:00
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
|
|
|
|
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
|
1999-02-16 19:30:04 +00:00
|
|
|
static NS_DEFINE_IID(kIXULContentSinkIID, NS_IXULCONTENTSINK_IID);
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
|
1999-02-16 19:30:04 +00:00
|
|
|
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
|
1999-01-05 03:53:15 +00:00
|
|
|
static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID);
|
1999-03-05 00:01:26 +00:00
|
|
|
static NS_DEFINE_CID(kHTMLCSSStyleSheetCID, NS_HTML_CSS_STYLESHEET_CID);
|
1999-01-05 03:53:15 +00:00
|
|
|
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
|
|
|
static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX
|
|
|
|
static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID);
|
1999-02-16 19:30:04 +00:00
|
|
|
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
|
1999-01-05 03:53:15 +00:00
|
|
|
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
1999-01-20 01:42:13 +00:00
|
|
|
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
1999-02-16 19:30:04 +00:00
|
|
|
static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID);
|
1999-01-05 03:53:15 +00:00
|
|
|
static NS_DEFINE_CID(kRangeListCID, NS_RANGELIST_CID);
|
|
|
|
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
1999-02-16 19:30:04 +00:00
|
|
|
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
|
|
|
|
static NS_DEFINE_CID(kXULDataSourceCID, NS_XULDATASOURCE_CID);
|
1999-02-03 02:48:55 +00:00
|
|
|
|
1999-02-23 03:31:26 +00:00
|
|
|
static NS_DEFINE_IID(kLWBrkCID, NS_LWBRK_CID);
|
|
|
|
static NS_DEFINE_IID(kILineBreakerFactoryIID, NS_ILINEBREAKERFACTORY_IID);
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
1999-02-09 03:15:41 +00:00
|
|
|
// nsElementMap
|
|
|
|
|
|
|
|
class nsElementMap
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
PLHashTable* mResources;
|
|
|
|
|
|
|
|
class ContentListItem {
|
|
|
|
public:
|
|
|
|
ContentListItem(nsIContent* aContent)
|
|
|
|
: mNext(nsnull), mContent(aContent) {}
|
|
|
|
|
|
|
|
ContentListItem* mNext;
|
|
|
|
nsIContent* mContent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PLHashNumber
|
|
|
|
HashPointer(const void* key)
|
|
|
|
{
|
|
|
|
return (PLHashNumber) key;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRIntn
|
|
|
|
ReleaseContentList(PLHashEntry* he, PRIntn index, void* closure)
|
|
|
|
{
|
|
|
|
ContentListItem* head =
|
|
|
|
(ContentListItem*) he->value;
|
|
|
|
|
|
|
|
while (head) {
|
|
|
|
ContentListItem* doomed = head;
|
|
|
|
head = head->mNext;
|
|
|
|
delete doomed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
nsElementMap(void)
|
|
|
|
{
|
|
|
|
// Create a table for mapping RDF resources to elements in the
|
|
|
|
// content tree.
|
|
|
|
static PRInt32 kInitialResourceTableSize = 1023;
|
|
|
|
if ((mResources = PL_NewHashTable(kInitialResourceTableSize,
|
|
|
|
HashPointer,
|
|
|
|
PL_CompareValues,
|
|
|
|
PL_CompareValues,
|
|
|
|
nsnull,
|
|
|
|
nsnull)) == nsnull) {
|
|
|
|
NS_ERROR("could not create hash table for resources");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsElementMap()
|
|
|
|
{
|
|
|
|
if (mResources) {
|
|
|
|
PL_HashTableEnumerateEntries(mResources, ReleaseContentList, nsnull);
|
|
|
|
PL_HashTableDestroy(mResources);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Add(nsIRDFResource* aResource, nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mResources != nsnull, "not initialized");
|
|
|
|
if (! mResources)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
ContentListItem* head =
|
|
|
|
(ContentListItem*) PL_HashTableLookup(mResources, aResource);
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
if (! head) {
|
|
|
|
head = new ContentListItem(aContent);
|
|
|
|
if (! head)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PL_HashTableAdd(mResources, aResource, head);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (1) {
|
|
|
|
if (head->mContent == aContent) {
|
|
|
|
NS_ERROR("attempt to add same element twice");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
if (! head->mNext)
|
|
|
|
break;
|
|
|
|
|
|
|
|
head = head->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
head->mNext = new ContentListItem(aContent);
|
|
|
|
if (! head->mNext)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Remove(nsIRDFResource* aResource, nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mResources != nsnull, "not initialized");
|
|
|
|
if (! mResources)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
ContentListItem* head =
|
|
|
|
(ContentListItem*) PL_HashTableLookup(mResources, aResource);
|
|
|
|
|
|
|
|
if (head) {
|
|
|
|
if (head->mContent == aContent) {
|
|
|
|
ContentListItem* newHead = head->mNext;
|
|
|
|
if (newHead) {
|
|
|
|
PL_HashTableAdd(mResources, aResource, newHead);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PL_HashTableRemove(mResources, aResource);
|
|
|
|
}
|
|
|
|
delete head;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ContentListItem* doomed = head->mNext;
|
|
|
|
while (doomed) {
|
|
|
|
if (doomed->mContent == aContent) {
|
|
|
|
head->mNext = doomed->mNext;
|
|
|
|
delete doomed;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
head = doomed;
|
|
|
|
doomed = doomed->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ERROR("attempt to remove an element that was never added");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Find(nsIRDFResource* aResource, nsISupportsArray* aResults)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mResources != nsnull, "not initialized");
|
|
|
|
if (! mResources)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
aResults->Clear();
|
|
|
|
ContentListItem* head =
|
|
|
|
(ContentListItem*) PL_HashTableLookup(mResources, aResource);
|
|
|
|
|
|
|
|
while (head) {
|
|
|
|
aResults->AppendElement(head->mContent);
|
|
|
|
head = head->mNext;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// XULDocumentImpl
|
|
|
|
|
|
|
|
class XULDocumentImpl : public nsIDocument,
|
1999-01-12 19:41:06 +00:00
|
|
|
public nsIRDFDocument,
|
1999-02-17 11:09:57 +00:00
|
|
|
public nsIDOMXULDocument,
|
1999-02-16 19:30:04 +00:00
|
|
|
public nsIJSScriptObject,
|
|
|
|
public nsIScriptObjectOwner,
|
|
|
|
public nsIHTMLContentContainer,
|
1999-02-17 11:09:57 +00:00
|
|
|
public nsIDOMNodeObserver,
|
|
|
|
public nsIDOMElementObserver
|
1999-01-12 19:41:06 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl();
|
|
|
|
virtual ~XULDocumentImpl();
|
1999-01-12 19:41:06 +00:00
|
|
|
|
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDocument interface
|
|
|
|
virtual nsIArena* GetArena();
|
|
|
|
|
|
|
|
NS_IMETHOD StartDocumentLoad(nsIURL *aUrl,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener **aDocListener,
|
|
|
|
const char* aCommand);
|
|
|
|
|
|
|
|
virtual const nsString* GetDocumentTitle() const;
|
|
|
|
|
|
|
|
virtual nsIURL* GetDocumentURL() const;
|
|
|
|
|
|
|
|
virtual nsIURLGroup* GetDocumentURLGroup() const;
|
|
|
|
|
1999-01-15 01:53:50 +00:00
|
|
|
NS_IMETHOD GetBaseURL(nsIURL*& aURL) const;
|
|
|
|
|
1999-01-25 16:05:04 +00:00
|
|
|
virtual nsString* GetDocumentCharacterSet() const;
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-01-25 16:05:04 +00:00
|
|
|
virtual void SetDocumentCharacterSet(nsString* aCharSetID);
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-23 03:31:26 +00:00
|
|
|
NS_IMETHOD GetLineBreaker(nsILineBreaker** aResult) ;
|
|
|
|
NS_IMETHOD SetLineBreaker(nsILineBreaker* aLineBreaker) ;
|
|
|
|
|
1999-01-23 06:59:35 +00:00
|
|
|
NS_IMETHOD GetHeaderData(nsIAtom* aHeaderField, nsString& aData) const;
|
|
|
|
NS_IMETHOD SetHeaderData(nsIAtom* aheaderField, const nsString& aData);
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
virtual nsresult CreateShell(nsIPresContext* aContext,
|
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIStyleSet* aStyleSet,
|
|
|
|
nsIPresShell** aInstancePtrResult);
|
|
|
|
|
|
|
|
virtual PRBool DeleteShell(nsIPresShell* aShell);
|
|
|
|
|
|
|
|
virtual PRInt32 GetNumberOfShells();
|
|
|
|
|
|
|
|
virtual nsIPresShell* GetShellAt(PRInt32 aIndex);
|
|
|
|
|
|
|
|
virtual nsIDocument* GetParentDocument();
|
|
|
|
|
|
|
|
virtual void SetParentDocument(nsIDocument* aParent);
|
|
|
|
|
|
|
|
virtual void AddSubDocument(nsIDocument* aSubDoc);
|
|
|
|
|
|
|
|
virtual PRInt32 GetNumberOfSubDocuments();
|
|
|
|
|
|
|
|
virtual nsIDocument* GetSubDocumentAt(PRInt32 aIndex);
|
|
|
|
|
|
|
|
virtual nsIContent* GetRootContent();
|
|
|
|
|
|
|
|
virtual void SetRootContent(nsIContent* aRoot);
|
|
|
|
|
|
|
|
virtual PRInt32 GetNumberOfStyleSheets();
|
|
|
|
|
|
|
|
virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex);
|
|
|
|
|
1999-01-23 06:59:35 +00:00
|
|
|
virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
virtual void AddStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
|
|
|
|
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
|
|
|
|
PRBool mDisabled);
|
|
|
|
|
|
|
|
virtual nsIScriptContextOwner *GetScriptContextOwner();
|
|
|
|
|
|
|
|
virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner);
|
|
|
|
|
|
|
|
NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager);
|
|
|
|
|
|
|
|
virtual void AddObserver(nsIDocumentObserver* aObserver);
|
|
|
|
|
|
|
|
virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver);
|
|
|
|
|
|
|
|
NS_IMETHOD BeginLoad();
|
|
|
|
|
|
|
|
NS_IMETHOD EndLoad();
|
|
|
|
|
|
|
|
NS_IMETHOD ContentChanged(nsIContent* aContent,
|
|
|
|
nsISupports* aSubContent);
|
|
|
|
|
1999-02-27 07:15:09 +00:00
|
|
|
NS_IMETHOD ContentStateChanged(nsIContent* aContent);
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
NS_IMETHOD AttributeChanged(nsIContent* aChild,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint); // See nsStyleConsts fot hint values
|
|
|
|
|
|
|
|
NS_IMETHOD ContentAppended(nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer);
|
|
|
|
|
|
|
|
NS_IMETHOD ContentInserted(nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
|
|
|
|
NS_IMETHOD ContentReplaced(nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
|
|
|
|
NS_IMETHOD ContentRemoved(nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
|
|
|
|
NS_IMETHOD StyleRuleChanged(nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint); // See nsStyleConsts fot hint values
|
|
|
|
|
|
|
|
NS_IMETHOD StyleRuleAdded(nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
|
|
|
|
|
|
|
NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
|
|
|
|
1999-02-11 23:12:28 +00:00
|
|
|
NS_IMETHOD GetSelection(nsIDOMSelection** aSelection);
|
1999-01-12 19:41:06 +00:00
|
|
|
|
|
|
|
NS_IMETHOD SelectAll();
|
|
|
|
|
|
|
|
NS_IMETHOD FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound);
|
|
|
|
|
1999-02-11 23:12:28 +00:00
|
|
|
virtual void CreateXIF(nsString & aBuffer, nsIDOMSelection* aSelection);
|
1999-01-12 19:41:06 +00:00
|
|
|
|
|
|
|
virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode);
|
|
|
|
|
|
|
|
virtual void BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode);
|
|
|
|
|
|
|
|
virtual void ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode);
|
|
|
|
|
|
|
|
virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode);
|
|
|
|
|
|
|
|
virtual PRBool IsInRange(const nsIContent *aStartContent, const nsIContent* aEndContent, const nsIContent* aContent) const;
|
|
|
|
|
|
|
|
virtual PRBool IsBefore(const nsIContent *aNewContent, const nsIContent* aCurrentContent) const;
|
|
|
|
|
1999-02-11 23:12:28 +00:00
|
|
|
virtual PRBool IsInSelection(nsIDOMSelection* aSelection, const nsIContent *aContent) const;
|
1999-01-12 19:41:06 +00:00
|
|
|
|
|
|
|
virtual nsIContent* GetPrevContent(const nsIContent *aContent) const;
|
|
|
|
|
|
|
|
virtual nsIContent* GetNextContent(const nsIContent *aContent) const;
|
|
|
|
|
|
|
|
virtual void SetDisplaySelection(PRBool aToggle);
|
|
|
|
|
|
|
|
virtual PRBool GetDisplaySelection() const;
|
|
|
|
|
|
|
|
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIDOMEvent** aDOMEvent,
|
|
|
|
PRUint32 aFlags,
|
|
|
|
nsEventStatus& aEventStatus);
|
|
|
|
|
|
|
|
|
|
|
|
// nsIXMLDocument interface
|
1999-01-19 23:07:33 +00:00
|
|
|
NS_IMETHOD PrologElementAt(PRUint32 aOffset, nsIContent** aContent);
|
|
|
|
NS_IMETHOD PrologCount(PRUint32* aCount);
|
1999-01-12 19:41:06 +00:00
|
|
|
NS_IMETHOD AppendToProlog(nsIContent* aContent);
|
1999-01-19 23:07:33 +00:00
|
|
|
NS_IMETHOD EpilogElementAt(PRUint32 aOffset, nsIContent** aContent);
|
|
|
|
NS_IMETHOD EpilogCount(PRUint32* aCount);
|
1999-01-12 19:41:06 +00:00
|
|
|
NS_IMETHOD AppendToEpilog(nsIContent* aContent);
|
|
|
|
|
|
|
|
// nsIRDFDocument interface
|
|
|
|
NS_IMETHOD SetRootResource(nsIRDFResource* resource);
|
|
|
|
NS_IMETHOD SplitProperty(nsIRDFResource* aResource, PRInt32* aNameSpaceID, nsIAtom** aTag);
|
1999-02-17 11:09:57 +00:00
|
|
|
NS_IMETHOD AddElementForResource(nsIRDFResource* aResource, nsIContent* aElement);
|
|
|
|
NS_IMETHOD RemoveElementForResource(nsIRDFResource* aResource, nsIContent* aElement);
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_IMETHOD GetElementsForResource(nsIRDFResource* aResource, nsISupportsArray* aElements);
|
1999-02-17 11:09:57 +00:00
|
|
|
NS_IMETHOD CreateContents(nsIContent* aElement);
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_IMETHOD AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder);
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
// nsIDOMDocument interface
|
|
|
|
NS_IMETHOD GetDoctype(nsIDOMDocumentType** aDoctype);
|
|
|
|
NS_IMETHOD GetImplementation(nsIDOMDOMImplementation** aImplementation);
|
|
|
|
NS_IMETHOD GetDocumentElement(nsIDOMElement** aDocumentElement);
|
|
|
|
|
|
|
|
NS_IMETHOD CreateElement(const nsString& aTagName, nsIDOMElement** aReturn);
|
|
|
|
NS_IMETHOD CreateDocumentFragment(nsIDOMDocumentFragment** aReturn);
|
|
|
|
NS_IMETHOD CreateTextNode(const nsString& aData, nsIDOMText** aReturn);
|
|
|
|
NS_IMETHOD CreateComment(const nsString& aData, nsIDOMComment** aReturn);
|
|
|
|
NS_IMETHOD CreateCDATASection(const nsString& aData, nsIDOMCDATASection** aReturn);
|
|
|
|
NS_IMETHOD CreateProcessingInstruction(const nsString& aTarget, const nsString& aData, nsIDOMProcessingInstruction** aReturn);
|
|
|
|
NS_IMETHOD CreateAttribute(const nsString& aName, nsIDOMAttr** aReturn);
|
|
|
|
NS_IMETHOD CreateEntityReference(const nsString& aName, nsIDOMEntityReference** aReturn);
|
|
|
|
NS_IMETHOD GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn);
|
|
|
|
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets);
|
1999-02-17 11:09:57 +00:00
|
|
|
|
|
|
|
// nsIDOMXULDocument interface
|
|
|
|
NS_DECL_IDOMXULDOCUMENT
|
1999-02-16 19:30:04 +00:00
|
|
|
|
|
|
|
// nsIDOMNode interface
|
|
|
|
NS_IMETHOD GetNodeName(nsString& aNodeName);
|
|
|
|
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
|
|
|
|
NS_IMETHOD SetNodeValue(const nsString& aNodeValue);
|
|
|
|
NS_IMETHOD GetNodeType(PRUint16* aNodeType);
|
|
|
|
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode);
|
|
|
|
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
|
|
|
|
NS_IMETHOD HasChildNodes(PRBool* aHasChildNodes);
|
|
|
|
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild);
|
|
|
|
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild);
|
|
|
|
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling);
|
|
|
|
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling);
|
|
|
|
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes);
|
|
|
|
NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument);
|
|
|
|
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn);
|
|
|
|
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
|
|
|
|
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
|
|
|
|
NS_IMETHOD AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn);
|
|
|
|
NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn);
|
|
|
|
|
|
|
|
// nsIJSScriptObject interface
|
|
|
|
virtual PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
|
|
|
virtual PRBool DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
|
|
|
virtual PRBool GetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
|
|
|
virtual PRBool SetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
|
|
|
virtual PRBool EnumerateProperty(JSContext *aContext);
|
|
|
|
virtual PRBool Resolve(JSContext *aContext, jsval aID);
|
|
|
|
virtual PRBool Convert(JSContext *aContext, jsval aID);
|
|
|
|
virtual void Finalize(JSContext *aContext);
|
|
|
|
|
|
|
|
// nsIScriptObjectOwner interface
|
|
|
|
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
|
|
|
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
|
|
|
|
|
|
|
// nsIHTMLContentContainer interface
|
|
|
|
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult);
|
|
|
|
NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult);
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
// nsIDOMNodeObserver interface
|
|
|
|
NS_DECL_IDOMNODEOBSERVER
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-17 11:09:57 +00:00
|
|
|
// nsIDOMElementObserver interface
|
|
|
|
NS_DECL_IDOMELEMENTOBSERVER
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
// Implementation methods
|
1999-02-01 22:34:51 +00:00
|
|
|
nsresult Init(void);
|
1999-01-14 10:55:08 +00:00
|
|
|
nsresult StartLayout(void);
|
|
|
|
|
1999-03-05 00:01:26 +00:00
|
|
|
void SearchForNodeByID(const nsString& anID, nsIContent* anElement, nsIDOMElement** aReturn);
|
1999-02-17 18:46:23 +00:00
|
|
|
|
1999-02-17 22:32:40 +00:00
|
|
|
static nsresult
|
1999-02-16 19:30:04 +00:00
|
|
|
GetElementsByTagName(nsIDOMNode* aNode,
|
|
|
|
const nsString& aTagName,
|
|
|
|
nsRDFDOMNodeList* aElements);
|
|
|
|
|
1999-02-23 02:40:51 +00:00
|
|
|
static nsresult
|
|
|
|
GetElementsByAttribute(nsIDOMNode* aNode,
|
|
|
|
const nsString& aAttribute,
|
|
|
|
const nsString& aValue,
|
|
|
|
nsRDFDOMNodeList* aElements);
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
protected:
|
1999-02-24 04:46:47 +00:00
|
|
|
// pseudo constants
|
|
|
|
static PRInt32 gRefCnt;
|
|
|
|
static nsIAtom* kAttributeAtom;
|
|
|
|
static nsIAtom* kElementAtom;
|
|
|
|
static nsIAtom* kIdAtom;
|
|
|
|
static nsIAtom* kObservesAtom;
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
nsIContent*
|
|
|
|
FindContent(const nsIContent* aStartNode,
|
|
|
|
const nsIContent* aTest1,
|
|
|
|
const nsIContent* aTest2) const;
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
nsresult
|
|
|
|
LoadCSSStyleSheet(nsIURL* url);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
AddNamedDataSource(const char* uri);
|
|
|
|
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
nsIArena* mArena;
|
|
|
|
nsVoidArray mObservers;
|
|
|
|
nsAutoString mDocumentTitle;
|
|
|
|
nsIURL* mDocumentURL;
|
|
|
|
nsIURLGroup* mDocumentURLGroup;
|
|
|
|
nsIContent* mRootContent;
|
|
|
|
nsIDocument* mParentDocument;
|
|
|
|
nsIScriptContextOwner* mScriptContextOwner;
|
|
|
|
void* mScriptObject;
|
|
|
|
nsString* mCharSetID;
|
|
|
|
nsVoidArray mStyleSheets;
|
|
|
|
nsIDOMSelection* mSelection;
|
|
|
|
PRBool mDisplaySelection;
|
|
|
|
nsVoidArray mPresShells;
|
|
|
|
nsINameSpaceManager* mNameSpaceManager;
|
|
|
|
nsIHTMLStyleSheet* mAttrStyleSheet;
|
|
|
|
nsIHTMLCSSStyleSheet* mInlineStyleSheet;
|
1999-02-04 10:50:50 +00:00
|
|
|
nsIRDFService* mRDFService;
|
1999-02-09 03:15:41 +00:00
|
|
|
nsElementMap mResources;
|
|
|
|
nsISupportsArray* mBuilders;
|
|
|
|
nsIRDFContentModelBuilder* mXULBuilder;
|
1999-02-04 10:50:50 +00:00
|
|
|
nsIRDFDataSource* mLocalDataSource;
|
1999-02-16 19:30:04 +00:00
|
|
|
nsIRDFDataSource* mDocumentDataSource;
|
|
|
|
nsIParser* mParser;
|
1999-02-23 03:31:26 +00:00
|
|
|
nsILineBreaker* mLineBreaker;
|
1999-01-14 10:55:08 +00:00
|
|
|
};
|
|
|
|
|
1999-02-24 04:46:47 +00:00
|
|
|
PRInt32 XULDocumentImpl::gRefCnt;
|
|
|
|
nsIAtom* XULDocumentImpl::kAttributeAtom;
|
|
|
|
nsIAtom* XULDocumentImpl::kElementAtom;
|
|
|
|
nsIAtom* XULDocumentImpl::kIdAtom;
|
|
|
|
nsIAtom* XULDocumentImpl::kObservesAtom;
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// ctors & dtors
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::XULDocumentImpl(void)
|
1998-12-24 05:07:14 +00:00
|
|
|
: mArena(nsnull),
|
|
|
|
mDocumentURL(nsnull),
|
|
|
|
mDocumentURLGroup(nsnull),
|
|
|
|
mRootContent(nsnull),
|
|
|
|
mParentDocument(nsnull),
|
|
|
|
mScriptContextOwner(nsnull),
|
1999-02-16 19:30:04 +00:00
|
|
|
mScriptObject(nsnull),
|
1998-12-24 05:07:14 +00:00
|
|
|
mSelection(nsnull),
|
|
|
|
mDisplaySelection(PR_FALSE),
|
|
|
|
mNameSpaceManager(nsnull),
|
|
|
|
mAttrStyleSheet(nsnull),
|
1999-01-05 03:53:15 +00:00
|
|
|
mRDFService(nsnull),
|
1999-02-09 03:15:41 +00:00
|
|
|
mBuilders(nsnull),
|
|
|
|
mXULBuilder(nsnull),
|
1999-01-14 10:55:08 +00:00
|
|
|
mLocalDataSource(nsnull),
|
1999-02-03 02:48:55 +00:00
|
|
|
mDocumentDataSource(nsnull),
|
1999-02-23 03:31:26 +00:00
|
|
|
mLineBreaker(nsnull),
|
1999-02-16 19:30:04 +00:00
|
|
|
mParser(nsnull)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// construct a selection object
|
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kRangeListCID,
|
|
|
|
nsnull,
|
1999-02-11 23:12:28 +00:00
|
|
|
kIDOMSelectionIID,
|
1999-02-24 04:46:47 +00:00
|
|
|
(void**) &mSelection))) {
|
|
|
|
NS_ERROR("unable to create DOM selection");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gRefCnt++ == 0) {
|
|
|
|
kAttributeAtom = NS_NewAtom("attribute");
|
|
|
|
kElementAtom = NS_NewAtom("element");
|
|
|
|
kIdAtom = NS_NewAtom("id");
|
|
|
|
kObservesAtom = NS_NewAtom("observes");
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::~XULDocumentImpl()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_IF_RELEASE(mDocumentDataSource);
|
1999-01-14 10:55:08 +00:00
|
|
|
NS_IF_RELEASE(mLocalDataSource);
|
|
|
|
|
1999-01-05 03:53:15 +00:00
|
|
|
if (mRDFService) {
|
|
|
|
nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService);
|
|
|
|
mRDFService = nsnull;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// mParentDocument is never refcounted
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_IF_RELEASE(mBuilders);
|
|
|
|
NS_IF_RELEASE(mXULBuilder);
|
1998-12-24 05:07:14 +00:00
|
|
|
NS_IF_RELEASE(mSelection);
|
|
|
|
NS_IF_RELEASE(mScriptContextOwner);
|
|
|
|
NS_IF_RELEASE(mAttrStyleSheet);
|
|
|
|
NS_IF_RELEASE(mRootContent);
|
|
|
|
NS_IF_RELEASE(mDocumentURLGroup);
|
|
|
|
NS_IF_RELEASE(mDocumentURL);
|
|
|
|
NS_IF_RELEASE(mArena);
|
|
|
|
NS_IF_RELEASE(mNameSpaceManager);
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_IF_RELEASE(mParser);
|
1999-02-23 03:31:26 +00:00
|
|
|
NS_IF_RELEASE(mLineBreaker);
|
1999-02-24 04:46:47 +00:00
|
|
|
|
|
|
|
if (--gRefCnt == 0) {
|
|
|
|
NS_IF_RELEASE(kAttributeAtom);
|
|
|
|
NS_IF_RELEASE(kElementAtom);
|
|
|
|
NS_IF_RELEASE(kIdAtom);
|
|
|
|
NS_IF_RELEASE(kObservesAtom);
|
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewXULDocument(nsIRDFDocument** result)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(result != nsnull, "null ptr");
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
XULDocumentImpl* doc = new XULDocumentImpl();
|
|
|
|
if (! doc)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(doc);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (NS_FAILED(rv = doc->Init())) {
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = doc;
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports interface
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::QueryInterface(REFNSIID iid, void** result)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*result = nsnull;
|
|
|
|
if (iid.Equals(kIDocumentIID) ||
|
|
|
|
iid.Equals(kISupportsIID)) {
|
|
|
|
*result = NS_STATIC_CAST(nsIDocument*, this);
|
|
|
|
}
|
|
|
|
else if (iid.Equals(kIRDFDocumentIID) ||
|
|
|
|
iid.Equals(kIXMLDocumentIID)) {
|
|
|
|
*result = NS_STATIC_CAST(nsIRDFDocument*, this);
|
|
|
|
}
|
1999-03-03 19:48:57 +00:00
|
|
|
else if (iid.Equals(nsIDOMXULDocument::GetIID()) ||
|
|
|
|
iid.Equals(nsIDOMDocument::GetIID()) ||
|
|
|
|
iid.Equals(nsIDOMNode::GetIID())) {
|
1999-02-17 11:09:57 +00:00
|
|
|
*result = NS_STATIC_CAST(nsIDOMXULDocument*, this);
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
else if (iid.Equals(kIJSScriptObjectIID)) {
|
|
|
|
*result = NS_STATIC_CAST(nsIJSScriptObject*, this);
|
|
|
|
}
|
|
|
|
else if (iid.Equals(kIScriptObjectOwnerIID)) {
|
|
|
|
*result = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
|
|
|
|
}
|
1999-02-04 10:50:50 +00:00
|
|
|
else if (iid.Equals(kIHTMLContentContainerIID)) {
|
|
|
|
*result = NS_STATIC_CAST(nsIHTMLContentContainer*, this);
|
|
|
|
}
|
1999-03-03 19:48:57 +00:00
|
|
|
else if (iid.Equals(nsIDOMNodeObserver::GetIID())) {
|
1999-02-16 19:30:04 +00:00
|
|
|
*result = NS_STATIC_CAST(nsIDOMNodeObserver*, this);
|
|
|
|
}
|
1999-03-03 19:48:57 +00:00
|
|
|
else if (iid.Equals(nsIDOMElementObserver::GetIID())) {
|
1999-02-17 11:56:15 +00:00
|
|
|
*result = NS_STATIC_CAST(nsIDOMElementObserver*, this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*result = nsnull;
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
NS_ADDREF(this);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_IMPL_ADDREF(XULDocumentImpl);
|
|
|
|
NS_IMPL_RELEASE(XULDocumentImpl);
|
1998-12-24 05:07:14 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDocument interface
|
|
|
|
|
|
|
|
nsIArena*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetArena()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mArena);
|
|
|
|
return mArena;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::StartDocumentLoad(nsIURL *aURL,
|
1999-01-12 19:41:06 +00:00
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener **aDocListener,
|
|
|
|
const char* aCommand)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-02-04 10:50:50 +00:00
|
|
|
NS_ASSERTION(aURL != nsnull, "null ptr");
|
|
|
|
if (! aURL)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
mDocumentTitle.Truncate();
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mDocumentURL);
|
|
|
|
mDocumentURL = aURL;
|
|
|
|
NS_ADDREF(aURL);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mDocumentURLGroup);
|
|
|
|
(void)aURL->GetURLGroup(&mDocumentURLGroup);
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
// Delete references to style sheets - this should be done in superclass...
|
|
|
|
PRInt32 index = mStyleSheets.Count();
|
|
|
|
while (--index >= 0) {
|
|
|
|
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index);
|
|
|
|
sheet->SetOwningDocument(nsnull);
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
|
|
|
mStyleSheets.Clear();
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
// Create an HTML style sheet for the HTML content.
|
|
|
|
nsIHTMLStyleSheet* sheet;
|
|
|
|
if (NS_SUCCEEDED(rv = nsRepository::CreateInstance(kHTMLStyleSheetCID,
|
|
|
|
nsnull,
|
|
|
|
kIHTMLStyleSheetIID,
|
|
|
|
(void**) &sheet))) {
|
|
|
|
if (NS_SUCCEEDED(rv = sheet->Init(aURL, this))) {
|
|
|
|
mAttrStyleSheet = sheet;
|
|
|
|
NS_ADDREF(mAttrStyleSheet);
|
|
|
|
|
|
|
|
AddStyleSheet(mAttrStyleSheet);
|
|
|
|
}
|
|
|
|
NS_RELEASE(sheet);
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("unable to add HTML style sheet");
|
1999-01-14 10:55:08 +00:00
|
|
|
return rv;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
1999-03-05 00:01:26 +00:00
|
|
|
|
|
|
|
// Create an inline style sheet for inline content that contains a style
|
|
|
|
// attribute.
|
|
|
|
nsIHTMLCSSStyleSheet* inlineSheet;
|
|
|
|
if (NS_SUCCEEDED(rv = nsRepository::CreateInstance(kHTMLCSSStyleSheetCID,
|
|
|
|
nsnull,
|
|
|
|
kIHTMLCSSStyleSheetIID,
|
|
|
|
(void**) &inlineSheet))) {
|
|
|
|
if (NS_SUCCEEDED(rv = inlineSheet->Init(aURL, this))) {
|
|
|
|
mInlineStyleSheet = inlineSheet;
|
|
|
|
NS_ADDREF(mInlineStyleSheet);
|
|
|
|
|
|
|
|
AddStyleSheet(mInlineStyleSheet);
|
|
|
|
}
|
|
|
|
NS_RELEASE(inlineSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("unable to add inline style sheet");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
// Create a composite data source that'll tie together local and
|
|
|
|
// remote stores.
|
|
|
|
nsIRDFCompositeDataSource* db;
|
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFCompositeDataSourceCID,
|
|
|
|
nsnull,
|
|
|
|
kIRDFCompositeDataSourceIID,
|
|
|
|
(void**) &db))) {
|
|
|
|
NS_ERROR("couldn't create composite datasource");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a XUL content model builder
|
|
|
|
NS_IF_RELEASE(mXULBuilder);
|
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFXULBuilderCID,
|
|
|
|
nsnull,
|
|
|
|
kIRDFContentModelBuilderIID,
|
|
|
|
(void**) &mXULBuilder))) {
|
|
|
|
NS_ERROR("couldn't create XUL builder");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = mXULBuilder->SetDataBase(db))) {
|
|
|
|
NS_ERROR("couldn't set builder's db");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mBuilders);
|
|
|
|
if (NS_FAILED(rv = AddContentModelBuilder(mXULBuilder))) {
|
|
|
|
NS_ERROR("could't add XUL builder");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
// Create a "scratch" in-memory data store to associate with the
|
|
|
|
// document to be a catch-all for any doc-specific info that we
|
|
|
|
// need to store (e.g., current sort order, etc.)
|
1999-02-04 10:50:50 +00:00
|
|
|
//
|
|
|
|
// XXX This needs to be cloned across windows, and the final
|
|
|
|
// instance needs to be flushed to disk. It may be that this is
|
|
|
|
// really an RDFXML data source...
|
1999-01-05 03:53:15 +00:00
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFInMemoryDataSourceCID,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsnull,
|
|
|
|
kIRDFDataSourceIID,
|
1999-02-09 03:15:41 +00:00
|
|
|
(void**) &mLocalDataSource))) {
|
|
|
|
NS_ERROR("couldn't create local data source");
|
1999-01-14 10:55:08 +00:00
|
|
|
return rv;
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
if (NS_FAILED(rv = db->AddDataSource(mLocalDataSource))) {
|
|
|
|
NS_ERROR("couldn't add local data source to db");
|
1999-01-14 10:55:08 +00:00
|
|
|
return rv;
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
// Now load the actual RDF/XML document data source. First, we'll
|
|
|
|
// see if the data source has been loaded and is registered with
|
|
|
|
// the RDF service. If so, do some monkey business to "pretend" to
|
|
|
|
// load it: really, we'll just walk its graph to generate the
|
|
|
|
// content model.
|
1999-02-09 03:15:41 +00:00
|
|
|
const char* uri;
|
|
|
|
if (NS_FAILED(rv = aURL->GetSpec(&uri)))
|
|
|
|
return rv;
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
// We need to construct a new stream and load it. The stream will
|
|
|
|
// automagically register itself as a named data source, so if
|
|
|
|
// subsequent docs ask for it, they'll get the real deal. In the
|
|
|
|
// meantime, add us as an nsIRDFXMLDataSourceObserver so that
|
|
|
|
// we'll be notified when we need to load style sheets, etc.
|
|
|
|
NS_IF_RELEASE(mDocumentDataSource);
|
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFInMemoryDataSourceCID,
|
|
|
|
nsnull,
|
|
|
|
kIRDFDataSourceIID,
|
|
|
|
(void**) &mDocumentDataSource))) {
|
|
|
|
NS_ERROR("unable to create XUL datasource");
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
if (NS_FAILED(rv = db->AddDataSource(mDocumentDataSource))) {
|
|
|
|
NS_ERROR("unable to add XUL datasource to db");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
if (NS_FAILED(rv = mDocumentDataSource->Init(uri))) {
|
|
|
|
NS_ERROR("unable to initialize XUL data source");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
nsCOMPtr<nsIXULContentSink> sink;
|
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kXULContentSinkCID,
|
|
|
|
nsnull,
|
|
|
|
kIXULContentSinkIID,
|
|
|
|
(void**) getter_AddRefs(sink)))) {
|
|
|
|
NS_ERROR("unable to create XUL content sink");
|
|
|
|
return rv;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebShell> webShell;
|
|
|
|
aContainer->QueryInterface(kIWebShellIID, getter_AddRefs(webShell));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = sink->Init(this, webShell, mDocumentDataSource))) {
|
|
|
|
NS_ERROR("Unable to initialize XUL content sink");
|
1999-02-09 03:15:41 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kParserCID,
|
|
|
|
nsnull,
|
|
|
|
kIParserIID,
|
|
|
|
(void**) &mParser))) {
|
|
|
|
NS_ERROR("unable to create parser");
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
if (NS_FAILED(rv = mParser->QueryInterface(kIStreamListenerIID, (void**) aDocListener))) {
|
|
|
|
NS_ERROR("parser doesn't support nsIStreamListener");
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kWellFormedDTDCID,
|
|
|
|
nsnull,
|
|
|
|
kIDTDIID,
|
|
|
|
(void**) getter_AddRefs(dtd)))) {
|
|
|
|
NS_ERROR("unable to construct DTD");
|
|
|
|
return rv;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
|
|
|
|
mParser->RegisterDTD(dtd);
|
|
|
|
mParser->SetCommand(aCommand);
|
|
|
|
mParser->SetContentSink(sink);
|
|
|
|
mParser->Parse(aURL);
|
1999-02-03 02:48:55 +00:00
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsString*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetDocumentTitle() const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return &mDocumentTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURL*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetDocumentURL() const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mDocumentURL);
|
|
|
|
return mDocumentURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURLGroup*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetDocumentURLGroup() const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mDocumentURLGroup);
|
|
|
|
return mDocumentURLGroup;
|
|
|
|
}
|
|
|
|
|
1999-01-15 01:53:50 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetBaseURL(nsIURL*& aURL) const
|
1999-01-15 01:53:50 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mDocumentURL);
|
|
|
|
aURL = mDocumentURL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-25 16:05:04 +00:00
|
|
|
nsString*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetDocumentCharacterSet() const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mCharSetID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::SetDocumentCharacterSet(nsString* aCharSetID)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
mCharSetID = aCharSetID;
|
|
|
|
}
|
|
|
|
|
1999-02-23 03:31:26 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetLineBreaker(nsILineBreaker** aResult)
|
|
|
|
{
|
|
|
|
if(nsnull == mLineBreaker ) {
|
|
|
|
// no line breaker, find a default one
|
|
|
|
nsILineBreakerFactory *lf;
|
|
|
|
nsresult result;
|
|
|
|
result = nsServiceManager::GetService(kLWBrkCID,
|
|
|
|
kILineBreakerFactoryIID,
|
|
|
|
(nsISupports **)&lf);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsILineBreaker *lb = nsnull ;
|
|
|
|
nsAutoString lbarg("");
|
|
|
|
result = lf->GetBreaker(lbarg, &lb);
|
|
|
|
if(NS_SUCCEEDED(result)) {
|
|
|
|
mLineBreaker = lb;
|
|
|
|
}
|
|
|
|
result = nsServiceManager::ReleaseService(kLWBrkCID, lf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aResult = mLineBreaker;
|
|
|
|
NS_IF_ADDREF(mLineBreaker);
|
|
|
|
return NS_OK; // XXX we should do error handling here
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::SetLineBreaker(nsILineBreaker* aLineBreaker)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mLineBreaker);
|
|
|
|
mLineBreaker = aLineBreaker;
|
|
|
|
NS_IF_ADDREF(mLineBreaker);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-23 06:59:35 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetHeaderData(nsIAtom* aHeaderField, nsString& aData) const
|
1999-01-23 06:59:35 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl:: SetHeaderData(nsIAtom* aheaderField, const nsString& aData)
|
1999-01-23 06:59:35 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
nsresult
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::CreateShell(nsIPresContext* aContext,
|
1999-01-14 10:55:08 +00:00
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIStyleSet* aStyleSet,
|
|
|
|
nsIPresShell** aInstancePtrResult)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aInstancePtrResult, "null ptr");
|
|
|
|
if (! aInstancePtrResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsIPresShell* shell;
|
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kPresShellCID,
|
|
|
|
nsnull,
|
|
|
|
kIPresShellIID,
|
|
|
|
(void**) &shell)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = shell->Init(this, aContext, aViewManager, aStyleSet))) {
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPresShells.AppendElement(shell);
|
1999-01-14 10:55:08 +00:00
|
|
|
*aInstancePtrResult = shell; // addref implicit
|
1998-12-24 05:07:14 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::DeleteShell(nsIPresShell* aShell)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mPresShells.RemoveElement(aShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetNumberOfShells()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mPresShells.Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetShellAt(PRInt32 aIndex)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[aIndex]);
|
|
|
|
NS_IF_ADDREF(shell);
|
|
|
|
return shell;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetParentDocument()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mParentDocument);
|
|
|
|
return mParentDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::SetParentDocument(nsIDocument* aParent)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
// Note that we do *not* AddRef our parent because that would
|
|
|
|
// create a circular reference.
|
|
|
|
mParentDocument = aParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::AddSubDocument(nsIDocument* aSubDoc)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
// we don't do subdocs.
|
|
|
|
PR_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetNumberOfSubDocuments()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetSubDocumentAt(PRInt32 aIndex)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
// we don't do subdocs.
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetRootContent()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mRootContent);
|
|
|
|
return mRootContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::SetRootContent(nsIContent* aRoot)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-01-12 19:41:06 +00:00
|
|
|
if (mRootContent) {
|
|
|
|
mRootContent->SetDocument(nsnull, PR_TRUE);
|
|
|
|
NS_RELEASE(mRootContent);
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
mRootContent = aRoot;
|
1999-01-12 19:41:06 +00:00
|
|
|
if (mRootContent) {
|
|
|
|
mRootContent->SetDocument(this, PR_TRUE);
|
|
|
|
NS_ADDREF(mRootContent);
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetNumberOfStyleSheets()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mStyleSheets.Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleSheet*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetStyleSheetAt(PRInt32 aIndex)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
nsIStyleSheet* sheet = NS_STATIC_CAST(nsIStyleSheet*, mStyleSheets[aIndex]);
|
|
|
|
NS_IF_ADDREF(sheet);
|
|
|
|
return sheet;
|
|
|
|
}
|
|
|
|
|
1999-01-23 06:59:35 +00:00
|
|
|
PRInt32
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetIndexOfStyleSheet(nsIStyleSheet* aSheet)
|
1999-01-23 06:59:35 +00:00
|
|
|
{
|
|
|
|
return mStyleSheets.IndexOf(aSheet);
|
|
|
|
}
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::AddStyleSheet(nsIStyleSheet* aSheet)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
|
|
|
if (!aSheet)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mStyleSheets.AppendElement(aSheet);
|
|
|
|
NS_ADDREF(aSheet);
|
|
|
|
|
|
|
|
aSheet->SetOwningDocument(this);
|
|
|
|
|
|
|
|
PRBool enabled;
|
|
|
|
aSheet->GetEnabled(enabled);
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
PRInt32 count, index;
|
|
|
|
|
|
|
|
count = mPresShells.Count();
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[index]);
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
shell->GetStyleSet(getter_AddRefs(set));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (set) {
|
1999-01-23 06:59:35 +00:00
|
|
|
set->AddDocStyleSheet(aSheet, this);
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
|
|
|
|
count = mObservers.Count();
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
|
|
|
observer->StyleSheetAdded(this, aSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
|
1998-12-24 05:07:14 +00:00
|
|
|
PRBool aDisabled)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
PRInt32 count;
|
|
|
|
PRInt32 index = mStyleSheets.IndexOf((void *)aSheet);
|
|
|
|
// If we're actually in the document style sheet list
|
|
|
|
if (-1 != index) {
|
|
|
|
count = mPresShells.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
shell->GetStyleSet(getter_AddRefs(set));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (set) {
|
1998-12-24 05:07:14 +00:00
|
|
|
if (aDisabled) {
|
|
|
|
set->RemoveDocStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
else {
|
1999-01-23 06:59:35 +00:00
|
|
|
set->AddDocStyleSheet(aSheet, this); // put it first
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count = mObservers.Count();
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
|
|
|
observer->StyleSheetDisabledStateChanged(this, aSheet, aDisabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIScriptContextOwner *
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetScriptContextOwner()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mScriptContextOwner);
|
|
|
|
return mScriptContextOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
// XXX HACK ALERT! If the script context owner is null, the document
|
|
|
|
// will soon be going away. So tell our content that to lose its
|
|
|
|
// reference to the document. This has to be done before we
|
|
|
|
// actually set the script context owner to null so that the
|
|
|
|
// content elements can remove references to their script objects.
|
1999-01-14 10:55:08 +00:00
|
|
|
if (!aScriptContextOwner && mRootContent)
|
1998-12-24 05:07:14 +00:00
|
|
|
mRootContent->SetDocument(nsnull, PR_TRUE);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mScriptContextOwner);
|
|
|
|
mScriptContextOwner = aScriptContextOwner;
|
|
|
|
NS_IF_ADDREF(mScriptContextOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetNameSpaceManager(nsINameSpaceManager*& aManager)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
aManager = mNameSpaceManager;
|
|
|
|
NS_IF_ADDREF(aManager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Note: We don't hold a reference to the document observer; we assume
|
|
|
|
// that it has a live reference to the document.
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::AddObserver(nsIDocumentObserver* aObserver)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
// XXX Make sure the observer isn't already in the list
|
|
|
|
if (mObservers.IndexOf(aObserver) == -1) {
|
|
|
|
mObservers.AppendElement(aObserver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::RemoveObserver(nsIDocumentObserver* aObserver)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mObservers.RemoveElement(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::BeginLoad()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PRInt32 i, count = mObservers.Count();
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
|
|
|
|
observer->BeginLoad(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::EndLoad()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
StartLayout();
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
PRInt32 i, count = mObservers.Count();
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
|
|
|
|
observer->EndLoad(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::ContentChanged(nsIContent* aContent,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsISupports* aSubContent)
|
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentChanged(this, aContent, aSubContent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-27 07:15:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::ContentStateChanged(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentStateChanged(this, aContent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::AttributeChanged(nsIContent* aChild,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->AttributeChanged(this, aChild, aAttribute, aHint);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::ContentAppended(nsIContent* aContainer,
|
1998-12-24 05:07:14 +00:00
|
|
|
PRInt32 aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentAppended(this, aContainer, aNewIndexInContainer);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::ContentInserted(nsIContent* aContainer,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentInserted(this, aContainer, aChild, aIndexInContainer);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::ContentReplaced(nsIContent* aContainer,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentReplaced(this, aContainer, aOldChild, aNewChild,
|
|
|
|
aIndexInContainer);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::ContentRemoved(nsIContent* aContainer,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentRemoved(this, aContainer,
|
|
|
|
aChild, aIndexInContainer);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::StyleRuleChanged(nsIStyleSheet* aStyleSheet,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->StyleRuleChanged(this, aStyleSheet, aStyleRule, aHint);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::StyleRuleAdded(nsIStyleSheet* aStyleSheet,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->StyleRuleAdded(this, aStyleSheet, aStyleRule);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->StyleRuleRemoved(this, aStyleSheet, aStyleRule);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-11 23:12:28 +00:00
|
|
|
XULDocumentImpl::GetSelection(nsIDOMSelection** aSelection)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
if (!mSelection) {
|
|
|
|
PR_ASSERT(0);
|
|
|
|
*aSelection = nsnull;
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mSelection);
|
|
|
|
*aSelection = mSelection;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::SelectAll()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
nsIContent * start = nsnull;
|
|
|
|
nsIContent * end = nsnull;
|
|
|
|
nsIContent * body = nsnull;
|
|
|
|
|
|
|
|
nsString bodyStr("BODY");
|
|
|
|
PRInt32 i, n;
|
|
|
|
mRootContent->ChildCount(n);
|
|
|
|
for (i=0;i<n;i++) {
|
|
|
|
nsIContent * child;
|
|
|
|
mRootContent->ChildAt(i, child);
|
|
|
|
PRBool isSynthetic;
|
|
|
|
child->IsSynthetic(isSynthetic);
|
|
|
|
if (!isSynthetic) {
|
|
|
|
nsIAtom * atom;
|
|
|
|
child->GetTag(atom);
|
|
|
|
if (bodyStr.EqualsIgnoreCase(atom)) {
|
|
|
|
body = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (body == nsnull) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = body;
|
|
|
|
// Find Very first Piece of Content
|
|
|
|
for (;;) {
|
|
|
|
start->ChildCount(n);
|
|
|
|
if (n <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsIContent * child = start;
|
|
|
|
child->ChildAt(0, start);
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
end = body;
|
|
|
|
// Last piece of Content
|
|
|
|
for (;;) {
|
|
|
|
end->ChildCount(n);
|
|
|
|
if (n <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsIContent * child = end;
|
|
|
|
child->ChildAt(n-1, end);
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
//NS_RELEASE(start);
|
|
|
|
//NS_RELEASE(end);
|
|
|
|
|
|
|
|
#if 0 // XXX nsSelectionRange is in another DLL
|
|
|
|
nsSelectionRange * range = mSelection->GetRange();
|
|
|
|
nsSelectionPoint * startPnt = range->GetStartPoint();
|
|
|
|
nsSelectionPoint * endPnt = range->GetEndPoint();
|
|
|
|
startPnt->SetPoint(start, -1, PR_TRUE);
|
|
|
|
endPnt->SetPoint(end, -1, PR_FALSE);
|
|
|
|
#endif
|
|
|
|
SetDisplaySelection(PR_TRUE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
aIsFound = PR_FALSE;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-11 23:12:28 +00:00
|
|
|
XULDocumentImpl::CreateXIF(nsString & aBuffer, nsIDOMSelection* aSelection)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::IsInRange(const nsIContent *aStartContent, const nsIContent* aEndContent, const nsIContent* aContent) const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PRBool result;
|
|
|
|
|
|
|
|
if (aStartContent == aEndContent) {
|
|
|
|
return PRBool(aContent == aStartContent);
|
|
|
|
}
|
|
|
|
else if (aStartContent == aContent || aEndContent == aContent) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = IsBefore(aStartContent,aContent);
|
|
|
|
if (result)
|
|
|
|
result = IsBefore(aContent, aEndContent);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::IsBefore(const nsIContent *aNewContent, const nsIContent* aCurrentContent) const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
if (nsnull != aNewContent && nsnull != aCurrentContent && aNewContent != aCurrentContent) {
|
1999-01-14 10:55:08 +00:00
|
|
|
nsIContent* test = FindContent(mRootContent, aNewContent, aCurrentContent);
|
1998-12-24 05:07:14 +00:00
|
|
|
if (test == aNewContent)
|
|
|
|
result = PR_TRUE;
|
|
|
|
|
|
|
|
NS_RELEASE(test);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1999-02-11 23:12:28 +00:00
|
|
|
XULDocumentImpl::IsInSelection(nsIDOMSelection* aSelection, const nsIContent *aContent) const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
if (mSelection != nsnull) {
|
|
|
|
#if 0 // XXX can't include this because nsSelectionPoint is in another DLL.
|
|
|
|
nsSelectionRange* range = mSelection->GetRange();
|
|
|
|
if (range != nsnull) {
|
|
|
|
nsSelectionPoint* startPoint = range->GetStartPoint();
|
|
|
|
nsSelectionPoint* endPoint = range->GetEndPoint();
|
|
|
|
|
|
|
|
nsIContent* startContent = startPoint->GetContent();
|
|
|
|
nsIContent* endContent = endPoint->GetContent();
|
|
|
|
result = IsInRange(startContent, endContent, aContent);
|
|
|
|
NS_IF_RELEASE(startContent);
|
|
|
|
NS_IF_RELEASE(endContent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetPrevContent(const nsIContent *aContent) const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
nsIContent* result = nsnull;
|
|
|
|
|
|
|
|
// Look at previous sibling
|
|
|
|
|
|
|
|
if (nsnull != aContent) {
|
|
|
|
nsIContent* parent;
|
|
|
|
aContent->GetParent(parent);
|
|
|
|
|
|
|
|
if (parent != nsnull && parent != mRootContent) {
|
|
|
|
PRInt32 index;
|
|
|
|
parent->IndexOf((nsIContent*)aContent, index);
|
|
|
|
if (index > 0)
|
|
|
|
parent->ChildAt(index-1, result);
|
|
|
|
else
|
|
|
|
result = GetPrevContent(parent);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(parent);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetNextContent(const nsIContent *aContent) const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
nsIContent* result = nsnull;
|
|
|
|
|
|
|
|
if (nsnull != aContent) {
|
|
|
|
// Look at next sibling
|
|
|
|
nsIContent* parent;
|
|
|
|
aContent->GetParent(parent);
|
|
|
|
|
|
|
|
if (parent != nsnull && parent != mRootContent) {
|
|
|
|
PRInt32 index;
|
|
|
|
parent->IndexOf((nsIContent*)aContent, index);
|
|
|
|
|
|
|
|
PRInt32 count;
|
|
|
|
parent->ChildCount(count);
|
|
|
|
if (index+1 < count) {
|
|
|
|
parent->ChildAt(index+1, result);
|
|
|
|
// Get first child down the tree
|
|
|
|
for (;;) {
|
|
|
|
PRInt32 n;
|
|
|
|
result->ChildCount(n);
|
|
|
|
if (n <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsIContent * old = result;
|
|
|
|
old->ChildAt(0, result);
|
|
|
|
NS_RELEASE(old);
|
|
|
|
result->ChildCount(n);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = GetNextContent(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(parent);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::SetDisplaySelection(PRBool aToggle)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
mDisplaySelection = aToggle;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetDisplaySelection() const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mDisplaySelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::HandleDOMEvent(nsIPresContext& aPresContext,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIDOMEvent** aDOMEvent,
|
|
|
|
PRUint32 aFlags,
|
|
|
|
nsEventStatus& aEventStatus)
|
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIXMLDocument interface
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::PrologElementAt(PRUint32 aOffset, nsIContent** aContent)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::PrologCount(PRUint32* aCount)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::AppendToProlog(nsIContent* aContent)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::EpilogElementAt(PRUint32 aOffset, nsIContent** aContent)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::EpilogCount(PRUint32* aCount)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::AppendToEpilog(nsIContent* aContent)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIRDFDocument interface
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::SetRootResource(nsIRDFResource* aResource)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_PRECONDITION(mXULBuilder != nsnull, "not initialized");
|
|
|
|
if (! mXULBuilder)
|
1999-01-12 19:41:06 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_PRECONDITION(mRootContent == nsnull, "already initialize");
|
|
|
|
if (mRootContent)
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
nsresult rv = mXULBuilder->CreateRootContent(aResource);
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_POSTCONDITION(mRootContent != nsnull, "root content wasn't set");
|
|
|
|
return rv;
|
1999-01-12 19:41:06 +00:00
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::SplitProperty(nsIRDFResource* aProperty,
|
1999-01-12 19:41:06 +00:00
|
|
|
PRInt32* aNameSpaceID,
|
|
|
|
nsIAtom** aTag)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aProperty != nsnull, "null ptr");
|
|
|
|
if (! aProperty)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// XXX okay, this is a total hack. for this to work right, we need
|
1999-02-04 10:50:50 +00:00
|
|
|
// to either:
|
|
|
|
//
|
|
|
|
// 1) Remember what the namespace and the tag were when the
|
|
|
|
// property was created, or
|
|
|
|
//
|
|
|
|
// 2) Iterate the entire set of namespace prefixes to see if the
|
|
|
|
// specified property's URI has any of them as a substring.
|
|
|
|
//
|
1999-01-12 19:41:06 +00:00
|
|
|
|
|
|
|
const char* p;
|
|
|
|
aProperty->GetValue(&p);
|
|
|
|
nsAutoString uri(p);
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
// First try to split the namespace using the rightmost '#' or '/'
|
|
|
|
// character.
|
1999-01-12 19:41:06 +00:00
|
|
|
if ((index = uri.RFind('#')) < 0) {
|
|
|
|
if ((index = uri.RFind('/')) < 0) {
|
1999-02-17 22:32:40 +00:00
|
|
|
*aNameSpaceID = kNameSpaceID_None;
|
1999-03-05 00:01:26 +00:00
|
|
|
*aTag = NS_NewAtom(uri);
|
1999-02-17 22:32:40 +00:00
|
|
|
return NS_OK;
|
1999-01-12 19:41:06 +00:00
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
// Using the above info, split the property's URI into a namespace
|
|
|
|
// prefix (that includes the trailing '#' or '/' character) and a
|
|
|
|
// tag.
|
1999-01-12 19:41:06 +00:00
|
|
|
nsAutoString tag;
|
|
|
|
PRInt32 count = uri.Length() - (index + 1);
|
|
|
|
uri.Right(tag, count);
|
|
|
|
uri.Cut(index + 1, count);
|
1999-02-04 10:50:50 +00:00
|
|
|
|
|
|
|
// XXX XUL atoms seem to all be in lower case. HTML atoms are in
|
|
|
|
// upper case. This sucks.
|
1999-02-12 06:19:07 +00:00
|
|
|
//tag.ToUpperCase(); // All XML is case sensitive even HTML in XML
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
nsresult rv;
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
rv = mNameSpaceManager->GetNameSpaceID(uri, nameSpaceID);
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
// Did we find one?
|
|
|
|
if (NS_SUCCEEDED(rv) && nameSpaceID != kNameSpaceID_Unknown) {
|
|
|
|
*aNameSpaceID = nameSpaceID;
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
*aTag = NS_NewAtom(tag);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nope: so we'll need to be a bit more creative. Let's see
|
|
|
|
// what happens if we remove the rightmost '#' and then try...
|
|
|
|
if (uri.Last() == '#') {
|
|
|
|
uri.Truncate(uri.Length() - 1);
|
|
|
|
rv = mNameSpaceManager->GetNameSpaceID(uri, nameSpaceID);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && nameSpaceID != kNameSpaceID_Unknown) {
|
|
|
|
*aNameSpaceID = nameSpaceID;
|
|
|
|
|
|
|
|
*aTag = NS_NewAtom(tag);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-26 02:09:48 +00:00
|
|
|
// allright, if we at least have a tag, then we can return the
|
|
|
|
// thing with kNameSpaceID_None for now.
|
|
|
|
if (tag.Length()) {
|
|
|
|
*aNameSpaceID = kNameSpaceID_None;
|
|
|
|
*aTag = NS_NewAtom(tag);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
// Okay, somebody make this code even more convoluted.
|
|
|
|
NS_ERROR("unable to convert URI to namespace/tag pair");
|
|
|
|
return NS_ERROR_FAILURE; // XXX?
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-17 11:09:57 +00:00
|
|
|
XULDocumentImpl::AddElementForResource(nsIRDFResource* aResource, nsIContent* aElement)
|
1999-02-09 03:15:41 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResource != nsnull, "null ptr");
|
|
|
|
if (! aResource)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
|
|
|
if (! aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
mResources.Add(aResource, aElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-17 11:09:57 +00:00
|
|
|
XULDocumentImpl::RemoveElementForResource(nsIRDFResource* aResource, nsIContent* aElement)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_PRECONDITION(aResource != nsnull, "null ptr");
|
|
|
|
if (! aResource)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
|
|
|
if (! aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
mResources.Remove(aResource, aElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-01 22:34:51 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetElementsForResource(nsIRDFResource* aResource, nsISupportsArray* aElements)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aElements != nsnull, "null ptr");
|
|
|
|
if (! aElements)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
mResources.Find(aResource, aElements);
|
1999-01-12 19:41:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-17 11:09:57 +00:00
|
|
|
XULDocumentImpl::CreateContents(nsIContent* aElement)
|
1999-01-12 19:41:06 +00:00
|
|
|
{
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
|
|
|
if (! aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (! mBuilders)
|
1999-01-12 19:41:06 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-09 03:15:41 +00:00
|
|
|
// XXX we should QueryInterface() here
|
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_ASSERTION(builder != nsnull, "null ptr");
|
|
|
|
if (! builder)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsresult rv = builder->CreateContents(aElement);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "error creating content");
|
|
|
|
// XXX ignore error code?
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
1999-02-01 22:34:51 +00:00
|
|
|
|
1999-02-17 18:33:33 +00:00
|
|
|
// Now that the contents have been created, perform broadcaster
|
|
|
|
// hookups if any of the children are observes nodes.
|
1999-02-17 19:35:53 +00:00
|
|
|
// XXX: Initial sync-up doesn't work, since no document observer exists
|
|
|
|
// yet.
|
1999-02-17 18:33:33 +00:00
|
|
|
PRInt32 childCount;
|
|
|
|
aElement->ChildCount(childCount);
|
|
|
|
for (PRInt32 j = 0; j < childCount; j++)
|
|
|
|
{
|
1999-02-17 18:46:23 +00:00
|
|
|
nsIContent* pChildContent = nsnull;
|
1999-02-17 18:33:33 +00:00
|
|
|
aElement->ChildAt(j, pChildContent);
|
|
|
|
|
|
|
|
if (!pChildContent)
|
|
|
|
break;
|
|
|
|
|
1999-02-17 18:46:23 +00:00
|
|
|
nsIAtom* pTag = nsnull;
|
1999-02-17 18:33:33 +00:00
|
|
|
pChildContent->GetTag(pTag);
|
|
|
|
|
|
|
|
if (!pTag)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsString tagName;
|
|
|
|
pTag->ToString(tagName);
|
|
|
|
|
|
|
|
if (tagName.EqualsIgnoreCase("observes"))
|
|
|
|
{
|
|
|
|
// Find the node that we're supposed to be
|
|
|
|
// observing and perform the hookup.
|
|
|
|
nsString elementValue;
|
|
|
|
nsString attributeValue;
|
|
|
|
|
1999-03-05 00:01:26 +00:00
|
|
|
pChildContent->GetAttribute(kNameSpaceID_None,
|
1999-02-24 04:46:47 +00:00
|
|
|
kElementAtom,
|
1999-02-17 18:33:33 +00:00
|
|
|
elementValue);
|
|
|
|
|
1999-03-05 00:01:26 +00:00
|
|
|
pChildContent->GetAttribute(kNameSpaceID_None,
|
1999-02-24 04:46:47 +00:00
|
|
|
kAttributeAtom,
|
1999-02-17 18:33:33 +00:00
|
|
|
attributeValue);
|
|
|
|
|
1999-03-05 00:01:26 +00:00
|
|
|
nsIDOMElement* pDOMNode = nsnull;
|
|
|
|
GetElementById(elementValue, &pDOMNode);
|
1999-02-17 18:33:33 +00:00
|
|
|
|
|
|
|
if (!pDOMNode)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// We have a DOM node to bind to. Add a broadcast
|
|
|
|
// listener to that node, but only if it's a XUL node.
|
|
|
|
// XXX: Handle context nodes.
|
1999-02-19 02:56:00 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> pListener( do_QueryInterface(aElement) );
|
|
|
|
nsCOMPtr<nsIDOMXULElement> pBroadcaster( do_QueryInterface(pDOMNode) );
|
1999-02-17 18:33:33 +00:00
|
|
|
if (pListener)
|
|
|
|
{
|
|
|
|
pBroadcaster->AddBroadcastListener(attributeValue,
|
|
|
|
pListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(pDOMNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(pChildContent);
|
|
|
|
NS_RELEASE(pTag);
|
|
|
|
}
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aBuilder != nsnull, "null ptr");
|
|
|
|
if (! aBuilder)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (! mBuilders) {
|
|
|
|
if (NS_FAILED(rv = NS_NewISupportsArray(&mBuilders)))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = aBuilder->SetDocument(this))) {
|
|
|
|
NS_ERROR("unable to set builder's document");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mBuilders->AppendElement(aBuilder) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMDocument interface
|
1999-01-14 10:55:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-16 19:30:04 +00:00
|
|
|
XULDocumentImpl::GetDoctype(nsIDOMDocumentType** aDoctype)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-16 19:30:04 +00:00
|
|
|
XULDocumentImpl::GetImplementation(nsIDOMDOMImplementation** aImplementation)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-16 19:30:04 +00:00
|
|
|
XULDocumentImpl::GetDocumentElement(nsIDOMElement** aDocumentElement)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-02-17 22:32:40 +00:00
|
|
|
if (nsnull == aDocumentElement) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult res = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (nsnull != mRootContent) {
|
1999-03-03 19:48:57 +00:00
|
|
|
res = mRootContent->QueryInterface(nsIDOMElement::GetIID(), (void**)aDocumentElement);
|
1999-02-17 22:32:40 +00:00
|
|
|
NS_ASSERTION(NS_OK == res, "Must be a DOM Element");
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-16 19:30:04 +00:00
|
|
|
XULDocumentImpl::CreateElement(const nsString& aTagName, nsIDOMElement** aReturn)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-16 19:30:04 +00:00
|
|
|
XULDocumentImpl::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-16 19:30:04 +00:00
|
|
|
XULDocumentImpl::CreateTextNode(const nsString& aData, nsIDOMText** aReturn)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-16 19:30:04 +00:00
|
|
|
XULDocumentImpl::CreateComment(const nsString& aData, nsIDOMComment** aReturn)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-01 22:34:51 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::CreateCDATASection(const nsString& aData, nsIDOMCDATASection** aReturn)
|
1999-01-12 19:41:06 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::CreateProcessingInstruction(const nsString& aTarget, const nsString& aData, nsIDOMProcessingInstruction** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-12 19:41:06 +00:00
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::CreateAttribute(const nsString& aName, nsIDOMAttr** aReturn)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::CreateEntityReference(const nsString& aName, nsIDOMEntityReference** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetElementsByTagName(const nsString& aTagName, nsIDOMNodeList** aReturn)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsRDFDOMNodeList* elements;
|
|
|
|
if (NS_FAILED(rv = nsRDFDOMNodeList::Create(&elements))) {
|
|
|
|
NS_ERROR("unable to create node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* root = GetRootContent();
|
|
|
|
NS_ASSERTION(root != nsnull, "no doc root");
|
|
|
|
|
|
|
|
if (root != nsnull) {
|
|
|
|
nsIDOMNode* domRoot;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(rv = root->QueryInterface(nsIDOMNode::GetIID(), (void**) &domRoot))) {
|
1999-02-16 19:30:04 +00:00
|
|
|
rv = GetElementsByTagName(domRoot, aTagName, elements);
|
|
|
|
NS_RELEASE(domRoot);
|
|
|
|
}
|
|
|
|
NS_RELEASE(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aReturn = elements;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-23 02:40:51 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetElementsByAttribute(const nsString& aAttribute, const nsString& aValue,
|
|
|
|
nsIDOMNodeList** aReturn)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsRDFDOMNodeList* elements;
|
|
|
|
if (NS_FAILED(rv = nsRDFDOMNodeList::Create(&elements))) {
|
|
|
|
NS_ERROR("unable to create node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* root = GetRootContent();
|
|
|
|
NS_ASSERTION(root != nsnull, "no doc root");
|
|
|
|
|
|
|
|
if (root != nsnull) {
|
|
|
|
nsIDOMNode* domRoot;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(rv = root->QueryInterface(nsIDOMNode::GetIID(), (void**) &domRoot))) {
|
1999-02-23 02:40:51 +00:00
|
|
|
rv = GetElementsByAttribute(domRoot, aAttribute, aValue, elements);
|
|
|
|
NS_RELEASE(domRoot);
|
|
|
|
}
|
|
|
|
NS_RELEASE(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aReturn = elements;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-17 11:09:57 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMXULDocument interface
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-03-05 00:01:26 +00:00
|
|
|
XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn)
|
1999-02-17 11:09:57 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoString uri(aId);
|
|
|
|
const char* documentURL;
|
|
|
|
mDocumentURL->GetSpec(&documentURL);
|
|
|
|
|
|
|
|
rdf_PossiblyMakeAbsolute(documentURL, uri);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> resource;
|
|
|
|
if (NS_FAILED(rv = mRDFService->GetUnicodeResource(uri, getter_AddRefs(resource)))) {
|
|
|
|
NS_ERROR("unable to get resource");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsArray> elements;
|
|
|
|
if (NS_FAILED(rv = NS_NewISupportsArray(getter_AddRefs(elements)))) {
|
|
|
|
NS_ERROR("unable to create new ISupportsArray");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = GetElementsForResource(resource, elements))) {
|
|
|
|
NS_ERROR("unable to get elements for resource");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elements->Count() > 0) {
|
|
|
|
nsISupports* element = elements->ElementAt(0);
|
1999-03-05 00:01:26 +00:00
|
|
|
rv = element->QueryInterface(nsIDOMElement::GetIID(), (void**) aReturn);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "not a DOM element");
|
1999-02-17 11:09:57 +00:00
|
|
|
NS_RELEASE(element);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-17 18:46:23 +00:00
|
|
|
// Didn't find it in our hash table. Walk the tree looking for the node
|
|
|
|
*aReturn = nsnull;
|
|
|
|
SearchForNodeByID(aId, mRootContent, aReturn);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XULDocumentImpl::SearchForNodeByID(const nsString& anID,
|
|
|
|
nsIContent* anElement,
|
1999-03-05 00:01:26 +00:00
|
|
|
nsIDOMElement** aReturn)
|
1999-02-17 18:46:23 +00:00
|
|
|
{
|
|
|
|
// See if we match.
|
|
|
|
PRInt32 namespaceID;
|
|
|
|
anElement->GetNameSpaceID(namespaceID);
|
|
|
|
|
|
|
|
nsString idValue;
|
|
|
|
|
1999-02-24 04:46:47 +00:00
|
|
|
anElement->GetAttribute(namespaceID, kIdAtom, idValue);
|
1999-02-17 18:46:23 +00:00
|
|
|
|
|
|
|
if (idValue == anID)
|
|
|
|
{
|
1999-03-05 00:01:26 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> pDomNode( do_QueryInterface(anElement) );
|
1999-02-17 18:46:23 +00:00
|
|
|
if (pDomNode)
|
|
|
|
{
|
|
|
|
*aReturn = pDomNode;
|
1999-02-24 02:18:35 +00:00
|
|
|
NS_ADDREF(*aReturn);
|
1999-02-17 18:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Walk children.
|
|
|
|
// XXX: Don't descend into closed tree items (or menu items or buttons?).
|
|
|
|
PRInt32 childCount;
|
|
|
|
anElement->ChildCount(childCount);
|
|
|
|
for (PRInt32 i = 0; i < childCount && !(*aReturn); i++)
|
|
|
|
{
|
|
|
|
nsIContent* pContent = nsnull;
|
|
|
|
anElement->ChildAt(i, pContent);
|
|
|
|
if (pContent)
|
|
|
|
{
|
|
|
|
SearchForNodeByID(anID, pContent, aReturn);
|
|
|
|
NS_RELEASE(pContent);
|
|
|
|
}
|
|
|
|
}
|
1999-02-17 11:09:57 +00:00
|
|
|
}
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMNode interface
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetNodeName(nsString& aNodeName)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetNodeValue(nsString& aNodeValue)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::SetNodeValue(const nsString& aNodeValue)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetNodeType(PRUint16* aNodeType)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetParentNode(nsIDOMNode** aParentNode)
|
|
|
|
{
|
1999-02-17 11:09:57 +00:00
|
|
|
*aParentNode = nsnull;
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::HasChildNodes(PRBool* aHasChildNodes)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetFirstChild(nsIDOMNode** aFirstChild)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetLastChild(nsIDOMNode** aLastChild)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetNextSibling(nsIDOMNode** aNextSibling)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIJSScriptObject interface
|
|
|
|
PRBool
|
|
|
|
XULDocumentImpl::AddProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
XULDocumentImpl::DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
XULDocumentImpl::GetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
|
|
|
{
|
|
|
|
PRBool result = PR_TRUE;
|
|
|
|
|
|
|
|
if (JSVAL_IS_STRING(aID) &&
|
|
|
|
PL_strcmp("location", JS_GetStringBytes(JS_ValueToString(aContext, aID))) == 0) {
|
|
|
|
if (nsnull != mScriptContextOwner) {
|
|
|
|
nsIScriptGlobalObject *global;
|
|
|
|
mScriptContextOwner->GetScriptGlobalObject(&global);
|
|
|
|
if (nsnull != global) {
|
|
|
|
nsIJSScriptObject *window;
|
|
|
|
if (NS_OK == global->QueryInterface(kIJSScriptObjectIID, (void **)&window)) {
|
|
|
|
result = window->GetProperty(aContext, aID, aVp);
|
|
|
|
NS_RELEASE(window);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
|
|
|
NS_RELEASE(global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
XULDocumentImpl::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
XULDocumentImpl::EnumerateProperty(JSContext *aContext)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
XULDocumentImpl::Resolve(JSContext *aContext, jsval aID)
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
XULDocumentImpl::Convert(JSContext *aContext, jsval aID)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
XULDocumentImpl::Finalize(JSContext *aContext)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIScriptObjectOwner interface
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
|
|
|
{
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
|
|
|
|
|
|
|
if (nsnull == mScriptObject) {
|
1999-02-17 11:09:57 +00:00
|
|
|
res = NS_NewScriptXULDocument(aContext, (nsISupports *)(nsIDOMXULDocument *)this, global, (void**)&mScriptObject);
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
*aScriptObject = mScriptObject;
|
|
|
|
|
|
|
|
NS_RELEASE(global);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::SetScriptObject(void *aScriptObject)
|
|
|
|
{
|
|
|
|
mScriptObject = aScriptObject;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIHTMLContentContainer interface
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mAttrStyleSheet;
|
|
|
|
if (nsnull == mAttrStyleSheet) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE; // probably not the right error...
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(mAttrStyleSheet);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("get the inline stylesheet!");
|
|
|
|
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mInlineStyleSheet;
|
|
|
|
if (nsnull == mInlineStyleSheet) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE; // probably not the right error...
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(mInlineStyleSheet);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMNodeObserver interface
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnSetNodeValue(nsIDOMNode* aNode, const nsString& aValue)
|
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-17 11:09:57 +00:00
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
nsIDOMNodeObserver* obs;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(builder->QueryInterface(nsIDOMNodeObserver::GetIID(), (void**) &obs))) {
|
1999-02-17 11:09:57 +00:00
|
|
|
obs->OnSetNodeValue(aNode, aValue);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aRefChild)
|
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-16 19:30:04 +00:00
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
nsIDOMNodeObserver* obs;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(builder->QueryInterface(nsIDOMNodeObserver::GetIID(), (void**) &obs))) {
|
1999-02-16 19:30:04 +00:00
|
|
|
obs->OnInsertBefore(aParent, aNewChild, aRefChild);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aOldChild)
|
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-17 11:09:57 +00:00
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
nsIDOMNodeObserver* obs;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(builder->QueryInterface(nsIDOMNodeObserver::GetIID(), (void**) &obs))) {
|
1999-02-17 11:09:57 +00:00
|
|
|
obs->OnReplaceChild(aParent, aNewChild, aOldChild);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)
|
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-17 11:09:57 +00:00
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
nsIDOMNodeObserver* obs;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(builder->QueryInterface(nsIDOMNodeObserver::GetIID(), (void**) &obs))) {
|
1999-02-17 11:09:57 +00:00
|
|
|
obs->OnRemoveChild(aParent, aOldChild);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)
|
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-17 11:09:57 +00:00
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
nsIDOMNodeObserver* obs;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(builder->QueryInterface(nsIDOMNodeObserver::GetIID(), (void**) &obs))) {
|
1999-02-17 11:09:57 +00:00
|
|
|
obs->OnAppendChild(aParent, aNewChild);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMElementObserver interface
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& aName, const nsString& aValue)
|
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-17 11:09:57 +00:00
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
nsIDOMElementObserver* obs;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(builder->QueryInterface(nsIDOMElementObserver::GetIID(), (void**) &obs))) {
|
1999-02-17 11:09:57 +00:00
|
|
|
obs->OnSetAttribute(aElement, aName, aValue);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString& aName)
|
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-17 11:09:57 +00:00
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
nsIDOMElementObserver* obs;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(builder->QueryInterface(nsIDOMElementObserver::GetIID(), (void**) &obs))) {
|
1999-02-17 11:09:57 +00:00
|
|
|
obs->OnRemoveAttribute(aElement, aName);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnSetAttributeNode(nsIDOMElement* aElement, nsIDOMAttr* aNewAttr)
|
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-17 11:09:57 +00:00
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
nsIDOMElementObserver* obs;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(builder->QueryInterface(nsIDOMElementObserver::GetIID(), (void**) &obs))) {
|
1999-02-17 11:09:57 +00:00
|
|
|
obs->OnSetAttributeNode(aElement, aNewAttr);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
1999-02-17 11:09:57 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnRemoveAttributeNode(nsIDOMElement* aElement, nsIDOMAttr* aOldAttr)
|
|
|
|
{
|
1999-02-23 08:10:24 +00:00
|
|
|
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
1999-02-17 11:09:57 +00:00
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
nsIDOMElementObserver* obs;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(builder->QueryInterface(nsIDOMElementObserver::GetIID(), (void**) &obs))) {
|
1999-02-17 11:09:57 +00:00
|
|
|
obs->OnRemoveAttributeNode(aElement, aOldAttr);
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Implementation methods
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
XULDocumentImpl::FindContent(const nsIContent* aStartNode,
|
|
|
|
const nsIContent* aTest1,
|
|
|
|
const nsIContent* aTest2) const
|
|
|
|
{
|
|
|
|
PRInt32 count;
|
|
|
|
aStartNode->ChildCount(count);
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for(index = 0; index < count;index++) {
|
|
|
|
nsIContent* child;
|
|
|
|
aStartNode->ChildAt(index, child);
|
|
|
|
nsIContent* content = FindContent(child,aTest1,aTest2);
|
|
|
|
if (content != nsnull) {
|
|
|
|
NS_IF_RELEASE(child);
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
if (child == aTest1 || child == aTest2) {
|
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(child);
|
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XULDocumentImpl::LoadCSSStyleSheet(nsIURL* url)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIInputStream* iin;
|
|
|
|
rv = NS_OpenURL(url, &iin);
|
1999-01-14 10:55:08 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_RELEASE(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIUnicharInputStream* uin = nsnull;
|
|
|
|
rv = NS_NewConverterStream(&uin, nsnull, iin);
|
|
|
|
NS_RELEASE(iin);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_RELEASE(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsICSSParser* parser;
|
|
|
|
rv = nsRepository::CreateInstance(kCSSParserCID,
|
|
|
|
nsnull,
|
|
|
|
kICSSParserIID,
|
|
|
|
(void**) &parser);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsICSSStyleSheet* sheet = nsnull;
|
|
|
|
// XXX note: we are ignoring rv until the error code stuff in the
|
|
|
|
// input routines is converted to use nsresult's
|
|
|
|
parser->SetCaseSensitive(PR_TRUE);
|
|
|
|
parser->Parse(uin, url, sheet);
|
|
|
|
if (nsnull != sheet) {
|
|
|
|
AddStyleSheet(sheet);
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
rv = NS_OK;
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;/* XXX */
|
|
|
|
}
|
|
|
|
NS_RELEASE(parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(uin);
|
|
|
|
NS_RELEASE(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::AddNamedDataSource(const char* uri)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_PRECONDITION(mXULBuilder != nsnull, "not initialized");
|
|
|
|
if (! mXULBuilder)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
nsresult rv;
|
1999-02-09 03:15:41 +00:00
|
|
|
nsCOMPtr<nsIRDFDataSource> ds;
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
if (NS_FAILED(rv = mRDFService->GetDataSource(uri, getter_AddRefs(ds)))) {
|
|
|
|
NS_ERROR("unable to get named datasource");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
nsCOMPtr<nsIRDFCompositeDataSource> db;
|
|
|
|
if (NS_FAILED(rv = mXULBuilder->GetDataBase(getter_AddRefs(db)))) {
|
|
|
|
NS_ERROR("unable to get XUL db");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
if (NS_FAILED(rv = db->AddDataSource(ds))) {
|
|
|
|
NS_ERROR("unable to add named data source to XUL db");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-01 22:34:51 +00:00
|
|
|
nsresult
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::Init(void)
|
1999-02-01 22:34:51 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = NS_NewHeapArena(&mArena, nsnull)))
|
|
|
|
return rv;
|
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
// Create a namespace manager so we can manage tags
|
1999-02-01 22:34:51 +00:00
|
|
|
if (NS_FAILED(rv = nsRepository::CreateInstance(kNameSpaceManagerCID,
|
|
|
|
nsnull,
|
|
|
|
kINameSpaceManagerIID,
|
|
|
|
(void**) &mNameSpaceManager)))
|
|
|
|
return rv;
|
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
// Keep the RDF service cached in a member variable to make using
|
|
|
|
// it a bit less painful
|
1999-02-01 22:34:51 +00:00
|
|
|
if (NS_FAILED(rv = nsServiceManager::GetService(kRDFServiceCID,
|
|
|
|
kIRDFServiceIID,
|
|
|
|
(nsISupports**) &mRDFService)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
nsresult
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::StartLayout(void)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
|
|
|
PRInt32 count = GetNumberOfShells();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIPresShell* shell = GetShellAt(i);
|
|
|
|
if (nsnull == shell)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Resize-reflow this time
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
|
|
|
shell->GetPresContext(getter_AddRefs(cx));
|
1999-01-14 10:55:08 +00:00
|
|
|
nsRect r;
|
|
|
|
cx->GetVisibleArea(r);
|
|
|
|
shell->InitialReflow(r.width, r.height);
|
|
|
|
|
|
|
|
// Now trigger a refresh
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (vm) {
|
1999-01-14 10:55:08 +00:00
|
|
|
vm->EnableRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start observing the document _after_ we do the initial
|
|
|
|
// reflow. Otherwise, we'll get into an trouble trying to
|
|
|
|
// creat kids before the root frame is established.
|
|
|
|
shell->BeginObservingDocument();
|
|
|
|
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
nsresult
|
1999-02-16 19:30:04 +00:00
|
|
|
XULDocumentImpl::GetElementsByTagName(nsIDOMNode* aNode,
|
|
|
|
const nsString& aTagName,
|
|
|
|
nsRDFDOMNodeList* aElements)
|
1999-01-12 19:41:06 +00:00
|
|
|
{
|
1999-02-16 19:30:04 +00:00
|
|
|
nsresult rv;
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-25 02:58:11 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
element = do_QueryInterface(aNode);
|
|
|
|
if (!element)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
if (aTagName.Equals("*")) {
|
|
|
|
if (NS_FAILED(rv = aElements->AppendNode(aNode))) {
|
|
|
|
NS_ERROR("unable to append element to node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsAutoString name;
|
|
|
|
if (NS_FAILED(rv = aNode->GetNodeName(name))) {
|
|
|
|
NS_ERROR("unable to get node name");
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
if (aTagName.Equals(name)) {
|
|
|
|
if (NS_FAILED(rv = aElements->AppendNode(aNode))) {
|
|
|
|
NS_ERROR("unable to append element to node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-01 22:34:51 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
nsCOMPtr<nsIDOMNodeList> children;
|
|
|
|
if (NS_FAILED(rv = aNode->GetChildNodes( getter_AddRefs(children) ))) {
|
|
|
|
NS_ERROR("unable to get node's children");
|
1999-02-01 22:34:51 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
// no kids: terminate the recursion
|
|
|
|
if (! children)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRUint32 length;
|
|
|
|
if (NS_FAILED(children->GetLength(&length))) {
|
|
|
|
NS_ERROR("unable to get node list's length");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < length; ++i) {
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
if (NS_FAILED(rv = children->Item(i, getter_AddRefs(child) ))) {
|
|
|
|
NS_ERROR("unable to get child from list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = GetElementsByTagName(child, aTagName, aElements))) {
|
|
|
|
NS_ERROR("unable to recursively get elements by tag name");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-02-23 02:40:51 +00:00
|
|
|
nsresult
|
|
|
|
XULDocumentImpl::GetElementsByAttribute(nsIDOMNode* aNode,
|
|
|
|
const nsString& aAttribute,
|
|
|
|
const nsString& aValue,
|
|
|
|
nsRDFDOMNodeList* aElements)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-02-25 02:58:11 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
element = do_QueryInterface(aNode);
|
|
|
|
if (!element)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-02-23 02:40:51 +00:00
|
|
|
nsAutoString name;
|
|
|
|
nsCOMPtr<nsIContent> pContent;
|
|
|
|
pContent = do_QueryInterface(aNode);
|
|
|
|
|
|
|
|
PRInt32 namespaceID;
|
|
|
|
pContent->GetNameSpaceID(namespaceID);
|
|
|
|
|
|
|
|
nsIAtom* pAtom = NS_NewAtom(aAttribute);
|
|
|
|
|
|
|
|
nsString actualValue;
|
|
|
|
|
|
|
|
rv = pContent->GetAttribute(namespaceID, pAtom, actualValue);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(pAtom);
|
|
|
|
|
|
|
|
if (((rv == NS_CONTENT_ATTR_NO_VALUE || rv == NS_CONTENT_ATTR_HAS_VALUE) && aValue == "*") ||
|
|
|
|
(rv == NS_CONTENT_ATTR_HAS_VALUE && actualValue == aValue))
|
|
|
|
{
|
|
|
|
if (NS_FAILED(rv = aElements->AppendNode(aNode))) {
|
|
|
|
NS_ERROR("unable to append element to node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> children;
|
|
|
|
if (NS_FAILED(rv = aNode->GetChildNodes( getter_AddRefs(children) ))) {
|
|
|
|
NS_ERROR("unable to get node's children");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no kids: terminate the recursion
|
|
|
|
if (! children)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRUint32 length;
|
|
|
|
if (NS_FAILED(children->GetLength(&length))) {
|
|
|
|
NS_ERROR("unable to get node list's length");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < length; ++i) {
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
if (NS_FAILED(rv = children->Item(i, getter_AddRefs(child) ))) {
|
|
|
|
NS_ERROR("unable to get child from list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = GetElementsByAttribute(child, aAttribute, aValue, aElements))) {
|
|
|
|
NS_ERROR("unable to recursively get elements by attribute");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
|
|
|
|
|