2015-05-03 19:32:37 +00: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 11:12:37 +00: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/. */
|
1998-11-11 22:06:16 +00:00
|
|
|
|
|
|
|
#ifndef nsXMLContentSink_h__
|
|
|
|
#define nsXMLContentSink_h__
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2003-10-05 07:29:50 +00:00
|
|
|
#include "nsContentSink.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIXMLContentSink.h"
|
2002-01-09 01:37:50 +00:00
|
|
|
#include "nsIExpatSink.h"
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-21 21:35:23 +00:00
|
|
|
#include "nsIDocumentTransformer.h"
|
2007-01-30 21:21:06 +00:00
|
|
|
#include "nsTArray.h"
|
2003-07-03 05:34:26 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2007-02-02 02:12:48 +00:00
|
|
|
#include "nsCRT.h"
|
2008-02-08 22:07:51 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2009-06-23 21:22:16 +00:00
|
|
|
#include "nsIDTD.h"
|
2010-10-25 12:17:38 +00:00
|
|
|
#include "mozilla/dom/FromParser.h"
|
2003-10-05 11:28:06 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
class nsIDocument;
|
1999-06-23 03:29:44 +00:00
|
|
|
class nsIURI;
|
1998-11-11 22:06:16 +00:00
|
|
|
class nsIContent;
|
1998-12-11 17:02:37 +00:00
|
|
|
class nsIParser;
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class NodeInfo;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2014-06-20 02:01:40 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
typedef enum {
|
|
|
|
eXMLContentSinkState_InProlog,
|
|
|
|
eXMLContentSinkState_InDocumentElement,
|
|
|
|
eXMLContentSinkState_InEpilog
|
|
|
|
} XMLContentSinkState;
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
struct StackNode {
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mNumFlushed;
|
2007-01-30 21:21:06 +00:00
|
|
|
};
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
class nsXMLContentSink : public nsContentSink,
|
|
|
|
public nsIXMLContentSink,
|
2002-06-20 12:04:22 +00:00
|
|
|
public nsITransformObserver,
|
2003-10-05 11:28:06 +00:00
|
|
|
public nsIExpatSink
|
1999-06-28 14:17:30 +00:00
|
|
|
{
|
1998-11-11 22:06:16 +00:00
|
|
|
public:
|
|
|
|
nsXMLContentSink();
|
|
|
|
|
2007-02-02 02:12:48 +00:00
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
nsresult Init(nsIDocument* aDoc,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
2003-04-03 18:57:33 +00:00
|
|
|
nsISupports* aContainer,
|
2002-03-27 06:19:14 +00:00
|
|
|
nsIChannel* aChannel);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
|
|
|
// nsISupports
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2008-02-08 22:07:51 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink,
|
|
|
|
nsContentSink)
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_DECL_NSIEXPATSINK
|
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
// nsIContentSink
|
2015-03-21 16:28:04 +00: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;
|
|
|
|
virtual void FlushPendingNotifications(mozFlushType aType) override;
|
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override;
|
|
|
|
virtual nsISupports *GetTarget() override;
|
|
|
|
virtual bool IsScriptExecuting() override;
|
|
|
|
virtual void ContinueInterruptedParsingAsync() override;
|
1998-11-11 22:06:16 +00:00
|
|
|
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-21 21:35:23 +00:00
|
|
|
// nsITransformObserver
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD OnDocumentCreated(nsIDocument *aResultDocument) override;
|
|
|
|
NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument) override;
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-21 21:35:23 +00:00
|
|
|
|
2007-05-31 01:42:48 +00:00
|
|
|
// nsICSSLoaderObserver
|
2014-06-20 10:32:49 +00:00
|
|
|
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet,
|
|
|
|
bool aWasAlternate,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsresult aStatus) override;
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool ParsePIData(const nsString &aData, nsString &aHref,
|
2006-03-17 14:38:57 +00:00
|
|
|
nsString &aTitle, nsString &aMedia,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool &aIsAlternate);
|
2006-03-17 14:38:57 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
protected:
|
2014-07-08 21:23:16 +00:00
|
|
|
virtual ~nsXMLContentSink();
|
2012-01-20 11:16:27 +00:00
|
|
|
|
2012-01-20 11:16:27 +00:00
|
|
|
nsIParser* GetParser();
|
|
|
|
|
2012-01-20 11:16:27 +00:00
|
|
|
void ContinueInterruptedParsingIfEnabled();
|
|
|
|
|
2007-04-20 22:59:18 +00:00
|
|
|
// Start layout. If aIgnorePendingSheets is true, this will happen even if
|
|
|
|
// we still have stylesheet loads pending. Otherwise, we'll wait until the
|
|
|
|
// stylesheets are all done loading.
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual void MaybeStartLayout(bool aIgnorePendingSheets);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
virtual nsresult AddAttributes(const char16_t** aNode, nsIContent* aContent);
|
|
|
|
nsresult AddText(const char16_t* aString, int32_t aLength);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
virtual bool OnOpenContainer(const char16_t **aAtts,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aAttsCount,
|
|
|
|
int32_t aNameSpaceID,
|
2003-06-24 01:20:40 +00:00
|
|
|
nsIAtom* aTagName,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aLineNumber) { return true; }
|
2004-09-30 22:27:45 +00:00
|
|
|
// Set the given content as the root element for the created document
|
|
|
|
// don't set if root element was already set.
|
|
|
|
// return TRUE if this call set the root element
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual bool SetDocElement(int32_t aNameSpaceID,
|
2004-09-30 22:27:45 +00:00
|
|
|
nsIAtom *aTagName,
|
|
|
|
nsIContent *aContent);
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool NotifyForDocElement() { return true; }
|
2014-01-04 15:02:17 +00:00
|
|
|
virtual nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
|
2014-06-20 02:01:40 +00:00
|
|
|
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
|
2011-09-29 06:19:26 +00:00
|
|
|
nsIContent** aResult, bool* aAppendContent,
|
2010-10-25 12:17:38 +00:00
|
|
|
mozilla::dom::FromParser aFromParser);
|
2002-12-02 23:24:57 +00:00
|
|
|
|
2005-06-02 02:38:20 +00:00
|
|
|
// aParent is allowed to be null here if this is the root content
|
|
|
|
// being closed
|
2006-11-04 05:45:02 +00:00
|
|
|
virtual nsresult CloseElement(nsIContent* aContent);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual nsresult FlushText(bool aReleaseTextNode = true);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
nsresult AddContentAsLeaf(nsIContent *aContent);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
nsIContent* GetCurrentContent();
|
2010-10-05 01:25:44 +00:00
|
|
|
StackNode* GetCurrentStackNode();
|
2007-01-30 21:21:06 +00:00
|
|
|
nsresult PushContent(nsIContent *aContent);
|
|
|
|
void PopContent();
|
2011-09-29 06:19:26 +00:00
|
|
|
bool HaveNotifiedForCurrentContent() const;
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
nsresult FlushTags() override;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
void UpdateChildCounts() override;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
|
|
|
void DidAddContent()
|
|
|
|
{
|
|
|
|
if (IsTimeToNotify()) {
|
|
|
|
FlushTags();
|
|
|
|
}
|
|
|
|
}
|
1999-06-28 14:17:30 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
// nsContentSink override
|
|
|
|
virtual nsresult ProcessStyleLink(nsIContent* aElement,
|
2005-03-30 00:36:57 +00:00
|
|
|
const nsSubstring& aHref,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aAlternate,
|
2005-03-30 00:36:57 +00:00
|
|
|
const nsSubstring& aTitle,
|
|
|
|
const nsSubstring& aType,
|
2015-03-21 16:28:04 +00:00
|
|
|
const nsSubstring& aMedia) override;
|
1999-06-28 14:17:30 +00:00
|
|
|
|
2001-11-02 10:13:05 +00:00
|
|
|
nsresult LoadXSLStyleSheet(nsIURI* aUrl);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool CanStillPrettyPrint();
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2002-10-09 07:03:15 +00:00
|
|
|
nsresult MaybePrettyPrint();
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
bool IsMonolithicContainer(mozilla::dom::NodeInfo* aNodeInfo);
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts,
|
2014-05-30 07:36:53 +00:00
|
|
|
uint32_t aAttsCount, uint32_t aLineNumber,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aInterruptable);
|
2014-01-04 15:02:17 +00:00
|
|
|
nsresult HandleEndElement(const char16_t *aName, bool aInterruptable);
|
|
|
|
nsresult HandleCharacterData(const char16_t *aData, uint32_t aLength,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aInterruptable);
|
2007-06-11 10:15:17 +00:00
|
|
|
|
2012-11-12 17:43:02 +00:00
|
|
|
nsCOMPtr<nsIContent> mDocElement;
|
2007-07-11 03:42:11 +00:00
|
|
|
nsCOMPtr<nsIContent> mCurrentHead; // When set, we're in an XHTML <haed>
|
1998-11-11 22:06:16 +00:00
|
|
|
|
|
|
|
XMLContentSinkState mState;
|
|
|
|
|
2015-10-12 17:07:51 +00:00
|
|
|
// The length of the valid data in mText.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mTextLength;
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mNotifyLevel;
|
2008-10-15 21:29:35 +00:00
|
|
|
nsCOMPtr<nsIContent> mLastTextNode;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mPrettyPrintXML : 1;
|
|
|
|
uint8_t mPrettyPrintHasSpecialRoot : 1;
|
|
|
|
uint8_t mPrettyPrintHasFactoredElements : 1;
|
|
|
|
uint8_t mPrettyPrinting : 1; // True if we called PrettyPrint() and it
|
2007-05-31 01:42:48 +00:00
|
|
|
// decided we should in fact prettyprint.
|
2012-06-20 07:05:39 +00:00
|
|
|
// True to call prevent script execution in the fragment mode.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mPreventScriptExecution : 1;
|
2004-04-20 17:12:48 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
nsTArray<StackNode> mContentStack;
|
|
|
|
|
2003-07-03 05:34:26 +00:00
|
|
|
nsCOMPtr<nsIDocumentTransformer> mXSLTProcessor;
|
2015-10-12 17:07:51 +00:00
|
|
|
|
|
|
|
static const int NS_ACCUMULATION_BUFFER_SIZE = 4096;
|
|
|
|
// Our currently accumulated text that we have not flushed to a textnode yet.
|
|
|
|
char16_t mText[NS_ACCUMULATION_BUFFER_SIZE];
|
1998-11-11 22:06:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXMLContentSink_h__
|