2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-09-09 18:03:47 +00:00
|
|
|
/* vim: set sw=2 ts=2 et tw=78: */
|
2001-09-25 01:32:19 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
1998-04-13 20:24:54 +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-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-02 22:24:56 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-04-20 08:11:12 +00:00
|
|
|
* Peter Annema <disttsc@bart.nl>
|
2002-04-05 11:29:40 +00:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2007-01-30 21:21:06 +00:00
|
|
|
* Henri Sivonen <hsivonen@iki.fi>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of 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"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2003-10-05 07:29:50 +00:00
|
|
|
|
2012-03-22 06:34:29 +00:00
|
|
|
/**
|
|
|
|
* This file is near-OBSOLETE. It is used for about:blank only and for the
|
|
|
|
* HTML element factory.
|
|
|
|
* Don't bother adding new stuff in this file.
|
|
|
|
*/
|
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
#include "nsContentSink.h"
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-12-17 07:14:49 +00:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIHTMLContentSink.h"
|
2000-06-16 14:54:57 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2006-11-04 05:45:02 +00:00
|
|
|
#include "nsScriptLoader.h"
|
2004-01-09 23:54:21 +00:00
|
|
|
#include "nsIURI.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1999-05-13 20:27:47 +00:00
|
|
|
#include "nsIContentViewer.h"
|
1999-11-19 07:35:27 +00:00
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
2000-05-10 13:13:39 +00:00
|
|
|
#include "nsINodeInfo.h"
|
2002-09-18 23:31:08 +00:00
|
|
|
#include "nsHTMLTokens.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsIAppShell.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "prlog.h"
|
2006-07-02 07:23:10 +00:00
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
#include "nsIContent.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-05-25 06:32:00 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2001-10-30 10:14:06 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
1998-09-06 00:20:59 +00:00
|
|
|
|
2005-01-12 02:47:53 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
2000-03-28 23:25:26 +00:00
|
|
|
#include "nsIDOMDocumentType.h"
|
2001-05-17 05:54:16 +00:00
|
|
|
#include "nsIScriptElement.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1999-09-30 22:07:04 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1998-04-22 22:12:24 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2000-04-14 02:47:28 +00:00
|
|
|
#include "nsIChannel.h"
|
2001-05-11 21:05:08 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2000-03-11 00:34:54 +00:00
|
|
|
#include "nsIDocShell.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
#include "nsIDocument.h"
|
2004-01-28 21:04:33 +00:00
|
|
|
#include "nsStubDocumentObserver.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsIHTMLDocument.h"
|
1998-12-20 01:21:23 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-01-09 00:14:53 +00:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
2000-02-04 22:50:39 +00:00
|
|
|
#include "nsICookieService.h"
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
1999-11-16 05:07:31 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-10-06 21:13:37 +00:00
|
|
|
#include "nsIPrincipal.h"
|
1999-09-11 17:28:36 +00:00
|
|
|
#include "nsTextFragment.h"
|
1999-12-03 09:24:22 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2001-06-20 01:04:24 +00:00
|
|
|
#include "nsIScriptGlobalObjectOwner.h"
|
1999-01-19 16:58:45 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
#include "nsIParserService.h"
|
|
|
|
|
1999-02-23 19:18:12 +00:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
1999-12-04 01:27:46 +00:00
|
|
|
#include "nsITimer.h"
|
1999-11-02 23:44:27 +00:00
|
|
|
#include "nsDOMError.h"
|
2000-05-25 13:29:15 +00:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsIScriptContext.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsStyleLinkElement.h"
|
1999-09-14 14:38:52 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
#include "nsWeakReference.h" // nsHTMLElementFactory supports weak references
|
2001-03-29 02:11:48 +00:00
|
|
|
#include "nsIPrompt.h"
|
2001-04-24 08:43:08 +00:00
|
|
|
#include "nsLayoutCID.h"
|
2002-08-26 20:13:31 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2001-06-21 14:40:55 +00:00
|
|
|
|
|
|
|
#include "nsEscape.h"
|
2002-04-18 22:11:17 +00:00
|
|
|
#include "nsIElementObserver.h"
|
2004-06-25 12:26:02 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2008-04-11 17:29:06 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2002-04-18 22:11:17 +00:00
|
|
|
|
2011-05-25 06:32:00 +00:00
|
|
|
using namespace mozilla;
|
2010-04-30 13:12:05 +00:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#ifdef NS_DEBUG
|
1998-06-30 23:51:53 +00:00
|
|
|
static PRLogModuleInfo* gSinkLogModuleInfo;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-11-19 18:29:35 +00:00
|
|
|
#define SINK_TRACE_NODE(_bit, _msg, _tag, _sp, _obj) \
|
|
|
|
_obj->SinkTraceNode(_bit, _msg, _tag, _sp, this)
|
1998-07-11 03:51:50 +00:00
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
#else
|
2002-11-19 18:29:35 +00:00
|
|
|
#define SINK_TRACE_NODE(_bit, _msg, _tag, _sp, _obj)
|
1998-06-30 23:51:53 +00:00
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
typedef nsGenericHTMLElement*
|
2010-10-25 12:17:38 +00:00
|
|
|
(*contentCreatorCallback)(already_AddRefed<nsINodeInfo>,
|
|
|
|
FromParser aFromParser);
|
2003-09-24 06:16:52 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement*
|
2010-07-23 09:49:57 +00:00
|
|
|
NS_NewHTMLNOTUSEDElement(already_AddRefed<nsINodeInfo> aNodeInfo,
|
2010-10-25 12:17:38 +00:00
|
|
|
FromParser aFromParser)
|
2003-09-24 06:16:52 +00:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("The element ctor should never be called");
|
2004-06-06 02:38:32 +00:00
|
|
|
return nsnull;
|
2003-09-24 06:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define HTML_TAG(_tag, _classname) NS_NewHTML##_classname##Element,
|
2010-07-06 04:24:35 +00:00
|
|
|
#define HTML_HTMLELEMENT_TAG(_tag) NS_NewHTMLElement,
|
2005-06-16 13:10:58 +00:00
|
|
|
#define HTML_OTHER(_tag) NS_NewHTMLNOTUSEDElement,
|
2003-09-24 06:16:52 +00:00
|
|
|
static const contentCreatorCallback sContentCreatorCallbacks[] = {
|
|
|
|
NS_NewHTMLUnknownElement,
|
|
|
|
#include "nsHTMLTagList.h"
|
|
|
|
#undef HTML_TAG
|
2010-07-06 04:24:35 +00:00
|
|
|
#undef HTML_HTMLELEMENT_TAG
|
2003-09-24 06:16:52 +00:00
|
|
|
#undef HTML_OTHER
|
2003-09-24 07:30:16 +00:00
|
|
|
NS_NewHTMLUnknownElement
|
|
|
|
};
|
2003-09-24 06:16:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
class SinkContext;
|
2006-02-08 05:56:13 +00:00
|
|
|
class HTMLContentSink;
|
|
|
|
|
2012-03-22 06:34:29 +00:00
|
|
|
/**
|
|
|
|
* This class is near-OBSOLETE. It is used for about:blank only.
|
|
|
|
* Don't bother adding new stuff in this file.
|
|
|
|
*/
|
2003-10-05 07:29:50 +00:00
|
|
|
class HTMLContentSink : public nsContentSink,
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2002-09-18 23:31:08 +00:00
|
|
|
public nsIDebugDumpContent,
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2007-01-30 21:21:06 +00:00
|
|
|
public nsIHTMLContentSink
|
1999-11-02 06:49:44 +00:00
|
|
|
{
|
1998-04-13 20:24:54 +00:00
|
|
|
public:
|
2003-10-05 07:29:50 +00:00
|
|
|
friend class SinkContext;
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink();
|
1999-02-12 17:45:58 +00:00
|
|
|
virtual ~HTMLContentSink();
|
1998-08-28 16:20:16 +00:00
|
|
|
|
1999-02-26 20:02:06 +00:00
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult Init(nsIDocument* aDoc, nsIURI* aURI, nsISupports* aContainer,
|
2001-03-03 00:39:29 +00:00
|
|
|
nsIChannel* aChannel);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
// nsISupports
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLContentSink, nsContentSink)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
// nsIContentSink
|
2008-10-30 21:31:00 +00:00
|
|
|
NS_IMETHOD WillParse(void);
|
2009-06-23 21:22:16 +00:00
|
|
|
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD DidBuildModel(bool aTerminated);
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHOD WillInterrupt(void);
|
|
|
|
NS_IMETHOD WillResume(void);
|
2012-01-20 11:16:27 +00:00
|
|
|
NS_IMETHOD SetParser(nsParserBase* aParser);
|
2005-08-24 20:56:58 +00:00
|
|
|
virtual void FlushPendingNotifications(mozFlushType aType);
|
2003-06-17 16:40:34 +00:00
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset);
|
2004-11-02 19:52:32 +00:00
|
|
|
virtual nsISupports *GetTarget();
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool IsScriptExecuting();
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
// nsIHTMLContentSink
|
1999-07-26 05:40:25 +00:00
|
|
|
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
2002-11-19 18:29:35 +00:00
|
|
|
NS_IMETHOD CloseContainer(const nsHTMLTag aTag);
|
2006-01-31 22:19:46 +00:00
|
|
|
NS_IMETHOD CloseMalformedContainer(const nsHTMLTag aTag);
|
1999-07-26 05:40:25 +00:00
|
|
|
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
2001-06-21 02:06:23 +00:00
|
|
|
NS_IMETHOD DidProcessTokens(void);
|
|
|
|
NS_IMETHOD WillProcessAToken(void);
|
|
|
|
NS_IMETHOD DidProcessAToken(void);
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHOD BeginContext(PRInt32 aID);
|
|
|
|
NS_IMETHOD EndContext(PRInt32 aID);
|
2005-09-09 18:03:47 +00:00
|
|
|
NS_IMETHOD OpenHead();
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD IsEnabled(PRInt32 aTag, bool* aReturn);
|
2000-09-01 18:17:43 +00:00
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2000-05-26 19:45:49 +00:00
|
|
|
// nsIDebugDumpContent
|
|
|
|
NS_IMETHOD DumpContentModel();
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2000-05-26 19:45:49 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
protected:
|
2003-07-31 14:07:17 +00:00
|
|
|
// If aCheckIfPresent is true, will only set an attribute in cases
|
|
|
|
// when it's not already set.
|
2004-06-25 12:26:02 +00:00
|
|
|
nsresult AddAttributes(const nsIParserNode& aNode, nsIContent* aContent,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aNotify = false,
|
|
|
|
bool aCheckIfPresent = false);
|
2005-01-12 19:45:38 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
2006-02-08 05:56:13 +00:00
|
|
|
CreateContentObject(const nsIParserNode& aNode, nsHTMLTag aNodeType);
|
2001-06-29 04:01:26 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void SinkTraceNode(PRUint32 aBit,
|
|
|
|
const char* aMsg,
|
2002-11-19 18:29:35 +00:00
|
|
|
const nsHTMLTag aTag,
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 aStackPos,
|
1999-09-30 22:07:04 +00:00
|
|
|
void* aThis);
|
|
|
|
#endif
|
|
|
|
|
2010-03-31 11:35:20 +00:00
|
|
|
nsCOMPtr<nsIHTMLDocument> mHTMLDocument;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// The maximum length of a text run
|
|
|
|
PRInt32 mMaxTextRun;
|
2000-01-31 23:39:19 +00:00
|
|
|
|
2010-03-31 11:35:20 +00:00
|
|
|
nsRefPtr<nsGenericHTMLElement> mRoot;
|
|
|
|
nsRefPtr<nsGenericHTMLElement> mBody;
|
|
|
|
nsRefPtr<nsGenericHTMLElement> mHead;
|
2004-09-17 20:11:02 +00:00
|
|
|
|
2009-03-20 08:15:35 +00:00
|
|
|
nsAutoTArray<SinkContext*, 8> mContextStack;
|
1998-08-28 16:20:16 +00:00
|
|
|
SinkContext* mCurrentContext;
|
|
|
|
SinkContext* mHeadContext;
|
1998-07-20 18:52:40 +00:00
|
|
|
|
2006-01-27 01:13:00 +00:00
|
|
|
// Boolean indicating whether we've seen a <head> tag that might have had
|
|
|
|
// attributes once already.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mHaveSeenHead;
|
2006-01-27 01:13:00 +00:00
|
|
|
|
2007-02-02 02:12:48 +00:00
|
|
|
// Boolean indicating whether we've notified insertion of our root content
|
|
|
|
// yet. We want to make sure to only do this once.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mNotifiedRootInsertion;
|
2007-02-02 02:12:48 +00:00
|
|
|
|
|
|
|
PRUint8 mScriptEnabled : 1;
|
|
|
|
PRUint8 mFramesEnabled : 1;
|
2012-01-25 07:50:03 +00:00
|
|
|
PRUint8 unused : 6; // bits available if someone needs one
|
2007-02-02 02:12:48 +00:00
|
|
|
|
2006-10-04 22:02:17 +00:00
|
|
|
nsINodeInfo* mNodeInfoCache[NS_HTML_TAG_MAX + 1];
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
nsresult FlushTags();
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Routines for tags that require special handling
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult CloseHTML();
|
|
|
|
nsresult OpenBody(const nsIParserNode& aNode);
|
|
|
|
nsresult CloseBody();
|
1998-12-15 06:10:59 +00:00
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
nsresult OpenHeadContext();
|
2005-10-21 15:39:06 +00:00
|
|
|
void CloseHeadContext();
|
2003-10-05 07:29:50 +00:00
|
|
|
|
|
|
|
// nsContentSink overrides
|
2007-01-30 21:21:06 +00:00
|
|
|
void UpdateChildCounts();
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
void NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
|
|
|
PRInt32 aIndexInContainer);
|
2007-10-04 05:16:35 +00:00
|
|
|
void NotifyRootInsertion();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsMonolithicContainer(nsHTMLTag aTag);
|
2001-06-21 02:06:23 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void ForceReflow();
|
1999-04-03 19:00:23 +00:00
|
|
|
#endif
|
2001-06-21 02:06:23 +00:00
|
|
|
};
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
class SinkContext
|
|
|
|
{
|
1998-08-28 16:20:16 +00:00
|
|
|
public:
|
|
|
|
SinkContext(HTMLContentSink* aSink);
|
|
|
|
~SinkContext();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsresult Begin(nsHTMLTag aNodeType, nsGenericHTMLElement* aRoot,
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 aNumFlushed, PRInt32 aInsertionPoint);
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult OpenContainer(const nsIParserNode& aNode);
|
2012-01-25 07:48:59 +00:00
|
|
|
nsresult CloseContainer(const nsHTMLTag aTag);
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult AddLeaf(const nsIParserNode& aNode);
|
2008-12-20 00:49:08 +00:00
|
|
|
nsresult AddLeaf(nsIContent* aContent);
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult End();
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult GrowStack();
|
2002-03-23 23:13:20 +00:00
|
|
|
nsresult AddText(const nsAString& aText);
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult FlushText(bool* aDidFlush = nsnull,
|
|
|
|
bool aReleaseLast = false);
|
|
|
|
nsresult FlushTextAndRelease(bool* aDidFlush = nsnull)
|
1999-10-26 14:55:51 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return FlushText(aDidFlush, true);
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2006-11-06 23:50:33 +00:00
|
|
|
nsresult FlushTags();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsCurrentContainer(nsHTMLTag mType);
|
1999-04-13 22:22:51 +00:00
|
|
|
|
2006-06-08 04:38:44 +00:00
|
|
|
void DidAddContent(nsIContent* aContent);
|
1999-10-26 14:55:51 +00:00
|
|
|
void UpdateChildCounts();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2005-09-22 02:33:36 +00:00
|
|
|
private:
|
|
|
|
// Function to check whether we've notified for the current content.
|
|
|
|
// What this actually does is check whether we've notified for all
|
|
|
|
// of the parent's kids.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool HaveNotifiedForCurrentContent() const;
|
2005-09-22 02:33:36 +00:00
|
|
|
|
|
|
|
public:
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink* mSink;
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 mNotifyLevel;
|
2006-07-19 04:36:36 +00:00
|
|
|
nsCOMPtr<nsIContent> mLastTextNode;
|
2000-01-31 23:39:19 +00:00
|
|
|
PRInt32 mLastTextNodeSize;
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
struct Node {
|
|
|
|
nsHTMLTag mType;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* mContent;
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 mNumFlushed;
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 mInsertionPoint;
|
2008-10-12 17:44:23 +00:00
|
|
|
|
|
|
|
nsIContent *Add(nsIContent *child);
|
1998-08-28 16:20:16 +00:00
|
|
|
};
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
Node* mStack;
|
|
|
|
PRInt32 mStackSize;
|
|
|
|
PRInt32 mStackPos;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
PRUnichar* mText;
|
|
|
|
PRInt32 mTextLength;
|
|
|
|
PRInt32 mTextSize;
|
2008-08-19 18:33:57 +00:00
|
|
|
|
|
|
|
private:
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mLastTextCharWasCR;
|
1998-08-28 16:20:16 +00:00
|
|
|
};
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
//----------------------------------------------------------------------
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-09-30 22:07:04 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void
|
|
|
|
HTMLContentSink::SinkTraceNode(PRUint32 aBit,
|
|
|
|
const char* aMsg,
|
2002-11-19 18:29:35 +00:00
|
|
|
const nsHTMLTag aTag,
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 aStackPos,
|
1999-09-30 22:07:04 +00:00
|
|
|
void* aThis)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo, aBit)) {
|
2005-09-11 10:08:43 +00:00
|
|
|
nsIParserService *parserService = nsContentUtils::GetParserService();
|
2005-06-16 13:10:58 +00:00
|
|
|
if (!parserService)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 tag(parserService->HTMLIdToStringTag(aTag));
|
2002-11-19 18:29:35 +00:00
|
|
|
PR_LogPrint("%s: this=%p node='%s' stackPos=%d",
|
2005-06-16 13:10:58 +00:00
|
|
|
aMsg, aThis, tag.get(), aStackPos);
|
1999-09-30 22:07:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::AddAttributes(const nsIParserNode& aNode,
|
2011-09-29 06:19:26 +00:00
|
|
|
nsIContent* aContent, bool aNotify,
|
|
|
|
bool aCheckIfPresent)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-08-28 16:20:16 +00:00
|
|
|
// Add tag attributes to the content attributes
|
2001-11-21 09:10:41 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
2001-11-21 09:10:41 +00:00
|
|
|
|
|
|
|
if (ac == 0) {
|
|
|
|
// No attributes, nothing to do. Do an early return to avoid
|
|
|
|
// constructing the nsAutoString object for nothing.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-06 07:14:40 +00:00
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
2001-03-13 02:27:25 +00:00
|
|
|
|
2003-07-22 14:21:59 +00:00
|
|
|
// The attributes are on the parser node in the order they came in in the
|
|
|
|
// source. What we want to happen if a single attribute is set multiple
|
|
|
|
// times on an element is that the first time should "win". That is, <input
|
|
|
|
// value="foo" value="bar"> should show "foo". So we loop over the
|
|
|
|
// attributes backwards; this ensures that the first attribute in the set
|
|
|
|
// wins. This does mean that we do some extra work in the case when the same
|
|
|
|
// attribute is set multiple times, but we save a HasAttr call in the much
|
2006-01-27 01:13:00 +00:00
|
|
|
// more common case of reasonable HTML. Note that if aCheckIfPresent is set
|
|
|
|
// then we actually want to loop _forwards_ to preserve the "first attribute
|
|
|
|
// wins" behavior. That does mean that when aCheckIfPresent is set the order
|
|
|
|
// of attributes will get "reversed" from the point of view of the
|
|
|
|
// serializer. But aCheckIfPresent is only true for malformed documents with
|
|
|
|
// multiple <html>, <head>, or <body> tags, so we're doing fixup anyway at
|
|
|
|
// that point.
|
|
|
|
|
|
|
|
PRInt32 i, limit, step;
|
|
|
|
if (aCheckIfPresent) {
|
|
|
|
i = 0;
|
|
|
|
limit = ac;
|
|
|
|
step = 1;
|
|
|
|
} else {
|
|
|
|
i = ac - 1;
|
|
|
|
limit = -1;
|
|
|
|
step = -1;
|
|
|
|
}
|
2003-07-22 14:21:59 +00:00
|
|
|
|
2010-03-08 15:45:00 +00:00
|
|
|
nsAutoString key;
|
2006-01-27 01:13:00 +00:00
|
|
|
for (; i != limit; i += step) {
|
2003-07-22 01:31:34 +00:00
|
|
|
// Get lower-cased key
|
2012-03-20 18:02:38 +00:00
|
|
|
nsresult rv = nsContentUtils::ASCIIToLower(aNode.GetKeyAt(i), key);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-09-22 02:09:26 +00:00
|
|
|
|
2010-03-08 15:45:00 +00:00
|
|
|
nsCOMPtr<nsIAtom> keyAtom = do_GetAtom(key);
|
2001-03-13 02:27:25 +00:00
|
|
|
|
2003-07-31 14:07:17 +00:00
|
|
|
if (aCheckIfPresent && aContent->HasAttr(kNameSpaceID_None, keyAtom)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-07-22 14:21:59 +00:00
|
|
|
// Get value and remove mandatory quotes
|
|
|
|
static const char* kWhitespace = "\n\r\t\b";
|
2006-04-17 21:28:47 +00:00
|
|
|
|
|
|
|
// Bug 114997: Don't trim whitespace on <input value="...">:
|
|
|
|
// Using ?: outside the function call would be more efficient, but
|
|
|
|
// we don't trust ?: with references.
|
2003-07-22 14:21:59 +00:00
|
|
|
const nsAString& v =
|
2006-04-17 21:28:47 +00:00
|
|
|
nsContentUtils::TrimCharsInSet(
|
|
|
|
(nodeType == eHTMLTag_input &&
|
2006-12-26 17:47:52 +00:00
|
|
|
keyAtom == nsGkAtoms::value) ?
|
2006-04-17 21:28:47 +00:00
|
|
|
"" : kWhitespace, aNode.GetValueAt(i));
|
2003-07-22 14:21:59 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (nodeType == eHTMLTag_a && keyAtom == nsGkAtoms::name) {
|
2006-02-03 14:18:39 +00:00
|
|
|
NS_ConvertUTF16toUTF8 cname(v);
|
|
|
|
NS_ConvertUTF8toUTF16 uv(nsUnescape(cname.BeginWriting()));
|
2003-07-22 14:21:59 +00:00
|
|
|
|
|
|
|
// Add attribute to content
|
|
|
|
aContent->SetAttr(kNameSpaceID_None, keyAtom, uv, aNotify);
|
|
|
|
} else {
|
|
|
|
// Add attribute to content
|
|
|
|
aContent->SetAttr(kNameSpaceID_None, keyAtom, v, aNotify);
|
1998-09-22 02:09:26 +00:00
|
|
|
}
|
1998-06-26 16:12:51 +00:00
|
|
|
}
|
2001-11-21 09:10:41 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2000-12-10 09:20:40 +00:00
|
|
|
/**
|
|
|
|
* Factory subroutine to create all of the html content objects.
|
|
|
|
*/
|
2005-01-12 19:45:38 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
2000-12-10 09:20:40 +00:00
|
|
|
HTMLContentSink::CreateContentObject(const nsIParserNode& aNode,
|
2006-02-08 05:56:13 +00:00
|
|
|
nsHTMLTag aNodeType)
|
2000-12-10 09:20:40 +00:00
|
|
|
{
|
|
|
|
// Find/create atom for the tag name
|
2001-11-28 06:13:11 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
|
|
|
|
if (aNodeType == eHTMLTag_userdefined) {
|
2010-06-08 23:25:27 +00:00
|
|
|
nsAutoString lower;
|
|
|
|
nsContentUtils::ASCIIToLower(aNode.GetText(), lower);
|
|
|
|
nsCOMPtr<nsIAtom> name = do_GetAtom(lower);
|
2011-06-14 07:56:49 +00:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2006-10-04 22:02:17 +00:00
|
|
|
}
|
|
|
|
else if (mNodeInfoCache[aNodeType]) {
|
|
|
|
nodeInfo = mNodeInfoCache[aNodeType];
|
|
|
|
}
|
|
|
|
else {
|
2005-09-11 10:08:43 +00:00
|
|
|
nsIParserService *parserService = nsContentUtils::GetParserService();
|
2005-06-16 13:10:58 +00:00
|
|
|
if (!parserService)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsIAtom *name = parserService->HTMLIdToAtomTag(aNodeType);
|
|
|
|
NS_ASSERTION(name, "What? Reverse mapping of id to string broken!!!");
|
|
|
|
|
2011-06-14 07:56:49 +00:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2006-10-04 22:02:17 +00:00
|
|
|
NS_IF_ADDREF(mNodeInfoCache[aNodeType] = nodeInfo);
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
2005-06-16 13:10:58 +00:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, nsnull);
|
2002-04-10 22:16:46 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Make the content object
|
2010-10-25 12:17:38 +00:00
|
|
|
return CreateHTMLElement(aNodeType, nodeInfo.forget(), FROM_PARSER_NETWORK);
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-07-23 09:49:57 +00:00
|
|
|
NS_NewHTMLElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
|
2010-10-25 12:17:38 +00:00
|
|
|
FromParser aFromParser)
|
2000-12-10 09:20:40 +00:00
|
|
|
{
|
2004-06-25 12:26:02 +00:00
|
|
|
*aResult = nsnull;
|
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo = aNodeInfo;
|
|
|
|
|
2005-09-11 10:08:43 +00:00
|
|
|
nsIParserService* parserService = nsContentUtils::GetParserService();
|
2002-11-19 13:39:20 +00:00
|
|
|
if (!parserService)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-12-10 09:20:40 +00:00
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
nsIAtom *name = nodeInfo->NameAtom();
|
2001-11-28 06:13:11 +00:00
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
|
2009-06-09 07:41:19 +00:00
|
|
|
"Trying to HTML elements that don't have the XHTML namespace");
|
2006-10-13 22:54:12 +00:00
|
|
|
|
|
|
|
*aResult = CreateHTMLElement(parserService->
|
|
|
|
HTMLCaseSensitiveAtomTagToId(name),
|
2010-07-23 09:49:57 +00:00
|
|
|
nodeInfo.forget(), aFromParser).get();
|
2006-10-13 22:54:12 +00:00
|
|
|
return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2000-12-10 09:20:40 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
2010-07-23 09:49:57 +00:00
|
|
|
CreateHTMLElement(PRUint32 aNodeType, already_AddRefed<nsINodeInfo> aNodeInfo,
|
2010-10-25 12:17:38 +00:00
|
|
|
FromParser aFromParser)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2006-10-16 21:43:08 +00:00
|
|
|
NS_ASSERTION(aNodeType <= NS_HTML_TAG_MAX ||
|
|
|
|
aNodeType == eHTMLTag_userdefined,
|
|
|
|
"aNodeType is out of bounds");
|
2006-10-13 22:54:12 +00:00
|
|
|
|
2004-06-02 00:25:00 +00:00
|
|
|
contentCreatorCallback cb = sContentCreatorCallbacks[aNodeType];
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-06-02 00:25:00 +00:00
|
|
|
NS_ASSERTION(cb != NS_NewHTMLNOTUSEDElement,
|
|
|
|
"Don't know how to construct tag element!");
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* result = cb(aNodeInfo, aFromParser);
|
2006-10-13 22:54:12 +00:00
|
|
|
NS_IF_ADDREF(result);
|
2004-06-06 02:38:32 +00:00
|
|
|
|
|
|
|
return result;
|
1998-09-01 01:37:17 +00:00
|
|
|
}
|
|
|
|
|
1999-05-06 19:26:43 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
SinkContext::SinkContext(HTMLContentSink* aSink)
|
2005-04-07 03:30:50 +00:00
|
|
|
: mSink(aSink),
|
|
|
|
mNotifyLevel(0),
|
|
|
|
mLastTextNodeSize(0),
|
|
|
|
mStack(nsnull),
|
|
|
|
mStackSize(0),
|
|
|
|
mStackPos(0),
|
|
|
|
mText(nsnull),
|
|
|
|
mTextLength(0),
|
2008-08-19 18:33:57 +00:00
|
|
|
mTextSize(0),
|
2011-10-17 14:59:28 +00:00
|
|
|
mLastTextCharWasCR(false)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(SinkContext);
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SinkContext::~SinkContext()
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(SinkContext);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mStack) {
|
1998-08-28 16:20:16 +00:00
|
|
|
for (PRInt32 i = 0; i < mStackPos; i++) {
|
|
|
|
NS_RELEASE(mStack[i].mContent);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
delete [] mStack;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
delete [] mText;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-09-18 23:31:08 +00:00
|
|
|
SinkContext::Begin(nsHTMLTag aNodeType,
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* aRoot,
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 aNumFlushed,
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 aInsertionPoint)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mStackSize < 1) {
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv = GrowStack();
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
1998-08-07 23:08:00 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStack[0].mType = aNodeType;
|
|
|
|
mStack[0].mContent = aRoot;
|
1999-10-26 14:55:51 +00:00
|
|
|
mStack[0].mNumFlushed = aNumFlushed;
|
|
|
|
mStack[0].mInsertionPoint = aInsertionPoint;
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_ADDREF(aRoot);
|
|
|
|
mStackPos = 1;
|
|
|
|
mTextLength = 0;
|
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
1999-04-13 22:22:51 +00:00
|
|
|
SinkContext::IsCurrentContainer(nsHTMLTag aTag)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aTag == mStack[mStackPos - 1].mType) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1999-04-13 22:22:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1999-04-13 22:22:51 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
void
|
2006-06-08 04:38:44 +00:00
|
|
|
SinkContext::DidAddContent(nsIContent* aContent)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2012-01-25 07:48:59 +00:00
|
|
|
if ((mStackPos == 2) && (mSink->mBody == mStack[1].mContent)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
// We just finished adding something to the body
|
1999-10-26 14:55:51 +00:00
|
|
|
mNotifyLevel = 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If we just added content to a node for which
|
2002-09-18 23:31:08 +00:00
|
|
|
// an insertion happen, we need to do an immediate
|
1999-10-26 14:55:51 +00:00
|
|
|
// notification for that insertion.
|
2006-06-08 04:38:44 +00:00
|
|
|
if (0 < mStackPos &&
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint != -1 &&
|
|
|
|
mStack[mStackPos - 1].mNumFlushed <
|
|
|
|
mStack[mStackPos - 1].mContent->GetChildCount()) {
|
2002-09-18 23:31:08 +00:00
|
|
|
nsIContent* parent = mStack[mStackPos - 1].mContent;
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Tracing code
|
2005-09-11 10:08:43 +00:00
|
|
|
nsIParserService *parserService = nsContentUtils::GetParserService();
|
2005-06-16 13:10:58 +00:00
|
|
|
if (parserService) {
|
|
|
|
nsHTMLTag tag = nsHTMLTag(mStack[mStackPos - 1].mType);
|
|
|
|
NS_ConvertUTF16toUTF8 str(parserService->HTMLIdToStringTag(tag));
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
SINK_TRACE(gSinkLogModuleInfo, SINK_TRACE_REFLOW,
|
2005-06-16 13:10:58 +00:00
|
|
|
("SinkContext::DidAddContent: Insertion notification for "
|
|
|
|
"parent=%s at position=%d and stackPos=%d",
|
|
|
|
str.get(), mStack[mStackPos - 1].mInsertionPoint - 1,
|
|
|
|
mStackPos - 1));
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
#endif
|
|
|
|
|
2008-10-12 17:44:23 +00:00
|
|
|
PRInt32 childIndex = mStack[mStackPos - 1].mInsertionPoint - 1;
|
|
|
|
NS_ASSERTION(parent->GetChildAt(childIndex) == aContent,
|
|
|
|
"Flushing the wrong child.");
|
|
|
|
mSink->NotifyInsert(parent, aContent, childIndex);
|
2003-09-27 04:18:26 +00:00
|
|
|
mStack[mStackPos - 1].mNumFlushed = parent->GetChildCount();
|
2006-06-08 04:38:44 +00:00
|
|
|
} else if (mSink->IsTimeToNotify()) {
|
2007-01-30 21:21:06 +00:00
|
|
|
SINK_TRACE(gSinkLogModuleInfo, SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("SinkContext::DidAddContent: Notification as a result of the "
|
|
|
|
"interval expiring; backoff count: %d", mSink->mBackoffCount));
|
2006-11-06 23:50:33 +00:00
|
|
|
FlushTags();
|
1999-12-04 01:27:46 +00:00
|
|
|
}
|
1999-01-12 23:49:13 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::OpenContainer(const nsIParserNode& aNode)
|
1998-07-20 18:52:40 +00:00
|
|
|
{
|
1999-10-26 14:55:51 +00:00
|
|
|
FlushTextAndRelease();
|
1998-07-20 18:52:40 +00:00
|
|
|
|
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"SinkContext::OpenContainer",
|
|
|
|
nsHTMLTag(aNode.GetNodeType()),
|
|
|
|
mStackPos,
|
|
|
|
mSink);
|
1998-07-20 18:52:40 +00:00
|
|
|
|
2006-04-08 00:32:03 +00:00
|
|
|
if (mStackPos <= 0) {
|
|
|
|
NS_ERROR("container w/o parent");
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (mStackPos + 1 > mStackSize) {
|
|
|
|
rv = GrowStack();
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1998-07-20 18:52:40 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Create new container content object
|
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* content =
|
2006-02-08 05:56:13 +00:00
|
|
|
mSink->CreateContentObject(aNode, nodeType).get();
|
2004-06-06 02:38:32 +00:00
|
|
|
if (!content) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-08-31 11:17:26 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStack[mStackPos].mType = nodeType;
|
|
|
|
mStack[mStackPos].mContent = content;
|
1999-10-26 14:55:51 +00:00
|
|
|
mStack[mStackPos].mNumFlushed = 0;
|
|
|
|
mStack[mStackPos].mInsertionPoint = -1;
|
2006-04-08 00:32:03 +00:00
|
|
|
++mStackPos;
|
2001-03-13 02:27:25 +00:00
|
|
|
|
1999-12-03 09:24:22 +00:00
|
|
|
rv = mSink->AddAttributes(aNode, content);
|
1998-09-03 01:23:12 +00:00
|
|
|
|
2008-10-12 17:44:23 +00:00
|
|
|
mStack[mStackPos - 2].Add(content);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1998-07-20 18:52:40 +00:00
|
|
|
|
2000-02-16 23:43:59 +00:00
|
|
|
if (mSink->IsMonolithicContainer(nodeType)) {
|
2002-09-18 23:31:08 +00:00
|
|
|
mSink->mInMonolithicContainer++;
|
2000-02-16 23:43:59 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Special handling for certain tags
|
|
|
|
switch (nodeType) {
|
2005-10-21 15:39:06 +00:00
|
|
|
case eHTMLTag_form:
|
2012-01-25 07:50:03 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for forms.");
|
2005-10-21 15:39:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_frameset:
|
2012-01-25 07:48:59 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for frames.");
|
2005-10-21 15:39:06 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
case eHTMLTag_noembed:
|
|
|
|
case eHTMLTag_noframes:
|
2012-01-25 07:50:03 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for noembed/noframes.");
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
case eHTMLTag_script:
|
2012-01-25 07:48:59 +00:00
|
|
|
case eHTMLTag_style:
|
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for styles and scripts.");
|
1999-12-07 07:25:56 +00:00
|
|
|
break;
|
2005-09-09 18:03:47 +00:00
|
|
|
|
2006-11-28 03:17:03 +00:00
|
|
|
case eHTMLTag_button:
|
2012-01-20 19:23:58 +00:00
|
|
|
#ifdef MOZ_MEDIA
|
2011-12-15 19:36:46 +00:00
|
|
|
case eHTMLTag_audio:
|
|
|
|
case eHTMLTag_video:
|
2012-01-20 19:23:58 +00:00
|
|
|
#endif
|
2006-11-28 03:17:03 +00:00
|
|
|
content->DoneCreatingElement();
|
|
|
|
break;
|
2012-01-20 19:23:58 +00:00
|
|
|
|
1999-12-07 07:25:56 +00:00
|
|
|
default:
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-20 18:52:40 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2005-09-22 02:33:36 +00:00
|
|
|
SinkContext::HaveNotifiedForCurrentContent() const
|
|
|
|
{
|
|
|
|
if (0 < mStackPos) {
|
|
|
|
nsIContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
return mStack[mStackPos-1].mNumFlushed == parent->GetChildCount();
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-09-22 02:33:36 +00:00
|
|
|
}
|
|
|
|
|
2008-10-12 17:44:23 +00:00
|
|
|
nsIContent *
|
|
|
|
SinkContext::Node::Add(nsIContent *child)
|
|
|
|
{
|
2008-12-20 00:49:08 +00:00
|
|
|
NS_ASSERTION(mContent, "No parent to insert/append into!");
|
2008-10-12 17:44:23 +00:00
|
|
|
if (mInsertionPoint != -1) {
|
|
|
|
NS_ASSERTION(mNumFlushed == mContent->GetChildCount(),
|
|
|
|
"Inserting multiple children without flushing.");
|
2011-10-17 14:59:28 +00:00
|
|
|
mContent->InsertChildAt(child, mInsertionPoint++, false);
|
2008-10-12 17:44:23 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mContent->AppendChildTo(child, false);
|
2008-10-12 17:44:23 +00:00
|
|
|
}
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
2012-01-25 07:48:59 +00:00
|
|
|
SinkContext::CloseContainer(const nsHTMLTag aTag)
|
1998-07-20 18:52:40 +00:00
|
|
|
{
|
1999-07-22 23:28:16 +00:00
|
|
|
nsresult result = NS_OK;
|
1998-07-20 18:52:40 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// Flush any collected text content. Release the last text
|
|
|
|
// node to indicate that no more should be added to it.
|
|
|
|
FlushTextAndRelease();
|
2002-04-17 04:17:16 +00:00
|
|
|
|
1998-07-20 18:52:40 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"SinkContext::CloseContainer",
|
|
|
|
aTag, mStackPos - 1, mSink);
|
1998-07-20 18:52:40 +00:00
|
|
|
|
2006-03-30 18:40:56 +00:00
|
|
|
NS_ASSERTION(mStackPos > 0,
|
|
|
|
"stack out of bounds. wrong context probably!");
|
2000-07-28 01:01:08 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mStackPos <= 0) {
|
2000-07-28 01:01:08 +00:00
|
|
|
return NS_OK; // Fix crash - Ref. bug 45975 or 45007
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
--mStackPos;
|
|
|
|
nsHTMLTag nodeType = mStack[mStackPos].mType;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2012-01-25 07:50:03 +00:00
|
|
|
NS_ASSERTION(nodeType == aTag,
|
2006-06-08 04:29:28 +00:00
|
|
|
"Tag mismatch. Closing tag on wrong context or something?");
|
|
|
|
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* content = mStack[mStackPos].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2008-02-02 23:41:24 +00:00
|
|
|
content->Compact();
|
1998-07-20 18:52:40 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If we're in a state where we do append notifications as
|
|
|
|
// we go up the tree, and we're at the level where the next
|
|
|
|
// notification needs to be done, do the notification.
|
|
|
|
if (mNotifyLevel >= mStackPos) {
|
|
|
|
// Check to see if new content has been added after our last
|
|
|
|
// notification
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
if (mStack[mStackPos].mNumFlushed < content->GetChildCount()) {
|
1999-10-26 14:55:51 +00:00
|
|
|
#ifdef NS_DEBUG
|
2003-11-19 01:20:56 +00:00
|
|
|
{
|
|
|
|
// Tracing code
|
2007-01-30 21:21:06 +00:00
|
|
|
SINK_TRACE(gSinkLogModuleInfo, SINK_TRACE_REFLOW,
|
2003-11-19 01:20:56 +00:00
|
|
|
("SinkContext::CloseContainer: reflow on notifyImmediate "
|
|
|
|
"tag=%s newIndex=%d stackPos=%d",
|
2010-03-08 15:45:00 +00:00
|
|
|
nsAtomCString(mStack[mStackPos].mContent->Tag()).get(),
|
2003-11-19 01:20:56 +00:00
|
|
|
mStack[mStackPos].mNumFlushed, mStackPos));
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
#endif
|
1999-10-26 14:55:51 +00:00
|
|
|
mSink->NotifyAppend(content, mStack[mStackPos].mNumFlushed);
|
2006-06-08 04:38:44 +00:00
|
|
|
mStack[mStackPos].mNumFlushed = content->GetChildCount();
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate that notification has now happened at this level
|
2002-09-18 23:31:08 +00:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2000-02-16 23:43:59 +00:00
|
|
|
if (mSink->IsMonolithicContainer(nodeType)) {
|
|
|
|
--mSink->mInMonolithicContainer;
|
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2006-06-08 04:38:44 +00:00
|
|
|
DidAddContent(content);
|
2001-03-06 00:52:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Special handling for certain tags
|
|
|
|
switch (nodeType) {
|
2002-09-18 23:31:08 +00:00
|
|
|
case eHTMLTag_noembed:
|
|
|
|
case eHTMLTag_noframes:
|
2012-01-25 07:50:03 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for noembed/noframes.");
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
2012-01-25 07:50:03 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
case eHTMLTag_form:
|
2012-01-25 07:50:03 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for forms.");
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
2005-10-21 15:39:06 +00:00
|
|
|
|
2008-07-09 08:22:20 +00:00
|
|
|
#ifdef MOZ_MEDIA
|
|
|
|
case eHTMLTag_video:
|
|
|
|
case eHTMLTag_audio:
|
|
|
|
#endif
|
2002-09-18 23:31:08 +00:00
|
|
|
case eHTMLTag_select:
|
2005-06-01 21:23:23 +00:00
|
|
|
case eHTMLTag_textarea:
|
2004-06-02 00:25:00 +00:00
|
|
|
case eHTMLTag_object:
|
|
|
|
case eHTMLTag_applet:
|
2008-08-18 02:10:28 +00:00
|
|
|
case eHTMLTag_title:
|
2005-09-22 02:33:36 +00:00
|
|
|
content->DoneAddingChildren(HaveNotifiedForCurrentContent());
|
2005-09-09 18:03:47 +00:00
|
|
|
break;
|
1999-11-11 22:15:02 +00:00
|
|
|
|
2005-09-09 18:03:47 +00:00
|
|
|
case eHTMLTag_script:
|
2012-01-25 07:48:59 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink to run scripts.");
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
2005-09-09 18:03:47 +00:00
|
|
|
|
|
|
|
case eHTMLTag_style:
|
2012-01-25 07:48:59 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for styles.");
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
2005-09-09 18:03:47 +00:00
|
|
|
break;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
1998-07-20 18:52:40 +00:00
|
|
|
}
|
|
|
|
|
1999-11-11 22:15:02 +00:00
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
|
1999-04-03 19:00:23 +00:00
|
|
|
#ifdef DEBUG
|
2005-04-07 03:30:50 +00:00
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo, SINK_ALWAYS_REFLOW)) {
|
1999-04-03 19:00:23 +00:00
|
|
|
mSink->ForceReflow();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-07-22 23:28:16 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::AddLeaf(const nsIParserNode& aNode)
|
1998-07-15 22:31:10 +00:00
|
|
|
{
|
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"SinkContext::AddLeaf",
|
|
|
|
nsHTMLTag(aNode.GetNodeType()),
|
|
|
|
mStackPos, mSink);
|
1998-07-15 22:31:10 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-07-15 22:31:10 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
switch (aNode.GetTokenType()) {
|
|
|
|
case eToken_start:
|
|
|
|
{
|
1999-10-26 14:55:51 +00:00
|
|
|
FlushTextAndRelease();
|
1998-07-15 22:31:10 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Create new leaf content object
|
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
2005-01-12 19:45:38 +00:00
|
|
|
nsRefPtr<nsGenericHTMLElement> content =
|
2006-02-08 05:56:13 +00:00
|
|
|
mSink->CreateContentObject(aNode, nodeType);
|
2004-06-06 02:38:32 +00:00
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_OUT_OF_MEMORY);
|
1998-09-03 01:23:12 +00:00
|
|
|
|
2003-04-17 23:15:21 +00:00
|
|
|
rv = mSink->AddAttributes(aNode, content);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Add new leaf to its parent
|
1999-01-09 00:14:53 +00:00
|
|
|
AddLeaf(content);
|
2002-03-31 10:14:01 +00:00
|
|
|
|
2005-11-10 15:51:10 +00:00
|
|
|
// Additional processing needed once the element is in the tree
|
2002-03-31 10:14:01 +00:00
|
|
|
switch (nodeType) {
|
2005-11-10 15:51:10 +00:00
|
|
|
case eHTMLTag_meta:
|
2012-01-25 07:50:03 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for metas.");
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
2005-11-10 15:51:10 +00:00
|
|
|
break;
|
|
|
|
|
2002-03-31 10:14:01 +00:00
|
|
|
case eHTMLTag_input:
|
|
|
|
content->DoneCreatingElement();
|
2011-08-08 17:31:32 +00:00
|
|
|
break;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2011-08-08 17:31:32 +00:00
|
|
|
case eHTMLTag_menuitem:
|
|
|
|
content->DoneCreatingElement();
|
2002-03-31 10:14:01 +00:00
|
|
|
break;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-04-16 18:09:53 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
case eToken_text:
|
|
|
|
case eToken_whitespace:
|
|
|
|
case eToken_newline:
|
1999-04-03 19:00:23 +00:00
|
|
|
rv = AddText(aNode.GetText());
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
case eToken_entity:
|
|
|
|
{
|
|
|
|
nsAutoString tmp;
|
|
|
|
PRInt32 unicode = aNode.TranslateToUnicodeStr(tmp);
|
|
|
|
if (unicode < 0) {
|
1999-04-03 19:00:23 +00:00
|
|
|
rv = AddText(aNode.GetText());
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
1999-07-05 19:45:27 +00:00
|
|
|
// Map carriage returns to newlines
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!tmp.IsEmpty()) {
|
|
|
|
if (tmp.CharAt(0) == '\r') {
|
2001-12-16 08:16:29 +00:00
|
|
|
tmp.Assign((PRUnichar)'\n');
|
2001-02-01 21:04:48 +00:00
|
|
|
}
|
|
|
|
rv = AddText(tmp);
|
1999-07-05 19:45:27 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
2002-04-16 18:09:53 +00:00
|
|
|
default:
|
1998-04-22 23:24:43 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-04-03 19:00:23 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1999-01-09 00:14:53 +00:00
|
|
|
nsresult
|
2008-12-20 00:49:08 +00:00
|
|
|
SinkContext::AddLeaf(nsIContent* aContent)
|
1999-01-09 00:14:53 +00:00
|
|
|
{
|
1999-12-08 23:05:14 +00:00
|
|
|
NS_ASSERTION(mStackPos > 0, "leaf w/o container");
|
1999-12-09 03:10:22 +00:00
|
|
|
if (mStackPos <= 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-10-12 17:44:23 +00:00
|
|
|
|
|
|
|
DidAddContent(mStack[mStackPos - 1].Add(aContent));
|
1999-01-09 00:14:53 +00:00
|
|
|
|
1999-04-03 19:00:23 +00:00
|
|
|
#ifdef DEBUG
|
2005-04-07 03:30:50 +00:00
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo, SINK_ALWAYS_REFLOW)) {
|
1999-04-03 19:00:23 +00:00
|
|
|
mSink->ForceReflow();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-01-09 00:14:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-10 04:13:59 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::End()
|
|
|
|
{
|
|
|
|
for (PRInt32 i = 0; i < mStackPos; i++) {
|
|
|
|
NS_RELEASE(mStack[i].mContent);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStackPos = 0;
|
|
|
|
mTextLength = 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
SinkContext::GrowStack()
|
|
|
|
{
|
|
|
|
PRInt32 newSize = mStackSize * 2;
|
2002-09-18 23:31:08 +00:00
|
|
|
if (newSize == 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
newSize = 32;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
Node* stack = new Node[newSize];
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!stack) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mStackPos != 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
memcpy(stack, mStack, sizeof(Node) * mStackPos);
|
|
|
|
delete [] mStack;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mStack = stack;
|
|
|
|
mStackSize = newSize;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
/**
|
|
|
|
* Add textual content to the current running text buffer. If the text buffer
|
|
|
|
* overflows, flush out the text by creating a text content object and adding
|
|
|
|
* it to the content tree.
|
|
|
|
*/
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// XXX If we get a giant string grow the buffer instead of chopping it
|
|
|
|
// up???
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
2002-03-23 23:13:20 +00:00
|
|
|
SinkContext::AddText(const nsAString& aText)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
|
|
|
PRInt32 addLen = aText.Length();
|
2002-09-18 23:31:08 +00:00
|
|
|
if (addLen == 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-09-09 18:03:47 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Create buffer when we first need it
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mTextSize == 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
mText = new PRUnichar[4096];
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!mText) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mTextSize = 4096;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Copy data from string into our buffer; flush buffer when it fills up
|
|
|
|
PRInt32 offset = 0;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
while (addLen != 0) {
|
1998-08-28 16:20:16 +00:00
|
|
|
PRInt32 amount = mTextSize - mTextLength;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
if (amount > addLen) {
|
|
|
|
amount = addLen;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (amount == 0) {
|
1999-10-26 14:55:51 +00:00
|
|
|
// Don't release last text node so we can add to it again
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult rv = FlushText();
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2008-08-19 19:07:15 +00:00
|
|
|
|
|
|
|
// Go back to the top of the loop so we re-calculate amount and
|
|
|
|
// don't fall through to CopyNewlineNormalizedUnicodeTo with a
|
|
|
|
// zero-length amount (which invalidates mLastTextCharWasCR).
|
|
|
|
continue;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
mTextLength +=
|
|
|
|
nsContentUtils::CopyNewlineNormalizedUnicodeTo(aText, offset,
|
|
|
|
&mText[mTextLength],
|
2008-08-19 18:33:57 +00:00
|
|
|
amount,
|
|
|
|
mLastTextCharWasCR);
|
1998-08-28 16:20:16 +00:00
|
|
|
offset += amount;
|
|
|
|
addLen -= amount;
|
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-11-28 23:51:06 +00:00
|
|
|
/**
|
2007-01-30 21:21:06 +00:00
|
|
|
* NOTE!! Forked into nsXMLContentSink. Please keep in sync.
|
|
|
|
*
|
1998-11-28 23:51:06 +00:00
|
|
|
* Flush all elements that have been seen so far such that
|
|
|
|
* they are visible in the tree. Specifically, make sure
|
|
|
|
* that they are all added to their respective parents.
|
1999-10-26 14:55:51 +00:00
|
|
|
* Also, do notification at the top for all content that
|
|
|
|
* has been newly added so that the frame tree is complete.
|
1998-11-28 23:51:06 +00:00
|
|
|
*/
|
|
|
|
nsresult
|
2006-11-06 23:50:33 +00:00
|
|
|
SinkContext::FlushTags()
|
1998-11-28 23:51:06 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mSink->mDeferredFlushTags = false;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool oldBeganUpdate = mSink->mBeganUpdate;
|
2007-05-17 23:54:35 +00:00
|
|
|
PRUint32 oldUpdates = mSink->mUpdatesInNotification;
|
2007-03-09 23:43:50 +00:00
|
|
|
|
2006-11-06 23:50:33 +00:00
|
|
|
++(mSink->mInNotification);
|
2007-05-17 23:54:35 +00:00
|
|
|
mSink->mUpdatesInNotification = 0;
|
2007-04-07 00:20:09 +00:00
|
|
|
{
|
|
|
|
// Scope so we call EndUpdate before we decrease mInNotification
|
|
|
|
mozAutoDocUpdate updateBatch(mSink->mDocument, UPDATE_CONTENT_MODEL,
|
2011-10-17 14:59:28 +00:00
|
|
|
true);
|
|
|
|
mSink->mBeganUpdate = true;
|
2007-04-07 00:20:09 +00:00
|
|
|
|
|
|
|
// Don't release last text node in case we need to add to it again
|
|
|
|
FlushText();
|
|
|
|
|
|
|
|
// Start from the base of the stack (growing downward) and do
|
|
|
|
// a notification from the node that is closest to the root of
|
|
|
|
// tree for any content that has been added.
|
|
|
|
|
|
|
|
// Note that we can start at stackPos == 0 here, because it's the caller's
|
|
|
|
// responsibility to handle flushing interactions between contexts (see
|
|
|
|
// HTMLContentSink::BeginContext).
|
|
|
|
PRInt32 stackPos = 0;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool flushed = false;
|
2007-04-07 00:20:09 +00:00
|
|
|
PRUint32 childCount;
|
|
|
|
nsGenericHTMLElement* content;
|
|
|
|
|
|
|
|
while (stackPos < mStackPos) {
|
|
|
|
content = mStack[stackPos].mContent;
|
|
|
|
childCount = content->GetChildCount();
|
|
|
|
|
|
|
|
if (!flushed && (mStack[stackPos].mNumFlushed < childCount)) {
|
2000-01-28 23:43:12 +00:00
|
|
|
#ifdef NS_DEBUG
|
2007-04-07 00:20:09 +00:00
|
|
|
{
|
|
|
|
// Tracing code
|
|
|
|
SINK_TRACE(gSinkLogModuleInfo, SINK_TRACE_REFLOW,
|
|
|
|
("SinkContext::FlushTags: tag=%s from newindex=%d at "
|
2010-03-08 15:45:00 +00:00
|
|
|
"stackPos=%d",
|
|
|
|
nsAtomCString(mStack[stackPos].mContent->Tag()).get(),
|
2007-04-07 00:20:09 +00:00
|
|
|
mStack[stackPos].mNumFlushed, stackPos));
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
#endif
|
2009-08-13 20:27:37 +00:00
|
|
|
if (mStack[stackPos].mInsertionPoint != -1) {
|
|
|
|
// We might have popped the child off our stack already
|
|
|
|
// but not notified on it yet, which is why we have to get it
|
|
|
|
// directly from its parent node.
|
|
|
|
|
2008-10-12 17:44:23 +00:00
|
|
|
PRInt32 childIndex = mStack[stackPos].mInsertionPoint - 1;
|
2009-08-13 20:27:37 +00:00
|
|
|
nsIContent* child = content->GetChildAt(childIndex);
|
|
|
|
// Child not on stack anymore; can't assert it's correct
|
|
|
|
NS_ASSERTION(!(mStackPos > (stackPos + 1)) ||
|
|
|
|
(child == mStack[stackPos + 1].mContent),
|
2008-10-12 17:44:23 +00:00
|
|
|
"Flushing the wrong child.");
|
|
|
|
mSink->NotifyInsert(content, child, childIndex);
|
2007-04-07 00:20:09 +00:00
|
|
|
} else {
|
|
|
|
mSink->NotifyAppend(content, mStack[stackPos].mNumFlushed);
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
flushed = true;
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
|
|
|
|
2007-04-07 00:20:09 +00:00
|
|
|
mStack[stackPos].mNumFlushed = childCount;
|
|
|
|
stackPos++;
|
2000-01-28 23:43:12 +00:00
|
|
|
}
|
2007-04-07 00:20:09 +00:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2006-11-06 23:50:33 +00:00
|
|
|
--(mSink->mInNotification);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2007-05-17 23:54:35 +00:00
|
|
|
if (mSink->mUpdatesInNotification > 1) {
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
mSink->mUpdatesInNotification = oldUpdates;
|
2007-03-09 23:43:50 +00:00
|
|
|
mSink->mBeganUpdate = oldBeganUpdate;
|
|
|
|
|
2005-04-07 03:30:50 +00:00
|
|
|
return NS_OK;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
/**
|
|
|
|
* NOTE!! Forked into nsXMLContentSink. Please keep in sync.
|
|
|
|
*/
|
1999-10-26 14:55:51 +00:00
|
|
|
void
|
|
|
|
SinkContext::UpdateChildCounts()
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
// Start from the top of the stack (growing upwards) and see if any
|
|
|
|
// new content has been appended. If so, we recognize that reflows
|
|
|
|
// have been generated for it and we should make sure that no
|
2006-05-12 20:36:39 +00:00
|
|
|
// further reflows occur. Note that we have to include stackPos == 0
|
|
|
|
// to properly notify on kids of <html>.
|
2002-09-18 23:31:08 +00:00
|
|
|
PRInt32 stackPos = mStackPos - 1;
|
2006-05-12 20:36:39 +00:00
|
|
|
while (stackPos >= 0) {
|
2005-04-07 03:30:50 +00:00
|
|
|
Node & node = mStack[stackPos];
|
|
|
|
node.mNumFlushed = node.mContent->GetChildCount();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
stackPos--;
|
|
|
|
}
|
2000-03-10 02:00:42 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1998-11-28 23:51:06 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
/**
|
|
|
|
* Flush any buffered text out by creating a text content object and
|
|
|
|
* adding it to the content.
|
|
|
|
*/
|
|
|
|
nsresult
|
2011-09-29 06:19:26 +00:00
|
|
|
SinkContext::FlushText(bool* aDidFlush, bool aReleaseLast)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool didFlush = false;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mTextLength != 0) {
|
1999-10-26 14:55:51 +00:00
|
|
|
if (mLastTextNode) {
|
2000-01-31 23:39:19 +00:00
|
|
|
if ((mLastTextNodeSize + mTextLength) > mSink->mMaxTextRun) {
|
|
|
|
mLastTextNodeSize = 0;
|
2002-12-19 20:23:57 +00:00
|
|
|
mLastTextNode = nsnull;
|
2000-01-31 23:39:19 +00:00
|
|
|
FlushText(aDidFlush, aReleaseLast);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool notify = HaveNotifiedForCurrentContent();
|
2006-10-28 01:22:53 +00:00
|
|
|
// We could probably always increase mInNotification here since
|
|
|
|
// if AppendText doesn't notify it shouldn't trigger evil code.
|
|
|
|
// But just in case it does, we don't want to mask any notifications.
|
|
|
|
if (notify) {
|
|
|
|
++mSink->mInNotification;
|
2000-01-31 23:39:19 +00:00
|
|
|
}
|
2006-10-28 01:22:53 +00:00
|
|
|
rv = mLastTextNode->AppendText(mText, mTextLength, notify);
|
|
|
|
if (notify) {
|
|
|
|
--mSink->mInNotification;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLastTextNodeSize += mTextLength;
|
|
|
|
mTextLength = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
didFlush = true;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2006-07-19 04:36:36 +00:00
|
|
|
nsCOMPtr<nsIContent> textContent;
|
2005-09-24 18:43:15 +00:00
|
|
|
rv = NS_NewTextNode(getter_AddRefs(textContent),
|
|
|
|
mSink->mNodeInfoManager);
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-03-31 09:51:02 +00:00
|
|
|
|
2002-12-19 20:23:57 +00:00
|
|
|
mLastTextNode = textContent;
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Set the text in the text node
|
2011-10-17 14:59:28 +00:00
|
|
|
mLastTextNode->SetText(mText, mTextLength, false);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
// Eat up the rest of the text up in state.
|
|
|
|
mLastTextNodeSize += mTextLength;
|
|
|
|
mTextLength = 0;
|
1998-09-06 00:20:59 +00:00
|
|
|
|
2008-12-20 00:49:08 +00:00
|
|
|
rv = AddLeaf(mLastTextNode);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
didFlush = true;
|
1998-07-20 18:52:40 +00:00
|
|
|
}
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (aDidFlush) {
|
1998-08-28 16:20:16 +00:00
|
|
|
*aDidFlush = didFlush;
|
|
|
|
}
|
1999-04-03 19:00:23 +00:00
|
|
|
|
2002-12-19 20:23:57 +00:00
|
|
|
if (aReleaseLast) {
|
2000-01-31 23:39:19 +00:00
|
|
|
mLastTextNodeSize = 0;
|
2002-12-19 20:23:57 +00:00
|
|
|
mLastTextNode = nsnull;
|
2011-10-17 14:59:28 +00:00
|
|
|
mLastTextCharWasCR = false;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-04-03 19:00:23 +00:00
|
|
|
#ifdef DEBUG
|
2005-04-07 03:30:50 +00:00
|
|
|
if (didFlush &&
|
2002-09-18 23:31:08 +00:00
|
|
|
SINK_LOG_TEST(gSinkLogModuleInfo, SINK_ALWAYS_REFLOW)) {
|
1999-04-03 19:00:23 +00:00
|
|
|
mSink->ForceReflow();
|
|
|
|
}
|
|
|
|
#endif
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-07-20 18:52:40 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
NS_NewHTMLContentSink(nsIHTMLContentSink** aResult,
|
|
|
|
nsIDocument* aDoc,
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI* aURI,
|
2003-04-02 11:18:00 +00:00
|
|
|
nsISupports* aContainer,
|
2001-03-03 00:39:29 +00:00
|
|
|
nsIChannel* aChannel)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
nsRefPtr<HTMLContentSink> it = new HTMLContentSink();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (!it) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult rv = it->Init(aDoc, aURI, aContainer, aChannel);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
*aResult = it;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
HTMLContentSink::HTMLContentSink()
|
|
|
|
{
|
|
|
|
// Note: operator new zeros our memory
|
|
|
|
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
#ifdef NS_DEBUG
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!gSinkLogModuleInfo) {
|
1998-08-28 16:20:16 +00:00
|
|
|
gSinkLogModuleInfo = PR_NewLogModule("htmlcontentsink");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::~HTMLContentSink()
|
|
|
|
{
|
1999-12-04 01:27:46 +00:00
|
|
|
if (mNotificationTimer) {
|
|
|
|
mNotificationTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
2009-03-20 08:15:35 +00:00
|
|
|
PRInt32 numContexts = mContextStack.Length();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
if (mCurrentContext == mHeadContext && numContexts > 0) {
|
1999-11-19 04:02:23 +00:00
|
|
|
// Pop off the second html context if it's not done earlier
|
|
|
|
mContextStack.RemoveElementAt(--numContexts);
|
|
|
|
}
|
|
|
|
|
2006-10-04 22:02:17 +00:00
|
|
|
PRInt32 i;
|
|
|
|
for (i = 0; i < numContexts; i++) {
|
2009-03-20 08:15:35 +00:00
|
|
|
SinkContext* sc = mContextStack.ElementAt(i);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (sc) {
|
1999-11-19 04:02:23 +00:00
|
|
|
sc->End();
|
|
|
|
if (sc == mCurrentContext) {
|
|
|
|
mCurrentContext = nsnull;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-11-19 04:02:23 +00:00
|
|
|
delete sc;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
1999-10-26 14:55:51 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
if (mCurrentContext == mHeadContext) {
|
|
|
|
mCurrentContext = nsnull;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
delete mCurrentContext;
|
|
|
|
|
|
|
|
delete mHeadContext;
|
2006-10-04 22:02:17 +00:00
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
for (i = 0; PRUint32(i) < ArrayLength(mNodeInfoCache); ++i) {
|
2006-10-04 22:02:17 +00:00
|
|
|
NS_IF_RELEASE(mNodeInfoCache[i]);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLContentSink)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLContentSink, nsContentSink)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHTMLDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mBody)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHead)
|
2011-10-11 05:50:08 +00:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(tmp->mNodeInfoCache); ++i) {
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_IF_RELEASE(tmp->mNodeInfoCache[i]);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLContentSink,
|
|
|
|
nsContentSink)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHTMLDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBody)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHead)
|
2011-10-11 05:50:08 +00:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(tmp->mNodeInfoCache); ++i) {
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mNodeInfoCache[i]");
|
|
|
|
cb.NoteXPCOMChild(tmp->mNodeInfoCache[i]);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLContentSink)
|
|
|
|
NS_INTERFACE_TABLE_BEGIN
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(HTMLContentSink, nsIContentSink)
|
|
|
|
NS_INTERFACE_TABLE_ENTRY(HTMLContentSink, nsIHTMLContentSink)
|
2003-10-05 07:29:50 +00:00
|
|
|
#if DEBUG
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_INTERFACE_TABLE_ENTRY(HTMLContentSink, nsIDebugDumpContent)
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2010-03-31 11:35:20 +00:00
|
|
|
NS_INTERFACE_TABLE_END
|
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsContentSink)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLContentSink, nsContentSink)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLContentSink, nsContentSink)
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2003-04-02 11:18:00 +00:00
|
|
|
IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer)
|
2001-06-20 01:04:24 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(aDoc && aContainer, true);
|
2001-06-20 01:04:24 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject = aDoc->GetScriptGlobalObject();
|
2001-06-20 01:04:24 +00:00
|
|
|
|
2009-01-23 09:02:09 +00:00
|
|
|
// Getting context is tricky if the document hasn't had its
|
2002-09-18 23:31:08 +00:00
|
|
|
// GlobalObject set yet
|
2001-06-20 01:04:24 +00:00
|
|
|
if (!globalObject) {
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObjectOwner> owner = do_GetInterface(aContainer);
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(owner, true);
|
2001-06-20 01:04:24 +00:00
|
|
|
|
2004-07-16 17:03:10 +00:00
|
|
|
globalObject = owner->GetScriptGlobalObject();
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(globalObject, true);
|
2001-06-20 01:04:24 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 22:48:53 +00:00
|
|
|
nsIScriptContext *scriptContext = globalObject->GetContext();
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(scriptContext, true);
|
2001-06-20 01:04:24 +00:00
|
|
|
|
2011-09-18 09:22:17 +00:00
|
|
|
JSContext* cx = scriptContext->GetNativeContext();
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(cx, true);
|
2001-06-20 01:04:24 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool enabled = true;
|
2006-04-27 18:21:11 +00:00
|
|
|
nsContentUtils::GetSecurityManager()->
|
|
|
|
CanExecuteScripts(cx, aDoc->NodePrincipal(), &enabled);
|
2001-06-20 01:04:24 +00:00
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::Init(nsIDocument* aDoc,
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI* aURI,
|
2003-04-02 11:18:00 +00:00
|
|
|
nsISupports* aContainer,
|
2001-03-03 00:39:29 +00:00
|
|
|
nsIChannel* aChannel)
|
2002-09-18 23:31:08 +00:00
|
|
|
{
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_ENSURE_TRUE(aContainer, NS_ERROR_NULL_POINTER);
|
2009-08-28 18:03:51 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult rv = nsContentSink::Init(aDoc, aURI, aContainer, aChannel);
|
2005-09-15 23:17:17 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-10-05 07:29:50 +00:00
|
|
|
return rv;
|
1998-08-31 17:51:32 +00:00
|
|
|
}
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
aDoc->AddObserver(this);
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsDocumentObserver = true;
|
2010-03-31 11:35:20 +00:00
|
|
|
mHTMLDocument = do_QueryInterface(aDoc);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2006-03-30 18:40:56 +00:00
|
|
|
NS_ASSERTION(mDocShell, "oops no docshell!");
|
2003-04-02 11:18:00 +00:00
|
|
|
|
|
|
|
// Find out if subframes are enabled
|
|
|
|
if (mDocShell) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool subFramesEnabled = true;
|
2003-04-02 11:18:00 +00:00
|
|
|
mDocShell->GetAllowSubframes(&subFramesEnabled);
|
|
|
|
if (subFramesEnabled) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mFramesEnabled = true;
|
2001-04-21 22:22:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-20 01:04:24 +00:00
|
|
|
// Find out if scripts are enabled, if not, show <noscript> content
|
2003-04-02 11:18:00 +00:00
|
|
|
if (IsScriptEnabled(aDoc, mDocShell)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mScriptEnabled = true;
|
2001-06-20 01:04:24 +00:00
|
|
|
}
|
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// Changed from 8192 to greatly improve page loading performance on
|
|
|
|
// large pages. See bugzilla bug 77540.
|
2011-05-25 06:32:00 +00:00
|
|
|
mMaxTextRun = Preferences::GetInt("content.maxtextrun", 8191);
|
2000-01-31 23:39:19 +00:00
|
|
|
|
2000-05-10 13:13:39 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2008-09-12 22:32:18 +00:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::html, nsnull,
|
2011-06-14 07:56:49 +00:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2008-09-25 22:46:52 +00:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2000-05-10 13:13:39 +00:00
|
|
|
|
1998-07-30 16:06:22 +00:00
|
|
|
// Make root part
|
2010-07-23 09:49:57 +00:00
|
|
|
mRoot = NS_NewHTMLHtmlElement(nodeInfo.forget());
|
2010-04-30 13:12:05 +00:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 13:12:05 +00:00
|
|
|
NS_ASSERTION(mDocument->GetChildCount() == 0,
|
|
|
|
"Document should have no kids here!");
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = mDocument->AppendChildTo(mRoot, false);
|
2010-04-30 13:12:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Make head part
|
2008-09-12 22:32:18 +00:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::head,
|
2011-06-14 07:56:49 +00:00
|
|
|
nsnull, kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2008-09-25 22:46:52 +00:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
mHead = NS_NewHTMLHeadElement(nodeInfo.forget());
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2004-06-06 02:38:32 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-07-30 16:06:22 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mRoot->AppendChildTo(mHead, false);
|
1998-07-30 16:06:22 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext = new SinkContext(this);
|
2001-06-20 01:04:24 +00:00
|
|
|
NS_ENSURE_TRUE(mCurrentContext, NS_ERROR_OUT_OF_MEMORY);
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->Begin(eHTMLTag_html, mRoot, 0, -1);
|
1998-08-28 16:20:16 +00:00
|
|
|
mContextStack.AppendElement(mCurrentContext);
|
|
|
|
|
2001-04-10 00:49:49 +00:00
|
|
|
#ifdef NS_DEBUG
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString spec;
|
2004-01-09 23:54:21 +00:00
|
|
|
(void)aURI->GetSpec(spec);
|
2007-01-30 21:21:06 +00:00
|
|
|
SINK_TRACE(gSinkLogModuleInfo, SINK_TRACE_CALLS,
|
1998-08-28 16:20:16 +00:00
|
|
|
("HTMLContentSink::Init: this=%p url='%s'",
|
2002-03-06 07:48:55 +00:00
|
|
|
this, spec.get()));
|
2001-04-10 00:49:49 +00:00
|
|
|
#endif
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-30 21:31:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillParse(void)
|
|
|
|
{
|
|
|
|
return WillParseImpl();
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
2009-06-23 21:22:16 +00:00
|
|
|
HTMLContentSink::WillBuildModel(nsDTDMode aDTDMode)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2007-01-30 21:21:06 +00:00
|
|
|
WillBuildModelImpl();
|
2009-06-23 21:22:16 +00:00
|
|
|
|
2001-12-07 21:53:39 +00:00
|
|
|
if (mHTMLDocument) {
|
2002-06-25 21:16:17 +00:00
|
|
|
nsCompatibility mode = eCompatibility_NavQuirks;
|
2009-06-23 21:22:16 +00:00
|
|
|
switch (aDTDMode) {
|
|
|
|
case eDTDMode_full_standards:
|
|
|
|
mode = eCompatibility_FullStandards;
|
|
|
|
break;
|
|
|
|
case eDTDMode_almost_standards:
|
|
|
|
mode = eCompatibility_AlmostStandards;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2002-06-25 21:16:17 +00:00
|
|
|
}
|
|
|
|
mHTMLDocument->SetCompatibilityMode(mode);
|
2001-12-07 21:53:39 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
// Notify document that the load is beginning
|
|
|
|
mDocument->BeginLoad();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-27 22:57:52 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
HTMLContentSink::DidBuildModel(bool aTerminated)
|
1998-06-30 23:51:53 +00:00
|
|
|
{
|
2009-10-02 11:13:59 +00:00
|
|
|
DidBuildModelImpl(aTerminated);
|
1998-08-10 17:39:48 +00:00
|
|
|
|
1998-08-31 17:51:32 +00:00
|
|
|
// Reflow the last batch of content
|
2012-01-25 07:48:59 +00:00
|
|
|
if (mBody) {
|
2007-01-30 21:21:06 +00:00
|
|
|
SINK_TRACE(gSinkLogModuleInfo, SINK_TRACE_REFLOW,
|
1999-04-03 19:00:23 +00:00
|
|
|
("HTMLContentSink::DidBuildModel: layout final content"));
|
2006-11-06 23:50:33 +00:00
|
|
|
mCurrentContext->FlushTags();
|
2002-09-18 23:31:08 +00:00
|
|
|
} else if (!mLayoutStarted) {
|
2001-04-10 00:49:49 +00:00
|
|
|
// We never saw the body, and layout never got started. Force
|
|
|
|
// layout *now*, to get an initial reflow.
|
2007-01-30 21:21:06 +00:00
|
|
|
SINK_TRACE(gSinkLogModuleInfo, SINK_TRACE_REFLOW,
|
2002-09-18 23:31:08 +00:00
|
|
|
("HTMLContentSink::DidBuildModel: forcing reflow on empty "
|
|
|
|
"document"));
|
2001-04-10 00:49:49 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
// NOTE: only force the layout if we are NOT destroying the
|
2003-04-02 11:18:00 +00:00
|
|
|
// docshell. If we are destroying it, then starting layout will
|
2002-09-18 23:31:08 +00:00
|
|
|
// likely cause us to crash, or at best waste a lot of time as we
|
|
|
|
// are just going to tear it down anyway.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool bDestroying = true;
|
2003-04-02 11:18:00 +00:00
|
|
|
if (mDocShell) {
|
|
|
|
mDocShell->IsBeingDestroyed(&bDestroying);
|
2001-12-07 00:02:03 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-12-07 00:02:03 +00:00
|
|
|
if (!bDestroying) {
|
2011-10-17 14:59:28 +00:00
|
|
|
StartLayout(false);
|
2001-12-07 00:02:03 +00:00
|
|
|
}
|
2001-04-10 00:49:49 +00:00
|
|
|
}
|
2000-10-18 20:37:54 +00:00
|
|
|
|
2007-02-03 00:48:29 +00:00
|
|
|
ScrollToRef();
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2006-06-19 21:10:29 +00:00
|
|
|
// Make sure we no longer respond to document mutations. We've flushed all
|
|
|
|
// our notifications out, so there's no need to do anything else here.
|
|
|
|
|
|
|
|
// XXXbz I wonder whether we could End() our contexts here too, or something,
|
2009-05-17 14:22:55 +00:00
|
|
|
// just to make sure we no longer notify... Or is the mIsDocumentObserver
|
|
|
|
// thing sufficient?
|
2006-06-19 21:10:29 +00:00
|
|
|
mDocument->RemoveObserver(this);
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsDocumentObserver = false;
|
2006-06-19 21:10:29 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mDocument->EndLoad();
|
2000-09-19 22:35:50 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
DropParserAndPerfHint();
|
2000-04-05 04:02:38 +00:00
|
|
|
|
1998-07-15 22:31:10 +00:00
|
|
|
return NS_OK;
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
NS_IMETHODIMP
|
2012-01-20 11:16:27 +00:00
|
|
|
HTMLContentSink::SetParser(nsParserBase* aParser)
|
1998-12-11 17:02:37 +00:00
|
|
|
{
|
2007-04-27 04:05:08 +00:00
|
|
|
NS_PRECONDITION(aParser, "Should have a parser here!");
|
1998-12-11 17:02:37 +00:00
|
|
|
mParser = aParser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-04-15 20:18:34 +00:00
|
|
|
HTMLContentSink::BeginContext(PRInt32 aPosition)
|
2002-09-18 23:31:08 +00:00
|
|
|
{
|
1999-04-15 20:18:34 +00:00
|
|
|
NS_PRECONDITION(aPosition > -1, "out of bounds");
|
1998-07-30 16:06:22 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
if (!mCurrentContext) {
|
2010-05-23 19:26:15 +00:00
|
|
|
NS_ERROR("Nonexistent context");
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-12-09 03:10:22 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// Flush everything in the current context so that we don't have
|
|
|
|
// to worry about insertions resulting in inconsistent frame creation.
|
2006-11-06 23:50:33 +00:00
|
|
|
mCurrentContext->FlushTags();
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2005-04-04 21:20:00 +00:00
|
|
|
// Sanity check.
|
|
|
|
if (mCurrentContext->mStackPos <= aPosition) {
|
|
|
|
NS_ERROR("Out of bounds position");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
PRInt32 insertionPoint = -1;
|
1999-04-15 20:18:34 +00:00
|
|
|
nsHTMLTag nodeType = mCurrentContext->mStack[aPosition].mType;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement* content = mCurrentContext->mStack[aPosition].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
// If the content under which the new context is created
|
|
|
|
// has a child on the stack, the insertion point is
|
|
|
|
// before the last child.
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aPosition < (mCurrentContext->mStackPos - 1)) {
|
2003-09-27 04:18:26 +00:00
|
|
|
insertionPoint = content->GetChildCount() - 1;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2011-03-22 15:17:44 +00:00
|
|
|
SinkContext* sc = new SinkContext(this);
|
1999-10-26 14:55:51 +00:00
|
|
|
sc->Begin(nodeType,
|
|
|
|
content,
|
|
|
|
mCurrentContext->mStack[aPosition].mNumFlushed,
|
|
|
|
insertionPoint);
|
1999-04-15 20:18:34 +00:00
|
|
|
NS_ADDREF(sc->mSink);
|
1998-07-22 23:42:47 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mContextStack.AppendElement(mCurrentContext);
|
|
|
|
mCurrentContext = sc;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-22 23:42:47 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-04-15 20:18:34 +00:00
|
|
|
HTMLContentSink::EndContext(PRInt32 aPosition)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2010-05-23 19:26:15 +00:00
|
|
|
NS_PRECONDITION(mCurrentContext && aPosition > -1, "nonexistent context");
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2009-03-20 08:15:35 +00:00
|
|
|
PRUint32 n = mContextStack.Length() - 1;
|
|
|
|
SinkContext* sc = mContextStack.ElementAt(n);
|
1998-08-28 16:20:16 +00:00
|
|
|
|
2008-10-12 17:44:23 +00:00
|
|
|
const SinkContext::Node &bottom = mCurrentContext->mStack[0];
|
|
|
|
|
|
|
|
NS_ASSERTION(sc->mStack[aPosition].mType == bottom.mType,
|
2002-09-18 23:31:08 +00:00
|
|
|
"ending a wrong context");
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
2008-10-12 17:44:23 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(bottom.mContent->GetChildCount() == bottom.mNumFlushed,
|
|
|
|
"Node at base of context stack not fully flushed.");
|
|
|
|
|
|
|
|
// Flushing tags before the assertion on the previous line would
|
|
|
|
// undoubtedly prevent the assertion from failing, but it shouldn't
|
|
|
|
// be failing anyway, FlushTags or no. Flushing here is nevertheless
|
|
|
|
// a worthwhile precaution, since we lose some information (e.g.,
|
|
|
|
// mInsertionPoints) when we end the current context.
|
|
|
|
mCurrentContext->FlushTags();
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2008-10-12 17:44:23 +00:00
|
|
|
sc->mStack[aPosition].mNumFlushed = bottom.mNumFlushed;
|
1999-10-26 14:55:51 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
for (PRInt32 i = 0; i<mCurrentContext->mStackPos; i++) {
|
1999-04-15 20:18:34 +00:00
|
|
|
NS_IF_RELEASE(mCurrentContext->mStack[i].mContent);
|
2002-09-18 23:31:08 +00:00
|
|
|
}
|
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
delete [] mCurrentContext->mStack;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
mCurrentContext->mStack = nsnull;
|
|
|
|
mCurrentContext->mStackPos = 0;
|
|
|
|
mCurrentContext->mStackSize = 0;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
delete [] mCurrentContext->mText;
|
|
|
|
|
|
|
|
mCurrentContext->mText = nsnull;
|
1999-04-15 20:18:34 +00:00
|
|
|
mCurrentContext->mTextLength = 0;
|
|
|
|
mCurrentContext->mTextSize = 0;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
NS_IF_RELEASE(mCurrentContext->mSink);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-04-15 20:18:34 +00:00
|
|
|
delete mCurrentContext;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mCurrentContext = sc;
|
1999-04-15 20:18:34 +00:00
|
|
|
mContextStack.RemoveElementAt(n);
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
2002-11-19 18:29:35 +00:00
|
|
|
HTMLContentSink::CloseHTML()
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::CloseHTML",
|
|
|
|
eHTMLTag_html, 0, this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
if (mHeadContext) {
|
|
|
|
if (mCurrentContext == mHeadContext) {
|
2009-03-20 08:15:35 +00:00
|
|
|
PRUint32 numContexts = mContextStack.Length();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-12-10 03:36:50 +00:00
|
|
|
// Pop off the second html context if it's not done earlier
|
2009-03-20 08:15:35 +00:00
|
|
|
mCurrentContext = mContextStack.ElementAt(--numContexts);
|
2000-01-28 23:43:12 +00:00
|
|
|
mContextStack.RemoveElementAt(numContexts);
|
1999-12-10 03:36:50 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2006-01-27 01:05:54 +00:00
|
|
|
NS_ASSERTION(mHeadContext->mTextLength == 0, "Losing text");
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mHeadContext->End();
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
delete mHeadContext;
|
|
|
|
mHeadContext = nsnull;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
2005-09-09 18:03:47 +00:00
|
|
|
HTMLContentSink::OpenHead()
|
|
|
|
{
|
|
|
|
nsresult rv = OpenHeadContext();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
1998-08-28 16:20:16 +00:00
|
|
|
HTMLContentSink::OpenBody(const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::OpenBody",
|
|
|
|
eHTMLTag_body,
|
|
|
|
mCurrentContext->mStackPos,
|
|
|
|
this);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-01-09 18:29:23 +00:00
|
|
|
CloseHeadContext(); // do this just in case if the HEAD was left open!
|
|
|
|
|
|
|
|
// Add attributes, if any, to the current BODY node
|
2002-09-18 23:31:08 +00:00
|
|
|
if (mBody) {
|
2011-10-17 14:59:28 +00:00
|
|
|
AddAttributes(aNode, mBody, true, true);
|
1999-04-05 20:53:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult rv = mCurrentContext->OpenContainer(aNode);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
mBody = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2003-10-11 00:27:45 +00:00
|
|
|
if (mCurrentContext->mStackPos > 1) {
|
2002-09-06 05:44:31 +00:00
|
|
|
PRInt32 parentIndex = mCurrentContext->mStackPos - 2;
|
2005-01-12 19:45:38 +00:00
|
|
|
nsGenericHTMLElement *parent = mCurrentContext->mStack[parentIndex].mContent;
|
2002-09-06 05:44:31 +00:00
|
|
|
PRInt32 numFlushed = mCurrentContext->mStack[parentIndex].mNumFlushed;
|
2006-05-12 20:36:39 +00:00
|
|
|
PRInt32 childCount = parent->GetChildCount();
|
|
|
|
NS_ASSERTION(numFlushed < childCount, "Already notified on the body?");
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
PRInt32 insertionPoint =
|
|
|
|
mCurrentContext->mStack[parentIndex].mInsertionPoint;
|
2002-09-06 05:44:31 +00:00
|
|
|
|
|
|
|
// XXX: I have yet to see a case where numFlushed is non-zero and
|
2002-09-18 23:31:08 +00:00
|
|
|
// insertionPoint is not -1, but this code will try to handle
|
|
|
|
// those cases too.
|
2002-09-06 05:44:31 +00:00
|
|
|
|
2008-10-14 19:00:08 +00:00
|
|
|
PRUint32 oldUpdates = mUpdatesInNotification;
|
2008-08-25 17:21:29 +00:00
|
|
|
mUpdatesInNotification = 0;
|
2002-09-06 05:44:31 +00:00
|
|
|
if (insertionPoint != -1) {
|
|
|
|
NotifyInsert(parent, mBody, insertionPoint - 1);
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2002-09-06 05:44:31 +00:00
|
|
|
NotifyAppend(parent, numFlushed);
|
|
|
|
}
|
2006-05-12 20:36:39 +00:00
|
|
|
mCurrentContext->mStack[parentIndex].mNumFlushed = childCount;
|
2008-08-25 17:21:29 +00:00
|
|
|
if (mUpdatesInNotification > 1) {
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
mUpdatesInNotification = oldUpdates;
|
2002-09-06 05:44:31 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
StartLayout(false);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult
|
2002-11-19 18:29:35 +00:00
|
|
|
HTMLContentSink::CloseBody()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-07-11 03:51:50 +00:00
|
|
|
SINK_TRACE_NODE(SINK_TRACE_CALLS,
|
2002-11-19 18:29:35 +00:00
|
|
|
"HTMLContentSink::CloseBody",
|
|
|
|
eHTMLTag_body,
|
|
|
|
mCurrentContext->mStackPos - 1,
|
|
|
|
this);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool didFlush;
|
1999-10-26 14:55:51 +00:00
|
|
|
nsresult rv = mCurrentContext->FlushTextAndRelease(&didFlush);
|
2002-09-18 23:31:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-29 19:07:24 +00:00
|
|
|
// Flush out anything that's left
|
2007-01-30 21:21:06 +00:00
|
|
|
SINK_TRACE(gSinkLogModuleInfo, SINK_TRACE_REFLOW,
|
1999-10-29 19:07:24 +00:00
|
|
|
("HTMLContentSink::CloseBody: layout final body content"));
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2006-11-06 23:50:33 +00:00
|
|
|
mCurrentContext->FlushTags();
|
2012-01-25 07:48:59 +00:00
|
|
|
mCurrentContext->CloseContainer(eHTMLTag_body);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-26 15:08:55 +00:00
|
|
|
|
2000-09-01 18:17:43 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
HTMLContentSink::IsEnabled(PRInt32 aTag, bool* aReturn)
|
2002-09-18 23:31:08 +00:00
|
|
|
{
|
2001-04-21 22:22:15 +00:00
|
|
|
nsHTMLTag theHTMLTag = nsHTMLTag(aTag);
|
2001-06-21 02:06:23 +00:00
|
|
|
|
2001-04-21 22:22:15 +00:00
|
|
|
if (theHTMLTag == eHTMLTag_script) {
|
2007-01-30 21:21:06 +00:00
|
|
|
*aReturn = mScriptEnabled;
|
2002-09-18 23:31:08 +00:00
|
|
|
} else if (theHTMLTag == eHTMLTag_frameset) {
|
2007-01-30 21:21:06 +00:00
|
|
|
*aReturn = mFramesEnabled;
|
2002-09-18 23:31:08 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aReturn = false;
|
2000-09-01 18:17:43 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-04-21 22:22:15 +00:00
|
|
|
return NS_OK;
|
2000-09-01 18:17:43 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::OpenContainer(const nsIParserNode& aNode)
|
|
|
|
{
|
1999-09-14 14:38:52 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
switch (aNode.GetNodeType()) {
|
|
|
|
case eHTMLTag_frameset:
|
2012-01-25 07:48:59 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for frames.");
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
2005-10-21 15:39:06 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_head:
|
|
|
|
rv = OpenHeadContext();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = AddAttributes(aNode, mHead, true, mHaveSeenHead);
|
|
|
|
mHaveSeenHead = true;
|
2005-10-21 15:39:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eHTMLTag_body:
|
|
|
|
rv = OpenBody(aNode);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_html:
|
|
|
|
if (mRoot) {
|
2006-01-27 01:13:00 +00:00
|
|
|
// If we've already hit this code once, need to check for
|
|
|
|
// already-present attributes on the root.
|
2011-10-17 14:59:28 +00:00
|
|
|
AddAttributes(aNode, mRoot, true, mNotifiedRootInsertion);
|
2006-01-12 17:11:57 +00:00
|
|
|
if (!mNotifiedRootInsertion) {
|
2007-10-04 05:16:35 +00:00
|
|
|
NotifyRootInsertion();
|
2006-01-12 17:11:57 +00:00
|
|
|
}
|
2008-01-16 21:54:33 +00:00
|
|
|
ProcessOfflineManifest(mRoot);
|
2005-10-21 15:39:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eHTMLTag_form:
|
2012-01-25 07:50:03 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for forms.");
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
2005-10-21 15:39:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rv = mCurrentContext->OpenContainer(aNode);
|
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 14:38:52 +00:00
|
|
|
return rv;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-12 00:18:26 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
2002-11-19 18:29:35 +00:00
|
|
|
HTMLContentSink::CloseContainer(const eHTMLTags aTag)
|
1998-08-28 16:20:16 +00:00
|
|
|
{
|
2005-10-21 15:39:06 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
switch (aTag) {
|
|
|
|
case eHTMLTag_frameset:
|
2012-01-25 07:48:59 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for frames.");
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
2005-10-21 15:39:06 +00:00
|
|
|
break;
|
|
|
|
case eHTMLTag_head:
|
|
|
|
CloseHeadContext();
|
|
|
|
break;
|
|
|
|
case eHTMLTag_body:
|
|
|
|
rv = CloseBody();
|
|
|
|
break;
|
|
|
|
case eHTMLTag_html:
|
|
|
|
rv = CloseHTML();
|
|
|
|
break;
|
|
|
|
case eHTMLTag_form:
|
2012-01-25 07:50:03 +00:00
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for forms.");
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
2005-10-21 15:39:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-01-25 07:48:59 +00:00
|
|
|
rv = mCurrentContext->CloseContainer(aTag);
|
2005-10-21 15:39:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-09-14 14:38:52 +00:00
|
|
|
return rv;
|
1998-08-28 16:20:16 +00:00
|
|
|
}
|
1998-07-12 00:18:26 +00:00
|
|
|
|
2006-01-31 22:19:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::CloseMalformedContainer(const eHTMLTags aTag)
|
|
|
|
{
|
2012-01-25 07:48:59 +00:00
|
|
|
return mCurrentContext->CloseContainer(aTag);
|
2006-01-31 22:19:46 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::AddLeaf(const nsIParserNode& aNode)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult rv;
|
1998-07-12 00:18:26 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
|
|
|
|
switch (nodeType) {
|
|
|
|
case eHTMLTag_link:
|
2012-01-25 07:48:59 +00:00
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
MOZ_NOT_REACHED("Must not use HTMLContentSink for links.");
|
1998-07-12 00:18:26 +00:00
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
break;
|
1998-08-28 16:20:16 +00:00
|
|
|
default:
|
|
|
|
rv = mCurrentContext->AddLeaf(aNode);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
break;
|
1998-07-22 23:42:47 +00:00
|
|
|
}
|
1999-09-14 14:38:52 +00:00
|
|
|
|
1998-08-28 16:20:16 +00:00
|
|
|
return rv;
|
1998-07-12 00:18:26 +00:00
|
|
|
}
|
|
|
|
|
2001-06-21 02:06:23 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-02 07:40:01 +00:00
|
|
|
HTMLContentSink::DidProcessTokens(void)
|
|
|
|
{
|
2001-06-21 02:06:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-11-02 07:40:01 +00:00
|
|
|
HTMLContentSink::WillProcessAToken(void)
|
|
|
|
{
|
2001-06-21 02:06:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-11-02 07:40:01 +00:00
|
|
|
HTMLContentSink::DidProcessAToken(void)
|
|
|
|
{
|
2007-01-30 21:21:06 +00:00
|
|
|
return DidProcessATokenImpl();
|
|
|
|
}
|
2001-06-29 04:01:26 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillInterrupt()
|
|
|
|
{
|
2008-10-30 21:31:00 +00:00
|
|
|
return WillInterruptImpl();
|
2007-01-30 21:21:06 +00:00
|
|
|
}
|
2001-11-02 07:40:01 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillResume()
|
|
|
|
{
|
|
|
|
return WillResumeImpl();
|
2001-06-21 02:06:23 +00:00
|
|
|
}
|
|
|
|
|
2003-01-03 23:17:22 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::OpenHeadContext()
|
|
|
|
{
|
2003-01-09 18:29:23 +00:00
|
|
|
if (mCurrentContext && mCurrentContext->IsCurrentContainer(eHTMLTag_head))
|
|
|
|
return NS_OK;
|
2003-01-03 23:17:22 +00:00
|
|
|
|
|
|
|
// Flush everything in the current context so that we don't have
|
|
|
|
// to worry about insertions resulting in inconsistent frame creation.
|
|
|
|
//
|
|
|
|
// Try to do this only if needed (costly), i.e., only if we are sure
|
|
|
|
// we are changing contexts from some other context to the head.
|
|
|
|
//
|
|
|
|
// PERF: This call causes approximately a 2% slowdown in page load time
|
|
|
|
// according to jrgm's page load tests, but seems to be a necessary evil
|
|
|
|
if (mCurrentContext && (mCurrentContext != mHeadContext)) {
|
2006-11-06 23:50:33 +00:00
|
|
|
mCurrentContext->FlushTags();
|
2003-01-03 23:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHeadContext) {
|
|
|
|
mHeadContext = new SinkContext(this);
|
|
|
|
NS_ENSURE_TRUE(mHeadContext, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2003-01-09 18:29:23 +00:00
|
|
|
nsresult rv = mHeadContext->Begin(eHTMLTag_head, mHead, 0, -1);
|
2003-01-03 23:17:22 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
mContextStack.AppendElement(mCurrentContext);
|
|
|
|
mCurrentContext = mHeadContext;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-21 15:39:06 +00:00
|
|
|
void
|
2003-01-03 23:17:22 +00:00
|
|
|
HTMLContentSink::CloseHeadContext()
|
|
|
|
{
|
2006-01-27 01:05:54 +00:00
|
|
|
if (mCurrentContext) {
|
|
|
|
if (!mCurrentContext->IsCurrentContainer(eHTMLTag_head))
|
|
|
|
return;
|
2003-01-03 23:17:22 +00:00
|
|
|
|
2006-01-27 01:05:54 +00:00
|
|
|
mCurrentContext->FlushTextAndRelease();
|
2009-03-23 22:10:12 +00:00
|
|
|
mCurrentContext->FlushTags();
|
2006-01-27 01:05:54 +00:00
|
|
|
}
|
|
|
|
|
2009-03-20 08:15:35 +00:00
|
|
|
if (!mContextStack.IsEmpty())
|
|
|
|
{
|
|
|
|
PRUint32 n = mContextStack.Length() - 1;
|
|
|
|
mCurrentContext = mContextStack.ElementAt(n);
|
|
|
|
mContextStack.RemoveElementAt(n);
|
|
|
|
}
|
2003-01-03 23:17:22 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
HTMLContentSink::ForceReflow()
|
|
|
|
{
|
2006-11-06 23:50:33 +00:00
|
|
|
mCurrentContext->FlushTags();
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
void
|
1999-10-26 14:55:51 +00:00
|
|
|
HTMLContentSink::NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
2006-01-12 17:11:57 +00:00
|
|
|
if (aContent && aContent->GetCurrentDoc() != mDocument) {
|
2005-05-19 19:56:13 +00:00
|
|
|
// aContent is not actually in our document anymore.... Just bail out of
|
|
|
|
// here; notifying on our document for this insert would be wrong.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification++;
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2007-03-09 23:43:50 +00:00
|
|
|
{
|
|
|
|
// Scope so we call EndUpdate before we decrease mInNotification
|
|
|
|
MOZ_AUTO_DOC_UPDATE(mDocument, UPDATE_CONTENT_MODEL, !mBeganUpdate);
|
|
|
|
nsNodeUtils::ContentInserted(NODE_FROM(aContent, mDocument),
|
|
|
|
aChildContent, aIndexInContainer);
|
|
|
|
mLastNotificationTime = PR_Now();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-01-28 23:43:12 +00:00
|
|
|
mInNotification--;
|
1999-10-26 14:55:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-04 05:16:35 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::NotifyRootInsertion()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mNotifiedRootInsertion, "Double-notifying on root?");
|
|
|
|
NS_ASSERTION(!mLayoutStarted,
|
|
|
|
"How did we start layout without notifying on root?");
|
|
|
|
// Now make sure to notify that we have now inserted our root. If
|
|
|
|
// there has been no initial reflow yet it'll be a no-op, but if
|
|
|
|
// there has been one we need this to get its frames constructed.
|
|
|
|
// Note that if mNotifiedRootInsertion is true we don't notify here,
|
|
|
|
// since that just means there are multiple <html> tags in the
|
|
|
|
// document; in those cases we just want to put all the attrs on one
|
|
|
|
// tag.
|
2011-10-17 14:59:28 +00:00
|
|
|
mNotifiedRootInsertion = true;
|
2007-10-04 05:16:35 +00:00
|
|
|
PRInt32 index = mDocument->IndexOf(mRoot);
|
|
|
|
NS_ASSERTION(index != -1, "mRoot not child of document?");
|
|
|
|
NotifyInsert(nsnull, mRoot, index);
|
|
|
|
|
|
|
|
// Now update the notification information in all our
|
|
|
|
// contexts, since we just inserted the root and notified on
|
|
|
|
// our whole tree
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2000-02-16 23:43:59 +00:00
|
|
|
HTMLContentSink::IsMonolithicContainer(nsHTMLTag aTag)
|
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
if (aTag == eHTMLTag_tr ||
|
|
|
|
aTag == eHTMLTag_select ||
|
|
|
|
aTag == eHTMLTag_applet ||
|
|
|
|
aTag == eHTMLTag_object) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2000-02-16 23:43:59 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-02-16 23:43:59 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
void
|
2007-01-30 21:21:06 +00:00
|
|
|
HTMLContentSink::UpdateChildCounts()
|
1999-10-26 14:55:51 +00:00
|
|
|
{
|
2009-03-20 08:15:35 +00:00
|
|
|
PRUint32 numContexts = mContextStack.Length();
|
|
|
|
for (PRUint32 i = 0; i < numContexts; i++) {
|
|
|
|
SinkContext* sc = mContextStack.ElementAt(i);
|
1999-10-26 14:55:51 +00:00
|
|
|
|
|
|
|
sc->UpdateChildCounts();
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
1999-10-26 14:55:51 +00:00
|
|
|
mCurrentContext->UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
2004-05-27 22:08:42 +00:00
|
|
|
void
|
2005-08-24 20:56:58 +00:00
|
|
|
HTMLContentSink::FlushPendingNotifications(mozFlushType aType)
|
2000-01-24 06:43:15 +00:00
|
|
|
{
|
2000-01-28 23:43:12 +00:00
|
|
|
// Only flush tags if we're not doing the notification ourselves
|
2004-05-27 22:08:42 +00:00
|
|
|
// (since we aren't reentrant)
|
2007-10-04 05:16:35 +00:00
|
|
|
if (!mInNotification) {
|
2009-05-17 14:22:55 +00:00
|
|
|
// Only flush if we're still a document observer (so that our child counts
|
|
|
|
// should be correct).
|
|
|
|
if (mIsDocumentObserver) {
|
|
|
|
if (aType >= Flush_ContentAndNotify) {
|
|
|
|
FlushTags();
|
|
|
|
}
|
|
|
|
else if (mCurrentContext) {
|
|
|
|
mCurrentContext->FlushText();
|
|
|
|
}
|
2006-11-06 23:50:33 +00:00
|
|
|
}
|
2009-04-21 23:53:52 +00:00
|
|
|
if (aType >= Flush_InterruptibleLayout) {
|
2005-08-24 20:56:58 +00:00
|
|
|
// Make sure that layout has started so that the reflow flush
|
|
|
|
// will actually happen.
|
2011-10-17 14:59:28 +00:00
|
|
|
StartLayout(true);
|
2005-08-24 20:56:58 +00:00
|
|
|
}
|
2000-01-24 06:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
1999-03-15 05:11:43 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::FlushTags()
|
|
|
|
{
|
2007-10-04 05:16:35 +00:00
|
|
|
if (!mNotifiedRootInsertion) {
|
|
|
|
NotifyRootInsertion();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
return mCurrentContext ? mCurrentContext->FlushTags() : NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:31:08 +00:00
|
|
|
NS_IMETHODIMP
|
2003-06-17 16:40:34 +00:00
|
|
|
HTMLContentSink::SetDocumentCharset(nsACString& aCharset)
|
2001-06-29 22:56:58 +00:00
|
|
|
{
|
2003-04-02 11:18:00 +00:00
|
|
|
if (mDocShell) {
|
2002-09-18 23:31:08 +00:00
|
|
|
// the following logic to get muCV is copied from
|
2002-08-26 20:13:31 +00:00
|
|
|
// nsHTMLDocument::StartDocumentLoad
|
|
|
|
// We need to call muCV->SetPrevDocCharacterSet here in case
|
|
|
|
// the charset is detected by parser DetectMetaTag
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> muCV;
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
2003-04-02 11:18:00 +00:00
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(cv));
|
2002-08-26 20:13:31 +00:00
|
|
|
if (cv) {
|
2002-09-18 23:31:08 +00:00
|
|
|
muCV = do_QueryInterface(cv);
|
2002-08-26 20:13:31 +00:00
|
|
|
} else {
|
2002-09-18 23:31:08 +00:00
|
|
|
// in this block of code, if we get an error result, we return
|
|
|
|
// it but if we get a null pointer, that's perfectly legal for
|
|
|
|
// parent and parentContentViewer
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
2003-04-02 11:18:00 +00:00
|
|
|
do_QueryInterface(mDocShell);
|
2002-08-26 20:13:31 +00:00
|
|
|
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-08-26 20:13:31 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
|
|
|
|
docShellAsItem->GetSameTypeParent(getter_AddRefs(parentAsItem));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
|
|
|
|
if (parent) {
|
|
|
|
nsCOMPtr<nsIContentViewer> parentContentViewer;
|
2002-09-18 23:31:08 +00:00
|
|
|
nsresult rv =
|
|
|
|
parent->GetContentViewer(getter_AddRefs(parentContentViewer));
|
2002-08-26 20:13:31 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && parentContentViewer) {
|
|
|
|
muCV = do_QueryInterface(parentContentViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2002-08-26 20:13:31 +00:00
|
|
|
if (muCV) {
|
2003-06-17 16:40:34 +00:00
|
|
|
muCV->SetPrevDocCharacterSet(aCharset);
|
2002-08-26 20:13:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-29 22:56:58 +00:00
|
|
|
if (mDocument) {
|
2003-10-22 06:09:48 +00:00
|
|
|
mDocument->SetDocumentCharacterSet(aCharset);
|
2001-06-29 22:56:58 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2001-06-29 22:56:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-11-02 19:52:32 +00:00
|
|
|
nsISupports *
|
|
|
|
HTMLContentSink::GetTarget()
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-04-15 22:34:50 +00:00
|
|
|
HTMLContentSink::IsScriptExecuting()
|
|
|
|
{
|
|
|
|
return IsScriptExecutingImpl();
|
|
|
|
}
|
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2000-05-26 19:45:49 +00:00
|
|
|
/**
|
|
|
|
* This will dump content model into the output file.
|
2002-09-18 23:31:08 +00:00
|
|
|
*
|
2000-05-26 19:45:49 +00:00
|
|
|
* @update harishd 05/25/00
|
2002-09-18 23:31:08 +00:00
|
|
|
* @param
|
|
|
|
* @return NS_OK all went well, error on failure
|
2000-05-26 19:45:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-09-18 23:31:08 +00:00
|
|
|
HTMLContentSink::DumpContentModel()
|
2000-05-26 19:45:49 +00:00
|
|
|
{
|
2002-09-18 23:31:08 +00:00
|
|
|
FILE* out = ::fopen("rtest_html.txt", "a");
|
|
|
|
if (out) {
|
|
|
|
if (mDocument) {
|
2010-04-30 13:12:05 +00:00
|
|
|
Element* root = mDocument->GetRootElement();
|
2002-09-18 23:31:08 +00:00
|
|
|
if (root) {
|
2004-01-09 23:54:21 +00:00
|
|
|
if (mDocumentURI) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString buf;
|
2004-01-09 23:54:21 +00:00
|
|
|
mDocumentURI->GetSpec(buf);
|
2002-09-18 23:31:08 +00:00
|
|
|
fputs(buf.get(), out);
|
2000-05-26 19:45:49 +00:00
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
|
|
|
fputs(";", out);
|
2011-10-17 14:59:28 +00:00
|
|
|
root->DumpContent(out, 0, false);
|
2002-09-18 23:31:08 +00:00
|
|
|
fputs(";\n", out);
|
2000-05-26 19:45:49 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2000-05-26 19:45:49 +00:00
|
|
|
fclose(out);
|
|
|
|
}
|
2002-09-18 23:31:08 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
return NS_OK;
|
2000-05-26 19:45:49 +00:00
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2001-06-21 02:06:23 +00:00
|
|
|
|