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-04-16 08:38:17 +00:00
|
|
|
// Note the ALPHABETICAL ORDERING
|
1999-02-01 22:34:51 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsDOMCID.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIArena.h"
|
1999-01-14 10:55:08 +00:00
|
|
|
#include "nsICSSParser.h"
|
|
|
|
#include "nsICSSStyleSheet.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsIContent.h"
|
1999-02-17 11:09:57 +00:00
|
|
|
#include "nsIDOMElementObserver.h"
|
1999-05-04 23:32:25 +00:00
|
|
|
#include "nsIDOMEventCapturer.h"
|
1999-05-16 07:05:51 +00:00
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIDOMNodeObserver.h"
|
|
|
|
#include "nsIDOMScriptObjectFactory.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsIDOMSelection.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIDOMStyleSheetCollection.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsIDOMText.h"
|
1999-02-17 11:09:57 +00:00
|
|
|
#include "nsIDOMXULDocument.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsIDOMXULElement.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 "nsIHTMLCSSStyleSheet.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsIHTMLContentContainer.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIHTMLStyleSheet.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIJSScriptObject.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsINameSpace.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-05-05 03:09:50 +00:00
|
|
|
#include "nsIRDFContainerUtils.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIRDFContentModelBuilder.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#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"
|
1999-05-04 23:32:25 +00:00
|
|
|
#include "nsIEventListenerManager.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"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStreamListener.h"
|
1999-04-23 16:48:33 +00:00
|
|
|
#include "nsIStreamLoadableDocument.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsIStyleContext.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsIStyleSheet.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsISupportsArray.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsITextContent.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIURLGroup.h"
|
|
|
|
#include "nsIWebShell.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsIXMLContent.h"
|
|
|
|
#include "nsIXULChildDocument.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIXULContentSink.h"
|
1999-03-10 01:37:31 +00:00
|
|
|
#include "nsIXULParentDocument.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-04-16 08:38:17 +00:00
|
|
|
#include "nsRDFContentUtils.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsRDFDOMNodeList.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsVoidArray.h"
|
1999-03-29 19:52:54 +00:00
|
|
|
#include "nsXPIDLString.h" // XXX should go away
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "plhash.h"
|
1999-02-03 02:48:55 +00:00
|
|
|
#include "plstr.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "prlog.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "rdfutil.h"
|
|
|
|
#include "rdf.h"
|
1999-02-23 03:31:26 +00:00
|
|
|
|
1999-05-04 23:32:25 +00:00
|
|
|
#include "nsIDOMEventCapturer.h"
|
|
|
|
#include "nsIDOMEventReceiver.h"
|
|
|
|
|
1999-02-23 03:31:26 +00:00
|
|
|
#include "nsILineBreakerFactory.h"
|
1999-03-27 00:58:42 +00:00
|
|
|
#include "nsIWordBreakerFactory.h"
|
1999-02-23 03:31:26 +00:00
|
|
|
#include "nsLWBrkCIID.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
|
1999-04-23 16:48:33 +00:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
static NS_DEFINE_IID(kICSSParserIID, NS_ICSS_PARSER_IID); // XXX grr..
|
|
|
|
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);
|
1999-05-16 07:05:51 +00:00
|
|
|
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
|
1999-04-16 08:38:17 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIHTMLContentContainerIID, NS_IHTMLCONTENTCONTAINER_IID);
|
|
|
|
static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID);
|
|
|
|
static NS_DEFINE_IID(kIHTMLCSSStyleSheetIID, NS_IHTML_CSS_STYLE_SHEET_IID);
|
|
|
|
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
|
|
|
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);
|
1999-04-16 08:38:17 +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);
|
|
|
|
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
|
|
|
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
|
1999-05-04 23:32:25 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMEventCapturerIID, NS_IDOMEVENTCAPTURER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventTargetIID, NS_IDOMEVENTTARGET_IID);
|
1999-04-16 08:38:17 +00:00
|
|
|
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
|
|
|
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);
|
|
|
|
static NS_DEFINE_IID(kIXULContentSinkIID, NS_IXULCONTENTSINK_IID);
|
1999-05-04 23:32:25 +00:00
|
|
|
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
|
1999-04-16 08:38:17 +00:00
|
|
|
|
1999-05-04 23:32:25 +00:00
|
|
|
static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID);
|
1999-04-16 08:38:17 +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-04-16 08:38:17 +00:00
|
|
|
static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID);
|
|
|
|
static NS_DEFINE_CID(kHTMLCSSStyleSheetCID, NS_HTML_CSS_STYLESHEET_CID);
|
|
|
|
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-04-16 08:38:17 +00:00
|
|
|
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
|
|
|
static NS_DEFINE_CID(kLocalStoreCID, NS_LOCALSTORE_CID);
|
1999-04-27 05:53:53 +00:00
|
|
|
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
1999-04-16 08:38:17 +00:00
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID);
|
|
|
|
static NS_DEFINE_CID(kRangeListCID, NS_RANGELIST_CID);
|
|
|
|
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
|
|
|
|
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
|
|
|
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-03-27 00:58:42 +00:00
|
|
|
static NS_DEFINE_IID(kIWordBreakerFactoryIID, NS_IWORDBREAKERFACTORY_IID);
|
1999-02-23 03:31:26 +00:00
|
|
|
|
1999-04-02 19:51:35 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
1999-04-16 08:38:17 +00:00
|
|
|
// Standard vocabulary items
|
|
|
|
|
|
|
|
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
|
|
|
|
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, type);
|
|
|
|
|
|
|
|
#define XUL_NAMESPACE_URI "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
#define XUL_NAMESPACE_URI_PREFIX XUL_NAMESPACE_URI "#"
|
|
|
|
DEFINE_RDF_VOCAB(XUL_NAMESPACE_URI_PREFIX, XUL, element);
|
1999-04-02 19:51:35 +00:00
|
|
|
|
|
|
|
static PRLogModuleInfo* gMapLog;
|
|
|
|
|
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
|
1999-04-27 05:53:53 +00:00
|
|
|
ReleaseContentList(PLHashEntry* he, PRIntn index, void* closure);
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
public:
|
|
|
|
nsElementMap(void);
|
|
|
|
virtual ~nsElementMap();
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Add(nsIRDFResource* aResource, nsIContent* aContent);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Remove(nsIRDFResource* aResource, nsIContent* aContent);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Find(nsIRDFResource* aResource, nsISupportsArray* aResults);
|
|
|
|
};
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
|
|
|
|
nsElementMap::nsElementMap()
|
|
|
|
{
|
|
|
|
// 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");
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
1999-04-27 05:53:53 +00:00
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
nsElementMap::~nsElementMap()
|
|
|
|
{
|
|
|
|
if (mResources) {
|
|
|
|
PL_HashTableEnumerateEntries(mResources, ReleaseContentList, nsnull);
|
|
|
|
PL_HashTableDestroy(mResources);
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
1999-04-27 05:53:53 +00:00
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsElementMap::ReleaseContentList(PLHashEntry* he, PRIntn index, void* closure)
|
|
|
|
{
|
|
|
|
nsIRDFResource* resource =
|
|
|
|
NS_REINTERPRET_CAST(nsIRDFResource*, NS_CONST_CAST(void*, he->key));
|
|
|
|
|
|
|
|
NS_RELEASE(resource);
|
|
|
|
|
|
|
|
ContentListItem* head =
|
|
|
|
(ContentListItem*) he->value;
|
|
|
|
|
|
|
|
while (head) {
|
|
|
|
ContentListItem* doomed = head;
|
|
|
|
head = head->mNext;
|
|
|
|
delete doomed;
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
nsresult
|
|
|
|
nsElementMap::Add(nsIRDFResource* aResource, nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mResources != nsnull, "not initialized");
|
|
|
|
if (! mResources)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
ContentListItem* head =
|
|
|
|
(ContentListItem*) PL_HashTableLookup(mResources, aResource);
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
if (! head) {
|
|
|
|
head = new ContentListItem(aContent);
|
|
|
|
if (! head)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
PL_HashTableAdd(mResources, aResource, head);
|
|
|
|
NS_ADDREF(aResource);
|
1999-05-08 10:29:24 +00:00
|
|
|
NS_ADDREF(aContent);
|
1999-04-27 05:53:53 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (1) {
|
|
|
|
if (head->mContent == aContent) {
|
|
|
|
NS_ERROR("attempt to add same element twice");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
if (! head->mNext)
|
1999-04-27 05:53:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
head = head->mNext;
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
head->mNext = new ContentListItem(aContent);
|
|
|
|
if (! head->mNext)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-05-08 10:29:24 +00:00
|
|
|
NS_ADDREF(aContent);
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
nsresult
|
|
|
|
nsElementMap::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) {
|
1999-05-08 10:29:24 +00:00
|
|
|
NS_RELEASE(aContent);
|
1999-04-27 05:53:53 +00:00
|
|
|
ContentListItem* newHead = head->mNext;
|
|
|
|
if (newHead) {
|
|
|
|
PL_HashTableAdd(mResources, aResource, newHead);
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-04-27 05:53:53 +00:00
|
|
|
// It was the last reference in the table
|
|
|
|
PL_HashTableRemove(mResources, aResource);
|
|
|
|
NS_RELEASE(aResource);
|
|
|
|
}
|
|
|
|
delete head;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ContentListItem* doomed = head->mNext;
|
|
|
|
while (doomed) {
|
|
|
|
if (doomed->mContent == aContent) {
|
|
|
|
head->mNext = doomed->mNext;
|
1999-05-08 10:29:24 +00:00
|
|
|
NS_RELEASE(aContent);
|
1999-04-27 05:53:53 +00:00
|
|
|
delete doomed;
|
|
|
|
return NS_OK;
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
1999-04-27 05:53:53 +00:00
|
|
|
head = doomed;
|
|
|
|
doomed = doomed->mNext;
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
// XXX Don't comment out this assert: if you get here,
|
|
|
|
// something has gone dreadfully, horribly
|
|
|
|
// wrong. Curse. Scream. File a bug against
|
|
|
|
// waterson@netscape.com.
|
|
|
|
NS_ERROR("attempt to remove an element that was never added");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
nsresult
|
|
|
|
nsElementMap::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;
|
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// XULDocumentImpl
|
|
|
|
|
|
|
|
class XULDocumentImpl : public nsIDocument,
|
1999-01-12 19:41:06 +00:00
|
|
|
public nsIRDFDocument,
|
1999-04-23 16:48:33 +00:00
|
|
|
public nsIStreamLoadableDocument,
|
1999-02-17 11:09:57 +00:00
|
|
|
public nsIDOMXULDocument,
|
1999-05-04 23:32:25 +00:00
|
|
|
public nsIDOMEventCapturer,
|
1999-02-16 19:30:04 +00:00
|
|
|
public nsIJSScriptObject,
|
|
|
|
public nsIScriptObjectOwner,
|
|
|
|
public nsIHTMLContentContainer,
|
1999-02-17 11:09:57 +00:00
|
|
|
public nsIDOMNodeObserver,
|
1999-03-10 01:37:31 +00:00
|
|
|
public nsIDOMElementObserver,
|
|
|
|
public nsIXULParentDocument,
|
|
|
|
public nsIXULChildDocument
|
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();
|
|
|
|
|
1999-05-11 20:22:52 +00:00
|
|
|
NS_IMETHOD GetContentType(nsString& aContentType) const;
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
NS_IMETHOD StartDocumentLoad(nsIURL *aUrl,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener **aDocListener,
|
|
|
|
const char* aCommand);
|
|
|
|
|
1999-04-23 16:48:33 +00:00
|
|
|
NS_IMETHOD LoadFromStream( nsIInputStream& xulStream,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
const char* aCommand );
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
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-04-27 21:49:25 +00:00
|
|
|
NS_IMETHOD GetDocumentCharacterSet(nsString& oCharSetID);
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-04-27 21:49:25 +00:00
|
|
|
NS_IMETHOD SetDocumentCharacterSet(const 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-03-27 00:58:42 +00:00
|
|
|
NS_IMETHOD GetWordBreaker(nsIWordBreaker** aResult) ;
|
|
|
|
NS_IMETHOD SetWordBreaker(nsIWordBreaker* aWordBreaker) ;
|
1999-02-23 03:31:26 +00:00
|
|
|
|
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);
|
|
|
|
|
1999-03-31 20:49:42 +00:00
|
|
|
NS_IMETHOD AppendToProlog(nsIContent* aContent);
|
|
|
|
NS_IMETHOD AppendToEpilog(nsIContent* aContent);
|
|
|
|
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const;
|
|
|
|
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const;
|
|
|
|
NS_IMETHOD GetChildCount(PRInt32& aCount);
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
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-04-20 00:00:02 +00:00
|
|
|
NS_IMETHOD ContentStatesChanged(nsIContent* aContent1, nsIContent* aContent2);
|
1999-02-27 07:15:09 +00:00
|
|
|
|
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-03-20 01:51:00 +00:00
|
|
|
NS_IMETHOD GetContentById(const nsString& aName, nsIContent** aContent);
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
// nsIRDFDocument interface
|
|
|
|
NS_IMETHOD SetRootResource(nsIRDFResource* resource);
|
1999-04-12 19:02:12 +00:00
|
|
|
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-03-10 01:37:31 +00:00
|
|
|
NS_IMETHOD GetDocumentDataSource(nsIRDFDataSource** aDatasource);
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-05-04 23:32:25 +00:00
|
|
|
// nsIDOMEventCapturer interface
|
|
|
|
NS_IMETHOD CaptureEvent(const nsString& aType);
|
|
|
|
NS_IMETHOD ReleaseEvent(const nsString& aType);
|
|
|
|
|
|
|
|
// nsIDOMEventReceiver interface (yuck. inherited from nsIDOMEventCapturer)
|
|
|
|
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
|
|
|
|
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
|
|
|
|
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
|
|
|
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
|
|
|
|
|
|
|
|
// nsIDOMEventTarget interface
|
|
|
|
NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener,
|
|
|
|
PRBool aPostProcess, PRBool aUseCapture);
|
|
|
|
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
|
|
|
|
PRBool aPostProcess, PRBool aUseCapture);
|
|
|
|
|
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-03-10 01:37:31 +00:00
|
|
|
|
|
|
|
// nsIXULParentDocument interface
|
|
|
|
NS_IMETHOD GetContentViewerContainer(nsIContentViewerContainer** aContainer);
|
|
|
|
NS_IMETHOD GetCommand(nsString& aCommand);
|
|
|
|
|
|
|
|
// nsIXULChildDocument Interface
|
1999-03-10 20:05:12 +00:00
|
|
|
NS_IMETHOD SetFragmentRoot(nsIRDFResource* aFragmentRoot);
|
|
|
|
NS_IMETHOD GetFragmentRoot(nsIRDFResource** aFragmentRoot);
|
1999-03-10 01:37:31 +00:00
|
|
|
|
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-04-16 08:38:17 +00:00
|
|
|
nsresult
|
|
|
|
ParseTagString(const nsString& aTagName, nsIAtom*& aName, PRInt32& aNameSpaceID);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
MakeProperty(PRInt32 aNameSpaceID, nsIAtom* aTag, nsIRDFResource** aResult);
|
|
|
|
|
1999-04-23 16:48:33 +00:00
|
|
|
protected:
|
|
|
|
nsresult PrepareToLoad( nsCOMPtr<nsIParser>* created_parser,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIURL* aOptionalURL = 0 );
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
protected:
|
1999-02-24 04:46:47 +00:00
|
|
|
// pseudo constants
|
|
|
|
static PRInt32 gRefCnt;
|
|
|
|
static nsIAtom* kIdAtom;
|
|
|
|
static nsIAtom* kObservesAtom;
|
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
static nsIRDFService* gRDFService;
|
|
|
|
static nsIRDFResource* kRDF_instanceOf;
|
|
|
|
static nsIRDFResource* kRDF_type;
|
|
|
|
static nsIRDFResource* kXUL_element;
|
|
|
|
|
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-04-30 09:04:36 +00:00
|
|
|
// IMPORTANT: The ownership implicit in the following member variables has been
|
|
|
|
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
|
|
|
|
// pointers for weak (ie, non owning) references. If you add any members to this
|
|
|
|
// class, please make the ownership explicit (pinkerton, scc).
|
|
|
|
// NOTE, THIS IS STILL IN PROGRESS, TALK TO PINK OR SCC BEFORE CHANGING
|
1999-01-14 10:55:08 +00:00
|
|
|
|
1999-04-30 09:04:36 +00:00
|
|
|
nsCOMPtr<nsIArena> mArena;
|
1999-02-16 19:30:04 +00:00
|
|
|
nsVoidArray mObservers;
|
|
|
|
nsAutoString mDocumentTitle;
|
1999-04-30 09:04:36 +00:00
|
|
|
nsIURL* mDocumentURL; // [OWNER] ??? compare with loader
|
|
|
|
nsIURLGroup* mDocumentURLGroup; // [OWNER] leads to loader
|
|
|
|
nsIContent* mRootContent; // [OWNER]
|
1999-02-16 19:30:04 +00:00
|
|
|
nsIDocument* mParentDocument;
|
1999-04-30 09:04:36 +00:00
|
|
|
nsIScriptContextOwner* mScriptContextOwner; // [WEAK] it owns me! (indirectly)
|
|
|
|
void* mScriptObject; // ????
|
1999-04-27 21:49:25 +00:00
|
|
|
nsString mCharSetID;
|
1999-02-16 19:30:04 +00:00
|
|
|
nsVoidArray mStyleSheets;
|
1999-04-30 09:04:36 +00:00
|
|
|
nsIDOMSelection* mSelection; // [OWNER]
|
1999-02-16 19:30:04 +00:00
|
|
|
PRBool mDisplaySelection;
|
|
|
|
nsVoidArray mPresShells;
|
1999-05-04 23:32:25 +00:00
|
|
|
nsIEventListenerManager* mListenerManager;
|
1999-04-30 09:04:36 +00:00
|
|
|
nsINameSpaceManager* mNameSpaceManager; // [OWNER]
|
|
|
|
nsIHTMLStyleSheet* mAttrStyleSheet; // [OWNER]
|
|
|
|
nsCOMPtr<nsIHTMLCSSStyleSheet> mInlineStyleSheet;
|
1999-02-09 03:15:41 +00:00
|
|
|
nsElementMap mResources;
|
1999-04-30 09:04:36 +00:00
|
|
|
nsISupportsArray* mBuilders; // [OWNER] of array, elements shouldn't own this, but they do
|
|
|
|
nsIRDFContentModelBuilder* mXULBuilder; // [OWNER]
|
|
|
|
nsIRDFDataSource* mLocalDataSource; // [OWNER]
|
|
|
|
nsIRDFDataSource* mDocumentDataSource; // [OWNER]
|
|
|
|
nsILineBreaker* mLineBreaker; // [OWNER]
|
|
|
|
nsIWordBreaker* mWordBreaker; // [OWNER]
|
|
|
|
nsIContentViewerContainer* mContentViewerContainer; // [WEAK] it owns me! (indirectly)
|
1999-03-10 01:37:31 +00:00
|
|
|
nsString mCommand;
|
1999-04-30 09:04:36 +00:00
|
|
|
nsIRDFResource* mFragmentRoot; // [OWNER]
|
|
|
|
nsVoidArray mSubDocuments; // [OWNER] of subelements
|
1999-05-15 08:46:14 +00:00
|
|
|
nsIDOMElement* mPopup; // [OWNER] of this popup element in the doc
|
1999-01-14 10:55:08 +00:00
|
|
|
};
|
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
PRInt32 XULDocumentImpl::gRefCnt = 0;
|
1999-02-24 04:46:47 +00:00
|
|
|
nsIAtom* XULDocumentImpl::kIdAtom;
|
|
|
|
nsIAtom* XULDocumentImpl::kObservesAtom;
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
nsIRDFService* XULDocumentImpl::gRDFService;
|
|
|
|
nsIRDFResource* XULDocumentImpl::kRDF_instanceOf;
|
|
|
|
nsIRDFResource* XULDocumentImpl::kRDF_type;
|
|
|
|
nsIRDFResource* XULDocumentImpl::kXUL_element;
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// ctors & dtors
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::XULDocumentImpl(void)
|
1999-04-30 09:04:36 +00:00
|
|
|
: mDocumentURL(nsnull),
|
1998-12-24 05:07:14 +00:00
|
|
|
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-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-04-27 21:49:25 +00:00
|
|
|
mCharSetID("UTF-8"),
|
1999-02-23 03:31:26 +00:00
|
|
|
mLineBreaker(nsnull),
|
1999-03-27 00:58:42 +00:00
|
|
|
mWordBreaker(nsnull),
|
1999-03-10 01:37:31 +00:00
|
|
|
mContentViewerContainer(nsnull),
|
|
|
|
mCommand(""),
|
1999-05-04 23:32:25 +00:00
|
|
|
mFragmentRoot(nsnull),
|
1999-05-15 08:46:14 +00:00
|
|
|
mListenerManager(nsnull),
|
|
|
|
mPopup(nsnull)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// construct a selection object
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRangeListCID,
|
1998-12-24 05:07:14 +00:00
|
|
|
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) {
|
|
|
|
kIdAtom = NS_NewAtom("id");
|
|
|
|
kObservesAtom = NS_NewAtom("observes");
|
1999-04-16 08:38:17 +00:00
|
|
|
|
|
|
|
// Keep the RDF service cached in a member variable to make using
|
|
|
|
// it a bit less painful
|
|
|
|
rv = nsServiceManager::GetService(kRDFServiceCID,
|
|
|
|
kIRDFServiceIID,
|
|
|
|
(nsISupports**) &gRDFService);
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF Service");
|
|
|
|
|
|
|
|
if (gRDFService) {
|
|
|
|
gRDFService->GetResource(kURIRDF_instanceOf, &kRDF_instanceOf);
|
|
|
|
gRDFService->GetResource(kURIRDF_type, &kRDF_type);
|
|
|
|
gRDFService->GetResource(kURIXUL_element, &kXUL_element);
|
|
|
|
}
|
1999-02-24 04:46:47 +00:00
|
|
|
}
|
1999-04-02 19:51:35 +00:00
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (! gMapLog)
|
|
|
|
gMapLog = PR_NewLogModule("nsXULDocumentElementMap");
|
|
|
|
#endif
|
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-05-04 23:32:25 +00:00
|
|
|
NS_IF_RELEASE(mListenerManager);
|
|
|
|
|
1999-05-15 08:46:14 +00:00
|
|
|
NS_IF_RELEASE(mPopup);
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
// mParentDocument is never refcounted
|
1999-03-10 20:05:12 +00:00
|
|
|
// Delete references to sub-documents
|
|
|
|
PRInt32 index = mSubDocuments.Count();
|
|
|
|
while (--index >= 0) {
|
|
|
|
nsIDocument* subdoc = (nsIDocument*) mSubDocuments.ElementAt(index);
|
|
|
|
NS_RELEASE(subdoc);
|
|
|
|
}
|
|
|
|
|
1999-04-30 09:04:36 +00:00
|
|
|
// set all builder references to document to nsnull -- out of band notification
|
|
|
|
// to break ownership cycle
|
1999-04-07 00:27:40 +00:00
|
|
|
if (mBuilders)
|
|
|
|
{
|
1999-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt = 0;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
1999-04-07 00:27:40 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1999-05-13 04:56:04 +00:00
|
|
|
printf("# of builders: %lu\n", (unsigned long)cnt);
|
1999-04-07 00:27:40 +00:00
|
|
|
#endif
|
|
|
|
|
1999-05-13 04:56:04 +00:00
|
|
|
for (PRUint32 i = 0; i < cnt; ++i)
|
1999-04-07 00:27:40 +00:00
|
|
|
{
|
|
|
|
// XXX we should QueryInterface() here
|
|
|
|
nsIRDFContentModelBuilder* builder
|
|
|
|
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
|
|
|
|
|
|
|
NS_ASSERTION(builder != nsnull, "null ptr");
|
|
|
|
if (! builder)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsresult rv = builder->SetDocument(nsnull);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "error creating content");
|
|
|
|
// XXX ignore error code?
|
|
|
|
|
|
|
|
NS_RELEASE(builder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(mAttrStyleSheet);
|
|
|
|
NS_IF_RELEASE(mRootContent);
|
|
|
|
NS_IF_RELEASE(mDocumentURLGroup);
|
|
|
|
NS_IF_RELEASE(mDocumentURL);
|
|
|
|
NS_IF_RELEASE(mNameSpaceManager);
|
1999-02-23 03:31:26 +00:00
|
|
|
NS_IF_RELEASE(mLineBreaker);
|
1999-03-27 00:58:42 +00:00
|
|
|
NS_IF_RELEASE(mWordBreaker);
|
1999-03-10 01:37:31 +00:00
|
|
|
NS_IF_RELEASE(mFragmentRoot);
|
1999-03-10 20:05:12 +00:00
|
|
|
|
1999-02-24 04:46:47 +00:00
|
|
|
if (--gRefCnt == 0) {
|
|
|
|
NS_IF_RELEASE(kIdAtom);
|
|
|
|
NS_IF_RELEASE(kObservesAtom);
|
1999-04-16 08:38:17 +00:00
|
|
|
|
|
|
|
if (gRDFService) {
|
|
|
|
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
|
|
|
|
gRDFService = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(kRDF_instanceOf);
|
|
|
|
NS_IF_RELEASE(kRDF_type);
|
|
|
|
NS_IF_RELEASE(kXUL_element);
|
1999-02-24 04:46:47 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
1999-03-10 01:37:31 +00:00
|
|
|
else if (iid.Equals(nsIXULParentDocument::GetIID())) {
|
|
|
|
*result = NS_STATIC_CAST(nsIXULParentDocument*, this);
|
|
|
|
}
|
|
|
|
else if (iid.Equals(nsIXULChildDocument::GetIID())) {
|
|
|
|
*result = NS_STATIC_CAST(nsIXULChildDocument*, this);
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
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);
|
|
|
|
}
|
1999-05-04 23:32:25 +00:00
|
|
|
else if (iid.Equals(kIDOMEventReceiverIID)) {
|
|
|
|
*result = NS_STATIC_CAST(nsIDOMEventReceiver*, this);
|
|
|
|
}
|
|
|
|
else if (iid.Equals(kIDOMEventTargetIID)) {
|
|
|
|
*result = NS_STATIC_CAST(nsIDOMEventTarget*, this);
|
|
|
|
}
|
|
|
|
else if (iid.Equals(kIDOMEventCapturerIID)) {
|
|
|
|
*result = NS_STATIC_CAST(nsIDOMEventCapturer*, this);
|
|
|
|
}
|
1999-04-23 16:48:33 +00:00
|
|
|
else if (iid.Equals(nsIStreamLoadableDocument::GetIID())) {
|
|
|
|
*result = NS_STATIC_CAST(nsIStreamLoadableDocument*, this);
|
|
|
|
}
|
1999-02-17 11:56:15 +00:00
|
|
|
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
|
|
|
{
|
1999-04-30 09:04:36 +00:00
|
|
|
nsIArena* result = mArena;
|
|
|
|
NS_IF_ADDREF(result);
|
|
|
|
return result;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-05-11 20:22:52 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetContentType(nsString& aContentType) const
|
|
|
|
{
|
|
|
|
// XXX Is this right, Chris?
|
|
|
|
aContentType.SetString("text/xul");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-23 16:48:33 +00:00
|
|
|
static
|
|
|
|
nsresult
|
|
|
|
generate_RDF_seed( nsString* result, nsIURL* aOptionalURL )
|
|
|
|
{
|
|
|
|
nsresult status = NS_OK;
|
|
|
|
|
|
|
|
if ( aOptionalURL )
|
|
|
|
{
|
|
|
|
const char* s = 0;
|
|
|
|
if ( NS_SUCCEEDED(status = aOptionalURL->GetSpec(&s)) )
|
|
|
|
(*result) = s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static int unique_per_session_index = 0;
|
|
|
|
|
|
|
|
result->Append("x-anonymous-xul://");
|
|
|
|
result->Append(PRInt32(++unique_per_session_index), /*base*/ 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XULDocumentImpl::PrepareToLoad( nsCOMPtr<nsIParser>* created_parser,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIURL* aOptionalURL )
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURL> syntheticURL;
|
|
|
|
if ( aOptionalURL )
|
|
|
|
syntheticURL = dont_QueryInterface(aOptionalURL);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsString seedString;
|
|
|
|
generate_RDF_seed(&seedString, 0);
|
|
|
|
NS_NewURL(getter_AddRefs(syntheticURL), seedString);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
1999-02-04 10:50:50 +00:00
|
|
|
NS_ASSERTION(aURL != nsnull, "null ptr");
|
|
|
|
if (! aURL)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-04-23 16:48:33 +00:00
|
|
|
#endif
|
1999-02-04 10:50:50 +00:00
|
|
|
|
1999-03-10 01:37:31 +00:00
|
|
|
if (aContainer && aContainer != mContentViewerContainer)
|
|
|
|
mContentViewerContainer = aContainer;
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
mDocumentTitle.Truncate();
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mDocumentURL);
|
|
|
|
NS_IF_RELEASE(mDocumentURLGroup);
|
1999-04-23 16:48:33 +00:00
|
|
|
|
|
|
|
mDocumentURL = syntheticURL;
|
|
|
|
NS_ADDREF(mDocumentURL);
|
|
|
|
syntheticURL->GetURLGroup(&mDocumentURLGroup);
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
|
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;
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv = nsComponentManager::CreateInstance(kHTMLStyleSheetCID,
|
1999-01-14 10:55:08 +00:00
|
|
|
nsnull,
|
|
|
|
kIHTMLStyleSheetIID,
|
|
|
|
(void**) &sheet))) {
|
1999-04-23 16:48:33 +00:00
|
|
|
if (NS_SUCCEEDED(rv = sheet->Init(syntheticURL, this))) {
|
1999-01-14 10:55:08 +00:00
|
|
|
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;
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv = nsComponentManager::CreateInstance(kHTMLCSSStyleSheetCID,
|
1999-03-05 00:01:26 +00:00
|
|
|
nsnull,
|
|
|
|
kIHTMLCSSStyleSheetIID,
|
1999-04-30 09:04:36 +00:00
|
|
|
(void**)&inlineSheet))) {
|
1999-04-23 16:48:33 +00:00
|
|
|
if (NS_SUCCEEDED(rv = inlineSheet->Init(syntheticURL, this))) {
|
1999-04-30 09:04:36 +00:00
|
|
|
mInlineStyleSheet = dont_QueryInterface(inlineSheet);
|
1999-03-05 00:01:26 +00:00
|
|
|
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-03-11 19:49:32 +00:00
|
|
|
// Create the composite data source and builder, but only do this if we're
|
1999-03-10 01:37:31 +00:00
|
|
|
// not a XUL fragment.
|
|
|
|
if (mFragmentRoot == nsnull) {
|
|
|
|
|
1999-04-12 19:02:12 +00:00
|
|
|
nsCOMPtr<nsIRDFCompositeDataSource> db;
|
1999-04-06 22:55:26 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kRDFCompositeDataSourceCID,
|
|
|
|
nsnull,
|
|
|
|
kIRDFCompositeDataSourceIID,
|
1999-04-12 19:02:12 +00:00
|
|
|
(void**) getter_AddRefs(db));
|
1999-04-06 22:55:26 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
1999-03-10 01:37:31 +00:00
|
|
|
NS_ERROR("couldn't create composite datasource");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-03-10 01:37:31 +00:00
|
|
|
// Create a XUL content model builder
|
|
|
|
NS_IF_RELEASE(mXULBuilder);
|
1999-04-06 22:55:26 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kRDFXULBuilderCID,
|
|
|
|
nsnull,
|
|
|
|
kIRDFContentModelBuilderIID,
|
|
|
|
(void**) &mXULBuilder);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
1999-03-10 01:37:31 +00:00
|
|
|
NS_ERROR("couldn't create XUL builder");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-03-10 01:37:31 +00:00
|
|
|
if (NS_FAILED(rv = mXULBuilder->SetDataBase(db))) {
|
|
|
|
NS_ERROR("couldn't set builder's db");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-03-10 01:37:31 +00:00
|
|
|
NS_IF_RELEASE(mBuilders);
|
|
|
|
if (NS_FAILED(rv = AddContentModelBuilder(mXULBuilder))) {
|
|
|
|
NS_ERROR("could't add XUL builder");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-03-10 01:37:31 +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.)
|
|
|
|
//
|
|
|
|
// 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-04-28 20:46:53 +00:00
|
|
|
#if 0
|
1999-04-16 08:38:17 +00:00
|
|
|
rv = gRDFService->GetDataSource("rdf:local-store", &mLocalDataSource);
|
1999-04-06 22:55:26 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
1999-03-10 01:37:31 +00:00
|
|
|
NS_ERROR("couldn't create local data source");
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-03-10 01:37:31 +00:00
|
|
|
if (NS_FAILED(rv = db->AddDataSource(mLocalDataSource))) {
|
|
|
|
NS_ERROR("couldn't add local data source to db");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-04-28 20:46:53 +00:00
|
|
|
#endif
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-04-23 16:48:33 +00:00
|
|
|
#if 0
|
1999-03-10 01:37:31 +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.
|
|
|
|
const char* uri;
|
|
|
|
if (NS_FAILED(rv = aURL->GetSpec(&uri)))
|
|
|
|
return rv;
|
1999-04-23 16:48:33 +00:00
|
|
|
#endif
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-03-10 01:37:31 +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 = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
|
|
|
|
nsnull,
|
|
|
|
kIRDFDataSourceIID,
|
|
|
|
(void**) &mDocumentDataSource))) {
|
|
|
|
NS_ERROR("unable to create XUL datasource");
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-03-10 01:37:31 +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-04-23 16:48:33 +00:00
|
|
|
const char* seedCString = 0;
|
|
|
|
syntheticURL->GetSpec(&seedCString);
|
|
|
|
if (NS_FAILED(rv = mDocumentDataSource->Init(seedCString))) {
|
1999-03-10 01:37:31 +00:00
|
|
|
NS_ERROR("unable to initialize XUL data source");
|
|
|
|
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
|
|
|
nsCOMPtr<nsIXULContentSink> sink;
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kXULContentSinkCID,
|
1999-02-16 19:30:04 +00:00
|
|
|
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
|
|
|
{
|
1999-03-12 05:21:25 +00:00
|
|
|
if (NS_FAILED(rv = sink->Init(this, mDocumentDataSource))) {
|
1999-02-16 19:30:04 +00:00
|
|
|
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-04-06 07:48:21 +00:00
|
|
|
nsCOMPtr<nsIParser> parser;
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kParserCID,
|
1999-02-16 19:30:04 +00:00
|
|
|
nsnull,
|
|
|
|
kIParserIID,
|
1999-04-07 00:07:28 +00:00
|
|
|
(void**) getter_AddRefs(parser)))) {
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_ERROR("unable to create parser");
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
nsCOMPtr<nsIDTD> dtd;
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kWellFormedDTDCID,
|
1999-02-16 19:30:04 +00:00
|
|
|
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
|
|
|
|
1999-03-10 01:37:31 +00:00
|
|
|
mCommand = aCommand;
|
|
|
|
|
1999-04-06 07:48:21 +00:00
|
|
|
parser->RegisterDTD(dtd);
|
|
|
|
parser->SetCommand(aCommand);
|
1999-04-27 21:49:25 +00:00
|
|
|
nsAutoString utf8("UTF-8");
|
|
|
|
parser->SetDocumentCharset(utf8, kCharsetFromDocTypeDefault);
|
1999-04-06 07:48:21 +00:00
|
|
|
parser->SetContentSink(sink); // grabs a reference to the parser
|
1999-04-23 16:48:33 +00:00
|
|
|
|
|
|
|
*created_parser = parser;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::StartDocumentLoad(nsIURL *aURL,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener **aDocListener,
|
|
|
|
const char* aCommand)
|
|
|
|
{
|
|
|
|
nsresult status;
|
|
|
|
nsCOMPtr<nsIParser> parser;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ( NS_FAILED(status = PrepareToLoad(&parser, aContainer, aCommand, aURL)) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStreamListener> listener = do_QueryInterface(parser, &status);
|
|
|
|
if ( NS_FAILED(status) )
|
|
|
|
{
|
|
|
|
NS_ERROR("parser doesn't support nsIStreamListener");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aDocListener = listener;
|
|
|
|
NS_IF_ADDREF(*aDocListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
parser->Parse(aURL);
|
|
|
|
}
|
1999-04-23 19:03:01 +00:00
|
|
|
while(0);
|
1999-02-03 02:48:55 +00:00
|
|
|
|
1999-04-23 16:48:33 +00:00
|
|
|
return status;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-04-23 16:48:33 +00:00
|
|
|
nsresult
|
|
|
|
XULDocumentImpl::LoadFromStream( nsIInputStream& xulStream,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
const char* aCommand )
|
|
|
|
{
|
|
|
|
nsresult status;
|
|
|
|
nsCOMPtr<nsIParser> parser;
|
|
|
|
if ( NS_SUCCEEDED(status = PrepareToLoad(&parser, aContainer, aCommand)) )
|
|
|
|
parser->Parse(xulStream);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
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-04-27 21:49:25 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetDocumentCharacterSet(nsString& oCharSetID)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-04-27 21:49:25 +00:00
|
|
|
oCharSetID = mCharSetID;
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 21:49:25 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::SetDocumentCharacterSet(const nsString& aCharSetID)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
mCharSetID = aCharSetID;
|
1999-04-27 21:49:25 +00:00
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
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-03-27 00:58:42 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetWordBreaker(nsIWordBreaker** aResult)
|
|
|
|
{
|
|
|
|
if(nsnull == mWordBreaker ) {
|
|
|
|
// no line breaker, find a default one
|
|
|
|
nsIWordBreakerFactory *lf;
|
|
|
|
nsresult result;
|
|
|
|
result = nsServiceManager::GetService(kLWBrkCID,
|
|
|
|
kIWordBreakerFactoryIID,
|
|
|
|
(nsISupports **)&lf);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsIWordBreaker *lb = nsnull ;
|
|
|
|
nsAutoString lbarg("");
|
|
|
|
result = lf->GetBreaker(lbarg, &lb);
|
|
|
|
if(NS_SUCCEEDED(result)) {
|
|
|
|
mWordBreaker = lb;
|
|
|
|
}
|
|
|
|
result = nsServiceManager::ReleaseService(kLWBrkCID, lf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aResult = mWordBreaker;
|
|
|
|
NS_IF_ADDREF(mWordBreaker);
|
|
|
|
return NS_OK; // XXX we should do error handling here
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::SetWordBreaker(nsIWordBreaker* aWordBreaker)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mWordBreaker);
|
|
|
|
mWordBreaker = aWordBreaker;
|
|
|
|
NS_IF_ADDREF(mWordBreaker);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-23 03:31:26 +00:00
|
|
|
|
|
|
|
|
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;
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kPresShellCID,
|
1998-12-24 05:07:14 +00:00
|
|
|
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-04-30 09:04:36 +00:00
|
|
|
*aInstancePtrResult = shell; // addref implicit in CreateInstance()
|
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
|
|
|
{
|
1999-03-10 20:05:12 +00:00
|
|
|
NS_ADDREF(aSubDoc);
|
|
|
|
mSubDocuments.AppendElement(aSubDoc);
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetNumberOfSubDocuments()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-03-10 20:05:12 +00:00
|
|
|
return mSubDocuments.Count();
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument*
|
1999-02-09 03:15:41 +00:00
|
|
|
XULDocumentImpl::GetSubDocumentAt(PRInt32 aIndex)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-03-10 20:05:12 +00:00
|
|
|
nsIDocument* doc = (nsIDocument*) mSubDocuments.ElementAt(aIndex);
|
|
|
|
if (nsnull != doc) {
|
|
|
|
NS_ADDREF(doc);
|
|
|
|
}
|
|
|
|
return doc;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-03-31 20:49:42 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::AppendToProlog(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::AppendToEpilog(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::ChildAt(PRInt32 aIndex, nsIContent*& aResult) const
|
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const
|
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetChildCount(PRInt32& aCount)
|
|
|
|
{
|
|
|
|
PR_ASSERT(0);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
mScriptContextOwner = aScriptContextOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
1999-04-20 00:00:02 +00:00
|
|
|
XULDocumentImpl::ContentStatesChanged(nsIContent* aContent1, nsIContent* aContent2)
|
1999-02-27 07:15:09 +00:00
|
|
|
{
|
|
|
|
PRInt32 count = mObservers.Count();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
1999-04-20 00:00:02 +00:00
|
|
|
observer->ContentStatesChanged(this, aContent1, aContent2);
|
1999-02-27 07:15:09 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
1999-05-16 07:05:51 +00:00
|
|
|
nsresult ret = NS_OK;
|
|
|
|
nsIDOMEvent* domEvent = nsnull;
|
|
|
|
|
|
|
|
if (NS_EVENT_FLAG_INIT == aFlags) {
|
|
|
|
aDOMEvent = &domEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Capturing stage
|
|
|
|
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
|
|
|
|
// XXX Check back with nsGenericDocument.cpp later to find out if this
|
|
|
|
// has been implemented.
|
|
|
|
}
|
|
|
|
|
|
|
|
//Local handling stage
|
|
|
|
if (nsnull != mListenerManager) {
|
|
|
|
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Bubbling stage
|
|
|
|
if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptContextOwner) {
|
|
|
|
nsIScriptGlobalObject* global;
|
|
|
|
if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(&global)) {
|
|
|
|
global->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus);
|
|
|
|
NS_RELEASE(global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_EVENT_FLAG_INIT == aFlags) {
|
|
|
|
// We're leaving the DOM event loop so if we created a DOM event, release here.
|
|
|
|
if (nsnull != *aDOMEvent) {
|
|
|
|
nsrefcnt rc;
|
|
|
|
NS_RELEASE2(*aDOMEvent, rc);
|
|
|
|
if (0 != rc) {
|
|
|
|
//Okay, so someone in the DOM loop (a listener, JS object) still has a ref to the DOM Event but
|
|
|
|
//the internal data hasn't been malloc'd. Force a copy of the data here so the DOM Event is still valid.
|
|
|
|
nsIPrivateDOMEvent *privateEvent;
|
|
|
|
if (NS_OK == (*aDOMEvent)->QueryInterface(kIPrivateDOMEventIID, (void**)&privateEvent)) {
|
|
|
|
privateEvent->DuplicatePrivateData();
|
|
|
|
NS_RELEASE(privateEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aDOMEvent = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIXMLDocument interface
|
1999-03-20 01:51:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetContentById(const nsString& aName, nsIContent** aContent)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
1999-03-29 19:52:54 +00:00
|
|
|
nsXPIDLCString p;
|
|
|
|
aProperty->GetValue( getter_Copies(p) );
|
1999-01-12 19:41:06 +00:00
|
|
|
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;
|
|
|
|
|
1999-04-02 19:51:35 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gMapLog, PR_LOG_ALWAYS)) {
|
|
|
|
nsXPIDLCString uri;
|
|
|
|
aResource->GetValue( getter_Copies(uri) );
|
|
|
|
PR_LOG(gMapLog, PR_LOG_ALWAYS,
|
|
|
|
("xulelemap(%p) add [%p] <-- %s\n",
|
|
|
|
this, aElement, (const char*) uri));
|
|
|
|
}
|
1999-03-18 20:46:02 +00:00
|
|
|
#endif
|
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
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-04-02 19:51:35 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gMapLog, PR_LOG_ALWAYS)) {
|
|
|
|
nsXPIDLCString uri;
|
|
|
|
aResource->GetValue( getter_Copies(uri) );
|
|
|
|
PR_LOG(gMapLog, PR_LOG_ALWAYS,
|
1999-04-28 04:19:28 +00:00
|
|
|
("xulelemap(%p) remove [%p] <-- %s\n",
|
1999-04-02 19:51:35 +00:00
|
|
|
this, aElement, (const char*) uri));
|
|
|
|
}
|
1999-03-18 20:46:02 +00:00
|
|
|
#endif
|
|
|
|
|
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-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt = 0;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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-03-05 22:33:27 +00:00
|
|
|
nsIContent* childContent = nsnull;
|
|
|
|
aElement->ChildAt(j, childContent);
|
1999-02-17 18:33:33 +00:00
|
|
|
|
1999-03-05 22:33:27 +00:00
|
|
|
if (!childContent)
|
1999-02-17 18:33:33 +00:00
|
|
|
break;
|
|
|
|
|
1999-03-05 22:33:27 +00:00
|
|
|
nsIAtom* tag = nsnull;
|
|
|
|
childContent->GetTag(tag);
|
1999-02-17 18:33:33 +00:00
|
|
|
|
1999-03-05 22:33:27 +00:00
|
|
|
if (!tag)
|
1999-02-17 18:33:33 +00:00
|
|
|
break;
|
|
|
|
|
1999-03-09 19:30:41 +00:00
|
|
|
if (tag == kObservesAtom)
|
1999-02-17 18:33:33 +00:00
|
|
|
{
|
|
|
|
// Find the node that we're supposed to be
|
|
|
|
// observing and perform the hookup.
|
|
|
|
nsString elementValue;
|
|
|
|
nsString attributeValue;
|
1999-03-09 19:30:41 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domContent;
|
|
|
|
domContent = do_QueryInterface(childContent);
|
1999-02-17 18:33:33 +00:00
|
|
|
|
1999-03-09 19:30:41 +00:00
|
|
|
domContent->GetAttribute("element",
|
|
|
|
elementValue);
|
1999-02-17 18:33:33 +00:00
|
|
|
|
1999-03-09 19:30:41 +00:00
|
|
|
domContent->GetAttribute("attribute",
|
|
|
|
attributeValue);
|
1999-02-17 18:33:33 +00:00
|
|
|
|
1999-03-05 22:33:27 +00:00
|
|
|
nsIDOMElement* domElement = nsnull;
|
|
|
|
GetElementById(elementValue, &domElement);
|
1999-02-17 18:33:33 +00:00
|
|
|
|
1999-03-05 22:33:27 +00:00
|
|
|
if (!domElement)
|
1999-02-17 18:33:33 +00:00
|
|
|
break;
|
|
|
|
|
1999-03-05 22:33:27 +00:00
|
|
|
// We have a DOM element to bind to. Add a broadcast
|
|
|
|
// listener to that element, but only if it's a XUL element.
|
1999-02-17 18:33:33 +00:00
|
|
|
// XXX: Handle context nodes.
|
1999-03-05 22:33:27 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> listener( do_QueryInterface(aElement) );
|
|
|
|
nsCOMPtr<nsIDOMXULElement> broadcaster( do_QueryInterface(domElement) );
|
|
|
|
if (listener)
|
1999-02-17 18:33:33 +00:00
|
|
|
{
|
1999-03-05 22:33:27 +00:00
|
|
|
broadcaster->AddBroadcastListener(attributeValue,
|
|
|
|
listener);
|
1999-02-17 18:33:33 +00:00
|
|
|
}
|
|
|
|
|
1999-03-05 22:33:27 +00:00
|
|
|
NS_RELEASE(domElement);
|
1999-02-17 18:33:33 +00:00
|
|
|
}
|
|
|
|
|
1999-03-05 22:33:27 +00:00
|
|
|
NS_RELEASE(childContent);
|
|
|
|
NS_RELEASE(tag);
|
1999-02-17 18:33:33 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-04-14 23:06:22 +00:00
|
|
|
return mBuilders->AppendElement(aBuilder) ? NS_OK : NS_ERROR_FAILURE;
|
1999-02-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
1999-03-10 01:37:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetDocumentDataSource(nsIRDFDataSource** aDataSource) {
|
|
|
|
if (mDocumentDataSource) {
|
|
|
|
NS_ADDREF(mDocumentDataSource);
|
|
|
|
*aDataSource = mDocumentDataSource;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aReturn != nsnull, "null ptr");
|
|
|
|
if (! aReturn)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// we need this so that we can create a resource URI
|
|
|
|
NS_PRECONDITION(mDocumentURL != nsnull, "not initialized");
|
|
|
|
if (! mDocumentURL)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> name;
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
|
|
|
|
// parse the user-provided string into a tag name and a namespace ID
|
|
|
|
rv = ParseTagString(aTagName, *getter_AddRefs(name), nameSpaceID);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to parse tag name");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// construct an element
|
|
|
|
nsCOMPtr<nsIContent> result;
|
|
|
|
rv = NS_NewRDFElement(nameSpaceID, name, getter_AddRefs(result));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// assign it an "anonymous" identifier so that it can be referred
|
|
|
|
// to in the graph.
|
|
|
|
nsCOMPtr<nsIRDFResource> resource;
|
|
|
|
const char* context;
|
|
|
|
rv = mDocumentURL->GetSpec(&context);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = rdf_CreateAnonymousResource(context, getter_AddRefs(resource));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsXPIDLCString uri;
|
|
|
|
rv = resource->GetValue(getter_Copies(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = result->SetAttribute(kNameSpaceID_None, kIdAtom, (const char*) uri, PR_FALSE);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set element's ID");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Set it's RDF:type in the graph s.t. the element's tag can be
|
|
|
|
// constructed from it.
|
|
|
|
nsCOMPtr<nsIRDFResource> type;
|
|
|
|
rv = MakeProperty(nameSpaceID, name, getter_AddRefs(type));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mDocumentDataSource->Assert(resource, kRDF_type, type, PR_TRUE);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set element's tag info in graph");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Mark it as a XUL element
|
|
|
|
rv = mDocumentDataSource->Assert(resource, kRDF_instanceOf, kXUL_element, PR_TRUE);
|
|
|
|
NS_ASSERTION(rv == NS_OK, "unable to mark as XUL element");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-04-27 05:53:53 +00:00
|
|
|
{
|
|
|
|
NS_WITH_SERVICE(nsIRDFContainerUtils, rdfc, kRDFContainerUtilsCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = rdfc->MakeSeq(mDocumentDataSource, resource, nsnull);
|
|
|
|
NS_ASSERTION(rv == NS_OK, "unable to mark as XUL element");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-04-16 08:38:17 +00:00
|
|
|
|
|
|
|
// `this' will be its document
|
|
|
|
rv = result->SetDocument(this, PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// get the DOM interface
|
|
|
|
rv = result->QueryInterface(nsIDOMElement::GetIID(), (void**) aReturn);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "not a DOM element");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
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-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aReturn != nsnull, "null ptr");
|
|
|
|
if (! aReturn)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITextContent> text;
|
|
|
|
rv = nsComponentManager::CreateInstance(kTextNodeCID, nsnull, nsITextContent::GetIID(), getter_AddRefs(text));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = text->SetText(aData.GetUnicode(), aData.Length(), PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = text->QueryInterface(nsIDOMText::GetIID(), (void**) aReturn);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "not a DOMText");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
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
|
|
|
|
|
1999-05-15 08:46:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetPopup(nsIDOMElement** anElement)
|
|
|
|
{
|
|
|
|
*anElement = mPopup;
|
|
|
|
NS_IF_ADDREF(mPopup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::SetPopup(nsIDOMElement* anElement)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mPopup);
|
|
|
|
NS_IF_ADDREF(anElement);
|
|
|
|
mPopup = anElement;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-17 11:09:57 +00:00
|
|
|
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
|
|
|
{
|
1999-04-01 02:30:03 +00:00
|
|
|
NS_PRECONDITION(mRootContent != nsnull, "document contains no content");
|
|
|
|
if (! mRootContent)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED; // XXX right error code?
|
|
|
|
|
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;
|
1999-04-22 06:06:17 +00:00
|
|
|
if (NS_FAILED(rv = gRDFService->GetUnicodeResource(uri.GetUnicode(), getter_AddRefs(resource)))) {
|
1999-02-17 11:09:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt = 0;
|
|
|
|
rv = elements->Count(&cnt);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
|
|
|
if (cnt > 0) {
|
|
|
|
if (cnt > 1) {
|
1999-03-18 20:46:02 +00:00
|
|
|
// This is a scary case that our API doesn't deal with well.
|
|
|
|
NS_WARNING("more than one element found with specified ID; returning first");
|
|
|
|
}
|
|
|
|
|
1999-02-17 11:09:57 +00:00
|
|
|
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-03-18 23:04:58 +00:00
|
|
|
// Didn't find it in our hash table. Walk the tree looking for the
|
|
|
|
// node. This happens for elements that aren't nsRDFElement
|
|
|
|
// objects (e.g., HTML content).
|
1999-03-18 20:46:02 +00:00
|
|
|
|
1999-02-17 18:46:23 +00:00
|
|
|
*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-03-10 01:37:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIXULParentDocument interface
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetContentViewerContainer(nsIContentViewerContainer** aContainer)
|
|
|
|
{
|
1999-04-30 09:04:36 +00:00
|
|
|
NS_PRECONDITION ( aContainer, "Null Parameter into GetContentViewerContainer" );
|
|
|
|
|
|
|
|
*aContainer = mContentViewerContainer;
|
|
|
|
NS_IF_ADDREF(*aContainer);
|
1999-03-10 01:37:31 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetCommand(nsString& aCommand)
|
|
|
|
{
|
|
|
|
aCommand = mCommand;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIXULChildDocument interface
|
|
|
|
NS_IMETHODIMP
|
1999-03-10 20:05:12 +00:00
|
|
|
XULDocumentImpl::SetFragmentRoot(nsIRDFResource* aFragmentRoot)
|
1999-03-10 01:37:31 +00:00
|
|
|
{
|
|
|
|
if (aFragmentRoot != mFragmentRoot)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mFragmentRoot);
|
|
|
|
NS_IF_ADDREF(aFragmentRoot);
|
|
|
|
mFragmentRoot = aFragmentRoot;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-03-10 20:05:12 +00:00
|
|
|
XULDocumentImpl::GetFragmentRoot(nsIRDFResource** aFragmentRoot)
|
1999-03-10 01:37:31 +00:00
|
|
|
{
|
|
|
|
if (mFragmentRoot) {
|
|
|
|
NS_ADDREF(mFragmentRoot);
|
|
|
|
*aFragmentRoot = mFragmentRoot;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMNode interface
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetNodeName(nsString& aNodeName)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
aNodeName.SetString("#document");
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetNodeValue(nsString& aNodeValue)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
aNodeValue.Truncate();
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::SetNodeValue(const nsString& aNodeValue)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetNodeType(PRUint16* aNodeType)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
*aNodeType = nsIDOMNode::DOCUMENT_NODE;
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aChildNodes != nsnull, "null ptr");
|
|
|
|
if (! aChildNodes)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mRootContent) {
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
*aChildNodes = nsnull;
|
|
|
|
|
|
|
|
nsRDFDOMNodeList* children;
|
|
|
|
rv = nsRDFDOMNodeList::Create(&children);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-05-04 23:32:25 +00:00
|
|
|
nsIDOMNode* domNode = nsnull;
|
1999-04-24 05:53:00 +00:00
|
|
|
rv = mRootContent->QueryInterface(nsIDOMNode::GetIID(), (void**)&domNode);
|
1999-04-16 08:38:17 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "root content is not a DOM node");
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = children->AppendNode(domNode);
|
|
|
|
NS_RELEASE(domNode);
|
|
|
|
|
|
|
|
*aChildNodes = children;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here, something bad happened.
|
|
|
|
NS_RELEASE(children);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aChildNodes = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::HasChildNodes(PRBool* aHasChildNodes)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aHasChildNodes != nsnull, "null ptr");
|
|
|
|
if (! aHasChildNodes)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mRootContent) {
|
|
|
|
*aHasChildNodes = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aHasChildNodes = PR_FALSE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetFirstChild(nsIDOMNode** aFirstChild)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aFirstChild != nsnull, "null ptr");
|
|
|
|
if (! aFirstChild)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mRootContent) {
|
|
|
|
return mRootContent->QueryInterface(nsIDOMNode::GetIID(), (void**) aFirstChild);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aFirstChild = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetLastChild(nsIDOMNode** aLastChild)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aLastChild != nsnull, "null ptr");
|
|
|
|
if (! aLastChild)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mRootContent) {
|
|
|
|
return mRootContent->QueryInterface(nsIDOMNode::GetIID(), (void**) aLastChild);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aLastChild = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aPreviousSibling != nsnull, "null ptr");
|
|
|
|
if (! aPreviousSibling)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aPreviousSibling = nsnull;
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetNextSibling(nsIDOMNode** aNextSibling)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aNextSibling != nsnull, "null ptr");
|
|
|
|
if (! aNextSibling)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aNextSibling = nsnull;
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aAttributes != nsnull, "null ptr");
|
|
|
|
if (! aAttributes)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aAttributes = nsnull;
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
NS_PRECONDITION(aOwnerDocument != nsnull, "null ptr");
|
|
|
|
if (! aOwnerDocument)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aOwnerDocument = nsnull;
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
1999-04-16 08:38:17 +00:00
|
|
|
// We don't allow cloning of a document
|
|
|
|
*aReturn = nsnull;
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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;
|
1999-04-30 09:04:36 +00:00
|
|
|
if (!mInlineStyleSheet) {
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE; // probably not the right error...
|
|
|
|
}
|
|
|
|
else {
|
1999-04-30 09:04:36 +00:00
|
|
|
NS_ADDREF(*aResult);
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIDOMNodeObserver interface
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::OnSetNodeValue(nsIDOMNode* aNode, const nsString& aValue)
|
|
|
|
{
|
1999-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBuilders->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt; ++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;
|
1999-03-09 09:44:27 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kCSSParserCID,
|
1999-01-14 10:55:08 +00:00
|
|
|
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-04-16 08:38:17 +00:00
|
|
|
if (NS_FAILED(rv = gRDFService->GetDataSource(uri, getter_AddRefs(ds)))) {
|
1999-02-09 03:15:41 +00:00
|
|
|
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;
|
|
|
|
|
1999-04-30 09:04:36 +00:00
|
|
|
if (NS_FAILED(rv = NS_NewHeapArena(getter_AddRefs(mArena), nsnull)))
|
1999-02-01 22:34:51 +00:00
|
|
|
return rv;
|
|
|
|
|
1999-02-04 10:50:50 +00:00
|
|
|
// Create a namespace manager so we can manage tags
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID,
|
1999-02-01 22:34:51 +00:00
|
|
|
nsnull,
|
|
|
|
kINameSpaceManagerIID,
|
|
|
|
(void**) &mNameSpaceManager)))
|
|
|
|
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
|
|
|
{
|
1999-03-10 20:05:12 +00:00
|
|
|
if (mFragmentRoot)
|
|
|
|
return NS_OK; // Subdocuments rely on the parent document for layout
|
|
|
|
|
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-04-10 04:49:21 +00:00
|
|
|
|
|
|
|
if (cx) {
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
cx->GetContainer(getter_AddRefs(container));
|
|
|
|
if (container) {
|
|
|
|
nsCOMPtr<nsIWebShell> webShell;
|
|
|
|
webShell = do_QueryInterface(container);
|
|
|
|
if (webShell) {
|
|
|
|
nsCOMPtr<nsIStyleContext> styleContext;
|
|
|
|
if (NS_SUCCEEDED(cx->ResolveStyleContextFor(mRootContent, nsnull,
|
|
|
|
PR_FALSE,
|
|
|
|
getter_AddRefs(styleContext)))) {
|
|
|
|
|
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
|
|
|
styleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
|
|
|
|
webShell->SetScrolling(disp->mOverflow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect r;
|
1999-01-14 10:55:08 +00:00
|
|
|
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
|
1999-03-05 22:33:27 +00:00
|
|
|
// create kids before the root frame is established.
|
1999-01-14 10:55:08 +00:00
|
|
|
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,
|
1999-03-09 08:10:50 +00:00
|
|
|
const nsString& aAttribute,
|
|
|
|
const nsString& aValue,
|
|
|
|
nsRDFDOMNodeList* aElements)
|
1999-02-23 02:40:51 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-02-25 02:58:11 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
element = do_QueryInterface(aNode);
|
|
|
|
if (!element)
|
1999-03-09 08:10:50 +00:00
|
|
|
return NS_OK;
|
1999-02-23 02:40:51 +00:00
|
|
|
|
1999-03-09 08:10:50 +00:00
|
|
|
nsAutoString attrValue;
|
|
|
|
if (NS_FAILED(rv = element->GetAttribute(aAttribute, attrValue))) {
|
|
|
|
NS_ERROR("unable to get attribute value");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-02-23 02:40:51 +00:00
|
|
|
|
1999-03-09 08:10:50 +00:00
|
|
|
if ((attrValue == aValue) || (attrValue.Length() > 0 && aValue == "*")) {
|
1999-02-23 02:40:51 +00:00
|
|
|
if (NS_FAILED(rv = aElements->AppendNode(aNode))) {
|
|
|
|
NS_ERROR("unable to append element to node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1999-03-09 08:10:50 +00:00
|
|
|
|
1999-02-23 02:40:51 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
nsresult
|
|
|
|
XULDocumentImpl::ParseTagString(const nsString& aTagName, nsIAtom*& aName, PRInt32& aNameSpaceID)
|
|
|
|
{
|
|
|
|
// Parse the tag into a name and a namespace ID. This is slightly
|
|
|
|
// different than nsIContent::ParseAttributeString() because we
|
|
|
|
// take the default namespace into account (rather than just
|
|
|
|
// assigning "no namespace") in the case that there is no
|
|
|
|
// namespace prefix present.
|
|
|
|
|
|
|
|
static char kNameSpaceSeparator[] = ":";
|
|
|
|
|
|
|
|
// XXX this is a gross hack, but it'll carry us for now. We parse
|
|
|
|
// the tag name using the root content, which presumably has all
|
|
|
|
// the namespace info we need.
|
|
|
|
NS_PRECONDITION(mRootContent != nsnull, "not initialized");
|
|
|
|
if (! mRootContent)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXMLContent> xml( do_QueryInterface(mRootContent) );
|
|
|
|
if (! xml) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsINameSpace> ns;
|
|
|
|
rv = xml->GetContainingNameSpace(*getter_AddRefs(ns));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(ns != nsnull, "expected xml namespace info to be available");
|
|
|
|
if (! ns)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsAutoString prefix;
|
|
|
|
nsAutoString name(aTagName);
|
|
|
|
PRInt32 nsoffset = name.Find(kNameSpaceSeparator);
|
|
|
|
if (-1 != nsoffset) {
|
|
|
|
name.Left(prefix, nsoffset);
|
|
|
|
name.Cut(0, nsoffset+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Figure out the namespace ID
|
|
|
|
nsCOMPtr<nsIAtom> nameSpaceAtom;
|
|
|
|
if (0 < prefix.Length())
|
|
|
|
nameSpaceAtom = getter_AddRefs(NS_NewAtom(prefix));
|
|
|
|
|
|
|
|
rv = ns->FindNameSpaceID(nameSpaceAtom, aNameSpaceID);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
aNameSpaceID = kNameSpaceID_None;
|
|
|
|
|
|
|
|
aName = NS_NewAtom(name);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XULDocumentImpl::MakeProperty(PRInt32 aNameSpaceID, nsIAtom* aTag, nsIRDFResource** aResult)
|
|
|
|
{
|
|
|
|
// Using the namespace ID and the tag, construct a fully-qualified
|
|
|
|
// URI and turn it into an RDF property.
|
|
|
|
|
|
|
|
NS_PRECONDITION(mNameSpaceManager != nsnull, "not initialized");
|
|
|
|
if (! mNameSpaceManager)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoString uri;
|
|
|
|
rv = mNameSpaceManager->GetNameSpaceURI(aNameSpaceID, uri);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get URI for namespace");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (uri.Last() != PRUnichar('#') && uri.Last() != PRUnichar('/'))
|
|
|
|
uri.Append('#');
|
|
|
|
|
|
|
|
uri.Append(aTag->GetUnicode());
|
|
|
|
|
1999-04-22 06:06:17 +00:00
|
|
|
rv = gRDFService->GetUnicodeResource(uri.GetUnicode(), aResult);
|
1999-04-16 08:38:17 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-05-04 23:32:25 +00:00
|
|
|
|
|
|
|
// nsIDOMEventCapturer and nsIDOMEventReceiver Interface Implementations
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
|
|
|
|
{
|
|
|
|
nsIEventListenerManager *manager;
|
|
|
|
|
|
|
|
if (NS_OK == GetListenerManager(&manager)) {
|
|
|
|
manager->AddEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
|
|
|
|
NS_RELEASE(manager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
|
|
|
|
{
|
|
|
|
if (nsnull != mListenerManager) {
|
|
|
|
mListenerManager->RemoveEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::AddEventListener(const nsString& aType, nsIDOMEventListener* aListener,
|
|
|
|
PRBool aPostProcess, PRBool aUseCapture)
|
|
|
|
{
|
|
|
|
nsIEventListenerManager *manager;
|
|
|
|
|
|
|
|
if (NS_OK == GetListenerManager(&manager)) {
|
|
|
|
PRInt32 flags = (aPostProcess ? NS_EVENT_FLAG_POST_PROCESS : NS_EVENT_FLAG_NONE) |
|
|
|
|
(aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE);
|
|
|
|
|
|
|
|
manager->AddEventListenerByType(aListener, aType, flags);
|
|
|
|
NS_RELEASE(manager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
|
|
|
|
PRBool aPostProcess, PRBool aUseCapture)
|
|
|
|
{
|
|
|
|
if (nsnull != mListenerManager) {
|
|
|
|
PRInt32 flags = (aPostProcess ? NS_EVENT_FLAG_POST_PROCESS : NS_EVENT_FLAG_NONE) |
|
|
|
|
(aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE);
|
|
|
|
|
|
|
|
mListenerManager->RemoveEventListenerByType(aListener, aType, flags);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetListenerManager(nsIEventListenerManager** aResult)
|
|
|
|
{
|
|
|
|
if (nsnull != mListenerManager) {
|
|
|
|
NS_ADDREF(mListenerManager);
|
|
|
|
*aResult = mListenerManager;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsresult rv = nsComponentManager::CreateInstance(kEventListenerManagerCID,
|
|
|
|
nsnull,
|
|
|
|
kIEventListenerManagerIID,
|
|
|
|
(void**) aResult);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
mListenerManager = *aResult;
|
|
|
|
NS_ADDREF(mListenerManager);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
XULDocumentImpl::GetNewListenerManager(nsIEventListenerManager **aResult)
|
|
|
|
{
|
|
|
|
return nsComponentManager::CreateInstance(kEventListenerManagerCID,
|
|
|
|
nsnull,
|
|
|
|
kIEventListenerManagerIID,
|
|
|
|
(void**) aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XULDocumentImpl::CaptureEvent(const nsString& aType)
|
|
|
|
{
|
|
|
|
nsIEventListenerManager *mManager;
|
|
|
|
|
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
|
|
|
//mManager->CaptureEvent(aListener);
|
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XULDocumentImpl::ReleaseEvent(const nsString& aType)
|
|
|
|
{
|
|
|
|
if (nsnull != mListenerManager) {
|
|
|
|
//mListenerManager->ReleaseEvent(aListener);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|