2002-05-03 03:10:23 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-09-25 01:32:19 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-24 05:07:14 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1998-12-24 05:07:14 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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.
|
1998-12-24 05:07:14 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-04-26 03:47:15 +00:00
|
|
|
*
|
2001-07-31 19:05:34 +00:00
|
|
|
* Contributor(s):
|
2001-09-25 01:32:19 +00:00
|
|
|
* Chris Waterson <waterson@netscape.com>
|
2000-06-20 05:43:52 +00:00
|
|
|
* Ben Goodger <ben@netscape.com>
|
2001-04-12 01:05:42 +00:00
|
|
|
* Pete Collins <petejc@collab.net>
|
2001-04-18 06:06:31 +00:00
|
|
|
* Dan Rosen <dr@netscape.com>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-01-05 21:57:59 +00:00
|
|
|
/*
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
An implementation for the XUL document. This implementation serves
|
|
|
|
as the basis for generating an NGLayout content model.
|
1999-01-05 21:57:59 +00:00
|
|
|
|
1999-08-30 02:45:54 +00:00
|
|
|
Notes
|
|
|
|
-----
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
1. We do some monkey business in the document observer methods to`
|
1999-08-30 02:45:54 +00:00
|
|
|
keep the element map in sync for HTML elements. Why don't we just
|
|
|
|
do it for _all_ elements? Well, in the case of XUL elements,
|
|
|
|
which may be lazily created during frame construction, the
|
|
|
|
document observer methods will never be called because we'll be
|
|
|
|
adding the XUL nodes into the content model "quietly".
|
|
|
|
|
|
|
|
2. The "element map" maps an RDF resource to the elements whose 'id'
|
|
|
|
or 'ref' attributes refer to that resource. We re-use the element
|
|
|
|
map to support the HTML-like 'getElementById()' method.
|
|
|
|
|
|
|
|
*/
|
1999-01-05 21:57:59 +00:00
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
// Note the ALPHABETICAL ORDERING
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsXULDocument.h"
|
2001-04-12 01:05:42 +00:00
|
|
|
#include "nsDocument.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsDOMCID.h"
|
2000-05-10 13:13:39 +00:00
|
|
|
#include "nsDOMError.h"
|
2000-12-10 09:18:57 +00:00
|
|
|
#include "nsIBoxObject.h"
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-21 20:51:34 +00:00
|
|
|
#include "nsIChannel.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsIChromeRegistry.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2000-02-17 21:05:52 +00:00
|
|
|
#include "nsICodebasePrincipal.h"
|
1999-12-06 23:05:31 +00:00
|
|
|
#include "nsIContentSink.h" // for NS_CONTENT_ID_COUNTER_BASE
|
2000-11-09 20:30:35 +00:00
|
|
|
#include "nsIScrollableView.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsIContentViewer.h"
|
1999-11-02 01:14:07 +00:00
|
|
|
#include "nsICSSStyleSheet.h"
|
2001-06-29 00:48:35 +00:00
|
|
|
#include "nsIDOMComment.h"
|
1999-05-16 07:05:51 +00:00
|
|
|
#include "nsIDOMEvent.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIDOMEventReceiver.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
2000-11-09 00:32:27 +00:00
|
|
|
#include "nsIDOMRange.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIDOMScriptObjectFactory.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsIDOMText.h"
|
|
|
|
#include "nsIDOMXULElement.h"
|
2000-04-26 13:58:56 +00:00
|
|
|
#include "nsIDOMAbstractView.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIDTD.h"
|
|
|
|
#include "nsIDocumentObserver.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsIFormControl.h"
|
1999-05-28 11:30:59 +00:00
|
|
|
#include "nsIHTMLContent.h"
|
2002-02-14 00:40:55 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
2000-01-19 03:11:39 +00:00
|
|
|
#include "nsIElementFactory.h"
|
2000-05-16 11:35:12 +00:00
|
|
|
#include "nsIEventStateManager.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsILoadGroup.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsINameSpace.h"
|
2000-06-01 23:10:44 +00:00
|
|
|
#include "nsIObserver.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-11-18 02:25:33 +00:00
|
|
|
#include "nsIPrincipal.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
1999-01-20 01:42:13 +00:00
|
|
|
#include "nsIRDFCompositeDataSource.h"
|
1999-05-05 03:09:50 +00:00
|
|
|
#include "nsIRDFContainerUtils.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIRDFNode.h"
|
1999-09-03 08:57:42 +00:00
|
|
|
#include "nsIRDFRemoteDataSource.h"
|
1999-01-05 03:53:15 +00:00
|
|
|
#include "nsIRDFService.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsIStyleSheet.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsITextContent.h"
|
1999-11-24 22:46:09 +00:00
|
|
|
#include "nsITimer.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIURL.h"
|
2000-03-11 00:22:48 +00:00
|
|
|
#include "nsIDocShell.h"
|
1999-11-29 06:04:15 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
2000-12-10 09:18:57 +00:00
|
|
|
#include "nsXULAtoms.h"
|
1999-04-16 08:38:17 +00:00
|
|
|
#include "nsIXMLContent.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsIXULContent.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsIXULContentSink.h"
|
2001-02-22 03:01:34 +00:00
|
|
|
#include "nsXULContentUtils.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsIXULPrototypeCache.h"
|
|
|
|
#include "nsLWBrkCIID.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsLayoutCID.h"
|
2001-02-19 21:50:04 +00:00
|
|
|
#include "nsContentCID.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsParserCIID.h"
|
2000-12-10 09:18:57 +00:00
|
|
|
#include "nsPIBoxObject.h"
|
1998-12-24 06:22:21 +00:00
|
|
|
#include "nsRDFCID.h"
|
2001-02-22 03:01:34 +00:00
|
|
|
#include "nsILocalStore.h"
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsRDFDOMNodeList.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2000-09-01 01:54:35 +00:00
|
|
|
#include "nsIDOMWindowInternal.h"
|
2001-04-18 06:06:31 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
1999-12-05 23:04:22 +00:00
|
|
|
#include "nsXULCommandDispatcher.h"
|
2001-09-07 09:30:03 +00:00
|
|
|
#include "nsTreeWalker.h"
|
1999-10-29 01:21:15 +00:00
|
|
|
#include "nsXULDocument.h"
|
1999-10-20 18:55:32 +00:00
|
|
|
#include "nsXULElement.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 "rdf.h"
|
1999-10-30 02:52:11 +00:00
|
|
|
#include "nsIFrame.h"
|
2000-05-10 23:02:32 +00:00
|
|
|
#include "nsIPrivateDOMImplementation.h"
|
|
|
|
#include "nsIDOMDOMImplementation.h"
|
2000-05-10 13:13:39 +00:00
|
|
|
#include "nsINodeInfo.h"
|
2000-05-13 08:13:54 +00:00
|
|
|
#include "nsIDOMDocumentType.h"
|
2001-02-25 00:00:52 +00:00
|
|
|
#include "nsIDOMProcessingInstruction.h"
|
2000-05-26 22:45:26 +00:00
|
|
|
#include "nsIXBLService.h"
|
2000-08-23 17:27:06 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2001-02-22 03:01:34 +00:00
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
#include "nsIMIMEService.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsMimeTypes.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsISelectionController.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2001-07-31 19:05:34 +00:00
|
|
|
#include "nsIFastLoadService.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsIPref.h"
|
2002-09-06 00:19:58 +00:00
|
|
|
#include "nsIFocusController.h"
|
2000-05-25 23:48:45 +00:00
|
|
|
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// CIDs
|
|
|
|
//
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-11-24 22:46:09 +00:00
|
|
|
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
|
|
|
|
static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID);
|
|
|
|
static NS_DEFINE_CID(kHTMLCSSStyleSheetCID, NS_HTML_CSS_STYLESHEET_CID);
|
1999-10-05 21:13:55 +00:00
|
|
|
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
|
1999-04-16 08:38:17 +00:00
|
|
|
static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID);
|
1999-11-24 22:46:09 +00:00
|
|
|
static NS_DEFINE_CID(kLWBrkCID, NS_LWBRK_CID);
|
|
|
|
static NS_DEFINE_CID(kLocalStoreCID, NS_LOCALSTORE_CID);
|
2001-03-10 21:02:12 +00:00
|
|
|
static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
|
1999-04-16 08:38:17 +00:00
|
|
|
static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
|
|
|
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
|
1999-10-29 01:21:15 +00:00
|
|
|
static NS_DEFINE_CID(kXMLElementFactoryCID, NS_XML_ELEMENT_FACTORY_CID);
|
1999-04-16 08:38:17 +00:00
|
|
|
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
|
1999-10-29 01:21:15 +00:00
|
|
|
static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID);
|
2000-05-10 23:02:32 +00:00
|
|
|
static NS_DEFINE_CID(kDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID);
|
2000-11-09 00:32:27 +00:00
|
|
|
static NS_DEFINE_CID(kRangeCID, NS_RANGE_CID);
|
1999-02-03 02:48:55 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
|
1999-02-23 03:31:26 +00:00
|
|
|
|
2001-01-31 01:33:03 +00:00
|
|
|
static PRBool IsChromeURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
// why is this check a member function of nsXULDocument? -gagan
|
2002-05-03 03:04:34 +00:00
|
|
|
PRBool isChrome = PR_FALSE;
|
2001-03-13 02:02:05 +00:00
|
|
|
if (NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome)
|
2001-01-31 01:33:03 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Miscellaneous Constants
|
|
|
|
//
|
1999-04-16 08:38:17 +00:00
|
|
|
|
1999-11-17 03:20:03 +00:00
|
|
|
const nsForwardReference::Phase nsForwardReference::kPasses[] = {
|
|
|
|
nsForwardReference::eConstruction,
|
|
|
|
nsForwardReference::eHookup,
|
|
|
|
nsForwardReference::eDone
|
1999-10-29 01:21:15 +00:00
|
|
|
};
|
1999-09-07 02:51:13 +00:00
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Statics
|
|
|
|
//
|
1999-09-03 07:02:25 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
PRInt32 nsXULDocument::gRefCnt = 0;
|
1999-09-30 02:32:34 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsIRDFService* nsXULDocument::gRDFService;
|
|
|
|
nsIRDFResource* nsXULDocument::kNC_persist;
|
|
|
|
nsIRDFResource* nsXULDocument::kNC_attribute;
|
|
|
|
nsIRDFResource* nsXULDocument::kNC_value;
|
1999-09-17 04:29:53 +00:00
|
|
|
|
2000-01-19 03:11:39 +00:00
|
|
|
nsIElementFactory* nsXULDocument::gHTMLElementFactory;
|
|
|
|
nsIElementFactory* nsXULDocument::gXMLElementFactory;
|
1999-02-09 03:15:41 +00:00
|
|
|
|
1999-11-02 01:14:07 +00:00
|
|
|
nsIXULPrototypeCache* nsXULDocument::gXULCache;
|
1999-04-16 08:38:17 +00:00
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
PRLogModuleInfo* nsXULDocument::gXULLog;
|
|
|
|
|
1999-12-16 03:19:34 +00:00
|
|
|
class nsProxyLoadStream : public nsIInputStream
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const char* mBuffer;
|
|
|
|
PRUint32 mSize;
|
|
|
|
PRUint32 mIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
nsProxyLoadStream(void) : mBuffer(nsnull)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsProxyLoadStream(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIBaseStream
|
|
|
|
NS_IMETHOD Close(void) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIInputStream
|
|
|
|
NS_IMETHOD Available(PRUint32 *aLength) {
|
|
|
|
*aLength = mSize - mIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) {
|
|
|
|
PRUint32 readCount = 0;
|
|
|
|
while (mIndex < mSize && aCount > 0) {
|
|
|
|
*aBuf = mBuffer[mIndex];
|
|
|
|
aBuf++;
|
|
|
|
mIndex++;
|
|
|
|
readCount++;
|
|
|
|
aCount--;
|
|
|
|
}
|
|
|
|
*aReadCount = readCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-22 07:03:33 +00:00
|
|
|
NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) {
|
|
|
|
NS_NOTREACHED("ReadSegments");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2002-03-12 00:59:06 +00:00
|
|
|
NS_IMETHOD IsNonBlocking(PRBool *aNonBlocking) {
|
|
|
|
*aNonBlocking = PR_TRUE;
|
|
|
|
return NS_OK;
|
2000-08-22 07:03:33 +00:00
|
|
|
}
|
|
|
|
|
1999-12-16 03:19:34 +00:00
|
|
|
// Implementation
|
|
|
|
void SetBuffer(const char* aBuffer, PRUint32 aSize) {
|
|
|
|
mBuffer = aBuffer;
|
|
|
|
mSize = aSize;
|
|
|
|
mIndex = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2000-11-17 20:54:21 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsProxyLoadStream, nsIInputStream);
|
1999-12-16 03:19:34 +00:00
|
|
|
|
1999-11-23 01:44:51 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
2001-02-22 03:01:34 +00:00
|
|
|
// PlaceholderRequest
|
1999-11-23 01:44:51 +00:00
|
|
|
//
|
2001-02-22 03:01:34 +00:00
|
|
|
// This is a dummy request implementation that we add to the load
|
2000-03-11 00:22:48 +00:00
|
|
|
// group. It ensures that EndDocumentLoad() in the docshell doesn't
|
1999-11-23 01:44:51 +00:00
|
|
|
// fire before we've finished building the complete document content
|
|
|
|
// model.
|
|
|
|
//
|
|
|
|
|
2001-02-22 03:01:34 +00:00
|
|
|
class PlaceHolderRequest : public nsIChannel
|
1999-11-23 01:44:51 +00:00
|
|
|
{
|
|
|
|
protected:
|
2001-02-22 03:01:34 +00:00
|
|
|
PlaceHolderRequest();
|
|
|
|
virtual ~PlaceHolderRequest();
|
1999-11-24 22:46:09 +00:00
|
|
|
|
|
|
|
static PRInt32 gRefCnt;
|
|
|
|
static nsIURI* gURI;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
1999-11-23 01:44:51 +00:00
|
|
|
|
|
|
|
public:
|
1999-11-24 22:46:09 +00:00
|
|
|
static nsresult
|
2001-02-22 03:01:34 +00:00
|
|
|
Create(nsIRequest** aResult);
|
2002-09-13 23:10:58 +00:00
|
|
|
|
1999-11-24 22:46:09 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
1999-11-23 01:44:51 +00:00
|
|
|
|
2002-09-13 23:10:58 +00:00
|
|
|
// nsIRequest
|
2002-03-20 22:50:33 +00:00
|
|
|
NS_IMETHOD GetName(nsACString &result) {
|
2000-08-21 08:23:54 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1999-11-23 01:44:51 +00:00
|
|
|
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_IMETHOD GetStatus(nsresult *status) { *status = NS_OK; return NS_OK; }
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_IMETHOD Cancel(nsresult status) { return NS_OK; }
|
1999-11-23 01:44:51 +00:00
|
|
|
NS_IMETHOD Suspend(void) { return NS_OK; }
|
|
|
|
NS_IMETHOD Resume(void) { return NS_OK; }
|
2002-09-13 23:10:58 +00:00
|
|
|
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
|
|
|
|
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
|
2002-03-20 22:50:33 +00:00
|
|
|
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) { *aLoadFlags = nsIRequest::LOAD_NORMAL; return NS_OK; }
|
2002-09-13 23:10:58 +00:00
|
|
|
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }
|
1999-11-23 01:44:51 +00:00
|
|
|
|
2002-09-13 23:10:58 +00:00
|
|
|
// nsIChannel
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_IMETHOD GetOriginalURI(nsIURI* *aOriginalURI) { *aOriginalURI = gURI; NS_ADDREF(*aOriginalURI); return NS_OK; }
|
|
|
|
NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) { gURI = aOriginalURI; NS_ADDREF(gURI); return NS_OK; }
|
|
|
|
NS_IMETHOD GetURI(nsIURI* *aURI) { *aURI = gURI; NS_ADDREF(*aURI); return NS_OK; }
|
|
|
|
NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; }
|
2001-02-22 03:01:34 +00:00
|
|
|
NS_IMETHOD Open(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; }
|
|
|
|
NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
|
2002-09-13 23:10:58 +00:00
|
|
|
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
|
|
|
|
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }
|
|
|
|
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; }
|
|
|
|
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; }
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) { *aSecurityInfo = nsnull; return NS_OK; }
|
2002-03-20 22:50:33 +00:00
|
|
|
NS_IMETHOD GetContentType(nsACString &aContentType) { aContentType.Truncate(); return NS_OK; }
|
|
|
|
NS_IMETHOD SetContentType(const nsACString &aContentType) { return NS_OK; }
|
|
|
|
NS_IMETHOD GetContentCharset(nsACString &aContentCharset) { aContentCharset.Truncate(); return NS_OK; }
|
|
|
|
NS_IMETHOD SetContentCharset(const nsACString &aContentCharset) { return NS_OK; }
|
2001-02-22 03:01:34 +00:00
|
|
|
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { return NS_OK; }
|
|
|
|
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { return NS_OK; }
|
|
|
|
|
1999-11-23 01:44:51 +00:00
|
|
|
};
|
|
|
|
|
2001-02-22 03:01:34 +00:00
|
|
|
PRInt32 PlaceHolderRequest::gRefCnt;
|
|
|
|
nsIURI* PlaceHolderRequest::gURI;
|
1999-11-23 01:44:51 +00:00
|
|
|
|
2001-02-22 03:01:34 +00:00
|
|
|
NS_IMPL_ADDREF(PlaceHolderRequest);
|
|
|
|
NS_IMPL_RELEASE(PlaceHolderRequest);
|
|
|
|
NS_IMPL_QUERY_INTERFACE2(PlaceHolderRequest, nsIRequest, nsIChannel);
|
1999-11-23 01:44:51 +00:00
|
|
|
|
|
|
|
nsresult
|
2001-02-22 03:01:34 +00:00
|
|
|
PlaceHolderRequest::Create(nsIRequest** aResult)
|
1999-11-23 01:44:51 +00:00
|
|
|
{
|
2001-02-22 03:01:34 +00:00
|
|
|
PlaceHolderRequest* request = new PlaceHolderRequest();
|
|
|
|
if (! request)
|
1999-11-24 22:46:09 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-11-23 01:44:51 +00:00
|
|
|
|
2001-02-22 03:01:34 +00:00
|
|
|
*aResult = request;
|
1999-11-24 22:46:09 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
1999-11-23 01:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-22 03:01:34 +00:00
|
|
|
PlaceHolderRequest::PlaceHolderRequest()
|
1999-11-23 01:44:51 +00:00
|
|
|
{
|
1999-11-24 22:46:09 +00:00
|
|
|
|
|
|
|
if (gRefCnt++ == 0) {
|
|
|
|
nsresult rv;
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = NS_NewURI(&gURI, NS_LITERAL_CSTRING("about:xul-master-placeholder"), nsnull);
|
1999-11-24 22:46:09 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create about:xul-master-placeholder");
|
|
|
|
}
|
1999-11-23 01:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-22 03:01:34 +00:00
|
|
|
PlaceHolderRequest::~PlaceHolderRequest()
|
1999-11-23 01:44:51 +00:00
|
|
|
{
|
1999-11-24 22:46:09 +00:00
|
|
|
if (--gRefCnt == 0) {
|
|
|
|
NS_IF_RELEASE(gURI);
|
|
|
|
}
|
1999-11-23 01:44:51 +00:00
|
|
|
}
|
|
|
|
|
2001-10-23 02:44:44 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct BroadcasterMapEntry : public PLDHashEntryHdr {
|
|
|
|
nsIDOMElement* mBroadcaster; // [WEAK]
|
2001-12-21 01:10:07 +00:00
|
|
|
nsSmallVoidArray mListeners; // [OWNING] of BroadcastListener objects
|
2001-10-23 02:44:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BroadcastListener {
|
|
|
|
nsIDOMElement* mListener; // [WEAK] XXXwaterson crash waiting to happen!
|
|
|
|
nsCOMPtr<nsIAtom> mAttribute;
|
|
|
|
};
|
1999-11-24 22:46:09 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-01-12 19:41:06 +00:00
|
|
|
// ctors & dtors
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::nsXULDocument(void)
|
1999-05-28 11:30:59 +00:00
|
|
|
: mParentDocument(nsnull),
|
1999-12-17 00:06:28 +00:00
|
|
|
mScriptGlobalObject(nsnull),
|
1999-11-18 02:25:33 +00:00
|
|
|
mNextSrcLoadWaiter(nsnull),
|
1999-05-28 11:30:59 +00:00
|
|
|
mDisplaySelection(PR_FALSE),
|
1999-09-30 02:32:34 +00:00
|
|
|
mIsPopup(PR_FALSE),
|
2001-11-15 02:46:29 +00:00
|
|
|
mApplyingPersistedAttrs(PR_FALSE),
|
2002-05-03 03:04:34 +00:00
|
|
|
mIsWritingFastLoad(PR_FALSE),
|
2001-03-23 10:56:18 +00:00
|
|
|
mBoxObjectTable(nsnull),
|
|
|
|
mTemplateBuilderTable(nsnull),
|
1999-11-17 03:20:03 +00:00
|
|
|
mResolutionPhase(nsForwardReference::eStart),
|
1999-12-06 23:05:31 +00:00
|
|
|
mNextContentID(NS_CONTENT_ID_COUNTER_BASE),
|
2001-04-12 01:05:42 +00:00
|
|
|
mNumCapturers(0),
|
1999-11-23 01:44:51 +00:00
|
|
|
mState(eState_Master),
|
2001-10-23 02:44:44 +00:00
|
|
|
mCurrentScriptProto(nsnull),
|
|
|
|
mBroadcasterMap(nsnull)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2001-12-16 11:58:03 +00:00
|
|
|
mCharSetID.Assign(NS_LITERAL_STRING("UTF-8"));
|
2001-02-07 07:45:36 +00:00
|
|
|
|
|
|
|
// Force initialization.
|
|
|
|
mBindingManager = do_CreateInstance("@mozilla.org/xbl/binding-manager;1");
|
|
|
|
nsCOMPtr<nsIDocumentObserver> observer(do_QueryInterface(mBindingManager));
|
|
|
|
if (observer) // We must always be the first observer of the document.
|
|
|
|
mObservers.InsertElementAt(observer, 0);
|
2001-04-12 23:35:24 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
mBidiEnabled = PR_FALSE;
|
|
|
|
#endif // IBMBIDI
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
mSubDocuments = nsnull;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::~nsXULDocument()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_ASSERTION(mNextSrcLoadWaiter == nsnull,
|
|
|
|
"unreferenced document still waiting for script source to load?");
|
|
|
|
|
1999-09-30 02:32:34 +00:00
|
|
|
// In case we failed somewhere early on and the forward observer
|
|
|
|
// decls never got resolved.
|
1999-10-05 21:13:55 +00:00
|
|
|
DestroyForwardReferences();
|
1999-09-30 02:32:34 +00:00
|
|
|
|
2001-10-23 02:44:44 +00:00
|
|
|
// Destroy our broadcaster map.
|
|
|
|
if (mBroadcasterMap)
|
|
|
|
PL_DHashTableDestroy(mBroadcasterMap);
|
|
|
|
|
2001-03-23 10:56:18 +00:00
|
|
|
// Notify observer that we're about to go away
|
2001-12-21 01:10:07 +00:00
|
|
|
// if an observer removes itself, we're ok (not if it removes others though)
|
2001-03-23 10:56:18 +00:00
|
|
|
PRInt32 i;
|
|
|
|
for (i = mObservers.Count() - 1; i >= 0; --i) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(i);
|
|
|
|
observer->DocumentWillBeDestroyed(this);
|
|
|
|
}
|
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
// Delete references to sub-documents and kill the subdocument map,
|
|
|
|
// if any. It holds strong references
|
|
|
|
if (mSubDocuments) {
|
|
|
|
PL_DHashTableDestroy(mSubDocuments);
|
|
|
|
mSubDocuments = nsnull;
|
1999-05-16 09:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete references to style sheets but only if we aren't a popup document.
|
|
|
|
if (!mIsPopup) {
|
2001-04-12 01:05:42 +00:00
|
|
|
i = mStyleSheets.Count();
|
1999-05-28 11:30:59 +00:00
|
|
|
while (--i >= 0) {
|
|
|
|
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(i);
|
1999-05-16 09:09:00 +00:00
|
|
|
sheet->SetOwningDocument(nsnull);
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
1999-03-10 20:05:12 +00:00
|
|
|
}
|
|
|
|
|
1999-09-03 08:57:42 +00:00
|
|
|
if (mLocalStore) {
|
|
|
|
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mLocalStore);
|
|
|
|
if (remote)
|
|
|
|
remote->Flush();
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:42:29 +00:00
|
|
|
if (mCSSLoader) {
|
2001-07-31 19:05:34 +00:00
|
|
|
mCSSLoader->DropDocumentReference();
|
1999-05-28 11:30:59 +00:00
|
|
|
}
|
1999-09-25 16:29:22 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
if (mScriptLoader) {
|
2001-07-31 19:05:34 +00:00
|
|
|
mScriptLoader->DropDocumentReference();
|
2001-05-17 05:54:16 +00:00
|
|
|
}
|
2001-04-12 01:05:42 +00:00
|
|
|
|
2001-03-23 10:56:18 +00:00
|
|
|
delete mTemplateBuilderTable;
|
2000-12-10 09:18:57 +00:00
|
|
|
delete mBoxObjectTable;
|
|
|
|
|
2001-04-03 20:42:41 +00:00
|
|
|
if (mListenerManager)
|
|
|
|
mListenerManager->SetListenerTarget(nsnull);
|
|
|
|
|
1999-02-24 04:46:47 +00:00
|
|
|
if (--gRefCnt == 0) {
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_IF_RELEASE(gRDFService);
|
1999-04-16 08:38:17 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
NS_IF_RELEASE(kNC_persist);
|
|
|
|
NS_IF_RELEASE(kNC_attribute);
|
|
|
|
NS_IF_RELEASE(kNC_value);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(gHTMLElementFactory);
|
1999-10-29 01:21:15 +00:00
|
|
|
NS_IF_RELEASE(gXMLElementFactory);
|
1999-10-05 21:13:55 +00:00
|
|
|
|
1999-11-02 01:14:07 +00:00
|
|
|
if (gXULCache) {
|
2002-05-03 03:04:34 +00:00
|
|
|
// Remove the current document here from the FastLoad table in
|
|
|
|
// case the document did not make it past StartLayout in
|
|
|
|
// ResumeWalk. The FastLoad table must be clear of entries so
|
|
|
|
// that the FastLoad file footer can be properly written.
|
2002-11-19 18:22:36 +00:00
|
|
|
if (mDocumentURL)
|
|
|
|
gXULCache->RemoveFromFastLoadSet(mDocumentURL);
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_RELEASE(gXULCache);
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
1999-02-24 04:46:47 +00:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
if (mNodeInfoManager) {
|
|
|
|
mNodeInfoManager->DropDocumentReference();
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-10-05 21:13:55 +00:00
|
|
|
NS_NewXULDocument(nsIXULDocument** result)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(result != nsnull, "null ptr");
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument* doc = new nsXULDocument();
|
1999-02-16 19:30:04 +00:00
|
|
|
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-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-01-12 19:41:06 +00:00
|
|
|
// nsISupports interface
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
1999-01-12 19:41:06 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_IMPL_ADDREF(nsXULDocument)
|
|
|
|
NS_IMPL_RELEASE(nsXULDocument)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsHTMLAnchorElement
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsXULDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXULDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXMLDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMXULDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOM3Node)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNSDocument)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentEvent)
|
2002-11-09 00:25:25 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOM3DocumentEvent)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentView)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentXBL)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentStyle)
|
2001-05-12 05:01:22 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentRange)
|
2001-09-07 09:30:03 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentTraversal)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIHTMLContentContainer)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
2002-11-09 00:25:25 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamLoaderObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULDocument)
|
|
|
|
NS_INTERFACE_MAP_END
|
1998-12-24 05:07:14 +00:00
|
|
|
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1998-12-24 05:07:14 +00:00
|
|
|
// nsIDocument interface
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
1998-12-24 05:07:14 +00:00
|
|
|
|
2001-03-12 06:39:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Reset");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2001-11-16 02:03:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("ResetToURI");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetArena(nsIArena** aArena)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IF_ADDREF(*aArena = mArena);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-09-24 22:43:23 +00:00
|
|
|
// Override the nsDocument.cpp method to keep from returning the
|
|
|
|
// "cached XUL" type which is completely internal and may confuse
|
|
|
|
// people
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetContentType(nsAString& aContentType)
|
1999-05-11 20:22:52 +00:00
|
|
|
{
|
2001-03-25 16:49:38 +00:00
|
|
|
aContentType.Assign(NS_LITERAL_STRING("application/vnd.mozilla.xul+xml"));
|
1999-05-11 20:22:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-09 15:45:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetContentType(const nsAString& aContentType)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContentType.Equals(NS_LITERAL_STRING("application/vnd.mozilla.xul+xml")),
|
|
|
|
"xul-documents always has content-type application/vnd.mozilla.xul+xml");
|
|
|
|
// Don't do anything, xul always has the mimetype
|
|
|
|
// application/vnd.mozilla.xul+xml
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-11 21:12:23 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetContentLanguage(nsAString& aContentLanguage) const
|
2001-09-11 21:12:23 +00:00
|
|
|
{
|
|
|
|
aContentLanguage.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::PrepareStyleSheets(nsIURI* anURL)
|
1999-05-16 08:50:27 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-05-16 08:50:27 +00:00
|
|
|
// Delete references to style sheets - this should be done in superclass...
|
1999-05-28 11:30:59 +00:00
|
|
|
PRInt32 i = mStyleSheets.Count();
|
|
|
|
while (--i >= 0) {
|
|
|
|
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(i);
|
1999-05-16 08:50:27 +00:00
|
|
|
sheet->SetOwningDocument(nsnull);
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
|
|
|
mStyleSheets.Clear();
|
|
|
|
|
|
|
|
// Create an HTML style sheet for the HTML content.
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), anURL, this);
|
1999-05-16 08:50:27 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("unable to add HTML style sheet");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
AddStyleSheet(mAttrStyleSheet, 0);
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
// Create an inline style sheet for inline content that contains a style
|
1999-05-16 08:50:27 +00:00
|
|
|
// attribute.
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mInlineStyleSheet), anURL, this);
|
1999-05-16 08:50:27 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("unable to add inline style sheet");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
AddStyleSheet(mInlineStyleSheet, 0);
|
|
|
|
|
1999-05-16 08:50:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-08 04:56:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetDocumentURL(nsIURI* anURL)
|
1999-05-16 08:50:27 +00:00
|
|
|
{
|
1999-05-28 11:30:59 +00:00
|
|
|
mDocumentURL = dont_QueryInterface(anURL);
|
1999-12-08 04:56:56 +00:00
|
|
|
return NS_OK;
|
1999-05-16 08:50:27 +00:00
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-11-15 22:14:37 +00:00
|
|
|
nsISupports* aContainer,
|
2000-05-01 06:58:53 +00:00
|
|
|
nsIStreamListener **aDocListener,
|
2001-11-02 01:53:13 +00:00
|
|
|
PRBool aReset,
|
|
|
|
nsIContentSink* aSink)
|
1999-04-23 16:48:33 +00:00
|
|
|
{
|
1999-12-04 07:45:57 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
mDocumentLoadGroup = getter_AddRefs(NS_GetWeakReference(aLoadGroup));
|
|
|
|
|
|
|
|
mDocumentTitle.Truncate();
|
|
|
|
|
|
|
|
rv = aChannel->GetOriginalURI(getter_AddRefs(mDocumentURL));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
rv = PrepareStyleSheets(mDocumentURL);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
// Look in the chrome cache: we've got this puppy loaded
|
|
|
|
// already.
|
|
|
|
nsCOMPtr<nsIXULPrototypeDocument> proto;
|
2002-05-07 01:29:44 +00:00
|
|
|
if (IsChromeURI(mDocumentURL))
|
|
|
|
gXULCache->GetPrototype(mDocumentURL, getter_AddRefs(proto));
|
2000-01-11 21:18:19 +00:00
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
// Same comment as nsChromeProtocolHandler::NewChannel and
|
|
|
|
// nsXULDocument::ResumeWalk
|
|
|
|
// - Ben Goodger
|
|
|
|
//
|
|
|
|
// We don't abort on failure here because there are too many valid
|
|
|
|
// cases that can return failure, and the null-ness of |proto| is enough
|
|
|
|
// to trigger the fail-safe parse-from-disk solution. Example failure cases
|
|
|
|
// (for reference) include:
|
|
|
|
//
|
|
|
|
// NS_ERROR_NOT_AVAILABLE: the URI cannot be found in the FastLoad cache,
|
|
|
|
// parse from disk
|
|
|
|
// other: the FastLoad cache file, XUL.mfl, could not be found, probably
|
|
|
|
// due to being accessed before a profile has been selected (e.g.
|
|
|
|
// loading chrome for the profile manager itself). This must be
|
|
|
|
// parsed from disk.
|
|
|
|
|
|
|
|
if (proto) {
|
2001-07-31 19:05:34 +00:00
|
|
|
// If we're racing with another document to load proto, wait till the
|
|
|
|
// load has finished loading before trying to add cloned style sheets.
|
|
|
|
// nsXULDocument::EndLoad will call proto->NotifyLoadDone, which will
|
|
|
|
// find all racing documents and notify them via OnPrototypeLoadDone,
|
|
|
|
// which will add style sheet clones to each document.
|
|
|
|
PRBool loaded;
|
|
|
|
rv = proto->AwaitLoadDone(this, &loaded);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
mMasterPrototype = mCurrentPrototype = proto;
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// Add cloned style sheet references only if the prototype has in
|
|
|
|
// fact already loaded. It may still be loading when we hit the XUL
|
|
|
|
// prototype cache.
|
|
|
|
if (loaded) {
|
|
|
|
rv = AddPrototypeSheets();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// We need a listener, even if proto is not yet loaded, in which
|
|
|
|
// event the listener's OnStopRequest method does nothing, and all
|
|
|
|
// the interesting work happens below nsXULDocument::EndLoad, from
|
|
|
|
// the call there to mCurrentPrototype->NotifyLoadDone().
|
|
|
|
*aDocListener = new CachedChromeStreamListener(this, loaded);
|
1999-12-04 07:45:57 +00:00
|
|
|
if (! *aDocListener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else {
|
2001-07-31 19:05:34 +00:00
|
|
|
PRBool useXULCache;
|
|
|
|
gXULCache->GetEnabled(&useXULCache);
|
|
|
|
PRBool fillXULCache = (useXULCache && IsChromeURI(mDocumentURL));
|
|
|
|
|
|
|
|
|
2000-01-11 21:18:19 +00:00
|
|
|
// It's just a vanilla document load. Create a parser to deal
|
|
|
|
// with the stream n' stuff.
|
2002-05-03 03:04:34 +00:00
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
nsCOMPtr<nsIParser> parser;
|
|
|
|
rv = PrepareToLoad(aContainer, aCommand, aChannel, aLoadGroup, getter_AddRefs(parser));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
mIsWritingFastLoad = PR_TRUE;
|
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> listener = do_QueryInterface(parser, &rv);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "parser doesn't support nsIStreamListener");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*aDocListener = listener;
|
|
|
|
|
|
|
|
parser->Parse(mDocumentURL);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
|
|
|
// Put the current prototype, created under PrepareToLoad, into the
|
|
|
|
// XUL prototype cache now. We can't do this under PrepareToLoad or
|
|
|
|
// overlay loading will break; search for PutPrototype in ResumeWalk
|
|
|
|
// and see the comment there.
|
|
|
|
if (fillXULCache) {
|
|
|
|
rv = gXULCache->PutPrototype(mCurrentPrototype);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-12-04 07:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aDocListener);
|
1999-10-29 01:21:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-23 16:48:33 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_IMETHODIMP
|
Landing changes Vidur made while the tree was closed for beta1 work, here's a list of the changes. r=me
[1] Cutting down the size of content. Made nsIJSScriptObject inherit from nsIScriptObjectOwner
[2] Cutting down the size of content. Made nsITextContent inherit from nsIContent.
[3] Cutting down the size of content. Moved implementation of nsIDOMReceiver to nsListenerManager. This is not true aggregation since it isn't transitive, but it's OK for now. It will be necessary for nsListenerManager to have a reference to its content in the future anyway, so the transitivity could be done.
dom/public/nsDOMPropEnums.h,v - bug 12559
dom/public/nsIJSScriptObject.h,v - [1]
dom/public/html/MANIFEST,v - bug 12559
dom/public/html/Makefile.in,v - bug 12559
dom/public/html/makefile.win,v - bug 12559
dom/public/html/nsIDOMHTMLInputElement.h,v - bug 17544
dom/public/idl/html/HTMLAnchorElement.idl,v - bug 12559
dom/public/idl/html/HTMLAreaElement.idl,v - bug 12559
dom/public/idl/html/HTMLInputElement.idl,v - bug 17544
dom/src/base/nsGlobalWindow.cpp,v - bug 30700
dom/src/base/nsGlobalWindow.h,v - [1]
dom/src/base/nsLocation.cpp,v - [1]
dom/src/html/nsJSHTMLAnchorElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLAreaElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLInputElement.cpp,v - bug 17544
layout/base/public/nsIDocument.h,v - bug 27953
layout/base/public/nsITextContent.h,v - [2]
layout/base/src/nsCommentNode.cpp,v - [2]
layout/base/src/nsDocument.cpp,v - bug 27953
layout/base/src/nsDocument.h,v - bug 27953
layout/base/src/nsDocumentViewer.cpp,v - bug 27953
layout/base/src/nsGenericDOMDataNode.cpp,v - [3]
layout/base/src/nsGenericDOMDataNode.h,v - [3]
layout/base/src/nsGenericElement.cpp,v - [3]
layout/base/src/nsGenericElement.h,v - [3]
layout/base/src/nsNameSpaceManager.cpp,v - bug 7834
layout/base/src/nsStyleContext.cpp,v - outline property shouldn't reflow
layout/base/src/nsTextNode.cpp,v - [2]
layout/events/src/nsEventListenerManager.cpp,v - [3]
layout/events/src/nsEventListenerManager.h,v - [3]
layout/html/base/src/nsGfxScrollFrame.cpp,v - nsString->nsAutoString
layout/html/content/src/nsAttributeContent.cpp,v - [2]
layout/html/content/src/nsHTMLAnchorElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAppletElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBodyElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLButtonElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDirectoryElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDivElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLEmbedElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFieldSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFormElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadingElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHtmlElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLImageElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInputElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInsElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIsIndexElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLIElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLabelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLayerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLegendElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLinkElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMapElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMenuElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMetaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLModElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLObjectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParagraphElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParamElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLPreElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLQuoteElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLScriptElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSelectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpacerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpanElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLStyleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCaptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCellElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableRowElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableSectionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTextAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTitleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLUListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLWBRElement.cpp,v - [1][3]
layout/html/document/src/nsHTMLDocument.cpp,v - bug 27953
layout/html/document/src/nsHTMLDocument.h,v - bug 27953
layout/xml/content/src/nsXMLCDATASection.cpp,v - [1][2]
layout/xml/content/src/nsXMLDocumentType.cpp,v - [1][2]
layout/xml/content/src/nsXMLElement.h,v - [1][2]
layout/xml/content/src/nsXMLEntity.cpp,v - [1][2]
layout/xml/content/src/nsXMLNotation.cpp,v - [1][2]
layout/xml/content/src/nsXMLProcessingInstruction.cpp,v - [1][2]
layout/xul/base/src/nsBoxFrame.cpp,v - nsString->nsAutoString
layout/xul/base/src/nsSliderFrame.cpp,v - nsString->nsAutoString
netwerk/protocol/http/src/nsHTTPRequest.cpp,v - nsString->nsAutoString
rdf/content/src/nsXULDocument.cpp,v - bug 27953
rdf/content/src/nsXULDocument.h,v - bug 27953
rdf/content/src/nsXULElement.h,v - [1]
xpcom/base/IIDS.h,v - bug 12559
2000-03-17 13:27:00 +00:00
|
|
|
nsXULDocument::StopDocumentLoad()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
const nsString*
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetDocumentTitle() const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return &mDocumentTitle;
|
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetDocumentURL(nsIURI** aURI) const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IF_ADDREF(*aURI = mDocumentURL);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2000-01-26 15:33:57 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetPrincipal(nsIPrincipal **aPrincipal)
|
1999-08-29 21:58:42 +00:00
|
|
|
{
|
2000-01-26 15:33:57 +00:00
|
|
|
return mMasterPrototype->GetDocumentPrincipal(aPrincipal);
|
1999-08-29 21:58:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-21 04:20:04 +00:00
|
|
|
NS_IMETHODIMP
|
2000-03-23 04:53:16 +00:00
|
|
|
nsXULDocument::AddPrincipal(nsIPrincipal *aPrincipal)
|
2000-03-21 04:20:04 +00:00
|
|
|
{
|
2000-08-22 07:03:33 +00:00
|
|
|
NS_NOTREACHED("AddPrincipal");
|
2000-03-21 04:20:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1999-10-05 04:08:14 +00:00
|
|
|
|
1999-09-18 06:34:24 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetDocumentLoadGroup(nsILoadGroup **aGroup) const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-09-21 06:44:56 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
|
|
|
|
|
|
|
|
*aGroup = group;
|
1999-09-18 06:34:24 +00:00
|
|
|
NS_IF_ADDREF(*aGroup);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetBaseURL(nsIURI*& aURL) const
|
1999-01-15 01:53:50 +00:00
|
|
|
{
|
2001-07-31 19:05:34 +00:00
|
|
|
if (mDocumentBaseURL) {
|
2001-04-30 23:35:09 +00:00
|
|
|
aURL = mDocumentBaseURL.get();
|
|
|
|
NS_ADDREF(aURL);
|
|
|
|
}
|
|
|
|
else {
|
2001-06-20 03:27:48 +00:00
|
|
|
GetDocumentURL(&aURL);
|
2001-04-30 23:35:09 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetBaseURL(nsIURI* aURL)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
|
2001-04-30 23:35:09 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = securityManager->CheckLoadURI(mDocumentURL, aURL, nsIScriptSecurityManager::STANDARD);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mDocumentBaseURL = aURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
return rv;
|
2001-04-30 23:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetBaseTarget(nsAString &aBaseTarget)
|
2001-04-30 23:35:09 +00:00
|
|
|
{
|
|
|
|
aBaseTarget.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::SetBaseTarget(const nsAString &aBaseTarget)
|
2001-04-30 23:35:09 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
1999-01-15 01:53:50 +00:00
|
|
|
}
|
|
|
|
|
2001-04-12 01:05:42 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets)
|
|
|
|
{
|
|
|
|
if (!mDOMStyleSheets) {
|
|
|
|
mDOMStyleSheets = new nsDOMStyleSheetList(this);
|
|
|
|
if (!mDOMStyleSheets) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aStyleSheets = mDOMStyleSheets;
|
|
|
|
NS_ADDREF(*aStyleSheets);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-27 21:49:25 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetDocumentCharacterSet(nsAString& oCharSetID)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
oCharSetID.Assign(mCharSetID);
|
1999-04-27 21:49:25 +00:00
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 21:49:25 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::SetDocumentCharacterSet(const nsAString& aCharSetID)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
if (!mCharSetID.Equals(aCharSetID)) {
|
|
|
|
mCharSetID.Assign(aCharSetID);
|
2000-06-01 23:10:44 +00:00
|
|
|
PRInt32 n = mCharSetObservers.Count();
|
2001-12-21 01:10:07 +00:00
|
|
|
// if an observer removes itself, we're NOT ok
|
2000-06-01 23:10:44 +00:00
|
|
|
for (PRInt32 i = 0; i < n; i++) {
|
|
|
|
nsIObserver* observer = (nsIObserver*) mCharSetObservers.ElementAt(i);
|
2001-10-19 20:52:59 +00:00
|
|
|
observer->Observe((nsIDocument*) this, "charset",
|
2001-04-02 19:40:52 +00:00
|
|
|
PromiseFlatString(aCharSetID).get());
|
2000-06-01 23:10:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-26 03:17:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetDocumentCharacterSetSource(PRInt32* aCharsetSource)
|
|
|
|
{
|
|
|
|
*aCharsetSource = mCharacterSetSource;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetDocumentCharacterSetSource(PRInt32 aCharsetSource)
|
|
|
|
{
|
|
|
|
mCharacterSetSource = aCharsetSource;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-01 23:10:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::AddCharSetObserver(nsIObserver* aObserver)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aObserver);
|
|
|
|
NS_ENSURE_TRUE(mCharSetObservers.AppendElement(aObserver), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::RemoveCharSetObserver(nsIObserver* aObserver)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aObserver);
|
|
|
|
NS_ENSURE_TRUE(mCharSetObservers.RemoveElement(aObserver), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-02-23 03:31:26 +00:00
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetLineBreaker(nsILineBreaker** aResult)
|
1999-02-23 03:31:26 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
if (!mLineBreaker) {
|
|
|
|
// no line breaker, find a default one
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsILineBreakerFactory> lf = do_GetService(kLWBrkCID, &rv);
|
|
|
|
if (lf) {
|
2000-04-17 14:30:23 +00:00
|
|
|
nsAutoString lbarg;
|
2002-12-11 14:24:49 +00:00
|
|
|
lf->GetBreaker(lbarg, getter_AddRefs(mLineBreaker));
|
|
|
|
}
|
1999-02-23 03:31:26 +00:00
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
1999-02-23 03:31:26 +00:00
|
|
|
*aResult = mLineBreaker;
|
1999-05-28 11:30:59 +00:00
|
|
|
NS_IF_ADDREF(*aResult);
|
2002-12-11 14:24:49 +00:00
|
|
|
|
1999-02-23 03:31:26 +00:00
|
|
|
return NS_OK; // XXX we should do error handling here
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetLineBreaker(nsILineBreaker* aLineBreaker)
|
1999-02-23 03:31:26 +00:00
|
|
|
{
|
1999-05-28 11:30:59 +00:00
|
|
|
mLineBreaker = dont_QueryInterface(aLineBreaker);
|
1999-02-23 03:31:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetWordBreaker(nsIWordBreaker** aResult)
|
1999-03-27 00:58:42 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
if (!mWordBreaker) {
|
|
|
|
// no line breaker, find a default one
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWordBreakerFactory> lf = do_GetService(kLWBrkCID, &rv);
|
|
|
|
if (lf) {
|
2000-04-17 14:30:23 +00:00
|
|
|
nsAutoString lbarg;
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = lf->GetBreaker(lbarg, getter_AddRefs(mWordBreaker));
|
|
|
|
}
|
1999-03-27 00:58:42 +00:00
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
1999-03-27 00:58:42 +00:00
|
|
|
*aResult = mWordBreaker;
|
1999-05-28 11:30:59 +00:00
|
|
|
NS_IF_ADDREF(*aResult);
|
2002-12-11 14:24:49 +00:00
|
|
|
|
1999-03-27 00:58:42 +00:00
|
|
|
return NS_OK; // XXX we should do error handling here
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetWordBreaker(nsIWordBreaker* aWordBreaker)
|
1999-03-27 00:58:42 +00:00
|
|
|
{
|
1999-05-28 11:30:59 +00:00
|
|
|
mWordBreaker = dont_QueryInterface(aWordBreaker);
|
1999-03-27 00:58:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-23 03:31:26 +00:00
|
|
|
|
|
|
|
|
1999-01-23 06:59:35 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsXULDocument::GetHeaderData(nsIAtom* aHeaderField,
|
2002-03-23 22:46:13 +00:00
|
|
|
nsAString& aData) const
|
1999-01-23 06:59:35 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
aData.Truncate();
|
1999-01-23 06:59:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsXULDocument:: SetHeaderData(nsIAtom* aHeaderField,
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& aData)
|
1999-01-23 06:59:35 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-07 01:17:21 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::CreateShell(nsIPresContext* aContext,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIStyleSet* aStyleSet,
|
|
|
|
nsIPresShell** aInstancePtrResult)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aInstancePtrResult, "null ptr");
|
|
|
|
|
|
|
|
nsIPresShell* shell;
|
2002-05-23 23:09:31 +00:00
|
|
|
nsresult rv = CallCreateInstance(kPresShellCID, &shell);
|
|
|
|
if (NS_FAILED(rv))
|
1998-12-24 05:07:14 +00:00
|
|
|
return rv;
|
|
|
|
|
2002-06-25 21:16:17 +00:00
|
|
|
rv = shell->Init(this, aContext, aViewManager, aStyleSet,
|
|
|
|
eCompatibility_FullStandards);
|
2002-05-23 23:09:31 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-12-24 05:07:14 +00:00
|
|
|
NS_RELEASE(shell);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPresShells.AppendElement(shell);
|
1999-04-30 09:04:36 +00:00
|
|
|
*aInstancePtrResult = shell; // addref implicit in CreateInstance()
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
PRBool
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::DeleteShell(nsIPresShell* aShell)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mPresShells.RemoveElement(aShell);
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
PRInt32
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetNumberOfShells()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mPresShells.Count();
|
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetShellAt(PRInt32 aIndex, nsIPresShell** aShell)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2001-12-21 01:10:07 +00:00
|
|
|
*aShell = NS_STATIC_CAST(nsIPresShell*, mPresShells.SafeElementAt(aIndex));
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IF_ADDREF(*aShell);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetParentDocument(nsIDocument** aParent)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IF_ADDREF(*aParent = mParentDocument);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::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;
|
2001-06-20 03:27:48 +00:00
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
SubDocClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
|
|
|
|
{
|
|
|
|
SubDocMapEntry *e = NS_STATIC_CAST(SubDocMapEntry *, entry);
|
|
|
|
|
|
|
|
NS_RELEASE(e->mKey);
|
|
|
|
NS_IF_RELEASE(e->mSubDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void)
|
|
|
|
SubDocInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry, const void *key)
|
|
|
|
{
|
|
|
|
SubDocMapEntry *e =
|
|
|
|
NS_CONST_CAST(SubDocMapEntry *,
|
|
|
|
NS_STATIC_CAST(const SubDocMapEntry *, entry));
|
|
|
|
|
|
|
|
e->mKey = NS_CONST_CAST(nsIContent *,
|
|
|
|
NS_STATIC_CAST(const nsIContent *, key));
|
|
|
|
NS_ADDREF(e->mKey);
|
|
|
|
|
|
|
|
e->mSubDocument = nsnull;
|
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-17 04:17:16 +00:00
|
|
|
nsXULDocument::SetSubDocumentFor(nsIContent *aContent, nsIDocument* aSubDoc)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2002-04-17 04:17:16 +00:00
|
|
|
NS_ENSURE_TRUE(aContent, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
if (!aSubDoc) {
|
|
|
|
// aSubDoc is nsnull, remove the mapping
|
|
|
|
|
|
|
|
if (mSubDocuments) {
|
|
|
|
SubDocMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(SubDocMapEntry*,
|
|
|
|
PL_DHashTableOperate(mSubDocuments, aContent,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_LIVE(entry)) {
|
|
|
|
entry->mSubDocument->SetParentDocument(nsnull);
|
|
|
|
|
|
|
|
PL_DHashTableRawRemove(mSubDocuments, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!mSubDocuments) {
|
|
|
|
// Create a new hashtable
|
|
|
|
|
|
|
|
static PLDHashTableOps hash_table_ops =
|
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashGetKeyStub,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
PL_DHashMatchEntryStub,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
SubDocClearEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
SubDocInitEntry
|
|
|
|
};
|
|
|
|
|
|
|
|
mSubDocuments = PL_NewDHashTable(&hash_table_ops, nsnull,
|
|
|
|
sizeof(SubDocMapEntry), 16);
|
|
|
|
if (!mSubDocuments) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a mapping to the hash table
|
|
|
|
SubDocMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(SubDocMapEntry*,
|
|
|
|
PL_DHashTableOperate(mSubDocuments, aContent,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
|
|
|
|
if (!entry) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry->mSubDocument) {
|
|
|
|
entry->mSubDocument->SetParentDocument(nsnull);
|
|
|
|
|
|
|
|
// Release the old sub document
|
|
|
|
NS_RELEASE(entry->mSubDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->mSubDocument = aSubDoc;
|
|
|
|
NS_ADDREF(entry->mSubDocument);
|
|
|
|
|
|
|
|
aSubDoc->SetParentDocument(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-17 04:17:16 +00:00
|
|
|
nsXULDocument::GetSubDocumentFor(nsIContent *aContent, nsIDocument** aSubDoc)
|
2002-04-04 22:42:19 +00:00
|
|
|
{
|
2002-04-17 04:17:16 +00:00
|
|
|
*aSubDoc = nsnull;
|
|
|
|
|
|
|
|
if (mSubDocuments) {
|
|
|
|
SubDocMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(SubDocMapEntry*,
|
|
|
|
PL_DHashTableOperate(mSubDocuments, aContent,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
*aSubDoc = entry->mSubDocument;
|
|
|
|
NS_ADDREF(*aSubDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
|
|
|
FindContentEnumerator(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 number, void *arg)
|
|
|
|
{
|
|
|
|
SubDocMapEntry *entry = NS_STATIC_CAST(SubDocMapEntry*, hdr);
|
|
|
|
FindContentData *data = NS_STATIC_CAST(FindContentData*, arg);
|
|
|
|
|
|
|
|
if (entry->mSubDocument == data->mSubDocument) {
|
|
|
|
data->mResult = NS_CONST_CAST(nsIContent *, entry->mKey);
|
|
|
|
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-17 04:17:16 +00:00
|
|
|
nsXULDocument::FindContentForSubDocument(nsIDocument *aDocument,
|
|
|
|
nsIContent **aContent)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2002-04-17 04:17:16 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDocument);
|
|
|
|
|
|
|
|
if (!mSubDocuments) {
|
|
|
|
*aContent = nsnull;
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
return NS_OK;
|
2002-04-17 04:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FindContentData data(aDocument);
|
|
|
|
PL_DHashTableEnumerate(mSubDocuments, FindContentEnumerator, &data);
|
|
|
|
|
|
|
|
*aContent = data.mResult;
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetRootContent(nsIContent** aRoot)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IF_ADDREF(*aRoot = mRootContent);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::SetRootContent(nsIContent* aRoot)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-01-12 19:41:06 +00:00
|
|
|
if (mRootContent) {
|
2000-05-19 04:48:43 +00:00
|
|
|
mRootContent->SetDocument(nsnull, PR_TRUE, PR_TRUE);
|
1999-01-12 19:41:06 +00:00
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
mRootContent = aRoot;
|
1999-01-12 19:41:06 +00:00
|
|
|
if (mRootContent) {
|
2000-05-19 04:48:43 +00:00
|
|
|
mRootContent->SetDocument(this, PR_TRUE, PR_TRUE);
|
1999-01-12 19:41:06 +00:00
|
|
|
}
|
2001-06-20 03:27:48 +00:00
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::ChildAt(PRInt32 aIndex, nsIContent*& aResult) const
|
1999-03-31 20:49:42 +00:00
|
|
|
{
|
2002-11-06 02:30:38 +00:00
|
|
|
if (aIndex != 0 || !mRootContent) {
|
|
|
|
aResult = nsnull;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
NS_ADDREF(aResult = mRootContent);
|
|
|
|
return NS_OK;
|
1999-03-31 20:49:42 +00:00
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const
|
1999-03-31 20:49:42 +00:00
|
|
|
{
|
2002-11-06 02:30:38 +00:00
|
|
|
aIndex = (aPossibleChild == mRootContent && mRootContent)? 0 : -1;
|
|
|
|
return NS_OK;
|
1999-03-31 20:49:42 +00:00
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetChildCount(PRInt32& aCount)
|
1999-03-31 20:49:42 +00:00
|
|
|
{
|
2002-11-06 02:30:38 +00:00
|
|
|
aCount = (mRootContent != nsnull);
|
|
|
|
return NS_OK;
|
1999-03-31 20:49:42 +00:00
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
2002-12-03 05:48:14 +00:00
|
|
|
nsXULDocument::GetNumberOfStyleSheets(PRBool aIncludeSpecialSheets,
|
|
|
|
PRInt32 *aCount)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2002-12-03 05:48:14 +00:00
|
|
|
PRInt32 count = mStyleSheets.Count();
|
|
|
|
if (aIncludeSpecialSheets) {
|
|
|
|
*aCount = count;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count != 0 &&
|
|
|
|
(nsIHTMLCSSStyleSheet*)mInlineStyleSheet == mStyleSheets.ElementAt(count - 1)) {
|
|
|
|
// subtract the inline style sheet
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count != 0 &&
|
|
|
|
(nsIHTMLStyleSheet*)mAttrStyleSheet == mStyleSheets.ElementAt(0)) {
|
|
|
|
// subtract the attr sheet
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(count >= 0, "How did we get a negative count?");
|
|
|
|
|
|
|
|
*aCount = count;
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
2002-12-03 05:48:14 +00:00
|
|
|
nsXULDocument::GetStyleSheetAt(PRInt32 aIndex, PRBool aIncludeSpecialSheets,
|
|
|
|
nsIStyleSheet** aSheet)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2002-12-03 05:48:14 +00:00
|
|
|
if (!aIncludeSpecialSheets) {
|
|
|
|
++aIndex; // adjust for the attr sheet
|
|
|
|
}
|
2001-06-20 03:27:48 +00:00
|
|
|
*aSheet = NS_STATIC_CAST(nsIStyleSheet*, mStyleSheets[aIndex]);
|
|
|
|
NS_IF_ADDREF(*aSheet);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetIndexOfStyleSheet(nsIStyleSheet* aSheet, PRInt32* aIndex)
|
1999-01-23 06:59:35 +00:00
|
|
|
{
|
2001-06-20 03:27:48 +00:00
|
|
|
*aIndex = mStyleSheets.IndexOf(aSheet);
|
|
|
|
return NS_OK;
|
1999-01-23 06:59:35 +00:00
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
void
|
2000-05-27 20:03:14 +00:00
|
|
|
nsXULDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
PRInt32 count = mPresShells.Count();
|
2001-04-12 01:05:42 +00:00
|
|
|
PRInt32 indx;
|
|
|
|
for (indx = 0; indx < count; indx++) {
|
2002-05-18 00:02:50 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = (nsIPresShell*)mPresShells.ElementAt(indx);
|
2000-05-27 20:03:14 +00:00
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
|
|
|
if (set) {
|
|
|
|
set->AddDocStyleSheet(aSheet, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
void
|
2002-03-15 09:45:31 +00:00
|
|
|
nsXULDocument::AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
|
|
|
if (!aSheet)
|
|
|
|
return;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
if (aSheet == mAttrStyleSheet) { // always first
|
1999-05-18 23:02:00 +00:00
|
|
|
mStyleSheets.InsertElementAt(aSheet, 0);
|
|
|
|
}
|
1999-05-19 00:05:40 +00:00
|
|
|
else if (aSheet == (nsIHTMLCSSStyleSheet*)mInlineStyleSheet) { // always last
|
1999-05-18 23:02:00 +00:00
|
|
|
mStyleSheets.AppendElement(aSheet);
|
|
|
|
}
|
|
|
|
else {
|
2001-12-21 01:10:07 +00:00
|
|
|
PRInt32 count = mStyleSheets.Count();
|
|
|
|
if (count != 0 &&
|
|
|
|
(nsIHTMLCSSStyleSheet*)mInlineStyleSheet == mStyleSheets.ElementAt(count - 1)) {
|
1999-05-18 23:02:00 +00:00
|
|
|
// keep attr sheet last
|
2001-12-21 01:10:07 +00:00
|
|
|
mStyleSheets.InsertElementAt(aSheet, count - 1);
|
1999-05-18 23:02:00 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mStyleSheets.AppendElement(aSheet);
|
|
|
|
}
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
NS_ADDREF(aSheet);
|
|
|
|
|
|
|
|
aSheet->SetOwningDocument(this);
|
|
|
|
|
2002-12-03 05:48:14 +00:00
|
|
|
PRBool applicable;
|
|
|
|
aSheet->GetApplicable(applicable);
|
|
|
|
|
|
|
|
if (applicable) {
|
2000-05-27 20:03:14 +00:00
|
|
|
AddStyleSheetToStyleSets(aSheet);
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
2002-12-03 05:48:14 +00:00
|
|
|
|
|
|
|
// if an observer removes itself, we're ok (not if it removes
|
|
|
|
// others though)
|
|
|
|
PRInt32 i;
|
|
|
|
for (i = mObservers.Count() - 1; i >= 0; --i) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(i);
|
|
|
|
observer->StyleSheetAdded(this, aSheet);
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2000-05-27 20:03:14 +00:00
|
|
|
NS_IMETHODIMP
|
2002-12-03 05:48:14 +00:00
|
|
|
nsXULDocument::UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& aOldSheets,
|
|
|
|
nsCOMArray<nsIStyleSheet>& aNewSheets)
|
2000-05-27 20:03:14 +00:00
|
|
|
{
|
2002-12-03 05:48:14 +00:00
|
|
|
// XXX Need to set the sheet on the ownernode if any
|
|
|
|
NS_PRECONDITION(aOldSheets.Count() == aNewSheets.Count(),
|
|
|
|
"The lists must be the same length!");
|
|
|
|
PRInt32 count = aOldSheets.Count();
|
2000-05-27 20:03:14 +00:00
|
|
|
|
2002-12-03 05:48:14 +00:00
|
|
|
nsCOMPtr<nsIStyleSheet> oldSheet;
|
|
|
|
PRInt32 i;
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
oldSheet = aOldSheets[i];
|
|
|
|
|
|
|
|
// First remove the old sheet.
|
|
|
|
NS_ASSERTION(oldSheet, "None of the old sheets should be null");
|
|
|
|
PRInt32 oldIndex = mStyleSheets.IndexOf((void*)oldSheet);
|
|
|
|
NS_ASSERTION(oldIndex != -1, "stylesheet not found");
|
|
|
|
mStyleSheets.RemoveElementAt(oldIndex);
|
|
|
|
|
|
|
|
PRBool applicable = PR_TRUE;
|
|
|
|
oldSheet->GetApplicable(applicable);
|
|
|
|
if (applicable) {
|
|
|
|
RemoveStyleSheetFromStyleSets(oldSheet);
|
|
|
|
}
|
|
|
|
// XXX we should really notify here, but right now that would
|
|
|
|
// force things like a full reframe on every sheet. We really
|
|
|
|
// need a way to batch this sucker...
|
|
|
|
|
|
|
|
oldSheet->SetOwningDocument(nsnull);
|
|
|
|
nsIStyleSheet* sheetPtr = oldSheet.get();
|
|
|
|
NS_RELEASE(sheetPtr);
|
|
|
|
|
|
|
|
// Now put the new one in its place. If it's null, just ignore it.
|
|
|
|
nsIStyleSheet* newSheet = aNewSheets[i];
|
|
|
|
if (newSheet) {
|
|
|
|
mStyleSheets.InsertElementAt((void*)newSheet, oldIndex);
|
|
|
|
nsIStyleSheet* sheetPtr = newSheet;
|
2000-05-27 20:03:14 +00:00
|
|
|
NS_ADDREF(sheetPtr);
|
2002-12-03 05:48:14 +00:00
|
|
|
newSheet->SetOwningDocument(this);
|
|
|
|
PRBool applicable = PR_TRUE;
|
|
|
|
newSheet->GetApplicable(applicable);
|
|
|
|
if (applicable) {
|
|
|
|
AddStyleSheetToStyleSets(newSheet);
|
2000-05-27 20:03:14 +00:00
|
|
|
}
|
2002-12-03 05:48:14 +00:00
|
|
|
|
|
|
|
// XXX we should be notifying here too.
|
2000-05-27 20:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-03 05:48:14 +00:00
|
|
|
// Now notify so _something_ happens, assuming we did anything
|
|
|
|
if (oldSheet) {
|
|
|
|
// if an observer removes itself, we're ok (not if it removes
|
|
|
|
// others though)
|
|
|
|
// XXXldb Hopefully the observer doesn't care which sheet you use.
|
|
|
|
for (PRInt32 indx = mObservers.Count() - 1; indx >= 0; --indx) {
|
|
|
|
nsIDocumentObserver* observer =
|
|
|
|
(nsIDocumentObserver*)mObservers.ElementAt(indx);
|
|
|
|
observer->StyleSheetRemoved(this, oldSheet);
|
|
|
|
}
|
2000-05-27 20:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
void
|
2000-05-27 20:03:14 +00:00
|
|
|
nsXULDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
PRInt32 count = mPresShells.Count();
|
2001-04-12 01:05:42 +00:00
|
|
|
PRInt32 indx;
|
|
|
|
for (indx = 0; indx < count; indx++) {
|
2002-05-18 00:02:50 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = (nsIPresShell*)mPresShells.ElementAt(indx);
|
2000-05-27 20:03:14 +00:00
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
|
|
|
|
if (set) {
|
|
|
|
set->RemoveDocStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
void
|
1999-11-29 22:15:07 +00:00
|
|
|
nsXULDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
mStyleSheets.RemoveElement(aSheet);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2002-12-03 05:48:14 +00:00
|
|
|
PRBool applicable = PR_TRUE;
|
|
|
|
aSheet->GetApplicable(applicable);
|
|
|
|
if (applicable) {
|
2000-05-27 20:03:14 +00:00
|
|
|
RemoveStyleSheetFromStyleSets(aSheet);
|
2002-12-03 05:48:14 +00:00
|
|
|
}
|
1999-11-29 22:15:07 +00:00
|
|
|
|
2002-12-03 05:48:14 +00:00
|
|
|
// if an observer removes itself, we're ok (not if it removes others though)
|
|
|
|
for (PRInt32 indx = mObservers.Count() - 1; indx >= 0; --indx) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(indx);
|
|
|
|
observer->StyleSheetRemoved(this, aSheet);
|
1999-11-29 22:15:07 +00:00
|
|
|
}
|
1999-11-30 04:33:28 +00:00
|
|
|
|
|
|
|
aSheet->SetOwningDocument(nsnull);
|
|
|
|
NS_RELEASE(aSheet);
|
1999-11-29 22:15:07 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 23:02:00 +00:00
|
|
|
NS_IMETHODIMP
|
2002-12-03 05:48:14 +00:00
|
|
|
nsXULDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex)
|
1999-05-18 23:02:00 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null ptr");
|
1999-11-02 01:14:07 +00:00
|
|
|
|
1999-05-18 23:02:00 +00:00
|
|
|
mStyleSheets.InsertElementAt(aSheet, aIndex + 1); // offset by one for attribute sheet
|
|
|
|
|
|
|
|
NS_ADDREF(aSheet);
|
|
|
|
aSheet->SetOwningDocument(this);
|
|
|
|
|
2002-12-03 05:48:14 +00:00
|
|
|
PRBool applicable;
|
|
|
|
aSheet->GetApplicable(applicable);
|
|
|
|
|
|
|
|
if (applicable) {
|
|
|
|
AddStyleSheetToStyleSets(aSheet);
|
|
|
|
}
|
1999-05-18 23:02:00 +00:00
|
|
|
|
2002-12-03 05:48:14 +00:00
|
|
|
// if an observer removes itself, we're ok (not if it removes
|
|
|
|
// others though)
|
1999-05-28 11:30:59 +00:00
|
|
|
PRInt32 i;
|
2002-12-03 05:48:14 +00:00
|
|
|
for (i = mObservers.Count() - 1; i >= 0; --i) {
|
1999-05-28 11:30:59 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(i);
|
1999-05-18 23:02:00 +00:00
|
|
|
observer->StyleSheetAdded(this, aSheet);
|
2002-12-03 05:48:14 +00:00
|
|
|
}
|
1999-05-18 23:02:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
void
|
2002-12-03 05:48:14 +00:00
|
|
|
nsXULDocument::SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
|
|
|
|
PRBool aApplicable)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
1999-05-28 11:30:59 +00:00
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
// If we're actually in the document style sheet list
|
1999-05-28 11:30:59 +00:00
|
|
|
if (-1 != mStyleSheets.IndexOf((void *)aSheet)) {
|
2002-12-03 05:48:14 +00:00
|
|
|
if (aApplicable) {
|
|
|
|
AddStyleSheetToStyleSets(aSheet);
|
|
|
|
} else {
|
|
|
|
RemoveStyleSheetFromStyleSets(aSheet);
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
}
|
2002-12-03 05:48:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
// XXX Some (nsHTMLEditor, eg) call this function for sheets that
|
|
|
|
// are not document sheets! So we have to always notify.
|
1998-12-24 05:07:14 +00:00
|
|
|
|
2002-12-03 06:53:22 +00:00
|
|
|
PRInt32 i;
|
2001-12-21 01:10:07 +00:00
|
|
|
// if an observer removes itself, we're ok (not if it removes others though)
|
2001-10-22 20:48:52 +00:00
|
|
|
for (i = mObservers.Count() - 1; i >= 0; --i) {
|
2002-12-03 05:48:14 +00:00
|
|
|
nsIDocumentObserver* observer =
|
|
|
|
(nsIDocumentObserver*)mObservers.ElementAt(i);
|
|
|
|
observer->StyleSheetApplicableStateChanged(this, aSheet, aApplicable);
|
1999-05-18 23:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetCSSLoader(nsICSSLoader*& aLoader)
|
1999-05-18 23:02:00 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2002-12-11 14:24:49 +00:00
|
|
|
if (!mCSSLoader) {
|
|
|
|
mCSSLoader = do_CreateInstance(kCSSLoaderCID, &result);
|
1999-05-18 23:02:00 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = mCSSLoader->Init(this);
|
1999-05-26 23:42:29 +00:00
|
|
|
mCSSLoader->SetCaseSensitive(PR_TRUE);
|
2002-06-25 21:16:17 +00:00
|
|
|
// no quirks in XUL
|
|
|
|
mCSSLoader->SetCompatibilityMode(eCompatibility_FullStandards);
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
1999-05-18 23:02:00 +00:00
|
|
|
}
|
|
|
|
aLoader = mCSSLoader;
|
|
|
|
NS_IF_ADDREF(aLoader);
|
|
|
|
return result;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetScriptLoader(nsIScriptLoader** aLoader)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLoader);
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (!mScriptLoader) {
|
|
|
|
nsScriptLoader* loader = new nsScriptLoader();
|
|
|
|
if (!loader) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mScriptLoader = loader;
|
|
|
|
mScriptLoader->Init(this);
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
*aLoader = mScriptLoader;
|
|
|
|
NS_IF_ADDREF(*aLoader);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-12-17 00:06:28 +00:00
|
|
|
*aScriptGlobalObject = mScriptGlobalObject;
|
1999-12-03 09:24:22 +00:00
|
|
|
NS_IF_ADDREF(*aScriptGlobalObject);
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-12-17 00:06:28 +00:00
|
|
|
if (!aScriptGlobalObject) {
|
|
|
|
// 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.
|
2000-09-15 06:39:29 +00:00
|
|
|
|
1999-12-17 00:06:28 +00:00
|
|
|
if (mRootContent)
|
2000-05-19 04:48:43 +00:00
|
|
|
mRootContent->SetDocument(nsnull, PR_TRUE, PR_TRUE);
|
1999-12-17 00:06:28 +00:00
|
|
|
|
2000-10-09 03:08:41 +00:00
|
|
|
// Propagate the out-of-band notification to each PresShell's
|
|
|
|
// anonymous content as well. This ensures that there aren't
|
|
|
|
// any accidental script references left in anonymous content
|
|
|
|
// keeping the document alive. (While not strictly necessary
|
|
|
|
// -- the PresShell owns us -- it's tidy.)
|
|
|
|
for (PRInt32 count = mPresShells.Count() - 1; count >= 0; --count) {
|
2002-05-18 00:02:50 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell =
|
|
|
|
NS_STATIC_CAST(nsIPresShell*, mPresShells[count]);
|
|
|
|
|
|
|
|
if (!shell)
|
2000-10-09 03:08:41 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
shell->ReleaseAnonymousContent();
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_jst
|
|
|
|
printf ("Content wrapper hash had %d entries.\n",
|
|
|
|
mContentWrapperHash.Count());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mContentWrapperHash.Reset();
|
1999-12-17 00:06:28 +00:00
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
mScriptGlobalObject = aScriptGlobalObject;
|
|
|
|
return NS_OK;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note: We don't hold a reference to the document observer; we assume
|
|
|
|
// that it has a live reference to the document.
|
1999-11-18 02:25:33 +00:00
|
|
|
void
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
PRBool
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::RemoveObserver(nsIDocumentObserver* aObserver)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mObservers.RemoveElement(aObserver);
|
|
|
|
}
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::BeginUpdate()
|
|
|
|
{
|
|
|
|
// XXX Never called. Does this matter?
|
2001-10-22 20:48:52 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
2000-01-28 23:43:12 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
|
|
|
|
observer->BeginUpdate(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::EndUpdate()
|
|
|
|
{
|
|
|
|
// XXX Never called. Does this matter?
|
2001-10-22 20:48:52 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
2000-01-28 23:43:12 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
|
|
|
|
observer->EndUpdate(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::BeginLoad()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-10-29 01:21:15 +00:00
|
|
|
// XXX Never called. Does this matter?
|
2001-10-22 20:48:52 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
|
|
|
|
observer->BeginLoad(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::EndLoad()
|
|
|
|
{
|
1999-10-05 21:13:55 +00:00
|
|
|
nsresult rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1999-11-02 01:14:07 +00:00
|
|
|
// Whack the prototype document into the cache so that the next
|
|
|
|
// time somebody asks for it, they don't need to load it by hand.
|
2002-05-03 03:04:34 +00:00
|
|
|
|
1999-11-02 01:14:07 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = mCurrentPrototype->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-02-22 03:01:34 +00:00
|
|
|
// Remember if the XUL cache is on
|
|
|
|
PRBool useXULCache;
|
|
|
|
gXULCache->GetEnabled(&useXULCache);
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
// If the current prototype is an overlay document (non-master prototype)
|
|
|
|
// and we're filling the FastLoad disk cache, tell the cache we're done
|
|
|
|
// loading it, and write the prototype.
|
|
|
|
if (useXULCache && mIsWritingFastLoad &&
|
2002-05-07 01:29:44 +00:00
|
|
|
mMasterPrototype != mCurrentPrototype &&
|
|
|
|
IsChromeURI(uri))
|
2002-05-03 03:04:34 +00:00
|
|
|
gXULCache->WritePrototype(mCurrentPrototype);
|
|
|
|
|
2002-07-23 23:30:04 +00:00
|
|
|
nsCOMPtr<nsIXULChromeRegistry> reg =
|
|
|
|
do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
|
2000-05-18 20:27:37 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-05-03 03:04:34 +00:00
|
|
|
|
2000-05-18 20:27:37 +00:00
|
|
|
nsCOMPtr<nsISupportsArray> sheets;
|
|
|
|
reg->GetStyleSheets(uri, getter_AddRefs(sheets));
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-05-18 20:27:37 +00:00
|
|
|
// Walk the sheets and add them to the prototype. Also put them into the document.
|
|
|
|
if (sheets) {
|
2001-07-31 19:05:34 +00:00
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
|
|
|
PRUint32 count;
|
|
|
|
sheets->Count(&count);
|
|
|
|
for (PRUint32 i = 0; i < count; i++) {
|
|
|
|
sheets->QueryElementAt(i, NS_GET_IID(nsICSSStyleSheet),
|
|
|
|
getter_AddRefs(sheet));
|
|
|
|
if (sheet) {
|
|
|
|
nsCOMPtr<nsIURI> sheetURL;
|
|
|
|
sheet->GetURL(*getter_AddRefs(sheetURL));
|
|
|
|
|
|
|
|
if (useXULCache && IsChromeURI(sheetURL)) {
|
|
|
|
mCurrentPrototype->AddStyleSheetReference(sheetURL);
|
|
|
|
}
|
2002-03-15 09:45:31 +00:00
|
|
|
AddStyleSheet(sheet, 0);
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
2000-05-18 20:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
if (useXULCache && IsChromeURI(uri)) {
|
|
|
|
// If it's a 'chrome:' prototype document, then notify any
|
|
|
|
// documents that raced to load the prototype, and awaited
|
|
|
|
// its load completion via proto->AwaitLoadDone().
|
|
|
|
rv = mCurrentPrototype->NotifyLoadDone();
|
1999-11-02 01:14:07 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1999-11-02 01:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now walk the prototype to build content.
|
1999-10-29 01:21:15 +00:00
|
|
|
rv = PrepareToWalk();
|
1999-10-05 21:13:55 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-07-16 04:03:52 +00:00
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
return ResumeWalk();
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// Called back from nsXULPrototypeDocument::NotifyLoadDone for each XUL
|
|
|
|
// document that raced to start the same prototype document load, lost
|
|
|
|
// the race, but hit the XUL prototype cache because the winner filled
|
|
|
|
// the cache with the not-yet-loaded prototype object.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::OnPrototypeLoadDone()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Need to clone style sheet references now, as we couldn't do that
|
|
|
|
// in StartDocumentLoad, because the prototype may not have finished
|
|
|
|
// loading at that point.
|
|
|
|
rv = AddPrototypeSheets();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Now we must do for each secondary or later XUL document (those that
|
|
|
|
// lost the race to start the prototype document load) what is done by
|
|
|
|
// nsCachedChromeStreamListener::OnStopRequest for the primary document
|
|
|
|
// (the one that won the race to start the prototype load).
|
|
|
|
rv = PrepareToWalk();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to prepare for walk");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return ResumeWalk();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
PR_STATIC_CALLBACK(PRBool)
|
|
|
|
ClearPresentationStuff(nsHashKey *aKey, void *aData, void* aClosure)
|
|
|
|
{
|
|
|
|
nsISupports *supp = NS_STATIC_CAST(nsISupports *, aData);
|
|
|
|
nsCOMPtr<nsPIBoxObject> boxObject(do_QueryInterface(supp));
|
|
|
|
|
|
|
|
if (boxObject) {
|
|
|
|
boxObject->InvalidatePresentationStuff();
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2002-04-18 19:50:31 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-22 23:48:14 +00:00
|
|
|
nsXULDocument::OnHide()
|
2002-04-18 19:50:31 +00:00
|
|
|
{
|
2002-04-22 23:48:14 +00:00
|
|
|
if (mBoxObjectTable) {
|
|
|
|
mBoxObjectTable->Enumerate(ClearPresentationStuff, nsnull);
|
|
|
|
}
|
2002-04-18 19:50:31 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-23 02:44:44 +00:00
|
|
|
static void PR_CALLBACK
|
|
|
|
ClearBroadcasterMapEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
|
|
|
|
{
|
|
|
|
BroadcasterMapEntry* entry =
|
|
|
|
NS_STATIC_CAST(BroadcasterMapEntry*, aEntry);
|
2002-08-16 21:47:12 +00:00
|
|
|
for (PRInt32 i = entry->mListeners.Count()-1; i>= 0; --i) {
|
2002-08-16 01:04:40 +00:00
|
|
|
delete (BroadcastListener*)entry->mListeners[i];
|
|
|
|
}
|
2001-10-23 02:44:44 +00:00
|
|
|
|
|
|
|
// N.B. that we need to manually run the dtor because we
|
2001-12-21 01:10:07 +00:00
|
|
|
// constructed the nsSmallVoidArray object in-place.
|
|
|
|
entry->mListeners.~nsSmallVoidArray();
|
2001-10-23 02:44:44 +00:00
|
|
|
}
|
|
|
|
|
2001-11-10 00:03:53 +00:00
|
|
|
static PRBool
|
|
|
|
CanBroadcast(PRInt32 aNameSpaceID, nsIAtom* aAttribute)
|
|
|
|
{
|
|
|
|
// Don't push changes to the |id|, |ref|, or |persist| attribute.
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if ((aAttribute == nsXULAtoms::id) ||
|
|
|
|
(aAttribute == nsXULAtoms::ref) ||
|
|
|
|
(aAttribute == nsXULAtoms::persist)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2001-11-15 02:46:29 +00:00
|
|
|
void
|
|
|
|
nsXULDocument::SynchronizeBroadcastListener(nsIDOMElement *aBroadcaster,
|
|
|
|
nsIDOMElement *aListener,
|
|
|
|
const nsAString &aAttr)
|
2001-10-23 02:44:44 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> broadcaster = do_QueryInterface(aBroadcaster);
|
|
|
|
nsCOMPtr<nsIContent> listener = do_QueryInterface(aListener);
|
|
|
|
|
|
|
|
if (aAttr.Equals(NS_LITERAL_STRING("*"))) {
|
|
|
|
PRInt32 count;
|
|
|
|
broadcaster->GetAttrCount(count);
|
|
|
|
while (--count >= 0) {
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsCOMPtr<nsIAtom> name;
|
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
|
|
|
broadcaster->GetAttrNameAt(count, nameSpaceID,
|
|
|
|
*getter_AddRefs(name),
|
|
|
|
*getter_AddRefs(prefix));
|
|
|
|
|
2001-11-10 00:03:53 +00:00
|
|
|
// _Don't_ push the |id|, |ref|, or |persist| attribute's value!
|
|
|
|
if (! CanBroadcast(nameSpaceID, name))
|
2001-10-23 02:44:44 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
broadcaster->GetAttr(nameSpaceID, name, value);
|
2002-09-12 04:40:22 +00:00
|
|
|
listener->SetAttr(nameSpaceID, name, value, PR_FALSE);
|
2001-11-15 02:46:29 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// XXX we don't fire the |onbroadcast| handler during
|
|
|
|
// initial hookup: doing so would potentially run the
|
|
|
|
// |onbroadcast| handler before the |onload| handler,
|
|
|
|
// which could define JS properties that mask XBL
|
|
|
|
// properties, etc.
|
|
|
|
ExecuteOnBroadcastHandlerFor(broadcaster, aListener, name);
|
|
|
|
#endif
|
2001-10-23 02:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Find out if the attribute is even present at all.
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> name = do_GetAtom(aAttr);
|
2001-10-23 02:44:44 +00:00
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
nsresult rv = broadcaster->GetAttr(kNameSpaceID_None, name, value);
|
|
|
|
|
|
|
|
if (rv == NS_CONTENT_ATTR_NO_VALUE ||
|
|
|
|
rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
2002-09-12 04:40:22 +00:00
|
|
|
listener->SetAttr(kNameSpaceID_None, name, value, PR_FALSE);
|
2001-10-23 02:44:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-09-12 04:40:22 +00:00
|
|
|
listener->UnsetAttr(kNameSpaceID_None, name, PR_FALSE);
|
2001-10-23 02:44:44 +00:00
|
|
|
}
|
2001-11-15 02:46:29 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// XXX we don't fire the |onbroadcast| handler during initial
|
|
|
|
// hookup: doing so would potentially run the |onbroadcast|
|
|
|
|
// handler before the |onload| handler, which could define JS
|
|
|
|
// properties that mask XBL properties, etc.
|
|
|
|
ExecuteOnBroadcastHandlerFor(broadcaster, aListener, name);
|
|
|
|
#endif
|
2001-10-23 02:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::AddBroadcastListenerFor(nsIDOMElement* aBroadcaster,
|
|
|
|
nsIDOMElement* aListener,
|
|
|
|
const nsAString& aAttr)
|
|
|
|
{
|
2002-07-18 05:53:28 +00:00
|
|
|
nsresult rv = nsContentUtils::CheckSameOrigin(this, aBroadcaster);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = nsContentUtils::CheckSameOrigin(this, aListener);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2002-07-16 13:09:15 +00:00
|
|
|
}
|
|
|
|
|
2001-10-23 02:44:44 +00:00
|
|
|
static PLDHashTableOps gOps = {
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashGetKeyStub,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
PL_DHashMatchEntryStub,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
ClearBroadcasterMapEntry,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
nsnull
|
|
|
|
};
|
|
|
|
|
|
|
|
if (! mBroadcasterMap) {
|
|
|
|
mBroadcasterMap =
|
|
|
|
PL_NewDHashTable(&gOps, nsnull, sizeof(BroadcasterMapEntry),
|
|
|
|
PL_DHASH_MIN_SIZE);
|
|
|
|
|
|
|
|
if (! mBroadcasterMap)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
BroadcasterMapEntry* entry =
|
|
|
|
NS_STATIC_CAST(BroadcasterMapEntry*,
|
|
|
|
PL_DHashTableOperate(mBroadcasterMap, aBroadcaster,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_FREE(entry)) {
|
|
|
|
entry =
|
|
|
|
NS_STATIC_CAST(BroadcasterMapEntry*,
|
|
|
|
PL_DHashTableOperate(mBroadcasterMap, aBroadcaster,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
|
|
|
|
if (! entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
entry->mBroadcaster = aBroadcaster;
|
|
|
|
|
2001-12-21 01:10:07 +00:00
|
|
|
// N.B. placement new to construct the nsSmallVoidArray object
|
2001-10-23 02:44:44 +00:00
|
|
|
// in-place
|
2001-12-21 01:10:07 +00:00
|
|
|
new (&entry->mListeners) nsSmallVoidArray();
|
2001-10-23 02:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only add the listener if it's not there already!
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> attr = do_GetAtom(aAttr);
|
2001-10-23 02:44:44 +00:00
|
|
|
|
|
|
|
BroadcastListener* bl;
|
|
|
|
for (PRInt32 i = entry->mListeners.Count() - 1; i >= 0; --i) {
|
|
|
|
bl = NS_STATIC_CAST(BroadcastListener*, entry->mListeners[i]);
|
|
|
|
|
|
|
|
if ((bl->mListener == aListener) && (bl->mAttribute == attr))
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bl = new BroadcastListener;
|
|
|
|
if (! bl)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
bl->mListener = aListener;
|
|
|
|
bl->mAttribute = attr;
|
|
|
|
|
|
|
|
entry->mListeners.AppendElement(bl);
|
|
|
|
|
|
|
|
SynchronizeBroadcastListener(aBroadcaster, aListener, aAttr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::RemoveBroadcastListenerFor(nsIDOMElement* aBroadcaster,
|
|
|
|
nsIDOMElement* aListener,
|
|
|
|
const nsAString& aAttr)
|
|
|
|
{
|
|
|
|
// If we haven't added any broadcast listeners, then there sure
|
|
|
|
// aren't any to remove.
|
|
|
|
if (! mBroadcasterMap)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
BroadcasterMapEntry* entry =
|
|
|
|
NS_STATIC_CAST(BroadcasterMapEntry*,
|
|
|
|
PL_DHashTableOperate(mBroadcasterMap, aBroadcaster,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> attr = do_GetAtom(aAttr);
|
2001-10-23 02:44:44 +00:00
|
|
|
for (PRInt32 i = entry->mListeners.Count() - 1; i >= 0; --i) {
|
|
|
|
BroadcastListener* bl =
|
|
|
|
NS_STATIC_CAST(BroadcastListener*, entry->mListeners[i]);
|
|
|
|
|
|
|
|
if ((bl->mListener == aListener) && (bl->mAttribute == attr)) {
|
|
|
|
entry->mListeners.RemoveElement(aListener);
|
|
|
|
|
|
|
|
if (entry->mListeners.Count() == 0)
|
|
|
|
PL_DHashTableOperate(mBroadcasterMap, aBroadcaster,
|
|
|
|
PL_DHASH_REMOVE);
|
|
|
|
|
|
|
|
SynchronizeBroadcastListener(aBroadcaster, aListener, aAttr);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::ContentChanged(nsIContent* aContent,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsISupports* aSubContent)
|
|
|
|
{
|
2001-10-22 20:48:52 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentChanged(this, aContent, aSubContent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-07 03:34:29 +00:00
|
|
|
nsXULDocument::ContentStatesChanged(nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2,
|
2002-04-11 03:49:30 +00:00
|
|
|
PRInt32 aStateMask)
|
1999-02-27 07:15:09 +00:00
|
|
|
{
|
2001-10-22 20:48:52 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
1999-02-27 07:15:09 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
2002-04-11 03:49:30 +00:00
|
|
|
observer->ContentStatesChanged(this, aContent1, aContent2, aStateMask);
|
1999-02-27 07:15:09 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-23 02:44:44 +00:00
|
|
|
nsresult
|
|
|
|
nsXULDocument::ExecuteOnBroadcastHandlerFor(nsIContent* aBroadcaster,
|
|
|
|
nsIDOMElement* aListener,
|
|
|
|
nsIAtom* aAttr)
|
|
|
|
{
|
|
|
|
// Now we execute the onchange handler in the context of the
|
|
|
|
// observer. We need to find the observer in order to
|
|
|
|
// execute the handler.
|
|
|
|
nsAutoString attrName;
|
|
|
|
aAttr->ToString(attrName);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> listener = do_QueryInterface(aListener);
|
|
|
|
PRInt32 count;
|
|
|
|
listener->ChildCount(count);
|
|
|
|
for (PRInt32 i = 0; i < count; ++i) {
|
2001-11-15 02:46:29 +00:00
|
|
|
// Look for an <observes> element beneath the listener. This
|
|
|
|
// ought to have an |element| attribute that refers to
|
|
|
|
// aBroadcaster, and an |attribute| element that tells us what
|
|
|
|
// attriubtes we're listening for.
|
2001-10-23 02:44:44 +00:00
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
listener->ChildAt(i, *getter_AddRefs(child));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
child->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag != nsXULAtoms::observes)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Is this the element that was listening to us?
|
|
|
|
nsAutoString listeningToID;
|
2001-11-15 02:46:29 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsXULAtoms::element, listeningToID);
|
2001-10-23 02:44:44 +00:00
|
|
|
|
|
|
|
nsAutoString broadcasterID;
|
|
|
|
aBroadcaster->GetAttr(kNameSpaceID_None, nsXULAtoms::id, broadcasterID);
|
|
|
|
|
|
|
|
if (listeningToID != broadcasterID)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// We are observing the broadcaster, but is this the right
|
|
|
|
// attribute?
|
|
|
|
nsAutoString listeningToAttribute;
|
2001-11-15 02:46:29 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsXULAtoms::attribute,
|
|
|
|
listeningToAttribute);
|
2001-10-23 02:44:44 +00:00
|
|
|
|
2001-11-15 02:46:29 +00:00
|
|
|
if (listeningToAttribute != attrName &&
|
|
|
|
listeningToAttribute != NS_LITERAL_STRING("*")) {
|
2001-10-23 02:44:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-11-15 02:46:29 +00:00
|
|
|
// This is the right <observes> element. Execute the
|
|
|
|
// |onbroadcast| event handler
|
2001-10-23 02:44:44 +00:00
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_XUL_BROADCAST;
|
|
|
|
|
|
|
|
PRInt32 j = mPresShells.Count();
|
|
|
|
while (--j >= 0) {
|
2002-05-18 00:02:50 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell =
|
|
|
|
NS_STATIC_CAST(nsIPresShell*, mPresShells[j]);
|
2001-10-23 02:44:44 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> aPresContext;
|
|
|
|
shell->GetPresContext(getter_AddRefs(aPresContext));
|
|
|
|
|
|
|
|
// Handle the DOM event
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2002-05-18 00:02:50 +00:00
|
|
|
child->HandleDOMEvent(aPresContext, &event, nsnull,
|
|
|
|
NS_EVENT_FLAG_INIT, &status);
|
2001-10-23 02:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::AttributeChanged(nsIContent* aElement,
|
2001-10-23 02:44:44 +00:00
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType,
|
2002-08-24 14:41:28 +00:00
|
|
|
nsChangeHint aHint)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-08-30 02:45:54 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// First see if we need to update our element map.
|
2001-03-23 10:56:18 +00:00
|
|
|
if ((aAttribute == nsXULAtoms::id) || (aAttribute == nsXULAtoms::ref)) {
|
1999-08-30 02:45:54 +00:00
|
|
|
|
1999-10-07 10:09:17 +00:00
|
|
|
rv = mElementMap.Enumerate(RemoveElementsFromMapByContent, aElement);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-30 02:45:54 +00:00
|
|
|
|
1999-10-07 10:09:17 +00:00
|
|
|
// That'll have removed _both_ the 'ref' and 'id' entries from
|
|
|
|
// the map. So add 'em back now.
|
|
|
|
rv = AddElementToMap(aElement);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-30 02:45:54 +00:00
|
|
|
}
|
|
|
|
|
2001-10-23 02:44:44 +00:00
|
|
|
// Synchronize broadcast listeners
|
2001-11-10 00:03:53 +00:00
|
|
|
if (mBroadcasterMap && CanBroadcast(aNameSpaceID, aAttribute)) {
|
2001-10-23 02:44:44 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> domele = do_QueryInterface(aElement);
|
|
|
|
BroadcasterMapEntry* entry =
|
|
|
|
NS_STATIC_CAST(BroadcasterMapEntry*,
|
|
|
|
PL_DHashTableOperate(mBroadcasterMap, domele.get(),
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
// We've got listeners: push the value.
|
|
|
|
nsAutoString value;
|
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, aAttribute,
|
|
|
|
value);
|
|
|
|
|
|
|
|
for (PRInt32 i = entry->mListeners.Count() - 1; i >= 0; --i) {
|
|
|
|
BroadcastListener* bl =
|
|
|
|
NS_STATIC_CAST(BroadcastListener*, entry->mListeners[i]);
|
|
|
|
|
|
|
|
if ((bl->mAttribute == aAttribute) ||
|
|
|
|
(bl->mAttribute == nsXULAtoms::_star)) {
|
|
|
|
nsCOMPtr<nsIContent> listener
|
|
|
|
= do_QueryInterface(bl->mListener);
|
|
|
|
|
|
|
|
if (rv == NS_CONTENT_ATTR_NO_VALUE ||
|
|
|
|
rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
|
|
|
listener->SetAttr(kNameSpaceID_None, aAttribute,
|
|
|
|
value, PR_TRUE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
listener->UnsetAttr(kNameSpaceID_None, aAttribute,
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExecuteOnBroadcastHandlerFor(aElement, bl->mListener,
|
|
|
|
aAttribute);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-15 02:46:29 +00:00
|
|
|
// Now notify external observers
|
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->AttributeChanged(this, aElement, aNameSpaceID, aAttribute, aModType, aHint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if there is anything we need to persist in the localstore.
|
|
|
|
//
|
|
|
|
// XXX Namespace handling broken :-(
|
|
|
|
nsAutoString persist;
|
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::persist, persist);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
|
|
|
nsAutoString attr;
|
|
|
|
rv = aAttribute->ToString(attr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (persist.Find(attr) >= 0) {
|
|
|
|
rv = Persist(aElement, kNameSpaceID_None, aAttribute);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::ContentAppended(nsIContent* aContainer,
|
1999-08-30 02:45:54 +00:00
|
|
|
PRInt32 aNewIndexInContainer)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-08-30 02:45:54 +00:00
|
|
|
// First update our element map
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
PRInt32 count;
|
|
|
|
rv = aContainer->ChildCount(count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
for (PRInt32 i = aNewIndexInContainer; i < count; ++i) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
rv = aContainer->ChildAt(i, *getter_AddRefs(child));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-09-17 04:29:53 +00:00
|
|
|
rv = AddSubtreeToDocument(child);
|
1999-08-30 02:45:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now notify external observers
|
2001-10-25 07:31:18 +00:00
|
|
|
PRInt32 count = mObservers.Count();
|
2001-10-25 21:01:43 +00:00
|
|
|
// XXXdwh There is a hacky ordering dependency between the binding manager
|
|
|
|
// and the frame constructor that forces us to walk the observer list
|
|
|
|
// in a forward order
|
2001-10-25 07:31:18 +00:00
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentAppended(this, aContainer, aNewIndexInContainer);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::ContentInserted(nsIContent* aContainer,
|
1999-08-30 02:45:54 +00:00
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-08-30 02:45:54 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-09-17 04:29:53 +00:00
|
|
|
rv = AddSubtreeToDocument(aChild);
|
1999-08-30 02:45:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now notify external observers
|
2001-10-25 07:31:18 +00:00
|
|
|
PRInt32 count = mObservers.Count();
|
2001-10-25 21:01:43 +00:00
|
|
|
// XXXdwh There is a hacky ordering dependency between the binding manager
|
|
|
|
// and the frame constructor that forces us to walk the observer list
|
|
|
|
// in a forward order
|
2001-10-25 07:31:18 +00:00
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentInserted(this, aContainer, aChild, aIndexInContainer);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::ContentReplaced(nsIContent* aContainer,
|
1999-08-30 02:45:54 +00:00
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-08-30 02:45:54 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-09-17 04:29:53 +00:00
|
|
|
rv = RemoveSubtreeFromDocument(aOldChild);
|
1999-08-30 02:45:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-09-17 04:29:53 +00:00
|
|
|
rv = AddSubtreeToDocument(aNewChild);
|
1999-08-30 02:45:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now notify external observers
|
2001-10-25 07:31:18 +00:00
|
|
|
PRInt32 count = mObservers.Count();
|
2001-10-25 21:01:43 +00:00
|
|
|
// XXXdwh There is a hacky ordering dependency between the binding manager
|
|
|
|
// and the frame constructor that forces us to walk the observer list
|
|
|
|
// in a reverse order
|
|
|
|
for (PRInt32 i = count-1; i >=0; i--) {
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->ContentReplaced(this, aContainer, aOldChild, aNewChild,
|
|
|
|
aIndexInContainer);
|
2001-10-25 20:39:40 +00:00
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::ContentRemoved(nsIContent* aContainer,
|
1999-08-30 02:45:54 +00:00
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-08-30 02:45:54 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-09-17 04:29:53 +00:00
|
|
|
rv = RemoveSubtreeFromDocument(aChild);
|
1999-08-30 02:45:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now notify external observers
|
2001-10-25 07:31:18 +00:00
|
|
|
PRInt32 count = mObservers.Count();
|
2001-10-25 21:01:43 +00:00
|
|
|
// XXXdwh There is a hacky ordering dependency between the binding manager
|
|
|
|
// and the frame constructor that forces us to walk the observer list
|
|
|
|
// in a reverse order
|
|
|
|
for (PRInt32 i = count-1; i >=0; i--) {
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
1999-11-18 02:25:33 +00:00
|
|
|
observer->ContentRemoved(this, aContainer,
|
1998-12-24 05:07:14 +00:00
|
|
|
aChild, aIndexInContainer);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::AttributeWillChange(nsIContent* aChild,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::StyleRuleChanged(nsIStyleSheet* aStyleSheet,
|
2002-08-24 14:41:28 +00:00
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
nsChangeHint aHint)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2001-10-22 20:48:52 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->StyleRuleChanged(this, aStyleSheet, aStyleRule, aHint);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::StyleRuleAdded(nsIStyleSheet* aStyleSheet,
|
1999-08-30 02:45:54 +00:00
|
|
|
nsIStyleRule* aStyleRule)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2001-10-22 20:48:52 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->StyleRuleAdded(this, aStyleSheet, aStyleRule);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
|
1999-08-30 02:45:54 +00:00
|
|
|
nsIStyleRule* aStyleRule)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
2001-10-22 20:48:52 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
|
|
|
observer->StyleRuleRemoved(this, aStyleSheet, aStyleRule);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
2000-09-14 11:45:01 +00:00
|
|
|
nsXULDocument::GetSelection(nsISelection** aSelection)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
if (!mSelection) {
|
2000-01-26 20:39:28 +00:00
|
|
|
NS_ASSERTION(0,"not initialized");
|
1998-12-24 05:07:14 +00:00
|
|
|
*aSelection = nsnull;
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
*aSelection = mSelection;
|
1999-05-28 11:30:59 +00:00
|
|
|
NS_ADDREF(*aSelection);
|
1998-12-24 05:07:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::SelectAll()
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
nsIContent * start = nsnull;
|
|
|
|
nsIContent * end = nsnull;
|
|
|
|
nsIContent * body = nsnull;
|
|
|
|
|
|
|
|
PRInt32 i, n;
|
|
|
|
mRootContent->ChildCount(n);
|
|
|
|
for (i=0;i<n;i++) {
|
|
|
|
nsIContent * child;
|
|
|
|
mRootContent->ChildAt(i, child);
|
2000-11-08 00:42:42 +00:00
|
|
|
nsCOMPtr<nsIAtom> atom;
|
|
|
|
child->GetTag(*getter_AddRefs(atom));
|
2002-02-19 22:49:12 +00:00
|
|
|
|
|
|
|
nsAutoString atomValue;
|
|
|
|
atom->ToString(atomValue);
|
|
|
|
|
|
|
|
ToUpperCase(atomValue);
|
|
|
|
if (NS_LITERAL_STRING("BODY").Equals(atomValue)) {
|
2000-11-08 00:42:42 +00:00
|
|
|
body = child;
|
|
|
|
break;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
2000-11-08 00:42:42 +00:00
|
|
|
|
1998-12-24 05:07:14 +00:00
|
|
|
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
|
2000-04-28 06:22:07 +00:00
|
|
|
SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
1998-12-24 05:07:14 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::FindNext(const nsAString &aSearchStr,
|
2000-08-23 17:27:06 +00:00
|
|
|
PRBool aMatchCase, PRBool aSearchDown,
|
|
|
|
PRBool &aIsFound)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
aIsFound = PR_FALSE;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_IMETHODIMP
|
2001-08-31 04:28:26 +00:00
|
|
|
nsXULDocument::FlushPendingNotifications(PRBool aFlushReflows, PRBool aUpdateViews)
|
2000-01-24 06:43:15 +00:00
|
|
|
{
|
2001-02-06 05:46:46 +00:00
|
|
|
if (aFlushReflows) {
|
2000-01-24 06:43:15 +00:00
|
|
|
|
2001-02-06 05:46:46 +00:00
|
|
|
PRInt32 i, count = mPresShells.Count();
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2002-05-18 00:02:50 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell =
|
|
|
|
NS_STATIC_CAST(nsIPresShell*, mPresShells[i]);
|
|
|
|
|
2001-02-06 05:46:46 +00:00
|
|
|
if (shell) {
|
2001-08-31 04:28:26 +00:00
|
|
|
shell->FlushPendingNotifications(aUpdateViews);
|
2001-02-06 05:46:46 +00:00
|
|
|
}
|
2000-01-24 06:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-21 03:25:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetAndIncrementContentID(PRInt32* aID)
|
|
|
|
{
|
|
|
|
*aID = mNextContentID++;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-09 21:41:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetBindingManager(nsIBindingManager** aResult)
|
|
|
|
{
|
|
|
|
*aResult = mBindingManager;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetNodeInfoManager(class nsINodeInfoManager *&aNodeInfoManager)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
aNodeInfoManager = mNodeInfoManager;
|
|
|
|
NS_ADDREF(aNodeInfoManager);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::AddReference(void *aKey, nsISupports *aReference)
|
|
|
|
{
|
|
|
|
nsVoidKey key(aKey);
|
|
|
|
|
|
|
|
if (mScriptGlobalObject) {
|
|
|
|
mContentWrapperHash.Put(&key, aReference);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::RemoveReference(void *aKey, nsISupports **aOldReference)
|
|
|
|
{
|
|
|
|
nsVoidKey key(aKey);
|
|
|
|
|
|
|
|
mContentWrapperHash.Remove(&key, aOldReference);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetContainer(nsISupports *aContainer)
|
|
|
|
{
|
|
|
|
mDocumentContainer = dont_AddRef(NS_GetWeakReference(aContainer));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetContainer(nsISupports **aContainer)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> container = do_QueryReferent(mDocumentContainer);
|
|
|
|
|
|
|
|
*aContainer = container;
|
|
|
|
NS_IF_ADDREF(*aContainer);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-11-07 05:17:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetScriptEventManager(nsIScriptEventManager **aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
void
|
2000-04-20 23:11:41 +00:00
|
|
|
nsXULDocument::SetDisplaySelection(PRInt8 aToggle)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
mDisplaySelection = aToggle;
|
|
|
|
}
|
|
|
|
|
2000-04-20 23:11:41 +00:00
|
|
|
PRInt8
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetDisplaySelection() const
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
|
|
|
return mDisplaySelection;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext,
|
1999-11-18 02:25:33 +00:00
|
|
|
nsEvent* aEvent,
|
1998-12-24 05:07:14 +00:00
|
|
|
nsIDOMEvent** aDOMEvent,
|
|
|
|
PRUint32 aFlags,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-12-24 05:07:14 +00:00
|
|
|
{
|
1999-05-16 07:05:51 +00:00
|
|
|
nsresult ret = NS_OK;
|
|
|
|
nsIDOMEvent* domEvent = nsnull;
|
2001-11-14 10:06:21 +00:00
|
|
|
PRBool externalDOMEvent = PR_FALSE;
|
1999-05-16 07:05:51 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
if (NS_EVENT_FLAG_INIT & aFlags) {
|
2001-11-14 10:06:21 +00:00
|
|
|
if (aDOMEvent) {
|
|
|
|
if (*aDOMEvent) {
|
|
|
|
externalDOMEvent = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aDOMEvent = &domEvent;
|
|
|
|
}
|
2002-11-09 00:25:25 +00:00
|
|
|
aEvent->flags |= aFlags;
|
2000-05-16 11:35:12 +00:00
|
|
|
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
|
2002-11-09 00:25:25 +00:00
|
|
|
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
|
1999-05-16 07:05:51 +00:00
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-05-16 07:05:51 +00:00
|
|
|
//Capturing stage
|
2002-11-09 00:25:25 +00:00
|
|
|
if (NS_EVENT_FLAG_CAPTURE & aFlags && mScriptGlobalObject) {
|
|
|
|
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags & NS_EVENT_CAPTURE_MASK, aEventStatus);
|
1999-05-16 07:05:51 +00:00
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-05-16 07:05:51 +00:00
|
|
|
//Local handling stage
|
2002-11-09 00:25:25 +00:00
|
|
|
if (mListenerManager) {
|
2000-02-08 02:05:57 +00:00
|
|
|
aEvent->flags |= aFlags;
|
2000-05-16 11:35:12 +00:00
|
|
|
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
|
2000-02-08 02:05:57 +00:00
|
|
|
aEvent->flags &= ~aFlags;
|
1999-05-16 07:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Bubbling stage
|
2002-11-09 00:25:25 +00:00
|
|
|
if (NS_EVENT_FLAG_BUBBLE & aFlags && mScriptGlobalObject) {
|
|
|
|
mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags & NS_EVENT_BUBBLE_MASK, aEventStatus);
|
1999-05-16 07:05:51 +00:00
|
|
|
}
|
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
if (NS_EVENT_FLAG_INIT & aFlags) {
|
1999-05-16 07:05:51 +00:00
|
|
|
// We're leaving the DOM event loop so if we created a DOM event, release here.
|
2001-11-14 10:06:21 +00:00
|
|
|
if (nsnull != *aDOMEvent && !externalDOMEvent) {
|
1999-05-16 07:05:51 +00:00
|
|
|
nsrefcnt rc;
|
|
|
|
NS_RELEASE2(*aDOMEvent, rc);
|
|
|
|
if (0 != rc) {
|
2002-12-11 14:24:49 +00:00
|
|
|
// 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.
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(*aDOMEvent);
|
|
|
|
if (privateEvent) {
|
1999-05-16 07:05:51 +00:00
|
|
|
privateEvent->DuplicatePrivateData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aDOMEvent = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
1998-12-24 05:07:14 +00:00
|
|
|
}
|
|
|
|
|
2001-03-13 11:37:16 +00:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsXULDocument::EventCaptureRegistration(PRInt32 aCapturerIncrement)
|
|
|
|
{
|
|
|
|
mNumCapturers += aCapturerIncrement;
|
2001-10-23 02:44:44 +00:00
|
|
|
NS_ASSERTION(mNumCapturers >= 0, "Number of capturers has become negative");
|
2001-03-13 11:37:16 +00:00
|
|
|
return (mNumCapturers > 0 ? PR_TRUE : PR_FALSE);
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1998-12-24 05:07:14 +00:00
|
|
|
// nsIXMLDocument interface
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
2000-09-02 15:35:19 +00:00
|
|
|
nsXULDocument::SetDefaultStylesheets(nsIURI* aUrl)
|
1999-06-28 14:12:07 +00:00
|
|
|
{
|
2000-01-26 20:39:28 +00:00
|
|
|
NS_ASSERTION(0,"not implemented");
|
2000-09-02 15:35:19 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::SetDefaultStylesheets");
|
1999-06-28 14:12:07 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1999-02-04 10:50:50 +00:00
|
|
|
|
2001-02-03 01:16:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetTitle(const PRUnichar *aTitle)
|
|
|
|
{
|
2001-05-19 11:27:30 +00:00
|
|
|
return SetTitle(nsDependentString(aTitle));
|
2001-02-03 01:16:20 +00:00
|
|
|
}
|
|
|
|
|
2002-08-13 18:41:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetXMLDeclaration(const nsAString& aVersion,
|
|
|
|
const nsAString& aEncoding,
|
|
|
|
const nsAString& aStandalone)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetXMLDeclaration(nsAString& aVersion,
|
|
|
|
nsAString& aEncoding,
|
|
|
|
nsAString& aStandalone)
|
|
|
|
{
|
|
|
|
aVersion.Truncate();
|
|
|
|
aEncoding.Truncate();
|
|
|
|
aStandalone.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-10-05 21:13:55 +00:00
|
|
|
// nsIXULDocument interface
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::AddElementForID(const nsAString& aID, nsIContent* aElement)
|
1999-02-09 03:15:41 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
|
|
|
if (! aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
mElementMap.Add(aID, aElement);
|
1999-02-09 03:15:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::RemoveElementForID(const nsAString& aID, nsIContent* aElement)
|
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-10-05 21:13:55 +00:00
|
|
|
mElementMap.Remove(aID, aElement);
|
1999-02-09 03:15:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-02-09 03:15:41 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetElementsForID(const nsAString& aID, nsISupportsArray* aElements)
|
1999-02-09 03:15:41 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aElements != nsnull, "null ptr");
|
|
|
|
if (! aElements)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
mElementMap.Find(aID, aElements);
|
1999-01-12 19:41:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-30 02:32:34 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::AddForwardReference(nsForwardReference* aRef)
|
1999-09-30 02:32:34 +00:00
|
|
|
{
|
1999-11-17 03:20:03 +00:00
|
|
|
if (mResolutionPhase < aRef->GetPhase()) {
|
1999-10-05 21:13:55 +00:00
|
|
|
mForwardReferences.AppendElement(aRef);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ERROR("forward references have already been resolved");
|
|
|
|
delete aRef;
|
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-30 02:32:34 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::ResolveForwardReferences()
|
1999-10-05 21:13:55 +00:00
|
|
|
{
|
1999-11-17 03:20:03 +00:00
|
|
|
if (mResolutionPhase == nsForwardReference::eDone)
|
1999-10-05 21:13:55 +00:00
|
|
|
return NS_OK;
|
1999-09-30 02:32:34 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
// Resolve each outstanding 'forward' reference. We iterate
|
|
|
|
// through the list of forward references until no more forward
|
|
|
|
// references can be resolved. This annealing process is
|
|
|
|
// guaranteed to converge because we've "closed the gate" to new
|
|
|
|
// forward references.
|
1999-09-30 02:32:34 +00:00
|
|
|
|
1999-11-17 03:20:03 +00:00
|
|
|
const nsForwardReference::Phase* pass = nsForwardReference::kPasses;
|
1999-11-17 02:45:46 +00:00
|
|
|
while ((mResolutionPhase = *pass) != nsForwardReference::eDone) {
|
1999-10-29 01:21:15 +00:00
|
|
|
PRInt32 previous = 0;
|
|
|
|
while (mForwardReferences.Count() && mForwardReferences.Count() != previous) {
|
|
|
|
previous = mForwardReferences.Count();
|
1999-09-30 02:32:34 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
for (PRInt32 i = 0; i < mForwardReferences.Count(); ++i) {
|
|
|
|
nsForwardReference* fwdref = NS_REINTERPRET_CAST(nsForwardReference*, mForwardReferences[i]);
|
1999-09-30 02:32:34 +00:00
|
|
|
|
1999-11-17 03:20:03 +00:00
|
|
|
if (fwdref->GetPhase() == *pass) {
|
1999-11-17 02:45:46 +00:00
|
|
|
nsForwardReference::Result result = fwdref->Resolve();
|
1999-10-05 21:13:55 +00:00
|
|
|
|
1999-11-17 02:45:46 +00:00
|
|
|
switch (result) {
|
|
|
|
case nsForwardReference::eResolve_Succeeded:
|
|
|
|
case nsForwardReference::eResolve_Error:
|
|
|
|
mForwardReferences.RemoveElementAt(i);
|
|
|
|
delete fwdref;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
1999-11-17 02:45:46 +00:00
|
|
|
// fixup because we removed from list
|
|
|
|
--i;
|
|
|
|
break;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
1999-11-17 02:45:46 +00:00
|
|
|
case nsForwardReference::eResolve_Later:
|
|
|
|
// do nothing. we'll try again later
|
|
|
|
;
|
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
1999-09-30 02:32:34 +00:00
|
|
|
}
|
|
|
|
}
|
1999-11-17 02:45:46 +00:00
|
|
|
|
|
|
|
++pass;
|
1999-09-30 02:32:34 +00:00
|
|
|
}
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
DestroyForwardReferences();
|
1999-09-30 02:32:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-08 04:56:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetMasterPrototype(nsIXULPrototypeDocument* aDocument)
|
|
|
|
{
|
|
|
|
mMasterPrototype = aDocument;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-22 22:00:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetMasterPrototype(nsIXULPrototypeDocument** aDocument)
|
|
|
|
{
|
|
|
|
*aDocument = mMasterPrototype;
|
|
|
|
NS_IF_ADDREF(*aDocument);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-08 04:56:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetCurrentPrototype(nsIXULPrototypeDocument* aDocument)
|
|
|
|
{
|
|
|
|
mCurrentPrototype = aDocument;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-20 06:39:37 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIDOMDocument interface
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetDoctype(nsIDOMDocumentType** aDoctype)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::GetDoctype");
|
2000-05-13 08:13:54 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDoctype);
|
|
|
|
*aDoctype = nsnull;
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetImplementation(nsIDOMDOMImplementation** aImplementation)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
2000-05-10 23:02:32 +00:00
|
|
|
nsresult rv;
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallCreateInstance(kDOMImplementationCID, aImplementation);
|
2000-05-10 23:02:32 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-01-14 10:55:08 +00:00
|
|
|
|
2000-05-10 23:02:32 +00:00
|
|
|
nsCOMPtr<nsIPrivateDOMImplementation> impl = do_QueryInterface(*aImplementation, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-06-21 23:56:52 +00:00
|
|
|
rv = impl->Init(mDocumentURL);
|
2000-05-10 23:02:32 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-01-14 10:55:08 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetDocumentElement(nsIDOMElement** aDocumentElement)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDocumentElement);
|
1999-02-17 22:32:40 +00:00
|
|
|
|
1999-05-28 11:30:59 +00:00
|
|
|
if (mRootContent) {
|
2002-12-11 14:24:49 +00:00
|
|
|
return CallQueryInterface(mRootContent, aDocumentElement);
|
1999-05-28 11:30:59 +00:00
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
|
|
|
*aDocumentElement = nsnull;
|
|
|
|
|
|
|
|
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
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateElement(const nsAString& aTagName,
|
2000-08-23 17:27:06 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2000-05-25 23:48:45 +00:00
|
|
|
nsCOMPtr<nsIAtom> name, prefix;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
name = do_GetAtom(aTagName);
|
2000-08-31 00:36:31 +00:00
|
|
|
NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
|
2000-05-25 23:48:45 +00:00
|
|
|
|
1999-07-27 17:20:28 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gXULLog, PR_LOG_DEBUG)) {
|
2000-08-23 17:27:06 +00:00
|
|
|
char* tagCStr = ToNewCString(aTagName);
|
1999-07-27 17:20:28 +00:00
|
|
|
|
|
|
|
PR_LOG(gXULLog, PR_LOG_DEBUG,
|
|
|
|
("xul[CreateElement] %s", tagCStr));
|
|
|
|
|
1999-09-04 13:59:52 +00:00
|
|
|
nsCRT::free(tagCStr);
|
1999-07-27 17:20:28 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-07-07 06:52:21 +00:00
|
|
|
*aReturn = nsnull;
|
|
|
|
|
2000-05-15 19:02:30 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> ni;
|
|
|
|
|
|
|
|
// CreateElement in the XUL document defaults to the XUL namespace.
|
|
|
|
mNodeInfoManager->GetNodeInfo(name, prefix, kNameSpaceID_XUL,
|
|
|
|
*getter_AddRefs(ni));
|
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
nsCOMPtr<nsIContent> result;
|
2000-05-15 19:02:30 +00:00
|
|
|
rv = CreateElement(ni, getter_AddRefs(result));
|
1999-04-16 08:38:17 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// get the DOM interface
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallQueryInterface(result, aReturn);
|
1999-04-16 08:38:17 +00:00
|
|
|
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-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::CreateDocumentFragment");
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateTextNode(const nsAString& aData,
|
2000-08-23 17:27:06 +00:00
|
|
|
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;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsITextContent> text = do_CreateInstance(kTextNodeCID, &rv);
|
1999-04-16 08:38:17 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
rv = text->SetText(aData, PR_FALSE);
|
1999-04-16 08:38:17 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallQueryInterface(text, aReturn);
|
1999-04-16 08:38:17 +00:00
|
|
|
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
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateComment(const nsAString& aData,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMComment** aReturn)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
2001-06-29 00:48:35 +00:00
|
|
|
nsCOMPtr<nsIContent> comment;
|
|
|
|
nsresult rv = NS_NewCommentNode(getter_AddRefs(comment));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallQueryInterface(comment, aReturn);
|
2001-06-29 00:48:35 +00:00
|
|
|
(*aReturn)->AppendData(aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
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
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateCDATASection(const nsAString& aData,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMCDATASection** aReturn)
|
1999-01-12 19:41:06 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::CreateCDATASection");
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1999-01-12 19:41:06 +00:00
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateProcessingInstruction(const nsAString& aTarget,
|
|
|
|
const nsAString& aData,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMProcessingInstruction** aReturn)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2001-02-25 00:00:52 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
nsresult rv = NS_NewXMLProcessingInstruction(getter_AddRefs(content),
|
|
|
|
aTarget, aData);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(content, aReturn);
|
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
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateAttribute(const nsAString& aName,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMAttr** aReturn)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::CreateAttribute");
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateEntityReference(const nsAString& aName,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMEntityReference** aReturn)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::CreateEntityReference");
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetElementsByTagName(const nsAString& aTagName,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMNodeList** aReturn)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsRDFDOMNodeList* elements;
|
|
|
|
if (NS_FAILED(rv = nsRDFDOMNodeList::Create(&elements))) {
|
|
|
|
NS_ERROR("unable to create node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
nsIContent* root = nsnull;
|
|
|
|
GetRootContent(&root);
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_ASSERTION(root != nsnull, "no doc root");
|
|
|
|
|
|
|
|
if (root != nsnull) {
|
2000-05-14 18:14:30 +00:00
|
|
|
rv = GetElementsByTagName(root, aTagName, kNameSpaceID_Unknown,
|
|
|
|
elements);
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_RELEASE(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aReturn = elements;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-23 02:40:51 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetElementsByAttribute(const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMNodeList** aReturn)
|
1999-02-23 02:40:51 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsRDFDOMNodeList* elements;
|
|
|
|
if (NS_FAILED(rv = nsRDFDOMNodeList::Create(&elements))) {
|
|
|
|
NS_ERROR("unable to create node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIContent> root;
|
|
|
|
GetRootContent(getter_AddRefs(root));
|
1999-02-23 02:40:51 +00:00
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> domRoot = do_QueryInterface(root);
|
|
|
|
NS_ASSERTION(domRoot, "no doc root");
|
|
|
|
|
|
|
|
if (domRoot) {
|
|
|
|
rv = GetElementsByAttribute(domRoot, aAttribute, aValue, elements);
|
1999-02-23 02:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*aReturn = elements;
|
2002-12-11 14:24:49 +00:00
|
|
|
|
|
|
|
return rv;
|
1999-02-23 02:40:51 +00:00
|
|
|
}
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
|
1999-09-03 07:02:25 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::Persist(const nsAString& aID,
|
|
|
|
const nsAString& aAttr)
|
1999-09-03 07:02:25 +00:00
|
|
|
{
|
2001-11-10 00:03:53 +00:00
|
|
|
// If we're currently reading persisted attributes out of the
|
|
|
|
// localstore, _don't_ re-enter and try to set them again!
|
2001-11-15 02:46:29 +00:00
|
|
|
if (mApplyingPersistedAttrs)
|
2001-11-10 00:03:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
1999-09-03 07:02:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domelement;
|
|
|
|
rv = GetElementById(aID, getter_AddRefs(domelement));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (! domelement)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> element = do_QueryInterface(domelement);
|
|
|
|
NS_ASSERTION(element != nsnull, "null ptr");
|
|
|
|
if (! element)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
2000-08-31 00:36:31 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> ni;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = element->NormalizeAttrString(aAttr, *getter_AddRefs(ni));
|
1999-09-03 07:02:25 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-08-31 00:36:31 +00:00
|
|
|
ni->GetNameAtom(*getter_AddRefs(tag));
|
|
|
|
ni->GetNamespaceID(nameSpaceID);
|
|
|
|
|
1999-09-03 07:02:25 +00:00
|
|
|
rv = Persist(element, nameSpaceID, tag);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2000-08-23 17:27:06 +00:00
|
|
|
nsXULDocument::Persist(nsIContent* aElement, PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute)
|
1999-09-03 07:02:25 +00:00
|
|
|
{
|
2001-11-15 02:46:29 +00:00
|
|
|
// First make sure we _have_ a local store to stuff the persisted
|
1999-09-14 22:36:55 +00:00
|
|
|
// information into. (We might not have one if profile information
|
|
|
|
// hasn't been loaded yet...)
|
|
|
|
if (! mLocalStore)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-09-03 07:02:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
nsCOMPtr<nsIRDFResource> element;
|
2001-02-22 03:01:34 +00:00
|
|
|
rv = nsXULContentUtils::GetElementResource(aElement, getter_AddRefs(element));
|
1999-09-03 07:02:25 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// No ID, so nothing to persist.
|
1999-10-05 21:13:55 +00:00
|
|
|
if (! element)
|
1999-09-03 07:02:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
// Ick. Construct a property from the attribute. Punt on
|
|
|
|
// namespaces for now.
|
|
|
|
const PRUnichar* attrstr;
|
|
|
|
rv = aAttribute->GetUnicode(&attrstr);
|
1999-09-03 07:02:25 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
nsCOMPtr<nsIRDFResource> attr;
|
2001-10-27 06:44:19 +00:00
|
|
|
rv = gRDFService->GetResource(NS_LossyConvertUCS2toASCII(attrstr).get(), getter_AddRefs(attr));
|
1999-10-05 21:13:55 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Turn the value into a literal
|
|
|
|
nsAutoString valuestr;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, aAttribute, valuestr);
|
1999-09-03 07:02:25 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PRBool novalue = (rv != NS_CONTENT_ATTR_HAS_VALUE);
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
// See if there was an old value...
|
|
|
|
nsCOMPtr<nsIRDFNode> oldvalue;
|
|
|
|
rv = mLocalStore->GetTarget(element, attr, PR_TRUE, getter_AddRefs(oldvalue));
|
1999-09-03 07:02:25 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
if (oldvalue && novalue) {
|
|
|
|
// ...there was an oldvalue, and they've removed it. XXXThis
|
|
|
|
// handling isn't quite right...
|
|
|
|
rv = mLocalStore->Unassert(element, attr, oldvalue);
|
1999-09-03 07:02:25 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-10-05 21:13:55 +00:00
|
|
|
// Now either 'change' or 'assert' based on whether there was
|
|
|
|
// an old value.
|
|
|
|
nsCOMPtr<nsIRDFLiteral> newvalue;
|
2001-06-30 11:02:25 +00:00
|
|
|
rv = gRDFService->GetLiteral(valuestr.get(), getter_AddRefs(newvalue));
|
1999-09-03 07:02:25 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
if (oldvalue) {
|
2001-11-10 00:03:53 +00:00
|
|
|
if (oldvalue != newvalue)
|
|
|
|
rv = mLocalStore->Change(element, attr, oldvalue, newvalue);
|
|
|
|
else
|
|
|
|
rv = NS_OK;
|
1999-09-03 07:02:25 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-10-05 21:13:55 +00:00
|
|
|
rv = mLocalStore->Assert(element, attr, newvalue, PR_TRUE);
|
1999-09-03 07:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-05 21:13:55 +00:00
|
|
|
|
|
|
|
// Add it to the persisted set for this document (if it's not
|
|
|
|
// there already).
|
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString docurl;
|
|
|
|
rv = mDocumentURL->GetSpec(docurl);
|
1999-10-05 21:13:55 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> doc;
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = gRDFService->GetResource(docurl.get(), getter_AddRefs(doc));
|
1999-10-05 21:13:55 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PRBool hasAssertion;
|
|
|
|
rv = mLocalStore->HasAssertion(doc, kNC_persist, element, PR_TRUE, &hasAssertion);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (! hasAssertion) {
|
|
|
|
rv = mLocalStore->Assert(doc, kNC_persist, element, PR_TRUE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-03 07:02:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-30 02:32:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::DestroyForwardReferences()
|
1999-09-30 02:32:34 +00:00
|
|
|
{
|
1999-10-05 21:13:55 +00:00
|
|
|
for (PRInt32 i = mForwardReferences.Count() - 1; i >= 0; --i) {
|
|
|
|
nsForwardReference* fwdref = NS_REINTERPRET_CAST(nsForwardReference*, mForwardReferences[i]);
|
|
|
|
delete fwdref;
|
1999-09-30 02:32:34 +00:00
|
|
|
}
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
mForwardReferences.Clear();
|
1999-09-30 02:32:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-05-19 04:28:40 +00:00
|
|
|
// nsIDOMNSDocument interface
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
1999-05-19 04:28:40 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetCharacterSet(nsAString& aCharacterSet)
|
2000-01-15 02:01:05 +00:00
|
|
|
{
|
|
|
|
return GetDocumentCharacterSet(aCharacterSet);
|
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
|
1999-05-19 04:28:40 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::CreateRange(nsIDOMRange** aRange)
|
1999-05-19 04:28:40 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
return CallCreateInstance(kRangeCID, aRange);
|
1999-05-19 04:28:40 +00:00
|
|
|
}
|
|
|
|
|
2001-09-07 09:30:03 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::CreateNodeIterator(nsIDOMNode *aRoot,
|
|
|
|
PRUint32 aWhatToShow,
|
|
|
|
nsIDOMNodeFilter *aFilter,
|
|
|
|
PRBool aEntityReferenceExpansion,
|
|
|
|
nsIDOMNodeIterator **_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::CreateTreeWalker(nsIDOMNode *aRoot,
|
|
|
|
PRUint32 aWhatToShow,
|
|
|
|
nsIDOMNodeFilter *aFilter,
|
|
|
|
PRBool aEntityReferenceExpansion,
|
|
|
|
nsIDOMTreeWalker **_retval)
|
|
|
|
{
|
2002-07-15 19:25:27 +00:00
|
|
|
*_retval = nsnull;
|
|
|
|
|
|
|
|
nsresult rv = nsContentUtils::CheckSameOrigin(this, aRoot);
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-09-07 09:30:03 +00:00
|
|
|
return NS_NewTreeWalker(aRoot,
|
|
|
|
aWhatToShow,
|
|
|
|
aFilter,
|
|
|
|
aEntityReferenceExpansion,
|
|
|
|
_retval);
|
|
|
|
}
|
|
|
|
|
2000-04-26 13:58:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetDefaultView(nsIDOMAbstractView** aDefaultView)
|
|
|
|
{
|
2000-08-17 22:44:01 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDefaultView);
|
|
|
|
*aDefaultView = nsnull;
|
|
|
|
|
2002-05-18 00:02:50 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = NS_STATIC_CAST(nsIPresShell *,
|
|
|
|
mPresShells.SafeElementAt(0));
|
2000-08-17 22:44:01 +00:00
|
|
|
NS_ENSURE_TRUE(shell, NS_OK);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> ctx;
|
|
|
|
nsresult rv = shell->GetPresContext(getter_AddRefs(ctx));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && ctx, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
rv = ctx->GetContainer(getter_AddRefs(container));
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && container, rv);
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window = do_GetInterface(container);
|
2000-08-17 22:44:01 +00:00
|
|
|
NS_ENSURE_TRUE(window, NS_OK);
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
return CallQueryInterface(window, aDefaultView);
|
2000-04-26 13:58:56 +00:00
|
|
|
}
|
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
nsresult
|
|
|
|
nsXULDocument::GetPixelDimensions(nsIPresShell* aShell,
|
2000-08-23 17:27:06 +00:00
|
|
|
PRInt32* aWidth,
|
|
|
|
PRInt32* aHeight)
|
2000-06-08 00:51:13 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsSize size;
|
|
|
|
nsIFrame* frame;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
result = FlushPendingNotifications();
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
result = aShell->GetPrimaryFrameFor(mRootContent, &frame);
|
|
|
|
if (NS_SUCCEEDED(result) && frame) {
|
|
|
|
nsIView* view;
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
aShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
result = frame->GetView(presContext, &view);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
// If we have a view check if it's scrollable. If not,
|
|
|
|
// just use the view size itself
|
|
|
|
if (view) {
|
|
|
|
nsIScrollableView* scrollableView;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
if (NS_SUCCEEDED(CallQueryInterface(view, &scrollableView))) {
|
2000-06-08 00:51:13 +00:00
|
|
|
scrollableView->GetScrolledView(view);
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-12-01 14:31:45 +00:00
|
|
|
nsRect r;
|
|
|
|
result = view->GetBounds(r);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
size.height = r.height;
|
|
|
|
size.width = r.width;
|
|
|
|
}
|
2000-06-08 00:51:13 +00:00
|
|
|
}
|
|
|
|
// If we don't have a view, use the frame size
|
|
|
|
else {
|
|
|
|
result = frame->GetSize(size);
|
|
|
|
}
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
// Convert from twips to pixels
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIPresContext> context;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
result = aShell->GetPresContext(getter_AddRefs(context));
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
float scale;
|
|
|
|
context->GetTwipsToPixels(&scale);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
*aWidth = NSTwipsToIntPixels(size.width, scale);
|
|
|
|
*aHeight = NSTwipsToIntPixels(size.height, scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aWidth = 0;
|
|
|
|
*aHeight = 0;
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
return result;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetWidth(PRInt32* aWidth)
|
1999-10-06 20:33:58 +00:00
|
|
|
{
|
2000-06-08 00:51:13 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// We make the assumption that the first presentation shell
|
|
|
|
// is the one for which we need information.
|
2001-06-20 03:27:48 +00:00
|
|
|
GetShellAt(0, getter_AddRefs(shell));
|
2000-06-08 00:51:13 +00:00
|
|
|
if (shell) {
|
|
|
|
PRInt32 width, height;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-06-08 00:51:13 +00:00
|
|
|
result = GetPixelDimensions(shell, &width, &height);
|
|
|
|
*aWidth = width;
|
|
|
|
} else
|
|
|
|
*aWidth = 0;
|
|
|
|
|
|
|
|
return result;
|
1999-10-06 20:33:58 +00:00
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetHeight(PRInt32* aHeight)
|
1999-10-06 20:33:58 +00:00
|
|
|
{
|
2000-06-08 00:51:13 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// We make the assumption that the first presentation shell
|
|
|
|
// is the one for which we need information.
|
2001-06-20 03:27:48 +00:00
|
|
|
GetShellAt(0, getter_AddRefs(shell));
|
2000-06-08 00:51:13 +00:00
|
|
|
if (shell) {
|
|
|
|
PRInt32 width, height;
|
|
|
|
|
|
|
|
result = GetPixelDimensions(shell, &width, &height);
|
|
|
|
*aHeight = height;
|
|
|
|
} else
|
|
|
|
*aHeight = 0;
|
|
|
|
|
|
|
|
return result;
|
1999-10-06 20:33:58 +00:00
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
|
2000-06-02 08:13:29 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsXULDocument::AddBinding(nsIDOMElement* aContent,
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& aURL)
|
2000-06-02 08:13:29 +00:00
|
|
|
{
|
2002-07-16 13:09:15 +00:00
|
|
|
nsresult rv = nsContentUtils::CheckSameOrigin(this, aContent);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-06-02 08:13:29 +00:00
|
|
|
nsCOMPtr<nsIBindingManager> bm;
|
|
|
|
GetBindingManager(getter_AddRefs(bm));
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aContent));
|
|
|
|
|
|
|
|
return bm->AddLayeredBinding(content, aURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsXULDocument::RemoveBinding(nsIDOMElement* aContent,
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& aURL)
|
2000-06-02 08:13:29 +00:00
|
|
|
{
|
|
|
|
if (mBindingManager) {
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aContent));
|
|
|
|
return mBindingManager->RemoveLayeredBinding(content, aURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-05-26 22:45:26 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::LoadBindingDocument(const nsAString& aURL, nsIDOMDocument** aResult)
|
2000-08-17 08:11:11 +00:00
|
|
|
{
|
2000-09-05 07:29:01 +00:00
|
|
|
if (mBindingManager) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
mBindingManager->LoadBindingDocument(this, aURL, getter_AddRefs(doc));
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc));
|
|
|
|
*aResult = domDoc;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-17 08:11:11 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-09-05 07:29:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetBindingParent(nsIDOMNode* aNode, nsIDOMElement** aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
|
|
|
|
if (!content)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> result;
|
|
|
|
content->GetBindingParent(getter_AddRefs(result));
|
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(result));
|
|
|
|
*aResult = elt;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-01-27 00:43:54 +00:00
|
|
|
static nsresult
|
2001-07-31 19:05:34 +00:00
|
|
|
GetElementByAttribute(nsIContent* aContent,
|
2001-01-27 00:43:54 +00:00
|
|
|
nsIAtom* aAttrName,
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& aAttrValue,
|
2001-01-27 00:43:54 +00:00
|
|
|
PRBool aUniversalMatch,
|
|
|
|
nsIDOMElement** aResult)
|
|
|
|
{
|
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
nsresult rv = aContent->GetAttr(kNameSpaceID_None, aAttrName, value);
|
2001-01-27 00:43:54 +00:00
|
|
|
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
|
|
|
if (aUniversalMatch || value.Equals(aAttrValue))
|
2002-12-11 14:24:49 +00:00
|
|
|
return CallQueryInterface(aContent, aResult);
|
2001-01-27 00:43:54 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-01-27 00:43:54 +00:00
|
|
|
|
|
|
|
PRInt32 childCount;
|
|
|
|
aContent->ChildCount(childCount);
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < childCount; ++i) {
|
|
|
|
nsCOMPtr<nsIContent> current;
|
2001-03-05 23:28:07 +00:00
|
|
|
aContent->ChildAt(i, *getter_AddRefs(current));
|
2001-01-27 00:43:54 +00:00
|
|
|
|
|
|
|
GetElementByAttribute(current, aAttrName, aAttrValue, aUniversalMatch, aResult);
|
|
|
|
|
|
|
|
if (*aResult)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-10 09:18:57 +00:00
|
|
|
NS_IMETHODIMP
|
2001-01-27 00:43:54 +00:00
|
|
|
nsXULDocument::GetAnonymousElementByAttribute(nsIDOMElement* aElement,
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& aAttrName,
|
|
|
|
const nsAString& aAttrValue,
|
2000-12-10 09:18:57 +00:00
|
|
|
nsIDOMElement** aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
2001-01-27 00:43:54 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
|
|
|
GetAnonymousNodes(aElement, getter_AddRefs(nodeList));
|
2001-07-31 19:05:34 +00:00
|
|
|
|
|
|
|
if (!nodeList)
|
2001-01-27 00:43:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> attribute = do_GetAtom(aAttrName);
|
2001-01-27 00:43:54 +00:00
|
|
|
|
|
|
|
PRUint32 length;
|
|
|
|
nodeList->GetLength(&length);
|
|
|
|
|
|
|
|
PRBool universalMatch = aAttrValue.Equals(NS_LITERAL_STRING("*"));
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < length; ++i) {
|
|
|
|
nsCOMPtr<nsIDOMNode> current;
|
|
|
|
nodeList->Item(i, getter_AddRefs(current));
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-01-27 00:43:54 +00:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(current));
|
|
|
|
|
|
|
|
GetElementByAttribute(content, attribute, aAttrValue, universalMatch, aResult);
|
|
|
|
if (*aResult)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-12-10 09:18:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-17 08:11:11 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsXULDocument::GetAnonymousNodes(nsIDOMElement* aElement,
|
|
|
|
nsIDOMNodeList** aResult)
|
2000-05-26 22:45:26 +00:00
|
|
|
{
|
2001-02-02 00:54:47 +00:00
|
|
|
*aResult = nsnull;
|
|
|
|
if (mBindingManager) {
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aElement));
|
|
|
|
return mBindingManager->GetAnonymousNodesFor(content, aResult);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2000-05-26 22:45:26 +00:00
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsXULDocument::GetLocation(nsIDOMLocation** aLocation)
|
2000-08-29 00:14:23 +00:00
|
|
|
{
|
|
|
|
if (mScriptGlobalObject) {
|
2000-09-01 01:54:35 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window(do_QueryInterface(mScriptGlobalObject));
|
2000-08-29 00:14:23 +00:00
|
|
|
if(window) {
|
|
|
|
return window->GetLocation(aLocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetTitle(nsAString& aTitle)
|
2000-08-29 00:14:23 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
aTitle.Assign(mDocumentTitle);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::SetTitle(const nsAString& aTitle)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
{
|
|
|
|
for (PRInt32 i = mPresShells.Count() - 1; i >= 0; --i) {
|
2002-05-18 00:02:50 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell =
|
|
|
|
NS_STATIC_CAST(nsIPresShell*, mPresShells[i]);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> context;
|
|
|
|
nsresult rv = shell->GetPresContext(getter_AddRefs(context));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
rv = context->GetContainer(getter_AddRefs(container));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!container)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> docShellWin = do_QueryInterface(container);
|
|
|
|
if(!docShellWin)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rv = docShellWin->SetTitle(PromiseFlatString(aTitle).get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-08-29 00:14:23 +00:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
mDocumentTitle.Assign(aTitle);
|
|
|
|
|
2001-09-20 07:42:48 +00:00
|
|
|
// Fire a DOM event for the title change.
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
|
2001-09-23 22:20:46 +00:00
|
|
|
if (event) {
|
|
|
|
event->InitEvent(NS_LITERAL_STRING("DOMTitleChanged"), PR_TRUE, PR_TRUE);
|
2001-09-27 21:43:00 +00:00
|
|
|
PRBool noDefault;
|
|
|
|
DispatchEvent(event, &noDefault);
|
2001-09-23 22:20:46 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
return NS_OK;
|
2000-08-29 00:14:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-10 00:50:54 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetDir(nsAString& aDirection)
|
2001-03-10 00:50:54 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
aDirection.Assign(NS_LITERAL_STRING("ltr"));
|
2001-03-10 00:50:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::SetDir(const nsAString& aDirection)
|
2001-03-10 00:50:54 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-02-17 11:09:57 +00:00
|
|
|
// nsIDOMXULDocument interface
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
1999-02-17 11:09:57 +00:00
|
|
|
|
1999-05-15 08:46:14 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetPopupNode(nsIDOMNode** aNode)
|
1999-07-01 00:07:41 +00:00
|
|
|
{
|
2001-04-18 06:06:31 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// get focus controller
|
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
2002-09-06 00:19:58 +00:00
|
|
|
GetFocusController(getter_AddRefs(focusController));
|
2001-04-18 06:06:31 +00:00
|
|
|
NS_ENSURE_TRUE(focusController, NS_ERROR_FAILURE);
|
|
|
|
// get popup node
|
|
|
|
rv = focusController->GetPopupNode(aNode); // addref happens here
|
|
|
|
|
|
|
|
return rv;
|
1999-07-01 00:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::SetPopupNode(nsIDOMNode* aNode)
|
1999-05-15 08:46:14 +00:00
|
|
|
{
|
2001-04-18 06:06:31 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// get focus controller
|
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
2002-09-06 00:19:58 +00:00
|
|
|
GetFocusController(getter_AddRefs(focusController));
|
2001-04-18 06:06:31 +00:00
|
|
|
NS_ENSURE_TRUE(focusController, NS_ERROR_FAILURE);
|
|
|
|
// set popup node
|
|
|
|
rv = focusController->SetPopupNode(aNode);
|
|
|
|
|
|
|
|
return rv;
|
1999-07-01 00:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetTooltipNode(nsIDOMNode** aNode)
|
1999-07-01 00:07:41 +00:00
|
|
|
{
|
1999-11-18 02:25:33 +00:00
|
|
|
*aNode = mTooltipNode;
|
|
|
|
NS_IF_ADDREF(*aNode);
|
|
|
|
return NS_OK;
|
1999-05-15 08:46:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::SetTooltipNode(nsIDOMNode* aNode)
|
1999-05-15 08:46:14 +00:00
|
|
|
{
|
1999-11-18 02:25:33 +00:00
|
|
|
mTooltipNode = dont_QueryInterface(aNode);
|
|
|
|
return NS_OK;
|
1999-05-15 08:46:14 +00:00
|
|
|
}
|
|
|
|
|
1999-07-01 00:07:41 +00:00
|
|
|
|
1999-05-28 20:24:58 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetCommandDispatcher(nsIDOMXULCommandDispatcher** aTracker)
|
1999-05-28 20:24:58 +00:00
|
|
|
{
|
1999-08-25 01:49:24 +00:00
|
|
|
*aTracker = mCommandDispatcher;
|
1999-05-28 20:24:58 +00:00
|
|
|
NS_IF_ADDREF(*aTracker);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-02 17:46:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::ImportNode(nsIDOMNode* aImportedNode,
|
|
|
|
PRBool aDeep,
|
|
|
|
nsIDOMNode** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateElementNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aQualifiedName,
|
2000-04-02 17:46:30 +00:00
|
|
|
nsIDOMElement** aReturn)
|
|
|
|
{
|
2000-05-15 19:02:30 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gXULLog, PR_LOG_DEBUG)) {
|
2000-08-23 17:27:06 +00:00
|
|
|
char* namespaceCStr = ToNewCString(aNamespaceURI);
|
|
|
|
char* tagCStr = ToNewCString(aQualifiedName);
|
2000-05-15 19:02:30 +00:00
|
|
|
|
|
|
|
PR_LOG(gXULLog, PR_LOG_DEBUG,
|
2000-08-31 00:36:31 +00:00
|
|
|
("xul[CreateElementNS] [%s]:%s", namespaceCStr, tagCStr));
|
2000-05-15 19:02:30 +00:00
|
|
|
|
|
|
|
nsCRT::free(tagCStr);
|
|
|
|
nsCRT::free(namespaceCStr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> name, prefix;
|
|
|
|
|
|
|
|
// parse the user-provided string into a tag name and prefix
|
|
|
|
rv = ParseTagString(aQualifiedName, *getter_AddRefs(name),
|
|
|
|
*getter_AddRefs(prefix));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
#ifdef PR_LOGGING
|
2000-08-23 17:27:06 +00:00
|
|
|
char* tagNameStr = ToNewCString(aQualifiedName);
|
2000-05-15 19:02:30 +00:00
|
|
|
PR_LOG(gXULLog, PR_LOG_ERROR,
|
|
|
|
("xul[CreateElement] unable to parse tag '%s'; no such namespace.", tagNameStr));
|
|
|
|
nsCRT::free(tagNameStr);
|
|
|
|
#endif
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get The real namespace ID
|
|
|
|
PRInt32 nameSpaceID;
|
2002-11-29 23:44:07 +00:00
|
|
|
rv = nsContentUtils::GetNSManagerWeakRef()->GetNameSpaceID(aNamespaceURI,
|
|
|
|
nameSpaceID);
|
2000-05-15 19:02:30 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> ni;
|
2001-12-23 23:23:41 +00:00
|
|
|
// XXX This whole method is deprecated!
|
2000-05-15 19:02:30 +00:00
|
|
|
mNodeInfoManager->GetNodeInfo(name, prefix, nameSpaceID,
|
|
|
|
*getter_AddRefs(ni));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> result;
|
|
|
|
rv = CreateElement(ni, getter_AddRefs(result));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// get the DOM interface
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallQueryInterface(result, aReturn);
|
2000-05-15 19:02:30 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "not a DOM element");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-02 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateAttributeNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aQualifiedName,
|
2000-04-02 17:46:30 +00:00
|
|
|
nsIDOMAttr** aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-02-17 11:09:57 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetElementById(const nsAString& aId,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMElement** aReturn)
|
1999-02-17 11:09:57 +00:00
|
|
|
{
|
2000-07-28 21:49:42 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
|
|
|
NS_WARN_IF_FALSE(!aId.IsEmpty(),"getElementById(\"\"), fix caller?");
|
|
|
|
if (aId.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-02-17 11:09:57 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
nsCOMPtr<nsIContent> element;
|
|
|
|
rv = mElementMap.FindFirst(aId, getter_AddRefs(element));
|
1999-08-30 02:45:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-02-17 11:09:57 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
if (element) {
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallQueryInterface(element, aReturn);
|
1999-02-17 11:09:57 +00:00
|
|
|
}
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
return rv;
|
1999-02-17 18:46:23 +00:00
|
|
|
}
|
|
|
|
|
2000-04-02 17:46:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aLocalName,
|
2000-04-02 17:46:30 +00:00
|
|
|
nsIDOMNodeList** aReturn)
|
|
|
|
{
|
2000-05-14 18:14:30 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsRDFDOMNodeList* elements;
|
|
|
|
if (NS_FAILED(rv = nsRDFDOMNodeList::Create(&elements))) {
|
|
|
|
NS_ERROR("unable to create node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-05-14 19:37:40 +00:00
|
|
|
*aReturn = elements;
|
2000-05-14 18:14:30 +00:00
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIContent> root;
|
|
|
|
GetRootContent(getter_AddRefs(root));
|
2000-05-14 19:37:40 +00:00
|
|
|
NS_ASSERTION(root, "no doc root");
|
2000-05-14 18:14:30 +00:00
|
|
|
|
2000-05-14 19:37:40 +00:00
|
|
|
if (root) {
|
|
|
|
PRInt32 nsid = kNameSpaceID_Unknown;
|
2000-08-23 17:27:06 +00:00
|
|
|
if (!aNamespaceURI.Equals(NS_LITERAL_STRING("*"))) {
|
2002-11-29 23:44:07 +00:00
|
|
|
rv = nsContentUtils::GetNSManagerWeakRef()->GetNameSpaceID(aNamespaceURI, nsid);
|
2000-05-14 19:37:40 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (nsid == kNameSpaceID_Unknown) {
|
|
|
|
// Namespace not found, then there can't be any elements to
|
|
|
|
// be found.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2000-05-14 18:14:30 +00:00
|
|
|
|
|
|
|
rv = GetElementsByTagName(root, aLocalName, nsid,
|
|
|
|
elements);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-02 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 19:22:56 +00:00
|
|
|
nsresult
|
2001-02-20 01:05:34 +00:00
|
|
|
nsXULDocument::AddElementToDocumentPre(nsIContent* aElement)
|
1999-09-17 04:29:53 +00:00
|
|
|
{
|
|
|
|
// Do a bunch of work that's necessary when an element gets added
|
|
|
|
// to the XUL Document.
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// 1. Add the element to the resource-to-element map
|
|
|
|
rv = AddElementToMap(aElement);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// 2. If the element is a 'command updater' (i.e., has a
|
|
|
|
// "commandupdater='true'" attribute), then add the element to the
|
|
|
|
// document's command dispatcher
|
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::commandupdater, value);
|
2000-09-07 23:18:38 +00:00
|
|
|
if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && value == NS_LITERAL_STRING("true")) {
|
2001-02-22 03:01:34 +00:00
|
|
|
rv = nsXULContentUtils::SetCommandUpdater(this, aElement);
|
1999-09-17 04:29:53 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-08 19:07:13 +00:00
|
|
|
// 3. Check for a broadcaster hookup attribute, in which case
|
|
|
|
// we'll hook the node up as a listener on a broadcaster.
|
1999-11-17 02:45:46 +00:00
|
|
|
PRBool listener, resolved;
|
|
|
|
rv = CheckBroadcasterHookup(this, aElement, &listener, &resolved);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// If it's not there yet, we may be able to defer hookup until
|
|
|
|
// later.
|
1999-11-17 03:20:03 +00:00
|
|
|
if (listener && !resolved && (mResolutionPhase != nsForwardReference::eDone)) {
|
1999-11-08 19:07:13 +00:00
|
|
|
BroadcasterHookup* hookup = new BroadcasterHookup(this, aElement);
|
|
|
|
if (! hookup)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
rv = AddForwardReference(hookup);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2001-02-20 01:05:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::AddElementToDocumentPost(nsIContent* aElement)
|
|
|
|
{
|
2001-04-07 01:57:21 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// We need to pay special attention to the keyset tag to set up a listener
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
aElement->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag.get() == nsXULAtoms::keyset) {
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-21 20:51:34 +00:00
|
|
|
// Create our XUL key listener and hook it up.
|
2001-07-31 19:05:34 +00:00
|
|
|
nsCOMPtr<nsIXBLService> xblService(do_GetService("@mozilla.org/xbl;1", &rv));
|
2001-04-07 01:57:21 +00:00
|
|
|
if (xblService) {
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(aElement));
|
|
|
|
xblService->AttachGlobalKeyHandler(rec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-20 01:05:34 +00:00
|
|
|
// See if we need to attach a XUL template to this node
|
|
|
|
return CheckTemplateBuilder(aElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::AddSubtreeToDocument(nsIContent* aElement)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Do pre-order addition magic
|
|
|
|
rv = AddElementToDocumentPre(aElement);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Recurse to children
|
|
|
|
PRInt32 count = 0;
|
1999-09-17 04:29:53 +00:00
|
|
|
nsCOMPtr<nsIXULContent> xulcontent = do_QueryInterface(aElement);
|
|
|
|
rv = xulcontent ? xulcontent->PeekChildCount(count) : aElement->ChildCount(count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
rv = aElement->ChildAt(count, *getter_AddRefs(child));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = AddSubtreeToDocument(child);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2001-02-20 01:05:34 +00:00
|
|
|
// Do post-order addition magic
|
|
|
|
return AddElementToDocumentPost(aElement);
|
1999-09-17 04:29:53 +00:00
|
|
|
}
|
|
|
|
|
2001-02-20 01:05:34 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::RemoveSubtreeFromDocument(nsIContent* aElement)
|
1999-09-17 04:29:53 +00:00
|
|
|
{
|
|
|
|
// Do a bunch of cleanup to remove an element from the XUL
|
|
|
|
// document.
|
|
|
|
nsresult rv;
|
|
|
|
|
2000-01-22 22:00:35 +00:00
|
|
|
// 1. Remove any children from the document.
|
1999-09-17 04:29:53 +00:00
|
|
|
PRInt32 count;
|
|
|
|
nsCOMPtr<nsIXULContent> xulcontent = do_QueryInterface(aElement);
|
|
|
|
rv = xulcontent ? xulcontent->PeekChildCount(count) : aElement->ChildCount(count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
rv = aElement->ChildAt(count, *getter_AddRefs(child));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = RemoveSubtreeFromDocument(child);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2000-01-22 22:00:35 +00:00
|
|
|
// 2. Remove the element from the resource-to-element map
|
1999-09-17 04:29:53 +00:00
|
|
|
rv = RemoveElementFromMap(aElement);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-01-22 22:00:35 +00:00
|
|
|
// 3. If the element is a 'command updater', then remove the
|
1999-09-17 04:29:53 +00:00
|
|
|
// element from the document's command dispatcher.
|
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::commandupdater, value);
|
2000-09-07 23:18:38 +00:00
|
|
|
if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && value == NS_LITERAL_STRING("true")) {
|
1999-09-17 04:29:53 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> domelement = do_QueryInterface(aElement);
|
|
|
|
NS_ASSERTION(domelement != nsnull, "not a DOM element");
|
|
|
|
if (! domelement)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
rv = mCommandDispatcher->RemoveCommandUpdater(domelement);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2002-09-13 23:10:58 +00:00
|
|
|
// 4. Remove the element from our broadcaster map, since it is no longer
|
|
|
|
// in the document.
|
|
|
|
// Do a getElementById to retrieve the broadcaster
|
2002-09-12 04:40:22 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> broadcaster;
|
2002-09-12 23:13:14 +00:00
|
|
|
nsAutoString observesVal;
|
|
|
|
|
|
|
|
if (aElement->HasAttr(kNameSpaceID_None, nsXULAtoms::observes)) {
|
|
|
|
aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::observes, observesVal);
|
|
|
|
if (!observesVal.IsEmpty()) {
|
|
|
|
GetElementById(observesVal, getter_AddRefs(broadcaster));
|
|
|
|
if (broadcaster) {
|
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(aElement));
|
2002-09-13 23:10:58 +00:00
|
|
|
RemoveBroadcastListenerFor(broadcaster,
|
2002-09-12 23:13:14 +00:00
|
|
|
elt,
|
|
|
|
NS_LITERAL_STRING("*"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aElement->HasAttr(kNameSpaceID_None, nsXULAtoms::command)) {
|
|
|
|
aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::command, observesVal);
|
|
|
|
if (!observesVal.IsEmpty()) {
|
|
|
|
GetElementById(observesVal, getter_AddRefs(broadcaster));
|
|
|
|
if (broadcaster) {
|
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(aElement));
|
2002-09-13 23:10:58 +00:00
|
|
|
RemoveBroadcastListenerFor(broadcaster,
|
2002-09-12 23:13:14 +00:00
|
|
|
elt,
|
|
|
|
NS_LITERAL_STRING("*"));
|
|
|
|
}
|
|
|
|
}
|
2002-09-12 04:40:22 +00:00
|
|
|
}
|
1999-09-17 04:29:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-23 10:56:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetTemplateBuilderFor(nsIContent* aContent, nsIXULTemplateBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
if (! mTemplateBuilderTable) {
|
|
|
|
mTemplateBuilderTable = new nsSupportsHashtable();
|
|
|
|
if (! mTemplateBuilderTable)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupportsKey key(aContent);
|
|
|
|
|
|
|
|
if (aContent) {
|
|
|
|
mTemplateBuilderTable->Put(&key, aBuilder);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mTemplateBuilderTable->Remove(&key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetTemplateBuilderFor(nsIContent* aContent, nsIXULTemplateBuilder** aResult)
|
|
|
|
{
|
|
|
|
if (mTemplateBuilderTable) {
|
|
|
|
nsISupportsKey key(aContent);
|
|
|
|
*aResult = NS_STATIC_CAST(nsIXULTemplateBuilder*, mTemplateBuilderTable->Get(&key));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-17 04:29:53 +00:00
|
|
|
// Attributes that are used with getElementById() and the
|
|
|
|
// resource-to-element map.
|
2001-03-23 10:56:18 +00:00
|
|
|
nsIAtom** nsXULDocument::kIdentityAttrs[] = { &nsXULAtoms::id, &nsXULAtoms::ref, nsnull };
|
1999-08-30 02:45:54 +00:00
|
|
|
|
|
|
|
nsresult
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::AddElementToMap(nsIContent* aElement)
|
1999-08-30 02:45:54 +00:00
|
|
|
{
|
1999-09-17 04:29:53 +00:00
|
|
|
// Look at the element's 'id' and 'ref' attributes, and if set,
|
|
|
|
// add pointers in the resource-to-element map to the element.
|
1999-08-30 02:45:54 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
for (PRInt32 i = 0; kIdentityAttrs[i] != nsnull; ++i) {
|
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, *kIdentityAttrs[i], value);
|
1999-10-05 21:13:55 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get attribute");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-30 02:45:54 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
|
|
|
rv = mElementMap.Add(value, aElement);
|
1999-08-30 02:45:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::RemoveElementFromMap(nsIContent* aElement)
|
1999-08-30 02:45:54 +00:00
|
|
|
{
|
1999-09-17 04:29:53 +00:00
|
|
|
// Remove the element from the resource-to-element map.
|
1999-08-30 02:45:54 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
for (PRInt32 i = 0; kIdentityAttrs[i] != nsnull; ++i) {
|
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, *kIdentityAttrs[i], value);
|
1999-10-05 21:13:55 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get attribute");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-30 02:45:54 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
|
|
|
rv = mElementMap.Remove(value, aElement);
|
1999-08-30 02:45:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRIntn
|
2000-04-27 05:53:36 +00:00
|
|
|
nsXULDocument::RemoveElementsFromMapByContent(const PRUnichar* aID,
|
|
|
|
nsIContent* aElement,
|
|
|
|
void* aClosure)
|
1999-08-30 02:45:54 +00:00
|
|
|
{
|
|
|
|
nsIContent* content = NS_REINTERPRET_CAST(nsIContent*, aClosure);
|
|
|
|
return (aElement == content) ? HT_ENUMERATE_REMOVE : HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-02-16 19:30:04 +00:00
|
|
|
// nsIDOMNode interface
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetNodeName(nsAString& aNodeName)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
aNodeName.Assign(NS_LITERAL_STRING("#document"));
|
1999-04-16 08:38:17 +00:00
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetNodeValue(nsAString& aNodeValue)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
SetDOMStringToNull(aNodeValue);
|
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::SetNodeValue(const nsAString& aNodeValue)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2000-08-23 17:27:06 +00:00
|
|
|
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetNodeType(PRUint16* aNodeType)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
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
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetParentNode(nsIDOMNode** aParentNode)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
1999-02-17 11:09:57 +00:00
|
|
|
*aParentNode = nsnull;
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
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)) {
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(mRootContent);
|
|
|
|
NS_ASSERTION(domNode, "root content is not a DOM node");
|
1999-04-16 08:38:17 +00:00
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
if (domNode) {
|
1999-04-16 08:38:17 +00:00
|
|
|
rv = children->AppendNode(domNode);
|
|
|
|
|
|
|
|
*aChildNodes = children;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here, something bad happened.
|
|
|
|
NS_RELEASE(children);
|
|
|
|
return rv;
|
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
|
|
|
*aChildNodes = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::HasChildNodes(PRBool* aHasChildNodes)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 05:19:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::HasAttributes(PRBool* aHasAttributes)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHasAttributes);
|
|
|
|
|
|
|
|
*aHasAttributes = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetFirstChild(nsIDOMNode** aFirstChild)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aFirstChild);
|
1999-04-16 08:38:17 +00:00
|
|
|
|
|
|
|
if (mRootContent) {
|
2002-12-11 14:24:49 +00:00
|
|
|
return CallQueryInterface(mRootContent, aFirstChild);
|
1999-04-16 08:38:17 +00:00
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
|
|
|
*aFirstChild = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetLastChild(nsIDOMNode** aLastChild)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aLastChild);
|
1999-04-16 08:38:17 +00:00
|
|
|
|
|
|
|
if (mRootContent) {
|
2002-12-11 14:24:49 +00:00
|
|
|
return CallQueryInterface(mRootContent, aLastChild);
|
1999-04-16 08:38:17 +00:00
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
|
|
|
*aLastChild = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
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
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetNextSibling(nsIDOMNode** aNextSibling)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
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
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
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
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-01 13:31:23 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetNamespaceURI(nsAString& aNamespaceURI)
|
2001-07-31 19:05:34 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
SetDOMStringToNull(aNamespaceURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-01 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetPrefix(nsAString& aPrefix)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
SetDOMStringToNull(aPrefix);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-01 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::SetPrefix(const nsAString& aPrefix)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
|
2000-04-01 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetLocalName(nsAString& aLocalName)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
SetDOMStringToNull(aLocalName);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-01 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsXULDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
|
|
|
|
nsIDOMNode** aReturn)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::InsertBefore");
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsXULDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
|
|
|
|
nsIDOMNode** aReturn)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::ReplaceChild");
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::RemoveChild");
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsXULDocument::AppendChild");
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-01 13:31:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::Normalize()
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::IsSupported(const nsAString& aFeature,
|
|
|
|
const nsAString& aVersion,
|
2000-09-14 05:19:00 +00:00
|
|
|
PRBool* aReturn)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2002-05-14 01:28:17 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIDOM3Node interface
|
|
|
|
//
|
|
|
|
|
2001-03-30 02:15:21 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::GetBaseURI(nsAString &aURI)
|
2001-03-30 02:15:21 +00:00
|
|
|
{
|
|
|
|
aURI.Truncate();
|
2001-04-30 23:35:09 +00:00
|
|
|
if (mDocumentBaseURL) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString spec;
|
|
|
|
mDocumentBaseURL->GetSpec(spec);
|
|
|
|
aURI = NS_ConvertUTF8toUCS2(spec);
|
2001-03-30 02:15:21 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
|
2002-05-14 01:28:17 +00:00
|
|
|
NS_IMETHODIMP
|
2002-12-04 05:18:39 +00:00
|
|
|
nsXULDocument::CompareDocumentPosition(nsIDOMNode* aOther,
|
|
|
|
PRUint16* aReturn)
|
2002-05-14 01:28:17 +00:00
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::IsSameNode(nsIDOMNode* aOther,
|
|
|
|
PRBool* aReturn)
|
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2001-09-11 03:04:49 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::LookupNamespacePrefix(const nsAString& aNamespaceURI,
|
|
|
|
nsAString& aPrefix)
|
2001-09-11 03:04:49 +00:00
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::LookupNamespaceURI(const nsAString& aNamespacePrefix,
|
|
|
|
nsAString& aNamespaceURI)
|
2001-09-11 03:04:49 +00:00
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("write me");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-02-16 19:30:04 +00:00
|
|
|
// nsIHTMLContentContainer interface
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
1999-02-16 19:30:04 +00:00
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
*aResult = mAttrStyleSheet;
|
2002-12-11 14:24:49 +00:00
|
|
|
if (!mAttrStyleSheet) {
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE; // probably not the right error...
|
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult)
|
1999-02-16 19:30:04 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-02-16 19:30:04 +00:00
|
|
|
// Implementation methods
|
1999-10-29 01:21:15 +00:00
|
|
|
//
|
1999-02-16 19:30:04 +00:00
|
|
|
|
1999-02-01 22:34:51 +00:00
|
|
|
nsresult
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::Init()
|
1999-02-01 22:34:51 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
rv = NS_NewHeapArena(getter_AddRefs(mArena), nsnull);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-02-01 22:34:51 +00:00
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
mNodeInfoManager = do_CreateInstance(NS_NODEINFOMANAGER_CONTRACTID, &rv);
|
2000-05-10 13:13:39 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-11-29 23:44:07 +00:00
|
|
|
mNodeInfoManager->Init(this);
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
// Create our command dispatcher and hook it up.
|
2000-11-04 08:21:20 +00:00
|
|
|
rv = nsXULCommandDispatcher::Create(this, getter_AddRefs(mCommandDispatcher));
|
2000-09-22 05:02:20 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a focus tracker");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
// this _could_ fail; e.g., if we've tried to grab the local store
|
|
|
|
// before profiles have initialized. If so, no big deal; nothing
|
|
|
|
// will persist.
|
2002-12-11 14:24:49 +00:00
|
|
|
mLocalStore = do_GetService(kLocalStoreCID);
|
1999-10-05 22:22:40 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
// Create a new nsISupportsArray for dealing with overlay references
|
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(mUnloadedOverlays));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Create a new nsISupportsArray that will hold owning references
|
|
|
|
// to each of the prototype documents used to construct this
|
|
|
|
// document. That will ensure that prototype elements will remain
|
|
|
|
// alive.
|
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(mPrototypes));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
if (gRefCnt++ == 0) {
|
|
|
|
// Keep the RDF service cached in a member variable to make using
|
|
|
|
// it a bit less painful
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallGetService(kRDFServiceCID, &gRDFService);
|
1999-10-05 21:13:55 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF Service");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
gRDFService->GetResource(NC_NAMESPACE_URI "persist", &kNC_persist);
|
|
|
|
gRDFService->GetResource(NC_NAMESPACE_URI "attribute", &kNC_attribute);
|
|
|
|
gRDFService->GetResource(NC_NAMESPACE_URI "value", &kNC_value);
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallCreateInstance(kHTMLElementFactoryCID, &gHTMLElementFactory);
|
1999-10-05 21:13:55 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get HTML element factory");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallCreateInstance(kXMLElementFactoryCID, &gXMLElementFactory);
|
1999-10-29 01:21:15 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get XML element factory");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallGetService(kXULPrototypeCacheCID, &gXULCache);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-05 21:13:55 +00:00
|
|
|
}
|
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (! gXULLog)
|
|
|
|
gXULLog = PR_NewLogModule("nsXULDocument");
|
|
|
|
#endif
|
|
|
|
|
1999-02-01 22:34:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
nsresult
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::StartLayout(void)
|
1999-01-14 10:55:08 +00:00
|
|
|
{
|
1999-10-29 01:21:15 +00:00
|
|
|
if (! mRootContent) {
|
|
|
|
#ifdef PR_LOGGING
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString urlspec;
|
|
|
|
mDocumentURL->GetSpec(urlspec);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
PR_LOG(gXULLog, PR_LOG_ALWAYS,
|
2002-03-06 07:48:55 +00:00
|
|
|
("xul: unable to layout '%s'; no root content", urlspec.get()));
|
1999-10-29 01:21:15 +00:00
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-01-14 10:55:08 +00:00
|
|
|
PRInt32 count = GetNumberOfShells();
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
GetShellAt(i, getter_AddRefs(shell));
|
1999-07-04 04:09:54 +00:00
|
|
|
if (nsnull == shell)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Resize-reflow this time
|
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
|
|
|
shell->GetPresContext(getter_AddRefs(cx));
|
1999-12-06 23:03:53 +00:00
|
|
|
NS_ASSERTION(cx != nsnull, "no pres context");
|
|
|
|
if (! cx)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
cx->GetContainer(getter_AddRefs(container));
|
|
|
|
NS_ASSERTION(container != nsnull, "pres context has no container");
|
|
|
|
if (! container)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-07-04 04:09:54 +00:00
|
|
|
|
2000-03-11 00:22:48 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
|
|
|
|
NS_ASSERTION(docShell != nsnull, "container is not a docshell");
|
|
|
|
if (! docShell)
|
1999-12-06 23:03:53 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-07-07 22:34:10 +00:00
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
nsRect r;
|
1999-07-04 04:09:54 +00:00
|
|
|
cx->GetVisibleArea(r);
|
2000-01-15 02:01:05 +00:00
|
|
|
|
2000-01-15 05:53:41 +00:00
|
|
|
// Trigger a refresh before the call to InitialReflow(), because
|
1999-07-21 04:47:15 +00:00
|
|
|
// the view manager's UpdateView() function is dropping dirty rects if
|
|
|
|
// refresh is disabled rather than accumulating them until refresh is
|
|
|
|
// enabled and then triggering a repaint...
|
1999-07-04 04:09:54 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
|
|
|
if (vm) {
|
1999-07-07 22:34:10 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2000-03-11 00:22:48 +00:00
|
|
|
nsresult rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
1999-07-07 22:34:10 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && (contentViewer != nsnull)) {
|
|
|
|
PRBool enabled;
|
|
|
|
contentViewer->GetEnableRendering(&enabled);
|
|
|
|
if (enabled) {
|
2000-02-09 15:48:01 +00:00
|
|
|
vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
|
1999-07-07 22:34:10 +00:00
|
|
|
}
|
|
|
|
}
|
1999-07-04 04:09:54 +00:00
|
|
|
}
|
2000-01-15 05:53:41 +00:00
|
|
|
|
|
|
|
shell->InitialReflow(r.width, r.height);
|
2000-08-22 22:53:46 +00:00
|
|
|
FlushPendingNotifications(); // This is done because iframes don't load their subdocs until
|
2001-07-31 19:05:34 +00:00
|
|
|
// they get reflowed. If we reflow asynchronously, our onload
|
2000-08-22 22:53:46 +00:00
|
|
|
// will fire too early. -- hyatt
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-07-04 04:09:54 +00:00
|
|
|
// Start observing the document _after_ we do the initial
|
|
|
|
// reflow. Otherwise, we'll get into an trouble trying to
|
|
|
|
// create kids before the root frame is established.
|
|
|
|
shell->BeginObservingDocument();
|
1999-01-14 10:55:08 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
nsresult
|
2000-05-14 18:14:30 +00:00
|
|
|
nsXULDocument::GetElementsByTagName(nsIContent *aContent,
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& aName,
|
2000-05-14 18:14:30 +00:00
|
|
|
PRInt32 aNamespaceID,
|
|
|
|
nsRDFDOMNodeList* aElements)
|
1999-01-12 19:41:06 +00:00
|
|
|
{
|
2000-05-14 18:14:30 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aContent);
|
|
|
|
NS_ENSURE_ARG_POINTER(aElements);
|
1998-12-24 05:07:14 +00:00
|
|
|
|
2000-05-14 18:14:30 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aContent));
|
1999-02-25 02:58:11 +00:00
|
|
|
if (!element)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-05-14 18:14:30 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> ni;
|
|
|
|
aContent->GetNodeInfo(*getter_AddRefs(ni));
|
|
|
|
NS_ENSURE_TRUE(ni, NS_OK);
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
if (aName.Equals(NS_LITERAL_STRING("*"))) {
|
2000-05-14 18:14:30 +00:00
|
|
|
if (aNamespaceID == kNameSpaceID_Unknown ||
|
|
|
|
ni->NamespaceEquals(aNamespaceID)) {
|
|
|
|
if (NS_FAILED(rv = aElements->AppendNode(element))) {
|
|
|
|
NS_ERROR("unable to append element to node list");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-02-16 19:30:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2000-05-14 18:14:30 +00:00
|
|
|
if (ni->Equals(aName) &&
|
|
|
|
(aNamespaceID == kNameSpaceID_Unknown ||
|
|
|
|
ni->NamespaceEquals(aNamespaceID))) {
|
|
|
|
if (NS_FAILED(rv = aElements->AppendNode(element))) {
|
1999-02-16 19:30:04 +00:00
|
|
|
NS_ERROR("unable to append element to node list");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-01 22:34:51 +00:00
|
|
|
|
2000-05-14 18:14:30 +00:00
|
|
|
PRInt32 length;
|
|
|
|
if (NS_FAILED(rv = aContent->ChildCount(length))) {
|
|
|
|
NS_ERROR("unable to get childcount");
|
1999-02-01 22:34:51 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-05-14 18:14:30 +00:00
|
|
|
for (PRInt32 i = 0; i < length; ++i) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
if (NS_FAILED(rv = aContent->ChildAt(i, *getter_AddRefs(child) ))) {
|
|
|
|
NS_ERROR("unable to get child from content");
|
1999-02-16 19:30:04 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-05-14 18:14:30 +00:00
|
|
|
if (NS_FAILED(rv = GetElementsByTagName(child, aName, aNamespaceID,
|
|
|
|
aElements))) {
|
1999-02-16 19:30:04 +00:00
|
|
|
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
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetElementsByAttribute(nsIDOMNode* aNode,
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
1999-03-09 08:10:50 +00:00
|
|
|
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
|
|
|
|
2002-01-24 02:03:19 +00:00
|
|
|
if ((attrValue.Equals(aValue)) || (!attrValue.IsEmpty() && aValue.Equals(NS_LITERAL_STRING("*")))) {
|
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-11-18 02:25:33 +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
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::ParseTagString(const nsAString& aTagName, nsIAtom*& aName,
|
2000-05-15 19:02:30 +00:00
|
|
|
nsIAtom*& aPrefix)
|
1999-04-16 08:38:17 +00:00
|
|
|
{
|
2000-05-15 19:02:30 +00:00
|
|
|
// Parse the tag into a name and prefix
|
1999-04-16 08:38:17 +00:00
|
|
|
|
2000-05-15 19:02:30 +00:00
|
|
|
static char kNameSpaceSeparator = ':';
|
1999-04-16 08:38:17 +00:00
|
|
|
|
|
|
|
nsAutoString prefix;
|
|
|
|
nsAutoString name(aTagName);
|
1999-07-18 00:01:21 +00:00
|
|
|
PRInt32 nsoffset = name.FindChar(kNameSpaceSeparator);
|
1999-04-16 08:38:17 +00:00
|
|
|
if (-1 != nsoffset) {
|
|
|
|
name.Left(prefix, nsoffset);
|
|
|
|
name.Cut(0, nsoffset+1);
|
|
|
|
}
|
|
|
|
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!prefix.IsEmpty())
|
2000-05-15 19:02:30 +00:00
|
|
|
aPrefix = NS_NewAtom(prefix);
|
1999-04-16 08:38:17 +00:00
|
|
|
|
|
|
|
aName = NS_NewAtom(name);
|
2000-05-15 19:02:30 +00:00
|
|
|
|
1999-04-16 08:38:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-09 00:25:25 +00:00
|
|
|
// nsIDOMEventReceiver Interface Implementations
|
1999-05-04 23:32:25 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
|
1999-05-04 23:32:25 +00:00
|
|
|
{
|
|
|
|
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
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
|
1999-05-04 23:32:25 +00:00
|
|
|
{
|
1999-05-28 11:30:59 +00:00
|
|
|
if (mListenerManager) {
|
1999-05-04 23:32:25 +00:00
|
|
|
mListenerManager->RemoveEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::AddEventListener(const nsAString& aType,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
PRBool aUseCapture)
|
1999-05-04 23:32:25 +00:00
|
|
|
{
|
2002-11-09 00:25:25 +00:00
|
|
|
return AddGroupedEventListener(aType, aListener, aUseCapture, nsnull);
|
1999-05-04 23:32:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::RemoveEventListener(const nsAString& aType,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
PRBool aUseCapture)
|
1999-05-04 23:32:25 +00:00
|
|
|
{
|
2002-11-09 00:25:25 +00:00
|
|
|
return RemoveGroupedEventListener(aType, aListener, aUseCapture, nsnull);
|
1999-05-04 23:32:25 +00:00
|
|
|
}
|
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
NS_IMETHODIMP
|
2001-09-27 21:43:00 +00:00
|
|
|
nsXULDocument::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval)
|
2000-05-16 11:35:12 +00:00
|
|
|
{
|
|
|
|
// Obtain a presentation context
|
|
|
|
PRInt32 count = GetNumberOfShells();
|
|
|
|
if (count == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
GetShellAt(0, getter_AddRefs(shell));
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-12-21 01:10:07 +00:00
|
|
|
if (shell) {
|
|
|
|
// Retrieve the context
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
shell->GetPresContext(getter_AddRefs(presContext));
|
2000-05-16 11:35:12 +00:00
|
|
|
|
2001-12-21 01:10:07 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
|
|
|
if (presContext &&
|
|
|
|
NS_SUCCEEDED(presContext->GetEventStateManager(getter_AddRefs(esm)))) {
|
|
|
|
return esm->DispatchNewEvent(NS_STATIC_CAST(nsIDocument*, this), aEvent, _retval);
|
|
|
|
}
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-11-09 00:25:25 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::AddGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
|
|
|
|
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEventListenerManager> manager;
|
|
|
|
|
|
|
|
nsresult rv = GetListenerManager(getter_AddRefs(manager));
|
|
|
|
if (NS_SUCCEEDED(rv) && manager) {
|
|
|
|
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
|
|
|
|
|
|
|
|
manager->AddEventListenerByType(aListener, aType, flags, aEvtGrp);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::RemoveGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
|
|
|
|
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
|
|
|
|
{
|
|
|
|
if (mListenerManager) {
|
|
|
|
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
|
|
|
|
|
|
|
|
mListenerManager->RemoveEventListenerByType(aListener, aType, flags, aEvtGrp);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::CanTrigger(const nsAString & type, PRBool *_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::IsRegisteredHere(const nsAString & type, PRBool *_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXULDocument::CreateEvent(const nsAString& aEventType,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsIDOMEvent** aReturn)
|
2000-05-16 11:35:12 +00:00
|
|
|
{
|
|
|
|
// Obtain a presentation context
|
|
|
|
PRInt32 count = GetNumberOfShells();
|
|
|
|
if (count == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
GetShellAt(0, getter_AddRefs(shell));
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-12-21 01:10:07 +00:00
|
|
|
if (shell) {
|
|
|
|
// Retrieve the context
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
shell->GetPresContext(getter_AddRefs(presContext));
|
2000-05-16 11:35:12 +00:00
|
|
|
|
2001-12-21 01:10:07 +00:00
|
|
|
if (presContext) {
|
|
|
|
nsCOMPtr<nsIEventListenerManager> lm;
|
|
|
|
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(lm)))) {
|
|
|
|
return lm->CreateEvent(presContext, nsnull, aEventType, aReturn);
|
|
|
|
}
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-11-09 00:25:25 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::CreateEventGroup(nsIDOMEventGroup **_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-05-04 23:32:25 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::GetListenerManager(nsIEventListenerManager** aResult)
|
1999-05-04 23:32:25 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
if (!mListenerManager) {
|
1999-05-28 11:30:59 +00:00
|
|
|
nsresult rv;
|
2002-12-11 14:24:49 +00:00
|
|
|
mListenerManager = do_CreateInstance(kEventListenerManagerCID, &rv);
|
1999-05-28 11:30:59 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-04-03 20:42:41 +00:00
|
|
|
|
|
|
|
mListenerManager->SetListenerTarget(NS_STATIC_CAST(nsIDocument*,this));
|
1999-05-04 23:32:25 +00:00
|
|
|
}
|
1999-05-28 11:30:59 +00:00
|
|
|
*aResult = mListenerManager;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
1999-05-04 23:32:25 +00:00
|
|
|
}
|
|
|
|
|
2000-02-16 06:59:07 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::HandleEvent(nsIDOMEvent *aEvent)
|
|
|
|
{
|
2001-09-27 21:43:00 +00:00
|
|
|
PRBool noDefault;
|
|
|
|
return DispatchEvent(aEvent, &noDefault);
|
2000-02-16 06:59:07 +00:00
|
|
|
}
|
|
|
|
|
2002-11-09 00:25:25 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
|
2002-04-20 01:48:32 +00:00
|
|
|
{
|
2002-11-09 00:25:25 +00:00
|
|
|
nsCOMPtr<nsIEventListenerManager> manager;
|
|
|
|
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager))) && manager) {
|
|
|
|
return manager->GetSystemEventGroupLM(aGroup);
|
1999-05-04 23:32:25 +00:00
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-05-19 04:28:40 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
nsresult
|
2000-05-15 19:02:30 +00:00
|
|
|
nsXULDocument::CreateElement(nsINodeInfo *aNodeInfo, nsIContent** aResult)
|
1999-10-05 21:13:55 +00:00
|
|
|
{
|
2000-05-15 19:02:30 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aNodeInfo);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIContent> result;
|
|
|
|
|
2000-05-15 19:02:30 +00:00
|
|
|
if (aNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
|
|
|
|
rv = nsXULElement::Create(aNodeInfo, getter_AddRefs(result));
|
2000-01-19 03:11:39 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-10-05 21:13:55 +00:00
|
|
|
else {
|
2000-05-15 19:02:30 +00:00
|
|
|
PRInt32 namespaceID;
|
|
|
|
aNodeInfo->GetNamespaceID(namespaceID);
|
|
|
|
|
2000-01-19 03:11:39 +00:00
|
|
|
nsCOMPtr<nsIElementFactory> elementFactory;
|
2000-05-15 19:02:30 +00:00
|
|
|
GetElementFactory(namespaceID, getter_AddRefs(elementFactory));
|
2000-01-19 03:11:39 +00:00
|
|
|
|
2000-05-15 19:02:30 +00:00
|
|
|
rv = elementFactory->CreateInstanceByTag(aNodeInfo,
|
2000-05-10 13:13:39 +00:00
|
|
|
getter_AddRefs(result));
|
1999-10-05 21:13:55 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-19 03:11:39 +00:00
|
|
|
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-10-05 21:13:55 +00:00
|
|
|
}
|
|
|
|
|
1999-12-06 23:05:31 +00:00
|
|
|
result->SetContentID(mNextContentID++);
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
*aResult = result;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-11-15 22:14:37 +00:00
|
|
|
nsXULDocument::PrepareToLoad(nsISupports* aContainer,
|
1999-10-29 01:21:15 +00:00
|
|
|
const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsIParser** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Get the document's principal
|
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
rv = aChannel->GetOwner(getter_AddRefs(owner));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(owner);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
return PrepareToLoadPrototype(mDocumentURL, aCommand, principal, aResult);
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-11-18 02:25:33 +00:00
|
|
|
nsXULDocument::PrepareToLoadPrototype(nsIURI* aURI, const char* aCommand,
|
|
|
|
nsIPrincipal* aDocumentPrincipal,
|
|
|
|
nsIParser** aResult)
|
1999-10-29 01:21:15 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// Create a new prototype document.
|
|
|
|
rv = NS_NewXULPrototypeDocument(nsnull,
|
|
|
|
NS_GET_IID(nsIXULPrototypeDocument),
|
|
|
|
getter_AddRefs(mCurrentPrototype));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// Bootstrap the master document prototype.
|
1999-11-24 22:46:09 +00:00
|
|
|
if (! mMasterPrototype) {
|
1999-11-18 02:25:33 +00:00
|
|
|
mMasterPrototype = mCurrentPrototype;
|
|
|
|
mMasterPrototype->SetDocumentPrincipal(aDocumentPrincipal);
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
rv = mCurrentPrototype->SetURI(aURI);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Create a XUL content sink, a parser, and kick off a load for
|
|
|
|
// the overlay.
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIXULContentSink> sink = do_CreateInstance(kXULContentSinkCID,
|
|
|
|
&rv);
|
1999-10-29 01:21:15 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create XUL content sink");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = sink->Init(this, mCurrentPrototype);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to initialize datasource sink");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIParser> parser = do_CreateInstance(kParserCID, &rv);
|
1999-10-29 01:21:15 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create parser");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-04-11 23:48:37 +00:00
|
|
|
parser->SetCommand(nsCRT::strcmp(aCommand, "view-source") ? eViewNormal :
|
|
|
|
eViewSource);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2002-02-12 21:17:53 +00:00
|
|
|
parser->SetDocumentCharset(NS_LITERAL_STRING("UTF-8"),
|
|
|
|
kCharsetFromDocTypeDefault);
|
1999-10-29 01:21:15 +00:00
|
|
|
parser->SetContentSink(sink); // grabs a reference to the parser
|
|
|
|
|
|
|
|
*aResult = parser;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::ApplyPersistentAttributes()
|
1999-10-05 21:13:55 +00:00
|
|
|
{
|
|
|
|
// Add all of the 'persisted' attributes into the content
|
|
|
|
// model.
|
|
|
|
if (! mLocalStore)
|
|
|
|
return NS_OK;
|
|
|
|
|
2001-11-15 02:46:29 +00:00
|
|
|
mApplyingPersistedAttrs = PR_TRUE;
|
2001-11-10 00:03:53 +00:00
|
|
|
|
2002-02-12 21:17:53 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISupportsArray> elements;
|
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(elements));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-05 21:13:55 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString docurl;
|
|
|
|
mDocumentURL->GetSpec(docurl);
|
1999-10-05 21:13:55 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> doc;
|
2002-03-06 07:48:55 +00:00
|
|
|
gRDFService->GetResource(docurl.get(), getter_AddRefs(doc));
|
1999-10-05 21:13:55 +00:00
|
|
|
|
2001-11-10 00:03:53 +00:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> persisted;
|
|
|
|
mLocalStore->GetTargets(doc, kNC_persist, PR_TRUE, getter_AddRefs(persisted));
|
1999-10-05 21:13:55 +00:00
|
|
|
|
|
|
|
while (1) {
|
2001-11-10 00:03:53 +00:00
|
|
|
PRBool hasmore = PR_FALSE;
|
|
|
|
persisted->HasMoreElements(&hasmore);
|
1999-10-05 21:13:55 +00:00
|
|
|
if (! hasmore)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> isupports;
|
2001-11-10 00:03:53 +00:00
|
|
|
persisted->GetNext(getter_AddRefs(isupports));
|
1999-10-05 21:13:55 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(isupports);
|
|
|
|
if (! resource) {
|
|
|
|
NS_WARNING("expected element to be a resource");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-11-10 00:03:53 +00:00
|
|
|
const char *uri;
|
|
|
|
resource->GetValueConst(&uri);
|
|
|
|
if (! uri)
|
|
|
|
continue;
|
1999-10-05 21:13:55 +00:00
|
|
|
|
|
|
|
nsAutoString id;
|
2001-11-10 00:03:53 +00:00
|
|
|
nsXULContentUtils::MakeElementID(this, NS_ConvertASCIItoUCS2(uri), id);
|
1999-10-05 21:13:55 +00:00
|
|
|
|
2001-11-10 00:03:53 +00:00
|
|
|
// This will clear the array if there are no elements.
|
2002-02-12 21:17:53 +00:00
|
|
|
GetElementsForID(id, elements);
|
1999-10-05 21:13:55 +00:00
|
|
|
|
2001-11-10 00:03:53 +00:00
|
|
|
PRUint32 cnt = 0;
|
2002-02-12 21:17:53 +00:00
|
|
|
elements->Count(&cnt);
|
1999-10-05 21:13:55 +00:00
|
|
|
if (! cnt)
|
|
|
|
continue;
|
|
|
|
|
2002-02-12 21:17:53 +00:00
|
|
|
ApplyPersistentAttributesToElements(resource, elements);
|
1999-10-05 21:13:55 +00:00
|
|
|
}
|
|
|
|
|
2001-11-15 02:46:29 +00:00
|
|
|
mApplyingPersistedAttrs = PR_FALSE;
|
2001-11-10 00:03:53 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::ApplyPersistentAttributesToElements(nsIRDFResource* aResource, nsISupportsArray* aElements)
|
1999-10-05 21:13:55 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> attrs;
|
|
|
|
rv = mLocalStore->ArcLabelsOut(aResource, getter_AddRefs(attrs));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
PRBool hasmore;
|
|
|
|
rv = attrs->HasMoreElements(&hasmore);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (! hasmore)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> isupports;
|
|
|
|
rv = attrs->GetNext(getter_AddRefs(isupports));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
|
|
|
if (! property) {
|
|
|
|
NS_WARNING("expected a resource");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* attrname;
|
|
|
|
rv = property->GetValueConst(&attrname);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> attr = do_GetAtom(attrname);
|
1999-10-05 21:13:55 +00:00
|
|
|
if (! attr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// XXX could hang namespace off here, as well...
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFNode> node;
|
|
|
|
rv = mLocalStore->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(node));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFLiteral> literal = do_QueryInterface(node);
|
|
|
|
if (! literal) {
|
|
|
|
NS_WARNING("expected a literal");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PRUnichar* value;
|
|
|
|
rv = literal->GetValueConst(&value);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-10-06 06:42:27 +00:00
|
|
|
PRInt32 len = nsCRT::strlen(value);
|
|
|
|
CBufDescriptor wrapper(value, PR_TRUE, len + 1, len);
|
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
rv = aElements->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-10-05 21:13:55 +00:00
|
|
|
for (PRInt32 i = PRInt32(cnt) - 1; i >= 0; --i) {
|
|
|
|
nsISupports* isupports2 = aElements->ElementAt(i);
|
|
|
|
if (! isupports2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> element = do_QueryInterface(isupports2);
|
|
|
|
NS_RELEASE(isupports2);
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = element->SetAttr(/* XXX */ kNameSpaceID_None,
|
|
|
|
attr,
|
|
|
|
nsAutoString(wrapper),
|
2001-11-10 00:03:53 +00:00
|
|
|
PR_TRUE);
|
1999-10-05 21:13:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULDocument::ContextStack
|
|
|
|
//
|
1999-10-05 21:13:55 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsXULDocument::ContextStack::ContextStack()
|
|
|
|
: mTop(nsnull), mDepth(0)
|
1999-10-27 02:21:05 +00:00
|
|
|
{
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXULDocument::ContextStack::~ContextStack()
|
|
|
|
{
|
|
|
|
while (mTop) {
|
|
|
|
Entry* doomed = mTop;
|
|
|
|
mTop = mTop->mNext;
|
|
|
|
NS_IF_RELEASE(doomed->mElement);
|
|
|
|
delete doomed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::ContextStack::Push(nsXULPrototypeElement* aPrototype, nsIContent* aElement)
|
|
|
|
{
|
|
|
|
Entry* entry = new Entry;
|
|
|
|
if (! entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
entry->mPrototype = aPrototype;
|
|
|
|
entry->mElement = aElement;
|
|
|
|
NS_IF_ADDREF(entry->mElement);
|
|
|
|
entry->mIndex = 0;
|
|
|
|
|
|
|
|
entry->mNext = mTop;
|
|
|
|
mTop = entry;
|
|
|
|
|
|
|
|
++mDepth;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::ContextStack::Pop()
|
|
|
|
{
|
|
|
|
if (mDepth == 0)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
Entry* doomed = mTop;
|
|
|
|
mTop = mTop->mNext;
|
|
|
|
--mDepth;
|
|
|
|
|
|
|
|
NS_IF_RELEASE(doomed->mElement);
|
|
|
|
delete doomed;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::ContextStack::Peek(nsXULPrototypeElement** aPrototype,
|
|
|
|
nsIContent** aElement,
|
|
|
|
PRInt32* aIndex)
|
|
|
|
{
|
|
|
|
if (mDepth == 0)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
*aPrototype = mTop->mPrototype;
|
|
|
|
*aElement = mTop->mElement;
|
|
|
|
NS_IF_ADDREF(*aElement);
|
|
|
|
*aIndex = mTop->mIndex;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::ContextStack::SetTopIndex(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
if (mDepth == 0)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
mTop->mIndex = aIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsXULDocument::ContextStack::IsInsideXULTemplate()
|
|
|
|
{
|
|
|
|
if (mDepth) {
|
|
|
|
nsCOMPtr<nsIContent> element = dont_QueryInterface(mTop->mElement);
|
|
|
|
while (element) {
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
element->GetNameSpaceID(nameSpaceID);
|
|
|
|
if (nameSpaceID == kNameSpaceID_XUL) {
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
element->GetTag(*getter_AddRefs(tag));
|
2001-03-23 10:56:18 +00:00
|
|
|
if (tag.get() == nsXULAtoms::Template) {
|
1999-10-29 01:21:15 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parent;
|
|
|
|
element->GetParent(*getter_AddRefs(parent));
|
|
|
|
element = parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Content model walking routines
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::PrepareToWalk()
|
|
|
|
{
|
|
|
|
// Prepare to walk the mCurrentPrototype
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Keep an owning reference to the prototype document so that its
|
|
|
|
// elements aren't yanked from beneath us.
|
|
|
|
mPrototypes->AppendElement(mCurrentPrototype);
|
|
|
|
|
|
|
|
// Push the overlay references onto our overlay processing
|
|
|
|
// stack. GetOverlayReferences() will return an ordered array of
|
|
|
|
// overlay references...
|
1999-11-02 01:14:07 +00:00
|
|
|
nsCOMPtr<nsISupportsArray> overlays;
|
|
|
|
rv = mCurrentPrototype->GetOverlayReferences(getter_AddRefs(overlays));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// ...and we preserve this ordering by appending to our
|
|
|
|
// mUnloadedOverlays array in reverse order
|
1999-11-02 01:14:07 +00:00
|
|
|
PRUint32 count;
|
|
|
|
overlays->Count(&count);
|
|
|
|
for (PRInt32 i = count - 1; i >= 0; --i) {
|
1999-11-02 02:02:27 +00:00
|
|
|
nsISupports* isupports = overlays->ElementAt(i);
|
1999-11-02 01:14:07 +00:00
|
|
|
mUnloadedOverlays->AppendElement(isupports);
|
1999-11-02 02:02:27 +00:00
|
|
|
NS_IF_RELEASE(isupports);
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now check the chrome registry for any additional overlays.
|
|
|
|
rv = AddChromeOverlays();
|
|
|
|
|
|
|
|
// Get the prototype's root element and initialize the context
|
|
|
|
// stack for the prototype walk.
|
|
|
|
nsXULPrototypeElement* proto;
|
|
|
|
rv = mCurrentPrototype->GetRootElement(&proto);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
if (! proto) {
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
rv = mCurrentPrototype->GetURI(getter_AddRefs(url));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString urlspec;
|
|
|
|
rv = url->GetSpec(urlspec);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PR_LOG(gXULLog, PR_LOG_ALWAYS,
|
2002-03-06 07:48:55 +00:00
|
|
|
("xul: error parsing '%s'", urlspec.get()));
|
1999-10-29 01:21:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do one-time initialization if we're preparing to walk the
|
|
|
|
// master document's prototype.
|
|
|
|
nsCOMPtr<nsIContent> root;
|
|
|
|
|
|
|
|
if (mState == eState_Master) {
|
|
|
|
rv = CreateElement(proto, getter_AddRefs(root));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
SetRootContent(root);
|
|
|
|
|
|
|
|
// Add the root element to the XUL document's ID-to-element map.
|
|
|
|
rv = AddElementToMap(root);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-11-24 22:46:09 +00:00
|
|
|
|
1999-11-23 01:44:51 +00:00
|
|
|
// Add a dummy channel to the load group as a placeholder for the document
|
|
|
|
// load
|
2001-02-22 03:01:34 +00:00
|
|
|
rv = PlaceHolderRequest::Create(getter_AddRefs(mPlaceHolderRequest));
|
1999-11-23 01:44:51 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-11-24 22:46:09 +00:00
|
|
|
|
1999-11-23 01:44:51 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1999-11-23 01:44:51 +00:00
|
|
|
if (group) {
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = mPlaceHolderRequest->SetLoadGroup(group);
|
1999-11-24 22:46:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-02-22 03:01:34 +00:00
|
|
|
rv = group->AddRequest(mPlaceHolderRequest, nsnull);
|
1999-11-24 22:46:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-11-23 01:44:51 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
|
2000-10-29 17:58:21 +00:00
|
|
|
// There'd better not be anything on the context stack at this
|
|
|
|
// point! This is the basis case for our "induction" in
|
|
|
|
// ResumeWalk(), below, which'll assume that there's always a
|
|
|
|
// content element on the context stack if either 1) we're in the
|
|
|
|
// "master" document, or 2) we're in an overlay, and we've got
|
|
|
|
// more than one prototype element (the single, root "overlay"
|
|
|
|
// element) on the stack.
|
|
|
|
NS_ASSERTION(mContextStack.Depth() == 0, "something's on the context stack already");
|
|
|
|
if (mContextStack.Depth() != 0)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
rv = mContextStack.Push(proto, root);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::AddChromeOverlays()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2002-07-23 23:30:04 +00:00
|
|
|
nsCOMPtr<nsIXULChromeRegistry> reg(do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv));
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> oe;
|
1999-11-05 05:31:15 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = mCurrentPrototype->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
reg->GetOverlays(uri, getter_AddRefs(oe));
|
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
if (!oe)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRBool moreElements;
|
|
|
|
oe->HasMoreElements(&moreElements);
|
|
|
|
|
|
|
|
while (moreElements) {
|
|
|
|
nsCOMPtr<nsISupports> next;
|
|
|
|
oe->GetNext(getter_AddRefs(next));
|
|
|
|
if (!next)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri = do_QueryInterface(next);
|
|
|
|
if (!uri)
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-09-24 02:07:20 +00:00
|
|
|
// See if this package is enabled/disabled. If it
|
|
|
|
// is disabled, we shouldn't append this element to
|
|
|
|
// the unloaded overlay list.
|
|
|
|
PRBool allowed = PR_TRUE;
|
|
|
|
reg->IsOverlayAllowed(uri, &allowed);
|
|
|
|
if (allowed)
|
|
|
|
mUnloadedOverlays->AppendElement(uri);
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
oe->HasMoreElements(&moreElements);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::ResumeWalk()
|
|
|
|
{
|
|
|
|
// Walk the prototype and build the delegate content model. The
|
|
|
|
// walk is performed in a top-down, left-to-right fashion. That
|
|
|
|
// is, a parent is built before any of its children; a node is
|
|
|
|
// only built after all of its siblings to the left are fully
|
|
|
|
// constructed.
|
|
|
|
//
|
|
|
|
// It is interruptable so that transcluded documents (e.g.,
|
|
|
|
// <html:script src="..." />) can be properly re-loaded if the
|
|
|
|
// cached copy of the document becomes stale.
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// Begin (or resume) walking the current prototype.
|
|
|
|
|
|
|
|
while (mContextStack.Depth() > 0) {
|
|
|
|
// Look at the top of the stack to determine what we're
|
|
|
|
// currently working on.
|
|
|
|
nsXULPrototypeElement* proto;
|
|
|
|
nsCOMPtr<nsIContent> element;
|
|
|
|
PRInt32 indx;
|
|
|
|
rv = mContextStack.Peek(&proto, getter_AddRefs(element), &indx);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (indx >= proto->mNumChildren) {
|
2001-02-20 01:05:34 +00:00
|
|
|
// We've processed all of the prototype's children. If
|
|
|
|
// we're in the master prototype, do post-order
|
|
|
|
// document-level hookup. (An overlay will get its
|
|
|
|
// document hookup done when it's successfully
|
|
|
|
// resolved.)
|
|
|
|
if (element && (mState == eState_Master))
|
|
|
|
AddElementToDocumentPost(element);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
// Now pop the context stack back up to the parent
|
|
|
|
// element and continue the prototype walk.
|
|
|
|
mContextStack.Pop();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grab the next child, and advance the current context stack
|
|
|
|
// to the next sibling to our right.
|
|
|
|
nsXULPrototypeNode* childproto = proto->mChildren[indx];
|
|
|
|
mContextStack.SetTopIndex(++indx);
|
|
|
|
|
|
|
|
switch (childproto->mType) {
|
|
|
|
case nsXULPrototypeNode::eType_Element: {
|
|
|
|
// An 'element', which may contain more content.
|
|
|
|
nsXULPrototypeElement* protoele =
|
|
|
|
NS_REINTERPRET_CAST(nsXULPrototypeElement*, childproto);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
|
|
|
|
if ((mState == eState_Master) || (mContextStack.Depth() > 1)) {
|
1999-11-08 19:07:13 +00:00
|
|
|
// We're in the master document -or -we're in an
|
|
|
|
// overlay, and far enough down into the overlay's
|
|
|
|
// content that we can simply build the delegates
|
|
|
|
// and attach them to the parent node.
|
2000-10-29 17:58:21 +00:00
|
|
|
NS_ASSERTION(element != nsnull, "no element on context stack");
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
rv = CreateElement(protoele, getter_AddRefs(child));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// ...and append it to the content model.
|
2001-04-02 00:45:52 +00:00
|
|
|
rv = element->AppendChildTo(child, PR_FALSE, PR_FALSE);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-02-13 19:22:56 +00:00
|
|
|
|
2001-02-20 01:05:34 +00:00
|
|
|
// do pre-order document-level hookup, but only if
|
|
|
|
// we're in the master document. For an overlay,
|
|
|
|
// this will happen when the overlay is
|
|
|
|
// successfully resolved.
|
|
|
|
if (mState == eState_Master)
|
|
|
|
AddElementToDocumentPre(child);
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We're in the "first ply" of an overlay: the
|
|
|
|
// "hookup" nodes. Create an 'overlay' element so
|
|
|
|
// that we can continue to build content, and
|
|
|
|
// enter a forward reference so we can hook it up
|
|
|
|
// later.
|
|
|
|
rv = CreateOverlayElement(protoele, getter_AddRefs(child));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it has children, push the element onto the context
|
|
|
|
// stack and begin to process them.
|
|
|
|
if (protoele->mNumChildren > 0) {
|
|
|
|
rv = mContextStack.Push(protoele, child);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2001-02-20 01:05:34 +00:00
|
|
|
else if (mState == eState_Master) {
|
|
|
|
// If there are no children, and we're in the
|
|
|
|
// master document, do post-order document hookup
|
|
|
|
// immediately.
|
|
|
|
AddElementToDocumentPost(child);
|
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXULPrototypeNode::eType_Script: {
|
1999-11-18 02:25:33 +00:00
|
|
|
// A script reference. Execute the script immediately;
|
1999-10-29 01:21:15 +00:00
|
|
|
// this may have side effects in the content model.
|
|
|
|
nsXULPrototypeScript* scriptproto =
|
|
|
|
NS_REINTERPRET_CAST(nsXULPrototypeScript*, childproto);
|
|
|
|
|
|
|
|
if (scriptproto->mSrcURI) {
|
|
|
|
// A transcluded script reference; this may
|
|
|
|
// "block" our prototype walk if the script isn't
|
|
|
|
// cached, or the cached copy of the script is
|
|
|
|
// stale and must be reloaded.
|
|
|
|
PRBool blocked;
|
1999-11-18 02:25:33 +00:00
|
|
|
rv = LoadScript(scriptproto, &blocked);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (blocked)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
else if (scriptproto->mJSObject) {
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
// An inline script
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
rv = ExecuteScript(scriptproto->mJSObject);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
case nsXULPrototypeNode::eType_Text: {
|
|
|
|
// A simple text node.
|
2001-01-10 01:08:23 +00:00
|
|
|
|
2000-10-29 17:58:21 +00:00
|
|
|
if ((mState == eState_Master) || (mContextStack.Depth() > 1)) {
|
|
|
|
// We're in the master document -or -we're in an
|
|
|
|
// overlay, and far enough down into the overlay's
|
|
|
|
// content that we can simply build the delegates
|
|
|
|
// and attach them to the parent node.
|
|
|
|
NS_ASSERTION(element != nsnull, "no element on context stack");
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsITextContent> text =
|
|
|
|
do_CreateInstance(kTextNodeCID, &rv);
|
2000-10-29 17:58:21 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsXULPrototypeText* textproto =
|
|
|
|
NS_REINTERPRET_CAST(nsXULPrototypeText*, childproto);
|
2001-06-30 11:02:25 +00:00
|
|
|
rv = text->SetText(textproto->mValue.get(),
|
2000-10-29 17:58:21 +00:00
|
|
|
textproto->mValue.Length(),
|
|
|
|
PR_FALSE);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2000-10-29 17:58:21 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2000-10-29 17:58:21 +00:00
|
|
|
nsCOMPtr<nsIContent> child = do_QueryInterface(text);
|
|
|
|
if (! child)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2000-04-12 07:38:17 +00:00
|
|
|
|
2001-04-02 00:45:52 +00:00
|
|
|
rv = element->AppendChildTo(child, PR_FALSE, PR_FALSE);
|
2000-10-29 17:58:21 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Once we get here, the context stack will have been
|
|
|
|
// depleted. That means that the entire prototype has been
|
|
|
|
// walked and content has been constructed.
|
|
|
|
|
|
|
|
// If we're not already, mark us as now processing overlays.
|
|
|
|
mState = eState_Overlay;
|
|
|
|
|
|
|
|
PRUint32 count;
|
|
|
|
mUnloadedOverlays->Count(&count);
|
|
|
|
|
|
|
|
// If there are no overlay URIs, then we're done.
|
|
|
|
if (! count)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri =
|
|
|
|
dont_AddRef(NS_REINTERPRET_CAST(nsIURI*, mUnloadedOverlays->ElementAt(count - 1)));
|
|
|
|
|
|
|
|
mUnloadedOverlays->RemoveElementAt(count - 1);
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gXULLog, PR_LOG_DEBUG)) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString urlspec;
|
|
|
|
uri->GetSpec(urlspec);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
PR_LOG(gXULLog, PR_LOG_DEBUG,
|
2002-03-06 07:48:55 +00:00
|
|
|
("xul: loading overlay %s", urlspec.get()));
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Look in the prototype cache for the prototype document with
|
2001-07-31 19:05:34 +00:00
|
|
|
// the specified overlay URI.
|
2002-05-07 01:29:44 +00:00
|
|
|
if (IsChromeURI(uri))
|
|
|
|
gXULCache->GetPrototype(uri, getter_AddRefs(mCurrentPrototype));
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
// Same comment as nsChromeProtocolHandler::NewChannel and
|
|
|
|
// nsXULDocument::StartDocumentLoad
|
|
|
|
// - Ben Goodger
|
|
|
|
//
|
|
|
|
// We don't abort on failure here because there are too many valid
|
|
|
|
// cases that can return failure, and the null-ness of |proto| is enough
|
|
|
|
// to trigger the fail-safe parse-from-disk solution. Example failure cases
|
|
|
|
// (for reference) include:
|
|
|
|
//
|
|
|
|
// NS_ERROR_NOT_AVAILABLE: the URI cannot be found in the FastLoad cache,
|
|
|
|
// parse from disk
|
|
|
|
// other: the FastLoad cache file, XUL.mfl, could not be found, probably
|
|
|
|
// due to being accessed before a profile has been selected (e.g.
|
|
|
|
// loading chrome for the profile manager itself). This must be
|
|
|
|
// parsed from disk.
|
|
|
|
|
2001-02-22 03:01:34 +00:00
|
|
|
PRBool cache;
|
|
|
|
gXULCache->GetEnabled(&cache);
|
|
|
|
|
|
|
|
if (cache && mCurrentPrototype) {
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_ASSERTION(IsChromeURI(uri), "XUL cache hit on non-chrome URI?");
|
|
|
|
PRBool loaded;
|
|
|
|
rv = mCurrentPrototype->AwaitLoadDone(this, &loaded);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (! loaded) {
|
|
|
|
// Return to the main event loop and eagerly await the
|
|
|
|
// prototype overlay load's completion. When the content
|
|
|
|
// sink completes, it will trigger an EndLoad(), which'll
|
|
|
|
// wind us back up here, in ResumeWalk().
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Found the overlay's prototype in the cache, fully loaded.
|
1999-11-02 01:14:07 +00:00
|
|
|
rv = AddPrototypeSheets();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Now prepare to walk the prototype to create its content
|
1999-10-29 01:21:15 +00:00
|
|
|
rv = PrepareToWalk();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PR_LOG(gXULLog, PR_LOG_DEBUG, ("xul: overlay was cached"));
|
|
|
|
}
|
|
|
|
else {
|
1999-12-16 03:19:34 +00:00
|
|
|
// Not there. Initiate a load.
|
1999-10-29 01:21:15 +00:00
|
|
|
PR_LOG(gXULLog, PR_LOG_DEBUG, ("xul: overlay was not cached"));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIParser> parser;
|
1999-11-18 02:25:33 +00:00
|
|
|
rv = PrepareToLoadPrototype(uri, "view", nsnull, getter_AddRefs(parser));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
mIsWritingFastLoad = PR_TRUE;
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> listener = do_QueryInterface(parser);
|
|
|
|
if (! listener)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2000-03-07 02:33:44 +00:00
|
|
|
// Add an observer to the parser; this'll get called when
|
|
|
|
// Necko fires its On[Start|Stop]Request() notifications,
|
|
|
|
// and will let us recover from a missing overlay.
|
|
|
|
ParserObserver* parserObserver = new ParserObserver(this);
|
|
|
|
if (! parserObserver)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(parserObserver);
|
|
|
|
parser->Parse(uri, parserObserver);
|
|
|
|
NS_RELEASE(parserObserver);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
|
|
|
|
rv = NS_OpenURI(listener, nsnull, uri, nsnull, group);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
|
|
|
// If it's a 'chrome:' prototype document, then put it into
|
|
|
|
// the prototype cache; other XUL documents will be reloaded
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-21 20:51:34 +00:00
|
|
|
// each time. We must do this after NS_OpenURI and AsyncOpen,
|
|
|
|
// or chrome code will wrongly create a cached chrome channel
|
|
|
|
// instead of a real one.
|
2001-07-31 19:05:34 +00:00
|
|
|
if (cache && IsChromeURI(uri)) {
|
|
|
|
rv = gXULCache->PutPrototype(mCurrentPrototype);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
// Return to the main event loop and eagerly await the
|
|
|
|
// overlay load's completion. When the content sink
|
|
|
|
// completes, it will trigger an EndLoad(), which'll wind
|
|
|
|
// us back up here, in ResumeWalk().
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here, there is nothing left for us to walk. The content
|
|
|
|
// model is built and ready for layout.
|
1999-11-23 01:44:51 +00:00
|
|
|
rv = ResolveForwardReferences();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ApplyPersistentAttributes();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
// Everything after this point we only want to do once we're
|
|
|
|
// certain that we've been embedded in a presentation shell.
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
StartLayout();
|
|
|
|
|
2002-05-03 03:04:34 +00:00
|
|
|
PRBool useXULCache;
|
|
|
|
gXULCache->GetEnabled(&useXULCache);
|
|
|
|
|
2002-05-07 01:29:44 +00:00
|
|
|
if (useXULCache && mIsWritingFastLoad && IsChromeURI(mDocumentURL))
|
2002-05-03 03:04:34 +00:00
|
|
|
gXULCache->WritePrototype(mMasterPrototype);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-10-22 20:48:52 +00:00
|
|
|
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
|
1999-10-29 01:21:15 +00:00
|
|
|
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
|
|
|
|
observer->EndLoad(this);
|
|
|
|
}
|
2002-01-16 00:16:51 +00:00
|
|
|
NS_ASSERTION(mPlaceHolderRequest, "Bug 119310, perhaps overlayinfo referenced a overlay that doesn't exist");
|
|
|
|
if (mPlaceHolderRequest) {
|
|
|
|
// Remove the placeholder channel; if we're the last channel in the
|
|
|
|
// load group, this will fire the OnEndDocumentLoad() method in the
|
|
|
|
// docshell, and run the onload handlers, etc.
|
|
|
|
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
|
|
|
|
if (group) {
|
|
|
|
rv = group->RemoveRequest(mPlaceHolderRequest, nsnull, NS_OK);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2002-01-16 00:16:51 +00:00
|
|
|
mPlaceHolderRequest = nsnull;
|
|
|
|
}
|
1999-11-24 22:46:09 +00:00
|
|
|
}
|
2002-05-03 03:04:34 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-11-18 02:25:33 +00:00
|
|
|
nsXULDocument::LoadScript(nsXULPrototypeScript* aScriptProto, PRBool* aBlock)
|
1999-10-29 01:21:15 +00:00
|
|
|
{
|
|
|
|
// Load a transcluded script
|
|
|
|
nsresult rv;
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
if (aScriptProto->mJSObject) {
|
|
|
|
rv = ExecuteScript(aScriptProto->mJSObject);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
// Ignore return value from execution, and don't block
|
1999-11-02 01:14:07 +00:00
|
|
|
*aBlock = PR_FALSE;
|
2001-07-31 19:05:34 +00:00
|
|
|
return NS_OK;
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// Try the XUL script cache, in case two XUL documents source the same
|
|
|
|
// .js file (e.g., strres.js from navigator.xul and utilityOverlay.xul).
|
|
|
|
// XXXbe the cache relies on aScriptProto's GC root!
|
|
|
|
PRBool useXULCache;
|
|
|
|
gXULCache->GetEnabled(&useXULCache);
|
|
|
|
|
|
|
|
if (useXULCache) {
|
|
|
|
gXULCache->GetScript(aScriptProto->mSrcURI,
|
|
|
|
NS_REINTERPRET_CAST(void**, &aScriptProto->mJSObject));
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
if (aScriptProto->mJSObject) {
|
|
|
|
rv = ExecuteScript(aScriptProto->mJSObject);
|
|
|
|
|
|
|
|
// Ignore return value from execution, and don't block
|
|
|
|
*aBlock = PR_FALSE;
|
|
|
|
return NS_OK;
|
1999-11-18 02:25:33 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the current script prototype so that OnStreamComplete can report
|
|
|
|
// the right file if there are errors in the script.
|
|
|
|
NS_ASSERTION(!mCurrentScriptProto,
|
|
|
|
"still loading a script when starting another load?");
|
|
|
|
mCurrentScriptProto = aScriptProto;
|
|
|
|
|
|
|
|
if (aScriptProto->mSrcLoading) {
|
|
|
|
// Another XULDocument load has started, which is still in progress.
|
|
|
|
// Remember to ResumeWalk this document when the load completes.
|
|
|
|
mNextSrcLoadWaiter = aScriptProto->mSrcLoadWaiters;
|
|
|
|
aScriptProto->mSrcLoadWaiters = this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Set mSrcLoading *before* calling NS_NewStreamLoader, in case the
|
|
|
|
// stream completes (probably due to an error) within the activation
|
|
|
|
// of NS_NewStreamLoader.
|
|
|
|
aScriptProto->mSrcLoading = PR_TRUE;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
|
|
|
|
|
|
|
|
// N.B., the loader will be released in OnStreamComplete
|
|
|
|
nsIStreamLoader* loader;
|
|
|
|
rv = NS_NewStreamLoader(&loader, aScriptProto->mSrcURI, this, nsnull, group);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
|
|
|
// Block until OnStreamComplete resumes us.
|
|
|
|
*aBlock = PR_TRUE;
|
1999-10-29 01:21:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-30 04:50:42 +00:00
|
|
|
NS_IMETHODIMP
|
2000-02-02 23:04:47 +00:00
|
|
|
nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
|
|
|
|
nsISupports* context,
|
|
|
|
nsresult aStatus,
|
|
|
|
PRUint32 stringLen,
|
|
|
|
const char* string)
|
1999-10-29 01:21:15 +00:00
|
|
|
{
|
2000-05-03 22:47:48 +00:00
|
|
|
// print a load error on bad status
|
2001-10-31 08:29:25 +00:00
|
|
|
// XXXbe shouldn't we do this only #ifdef DEBUG
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-21 20:51:34 +00:00
|
|
|
if (NS_FAILED(aStatus)) {
|
2001-07-31 19:05:34 +00:00
|
|
|
nsCOMPtr<nsIRequest> request;
|
2001-02-22 03:01:34 +00:00
|
|
|
aLoader->GetRequest(getter_AddRefs(request));
|
2001-07-31 19:05:34 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
channel = do_QueryInterface(request);
|
|
|
|
if (channel) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString uriSpec;
|
|
|
|
uri->GetSpec(uriSpec);
|
|
|
|
printf("Failed to load %s\n", uriSpec.get());
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
2000-05-03 22:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
// This is the completion routine that will be called when a
|
1999-11-18 02:25:33 +00:00
|
|
|
// transcluded script completes. Compile and execute the script
|
|
|
|
// if the load was successful, then continue building content
|
|
|
|
// from the prototype.
|
1999-10-29 01:21:15 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-11-23 01:44:51 +00:00
|
|
|
NS_ASSERTION(mCurrentScriptProto && mCurrentScriptProto->mSrcLoading,
|
1999-11-18 02:25:33 +00:00
|
|
|
"script source not loading on unichar stream complete?");
|
1999-11-02 01:14:07 +00:00
|
|
|
|
1999-11-23 01:44:51 +00:00
|
|
|
// Clear mCurrentScriptProto now, but save it first for use below in
|
|
|
|
// the compile/execute code, and in the while loop that resumes walks
|
|
|
|
// of other documents that raced to load this script
|
|
|
|
nsXULPrototypeScript* scriptProto = mCurrentScriptProto;
|
|
|
|
mCurrentScriptProto = nsnull;
|
|
|
|
|
|
|
|
// Clear the prototype's loading flag before executing the script or
|
|
|
|
// resuming document walks, in case any of those control flows starts a
|
|
|
|
// new script load.
|
|
|
|
scriptProto->mSrcLoading = PR_FALSE;
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
2001-07-31 19:05:34 +00:00
|
|
|
// If the including XUL document is a FastLoad document, and we're
|
|
|
|
// compiling an out-of-line script (one with src=...), then we must
|
|
|
|
// be writing a new FastLoad file. If we were reading this script
|
|
|
|
// from the FastLoad file, XULContentSinkImpl::OpenScript (over in
|
|
|
|
// nsXULContentSink.cpp) would have already deserialized a non-null
|
|
|
|
// script->mJSObject, causing control flow at the top of LoadScript
|
|
|
|
// not to reach here.
|
|
|
|
//
|
|
|
|
// Start and Select the .js document in the FastLoad multiplexor
|
|
|
|
// before serializing script data under scriptProto->Compile, and
|
|
|
|
// End muxing afterward.
|
|
|
|
nsCOMPtr<nsIURI> uri = scriptProto->mSrcURI;
|
2002-05-03 03:04:34 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFastLoadService> fastLoadService;
|
2002-05-14 01:15:27 +00:00
|
|
|
PRBool useXULCache;
|
|
|
|
gXULCache->GetEnabled(&useXULCache);
|
|
|
|
if (useXULCache)
|
|
|
|
gXULCache->GetFastLoadService(getter_AddRefs(fastLoadService));
|
2002-05-03 03:04:34 +00:00
|
|
|
|
|
|
|
if (fastLoadService) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString urispec;
|
|
|
|
uri->GetAsciiSpec(urispec);
|
2002-05-03 03:04:34 +00:00
|
|
|
rv = fastLoadService->StartMuxedDocument(uri, urispec.get(),
|
|
|
|
nsIFastLoadService::NS_FASTLOAD_WRITE);
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_ASSERTION(rv != NS_ERROR_NOT_AVAILABLE, "reading FastLoad?!");
|
2002-05-03 03:04:34 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIURI> oldURI;
|
|
|
|
fastLoadService->SelectMuxedDocument(uri, getter_AddRefs(oldURI));
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
|
|
|
|
2000-04-17 14:30:23 +00:00
|
|
|
nsString stringStr; stringStr.AssignWithConversion(string, stringLen);
|
2001-07-31 19:05:34 +00:00
|
|
|
rv = scriptProto->Compile(stringStr.get(), stringLen, uri, 1, this,
|
2002-05-03 03:04:34 +00:00
|
|
|
mCurrentPrototype);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
|
|
|
// End muxing the .js file into the FastLoad file. We don't Abort
|
|
|
|
// the FastLoad process here, when writing, as we do when reading.
|
|
|
|
// XXXbe maybe we should...
|
|
|
|
// NB: we don't need to Select mDocumentURL again, because scripts
|
|
|
|
// load after their including prototype document has fully loaded.
|
2002-05-03 03:04:34 +00:00
|
|
|
if (fastLoadService)
|
|
|
|
fastLoadService->EndMuxedDocument(uri);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1999-11-23 01:44:51 +00:00
|
|
|
aStatus = rv;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && scriptProto->mJSObject) {
|
|
|
|
rv = ExecuteScript(scriptProto->mJSObject);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
|
|
|
// If the XUL cache is enabled, save the script object there in
|
|
|
|
// case different XUL documents source the same script.
|
2001-09-06 02:00:39 +00:00
|
|
|
//
|
|
|
|
// But don't save the script in the cache unless the master XUL
|
|
|
|
// document URL is a chrome: URL. It is valid for a URL such as
|
|
|
|
// about:config to translate into a master document URL, whose
|
|
|
|
// prototype document nodes -- including prototype scripts that
|
|
|
|
// hold GC roots protecting their mJSObject pointers -- are not
|
|
|
|
// cached in the XUL prototype cache. See StartDocumentLoad,
|
|
|
|
// the fillXULCache logic.
|
|
|
|
//
|
|
|
|
// A document such as about:config is free to load a script via
|
|
|
|
// a URL such as chrome://global/content/config.js, and we must
|
|
|
|
// not cache that script object without a prototype cache entry
|
|
|
|
// containing a companion nsXULPrototypeScript node that owns a
|
|
|
|
// GC root protecting the script object. Otherwise, the script
|
|
|
|
// cache entry will dangle once uncached prototype document is
|
|
|
|
// released when its owning nsXULDocument is unloaded.
|
|
|
|
//
|
|
|
|
// (See http://bugzilla.mozilla.org/show_bug.cgi?id=98207 for
|
|
|
|
// the true crime story.)
|
2001-07-31 19:05:34 +00:00
|
|
|
PRBool useXULCache;
|
|
|
|
gXULCache->GetEnabled(&useXULCache);
|
|
|
|
|
2001-09-06 02:00:39 +00:00
|
|
|
if (useXULCache && IsChromeURI(mDocumentURL)) {
|
2001-07-31 19:05:34 +00:00
|
|
|
gXULCache->PutScript(scriptProto->mSrcURI,
|
|
|
|
NS_REINTERPRET_CAST(void*, scriptProto->mJSObject));
|
|
|
|
}
|
1999-11-02 01:14:07 +00:00
|
|
|
}
|
1999-11-18 02:25:33 +00:00
|
|
|
// ignore any evaluation errors
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// balance the addref we added in LoadScript()
|
|
|
|
NS_RELEASE(aLoader);
|
|
|
|
|
1999-11-02 06:49:44 +00:00
|
|
|
rv = ResumeWalk();
|
1999-11-18 02:25:33 +00:00
|
|
|
|
1999-11-23 01:44:51 +00:00
|
|
|
// Load a pointer to the prototype-script's list of nsXULDocuments who
|
|
|
|
// raced to load the same script
|
|
|
|
nsXULDocument** docp = &scriptProto->mSrcLoadWaiters;
|
|
|
|
|
|
|
|
// Resume walking other documents that waited for this one's load, first
|
|
|
|
// executing the script we just compiled, in each doc's script context
|
1999-11-18 02:25:33 +00:00
|
|
|
nsXULDocument* doc;
|
|
|
|
while ((doc = *docp) != nsnull) {
|
1999-11-23 01:44:51 +00:00
|
|
|
NS_ASSERTION(doc->mCurrentScriptProto == scriptProto,
|
|
|
|
"waiting for wrong script to load?");
|
|
|
|
doc->mCurrentScriptProto = nsnull;
|
|
|
|
|
|
|
|
// Unlink doc from scriptProto's list before executing and resuming
|
1999-11-18 02:25:33 +00:00
|
|
|
*docp = doc->mNextSrcLoadWaiter;
|
|
|
|
doc->mNextSrcLoadWaiter = nsnull;
|
1999-11-23 01:44:51 +00:00
|
|
|
|
|
|
|
// Execute only if we loaded and compiled successfully, then resume
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
if (NS_SUCCEEDED(aStatus) && scriptProto->mJSObject) {
|
|
|
|
doc->ExecuteScript(scriptProto->mJSObject);
|
1999-11-23 01:44:51 +00:00
|
|
|
}
|
1999-11-20 03:10:42 +00:00
|
|
|
doc->ResumeWalk();
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
1999-11-23 01:44:51 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-11-18 02:25:33 +00:00
|
|
|
nsXULDocument::ExecuteScript(JSObject* aScriptObject)
|
1999-10-29 01:21:15 +00:00
|
|
|
{
|
2001-03-19 22:22:24 +00:00
|
|
|
NS_PRECONDITION(aScriptObject != nsnull, "null ptr");
|
|
|
|
if (! aScriptObject)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
// Execute the precompiled script with the given version
|
1999-10-29 01:21:15 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
NS_ASSERTION(mScriptGlobalObject != nsnull, "no script global object");
|
|
|
|
if (! mScriptGlobalObject)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> context;
|
1999-12-03 09:24:22 +00:00
|
|
|
rv = mScriptGlobalObject->GetContext(getter_AddRefs(context));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-07-19 05:48:49 +00:00
|
|
|
if (! context) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
1999-11-18 02:25:33 +00:00
|
|
|
rv = context->ExecuteScript(aScriptObject, nsnull, nsnull, nsnull);
|
1999-10-29 01:21:15 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::CreateElement(nsXULPrototypeElement* aPrototype, nsIContent** aResult)
|
|
|
|
{
|
|
|
|
// Create a content model element from a prototype element.
|
|
|
|
NS_PRECONDITION(aPrototype != nsnull, "null ptr");
|
|
|
|
if (! aPrototype)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gXULLog, PR_LOG_ALWAYS)) {
|
|
|
|
nsAutoString tagstr;
|
2000-05-10 13:13:39 +00:00
|
|
|
aPrototype->mNodeInfo->GetQualifiedName(tagstr);
|
1999-11-18 02:25:33 +00:00
|
|
|
|
2000-04-26 01:13:55 +00:00
|
|
|
nsCAutoString tagstrC;
|
|
|
|
tagstrC.AssignWithConversion(tagstr);
|
1999-10-29 01:21:15 +00:00
|
|
|
PR_LOG(gXULLog, PR_LOG_ALWAYS,
|
|
|
|
("xul: creating <%s> from prototype",
|
2001-10-27 06:44:19 +00:00
|
|
|
tagstrC.get()));
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> result;
|
|
|
|
|
2002-09-25 09:56:09 +00:00
|
|
|
if (aPrototype->mNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
|
|
|
|
// If it's a XUL element, it'll be lightweight until somebody
|
|
|
|
// monkeys with it.
|
|
|
|
rv = nsXULElement::Create(aPrototype, this, PR_TRUE, getter_AddRefs(result));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
else if (aPrototype->mNodeInfo->NamespaceEquals(kNameSpaceID_XHTML)) {
|
1999-10-29 01:21:15 +00:00
|
|
|
// If it's an HTML element, it's gonna be heavyweight no matter
|
|
|
|
// what. So we need to copy everything out of the prototype
|
|
|
|
// into the element.
|
1999-11-18 02:25:33 +00:00
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
gHTMLElementFactory->CreateInstanceByTag(aPrototype->mNodeInfo,
|
|
|
|
getter_AddRefs(result));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2000-05-19 04:48:43 +00:00
|
|
|
rv = result->SetDocument(this, PR_FALSE, PR_TRUE);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = AddAttributes(aPrototype, result);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2002-09-25 09:56:09 +00:00
|
|
|
else {
|
2000-01-19 03:11:39 +00:00
|
|
|
// If it's not a XUL element, it's gonna be heavyweight no matter
|
|
|
|
// what. So we need to copy everything out of the prototype
|
|
|
|
// into the element.
|
2000-05-10 13:13:39 +00:00
|
|
|
|
|
|
|
PRInt32 namespaceID;
|
|
|
|
aPrototype->mNodeInfo->GetNamespaceID(namespaceID);
|
2000-01-19 03:11:39 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIElementFactory> elementFactory;
|
2000-05-10 13:13:39 +00:00
|
|
|
GetElementFactory(namespaceID,
|
|
|
|
getter_AddRefs(elementFactory));
|
2001-09-05 04:20:54 +00:00
|
|
|
rv = elementFactory->CreateInstanceByTag(aPrototype->mNodeInfo,
|
|
|
|
getter_AddRefs(result));
|
2000-01-19 03:11:39 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2000-05-19 04:48:43 +00:00
|
|
|
rv = result->SetDocument(this, PR_FALSE, PR_TRUE);
|
2000-01-19 03:11:39 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = AddAttributes(aPrototype, result);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
1999-12-06 23:05:31 +00:00
|
|
|
result->SetContentID(mNextContentID++);
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
*aResult = result;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::CreateOverlayElement(nsXULPrototypeElement* aPrototype, nsIContent** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// This doesn't really do anything except create a placeholder
|
|
|
|
// element. I'd use an XML element, but it gets its knickers in a
|
|
|
|
// knot with DOM ranges when you try to remove its children.
|
|
|
|
nsCOMPtr<nsIContent> element;
|
1999-11-04 19:43:43 +00:00
|
|
|
rv = nsXULElement::Create(aPrototype, this, PR_FALSE, getter_AddRefs(element));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-02-14 00:40:55 +00:00
|
|
|
|
1999-11-08 19:07:13 +00:00
|
|
|
OverlayForwardReference* fwdref = new OverlayForwardReference(this, element);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (! fwdref)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// transferring ownership to ya...
|
|
|
|
rv = AddForwardReference(fwdref);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*aResult = element;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::AddAttributes(nsXULPrototypeElement* aPrototype, nsIContent* aElement)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < aPrototype->mNumAttributes; ++i) {
|
|
|
|
nsXULPrototypeAttribute* protoattr = &(aPrototype->mAttributes[i]);
|
2000-09-15 06:52:17 +00:00
|
|
|
nsAutoString valueStr;
|
|
|
|
protoattr->mValue.GetValue( valueStr );
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->SetAttr(protoattr->mNodeInfo,
|
|
|
|
valueStr,
|
|
|
|
PR_FALSE);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::CheckTemplateBuilder(nsIContent* aElement)
|
|
|
|
{
|
|
|
|
// Check aElement for a 'datasources' attribute, and if it has
|
|
|
|
// one, create and initialize a template builder.
|
|
|
|
nsresult rv;
|
|
|
|
|
2001-02-20 01:05:34 +00:00
|
|
|
// See if the element already has a `database' attribute. If it
|
|
|
|
// does, then the template builder has already been created.
|
|
|
|
//
|
|
|
|
// XXX this approach will crash and burn (well, maybe not _that_
|
|
|
|
// bad) if aElement is not a XUL element.
|
|
|
|
nsCOMPtr<nsIDOMXULElement> xulele = do_QueryInterface(aElement);
|
|
|
|
if (xulele) {
|
|
|
|
nsCOMPtr<nsIRDFCompositeDataSource> ds;
|
|
|
|
xulele->GetDatabase(getter_AddRefs(ds));
|
|
|
|
if (ds)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsAutoString datasources;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::datasources, datasources);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (rv != NS_CONTENT_ATTR_HAS_VALUE)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Get the document and its URL
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2001-03-23 10:56:18 +00:00
|
|
|
aElement->GetDocument(*getter_AddRefs(doc));
|
1999-10-29 01:21:15 +00:00
|
|
|
NS_ASSERTION(doc != nsnull, "no document");
|
|
|
|
if (! doc)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// construct a new builder
|
2001-03-23 10:56:18 +00:00
|
|
|
PRInt32 nameSpaceID = 0;
|
|
|
|
nsCOMPtr<nsIAtom> baseTag;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-03-23 10:56:18 +00:00
|
|
|
nsCOMPtr<nsIXBLService> xblService = do_GetService("@mozilla.org/xbl;1");
|
|
|
|
if (xblService)
|
|
|
|
xblService->ResolveTag(aElement, &nameSpaceID, getter_AddRefs(baseTag));
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
// By default, we build content for an tree and then we attach
|
|
|
|
// the tree content view. However, if the `dont-build-content'
|
|
|
|
// flag is set, then we we'll attach an tree builder which
|
|
|
|
// directly implements the tree view.
|
2002-01-24 21:30:22 +00:00
|
|
|
// XXXwaterson maybe we should do the latter by default: it ought
|
|
|
|
// to reduce the footprint a great deal.
|
2002-03-29 02:46:01 +00:00
|
|
|
if ((nameSpaceID == kNameSpaceID_XUL) && (baseTag == nsXULAtoms::tree)) {
|
2002-01-03 22:58:23 +00:00
|
|
|
nsAutoString flags;
|
|
|
|
aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::flags, flags);
|
2002-03-19 06:46:56 +00:00
|
|
|
if (flags.Find(NS_LITERAL_STRING("dont-build-content")) >= 0) {
|
2002-01-03 22:58:23 +00:00
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> builder =
|
2002-03-29 02:46:01 +00:00
|
|
|
do_CreateInstance("@mozilla.org/xul/xul-tree-builder;1");
|
2002-01-03 22:58:23 +00:00
|
|
|
|
|
|
|
if (! builder)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2002-01-24 21:30:22 +00:00
|
|
|
builder->Init(aElement);
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
// Because the tree box object won't be created until the
|
2002-01-03 22:58:23 +00:00
|
|
|
// frame is available, we need to tuck the template builder
|
|
|
|
// away in the binding manager so there's at least one
|
|
|
|
// reference to it.
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
|
|
|
|
if (xuldoc)
|
|
|
|
xuldoc->SetTemplateBuilderFor(aElement, builder);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
// Force an <treechildren> to be created if one isn't
|
2002-01-24 21:30:22 +00:00
|
|
|
// there already: this is the only way to create an
|
2002-03-29 02:46:01 +00:00
|
|
|
// <treebody> for the rdfliner.
|
2002-01-16 03:01:28 +00:00
|
|
|
nsCOMPtr<nsIContent> bodyContent;
|
2002-01-24 21:30:22 +00:00
|
|
|
nsXULContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL,
|
2002-03-29 02:46:01 +00:00
|
|
|
nsXULAtoms::treechildren,
|
2002-01-24 21:30:22 +00:00
|
|
|
getter_AddRefs(bodyContent));
|
|
|
|
|
|
|
|
if (! bodyContent) {
|
2002-01-16 03:01:28 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc = do_QueryInterface(doc);
|
|
|
|
if (domdoc) {
|
|
|
|
nsCOMPtr<nsIDOMElement> bodyElement;
|
2002-03-29 02:46:01 +00:00
|
|
|
domdoc->CreateElement(NS_LITERAL_STRING("treechildren"),
|
2002-01-16 03:01:28 +00:00
|
|
|
getter_AddRefs(bodyElement));
|
2002-01-24 21:30:22 +00:00
|
|
|
|
2002-01-16 03:01:28 +00:00
|
|
|
bodyContent = do_QueryInterface(bodyElement);
|
|
|
|
aElement->AppendChildTo(bodyContent, PR_FALSE, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-03 22:58:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-17 21:05:52 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2002-01-24 21:30:22 +00:00
|
|
|
// Create and initialize a content builder.
|
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> builder
|
2002-01-03 22:58:23 +00:00
|
|
|
= do_CreateInstance("@mozilla.org/xul/xul-template-builder;1");
|
2000-02-17 21:05:52 +00:00
|
|
|
|
2002-01-03 22:58:23 +00:00
|
|
|
if (! builder)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-17 21:05:52 +00:00
|
|
|
|
2002-01-24 21:30:22 +00:00
|
|
|
builder->Init(aElement);
|
2002-01-03 22:58:23 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIXULContent> xulcontent = do_QueryInterface(aElement);
|
|
|
|
if (xulcontent) {
|
|
|
|
// Mark the XUL element as being lazy, so the template builder
|
|
|
|
// will run when layout first asks for these nodes.
|
|
|
|
xulcontent->SetLazyState(nsIXULContent::eChildrenMustBeRebuilt);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Force construction of immediate template sub-content _now_.
|
|
|
|
builder->CreateContents(aElement);
|
1999-11-02 01:14:07 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-02 01:14:07 +00:00
|
|
|
nsresult
|
|
|
|
nsXULDocument::AddPrototypeSheets()
|
|
|
|
{
|
|
|
|
// Add mCurrentPrototype's style sheets to the document.
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsArray> sheets;
|
|
|
|
rv = mCurrentPrototype->GetStyleSheetReferences(getter_AddRefs(sheets));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PRUint32 count;
|
|
|
|
sheets->Count(&count);
|
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
1999-11-02 02:02:27 +00:00
|
|
|
nsISupports* isupports = sheets->ElementAt(i);
|
1999-11-02 01:14:07 +00:00
|
|
|
nsCOMPtr<nsIURI> uri = do_QueryInterface(isupports);
|
1999-11-18 02:25:33 +00:00
|
|
|
NS_IF_RELEASE(isupports);
|
1999-11-02 02:02:27 +00:00
|
|
|
|
2002-12-11 03:33:40 +00:00
|
|
|
NS_ASSERTION(uri, "not a URI!!!");
|
1999-11-02 01:14:07 +00:00
|
|
|
if (! uri)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2002-12-11 03:33:40 +00:00
|
|
|
if (!IsChromeURI(uri)) {
|
|
|
|
// These don't get to be in the prototype cache anyway...
|
|
|
|
// and we can't load non-chrome sheets synchronously
|
|
|
|
continue;
|
|
|
|
}
|
1999-11-02 01:14:07 +00:00
|
|
|
|
2002-12-11 03:33:40 +00:00
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
1999-11-02 01:14:07 +00:00
|
|
|
|
2002-12-11 03:33:40 +00:00
|
|
|
// If the sheet is a chrome URL, then we can refetch the sheet
|
|
|
|
// synchronously, since we know the sheet is local. It's not
|
|
|
|
// too late! :) If we're lucky, the loader will just pull it
|
|
|
|
// from the prototype cache anyway.
|
|
|
|
// Otherwise we just bail. It shouldn't currently
|
|
|
|
// be possible to get into this situation for any reason
|
|
|
|
// other than a skin switch anyway (since skin switching is the
|
|
|
|
// only system that partially invalidates the XUL cache).
|
|
|
|
// - dwh
|
|
|
|
//XXXbz we hit this code from fastload all the time. Bug 183505.
|
|
|
|
nsCOMPtr<nsICSSLoader> loader;
|
|
|
|
rv = GetCSSLoader(*getter_AddRefs(loader));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = loader->LoadAgentSheet(uri, getter_AddRefs(sheet));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-11-02 01:14:07 +00:00
|
|
|
|
2002-12-11 03:33:40 +00:00
|
|
|
AddStyleSheet(sheet, 0);
|
1999-11-02 01:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULDocument::OverlayForwardReference
|
|
|
|
//
|
|
|
|
|
|
|
|
nsForwardReference::Result
|
|
|
|
nsXULDocument::OverlayForwardReference::Resolve()
|
|
|
|
{
|
|
|
|
// Resolve a forward reference from an overlay element; attempt to
|
|
|
|
// hook it up into the main document.
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoString id;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = mOverlay->GetAttr(kNameSpaceID_None, nsXULAtoms::id, id);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return eResolve_Error;
|
|
|
|
|
2002-02-18 05:39:48 +00:00
|
|
|
if (id.IsEmpty()) {
|
|
|
|
// overlay had no id, use the root element
|
|
|
|
mDocument->InsertElement(mDocument->mRootContent, mOverlay);
|
|
|
|
mResolved = PR_TRUE;
|
|
|
|
return eResolve_Succeeded;
|
|
|
|
}
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> domtarget;
|
1999-11-08 19:07:13 +00:00
|
|
|
rv = mDocument->GetElementById(id, getter_AddRefs(domtarget));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return eResolve_Error;
|
|
|
|
|
|
|
|
// If we can't find the element in the document, defer the hookup
|
|
|
|
// until later.
|
|
|
|
if (! domtarget)
|
|
|
|
return eResolve_Later;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> target = do_QueryInterface(domtarget);
|
|
|
|
NS_ASSERTION(target != nsnull, "not an nsIContent");
|
|
|
|
if (! target)
|
|
|
|
return eResolve_Error;
|
|
|
|
|
|
|
|
rv = Merge(target, mOverlay);
|
|
|
|
if (NS_FAILED(rv)) return eResolve_Error;
|
2001-02-20 01:05:34 +00:00
|
|
|
|
|
|
|
// Add child and any descendants to the element map
|
|
|
|
rv = mDocument->AddSubtreeToDocument(target);
|
|
|
|
if (NS_FAILED(rv)) return eResolve_Error;
|
|
|
|
|
2002-09-25 09:56:09 +00:00
|
|
|
#ifdef PR_LOGGING
|
2000-04-26 01:13:55 +00:00
|
|
|
nsCAutoString idC;
|
|
|
|
idC.AssignWithConversion(id);
|
1999-10-29 01:21:15 +00:00
|
|
|
PR_LOG(gXULLog, PR_LOG_ALWAYS,
|
|
|
|
("xul: overlay resolved '%s'",
|
2001-10-27 06:44:19 +00:00
|
|
|
idC.get()));
|
2002-09-25 09:56:09 +00:00
|
|
|
#endif
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
mResolved = PR_TRUE;
|
|
|
|
return eResolve_Succeeded;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::OverlayForwardReference::Merge(nsIContent* aTargetNode,
|
|
|
|
nsIContent* aOverlayNode)
|
|
|
|
{
|
2001-01-10 01:08:23 +00:00
|
|
|
// This function is given:
|
2001-07-31 19:05:34 +00:00
|
|
|
// aTargetNode: the node in the document whose 'id' attribute
|
|
|
|
// matches a toplevel node in our overlay.
|
2001-01-10 01:08:23 +00:00
|
|
|
// aOverlayNode: the node in the overlay document that matches
|
|
|
|
// a node in the actual document.
|
2001-07-31 19:05:34 +00:00
|
|
|
//
|
2001-01-10 01:08:23 +00:00
|
|
|
// This function merges the tree from the overlay into the tree in
|
|
|
|
// the document, overwriting attributes and appending child content
|
|
|
|
// nodes appropriately. (See XUL overlay reference for details)
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
// Merge attributes from the overlay content node to that of the
|
|
|
|
// actual document.
|
|
|
|
PRInt32 attrCount, i;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aOverlayNode->GetAttrCount(attrCount);
|
2001-01-10 01:08:23 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
for (i = 0; i < attrCount; ++i) {
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsCOMPtr<nsIAtom> attr, prefix;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aOverlayNode->GetAttrNameAt(i, nameSpaceID, *getter_AddRefs(attr), *getter_AddRefs(prefix));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
// We don't want to swap IDs, they should be the same.
|
2001-03-23 10:56:18 +00:00
|
|
|
if (nameSpaceID == kNameSpaceID_None && attr.get() == nsXULAtoms::id)
|
2001-01-10 01:08:23 +00:00
|
|
|
continue;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aOverlayNode->GetAttr(nameSpaceID, attr, value);
|
2001-01-10 01:08:23 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
nsAutoString tempID;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aOverlayNode->GetAttr(kNameSpaceID_None, nsXULAtoms::id, tempID);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
// Element in the overlay has the 'removeelement' attribute set
|
|
|
|
// so remove it from the actual document.
|
2001-03-23 10:56:18 +00:00
|
|
|
if (attr.get() == nsXULAtoms::removeelement &&
|
2001-01-10 01:08:23 +00:00
|
|
|
value.EqualsIgnoreCase("true")) {
|
|
|
|
nsCOMPtr<nsIContent> parent;
|
|
|
|
rv = aTargetNode->GetParent(*getter_AddRefs(parent));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
rv = RemoveElement(parent, aTargetNode);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> ni;
|
|
|
|
aTargetNode->GetNodeInfo(*getter_AddRefs(ni));
|
2000-05-17 04:53:16 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
if (ni) {
|
|
|
|
nsCOMPtr<nsINodeInfoManager> nimgr;
|
|
|
|
ni->GetNodeInfoManager(*getter_AddRefs(nimgr));
|
2000-05-17 04:53:16 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
nimgr->GetNodeInfo(attr, prefix, nameSpaceID,
|
|
|
|
*getter_AddRefs(ni));
|
|
|
|
}
|
2000-05-17 04:53:16 +00:00
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aTargetNode->SetAttr(ni, value, PR_FALSE);
|
2001-01-10 01:08:23 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
// Walk our child nodes, looking for elements that have the 'id'
|
|
|
|
// attribute set. If we find any, we must do a parent check in the
|
2001-07-31 19:05:34 +00:00
|
|
|
// actual document to ensure that the structure matches that of
|
2001-01-10 01:08:23 +00:00
|
|
|
// the actual document. If it does, we can call ourselves and attempt
|
|
|
|
// to merge inside that subtree. If not, we just append the tree to
|
|
|
|
// the parent like any other.
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
PRInt32 childCount;
|
|
|
|
rv = aOverlayNode->ChildCount(childCount);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
for (i = 0; i < childCount; i++) {
|
|
|
|
nsCOMPtr<nsIContent> currContent;
|
|
|
|
rv = aOverlayNode->ChildAt(0, *getter_AddRefs(currContent));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
nsAutoString id;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = currContent->GetAttr(kNameSpaceID_None, nsXULAtoms::id, id);
|
2001-01-10 01:08:23 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> nodeInDocument;
|
|
|
|
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
rv = aTargetNode->GetDocument(*getter_AddRefs(document));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDocument(do_QueryInterface(document));
|
|
|
|
if (!domDocument) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = domDocument->GetElementById(id, getter_AddRefs(nodeInDocument));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// The item has an 'id' attribute set, and we need to check with
|
|
|
|
// the actual document to see if an item with this id exists at
|
|
|
|
// this locale. If so, we want to merge the subtree under that
|
2001-01-10 01:08:23 +00:00
|
|
|
// node. Otherwise, we just do an append as if the element had
|
|
|
|
// no id attribute.
|
|
|
|
if (nodeInDocument) {
|
|
|
|
// Given two parents, aTargetNode and aOverlayNode, we want
|
2001-07-31 19:05:34 +00:00
|
|
|
// to call merge on currContent if we find an associated
|
2001-01-10 01:08:23 +00:00
|
|
|
// node in the document with the same id as currContent that
|
|
|
|
// also has aTargetNode as its parent.
|
|
|
|
|
|
|
|
nsAutoString documentParentID;
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aTargetNode->GetAttr(kNameSpaceID_None, nsXULAtoms::id,
|
|
|
|
documentParentID);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> nodeParent;
|
|
|
|
rv = nodeInDocument->GetParentNode(getter_AddRefs(nodeParent));
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-01-10 01:08:23 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> elementParent(do_QueryInterface(nodeParent));
|
|
|
|
|
|
|
|
nsAutoString parentID;
|
|
|
|
elementParent->GetAttribute(NS_LITERAL_STRING("id"), parentID);
|
|
|
|
if (parentID.Equals(documentParentID)) {
|
|
|
|
// The element matches. "Go Deep!"
|
|
|
|
nsCOMPtr<nsIContent> childDocumentContent(do_QueryInterface(nodeInDocument));
|
|
|
|
rv = Merge(childDocumentContent, currContent);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = aOverlayNode->RemoveChildAt(0, PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
2001-01-10 01:08:23 +00:00
|
|
|
|
|
|
|
rv = aOverlayNode->RemoveChildAt(0, PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = InsertElement(aTargetNode, currContent);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 19:05:34 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsXULDocument::OverlayForwardReference::~OverlayForwardReference()
|
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gXULLog, PR_LOG_ALWAYS) && !mResolved) {
|
|
|
|
nsAutoString id;
|
2001-08-17 08:14:14 +00:00
|
|
|
mOverlay->GetAttr(kNameSpaceID_None, nsXULAtoms::id, id);
|
1999-11-18 02:25:33 +00:00
|
|
|
|
2000-04-26 01:13:55 +00:00
|
|
|
nsCAutoString idC;
|
|
|
|
idC.AssignWithConversion(id);
|
1999-10-29 01:21:15 +00:00
|
|
|
PR_LOG(gXULLog, PR_LOG_ALWAYS,
|
|
|
|
("xul: overlay failed to resolve '%s'",
|
2001-10-27 06:44:19 +00:00
|
|
|
idC.get()));
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULDocument::BroadcasterHookup
|
|
|
|
//
|
|
|
|
|
|
|
|
nsForwardReference::Result
|
|
|
|
nsXULDocument::BroadcasterHookup::Resolve()
|
1999-11-08 19:07:13 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-11-17 02:45:46 +00:00
|
|
|
|
|
|
|
PRBool listener;
|
|
|
|
rv = CheckBroadcasterHookup(mDocument, mObservesElement, &listener, &mResolved);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return eResolve_Error;
|
|
|
|
|
|
|
|
return mResolved ? eResolve_Succeeded : eResolve_Later;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsXULDocument::BroadcasterHookup::~BroadcasterHookup()
|
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gXULLog, PR_LOG_ALWAYS) && !mResolved) {
|
|
|
|
// Tell the world we failed
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
rv = mObservesElement->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
nsAutoString broadcasterID;
|
|
|
|
nsAutoString attribute;
|
|
|
|
|
2001-03-23 10:56:18 +00:00
|
|
|
if (tag.get() == nsXULAtoms::observes) {
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = mObservesElement->GetAttr(kNameSpaceID_None, nsXULAtoms::element, broadcasterID);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = mObservesElement->GetAttr(kNameSpaceID_None, nsXULAtoms::attribute, attribute);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
}
|
|
|
|
else {
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = mObservesElement->GetAttr(kNameSpaceID_None, nsXULAtoms::observes, broadcasterID);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
attribute.Assign(NS_LITERAL_STRING("*"));
|
1999-11-08 19:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString tagStr;
|
|
|
|
rv = tag->ToString(tagStr);
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
2000-04-26 01:13:55 +00:00
|
|
|
nsCAutoString tagstrC, attributeC,broadcasteridC;
|
|
|
|
tagstrC.AssignWithConversion(tagStr);
|
|
|
|
attributeC.AssignWithConversion(attribute);
|
|
|
|
broadcasteridC.AssignWithConversion(broadcasterID);
|
1999-11-08 19:07:13 +00:00
|
|
|
PR_LOG(gXULLog, PR_LOG_ALWAYS,
|
|
|
|
("xul: broadcaster hookup failed <%s attribute='%s'> to %s",
|
2001-10-27 06:44:19 +00:00
|
|
|
tagstrC.get(),
|
|
|
|
attributeC.get(),
|
|
|
|
broadcasteridC.get()));
|
1999-11-08 19:07:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::CheckBroadcasterHookup(nsXULDocument* aDocument,
|
|
|
|
nsIContent* aElement,
|
1999-11-17 02:45:46 +00:00
|
|
|
PRBool* aNeedsHookup,
|
1999-11-08 19:07:13 +00:00
|
|
|
PRBool* aDidResolve)
|
1999-10-29 01:21:15 +00:00
|
|
|
{
|
|
|
|
// Resolve a broadcaster hookup. Look at the element that we're
|
|
|
|
// trying to resolve: it could be an '<observes>' element, or just
|
|
|
|
// a vanilla element with an 'observes' attribute on it.
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-11-08 19:07:13 +00:00
|
|
|
*aDidResolve = PR_FALSE;
|
|
|
|
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
rv = aElement->GetNameSpaceID(nameSpaceID);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
1999-11-08 19:07:13 +00:00
|
|
|
rv = aElement->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> listener;
|
|
|
|
nsAutoString broadcasterID;
|
|
|
|
nsAutoString attribute;
|
|
|
|
|
2001-03-23 10:56:18 +00:00
|
|
|
if ((nameSpaceID == kNameSpaceID_XUL) && (tag.get() == nsXULAtoms::observes)) {
|
1999-10-29 01:21:15 +00:00
|
|
|
// It's an <observes> element, which means that the actual
|
|
|
|
// listener is the _parent_ node. This element should have an
|
|
|
|
// 'element' attribute that specifies the ID of the
|
|
|
|
// broadcaster element, and an 'attribute' element, which
|
|
|
|
// specifies the name of the attribute to observe.
|
|
|
|
nsCOMPtr<nsIContent> parent;
|
1999-11-08 19:07:13 +00:00
|
|
|
rv = aElement->GetParent(*getter_AddRefs(parent));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> parentTag;
|
|
|
|
rv = parent->GetTag(*getter_AddRefs(parentTag));
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
// If we're still parented by an 'overlay' tag, then we haven't
|
|
|
|
// made it into the real document yet. Defer hookup.
|
2001-03-23 10:56:18 +00:00
|
|
|
if (parentTag.get() == nsXULAtoms::overlay) {
|
1999-11-17 02:45:46 +00:00
|
|
|
*aNeedsHookup = PR_TRUE;
|
1999-11-08 19:07:13 +00:00
|
|
|
return NS_OK;
|
1999-11-17 02:45:46 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
listener = do_QueryInterface(parent);
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::element, broadcasterID);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::attribute, attribute);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// It's a generic element, which means that we'll use the
|
|
|
|
// value of the 'observes' attribute to determine the ID of
|
|
|
|
// the broadcaster element, and we'll watch _all_ of its
|
|
|
|
// values.
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::observes, broadcasterID);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Bail if there's no broadcasterID
|
2002-01-24 02:03:19 +00:00
|
|
|
if ((rv != NS_CONTENT_ATTR_HAS_VALUE) || (broadcasterID.IsEmpty())) {
|
2001-03-21 08:15:12 +00:00
|
|
|
// Try the command attribute next.
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aElement->GetAttr(kNameSpaceID_None, nsXULAtoms::command, broadcasterID);
|
2001-03-21 08:15:12 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-01-24 02:03:19 +00:00
|
|
|
if (rv == NS_CONTENT_ATTR_HAS_VALUE && !broadcasterID.IsEmpty()) {
|
2001-03-21 08:15:12 +00:00
|
|
|
// We've got something in the command attribute. We only treat this as
|
|
|
|
// a normal broadcaster if we are not a menuitem or a key.
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-03-21 08:15:12 +00:00
|
|
|
aElement->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag.get() == nsXULAtoms::menuitem || tag.get() == nsXULAtoms::key) {
|
|
|
|
*aNeedsHookup = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aNeedsHookup = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-17 02:45:46 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
1999-11-08 19:07:13 +00:00
|
|
|
listener = do_QueryInterface(aElement);
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
attribute.Assign(NS_LITERAL_STRING("*"));
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
1999-11-04 18:37:58 +00:00
|
|
|
// Make sure we got a valid listener.
|
|
|
|
NS_ASSERTION(listener != nsnull, "no listener");
|
|
|
|
if (! listener)
|
1999-11-08 19:07:13 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-11-04 18:37:58 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
// Try to find the broadcaster element in the document.
|
2001-10-23 02:44:44 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> broadcaster;
|
|
|
|
rv = aDocument->GetElementById(broadcasterID, getter_AddRefs(broadcaster));
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
// If we can't find the broadcaster, then we'll need to defer the
|
|
|
|
// hookup. We may need to resolve some of the other overlays
|
|
|
|
// first.
|
2001-10-23 02:44:44 +00:00
|
|
|
if (! broadcaster) {
|
1999-11-17 02:45:46 +00:00
|
|
|
*aNeedsHookup = PR_TRUE;
|
1999-11-08 19:07:13 +00:00
|
|
|
return NS_OK;
|
1999-11-17 02:45:46 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-10-23 02:44:44 +00:00
|
|
|
rv = aDocument->AddBroadcastListenerFor(broadcaster, listener, attribute);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
// Tell the world we succeeded
|
|
|
|
if (PR_LOG_TEST(gXULLog, PR_LOG_ALWAYS)) {
|
|
|
|
nsCOMPtr<nsIContent> content =
|
|
|
|
do_QueryInterface(listener);
|
|
|
|
|
|
|
|
NS_ASSERTION(content != nsnull, "not an nsIContent");
|
|
|
|
if (! content)
|
1999-11-08 19:07:13 +00:00
|
|
|
return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tag2;
|
|
|
|
rv = content->GetTag(*getter_AddRefs(tag2));
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
|
|
|
nsAutoString tagStr;
|
|
|
|
rv = tag2->ToString(tagStr);
|
1999-11-08 19:07:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2000-04-26 01:13:55 +00:00
|
|
|
nsCAutoString tagstrC, attributeC,broadcasteridC;
|
|
|
|
tagstrC.AssignWithConversion(tagStr);
|
|
|
|
attributeC.AssignWithConversion(attribute);
|
|
|
|
broadcasteridC.AssignWithConversion(broadcasterID);
|
1999-10-29 01:21:15 +00:00
|
|
|
PR_LOG(gXULLog, PR_LOG_ALWAYS,
|
|
|
|
("xul: broadcaster hookup <%s attribute='%s'> to %s",
|
2001-10-27 06:44:19 +00:00
|
|
|
tagstrC.get(),
|
|
|
|
attributeC.get(),
|
|
|
|
broadcasteridC.get()));
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-11-17 02:45:46 +00:00
|
|
|
*aNeedsHookup = PR_FALSE;
|
1999-11-08 19:07:13 +00:00
|
|
|
*aDidResolve = PR_TRUE;
|
|
|
|
return NS_OK;
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULDocument::InsertElement(nsIContent* aParent, nsIContent* aChild)
|
|
|
|
{
|
2001-01-10 01:08:23 +00:00
|
|
|
// Insert aChild appropriately into aParent, accounting for a
|
1999-10-29 01:21:15 +00:00
|
|
|
// 'pos' attribute set on aChild.
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoString posStr;
|
|
|
|
PRBool wasInserted = PR_FALSE;
|
|
|
|
|
2000-06-20 05:43:52 +00:00
|
|
|
// insert after an element of a given id
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aChild->GetAttr(kNameSpaceID_None, nsXULAtoms::insertafter, posStr);
|
2000-06-20 05:43:52 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
PRBool isInsertAfter = PR_TRUE;
|
|
|
|
|
|
|
|
if (rv != NS_CONTENT_ATTR_HAS_VALUE) {
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aChild->GetAttr(kNameSpaceID_None, nsXULAtoms::insertbefore, posStr);
|
2000-06-20 05:43:52 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
isInsertAfter = PR_FALSE;
|
|
|
|
}
|
2001-07-31 19:05:34 +00:00
|
|
|
|
1999-10-29 01:21:15 +00:00
|
|
|
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
2000-06-20 05:43:52 +00:00
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
rv = aParent->GetDocument(*getter_AddRefs(document));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDocument(do_QueryInterface(document));
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
|
|
|
|
2001-09-29 08:28:41 +00:00
|
|
|
char* str = ToNewCString(posStr);
|
2001-03-23 10:56:18 +00:00
|
|
|
char* rest;
|
|
|
|
char* token = nsCRT::strtok(str, ", ", &rest);
|
2000-06-20 05:43:52 +00:00
|
|
|
|
|
|
|
while (token) {
|
|
|
|
rv = xulDocument->GetElementById(NS_ConvertASCIItoUCS2(token), getter_AddRefs(domElement));
|
|
|
|
if (domElement) break;
|
1999-10-29 01:21:15 +00:00
|
|
|
|
2001-03-23 10:56:18 +00:00
|
|
|
token = nsCRT::strtok(rest, ", ", &rest);
|
2000-06-20 05:43:52 +00:00
|
|
|
}
|
|
|
|
nsMemory::Free(str);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (domElement) {
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(domElement));
|
|
|
|
NS_ASSERTION(content != nsnull, "null ptr");
|
|
|
|
if (!content)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
PRInt32 pos;
|
|
|
|
aParent->IndexOf(content, pos);
|
|
|
|
|
|
|
|
if (pos != -1) {
|
|
|
|
pos = isInsertAfter ? pos + 1 : pos;
|
2001-04-02 00:45:52 +00:00
|
|
|
rv = aParent->InsertChildAt(aChild, pos, PR_FALSE, PR_TRUE);
|
2000-06-20 05:43:52 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
wasInserted = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wasInserted) {
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
rv = aChild->GetAttr(kNameSpaceID_None, nsXULAtoms::position, posStr);
|
2000-06-20 05:43:52 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
|
|
|
|
// Positions are one-indexed.
|
|
|
|
PRInt32 pos = posStr.ToInteger(NS_REINTERPRET_CAST(PRInt32*, &rv));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-04-02 00:45:52 +00:00
|
|
|
rv = aParent->InsertChildAt(aChild, pos - 1, PR_FALSE, PR_TRUE);
|
2001-11-27 00:34:33 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
wasInserted = PR_TRUE;
|
|
|
|
// If the insertion fails, then we should still attempt an append.
|
|
|
|
// Thus, rather than returning rv immediately, we fall through
|
|
|
|
// to the final "catch-all" case that just does an AppendChildTo.
|
2000-06-20 05:43:52 +00:00
|
|
|
}
|
1999-10-29 01:21:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! wasInserted) {
|
2001-04-02 00:45:52 +00:00
|
|
|
rv = aParent->AppendChildTo(aChild, PR_FALSE, PR_TRUE);
|
1999-10-29 01:21:15 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-01-10 01:08:23 +00:00
|
|
|
nsresult
|
|
|
|
nsXULDocument::RemoveElement(nsIContent* aParent, nsIContent* aChild)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
PRInt32 nodeOffset;
|
|
|
|
rv = aParent->IndexOf(aChild, nodeOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-01-14 21:41:19 +00:00
|
|
|
rv = aParent->RemoveChildAt(nodeOffset, PR_TRUE);
|
2001-01-10 01:08:23 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:20:54 +00:00
|
|
|
void
|
|
|
|
nsXULDocument::GetElementFactory(PRInt32 aNameSpaceID,
|
|
|
|
nsIElementFactory** aResult)
|
2000-01-19 03:11:39 +00:00
|
|
|
{
|
2001-09-05 04:20:54 +00:00
|
|
|
// Retrieve the appropriate factory.
|
2002-11-29 23:44:07 +00:00
|
|
|
nsContentUtils::GetNSManagerWeakRef()->GetElementFactory(aNameSpaceID,
|
|
|
|
aResult);
|
2000-01-19 03:11:39 +00:00
|
|
|
|
2001-09-05 04:20:54 +00:00
|
|
|
if (!*aResult) {
|
|
|
|
// Nothing found. Use generic XML element.
|
|
|
|
*aResult = gXMLElementFactory;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
}
|
2000-01-19 03:11:39 +00:00
|
|
|
}
|
|
|
|
|
2000-12-10 09:18:57 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
if (!mBoxObjectTable)
|
|
|
|
mBoxObjectTable = new nsSupportsHashtable;
|
|
|
|
else {
|
|
|
|
nsISupportsKey key(aElement);
|
2001-07-31 19:05:34 +00:00
|
|
|
nsCOMPtr<nsISupports> supports =
|
|
|
|
getter_AddRefs(NS_STATIC_CAST(nsISupports*, mBoxObjectTable->Get(&key)));
|
2000-12-10 09:18:57 +00:00
|
|
|
nsCOMPtr<nsIBoxObject> boxObject(do_QueryInterface(supports));
|
|
|
|
if (boxObject) {
|
|
|
|
*aResult = boxObject;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
GetShellAt(0, getter_AddRefs(shell));
|
2000-12-10 09:18:57 +00:00
|
|
|
if (!shell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRInt32 namespaceID;
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-21 20:51:34 +00:00
|
|
|
nsCOMPtr<nsIXBLService> xblService =
|
2001-07-25 07:54:28 +00:00
|
|
|
do_GetService("@mozilla.org/xbl;1", &rv);
|
2000-12-10 09:18:57 +00:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aElement));
|
|
|
|
xblService->ResolveTag(content, &namespaceID, getter_AddRefs(tag));
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2000-12-10 09:18:57 +00:00
|
|
|
nsCAutoString contractID("@mozilla.org/layout/xul-boxobject");
|
|
|
|
if (namespaceID == kNameSpaceID_XUL) {
|
|
|
|
if (tag.get() == nsXULAtoms::browser)
|
|
|
|
contractID += "-browser";
|
|
|
|
else if (tag.get() == nsXULAtoms::editor)
|
|
|
|
contractID += "-editor";
|
|
|
|
else if (tag.get() == nsXULAtoms::iframe)
|
|
|
|
contractID += "-iframe";
|
|
|
|
else if (tag.get() == nsXULAtoms::menu)
|
|
|
|
contractID += "-menu";
|
2001-08-18 01:04:47 +00:00
|
|
|
else if (tag.get() == nsXULAtoms::popup || tag.get() == nsXULAtoms::menupopup ||
|
|
|
|
tag.get() == nsXULAtoms::tooltip)
|
|
|
|
contractID += "-popup";
|
2000-12-10 09:18:57 +00:00
|
|
|
else if (tag.get() == nsXULAtoms::tree)
|
|
|
|
contractID += "-tree";
|
2002-01-12 01:18:10 +00:00
|
|
|
else if (tag.get() == nsXULAtoms::listbox)
|
|
|
|
contractID += "-listbox";
|
2000-12-10 09:18:57 +00:00
|
|
|
else if (tag.get() == nsXULAtoms::scrollbox)
|
|
|
|
contractID += "-scrollbox";
|
2002-03-29 02:46:01 +00:00
|
|
|
else if (tag.get() == nsXULAtoms::tree)
|
|
|
|
contractID += "-tree";
|
2000-12-10 09:18:57 +00:00
|
|
|
}
|
|
|
|
contractID += ";1";
|
|
|
|
|
2001-10-27 06:44:19 +00:00
|
|
|
nsCOMPtr<nsIBoxObject> boxObject(do_CreateInstance(contractID.get()));
|
2001-07-31 19:05:34 +00:00
|
|
|
if (!boxObject)
|
2000-12-10 09:18:57 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIBoxObject> privateBox(do_QueryInterface(boxObject));
|
|
|
|
if (NS_FAILED(rv = privateBox->Init(content, shell)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
SetBoxObjectFor(aElement, boxObject);
|
|
|
|
|
|
|
|
*aResult = boxObject;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject* aBoxObject)
|
|
|
|
{
|
|
|
|
if (!mBoxObjectTable) {
|
2001-07-31 19:05:34 +00:00
|
|
|
if (!aBoxObject)
|
2000-12-10 09:18:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
mBoxObjectTable = new nsSupportsHashtable;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupportsKey key(aElement);
|
|
|
|
|
|
|
|
if (aBoxObject)
|
|
|
|
mBoxObjectTable->Put(&key, aBoxObject);
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsISupports> supp;
|
|
|
|
mBoxObjectTable->Remove(&key, getter_AddRefs(supp));
|
|
|
|
nsCOMPtr<nsPIBoxObject> boxObject(do_QueryInterface(supp));
|
|
|
|
if (boxObject)
|
|
|
|
boxObject->SetDocument(nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:46:09 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
1999-12-04 07:45:57 +00:00
|
|
|
// CachedChromeStreamListener
|
1999-11-24 22:46:09 +00:00
|
|
|
//
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
nsXULDocument::CachedChromeStreamListener::CachedChromeStreamListener(nsXULDocument* aDocument, PRBool aProtoLoaded)
|
|
|
|
: mDocument(aDocument),
|
|
|
|
mProtoLoaded(aProtoLoaded)
|
1999-11-24 22:46:09 +00:00
|
|
|
{
|
1999-12-04 07:45:57 +00:00
|
|
|
NS_ADDREF(mDocument);
|
1999-11-24 22:46:09 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
|
|
|
|
nsXULDocument::CachedChromeStreamListener::~CachedChromeStreamListener()
|
1999-11-24 22:46:09 +00:00
|
|
|
{
|
|
|
|
NS_RELEASE(mDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-10 06:01:08 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(nsXULDocument::CachedChromeStreamListener, nsIRequestObserver, nsIStreamListener);
|
1999-11-24 22:46:09 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-22 03:01:34 +00:00
|
|
|
nsXULDocument::CachedChromeStreamListener::OnStartRequest(nsIRequest *request, nsISupports* acontext)
|
1999-11-24 22:46:09 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-22 03:01:34 +00:00
|
|
|
nsXULDocument::CachedChromeStreamListener::OnStopRequest(nsIRequest *request,
|
1999-12-04 07:45:57 +00:00
|
|
|
nsISupports* aContext,
|
2001-04-10 06:01:08 +00:00
|
|
|
nsresult aStatus)
|
1999-11-24 22:46:09 +00:00
|
|
|
{
|
2001-07-31 19:05:34 +00:00
|
|
|
if (! mProtoLoaded)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-11-24 22:46:09 +00:00
|
|
|
nsresult rv;
|
1999-12-04 07:45:57 +00:00
|
|
|
rv = mDocument->PrepareToWalk();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to prepare for walk");
|
1999-11-24 22:46:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
return mDocument->ResumeWalk();
|
|
|
|
}
|
1999-11-24 22:46:09 +00:00
|
|
|
|
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
NS_IMETHODIMP
|
2001-02-22 03:01:34 +00:00
|
|
|
nsXULDocument::CachedChromeStreamListener::OnDataAvailable(nsIRequest *request,
|
1999-12-04 07:45:57 +00:00
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
PRUint32 aSourceOffset,
|
|
|
|
PRUint32 aCount)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("CachedChromeStream doesn't receive data");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-11-24 22:46:09 +00:00
|
|
|
}
|
2000-01-19 03:28:06 +00:00
|
|
|
|
2000-03-07 02:33:44 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ParserObserver
|
|
|
|
//
|
|
|
|
|
|
|
|
nsXULDocument::ParserObserver::ParserObserver(nsXULDocument* aDocument)
|
|
|
|
: mDocument(aDocument)
|
|
|
|
{
|
|
|
|
NS_ADDREF(mDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXULDocument::ParserObserver::~ParserObserver()
|
|
|
|
{
|
2000-03-15 23:58:01 +00:00
|
|
|
NS_IF_RELEASE(mDocument);
|
2000-03-07 02:33:44 +00:00
|
|
|
}
|
|
|
|
|
2001-04-10 06:01:08 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsXULDocument::ParserObserver, nsIRequestObserver);
|
2000-03-07 02:33:44 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-22 03:01:34 +00:00
|
|
|
nsXULDocument::ParserObserver::OnStartRequest(nsIRequest *request,
|
2000-03-07 02:33:44 +00:00
|
|
|
nsISupports* aContext)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-22 03:01:34 +00:00
|
|
|
nsXULDocument::ParserObserver::OnStopRequest(nsIRequest *request,
|
2000-03-07 02:33:44 +00:00
|
|
|
nsISupports* aContext,
|
2001-04-10 06:01:08 +00:00
|
|
|
nsresult aStatus)
|
2000-03-07 02:33:44 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (NS_FAILED(aStatus)) {
|
|
|
|
// If an overlay load fails, we need to nudge the prototype
|
|
|
|
// walk along.
|
|
|
|
#define YELL_IF_MISSING_OVERLAY 1
|
|
|
|
#if defined(DEBUG) || defined(YELL_IF_MISSING_OVERLAY)
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2001-02-22 03:01:34 +00:00
|
|
|
nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
|
|
|
|
if (!aChannel) return NS_ERROR_FAILURE;
|
|
|
|
|
2000-03-07 02:33:44 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
aChannel->GetOriginalURI(getter_AddRefs(uri));
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString spec;
|
|
|
|
uri->GetSpec(spec);
|
2000-03-07 02:33:44 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
printf("*** Failed to load overlay %s\n", spec.get());
|
2000-03-07 02:33:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
rv = mDocument->ResumeWalk();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drop the reference to the document to break cycle between the
|
|
|
|
// document, the parser, the content sink, and the parser
|
|
|
|
// observer.
|
|
|
|
NS_RELEASE(mDocument);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
void
|
|
|
|
nsXULDocument::GetFocusController(nsIFocusController** aFocusController)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryReferent(mDocumentContainer);
|
|
|
|
nsCOMPtr<nsPIDOMWindow> windowPrivate = do_GetInterface(ir);
|
|
|
|
if (windowPrivate) {
|
|
|
|
windowPrivate->GetRootFocusController(aFocusController);
|
|
|
|
} else
|
|
|
|
*aFocusController = nsnull;
|
|
|
|
}
|
|
|
|
|
2001-04-12 23:35:24 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
/**
|
2001-07-31 19:05:34 +00:00
|
|
|
* Retrieve and get bidi state of the document
|
2001-04-12 23:35:24 +00:00
|
|
|
* set depending on presence of bidi data.
|
|
|
|
* (see nsIDocument.h)
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::GetBidiEnabled(PRBool* aBidiEnabled) const
|
|
|
|
{
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aBidiEnabled);
|
|
|
|
*aBidiEnabled = mBidiEnabled;
|
|
|
|
return NS_OK;
|
2001-04-12 23:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULDocument::SetBidiEnabled(PRBool aBidiEnabled)
|
|
|
|
{
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_ASSERTION(aBidiEnabled, "cannot disable bidi once enabled");
|
|
|
|
if (aBidiEnabled) {
|
|
|
|
mBidiEnabled = PR_TRUE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2001-04-12 23:35:24 +00:00
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
2000-05-13 08:13:54 +00:00
|
|
|
|
2000-03-07 02:33:44 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
2000-01-19 03:28:06 +00:00
|
|
|
// The XUL element factory
|
2000-03-07 02:33:44 +00:00
|
|
|
//
|
2000-01-19 03:28:06 +00:00
|
|
|
|
|
|
|
class XULElementFactoryImpl : public nsIElementFactory
|
|
|
|
{
|
|
|
|
protected:
|
2001-07-31 19:05:34 +00:00
|
|
|
XULElementFactoryImpl();
|
|
|
|
virtual ~XULElementFactoryImpl();
|
2000-01-19 03:28:06 +00:00
|
|
|
|
|
|
|
public:
|
2001-07-31 19:05:34 +00:00
|
|
|
friend
|
|
|
|
nsresult
|
|
|
|
NS_NewXULElementFactory(nsIElementFactory** aResult);
|
2000-01-19 03:28:06 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS
|
2000-01-19 03:28:06 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
// nsIElementFactory interface
|
|
|
|
NS_IMETHOD CreateInstanceByTag(nsINodeInfo *aNodeInfo, nsIContent** aResult);
|
2000-01-19 03:28:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
XULElementFactoryImpl::XULElementFactoryImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
XULElementFactoryImpl::~XULElementFactoryImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-17 20:54:21 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(XULElementFactoryImpl, nsIElementFactory)
|
2000-01-19 03:28:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewXULElementFactory(nsIElementFactory** aResult)
|
|
|
|
{
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
|
|
|
if (! aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-01-19 03:28:06 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
XULElementFactoryImpl* result = new XULElementFactoryImpl();
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-01-19 03:28:06 +00:00
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
NS_ADDREF(result);
|
|
|
|
*aResult = result;
|
|
|
|
return NS_OK;
|
2000-01-19 03:28:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-10 13:13:39 +00:00
|
|
|
XULElementFactoryImpl::CreateInstanceByTag(nsINodeInfo *aNodeInfo,
|
|
|
|
nsIContent** aResult)
|
2000-01-19 03:28:06 +00:00
|
|
|
{
|
2001-07-31 19:05:34 +00:00
|
|
|
return nsXULElement::Create(aNodeInfo, aResult);
|
2000-01-19 03:28:06 +00:00
|
|
|
}
|