From eaa83af43efadb518751e5dd2a4f96d14f7b86c8 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Thu, 22 Apr 2004 18:28:36 +0000 Subject: [PATCH] Fixing bug 241328. Eliminating dead code, and making some classes use less memory on some 64-bit platforms. Also doing some general cleaning. r+sr=bzbarsky@mit.edu --- htmlparser/public/nsHTMLTokens.h | 532 ------------ htmlparser/public/nsToken.h | 303 ------- htmlparser/src/nsHTMLTokens.cpp | 171 ---- htmlparser/src/nsParserNode.cpp | 391 --------- htmlparser/src/nsParserNode.h | 321 ------- htmlparser/src/nsToken.cpp | 195 ----- htmlparser/src/nsViewSourceHTML.cpp | 1228 --------------------------- htmlparser/src/win32.order | 0 8 files changed, 3141 deletions(-) delete mode 100644 htmlparser/src/win32.order diff --git a/htmlparser/public/nsHTMLTokens.h b/htmlparser/public/nsHTMLTokens.h index 275cffd71a0..e69de29bb2d 100644 --- a/htmlparser/public/nsHTMLTokens.h +++ b/htmlparser/public/nsHTMLTokens.h @@ -1,532 +0,0 @@ - -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * 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"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * MODULE NOTES: - * @update gess 4/1/98 - * - * This file contains the declarations for all the HTML specific token types that - * our DTD's understand. In fact, the same set of token types are used for XML. - * Currently we have tokens for text, comments, start and end tags, entities, - * attributes, style, script and skipped content. Whitespace and newlines also - * have their own token types, but don't count on them to stay forever. - * - * If you're looking for the html tags, they're in a file called nsHTMLTag.h/cpp. - * - * Most of the token types have a similar API. They have methods to get the type - * of token (GetTokenType); those that represent HTML tags also have a method to - * get type tag type (GetTypeID). In addition, most have a method that causes the - * token to help in the parsing process called (Consume). We've also thrown in a - * few standard debugging methods as well. - */ - -#ifndef HTMLTOKENS_H -#define HTMLTOKENS_H - -#include "nsToken.h" -#include "nsHTMLTags.h" -#include "nsParserError.h" -#include "nsString.h" -#include "nsScannerString.h" - -class nsScanner; - - /******************************************************************* - * This enum defines the set of token types that we currently support. - *******************************************************************/ - -enum eHTMLTokenTypes { - eToken_unknown=0, - eToken_start=1, eToken_end, eToken_comment, eToken_entity, - eToken_whitespace, eToken_newline, eToken_text, eToken_attribute, - eToken_script, eToken_style, eToken_skippedcontent, eToken_instruction, - eToken_cdatasection, eToken_error, eToken_doctypeDecl, eToken_markupDecl, - eToken_last //make sure this stays the last token... -}; - -enum eHTMLCategory { - eHTMLCategory_unknown=0, - eHTMLCategory_inline, - eHTMLCategory_block, - eHTMLCategory_blockAndInline, - eHTMLCategory_list, - eHTMLCategory_table, - eHTMLCategory_tablepart, - eHTMLCategory_tablerow, - eHTMLCategory_tabledata, - eHTMLCategory_head, - eHTMLCategory_html, - eHTMLCategory_body, - eHTMLCategory_form, - eHTMLCategory_options, - eHTMLCategory_frameset, - eHTMLCategory_text -}; - - -nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScanner); -nsresult ConsumeAttributeText(PRUnichar aChar,nsString& aString,nsScanner& aScanner); -const PRUnichar* GetTagName(PRInt32 aTag); -//PRInt32 FindEntityIndex(nsString& aString,PRInt32 aCount=-1); - - - -/** - * This declares the basic token type used in the HTML DTD's. - * @update gess 3/25/98 - */ -class CHTMLToken : public CToken { -public: - virtual ~CHTMLToken(); - - CHTMLToken(eHTMLTags aTag); - - virtual eContainerInfo GetContainerInfo(void) const {return eFormUnknown;} - virtual void SetContainerInfo(eContainerInfo aInfo) { } - -protected: -}; - -/** - * This declares start tokens, which always take the form . - * This class also knows how to consume related attributes. - * - * @update gess 3/25/98 - */ -class CStartToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CStartToken(eHTMLTags aTag=eHTMLTag_unknown); - CStartToken(const nsAString& aString); - CStartToken(const nsAString& aName,eHTMLTags aTag); - - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual PRInt32 GetTypeID(void); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - - virtual PRBool IsEmpty(void); - virtual void SetEmpty(PRBool aValue); - - virtual const nsAString& GetStringValue(); - virtual void GetSource(nsString& anOutputString); - virtual void AppendSourceTo(nsAString& anOutputString); - - //the following info is used to set well-formedness state on start tags... - virtual eContainerInfo GetContainerInfo(void) const {return mContainerInfo;} - virtual void SetContainerInfo(eContainerInfo aContainerInfo) {mContainerInfo=aContainerInfo;} - virtual PRBool IsWellFormed(void) const {return PRBool(eWellFormed==mContainerInfo);} - - - /* - * Get and set the ID attribute atom for this element. - * See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types - * for the definition of an ID attribute. - * - */ - virtual nsresult GetIDAttributeAtom(nsIAtom** aResult); - virtual nsresult SetIDAttributeAtom(nsIAtom* aID); - - nsString mTextValue; - nsString mTrailingContent; - protected: - eContainerInfo mContainerInfo; - nsCOMPtr mIDAttributeAtom; - PRPackedBool mEmpty; -#ifdef DEBUG - PRPackedBool mAttributed; -#endif -}; - - -/** - * This declares end tokens, which always take the - * form . This class also knows how to consume - * related attributes. - * - * @update gess 3/25/98 - */ -class CEndToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CEndToken(eHTMLTags aTag); - CEndToken(const nsAString& aString); - CEndToken(const nsAString& aName,eHTMLTags aTag); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual PRInt32 GetTypeID(void); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - - virtual const nsAString& GetStringValue(); - virtual void GetSource(nsString& anOutputString); - virtual void AppendSourceTo(nsAString& anOutputString); - - protected: - nsString mTextValue; -}; - - -/** - * This declares comment tokens. Comments are usually - * thought of as tokens, but we treat them that way - * here so that the parser can have a consistent view - * of all tokens. - * - * @update gess 3/25/98 - */ -class CCommentToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CCommentToken(); - CCommentToken(const nsAString& aString); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetStringValue(void); - virtual void AppendSourceTo(nsAString& anOutputString); - - nsresult ConsumeStrictComment(nsScanner& aScanner); - nsresult ConsumeQuirksComment(nsScanner& aScanner); - - protected: - nsScannerSubstring mComment; // does not include MDO & MDC - nsScannerSubstring mCommentDecl; // includes MDO & MDC -}; - - -/** - * This class declares entity tokens, which always take - * the form &xxxx;. This class also offers a few utility - * methods that allow you to easily reduce entities. - * - * @update gess 3/25/98 - */ -class CEntityToken : public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CEntityToken(); - CEntityToken(const nsAString& aString); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - PRInt32 TranslateToUnicodeStr(nsString& aString); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - static nsresult ConsumeEntity(PRUnichar aChar,nsString& aString,nsScanner& aScanner); - static PRInt32 TranslateToUnicodeStr(PRInt32 aValue,nsString& aString); - - virtual const nsAString& GetStringValue(void); - virtual void GetSource(nsString& anOutputString); - virtual void AppendSourceTo(nsAString& anOutputString); - - protected: - nsString mTextValue; -}; - - -/** - * Whitespace tokens are used where whitespace can be - * detected as distinct from text. This allows us to - * easily skip leading/trailing whitespace when desired. - * - * @update gess 3/25/98 - */ -class CWhitespaceToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CWhitespaceToken(); - CWhitespaceToken(const nsAString& aString); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetStringValue(void); - - protected: - nsString mTextValue; -}; - -/** - * Text tokens contain the normalized form of html text. - * These tokens are guaranteed not to contain entities, - * start or end tags, or newlines. - * - * @update gess 3/25/98 - */ -class CTextToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CTextToken(); - CTextToken(const nsAString& aString); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - nsresult ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScanner& aScanner, - nsString& aEndTagName,PRInt32 aFlag,PRBool& aFlushTokens); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual PRInt32 GetTextLength(void); - virtual void CopyTo(nsAString& aStr); - virtual const nsAString& GetStringValue(void); - virtual void Bind(nsScanner* aScanner, nsScannerIterator& aStart, nsScannerIterator& aEnd); - virtual void Bind(const nsAString& aStr); - - protected: - nsScannerSubstring mTextValue; -}; - - -/** - * CDATASection tokens contain raw unescaped text content delimited by - * a ![CDATA[ and ]]. - * XXX Not really a HTML construct - maybe we need a separation - * - * @update vidur 11/12/98 - */ -class CCDATASectionToken : public CHTMLToken { - CTOKEN_IMPL_SIZEOF - -public: - CCDATASectionToken(eHTMLTags aTag = eHTMLTag_unknown); - CCDATASectionToken(const nsAString& aString); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetStringValue(void); - - protected: - nsString mTextValue; -}; - - -/** - * Declaration tokens contain raw unescaped text content (not really, but - * right now we use this only for view source). - * XXX Not really a HTML construct - maybe we need a separation - * - */ -class CMarkupDeclToken : public CHTMLToken { - CTOKEN_IMPL_SIZEOF - -public: - CMarkupDeclToken(); - CMarkupDeclToken(const nsAString& aString); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetStringValue(void); - -protected: - nsScannerSubstring mTextValue; -}; - - -/** - * Attribute tokens are used to contain attribute key/value - * pairs whereever they may occur. Typically, they should - * occur only in start tokens. However, we may expand that - * ability when XML tokens become commonplace. - * - * @update gess 3/25/98 - */ -class CAttributeToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CAttributeToken(); - CAttributeToken(const nsAString& aString); - CAttributeToken(const nsAString& aKey, const nsAString& aString); - ~CAttributeToken() {} - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetKey(void); // XXX {return mTextKey;} - virtual void SetKey(const nsAString& aKey); - virtual void BindKey(nsScanner* aScanner, nsScannerIterator& aStart, nsScannerIterator& aEnd); - virtual const nsAString& GetValue(void) {return mTextValue;} - virtual void SanitizeKey(); - virtual const nsAString& GetStringValue(void); - virtual void GetSource(nsString& anOutputString); - virtual void AppendSourceTo(nsAString& anOutputString); - - PRPackedBool mHasEqualWithoutValue; - protected: -#ifdef DEBUG - PRPackedBool mLastAttribute; -#endif - nsAutoString mTextValue; - nsScannerSubstring mTextKey; -}; - - -/** - * Newline tokens contain, you guessed it, newlines. - * They consume newline (CR/LF) either alone or in pairs. - * - * @update gess 3/25/98 - */ -class CNewlineToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CNewlineToken(); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetStringValue(void); - - static void AllocNewline(); - static void FreeNewline(); -}; - - -/** - * Script tokens contain sequences of javascript (or, gulp, - * any other script you care to send). We don't tokenize - * it here, nor validate it. We just wrap it up, and pass - * it along to the html parser, who sends it (later on) - * to the scripting engine. - * - * @update gess 3/25/98 - */ -class CScriptToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CScriptToken(); - CScriptToken(const nsAString& aString); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetStringValue(void); - - protected: - nsString mTextValue; -}; - - -/** - * Style tokens contain sequences of css style. We don't - * tokenize it here, nor validate it. We just wrap it up, - * and pass it along to the html parser, who sends it - * (later on) to the style engine. - * - * @update gess 3/25/98 - */ -class CStyleToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CStyleToken(); - CStyleToken(const nsAString& aString); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetStringValue(void); - - protected: - nsString mTextValue; -}; - - -/** - * Whitespace tokens are used where whitespace can be - * detected as distinct from text. This allows us to - * easily skip leading/trailing whitespace when desired. - * - * @update gess 3/25/98 - */ -class CInstructionToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - - public: - CInstructionToken(); - CInstructionToken(const nsAString& aString); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetStringValue(void); - - protected: - nsString mTextValue; -}; - -class CErrorToken : public CHTMLToken { - CTOKEN_IMPL_SIZEOF - -public: - CErrorToken(nsParserError* aError=0); - ~CErrorToken(); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - - void SetError(nsParserError* aError); // CErrorToken takes ownership of aError - - // The nsParserError object returned by GetError is still owned by CErrorToken. - // DO NOT use the delete operator on it. Should we change this so that a copy - // of nsParserError is returned which needs to be destroyed by the consumer? - const nsParserError* GetError(void); - - virtual const nsAString& GetStringValue(void); -protected: - nsString mTextValue; - nsParserError* mError; -}; - -/** - * This token is generated by the HTML and Expat tokenizers - * when they see the doctype declaration ("") - * - */ - -class CDoctypeDeclToken: public CHTMLToken { - CTOKEN_IMPL_SIZEOF - -public: - CDoctypeDeclToken(eHTMLTags aTag=eHTMLTag_unknown); - CDoctypeDeclToken(const nsAString& aString,eHTMLTags aTag=eHTMLTag_unknown); - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - virtual const char* GetClassName(void); - virtual PRInt32 GetTokenType(void); - virtual const nsAString& GetStringValue(void); - virtual void SetStringValue(const nsAString& aStr); - - protected: - nsString mTextValue; -}; - -#endif diff --git a/htmlparser/public/nsToken.h b/htmlparser/public/nsToken.h index f007ed46542..e69de29bb2d 100644 --- a/htmlparser/public/nsToken.h +++ b/htmlparser/public/nsToken.h @@ -1,303 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * 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"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -/** - * MODULE NOTES: - * @update gess 4/1/98 - * - * This class is defines the basic notion of a token - * within our system. All other tokens are derived from - * this one. It offers a few basic interfaces, but the - * most important is consume(). The consume() method gets - * called during the tokenization process when an instance - * of that particular token type gets detected in the - * input stream. - * - * CToken objects that are allocated from the heap _must_ be allocated - * using the nsTokenAllocator: the nsTokenAllocator object uses an - * arena to manage the tokens. - * - * The nsTokenAllocator object's arena implementation requires - * object size at destruction time to properly recycle the object; - * therefore, CToken::operator delete() is not public. Instead, - * heap-allocated tokens should be destroyed using the static - * Destroy() method, which accepts a token and the arena from which - * the token was allocated. - * - * Leaf classes (that are actually instantiated from the heap) must - * implement the SizeOf() method, which Destroy() uses to determine - * the size of the token in order to properly recycle it. - */ - - -#ifndef CTOKEN__ -#define CTOKEN__ - -#include "prtypes.h" -#include "nsString.h" -#include "nsError.h" -#include "nsFixedSizeAllocator.h" - -#define NS_HTMLTOKENS_NOT_AN_ENTITY \ - NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_HTMLPARSER,2000) - -class nsScanner; -class nsTokenAllocator; - -enum eContainerInfo { - eWellFormed, - eMalformed, - eFormUnknown -}; - -/** - * Implement the SizeOf() method; leaf classes derived from CToken - * must declare this. - */ -#define CTOKEN_IMPL_SIZEOF \ -protected: \ - virtual size_t SizeOf() const { return sizeof(*this); } \ -public: - -/** - * Token objects represent sequences of characters as they - * are consumed from the input stream (URL). While they're - * pretty general in nature, we use subclasses (found in - * nsHTMLTokens.h) to define , , , - * , <&entity>, , and tokens. - * - * @update gess 3/25/98 - */ -class CToken { - public: - - enum eTokenOrigin {eSource,eResidualStyle}; - - protected: - - // nsTokenAllocator should be the only class that tries to - // allocate tokens from the heap. - friend class nsTokenAllocator; - - /** - * - * @update harishd 08/01/00 - * @param aSize - - * @param aArena - Allocate memory from this pool. - */ - static void * operator new (size_t aSize,nsFixedSizeAllocator& anArena) CPP_THROW_NEW - { - return anArena.Alloc(aSize); - } - - /** - * Hide operator delete; clients should use Destroy() instead. - */ - static void operator delete (void*,size_t) {} - - public: - /** - * destructor - * @update gess5/11/98 - */ - virtual ~CToken(); - - /** - * Destroy a token. - */ - static void Destroy(CToken* aToken,nsFixedSizeAllocator& aArenaPool) - { - size_t sz = aToken->SizeOf(); - aToken->~CToken(); - aArenaPool.Free(aToken, sz); - } - - /** - * Make a note on number of times you have been referenced - * @update harishd 08/02/00 - */ - void AddRef() { ++mUseCount; } - - /** - * Free yourself if no one is holding you. - * @update harishd 08/02/00 - */ - void Release(nsFixedSizeAllocator& aArenaPool) { - if(--mUseCount==0) - Destroy(this, aArenaPool); - } - - /** - * Default constructor - * @update gess7/21/98 - */ - CToken(PRInt32 aTag=0); - - /** - * Retrieve string value of the token - * @update gess5/11/98 - * @return reference to string containing string value - */ - virtual const nsAString& GetStringValue(void) = 0; - - /** - * Get string of full contents, suitable for debug dump. - * It should look exactly like the input source. - * @update gess5/11/98 - * @return reference to string containing string value - */ - virtual void GetSource(nsString& anOutputString); - - /** @update harishd 03/23/00 - * @return reference to string containing string value - */ - virtual void AppendSourceTo(nsAString& anOutputString); - - /** - * Sets the ordinal value of this token (not currently used) - * @update gess5/11/98 - * @param value is the new ord value for this token - */ - virtual void SetTypeID(PRInt32 aValue); - - /** - * Getter which retrieves the current ordinal value for this token - * @update gess5/11/98 - * @return current ordinal value - */ - virtual PRInt32 GetTypeID(void); - - /** - * Getter which retrieves the current attribute count for this token - * @update gess5/11/98 - * @return current attribute count - */ - virtual PRInt16 GetAttributeCount(void); - - /** - * Causes token to consume data from given scanner. - * Note that behavior varies wildly between CToken subclasses. - * @update gess5/11/98 - * @param aChar -- most recent char consumed - * @param aScanner -- input source where token should get data - * @return error code (0 means ok) - */ - virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode); - - /** - * Getter which retrieves type of token - * @update gess5/11/98 - * @return int containing token type - */ - virtual PRInt32 GetTokenType(void); - - /** - * Getter which retrieves the class name for this token - * This method is only used for debug purposes. - * @update gess5/11/98 - * @return const char* containing class name - */ - virtual const char* GetClassName(void); - - - /** - * For tokens who care, this can tell us whether the token is - * well formed or not. - * - * @update gess 8/30/00 - * @return PR_FALSE; subclasses MUST override if they care. - */ - virtual PRBool IsWellFormed(void) const {return PR_FALSE;} - - virtual PRBool IsEmpty(void) { return PR_FALSE; } - - /** - * If aValue is TRUE then the token represents a short-hand tag - */ - virtual void SetEmpty(PRBool aValue) { return ; } - - PRInt32 GetNewlineCount() - { - return mNewlineCount; - } - - void SetNewlineCount(PRInt32 aCount) - { - mNewlineCount = aCount; - } - - PRInt32 GetLineNumber() - { - return mLineNumber; - } - - void SetLineNumber(PRInt32 aLineNumber) - { - mLineNumber = mLineNumber == 0 ? aLineNumber : mLineNumber; - } - - void SetAttributeCount(PRInt16 aValue) { mAttrCount = aValue; } - - /** - * perform self test. - * @update gess5/11/98 - */ - virtual void SelfTest(void); - - static int GetTokenCount(); - - - -protected: - /** - * Returns the size of the token object. - */ - virtual size_t SizeOf() const = 0; - - PRInt32 mTypeID; - PRInt32 mUseCount; - PRInt32 mNewlineCount; - PRInt32 mLineNumber; - PRInt16 mAttrCount; -}; - - - -#endif - - diff --git a/htmlparser/src/nsHTMLTokens.cpp b/htmlparser/src/nsHTMLTokens.cpp index 348091a313f..89f8907b660 100644 --- a/htmlparser/src/nsHTMLTokens.cpp +++ b/htmlparser/src/nsHTMLTokens.cpp @@ -115,25 +115,6 @@ CStartToken::CStartToken(const nsAString& aName,eHTMLTags aTag) : CHTMLToken(aTa #endif } -nsresult CStartToken::GetIDAttributeAtom(nsIAtom** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - *aResult = mIDAttributeAtom; - NS_IF_ADDREF(*aResult); - - return NS_OK; -} - - -nsresult CStartToken::SetIDAttributeAtom(nsIAtom* aID) -{ - NS_ENSURE_ARG(aID); - mIDAttributeAtom = aID; - - return NS_OK; -} - - /* * This method returns the typeid (the tag type) for this token. * @@ -148,17 +129,6 @@ PRInt32 CStartToken::GetTypeID(){ return mTypeID; } -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CStartToken::GetClassName(void) { - return "start"; -} - /* * * @@ -365,17 +335,6 @@ PRInt32 CEndToken::GetTypeID(){ return mTypeID; } -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CEndToken::GetClassName(void) { - return "/end"; -} - /* * * @@ -447,17 +406,6 @@ CTextToken::CTextToken(const nsAString& aName) : CHTMLToken(eHTMLTag_text) { mTextValue.Rebind(aName); } -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CTextToken::GetClassName(void) { - return "text"; -} - /* * * @@ -715,17 +663,6 @@ CCDATASectionToken::CCDATASectionToken(const nsAString& aName) : CHTMLToken(eHTM mTextValue.Assign(aName); } -/* - * - * - * @update vidur 11/12/98 - * @param - * @return - */ -const char* CCDATASectionToken::GetClassName(void) { - return "cdatasection"; -} - /* * * @update vidur 11/12/98 @@ -843,15 +780,6 @@ CMarkupDeclToken::CMarkupDeclToken(const nsAString& aName) : CHTMLToken(eHTMLTag mTextValue.Rebind(aName); } -/* - * - * - * @param - * @return - */ -const char* CMarkupDeclToken::GetClassName(void) { - return "markupdeclaration"; -} /* * @@ -1255,17 +1183,6 @@ const nsAString& CCommentToken::GetStringValue(void) return mComment.AsString(); } -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CCommentToken::GetClassName(void){ - return "/**/"; -} - /* * * @@ -1287,18 +1204,6 @@ PRInt32 CCommentToken::GetTokenType(void) { CNewlineToken::CNewlineToken() : CHTMLToken(eHTMLTag_newline) { } - -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CNewlineToken::GetClassName(void) { - return "crlf"; -} - /* * * @@ -1426,17 +1331,6 @@ CAttributeToken::CAttributeToken(const nsAString& aKey, const nsAString& aName) #endif } -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CAttributeToken::GetClassName(void) { - return "attr"; -} - /* * * @@ -1880,17 +1774,6 @@ CWhitespaceToken::CWhitespaceToken(const nsAString& aName) : CHTMLToken(eHTMLTag mTextValue.Assign(aName); } -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CWhitespaceToken::GetClassName(void) { - return "ws"; -} - /* * * @@ -1965,18 +1848,6 @@ nsresult CEntityToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFla return result; } -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CEntityToken::GetClassName(void) { - return "&entity"; -} - - /* * * @@ -2245,18 +2116,6 @@ CScriptToken::CScriptToken(const nsAString& aString) : CHTMLToken(eHTMLTag_scrip mTextValue.Assign(aString); } - -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CScriptToken::GetClassName(void) { - return "script"; -} - /* * * @@ -2287,17 +2146,6 @@ CStyleToken::CStyleToken(const nsAString& aString) : CHTMLToken(eHTMLTag_style) mTextValue.Assign(aString); } -/* - * - * - * @update gess 3/25/98 - * @param - * @return - */ -const char* CStyleToken::GetClassName(void) { - return "style"; -} - /* * * @@ -2370,17 +2218,6 @@ nsresult CInstructionToken::Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 return result; } -/** - * - * - * @update gess 9/23/98 - * @param - * @return - */ -const char* CInstructionToken::GetClassName(void){ - return "instruction"; -} - /** * * @@ -2412,10 +2249,6 @@ PRInt32 CErrorToken::GetTokenType(void){ return eToken_error; } -const char* CErrorToken::GetClassName(void){ - return "error"; -} - void CErrorToken::SetError(nsParserError *aError) { mError = aError; } @@ -2488,10 +2321,6 @@ nsresult CDoctypeDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 return result; } -const char* CDoctypeDeclToken::GetClassName(void) { - return "doctype"; -} - PRInt32 CDoctypeDeclToken::GetTokenType(void) { return eToken_doctypeDecl; } diff --git a/htmlparser/src/nsParserNode.cpp b/htmlparser/src/nsParserNode.cpp index 9cc5a7cbb3b..e69de29bb2d 100644 --- a/htmlparser/src/nsParserNode.cpp +++ b/htmlparser/src/nsParserNode.cpp @@ -1,391 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * 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"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -#include "nsIAtom.h" -#include "nsParserNode.h" -#include -#include "nsHTMLTokens.h" -#include "nsITokenizer.h" -#include "nsDTDUtils.h" - - -/** - * Default Constructor - */ -nsCParserNode::nsCParserNode() - : mToken(nsnull), - mUseCount(0), - mGenericState(PR_FALSE), - mTokenAllocator(nsnull) -{ - MOZ_COUNT_CTOR(nsCParserNode); -#ifdef HEAP_ALLOCATED_NODES - mNodeAllocator = nsnull; -#endif -} - -/** - * Constructor - * - * @update gess 3/25/98 - * @param aToken -- token to init internal token - * @return - */ -nsCParserNode::nsCParserNode(CToken* aToken, - nsTokenAllocator* aTokenAllocator, - nsNodeAllocator* aNodeAllocator): nsIParserNode() -{ - mRefCnt = 0; - MOZ_COUNT_CTOR(nsCParserNode); - - static int theNodeCount = 0; - ++theNodeCount; - mToken = aToken; - IF_HOLD(mToken); - mTokenAllocator = aTokenAllocator; - mUseCount = 0; - mGenericState = PR_FALSE; -#ifdef HEAP_ALLOCATED_NODES - mNodeAllocator = aNodeAllocator; -#endif -} - -/** - * default destructor - * NOTE: We intentionally DONT recycle mToken here. - * It may get cached for use elsewhere - * @update gess 3/25/98 - * @param - * @return - */ -nsCParserNode::~nsCParserNode() { - MOZ_COUNT_DTOR(nsCParserNode); - ReleaseAll(); -#ifdef HEAP_ALLOCATED_NODES - if(mNodeAllocator) { - mNodeAllocator->Recycle(this); - } - mNodeAllocator = nsnull; -#endif - mTokenAllocator = 0; -} - - -/** - * Init - * - * @update gess 3/25/98 - * @param - * @return - */ - -nsresult -nsCParserNode::Init(CToken* aToken, - nsTokenAllocator* aTokenAllocator, - nsNodeAllocator* aNodeAllocator) -{ - mTokenAllocator = aTokenAllocator; - mToken = aToken; - IF_HOLD(mToken); - mGenericState = PR_FALSE; - mUseCount=0; -#ifdef HEAP_ALLOCATED_NODES - mNodeAllocator = aNodeAllocator; -#endif - return NS_OK; -} - -void -nsCParserNode::AddAttribute(CToken* aToken) -{ -} - - -/** - * Gets the name of this node. Currently unused. - * - * @update gess 3/25/98 - * @param - * @return string ref containing node name - */ -const nsAString& -nsCParserNode::GetTagName() const { - return EmptyString(); -} - - -/** - * Get text value of this node, which translates into - * getting the text value of the underlying token - * - * @update gess 3/25/98 - * @param - * @return string ref of text from internal token - */ -const nsAString& -nsCParserNode::GetText() const -{ - if (mToken) { - return mToken->GetStringValue(); - } - return EmptyString(); -} - -/** - * Get node type, meaning, get the tag type of the - * underlying token - * - * @update gess 3/25/98 - * @param - * @return int value that represents tag type - */ -PRInt32 -nsCParserNode::GetNodeType(void) const -{ - return (mToken) ? mToken->GetTypeID() : 0; -} - - -/** - * Gets the token type, which corresponds to a value from - * eHTMLTokens_xxx. - * - * @update gess 3/25/98 - * @param - * @return - */ -PRInt32 -nsCParserNode::GetTokenType(void) const -{ - return (mToken) ? mToken->GetTokenType() : 0; -} - - -/** - * Retrieve the number of attributes on this node - * - * @update gess 3/25/98 - * @param - * @return int -- representing attribute count - */ -PRInt32 -nsCParserNode::GetAttributeCount(PRBool askToken) const -{ - return 0; -} - -/** - * Retrieve the string rep of the attribute key at the - * given index. - * - * @update gess 3/25/98 - * @param anIndex-- offset of attribute to retrieve - * @return string rep of given attribute text key - */ -const nsAString& -nsCParserNode::GetKeyAt(PRUint32 anIndex) const -{ - return EmptyString(); -} - - -/** - * Retrieve the string rep of the attribute at given offset - * - * @update gess 3/25/98 - * @param anIndex-- offset of attribute to retrieve - * @return string rep of given attribute text value - */ -const nsAString& -nsCParserNode::GetValueAt(PRUint32 anIndex) const -{ - return EmptyString(); -} - -PRInt32 -nsCParserNode::TranslateToUnicodeStr(nsString& aString) const -{ - if (eToken_entity == mToken->GetTokenType()) { - return ((CEntityToken*)mToken)->TranslateToUnicodeStr(aString); - } - return -1; -} - -/** - * This getter retrieves the line number from the input source where - * the token occured. Lines are interpreted as occuring between \n characters. - * @update gess7/24/98 - * @return int containing the line number the token was found on - */ -PRInt32 -nsCParserNode::GetSourceLineNumber(void) const { - return mToken ? mToken->GetLineNumber() : 0; -} - -/** - * This method pop the attribute token - * @update harishd 03/25/99 - * @return token at anIndex - */ - -CToken* -nsCParserNode::PopAttributeToken() { - return 0; -} - -/** Retrieve a string containing the tag and its attributes in "source" form - * @update rickg 06June2000 - * @return void - */ -void -nsCParserNode::GetSource(nsString& aString) -{ - eHTMLTags theTag = mToken ? (eHTMLTags)mToken->GetTypeID() : eHTMLTag_unknown; - aString.Assign(PRUnichar('<')); - const PRUnichar* theTagName = nsHTMLTags::GetStringValue(theTag); - if(theTagName) { - aString.Append(theTagName); - } - aString.Append(PRUnichar('>')); -} - -/** Release all the objects you're holding to. - * @update harishd 08/02/00 - * @return void - */ -nsresult -nsCParserNode::ReleaseAll() -{ - if(mTokenAllocator) { - IF_FREE(mToken,mTokenAllocator); - } - return NS_OK; -} - -nsresult -nsCParserStartNode::Init(CToken* aToken, - nsTokenAllocator* aTokenAllocator, - nsNodeAllocator* aNodeAllocator) -{ - NS_ASSERTION(mAttributes.GetSize() == 0, "attributes not recycled!"); - return nsCParserNode::Init(aToken, aTokenAllocator, aNodeAllocator); -} - -void nsCParserStartNode::AddAttribute(CToken* aToken) -{ - NS_ASSERTION(0 != aToken, "Error: Token shouldn't be null!"); - mAttributes.Push(aToken); -} - -PRInt32 -nsCParserStartNode::GetAttributeCount(PRBool askToken) const -{ - PRInt32 result = 0; - if (askToken) { - result = mToken ? mToken->GetAttributeCount() : 0; - } - else { - result = mAttributes.GetSize(); - } - return result; -} - -const nsAString& -nsCParserStartNode::GetKeyAt(PRUint32 anIndex) const -{ - if ((PRInt32)anIndex < mAttributes.GetSize()) { - CAttributeToken* attr = - NS_STATIC_CAST(CAttributeToken*, mAttributes.ObjectAt(anIndex)); - if (attr) { - return attr->GetKey(); - } - } - return EmptyString(); -} - -const nsAString& -nsCParserStartNode::GetValueAt(PRUint32 anIndex) const -{ - if (PRInt32(anIndex) < mAttributes.GetSize()) { - CAttributeToken* attr = - NS_STATIC_CAST(CAttributeToken*, mAttributes.ObjectAt(anIndex)); - if (attr) { - return attr->GetValue(); - } - } - return EmptyString(); -} - -CToken* -nsCParserStartNode::PopAttributeToken() -{ - return NS_STATIC_CAST(CToken*, mAttributes.Pop()); -} - -void nsCParserStartNode::GetSource(nsString& aString) -{ - aString.Assign(PRUnichar('<')); - const PRUnichar* theTagName = - nsHTMLTags::GetStringValue(nsHTMLTag(mToken->GetTypeID())); - if (theTagName) { - aString.Append(theTagName); - } - PRInt32 index; - PRInt32 size = mAttributes.GetSize(); - for (index = 0 ; index < size; ++index) { - CAttributeToken *theToken = - NS_STATIC_CAST(CAttributeToken*, mAttributes.ObjectAt(index)); - if (theToken) { - theToken->AppendSourceTo(aString); - aString.Append(PRUnichar(' ')); //this will get removed... - } - } - aString.Append(PRUnichar('>')); -} - -nsresult nsCParserStartNode::ReleaseAll() -{ - NS_ASSERTION(0!=mTokenAllocator, "Error: no token allocator"); - CToken* theAttrToken; - while ((theAttrToken = NS_STATIC_CAST(CToken*, mAttributes.Pop()))) { - IF_FREE(theAttrToken, mTokenAllocator); - } - nsCParserNode::ReleaseAll(); - return NS_OK; -} - diff --git a/htmlparser/src/nsParserNode.h b/htmlparser/src/nsParserNode.h index 3a9fde2bcca..e69de29bb2d 100644 --- a/htmlparser/src/nsParserNode.h +++ b/htmlparser/src/nsParserNode.h @@ -1,321 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * 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"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -/** - * MODULE NOTES: - * @update gess 4/1/98 - * - * This class is defines the basic interface between the - * parser and the content sink. The parser will iterate - * over the collection of tokens that it sees from the - * tokenizer, coverting each related "group" into one of - * these. This object gets passed to the sink, and is - * then immediately reused. - * - * If you want to hang onto one of these, you should - * make your own copy. - * - */ - -#ifndef NS_PARSERNODE__ -#define NS_PARSERNODE__ - -#include "nsIParserNode.h" -#include "nsToken.h" -#include "nsString.h" -#include "nsParserCIID.h" -#include "nsDeque.h" -#include "nsDTDUtils.h" - -class nsTokenAllocator; - -class nsCParserNode : public nsIParserNode { - - protected: - - PRInt32 mRefCnt; - - public: - - void AddRef() - { - ++mRefCnt; - } - - void Release(nsFixedSizeAllocator& aPool) - { - if (--mRefCnt == 0) - Destroy(this, aPool); - } - -#ifndef HEAP_ALLOCATED_NODES - protected: - - /** - * Hide operator new; clients should use Create() instead. - */ - static void* operator new(size_t) CPP_THROW_NEW { return 0; } - - /** - * Hide operator delete; clients should use Destroy() instead. - */ - static void operator delete(void*,size_t) {} - -#endif - - public: - static nsCParserNode* Create(CToken* aToken, - nsTokenAllocator* aTokenAllocator, - nsNodeAllocator* aNodeAllocator) - { -#ifdef HEAP_ALLOCATED_NODES - return new -#else - nsFixedSizeAllocator& pool = aNodeAllocator->GetArenaPool(); - void* place = pool.Alloc(sizeof(nsCParserNode)); - return ::new (place) -#endif - nsCParserNode(aToken, aTokenAllocator, aNodeAllocator); - } - - static void Destroy(nsCParserNode* aNode, nsFixedSizeAllocator& aPool) - { -#ifdef HEAP_ALLOCATED_NODES - delete aNode; -#else - aNode->~nsCParserNode(); - aPool.Free(aNode, sizeof(*aNode)); -#endif - } - - /** - * Default constructor - */ - nsCParserNode(); - - /** - * Constructor - * @update gess5/11/98 - * @param aToken is the token this node "refers" to - */ - nsCParserNode(CToken* aToken, - nsTokenAllocator* aTokenAllocator, - nsNodeAllocator* aNodeAllocator=0); - - /** - * Destructor - * @update gess5/11/98 - */ - virtual ~nsCParserNode(); - - /** - * Init - * @update gess5/11/98 - */ - virtual nsresult Init(CToken* aToken, - nsTokenAllocator* aTokenAllocator, - nsNodeAllocator* aNodeAllocator=0); - - /** - * Retrieve the name of the node - * @update gess5/11/98 - * @return string containing node name - */ - virtual const nsAString& GetTagName() const; - - /** - * Retrieve the text from the given node - * @update gess5/11/98 - * @return string containing node text - */ - virtual const nsAString& GetText() const; - - /** - * Retrieve the type of the parser node. - * @update gess5/11/98 - * @return node type. - */ - virtual PRInt32 GetNodeType() const; - - /** - * Retrieve token type of parser node - * @update gess5/11/98 - * @return token type - */ - virtual PRInt32 GetTokenType() const; - - - //*************************************** - //methods for accessing key/value pairs - //*************************************** - - /** - * Retrieve the number of attributes in this node. - * @update gess5/11/98 - * @return count of attributes (may be 0) - */ - virtual PRInt32 GetAttributeCount(PRBool askToken=PR_FALSE) const; - - /** - * Retrieve the key (of key/value pair) at given index - * @update gess5/11/98 - * @param anIndex is the index of the key you want - * @return string containing key. - */ - virtual const nsAString& GetKeyAt(PRUint32 anIndex) const; - - /** - * Retrieve the value (of key/value pair) at given index - * @update gess5/11/98 - * @param anIndex is the index of the value you want - * @return string containing value. - */ - virtual const nsAString& GetValueAt(PRUint32 anIndex) const; - - /** - * NOTE: When the node is an entity, this will translate the entity - * to it's unicode value, and store it in aString. - * @update gess5/11/98 - * @param aString will contain the resulting unicode string value - * @return int (unicode char or unicode index from table) - */ - virtual PRInt32 TranslateToUnicodeStr(nsString& aString) const; - - /** - * - * @update gess5/11/98 - * @param - * @return - */ - virtual void AddAttribute(CToken* aToken); - - /** - * This getter retrieves the line number from the input source where - * the token occured. Lines are interpreted as occuring between \n characters. - * @update gess7/24/98 - * @return int containing the line number the token was found on - */ - virtual PRInt32 GetSourceLineNumber(void) const; - - /** This method pop the attribute token from the given index - * @update harishd 03/25/99 - * @return token at anIndex - */ - virtual CToken* PopAttributeToken(); - - /** Retrieve a string containing the tag and its attributes in "source" form - * @update rickg 06June2000 - * @return void - */ - virtual void GetSource(nsString& aString); - - /** - * This pair of methods allows us to set a generic bit (for arbitrary use) - * on each node stored in the context. - * @update gess 11May2000 - */ - virtual PRBool GetGenericState(void) const {return mGenericState;} - virtual void SetGenericState(PRBool aState) {mGenericState=aState;} - - /** Release all the objects you're holding - * @update harishd 08/02/00 - * @return void - */ - virtual nsresult ReleaseAll(); - - CToken* mToken; - PRInt32 mUseCount; - PRPackedBool mGenericState; - - nsTokenAllocator* mTokenAllocator; -#ifdef HEAP_ALLOCATED_NODES - nsNodeAllocator* mNodeAllocator; // weak -#endif -}; - - -class nsCParserStartNode : public nsCParserNode -{ -public: - static nsCParserNode* Create(CToken* aToken, - nsTokenAllocator* aTokenAllocator, - nsNodeAllocator* aNodeAllocator) - { -#ifdef HEAP_ALLOCATED_NODES - return new -#else - nsFixedSizeAllocator& pool = aNodeAllocator->GetArenaPool(); - void* place = pool.Alloc(sizeof(nsCParserStartNode)); - return ::new (place) -#endif - nsCParserStartNode(aToken, aTokenAllocator, aNodeAllocator); - } - - nsCParserStartNode() - : nsCParserNode(), mAttributes(0) { } - - nsCParserStartNode(CToken* aToken, - nsTokenAllocator* aTokenAllocator, - nsNodeAllocator* aNodeAllocator = 0) - : nsCParserNode(aToken, aTokenAllocator, aNodeAllocator), mAttributes(0) { } - - virtual ~nsCParserStartNode() - { - NS_ASSERTION(0 != mTokenAllocator, "Error: no token allocator"); - CToken* theAttrToken = 0; - while ((theAttrToken = NS_STATIC_CAST(CToken*, mAttributes.Pop()))) { - IF_FREE(theAttrToken, mTokenAllocator); - } - } - - virtual nsresult Init(CToken* aToken, - nsTokenAllocator* aTokenAllocator, - nsNodeAllocator* aNodeAllocator = 0); - virtual void AddAttribute(CToken* aToken); - virtual PRInt32 GetAttributeCount(PRBool askToken = PR_FALSE) const; - virtual const nsAString& GetKeyAt(PRUint32 anIndex) const; - virtual const nsAString& GetValueAt(PRUint32 anIndex) const; - virtual CToken* PopAttributeToken(); - virtual void GetSource(nsString& aString); - virtual nsresult ReleaseAll(); -protected: - nsDeque mAttributes; -}; - -#endif - diff --git a/htmlparser/src/nsToken.cpp b/htmlparser/src/nsToken.cpp index 28bc5b73a1d..e69de29bb2d 100644 --- a/htmlparser/src/nsToken.cpp +++ b/htmlparser/src/nsToken.cpp @@ -1,195 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * 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"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsToken.h" -#include "nsScanner.h" - - -#ifdef MATCH_CTOR_DTOR -MOZ_DECL_CTOR_COUNTER(CToken) -#endif - -static int TokenCount=0; -static int DelTokenCount=0; - -int CToken::GetTokenCount(){return TokenCount-DelTokenCount;} - - -/************************************************************** - And now for the CToken... - **************************************************************/ - -/** - * Default constructor - * - * @update gess 7/21/98 - */ -CToken::CToken(PRInt32 aTag) { - // Tokens are allocated through the arena ( not heap allocated..yay ). - // We, therefore, don't need this macro anymore.. -#ifdef MATCH_CTOR_DTOR - MOZ_COUNT_CTOR(CToken); -#endif - mAttrCount=0; - mNewlineCount=0; - mLineNumber = 0; - mTypeID=aTag; - // Note that the use count starts with 1 instead of 0. This - // is because of the assumption that any token created is in - // use and therefore does not require an explicit addref, or - // rather IF_HOLD. This, also, will make sure that tokens created - // on the stack do not accidently hit the arena recycler. - mUseCount=1; - -#ifdef NS_DEBUG - ++TokenCount; -#endif -} - -/** - * Decstructor - * - * @update gess 3/25/98 - */ -CToken::~CToken() { - // Tokens are allocated through the arena ( not heap allocated..yay ). - // We, therefore, don't need this macro anymore.. -#ifdef MATCH_CTOR_DTOR - MOZ_COUNT_DTOR(CToken); -#endif - ++DelTokenCount; - mUseCount=0; -} - - -/** - * Virtual method used to tell this toke to consume his - * valid chars. - * - * @update gess 3/25/98 - * @param aChar -- first char in sequence - * @param aScanner -- object to retrieve data from - * @return int error code - */ -nsresult CToken::Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aMode) { - nsresult result=NS_OK; - return result; -} - -/** - * Get string of full contents, suitable for debug dump. - * It should look exactly like the input source. - * @update gess5/11/98 - * @return reference to string containing string value - */ -void CToken::GetSource(nsString& anOutputString){ - anOutputString.Assign(GetStringValue()); -} - -/** - * @update harishd 3/23/00 - * @return reference to string containing string value - */ -void CToken::AppendSourceTo(nsAString& anOutputString){ - anOutputString.Append(GetStringValue()); -} - -/** - * Sets the internal ordinal value for this token. - * This method is deprecated, and will soon be going away. - * - * @update gess 3/25/98 - * @param value -- new ordinal value for this token - */ -void CToken::SetTypeID(PRInt32 aTypeID) { - mTypeID=aTypeID; -} - -/** - * Retrieves copy of internal ordinal value. - * This method is deprecated, and will soon be going away. - * - * @update gess 3/25/98 - * @return int containing ordinal value - */ -PRInt32 CToken::GetTypeID(void) { - return mTypeID; -} - -/** - * Retrieves copy of attr count for this token - * - * @update gess 3/25/98 - * @return int containing attribute count - */ -PRInt16 CToken::GetAttributeCount(void) { - return mAttrCount; -} - - -/** - * Retrieve type of token. This class returns -1, but - * subclasses return something more meaningful. - * - * @update gess 3/25/98 - * @return int value containing token type. - */ -PRInt32 CToken::GetTokenType(void) { - return -1; -} - -/** - * retrieve this tokens classname. - * - * @update gess 3/25/98 - * @return char* containing name of class - */ -const char* CToken::GetClassName(void) { - return "token"; -} - - -/** - * - * @update gess 3/25/98 - */ -void CToken::SelfTest(void) { -#ifdef _DEBUG -#endif -} - - diff --git a/htmlparser/src/nsViewSourceHTML.cpp b/htmlparser/src/nsViewSourceHTML.cpp index 6f06bfcd0c5..e69de29bb2d 100644 --- a/htmlparser/src/nsViewSourceHTML.cpp +++ b/htmlparser/src/nsViewSourceHTML.cpp @@ -1,1228 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * jce2@po.cwru.edu : Added pref to turn on/off - * Boris Zbarsky - * rbs@maths.uq.edu.au - * Andreas M. Schneider - * - * Alternatively, the contents of this file may be used under the terms of - * 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"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * MODULE NOTES: - * @update gess 4/8/98 - * - * - */ - -/* - * Set NS_VIEWSOURCE_TOKENS_PER_BLOCK to 0 to disable multi-block - * output. Multi-block output helps reduce the amount of bidi - * processing we have to do on the resulting content model. - */ -#define NS_VIEWSOURCE_TOKENS_PER_BLOCK 16 - -#ifdef RAPTOR_PERF_METRICS -# define START_TIMER() \ - if(mParser) mParser->mParseTime.Start(PR_FALSE); \ - if(mParser) mParser->mDTDTime.Start(PR_FALSE); - -# define STOP_TIMER() \ - if(mParser) mParser->mParseTime.Stop(); \ - if(mParser) mParser->mDTDTime.Stop(); - -#else -# define STOP_TIMER() -# define START_TIMER() -#endif - -#include "nsIAtom.h" -#include "nsViewSourceHTML.h" -#include "nsCRT.h" -#include "nsParser.h" -#include "nsScanner.h" -#include "nsIParser.h" -#include "nsDTDUtils.h" -#include "nsIContentSink.h" -#include "nsIHTMLContentSink.h" -#include "nsHTMLTokenizer.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" -#include "nsUnicharUtils.h" -#include "nsPrintfCString.h" - -#include "nsIServiceManager.h" - -#include "COtherDTD.h" -#include "nsElementTable.h" - -#include "prenv.h" //this is here for debug reasons... -#include "prtypes.h" //this is here for debug reasons... -#include "prio.h" -#include "plstr.h" -#include "prmem.h" - -#ifdef RAPTOR_PERF_METRICS -#include "stopwatch.h" -Stopwatch vsTimer; -#endif - - -static NS_DEFINE_IID(kClassIID, NS_VIEWSOURCE_HTML_IID); - -// Define this to dump the viewsource stuff to a file -//#define DUMP_TO_FILE -#ifdef DUMP_TO_FILE -#include - FILE* gDumpFile=0; - static const char* gDumpFileName = "/tmp/viewsource.html"; -// static const char* gDumpFileName = "\\temp\\viewsource.html"; -#endif // DUMP_TO_FILE - -// bug 22022 - these are used to toggle 'Wrap Long Lines' on the viewsource -// window by selectively setting/unsetting the following class defined in -// viewsource.css; the setting is remembered between invocations using a pref. -static const char kBodyId[] = "viewsource"; -static const char kBodyClassWrap[] = "wrap"; - -/** - * This method gets called as part of our COM-like interfaces. - * Its purpose is to create an interface to parser object - * of some type. - * - * @update gess 4/8/98 - * @param nsIID id of object to discover - * @param aInstancePtr ptr to newly discovered interface - * @return NS_xxx result code - */ -nsresult CViewSourceHTML::QueryInterface(const nsIID& aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - - if(aIID.Equals(NS_GET_IID(nsISupports))) { //do IUnknown... - *aInstancePtr = (nsIDTD*)(this); - } - else if(aIID.Equals(NS_GET_IID(nsIDTD))) { //do IParser base class... - *aInstancePtr = (nsIDTD*)(this); - } - else if(aIID.Equals(kClassIID)) { //do this class... - *aInstancePtr = (CViewSourceHTML*)(this); - } - else { - *aInstancePtr=0; - return NS_NOINTERFACE; - } - NS_ADDREF_THIS(); - return NS_OK; -} - -/** - * This method is defined in nsIParser. It is used to - * cause the COM-like construction of an nsParser. - * - * @update gess 4/8/98 - * @param nsIParser** ptr to newly instantiated parser - * @return NS_xxx error result - */ -nsresult NS_NewViewSourceHTML(nsIDTD** aInstancePtrResult) -{ - CViewSourceHTML* it = new CViewSourceHTML(); - - if (it == 0) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return it->QueryInterface(kClassIID, (void **) aInstancePtrResult); -} - - -NS_IMPL_ADDREF(CViewSourceHTML) -NS_IMPL_RELEASE(CViewSourceHTML) - -/******************************************** - ********************************************/ - -class CIndirectTextToken : public CTextToken { -public: - CIndirectTextToken() : CTextToken() { - mIndirectString=0; - } - - void SetIndirectString(const nsAString& aString) { - mIndirectString=&aString; - } - - virtual const nsAString& GetStringValue(void){ - return (const nsAString&)*mIndirectString; - } - - const nsAString* mIndirectString; -}; - - -/******************************************************************* - Now define the CSharedVSCOntext class... - *******************************************************************/ - -class CSharedVSContext { -public: - - CSharedVSContext() : - mEndNode(), - mStartNode(), - mTokenNode(), - mITextToken(), - mErrorToken(NS_LITERAL_STRING("error")) { - } - - ~CSharedVSContext() { - } - - static CSharedVSContext& GetSharedContext() { - static CSharedVSContext gSharedVSContext; - return gSharedVSContext; - } - - nsCParserNode mEndNode; - nsCParserStartNode mStartNode; - nsCParserStartNode mTokenNode; - CIndirectTextToken mITextToken; - CTextToken mErrorToken; -}; - -enum { - VIEW_SOURCE_START_TAG = 0, - VIEW_SOURCE_END_TAG = 1, - VIEW_SOURCE_COMMENT = 2, - VIEW_SOURCE_CDATA = 3, - VIEW_SOURCE_DOCTYPE = 4, - VIEW_SOURCE_PI = 5, - VIEW_SOURCE_ENTITY = 6, - VIEW_SOURCE_TEXT = 7, - VIEW_SOURCE_ATTRIBUTE_NAME = 8, - VIEW_SOURCE_ATTRIBUTE_VALUE = 9, - VIEW_SOURCE_SUMMARY = 10, - VIEW_SOURCE_POPUP = 11, - VIEW_SOURCE_MARKUPDECLARATION = 12 -}; - -static const char* const kElementClasses[] = { - "start-tag", - "end-tag", - "comment", - "cdata", - "doctype", - "pi", - "entity", - "text", - "attribute-name", - "attribute-value", - "summary", - "popup", - "markupdeclaration" -}; - -static const char* const kBeforeText[] = { - "<", - "", - ">", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "" -}; - -#ifdef DUMP_TO_FILE -static const char* const kDumpFileBeforeText[] = { - "<", - "</", - "", - "", - "", - "", - "&", - "", - "", - "=", - "", - "", - "" -}; - -static const char* const kDumpFileAfterText[] = { - ">", - ">", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "" -}; -#endif // DUMP_TO_FILE - -/** - * Default constructor - * - * @update gess 4/9/98 - * @param - * @return - */ -CViewSourceHTML::CViewSourceHTML() : mFilename(), mTags(), mErrors() { - mStartTag = VIEW_SOURCE_START_TAG; - mEndTag = VIEW_SOURCE_END_TAG; - mCommentTag = VIEW_SOURCE_COMMENT; - mCDATATag = VIEW_SOURCE_CDATA; - mMarkupDeclaration = VIEW_SOURCE_MARKUPDECLARATION; - mDocTypeTag = VIEW_SOURCE_DOCTYPE; - mPITag = VIEW_SOURCE_PI; - mEntityTag = VIEW_SOURCE_ENTITY; - mText = VIEW_SOURCE_TEXT; - mKey = VIEW_SOURCE_ATTRIBUTE_NAME; - mValue = VIEW_SOURCE_ATTRIBUTE_VALUE; - mSummaryTag = VIEW_SOURCE_SUMMARY; - mPopupTag = VIEW_SOURCE_POPUP; - mSyntaxHighlight = PR_FALSE; - mWrapLongLines = PR_FALSE; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - PRBool temp; - nsresult rv; - rv = prefBranch->GetBoolPref("view_source.syntax_highlight", &temp); - mSyntaxHighlight = NS_SUCCEEDED(rv) ? temp : PR_TRUE; - - rv = prefBranch->GetBoolPref("view_source.wrap_long_lines", &temp); - mWrapLongLines = NS_SUCCEEDED(rv) ? temp : PR_FALSE; - } - - mParser = 0; - mSink = 0; - mLineNumber = 1; - mTokenizer = 0; - mDocType=eHTML3_Quirks; // why? - mHasOpenRoot=PR_FALSE; - mHasOpenBody=PR_FALSE; - - mTokenCount=0; - -#ifdef DUMP_TO_FILE - gDumpFile = fopen(gDumpFileName,"w"); -#endif // DUMP_TO_FILE - -} - - - -/** - * Default destructor - * - * @update gess 4/9/98 - * @param - * @return - */ -CViewSourceHTML::~CViewSourceHTML(){ - mParser=0; //just to prove we destructed... -} - -/** - * - * @update gess1/8/99 - * @param - * @return - */ -const nsIID& CViewSourceHTML::GetMostDerivedIID(void) const{ - return kClassIID; -} - -/** - * Call this method if you want the DTD to construct a fresh - * instance of itself. - * @update gess7/23/98 - * @param - * @return - */ -nsresult CViewSourceHTML::CreateNewInstance(nsIDTD** aInstancePtrResult){ - return NS_NewViewSourceHTML(aInstancePtrResult); -} - -/** - * This method is called to determine if the given DTD can parse - * a document in a given source-type. - * NOTE: Parsing always assumes that the end result will involve - * storing the result in the main content model. - * @update gess6/24/98 - * @param - * @return TRUE if this DTD can satisfy the request; FALSE otherwise. - */ -NS_IMETHODIMP_(eAutoDetectResult) -CViewSourceHTML::CanParse(CParserContext& aParserContext, - const nsString& aBuffer, PRInt32 aVersion) -{ - eAutoDetectResult result=eUnknownDetect; - - if(eViewSource==aParserContext.mParserCommand) { - if(aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kPlainTextContentType)) || - aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kTextCSSContentType)) || - aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kTextJSContentType)) || - aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kApplicationJSContentType))) { - result=eValidDetect; - } - if(aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kXMLTextContentType)) || - aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kXMLApplicationContentType)) || - aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kXHTMLApplicationContentType)) || - aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kRDFTextContentType)) || - aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kHTMLTextContentType)) || - aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kXULTextContentType)) || -#ifdef MOZ_SVG - aParserContext.mMimeType.Equals(NS_LITERAL_CSTRING(kSVGTextContentType)) || -#endif - aParserContext.mMimeType.Equals(kSGMLTextContentType)) { - result=ePrimaryDetect; - } - } - return result; -} - - -/** - * The parser uses a code sandwich to wrap the parsing process. Before - * the process begins, WillBuildModel() is called. Afterwards the parser - * calls DidBuildModel(). - * @update rickg 03.20.2000 - * @param aParserContext - * @param aSink - * @return error code (almost always 0) - */ -nsresult CViewSourceHTML::WillBuildModel(const CParserContext& aParserContext, - nsITokenizer* aTokenizer, - nsIContentSink* aSink){ - - nsresult result=NS_OK; - -#ifdef RAPTOR_PERF_METRICS - vsTimer.Reset(); - NS_START_STOPWATCH(vsTimer); -#endif - - STOP_TIMER(); - mSink=(nsIHTMLContentSink*)aSink; - - if((!aParserContext.mPrevContext) && (mSink)) { - - nsAString & contextFilename = aParserContext.mScanner->GetFilename(); - mFilename = Substring(contextFilename, - 12, // The length of "view-source:" - contextFilename.Length() - 12); - - mTags.Truncate(); - mErrors.Assign(NS_LITERAL_STRING(" HTML 4.0 Strict-DTD validation (enabled); [Should use Transitional?].\n")); - - mDocType=aParserContext.mDocType; - mMimeType=aParserContext.mMimeType; - mDTDMode=aParserContext.mDTDMode; - mParserCommand=aParserContext.mParserCommand; - mTokenizer = aTokenizer; - mErrorCount=0; - mTagCount=0; - -#ifdef DUMP_TO_FILE - if (gDumpFile) { - - fprintf(gDumpFile, "\n"); - fprintf(gDumpFile, "\n"); - fprintf(gDumpFile, ""); - fprintf(gDumpFile, "Source of: "); - fputs(NS_ConvertUCS2toUTF8(mFilename).get(), gDumpFile); - fprintf(gDumpFile, "\n"); - fprintf(gDumpFile, "\n"); - fprintf(gDumpFile, "\n"); - fprintf(gDumpFile, "\n"); - fprintf(gDumpFile, "\n"); - fprintf(gDumpFile, "
\n");
-    }
-#endif //DUMP_TO_FILE
-  }
-
-
-  if(eViewSource!=aParserContext.mParserCommand)
-    mDocType=ePlainText;
-  else mDocType=aParserContext.mDocType;
-
-  mLineNumber = 1;
-  result = mSink->WillBuildModel(); 
-
-  START_TIMER();
-  return result;
-}
-
-/**
-  * The parser uses a code sandwich to wrap the parsing process. Before
-  * the process begins, WillBuildModel() is called. Afterwards the parser
-  * calls DidBuildModel(). 
-  * @update	gess5/18/98
-  * @param	aFilename is the name of the file being parsed.
-  * @return	error code (almost always 0)
-  */
-NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink) {
-  nsresult result=NS_OK;
-
-  if(aTokenizer && aParser) {
-
-    nsITokenizer*  oldTokenizer=mTokenizer;
-    mTokenizer=aTokenizer;
-    nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
-
-    if(!mHasOpenRoot) {
-      // For the stack-allocated tokens below, it's safe to pass a null
-      // token allocator, because there are no attributes on the tokens.
-      PRBool didBlock = PR_FALSE;
-
-      CStartToken htmlToken(NS_LITERAL_STRING("HTML"), eHTMLTag_html);
-      nsCParserNode htmlNode(&htmlToken, 0/*stack token*/);
-      mSink->OpenHTML(htmlNode);
-
-      CStartToken headToken(NS_LITERAL_STRING("HEAD"), eHTMLTag_head);
-      nsCParserNode headNode(&headToken, 0/*stack token*/);
-      mSink->OpenHead(headNode);
-
-      // Note that XUL will automatically add the prefix "Source of: "
-      if (StringBeginsWith(mFilename, NS_LITERAL_STRING("data:")) &&
-          mFilename.Length() > 50) {
-        nsAutoString dataFilename(Substring(mFilename, 0, 50));
-        dataFilename.Append(NS_LITERAL_STRING("..."));
-        mSink->SetTitle(dataFilename);
-      } else {
-        mSink->SetTitle(mFilename);
-      }
-
-      if (theAllocator) {
-        CStartToken* theToken=
-          NS_STATIC_CAST(CStartToken*,
-                         theAllocator->CreateTokenOfType(eToken_start,
-                                                         eHTMLTag_link,
-                                                         NS_LITERAL_STRING("LINK")));
-        if (theToken) {
-          nsCParserStartNode theNode(theToken, theAllocator);
-
-          AddAttrToNode(theNode, theAllocator,
-                        NS_LITERAL_STRING("rel"),
-                        NS_LITERAL_STRING("stylesheet"));
-
-          AddAttrToNode(theNode, theAllocator,
-                        NS_LITERAL_STRING("type"),
-                        NS_LITERAL_STRING("text/css"));
-
-          AddAttrToNode(theNode, theAllocator,
-                        NS_LITERAL_STRING("href"),
-                        NS_LITERAL_STRING("resource://gre/res/viewsource.css"));
-          
-          result = mSink->AddLeaf(theNode);
-          didBlock = result == NS_ERROR_HTMLPARSER_BLOCK;
-        }
-      }
-
-      CEndToken endHeadToken(eHTMLTag_head);
-      nsCParserNode endHeadNode(&endHeadToken, 0/*stack token*/);
-      result = mSink->CloseHead();
-      if(NS_SUCCEEDED(result)) {
-        mHasOpenRoot = PR_TRUE;
-        if (didBlock) {
-          result = NS_ERROR_HTMLPARSER_BLOCK;
-        }
-      }
-    }
-    if (NS_SUCCEEDED(result) && !mHasOpenBody) {
-      if (theAllocator) {
-        CStartToken* bodyToken=
-          NS_STATIC_CAST(CStartToken*,
-                         theAllocator->CreateTokenOfType(eToken_start,
-                                                         eHTMLTag_body,
-                                                         NS_LITERAL_STRING("BODY")));
-        if (bodyToken) {
-          nsCParserStartNode bodyNode(bodyToken, theAllocator);
-
-          AddAttrToNode(bodyNode, theAllocator,
-                        NS_LITERAL_STRING("id"),
-                        NS_ConvertASCIItoUCS2(kBodyId));
-          
-          if (mWrapLongLines) {
-            AddAttrToNode(bodyNode, theAllocator,
-                          NS_LITERAL_STRING("class"),
-                          NS_ConvertASCIItoUCS2(kBodyClassWrap));
-          }
-          result = mSink->OpenBody(bodyNode);
-          if(NS_SUCCEEDED(result)) mHasOpenBody=PR_TRUE;
-        }
-        
-        if (NS_SUCCEEDED(result)) {
-          CStartToken* preToken =
-            NS_STATIC_CAST(CStartToken*,
-                           theAllocator->CreateTokenOfType(eToken_start,
-                                                           eHTMLTag_pre,
-                                                           NS_LITERAL_STRING("PRE")));
-          if (preToken) {
-            nsCParserStartNode preNode(preToken, theAllocator);
-            AddAttrToNode(preNode, theAllocator,
-                          NS_LITERAL_STRING("id"),
-                          NS_LITERAL_STRING("line1"));
-            result = mSink->OpenContainer(preNode);
-          } else {
-            result = NS_ERROR_OUT_OF_MEMORY;
-          }
-        }
-      }
-    }
-
-    mSink->WillProcessTokens();
-
-    while(NS_SUCCEEDED(result)){
-      CToken* theToken=mTokenizer->PopToken();
-      if(theToken) {
-        result=HandleToken(theToken,aParser);
-        if(NS_SUCCEEDED(result)) {
-          IF_FREE(theToken, mTokenizer->GetTokenAllocator());
-          if (mParser->CanInterrupt() &&
-              mSink->DidProcessAToken() == NS_ERROR_HTMLPARSER_INTERRUPTED) {
-            result = NS_ERROR_HTMLPARSER_INTERRUPTED;
-            break;
-          }
-        }
-        else if(NS_ERROR_HTMLPARSER_BLOCK!=result){
-          mTokenizer->PushTokenFront(theToken);
-        }
-      }
-      else break;
-    }//while
-   
-    mTokenizer=oldTokenizer;
-  }
-  else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
-  return result;
-}
-
-
-/**
- * Call this to display an error summary regarding the page.
- * 
- * @update	rickg 6June2000
- * @return  nsresult
- */
-nsresult  CViewSourceHTML::GenerateSummary() {
-  nsresult result=NS_OK;
-
-  if(mErrorCount && mTagCount) {
-
-    mErrors.Append(NS_LITERAL_STRING("\n\n "));
-    mErrors.AppendInt(mErrorCount);
-    mErrors.Append(NS_LITERAL_STRING(" error(s) detected -- see highlighted portions.\n"));
-
-    result=WriteTag(mSummaryTag,mErrors,0,PR_FALSE);
-  }
-
-  return result;
-}
-
-/**
- * Call this to start a new PRE block.  See bug 86355 for why this
- * makes some pages much faster.
- */
-void CViewSourceHTML::StartNewPreBlock(void){
-  CEndToken endToken(eHTMLTag_pre);
-  nsCParserNode endNode(&endToken, 0/*stack token*/);
-  mSink->CloseContainer(eHTMLTag_pre);
-
-  nsTokenAllocator* theAllocator = mTokenizer->GetTokenAllocator();
-  if (!theAllocator) {
-    return;
-  }
-  
-  CStartToken* theToken =
-    NS_STATIC_CAST(CStartToken*,
-                   theAllocator->CreateTokenOfType(eToken_start,
-                                                   eHTMLTag_pre,
-                                                   NS_LITERAL_STRING("PRE")));
-  if (!theToken) {
-    return;
-  }
-
-  nsCParserStartNode startNode(theToken, theAllocator);
-  AddAttrToNode(startNode, theAllocator,
-                NS_LITERAL_STRING("id"),
-                NS_ConvertASCIItoUCS2(nsPrintfCString("line%d", mLineNumber)));
-  mSink->OpenContainer(startNode);
-  
-#ifdef DUMP_TO_FILE
-  if (gDumpFile) {
-    fprintf(gDumpFile, "
\n"); - fprintf(gDumpFile, "
\n", mLineNumber);
-  }
-#endif // DUMP_TO_FILE
-
-  mTokenCount = 0;
-}
-
-void CViewSourceHTML::AddAttrToNode(nsCParserStartNode& aNode,
-                                    nsTokenAllocator* aAllocator,
-                                    const nsAString& aAttrName,
-                                    const nsAString& aAttrValue)
-{
-  NS_PRECONDITION(aAllocator, "Must have a token allocator!");
-  
-  CAttributeToken* theAttr =
-    (CAttributeToken*) aAllocator->CreateTokenOfType(eToken_attribute,
-                                                     eHTMLTag_unknown,
-                                                     aAttrValue);
-  if (!theAttr) {
-    NS_ERROR("Failed to allocate attribute token");
-    return;
-  }
-
-  theAttr->SetKey(aAttrName);
-  aNode.AddAttribute(theAttr);
-}
-
-/**
- * 
- * @update	gess5/18/98
- * @param 
- * @return
- */
-NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink){
-  nsresult result= NS_OK;
-
-  //ADD CODE HERE TO CLOSE OPEN CONTAINERS...
-
-  if(aParser){
-
-    mParser=(nsParser*)aParser;  //debug XXX
-    STOP_TIMER();
-
-    mSink=(nsIHTMLContentSink*)aParser->GetContentSink();
-    if((aNotifySink) && (mSink)) {
-        //now let's close automatically auto-opened containers...
-
-#ifdef DUMP_TO_FILE
-      if(gDumpFile) {
-        fprintf(gDumpFile, "
\n"); - fprintf(gDumpFile, "\n"); - fprintf(gDumpFile, "\n"); - fclose(gDumpFile); - } -#endif // DUMP_TO_FILE - - if(ePlainText!=mDocType) { - CEndToken theToken(eHTMLTag_pre); - nsCParserNode preNode(&theToken, 0/*stack token*/); - mSink->CloseContainer(eHTMLTag_pre); - - CEndToken bodyToken(eHTMLTag_body); - nsCParserNode bodyNode(&bodyToken, 0/*stack token*/); - mSink->CloseBody(); - - CEndToken htmlToken(eHTMLTag_html); - nsCParserNode htmlNode(&htmlToken, 0/*stack token*/); - mSink->CloseHTML(); - } - result = mSink->DidBuildModel(); - } - - START_TIMER(); - - } - -#ifdef RAPTOR_PERF_METRICS - NS_STOP_STOPWATCH(vsTimer); - printf("viewsource timer: "); - vsTimer.Print(); - printf("\n"); -#endif - - return result; -} - -/** - * Use this id you want to stop the building content model - * --------------[ Sets DTD to STOP mode ]---------------- - * It's recommended to use this method in accordance with - * the parser's terminate() method. - * - * @update harishd 07/22/99 - * @param - * @return - */ -NS_IMETHODIMP_(void) -CViewSourceHTML::Terminate() { -} - -NS_IMETHODIMP_(PRInt32) -CViewSourceHTML::GetType() { - return NS_IPARSER_FLAG_HTML; -} - -NS_IMETHODIMP -CViewSourceHTML::CollectSkippedContent(PRInt32 aTag, nsAString& aContent, PRInt32 &aLineNo) -{ - return NS_OK; -} - -/** - * - * @update gess5/18/98 - * @param - * @return - */ -NS_IMETHODIMP CViewSourceHTML::WillResumeParse(nsIContentSink* aSink){ - nsresult result = NS_OK; - if(mSink) { - result = mSink->WillResume(); - } - return result; -} - -/** - * - * @update gess5/18/98 - * @param - * @return - */ -NS_IMETHODIMP CViewSourceHTML::WillInterruptParse(nsIContentSink* aSink){ - nsresult result = NS_OK; - if(mSink) { - result = mSink->WillInterrupt(); - } - return result; -} - -/** - * Called by the parser to enable/disable dtd verification of the - * internal context stack. - * @update gess 7/23/98 - * @param - * @return - */ -void CViewSourceHTML::SetVerification(PRBool aEnabled) -{ -} - -/** - * This method is called to determine whether or not a tag - * of one type can contain a tag of another type. - * - * @update gess 3/25/98 - * @param aParent -- int tag of parent container - * @param aChild -- int tag of child container - * @return PR_TRUE if parent can contain child - */ -PRBool CViewSourceHTML::CanContain(PRInt32 aParent,PRInt32 aChild) const{ - PRBool result=PR_TRUE; - return result; -} - -/** - * Give rest of world access to our tag enums, so that CanContain(), etc, - * become useful. - */ -NS_IMETHODIMP -CViewSourceHTML::StringTagToIntTag(const nsAString &aTag, - PRInt32* aIntTag) const -{ - *aIntTag = nsHTMLTags::LookupTag(aTag); - - return NS_OK; -} - -NS_IMETHODIMP_(const PRUnichar *) -CViewSourceHTML::IntTagToStringTag(PRInt32 aIntTag) const -{ - const PRUnichar *str_ptr = nsHTMLTags::GetStringValue((nsHTMLTag)aIntTag); - - NS_ASSERTION(str_ptr, "Bad tag enum passed to COtherDTD::IntTagToStringTag()" - "!!"); - - return str_ptr; -} - -NS_IMETHODIMP_(nsIAtom *) -CViewSourceHTML::IntTagToAtom(PRInt32 aIntTag) const -{ - nsIAtom *atom = nsHTMLTags::GetAtom((nsHTMLTag)aIntTag); - - NS_ASSERTION(atom, "Bad tag enum passed to COtherDTD::IntTagToAtom()" - "!!"); - - return atom; -} - -PRBool CViewSourceHTML::IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const { - PRBool result=PR_FALSE; - return result; -} - -PRBool CViewSourceHTML::IsInlineElement(PRInt32 aTagID,PRInt32 aParentID) const { - PRBool result=PR_FALSE; - return result; -} - -/** - * This method gets called to determine whether a given - * tag is itself a container - * - * @update gess 3/25/98 - * @param aTag -- tag to test for containership - * @return PR_TRUE if given tag can contain other tags - */ -PRBool CViewSourceHTML::IsContainer(PRInt32 aTag) const{ - PRBool result=PR_TRUE; - return result; -} - -/** - * This method gets called when a tag needs to write it's attributes - * - * @update gess 3/25/98 - * @param - * @return result status - */ -nsresult CViewSourceHTML::WriteAttributes(PRInt32 attrCount) { - nsresult result=NS_OK; - - if(attrCount){ //go collect the attributes... - - CSharedVSContext& theContext=CSharedVSContext::GetSharedContext(); - - int attr = 0; - for(attr = 0; attr < attrCount; ++attr){ - CToken* theToken = mTokenizer->PeekToken(); - if(theToken) { - eHTMLTokenTypes theType = eHTMLTokenTypes(theToken->GetTokenType()); - if(eToken_attribute == theType){ - mTokenizer->PopToken(); //pop it for real... - theContext.mTokenNode.AddAttribute(theToken); //and add it to the node. - - CAttributeToken* theAttrToken = (CAttributeToken*)theToken; - const nsAString& theKey = theAttrToken->GetKey(); - - result = WriteTag(mKey,theKey,0,PR_FALSE); - const nsAString& theValue = theAttrToken->GetValue(); - - if(!theValue.IsEmpty() || theAttrToken->mHasEqualWithoutValue){ - result = WriteTag(mValue,theValue,0,PR_FALSE); - } - } - } - else return kEOF; - } - } - - return result; -} - -/** - * This method gets called when a tag needs to be sent out - * - * @update gess 3/25/98 - * @param - * @return result status - */ -nsresult CViewSourceHTML::WriteTag(PRInt32 aTagType,const nsAString & aText,PRInt32 attrCount,PRBool aNewlineRequired) { - static nsString theString; - - nsresult result=NS_OK; - - // adjust line number to what it will be after we finish writing this tag - // XXXbz life here sucks. We can't use the GetNewlineCount on the token, - // because Text tokens in