2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-10-05 11:29:50 +04:00
|
|
|
|
2012-03-22 10:34:29 +04: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.
|
|
|
|
*/
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
#include "nsContentSink.h"
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2001-12-17 10:14:49 +03:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIHTMLContentSink.h"
|
2000-06-16 18:54:57 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2006-11-04 08:45:02 +03:00
|
|
|
#include "nsScriptLoader.h"
|
2004-01-10 02:54:21 +03:00
|
|
|
#include "nsIURI.h"
|
1999-05-14 00:27:47 +04:00
|
|
|
#include "nsIContentViewer.h"
|
2014-06-20 06:01:40 +04:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
2013-08-12 19:28:41 +04:00
|
|
|
#include "nsToken.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsIAppShell.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "prtime.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
#include "nsIContent.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-05-25 10:32:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-10-30 13:14:06 +03:00
|
|
|
#include "nsGenericHTMLElement.h"
|
1998-09-06 04:20:59 +04:00
|
|
|
|
2005-01-12 05:47:53 +03:00
|
|
|
#include "nsIDOMDocument.h"
|
2000-03-29 03:25:26 +04:00
|
|
|
#include "nsIDOMDocumentType.h"
|
2001-05-17 09:54:16 +04:00
|
|
|
#include "nsIScriptElement.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1999-10-01 02:07:04 +04:00
|
|
|
#include "nsIServiceManager.h"
|
1998-04-23 02:12:24 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2001-02-19 15:55:42 +03:00
|
|
|
#include "nsContentUtils.h"
|
2000-04-14 06:47:28 +04:00
|
|
|
#include "nsIChannel.h"
|
2001-05-12 01:05:08 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
2000-03-11 03:34:54 +03:00
|
|
|
#include "nsIDocShell.h"
|
1999-01-19 19:58:45 +03:00
|
|
|
#include "nsIDocument.h"
|
2004-01-29 00:04:33 +03:00
|
|
|
#include "nsStubDocumentObserver.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsIHTMLDocument.h"
|
1999-01-09 03:14:53 +03:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
2000-02-05 01:50:39 +03:00
|
|
|
#include "nsICookieService.h"
|
2009-01-18 23:14:14 +03:00
|
|
|
#include "nsTArray.h"
|
1999-11-16 08:07:31 +03:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-10-07 01:13:37 +04:00
|
|
|
#include "nsIPrincipal.h"
|
1999-09-11 21:28:36 +04:00
|
|
|
#include "nsTextFragment.h"
|
1999-12-03 12:24:22 +03:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
1999-01-19 19:58:45 +03:00
|
|
|
|
1999-10-01 02:07:04 +04:00
|
|
|
#include "nsIParserService.h"
|
|
|
|
|
1999-02-23 22:18:12 +03:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
1999-12-04 04:27:46 +03:00
|
|
|
#include "nsITimer.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2000-05-25 17:29:15 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsIScriptContext.h"
|
2001-05-19 06:59:15 +04:00
|
|
|
#include "nsStyleLinkElement.h"
|
1999-09-14 18:38:52 +04:00
|
|
|
|
2002-09-19 03:31:08 +04:00
|
|
|
#include "nsWeakReference.h" // nsHTMLElementFactory supports weak references
|
2001-03-29 06:11:48 +04:00
|
|
|
#include "nsIPrompt.h"
|
2001-04-24 12:43:08 +04:00
|
|
|
#include "nsLayoutCID.h"
|
2002-08-27 00:13:31 +04:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2001-06-21 18:40:55 +04:00
|
|
|
|
|
|
|
#include "nsEscape.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2013-04-04 16:01:08 +04:00
|
|
|
#include "nsTextNode.h"
|
2002-04-19 02:11:17 +04:00
|
|
|
|
2011-05-25 10:32:00 +04:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:05 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2010-07-23 13:49:57 +04:00
|
|
|
typedef nsGenericHTMLElement*
|
2014-06-20 06:01:40 +04:00
|
|
|
(*contentCreatorCallback)(already_AddRefed<mozilla::dom::NodeInfo>&&,
|
2010-10-25 16:17:38 +04:00
|
|
|
FromParser aFromParser);
|
2003-09-24 10:16:52 +04:00
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsGenericHTMLElement*
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_NewHTMLNOTUSEDElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2010-10-25 16:17:38 +04:00
|
|
|
FromParser aFromParser)
|
2003-09-24 10:16:52 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("The element ctor should never be called");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2003-09-24 10:16:52 +04:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:45:28 +03:00
|
|
|
#define HTML_TAG(_tag, _classname, _interfacename) NS_NewHTML##_classname##Element,
|
2005-06-16 17:10:58 +04:00
|
|
|
#define HTML_OTHER(_tag) NS_NewHTMLNOTUSEDElement,
|
2003-09-24 10:16:52 +04:00
|
|
|
static const contentCreatorCallback sContentCreatorCallbacks[] = {
|
|
|
|
NS_NewHTMLUnknownElement,
|
|
|
|
#include "nsHTMLTagList.h"
|
|
|
|
#undef HTML_TAG
|
|
|
|
#undef HTML_OTHER
|
2003-09-24 11:30:16 +04:00
|
|
|
NS_NewHTMLUnknownElement
|
|
|
|
};
|
2003-09-24 10:16:52 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
class SinkContext;
|
2006-02-08 08:56:13 +03:00
|
|
|
class HTMLContentSink;
|
|
|
|
|
2012-03-22 10:34:29 +04: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 11:29:50 +04:00
|
|
|
class HTMLContentSink : public nsContentSink,
|
2007-01-31 00:21:06 +03:00
|
|
|
public nsIHTMLContentSink
|
1999-11-02 09:49:44 +03:00
|
|
|
{
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
2003-10-05 11:29:50 +04:00
|
|
|
friend class SinkContext;
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
HTMLContentSink();
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult Init(nsIDocument* aDoc, nsIURI* aURI, nsISupports* aContainer,
|
2001-03-03 03:39:29 +03:00
|
|
|
nsIChannel* aChannel);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-16 02:31:10 +04:00
|
|
|
// nsISupports
|
2003-10-05 11:29:50 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-03-31 15:35:20 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLContentSink, nsContentSink)
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-16 02:31:10 +04:00
|
|
|
// nsIContentSink
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD WillParse(void) override;
|
|
|
|
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override;
|
|
|
|
NS_IMETHOD DidBuildModel(bool aTerminated) override;
|
|
|
|
NS_IMETHOD WillInterrupt(void) override;
|
|
|
|
NS_IMETHOD WillResume(void) override;
|
|
|
|
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
2017-01-05 10:31:56 +03:00
|
|
|
virtual void FlushPendingNotifications(FlushType aType) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override;
|
|
|
|
virtual nsISupports *GetTarget() override;
|
|
|
|
virtual bool IsScriptExecuting() override;
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
// nsIHTMLContentSink
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD OpenContainer(ElementType aNodeType) override;
|
|
|
|
NS_IMETHOD CloseContainer(ElementType aTag) override;
|
2000-09-01 22:17:43 +04:00
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~HTMLContentSink();
|
|
|
|
|
2010-03-31 15:35:20 +04:00
|
|
|
nsCOMPtr<nsIHTMLDocument> mHTMLDocument;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-09-19 03:31:08 +04:00
|
|
|
// The maximum length of a text run
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mMaxTextRun;
|
2000-02-01 02:39:19 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> mRoot;
|
|
|
|
RefPtr<nsGenericHTMLElement> mBody;
|
|
|
|
RefPtr<nsGenericHTMLElement> mHead;
|
2004-09-18 00:11:02 +04:00
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<SinkContext*, 8> mContextStack;
|
1998-08-28 20:20:16 +04:00
|
|
|
SinkContext* mCurrentContext;
|
|
|
|
SinkContext* mHeadContext;
|
1998-07-20 22:52:40 +04:00
|
|
|
|
2006-01-27 04:13:00 +03:00
|
|
|
// Boolean indicating whether we've seen a <head> tag that might have had
|
|
|
|
// attributes once already.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHaveSeenHead;
|
2006-01-27 04:13:00 +03:00
|
|
|
|
2007-02-02 05:12:48 +03: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 10:19:26 +04:00
|
|
|
bool mNotifiedRootInsertion;
|
2007-02-02 05:12:48 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
nsresult FlushTags() override;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
// Routines for tags that require special handling
|
2005-10-21 19:39:06 +04:00
|
|
|
nsresult CloseHTML();
|
2013-08-17 19:39:34 +04:00
|
|
|
nsresult OpenBody();
|
2005-10-21 19:39:06 +04:00
|
|
|
nsresult CloseBody();
|
1998-12-15 09:10:59 +03:00
|
|
|
|
2005-10-21 19:39:06 +04:00
|
|
|
void CloseHeadContext();
|
2003-10-05 11:29:50 +04:00
|
|
|
|
|
|
|
// nsContentSink overrides
|
2015-03-21 19:28:04 +03:00
|
|
|
void UpdateChildCounts() override;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
1999-10-26 18:55:51 +04:00
|
|
|
void NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndexInContainer);
|
2007-10-04 09:16:35 +04:00
|
|
|
void NotifyRootInsertion();
|
2001-06-21 06:06:23 +04:00
|
|
|
};
|
|
|
|
|
2002-09-19 03:31:08 +04:00
|
|
|
class SinkContext
|
|
|
|
{
|
1998-08-28 20:20:16 +04:00
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit SinkContext(HTMLContentSink* aSink);
|
1998-08-28 20:20:16 +04:00
|
|
|
~SinkContext();
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsresult Begin(nsHTMLTag aNodeType, nsGenericHTMLElement* aRoot,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aNumFlushed, int32_t aInsertionPoint);
|
2013-08-17 19:39:34 +04:00
|
|
|
nsresult OpenBody();
|
2013-08-17 23:26:48 +04:00
|
|
|
nsresult CloseBody();
|
1998-08-28 20:20:16 +04:00
|
|
|
nsresult End();
|
1998-06-28 02:57:52 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
nsresult GrowStack();
|
2006-11-07 02:50:33 +03:00
|
|
|
nsresult FlushTags();
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsCurrentContainer(nsHTMLTag mType);
|
1999-04-14 02:22:51 +04:00
|
|
|
|
2006-06-08 08:38:44 +04:00
|
|
|
void DidAddContent(nsIContent* aContent);
|
1999-10-26 18:55:51 +04:00
|
|
|
void UpdateChildCounts();
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2005-09-22 06:33:36 +04: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 10:19:26 +04:00
|
|
|
bool HaveNotifiedForCurrentContent() const;
|
2016-07-21 01:19:00 +03:00
|
|
|
|
2005-09-22 06:33:36 +04:00
|
|
|
public:
|
1998-08-28 20:20:16 +04:00
|
|
|
HTMLContentSink* mSink;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mNotifyLevel;
|
1998-06-28 02:57:52 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
struct Node {
|
|
|
|
nsHTMLTag mType;
|
2005-01-12 22:45:38 +03:00
|
|
|
nsGenericHTMLElement* mContent;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mNumFlushed;
|
|
|
|
int32_t mInsertionPoint;
|
2008-10-12 21:44:23 +04:00
|
|
|
|
|
|
|
nsIContent *Add(nsIContent *child);
|
1998-08-28 20:20:16 +04:00
|
|
|
};
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
Node* mStack;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mStackSize;
|
|
|
|
int32_t mStackPos;
|
1998-08-28 20:20:16 +04:00
|
|
|
};
|
1998-06-28 02:57:52 +04:00
|
|
|
|
2000-12-10 12:20:40 +03:00
|
|
|
nsresult
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_NewHTMLElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2016-09-01 13:08:50 +03:00
|
|
|
FromParser aFromParser, const nsAString* aIs)
|
2000-12-10 12:20:40 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2004-06-25 16:26:02 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo = aNodeInfo;
|
2010-07-23 13:49:57 +04:00
|
|
|
|
2005-09-11 14:08:43 +04:00
|
|
|
nsIParserService* parserService = nsContentUtils::GetParserService();
|
2002-11-19 16:39:20 +03:00
|
|
|
if (!parserService)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-12-10 12:20:40 +03:00
|
|
|
|
2010-07-23 13:49:57 +04:00
|
|
|
nsIAtom *name = nodeInfo->NameAtom();
|
2001-11-28 09:13:11 +03:00
|
|
|
|
2016-07-21 01:19:00 +03:00
|
|
|
NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
|
2009-06-09 11:41:19 +04:00
|
|
|
"Trying to HTML elements that don't have the XHTML namespace");
|
2014-02-24 01:01:26 +04:00
|
|
|
|
2016-12-08 22:33:44 +03:00
|
|
|
int32_t tag = parserService->HTMLCaseSensitiveAtomTagToId(name);
|
|
|
|
|
2014-02-24 01:01:26 +04:00
|
|
|
// Per the Custom Element specification, unknown tags that are valid custom
|
|
|
|
// element names should be HTMLElement instead of HTMLUnknownElement.
|
2016-12-08 22:33:44 +03:00
|
|
|
bool isCustomElementName = (tag == eHTMLTag_userdefined &&
|
|
|
|
nsContentUtils::IsCustomElementName(name));
|
|
|
|
if (isCustomElementName) {
|
2014-02-24 01:01:26 +04:00
|
|
|
NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser));
|
2016-12-08 22:33:44 +03:00
|
|
|
} else {
|
|
|
|
*aResult = CreateHTMLElement(tag, nodeInfo.forget(), aFromParser).take();
|
|
|
|
}
|
2014-02-24 01:01:26 +04:00
|
|
|
|
2016-12-08 22:33:44 +03:00
|
|
|
if (!*aResult) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-02-24 01:01:26 +04:00
|
|
|
|
2016-12-08 22:33:44 +03:00
|
|
|
if (isCustomElementName || aIs) {
|
|
|
|
nsContentUtils::SetupCustomElement(*aResult, aIs);
|
2014-02-24 01:01:26 +04:00
|
|
|
}
|
|
|
|
|
2016-12-08 22:33:44 +03:00
|
|
|
return NS_OK;
|
2000-12-10 12:20:40 +03:00
|
|
|
}
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
2014-03-15 23:00:17 +04:00
|
|
|
CreateHTMLElement(uint32_t aNodeType,
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2010-10-25 16:17:38 +04:00
|
|
|
FromParser aFromParser)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2006-10-17 01:43:08 +04:00
|
|
|
NS_ASSERTION(aNodeType <= NS_HTML_TAG_MAX ||
|
|
|
|
aNodeType == eHTMLTag_userdefined,
|
|
|
|
"aNodeType is out of bounds");
|
2006-10-14 02:54:12 +04:00
|
|
|
|
2004-06-02 04:25:00 +04:00
|
|
|
contentCreatorCallback cb = sContentCreatorCallbacks[aNodeType];
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2004-06-02 04:25:00 +04:00
|
|
|
NS_ASSERTION(cb != NS_NewHTMLNOTUSEDElement,
|
|
|
|
"Don't know how to construct tag element!");
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> result = cb(Move(aNodeInfo), aFromParser);
|
2004-06-06 06:38:32 +04:00
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return result.forget();
|
1998-09-01 05:37:17 +04:00
|
|
|
}
|
|
|
|
|
1999-05-06 23:26:43 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
SinkContext::SinkContext(HTMLContentSink* aSink)
|
2005-04-07 07:30:50 +04:00
|
|
|
: mSink(aSink),
|
|
|
|
mNotifyLevel(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mStack(nullptr),
|
2005-04-07 07:30:50 +04:00
|
|
|
mStackSize(0),
|
2013-08-17 22:42:20 +04:00
|
|
|
mStackPos(0)
|
1998-08-28 20:20:16 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(SinkContext);
|
1998-08-28 20:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SinkContext::~SinkContext()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(SinkContext);
|
2002-09-19 03:31:08 +04:00
|
|
|
|
|
|
|
if (mStack) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < mStackPos; i++) {
|
1998-08-28 20:20:16 +04:00
|
|
|
NS_RELEASE(mStack[i].mContent);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-08-28 20:20:16 +04:00
|
|
|
delete [] mStack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-09-19 03:31:08 +04:00
|
|
|
SinkContext::Begin(nsHTMLTag aNodeType,
|
2005-01-12 22:45:38 +03:00
|
|
|
nsGenericHTMLElement* aRoot,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aNumFlushed,
|
|
|
|
int32_t aInsertionPoint)
|
1998-08-28 20:20:16 +04:00
|
|
|
{
|
2002-09-19 03:31:08 +04:00
|
|
|
if (mStackSize < 1) {
|
1998-08-28 20:20:16 +04:00
|
|
|
nsresult rv = GrowStack();
|
2002-09-19 03:31:08 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 20:20:16 +04:00
|
|
|
return rv;
|
1998-08-08 03:08:00 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
mStack[0].mType = aNodeType;
|
|
|
|
mStack[0].mContent = aRoot;
|
1999-10-26 18:55:51 +04:00
|
|
|
mStack[0].mNumFlushed = aNumFlushed;
|
|
|
|
mStack[0].mInsertionPoint = aInsertionPoint;
|
1998-08-28 20:20:16 +04:00
|
|
|
NS_ADDREF(aRoot);
|
|
|
|
mStackPos = 1;
|
|
|
|
|
1998-07-16 02:31:10 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
1999-04-14 02:22:51 +04:00
|
|
|
SinkContext::IsCurrentContainer(nsHTMLTag aTag)
|
|
|
|
{
|
2002-09-19 03:31:08 +04:00
|
|
|
if (aTag == mStack[mStackPos - 1].mType) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1999-04-14 02:22:51 +04:00
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1999-04-14 02:22:51 +04:00
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
void
|
2006-06-08 08:38:44 +04:00
|
|
|
SinkContext::DidAddContent(nsIContent* aContent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2012-01-25 11:48:59 +04:00
|
|
|
if ((mStackPos == 2) && (mSink->mBody == mStack[1].mContent)) {
|
1998-08-28 20:20:16 +04:00
|
|
|
// We just finished adding something to the body
|
1999-10-26 18:55:51 +04:00
|
|
|
mNotifyLevel = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-10-26 18:55:51 +04:00
|
|
|
// If we just added content to a node for which
|
2002-09-19 03:31:08 +04:00
|
|
|
// an insertion happen, we need to do an immediate
|
1999-10-26 18:55:51 +04:00
|
|
|
// notification for that insertion.
|
2006-06-08 08:38:44 +04:00
|
|
|
if (0 < mStackPos &&
|
|
|
|
mStack[mStackPos - 1].mInsertionPoint != -1 &&
|
|
|
|
mStack[mStackPos - 1].mNumFlushed <
|
|
|
|
mStack[mStackPos - 1].mContent->GetChildCount()) {
|
2002-09-19 03:31:08 +04:00
|
|
|
nsIContent* parent = mStack[mStackPos - 1].mContent;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t childIndex = mStack[mStackPos - 1].mInsertionPoint - 1;
|
2008-10-12 21:44:23 +04:00
|
|
|
NS_ASSERTION(parent->GetChildAt(childIndex) == aContent,
|
|
|
|
"Flushing the wrong child.");
|
|
|
|
mSink->NotifyInsert(parent, aContent, childIndex);
|
2003-09-27 08:18:26 +04:00
|
|
|
mStack[mStackPos - 1].mNumFlushed = parent->GetChildCount();
|
2006-06-08 08:38:44 +04:00
|
|
|
} else if (mSink->IsTimeToNotify()) {
|
2006-11-07 02:50:33 +03:00
|
|
|
FlushTags();
|
1999-12-04 04:27:46 +03:00
|
|
|
}
|
1999-01-13 02:49:13 +03:00
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
nsresult
|
2013-08-17 19:39:34 +04:00
|
|
|
SinkContext::OpenBody()
|
1998-07-20 22:52:40 +04:00
|
|
|
{
|
2006-04-08 04:32:03 +04:00
|
|
|
if (mStackPos <= 0) {
|
|
|
|
NS_ERROR("container w/o parent");
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
nsresult rv;
|
|
|
|
if (mStackPos + 1 > mStackSize) {
|
|
|
|
rv = GrowStack();
|
2002-09-19 03:31:08 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 20:20:16 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1998-07-20 22:52:40 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo =
|
2013-08-17 19:39:34 +04:00
|
|
|
mSink->mNodeInfoManager->GetNodeInfo(nsGkAtoms::body, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// Make the content object
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> body =
|
2013-08-17 19:39:34 +04:00
|
|
|
NS_NewHTMLBodyElement(nodeInfo.forget(), FROM_PARSER_NETWORK);
|
|
|
|
if (!body) {
|
2004-06-06 06:38:32 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-08-31 15:17:26 +04:00
|
|
|
|
2013-08-17 19:39:34 +04:00
|
|
|
mStack[mStackPos].mType = eHTMLTag_body;
|
|
|
|
body.forget(&mStack[mStackPos].mContent);
|
1999-10-26 18:55:51 +04:00
|
|
|
mStack[mStackPos].mNumFlushed = 0;
|
|
|
|
mStack[mStackPos].mInsertionPoint = -1;
|
2006-04-08 04:32:03 +04:00
|
|
|
++mStackPos;
|
2013-08-17 19:39:34 +04:00
|
|
|
mStack[mStackPos - 2].Add(mStack[mStackPos - 1].mContent);
|
1998-07-20 22:52:40 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2005-09-22 06:33:36 +04:00
|
|
|
SinkContext::HaveNotifiedForCurrentContent() const
|
|
|
|
{
|
|
|
|
if (0 < mStackPos) {
|
|
|
|
nsIContent* parent = mStack[mStackPos - 1].mContent;
|
|
|
|
return mStack[mStackPos-1].mNumFlushed == parent->GetChildCount();
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2005-09-22 06:33:36 +04:00
|
|
|
}
|
|
|
|
|
2008-10-12 21:44:23 +04:00
|
|
|
nsIContent *
|
|
|
|
SinkContext::Node::Add(nsIContent *child)
|
|
|
|
{
|
2008-12-20 03:49:08 +03:00
|
|
|
NS_ASSERTION(mContent, "No parent to insert/append into!");
|
2008-10-12 21:44:23 +04:00
|
|
|
if (mInsertionPoint != -1) {
|
|
|
|
NS_ASSERTION(mNumFlushed == mContent->GetChildCount(),
|
|
|
|
"Inserting multiple children without flushing.");
|
2011-10-17 18:59:28 +04:00
|
|
|
mContent->InsertChildAt(child, mInsertionPoint++, false);
|
2008-10-12 21:44:23 +04:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mContent->AppendChildTo(child, false);
|
2008-10-12 21:44:23 +04:00
|
|
|
}
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
nsresult
|
2013-08-17 23:26:48 +04:00
|
|
|
SinkContext::CloseBody()
|
1998-07-20 22:52:40 +04:00
|
|
|
{
|
2006-03-30 22:40:56 +04:00
|
|
|
NS_ASSERTION(mStackPos > 0,
|
|
|
|
"stack out of bounds. wrong context probably!");
|
2000-07-28 05:01:08 +04:00
|
|
|
|
2002-09-19 03:31:08 +04:00
|
|
|
if (mStackPos <= 0) {
|
2000-07-28 05:01:08 +04:00
|
|
|
return NS_OK; // Fix crash - Ref. bug 45975 or 45007
|
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
--mStackPos;
|
2013-08-17 23:26:48 +04:00
|
|
|
NS_ASSERTION(mStack[mStackPos].mType == eHTMLTag_body,
|
2006-06-08 08:29:28 +04:00
|
|
|
"Tag mismatch. Closing tag on wrong context or something?");
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsGenericHTMLElement* content = mStack[mStackPos].mContent;
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2008-02-03 02:41:24 +03:00
|
|
|
content->Compact();
|
1998-07-20 22:52:40 +04:00
|
|
|
|
1999-10-26 18:55:51 +04: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-19 03:31:08 +04:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
if (mStack[mStackPos].mNumFlushed < content->GetChildCount()) {
|
1999-10-26 18:55:51 +04:00
|
|
|
mSink->NotifyAppend(content, mStack[mStackPos].mNumFlushed);
|
2006-06-08 08:38:44 +04:00
|
|
|
mStack[mStackPos].mNumFlushed = content->GetChildCount();
|
1999-10-26 18:55:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate that notification has now happened at this level
|
2002-09-19 03:31:08 +04:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1998-08-28 20:20:16 +04:00
|
|
|
}
|
1999-10-26 18:55:51 +04:00
|
|
|
|
2006-06-08 08:38:44 +04:00
|
|
|
DidAddContent(content);
|
1999-11-12 01:15:02 +03:00
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
|
2013-08-17 23:26:48 +04:00
|
|
|
return NS_OK;
|
1999-07-23 03:28:16 +04:00
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
nsresult
|
|
|
|
SinkContext::End()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < mStackPos; i++) {
|
1998-08-28 20:20:16 +04:00
|
|
|
NS_RELEASE(mStack[i].mContent);
|
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
mStackPos = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
nsresult
|
|
|
|
SinkContext::GrowStack()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newSize = mStackSize * 2;
|
2002-09-19 03:31:08 +04:00
|
|
|
if (newSize == 0) {
|
1998-08-28 20:20:16 +04:00
|
|
|
newSize = 32;
|
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
Node* stack = new Node[newSize];
|
2002-09-19 03:31:08 +04:00
|
|
|
|
|
|
|
if (mStackPos != 0) {
|
1998-08-28 20:20:16 +04:00
|
|
|
memcpy(stack, mStack, sizeof(Node) * mStackPos);
|
|
|
|
delete [] mStack;
|
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
mStack = stack;
|
|
|
|
mStackSize = newSize;
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-11-29 02:51:06 +03:00
|
|
|
/**
|
2007-01-31 00:21:06 +03:00
|
|
|
* NOTE!! Forked into nsXMLContentSink. Please keep in sync.
|
|
|
|
*
|
1998-11-29 02:51:06 +03: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 18:55:51 +04:00
|
|
|
* Also, do notification at the top for all content that
|
|
|
|
* has been newly added so that the frame tree is complete.
|
1998-11-29 02:51:06 +03:00
|
|
|
*/
|
|
|
|
nsresult
|
2006-11-07 02:50:33 +03:00
|
|
|
SinkContext::FlushTags()
|
1998-11-29 02:51:06 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mSink->mDeferredFlushTags = false;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool oldBeganUpdate = mSink->mBeganUpdate;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t oldUpdates = mSink->mUpdatesInNotification;
|
2007-03-10 02:43:50 +03:00
|
|
|
|
2006-11-07 02:50:33 +03:00
|
|
|
++(mSink->mInNotification);
|
2007-05-18 03:54:35 +04:00
|
|
|
mSink->mUpdatesInNotification = 0;
|
2007-04-07 04:20:09 +04:00
|
|
|
{
|
|
|
|
// Scope so we call EndUpdate before we decrease mInNotification
|
|
|
|
mozAutoDocUpdate updateBatch(mSink->mDocument, UPDATE_CONTENT_MODEL,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
|
|
|
mSink->mBeganUpdate = true;
|
2007-04-07 04:20:09 +04:00
|
|
|
|
|
|
|
// 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).
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t stackPos = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool flushed = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount;
|
2007-04-07 04:20:09 +04:00
|
|
|
nsGenericHTMLElement* content;
|
|
|
|
|
|
|
|
while (stackPos < mStackPos) {
|
|
|
|
content = mStack[stackPos].mContent;
|
|
|
|
childCount = content->GetChildCount();
|
|
|
|
|
|
|
|
if (!flushed && (mStack[stackPos].mNumFlushed < childCount)) {
|
2009-08-14 00:27:37 +04: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.
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t childIndex = mStack[stackPos].mInsertionPoint - 1;
|
2009-08-14 00:27:37 +04: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 21:44:23 +04:00
|
|
|
"Flushing the wrong child.");
|
|
|
|
mSink->NotifyInsert(content, child, childIndex);
|
2007-04-07 04:20:09 +04:00
|
|
|
} else {
|
|
|
|
mSink->NotifyAppend(content, mStack[stackPos].mNumFlushed);
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
flushed = true;
|
2002-09-19 03:31:08 +04:00
|
|
|
}
|
|
|
|
|
2007-04-07 04:20:09 +04:00
|
|
|
mStack[stackPos].mNumFlushed = childCount;
|
|
|
|
stackPos++;
|
2000-01-29 02:43:12 +03:00
|
|
|
}
|
2007-04-07 04:20:09 +04:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1999-10-26 18:55:51 +04:00
|
|
|
}
|
2006-11-07 02:50:33 +03:00
|
|
|
--(mSink->mInNotification);
|
1999-10-26 18:55:51 +04:00
|
|
|
|
2007-05-18 03:54:35 +04:00
|
|
|
if (mSink->mUpdatesInNotification > 1) {
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
mSink->mUpdatesInNotification = oldUpdates;
|
2007-03-10 02:43:50 +03:00
|
|
|
mSink->mBeganUpdate = oldBeganUpdate;
|
|
|
|
|
2005-04-07 07:30:50 +04:00
|
|
|
return NS_OK;
|
1999-10-26 18:55:51 +04:00
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
/**
|
|
|
|
* NOTE!! Forked into nsXMLContentSink. Please keep in sync.
|
|
|
|
*/
|
1999-10-26 18:55:51 +04:00
|
|
|
void
|
|
|
|
SinkContext::UpdateChildCounts()
|
|
|
|
{
|
2002-09-19 03:31:08 +04: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-13 00:36:39 +04:00
|
|
|
// further reflows occur. Note that we have to include stackPos == 0
|
|
|
|
// to properly notify on kids of <html>.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t stackPos = mStackPos - 1;
|
2006-05-13 00:36:39 +04:00
|
|
|
while (stackPos >= 0) {
|
2005-04-07 07:30:50 +04:00
|
|
|
Node & node = mStack[stackPos];
|
|
|
|
node.mNumFlushed = node.mContent->GetChildCount();
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1999-10-26 18:55:51 +04:00
|
|
|
stackPos--;
|
|
|
|
}
|
2000-03-10 05:00:42 +03:00
|
|
|
|
2002-09-19 03:31:08 +04:00
|
|
|
mNotifyLevel = mStackPos - 1;
|
1998-11-29 02:51:06 +03:00
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewHTMLContentSink(nsIHTMLContentSink** aResult,
|
|
|
|
nsIDocument* aDoc,
|
2004-01-10 02:54:21 +03:00
|
|
|
nsIURI* aURI,
|
2003-04-02 15:18:00 +04:00
|
|
|
nsISupports* aContainer,
|
2001-03-03 03:39:29 +03:00
|
|
|
nsIChannel* aChannel)
|
1998-08-28 20:20:16 +04:00
|
|
|
{
|
2002-09-19 03:31:08 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLContentSink> it = new HTMLContentSink();
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult rv = it->Init(aDoc, aURI, aContainer, aChannel);
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-09-19 03:31:08 +04:00
|
|
|
|
|
|
|
*aResult = it;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-28 20:20:16 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-09-19 03:31:08 +04:00
|
|
|
HTMLContentSink::HTMLContentSink()
|
2017-01-24 19:10:39 +03:00
|
|
|
: mMaxTextRun(0)
|
|
|
|
, mCurrentContext(nullptr)
|
|
|
|
, mHeadContext(nullptr)
|
|
|
|
, mHaveSeenHead(false)
|
|
|
|
, mNotifiedRootInsertion(false)
|
2002-09-19 03:31:08 +04:00
|
|
|
{
|
1998-08-28 20:20:16 +04:00
|
|
|
}
|
1998-04-23 03:24:43 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
HTMLContentSink::~HTMLContentSink()
|
|
|
|
{
|
1999-12-04 04:27:46 +03:00
|
|
|
if (mNotificationTimer) {
|
|
|
|
mNotificationTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t numContexts = mContextStack.Length();
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
if (mCurrentContext == mHeadContext && numContexts > 0) {
|
1999-11-19 07:02:23 +03:00
|
|
|
// Pop off the second html context if it's not done earlier
|
|
|
|
mContextStack.RemoveElementAt(--numContexts);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i;
|
2006-10-05 02:02:17 +04:00
|
|
|
for (i = 0; i < numContexts; i++) {
|
2009-03-20 11:15:35 +03:00
|
|
|
SinkContext* sc = mContextStack.ElementAt(i);
|
2002-09-19 03:31:08 +04:00
|
|
|
if (sc) {
|
1999-11-19 07:02:23 +03:00
|
|
|
sc->End();
|
|
|
|
if (sc == mCurrentContext) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurrentContext = nullptr;
|
1999-11-19 07:02:23 +03:00
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1999-11-19 07:02:23 +03:00
|
|
|
delete sc;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-26 18:55:51 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
if (mCurrentContext == mHeadContext) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurrentContext = nullptr;
|
1998-08-28 20:20:16 +04:00
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
|
|
|
delete mCurrentContext;
|
|
|
|
|
|
|
|
delete mHeadContext;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLContentSink)
|
|
|
|
|
2010-03-31 15:35:20 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLContentSink, nsContentSink)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mHTMLDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBody)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mHead)
|
2010-03-31 15:35:20 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLContentSink,
|
|
|
|
nsContentSink)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHTMLDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBody)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHead)
|
2010-03-31 15:35:20 +04:00
|
|
|
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)
|
|
|
|
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 20:20:16 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::Init(nsIDocument* aDoc,
|
2004-01-10 02:54:21 +03:00
|
|
|
nsIURI* aURI,
|
2003-04-02 15:18:00 +04:00
|
|
|
nsISupports* aContainer,
|
2001-03-03 03:39:29 +03:00
|
|
|
nsIChannel* aChannel)
|
2002-09-19 03:31:08 +04:00
|
|
|
{
|
2003-10-05 11:29:50 +04:00
|
|
|
NS_ENSURE_TRUE(aContainer, NS_ERROR_NULL_POINTER);
|
2016-07-21 01:19:00 +03:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult rv = nsContentSink::Init(aDoc, aURI, aContainer, aChannel);
|
2005-09-16 03:17:17 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-10-05 11:29:50 +04:00
|
|
|
return rv;
|
1998-08-31 21:51:32 +04:00
|
|
|
}
|
|
|
|
|
2000-01-29 02:43:12 +03:00
|
|
|
aDoc->AddObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDocumentObserver = true;
|
2010-03-31 15:35:20 +04:00
|
|
|
mHTMLDocument = do_QueryInterface(aDoc);
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2006-03-30 22:40:56 +04:00
|
|
|
NS_ASSERTION(mDocShell, "oops no docshell!");
|
2003-04-02 15:18:00 +04:00
|
|
|
|
2002-09-19 03:31:08 +04:00
|
|
|
// Changed from 8192 to greatly improve page loading performance on
|
|
|
|
// large pages. See bugzilla bug 77540.
|
2011-05-25 10:32:00 +04:00
|
|
|
mMaxTextRun = Preferences::GetInt("content.maxtextrun", 8191);
|
2000-02-01 02:39:19 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-07-30 18:20:58 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::html, nullptr,
|
2011-06-14 11:56:49 +04:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2000-05-10 17:13:39 +04:00
|
|
|
|
1998-07-30 20:06:22 +04:00
|
|
|
// Make root part
|
2010-07-23 13:49:57 +04:00
|
|
|
mRoot = NS_NewHTMLHtmlElement(nodeInfo.forget());
|
2010-04-30 17:12:05 +04:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-06-28 02:57:52 +04:00
|
|
|
}
|
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
NS_ASSERTION(mDocument->GetChildCount() == 0,
|
|
|
|
"Document should have no kids here!");
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = mDocument->AppendChildTo(mRoot, false);
|
2010-04-30 17:12:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
// Make head part
|
2008-09-13 02:32:18 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::head,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, kNameSpaceID_XHTML,
|
2011-06-14 11:56:49 +04:00
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2000-05-10 17:13:39 +04:00
|
|
|
|
2010-07-23 13:49:57 +04:00
|
|
|
mHead = NS_NewHTMLHeadElement(nodeInfo.forget());
|
2002-09-19 03:31:08 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2004-06-06 06:38:32 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-07-30 20:06:22 +04:00
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mRoot->AppendChildTo(mHead, false);
|
1998-07-30 20:06:22 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
mCurrentContext = new SinkContext(this);
|
1999-10-26 18:55:51 +04:00
|
|
|
mCurrentContext->Begin(eHTMLTag_html, mRoot, 0, -1);
|
1998-08-28 20:20:16 +04:00
|
|
|
mContextStack.AppendElement(mCurrentContext);
|
|
|
|
|
1998-07-16 02:31:10 +04:00
|
|
|
return NS_OK;
|
1998-06-28 02:57:52 +04:00
|
|
|
}
|
|
|
|
|
2008-10-31 00:31:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillParse(void)
|
|
|
|
{
|
|
|
|
return WillParseImpl();
|
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
NS_IMETHODIMP
|
2009-06-24 01:22:16 +04:00
|
|
|
HTMLContentSink::WillBuildModel(nsDTDMode aDTDMode)
|
1998-08-28 20:20:16 +04:00
|
|
|
{
|
2007-01-31 00:21:06 +03:00
|
|
|
WillBuildModelImpl();
|
2009-06-24 01:22:16 +04:00
|
|
|
|
2001-12-08 00:53:39 +03:00
|
|
|
if (mHTMLDocument) {
|
2002-06-26 01:16:17 +04:00
|
|
|
nsCompatibility mode = eCompatibility_NavQuirks;
|
2009-06-24 01:22:16 +04:00
|
|
|
switch (aDTDMode) {
|
|
|
|
case eDTDMode_full_standards:
|
|
|
|
mode = eCompatibility_FullStandards;
|
|
|
|
break;
|
|
|
|
case eDTDMode_almost_standards:
|
|
|
|
mode = eCompatibility_AlmostStandards;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2002-06-26 01:16:17 +04:00
|
|
|
}
|
|
|
|
mHTMLDocument->SetCompatibilityMode(mode);
|
2001-12-08 00:53:39 +03:00
|
|
|
}
|
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
// Notify document that the load is beginning
|
|
|
|
mDocument->BeginLoad();
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-28 02:57:52 +04:00
|
|
|
|
1998-07-16 02:31:10 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HTMLContentSink::DidBuildModel(bool aTerminated)
|
1998-07-01 03:51:53 +04:00
|
|
|
{
|
2009-10-02 15:13:59 +04:00
|
|
|
DidBuildModelImpl(aTerminated);
|
1998-08-10 21:39:48 +04:00
|
|
|
|
1998-08-31 21:51:32 +04:00
|
|
|
// Reflow the last batch of content
|
2012-01-25 11:48:59 +04:00
|
|
|
if (mBody) {
|
2006-11-07 02:50:33 +03:00
|
|
|
mCurrentContext->FlushTags();
|
2002-09-19 03:31:08 +04:00
|
|
|
} else if (!mLayoutStarted) {
|
2001-04-10 04:49:49 +04:00
|
|
|
// We never saw the body, and layout never got started. Force
|
|
|
|
// layout *now*, to get an initial reflow.
|
2002-09-19 03:31:08 +04:00
|
|
|
// NOTE: only force the layout if we are NOT destroying the
|
2003-04-02 15:18:00 +04:00
|
|
|
// docshell. If we are destroying it, then starting layout will
|
2002-09-19 03:31:08 +04: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 10:19:26 +04:00
|
|
|
bool bDestroying = true;
|
2003-04-02 15:18:00 +04:00
|
|
|
if (mDocShell) {
|
|
|
|
mDocShell->IsBeingDestroyed(&bDestroying);
|
2001-12-07 03:02:03 +03:00
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2001-12-07 03:02:03 +03:00
|
|
|
if (!bDestroying) {
|
2011-10-17 18:59:28 +04:00
|
|
|
StartLayout(false);
|
2001-12-07 03:02:03 +03:00
|
|
|
}
|
2001-04-10 04:49:49 +04:00
|
|
|
}
|
2000-10-19 00:37:54 +04:00
|
|
|
|
2007-02-03 03:48:29 +03:00
|
|
|
ScrollToRef();
|
1998-08-28 20:20:16 +04:00
|
|
|
|
2006-06-20 01:10:29 +04: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 18:22:55 +04:00
|
|
|
// just to make sure we no longer notify... Or is the mIsDocumentObserver
|
|
|
|
// thing sufficient?
|
2006-06-20 01:10:29 +04:00
|
|
|
mDocument->RemoveObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDocumentObserver = false;
|
2016-07-21 01:19:00 +03:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
mDocument->EndLoad();
|
2000-09-20 02:35:50 +04:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
DropParserAndPerfHint();
|
2000-04-05 08:02:38 +04:00
|
|
|
|
1998-07-16 02:31:10 +04:00
|
|
|
return NS_OK;
|
1998-06-28 02:57:52 +04:00
|
|
|
}
|
|
|
|
|
1998-12-11 20:02:37 +03:00
|
|
|
NS_IMETHODIMP
|
2012-01-20 15:16:27 +04:00
|
|
|
HTMLContentSink::SetParser(nsParserBase* aParser)
|
1998-12-11 20:02:37 +03:00
|
|
|
{
|
2007-04-27 08:05:08 +04:00
|
|
|
NS_PRECONDITION(aParser, "Should have a parser here!");
|
1998-12-11 20:02:37 +03:00
|
|
|
mParser = aParser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-21 19:39:06 +04:00
|
|
|
nsresult
|
2002-11-19 21:29:35 +03:00
|
|
|
HTMLContentSink::CloseHTML()
|
1998-08-28 20:20:16 +04:00
|
|
|
{
|
2002-09-19 03:31:08 +04:00
|
|
|
if (mHeadContext) {
|
|
|
|
if (mCurrentContext == mHeadContext) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numContexts = mContextStack.Length();
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1999-12-10 06:36:50 +03:00
|
|
|
// Pop off the second html context if it's not done earlier
|
2009-03-20 11:15:35 +03:00
|
|
|
mCurrentContext = mContextStack.ElementAt(--numContexts);
|
2000-01-29 02:43:12 +03:00
|
|
|
mContextStack.RemoveElementAt(numContexts);
|
1999-12-10 06:36:50 +03:00
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
mHeadContext->End();
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
delete mHeadContext;
|
2012-07-30 18:20:58 +04:00
|
|
|
mHeadContext = nullptr;
|
1998-08-28 20:20:16 +04:00
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-21 19:39:06 +04:00
|
|
|
nsresult
|
2013-08-17 19:39:34 +04:00
|
|
|
HTMLContentSink::OpenBody()
|
1998-08-28 20:20:16 +04:00
|
|
|
{
|
2003-01-09 21:29:23 +03:00
|
|
|
CloseHeadContext(); // do this just in case if the HEAD was left open!
|
|
|
|
|
2013-08-17 03:51:58 +04:00
|
|
|
// if we already have a body we're done
|
2002-09-19 03:31:08 +04:00
|
|
|
if (mBody) {
|
1999-04-06 00:53:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2013-08-17 19:39:34 +04:00
|
|
|
nsresult rv = mCurrentContext->OpenBody();
|
2002-09-19 03:31:08 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
1998-08-28 20:20:16 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
mBody = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2003-10-11 04:27:45 +04:00
|
|
|
if (mCurrentContext->mStackPos > 1) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t parentIndex = mCurrentContext->mStackPos - 2;
|
2005-01-12 22:45:38 +03:00
|
|
|
nsGenericHTMLElement *parent = mCurrentContext->mStack[parentIndex].mContent;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t numFlushed = mCurrentContext->mStack[parentIndex].mNumFlushed;
|
|
|
|
int32_t childCount = parent->GetChildCount();
|
2006-05-13 00:36:39 +04:00
|
|
|
NS_ASSERTION(numFlushed < childCount, "Already notified on the body?");
|
2016-07-21 01:19:00 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t insertionPoint =
|
2002-09-19 03:31:08 +04:00
|
|
|
mCurrentContext->mStack[parentIndex].mInsertionPoint;
|
2002-09-06 09:44:31 +04:00
|
|
|
|
|
|
|
// XXX: I have yet to see a case where numFlushed is non-zero and
|
2002-09-19 03:31:08 +04:00
|
|
|
// insertionPoint is not -1, but this code will try to handle
|
|
|
|
// those cases too.
|
2002-09-06 09:44:31 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t oldUpdates = mUpdatesInNotification;
|
2008-08-25 21:21:29 +04:00
|
|
|
mUpdatesInNotification = 0;
|
2002-09-06 09:44:31 +04:00
|
|
|
if (insertionPoint != -1) {
|
|
|
|
NotifyInsert(parent, mBody, insertionPoint - 1);
|
2002-09-19 03:31:08 +04:00
|
|
|
} else {
|
2002-09-06 09:44:31 +04:00
|
|
|
NotifyAppend(parent, numFlushed);
|
|
|
|
}
|
2006-05-13 00:36:39 +04:00
|
|
|
mCurrentContext->mStack[parentIndex].mNumFlushed = childCount;
|
2008-08-25 21:21:29 +04:00
|
|
|
if (mUpdatesInNotification > 1) {
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
mUpdatesInNotification = oldUpdates;
|
2002-09-06 09:44:31 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
StartLayout(false);
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2005-10-21 19:39:06 +04:00
|
|
|
nsresult
|
2002-11-19 21:29:35 +03:00
|
|
|
HTMLContentSink::CloseBody()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-29 23:07:24 +04:00
|
|
|
// Flush out anything that's left
|
2006-11-07 02:50:33 +03:00
|
|
|
mCurrentContext->FlushTags();
|
2013-08-17 23:26:48 +04:00
|
|
|
mCurrentContext->CloseBody();
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-26 19:08:55 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
NS_IMETHODIMP
|
2013-08-17 16:06:23 +04:00
|
|
|
HTMLContentSink::OpenContainer(ElementType aElementType)
|
1998-08-28 20:20:16 +04:00
|
|
|
{
|
1999-09-14 18:38:52 +04:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2013-08-17 16:06:23 +04:00
|
|
|
switch (aElementType) {
|
|
|
|
case eBody:
|
2013-08-17 19:39:34 +04:00
|
|
|
rv = OpenBody();
|
2005-10-21 19:39:06 +04:00
|
|
|
break;
|
2013-08-17 16:06:23 +04:00
|
|
|
case eHTML:
|
2005-10-21 19:39:06 +04:00
|
|
|
if (mRoot) {
|
2013-08-17 03:51:58 +04:00
|
|
|
// If we've already hit this code once, then we're done
|
2006-01-12 20:11:57 +03:00
|
|
|
if (!mNotifiedRootInsertion) {
|
2007-10-04 09:16:35 +04:00
|
|
|
NotifyRootInsertion();
|
2006-01-12 20:11:57 +03:00
|
|
|
}
|
2008-01-17 00:54:33 +03:00
|
|
|
ProcessOfflineManifest(mRoot);
|
2005-10-21 19:39:06 +04:00
|
|
|
}
|
|
|
|
break;
|
1998-08-28 20:20:16 +04:00
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1999-09-14 18:38:52 +04:00
|
|
|
return rv;
|
1998-08-28 20:20:16 +04:00
|
|
|
}
|
1998-07-12 04:18:26 +04:00
|
|
|
|
1998-08-28 20:20:16 +04:00
|
|
|
NS_IMETHODIMP
|
2013-08-17 16:06:23 +04:00
|
|
|
HTMLContentSink::CloseContainer(const ElementType aTag)
|
1998-08-28 20:20:16 +04:00
|
|
|
{
|
2005-10-21 19:39:06 +04:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2005-10-21 19:39:06 +04:00
|
|
|
switch (aTag) {
|
2013-08-17 16:06:23 +04:00
|
|
|
case eBody:
|
2005-10-21 19:39:06 +04:00
|
|
|
rv = CloseBody();
|
|
|
|
break;
|
2013-08-17 16:06:23 +04:00
|
|
|
case eHTML:
|
2005-10-21 19:39:06 +04:00
|
|
|
rv = CloseHTML();
|
|
|
|
break;
|
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1999-09-14 18:38:52 +04:00
|
|
|
return rv;
|
1998-08-28 20:20:16 +04:00
|
|
|
}
|
1998-07-12 04:18:26 +04:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillInterrupt()
|
|
|
|
{
|
2008-10-31 00:31:00 +03:00
|
|
|
return WillInterruptImpl();
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLContentSink::WillResume()
|
|
|
|
{
|
|
|
|
return WillResumeImpl();
|
2001-06-21 06:06:23 +04:00
|
|
|
}
|
|
|
|
|
2005-10-21 19:39:06 +04:00
|
|
|
void
|
2003-01-04 02:17:22 +03:00
|
|
|
HTMLContentSink::CloseHeadContext()
|
|
|
|
{
|
2006-01-27 04:05:54 +03:00
|
|
|
if (mCurrentContext) {
|
|
|
|
if (!mCurrentContext->IsCurrentContainer(eHTMLTag_head))
|
|
|
|
return;
|
2003-01-04 02:17:22 +03:00
|
|
|
|
2009-03-24 01:10:12 +03:00
|
|
|
mCurrentContext->FlushTags();
|
2006-01-27 04:05:54 +03:00
|
|
|
}
|
|
|
|
|
2009-03-20 11:15:35 +03:00
|
|
|
if (!mContextStack.IsEmpty())
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t n = mContextStack.Length() - 1;
|
2009-03-20 11:15:35 +03:00
|
|
|
mCurrentContext = mContextStack.ElementAt(n);
|
|
|
|
mContextStack.RemoveElementAt(n);
|
|
|
|
}
|
2003-01-04 02:17:22 +03:00
|
|
|
}
|
|
|
|
|
2002-09-19 03:31:08 +04:00
|
|
|
void
|
1999-10-26 18:55:51 +04:00
|
|
|
HTMLContentSink::NotifyInsert(nsIContent* aContent,
|
|
|
|
nsIContent* aChildContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndexInContainer)
|
1999-10-26 18:55:51 +04:00
|
|
|
{
|
2014-10-02 23:07:24 +04:00
|
|
|
if (aContent && aContent->GetUncomposedDoc() != mDocument) {
|
2005-05-19 23:56:13 +04: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-29 02:43:12 +03:00
|
|
|
mInNotification++;
|
2002-09-19 03:31:08 +04:00
|
|
|
|
2007-03-10 02:43:50 +03: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-19 03:31:08 +04:00
|
|
|
|
2000-01-29 02:43:12 +03:00
|
|
|
mInNotification--;
|
1999-10-26 18:55:51 +04:00
|
|
|
}
|
|
|
|
|
2007-10-04 09:16:35 +04: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 18:59:28 +04:00
|
|
|
mNotifiedRootInsertion = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = mDocument->IndexOf(mRoot);
|
2007-10-04 09:16:35 +04:00
|
|
|
NS_ASSERTION(index != -1, "mRoot not child of document?");
|
2012-07-30 18:20:58 +04:00
|
|
|
NotifyInsert(nullptr, mRoot, index);
|
2007-10-04 09:16:35 +04:00
|
|
|
|
|
|
|
// Now update the notification information in all our
|
|
|
|
// contexts, since we just inserted the root and notified on
|
|
|
|
// our whole tree
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
1999-10-26 18:55:51 +04:00
|
|
|
void
|
2007-01-31 00:21:06 +03:00
|
|
|
HTMLContentSink::UpdateChildCounts()
|
1999-10-26 18:55:51 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numContexts = mContextStack.Length();
|
|
|
|
for (uint32_t i = 0; i < numContexts; i++) {
|
2009-03-20 11:15:35 +03:00
|
|
|
SinkContext* sc = mContextStack.ElementAt(i);
|
1999-10-26 18:55:51 +04:00
|
|
|
|
|
|
|
sc->UpdateChildCounts();
|
|
|
|
}
|
2002-09-19 03:31:08 +04:00
|
|
|
|
1999-10-26 18:55:51 +04:00
|
|
|
mCurrentContext->UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
2004-05-28 02:08:42 +04:00
|
|
|
void
|
2017-01-05 10:31:56 +03:00
|
|
|
HTMLContentSink::FlushPendingNotifications(FlushType aType)
|
2000-01-24 09:43:15 +03:00
|
|
|
{
|
2000-01-29 02:43:12 +03:00
|
|
|
// Only flush tags if we're not doing the notification ourselves
|
2004-05-28 02:08:42 +04:00
|
|
|
// (since we aren't reentrant)
|
2007-10-04 09:16:35 +04:00
|
|
|
if (!mInNotification) {
|
2009-05-17 18:22:55 +04:00
|
|
|
// Only flush if we're still a document observer (so that our child counts
|
|
|
|
// should be correct).
|
|
|
|
if (mIsDocumentObserver) {
|
2017-01-05 10:31:56 +03:00
|
|
|
if (aType >= FlushType::ContentAndNotify) {
|
2009-05-17 18:22:55 +04:00
|
|
|
FlushTags();
|
|
|
|
}
|
2006-11-07 02:50:33 +03:00
|
|
|
}
|
2017-01-05 10:31:56 +03:00
|
|
|
if (aType >= FlushType::InterruptibleLayout) {
|
2005-08-25 00:56:58 +04:00
|
|
|
// Make sure that layout has started so that the reflow flush
|
|
|
|
// will actually happen.
|
2011-10-17 18:59:28 +04:00
|
|
|
StartLayout(true);
|
2005-08-25 00:56:58 +04:00
|
|
|
}
|
2000-01-24 09:43:15 +03:00
|
|
|
}
|
|
|
|
}
|
1999-03-15 08:11:43 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::FlushTags()
|
|
|
|
{
|
2007-10-04 09:16:35 +04:00
|
|
|
if (!mNotifiedRootInsertion) {
|
|
|
|
NotifyRootInsertion();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-07-21 01:19:00 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
return mCurrentContext ? mCurrentContext->FlushTags() : NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-19 03:31:08 +04:00
|
|
|
NS_IMETHODIMP
|
2003-06-17 20:40:34 +04:00
|
|
|
HTMLContentSink::SetDocumentCharset(nsACString& aCharset)
|
2001-06-30 02:56:58 +04:00
|
|
|
{
|
2014-04-21 09:00:33 +04:00
|
|
|
MOZ_ASSERT_UNREACHABLE("<meta charset> case doesn't occur with about:blank");
|
2013-10-16 05:46:10 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-06-30 02:56:58 +04:00
|
|
|
}
|
|
|
|
|
2004-11-02 22:52:32 +03:00
|
|
|
nsISupports *
|
|
|
|
HTMLContentSink::GetTarget()
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-04-16 02:34:50 +04:00
|
|
|
HTMLContentSink::IsScriptExecuting()
|
|
|
|
{
|
|
|
|
return IsScriptExecutingImpl();
|
|
|
|
}
|