Fix for bug 235747 (Move parser stuff into mozilla/parser). Removing files from old location, new location is mozilla/parser/htmlparser. r=cls, sr=jst.

This commit is contained in:
peterv%propagandism.org 2004-05-05 18:21:24 +00:00
Родитель d6abf0fc93
Коммит 626306d99d
398 изменённых файлов: 0 добавлений и 49904 удалений

Просмотреть файл

@ -1 +0,0 @@
Makefile

Просмотреть файл

@ -1 +0,0 @@
Makefile

Просмотреть файл

@ -1,193 +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) 1999
* 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 ***** */
/******
This file contains the list of all HTML tags
See nsHTMLTags.h for access to the enum values for tags
It is designed to be used as inline input to nsHTMLTags.cpp and
nsHTMLContentSink *only* through the magic of C preprocessing.
All entires must be enclosed in the macro HTML_TAG which will have cruel
and unusual things done to it
It is recommended (but not strictly necessary) to keep all entries
in alphabetical order
The first argument to HTML_TAG is both the enum identifier of the
property and the string value. The second argument is the "creator"
method of the form NS_New$TAGNAMEElement, that will be used by
nsHTMLContentSink.cpp to create a content object for a tag of that
type. Use NOTUSED, if the particular tag has a non-standard creator.
The HTML_OTHER macro is for values in the nsHTMLTag enum that are
not strictly tags.
Entries *must* use only lowercase characters.
** Break these invarient and bad things will happen. **
******/
HTML_TAG(a, Anchor)
HTML_TAG(abbr, Span)
HTML_TAG(acronym, Span)
HTML_TAG(address, Span)
HTML_TAG(applet, Applet)
HTML_TAG(area, Area)
HTML_TAG(b, Span)
HTML_TAG(base, Shared)
HTML_TAG(basefont, Shared)
HTML_TAG(bdo, Span)
HTML_TAG(bgsound, Span)
HTML_TAG(big, Span)
HTML_TAG(blink, Span)
HTML_TAG(blockquote, Shared)
HTML_TAG(body, Body)
HTML_TAG(br, BR)
HTML_TAG(button, Button)
HTML_TAG(caption, TableCaption)
HTML_TAG(center, Span)
HTML_TAG(cite, Span)
HTML_TAG(code, Span)
HTML_TAG(col, TableCol)
HTML_TAG(colgroup, TableCol)
HTML_TAG(counter, Span)
HTML_TAG(dd, Span)
HTML_TAG(del, Mod)
HTML_TAG(dfn, Span)
HTML_TAG(dir, Shared)
HTML_TAG(div, Div)
HTML_TAG(dl, SharedList)
HTML_TAG(dt, Span)
HTML_TAG(em, Span)
HTML_TAG(embed, Shared)
HTML_TAG(endnote, Span)
HTML_TAG(fieldset, FieldSet)
HTML_TAG(font, Font)
HTML_TAG(form, NOTUSED)
HTML_TAG(frame, Frame)
HTML_TAG(frameset, FrameSet)
HTML_TAG(h1, Heading)
HTML_TAG(h2, Heading)
HTML_TAG(h3, Heading)
HTML_TAG(h4, Heading)
HTML_TAG(h5, Heading)
HTML_TAG(h6, Heading)
HTML_TAG(head, Head)
HTML_TAG(hr, HR)
HTML_TAG(html, Html)
HTML_TAG(i, Span)
HTML_TAG(iframe, IFrame)
HTML_TAG(image, Span)
HTML_TAG(img, Image)
HTML_TAG(input, NOTUSED)
HTML_TAG(ins, Mod)
HTML_TAG(isindex, Shared)
HTML_TAG(kbd, Span)
HTML_TAG(keygen, Span)
HTML_TAG(label, Label)
HTML_TAG(legend, Legend)
HTML_TAG(li, LI)
HTML_TAG(link, Link)
HTML_TAG(listing, Span)
HTML_TAG(map, Map)
HTML_TAG(marquee, Div)
HTML_TAG(menu, Shared)
HTML_TAG(meta, Meta)
HTML_TAG(multicol, Span)
HTML_TAG(nobr, Span)
HTML_TAG(noembed, Div)
HTML_TAG(noframes, Div)
HTML_TAG(noscript, Div)
HTML_TAG(object, Object)
HTML_TAG(ol, SharedList)
HTML_TAG(optgroup, OptGroup)
HTML_TAG(option, Option)
HTML_TAG(p, Paragraph)
HTML_TAG(param, Shared)
HTML_TAG(parsererror, Div)
HTML_TAG(plaintext, Span)
HTML_TAG(pre, Pre)
HTML_TAG(q, Shared)
HTML_TAG(s, Span)
HTML_TAG(samp, Span)
HTML_TAG(script, Script)
HTML_TAG(select, NOTUSED)
HTML_TAG(server, Span)
HTML_TAG(small, Span)
HTML_TAG(sound, Span)
HTML_TAG(sourcetext, Div)
HTML_TAG(spacer, Shared)
HTML_TAG(span, Span)
HTML_TAG(strike, Span)
HTML_TAG(strong, Span)
HTML_TAG(style, Style)
HTML_TAG(sub, Span)
HTML_TAG(sup, Span)
HTML_TAG(table, Table)
HTML_TAG(tbody, TableSection)
HTML_TAG(td, TableCell)
HTML_TAG(textarea, TextArea)
HTML_TAG(tfoot, TableSection)
HTML_TAG(th, TableCell)
HTML_TAG(thead, TableSection)
HTML_TAG(title, Title)
HTML_TAG(tr, TableRow)
HTML_TAG(tt, Span)
HTML_TAG(u, Span)
HTML_TAG(ul, SharedList)
HTML_TAG(var, Span)
HTML_TAG(wbr, Shared)
HTML_TAG(xmp, Span)
/* These are not for tags. But they will be included in the nsHTMLTag
enum anyway */
/* XXX: The second parameters in some of the following entries look
like they are just wrong. They should really be NOTUSED. For now,
I'm just emulating what nsHTMLContentSink has done all along.
*/
HTML_OTHER(text, Span)
HTML_OTHER(whitespace, Span)
HTML_OTHER(newline, Span)
HTML_OTHER(comment, Span)
HTML_OTHER(entity, Span)
HTML_OTHER(doctypeDecl, Span)
HTML_OTHER(markupDecl, Span)
HTML_OTHER(instruction, Span)

Просмотреть файл

@ -1,82 +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 Communicator client 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 ***** */
#ifndef nsHTMLTags_h___
#define nsHTMLTags_h___
#include "nsAString.h"
class nsIAtom;
/*
Declare the enum list using the magic of preprocessing
enum values are "eHTMLTag_foo" (where foo is the tag)
To change the list of tags, see nsHTMLTagList.h
*/
#define HTML_TAG(_tag, _classname) eHTMLTag_##_tag,
#define HTML_OTHER(_tag, _classname) eHTMLTag_##_tag,
enum nsHTMLTag {
/* this enum must be first and must be zero */
eHTMLTag_unknown = 0,
#include "nsHTMLTagList.h"
/* can't be moved into nsHTMLTagList since gcc3.4 doesn't like a
comma at the end of enum list*/
eHTMLTag_userdefined
};
#undef HTML_TAG
#undef HTML_OTHER
// Currently there are 110 HTML tags. eHTMLTag_text = 112.
#define NS_HTML_TAG_MAX PRInt32(eHTMLTag_text - 1)
class nsHTMLTags {
public:
static nsresult AddRefTable(void);
static void ReleaseTable(void);
static nsHTMLTag LookupTag(const nsAString& aTagName);
static nsHTMLTag CaseSensitiveLookupTag(const PRUnichar* aTagName);
static const PRUnichar *GetStringValue(nsHTMLTag aEnum);
static nsIAtom *GetAtom(nsHTMLTag aEnum);
};
#define eHTMLTags nsHTMLTag
#endif /* nsHTMLTags_h___ */

Просмотреть файл

@ -1,512 +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 <xxxx>.
* 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 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 eWellFormed == mContainerInfo;
}
nsString mTextValue;
nsString mTrailingContent;
protected:
eContainerInfo mContainerInfo;
PRPackedBool mEmpty;
#ifdef DEBUG
PRPackedBool mAttributed;
#endif
};
/**
* This declares end tokens, which always take the
* form </xxxx>. 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 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 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 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 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 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 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 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 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 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 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 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 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 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 ("<!DOCTYPE ... >")
*
*/
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 PRInt32 GetTokenType(void);
virtual const nsAString& GetStringValue(void);
virtual void SetStringValue(const nsAString& aStr);
protected:
nsString mTextValue;
};
#endif

Просмотреть файл

@ -1,124 +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 Communicator client 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 ***** */
#ifndef nsIContentSink_h___
#define nsIContentSink_h___
/**
* MODULE NOTES:
* @update gess 4/1/98
*
* This pure virtual interface is used as the "glue" that connects the parsing
* process to the content model construction process.
*
* The icontentsink interface is a very lightweight wrapper that represents the
* content-sink model building process. There is another one that you may care
* about more, which is the IHTMLContentSink interface. (See that file for details).
*/
#include "nsISupports.h"
#include "nsString.h"
class nsIParser;
#define NS_ICONTENT_SINK_IID \
{ 0xa6cf9052, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
// The base value for the content ID counter.
// Values greater than or equal to this base value are used
// by each of the content sinks to assign unique values
// to the content objects created by them.
#define NS_CONTENT_ID_COUNTER_BASE 10000
class nsIContentSink : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENT_SINK_IID)
/**
* This method gets called when the parser begins the process
* of building the content model via the content sink.
*
* @update 5/7/98 gess
*/
NS_IMETHOD WillBuildModel(void)=0;
/**
* This method gets called when the parser concludes the process
* of building the content model via the content sink.
*
* @update 5/7/98 gess
*/
NS_IMETHOD DidBuildModel()=0;
/**
* This method gets called when the parser gets i/o blocked,
* and wants to notify the sink that it may be a while before
* more data is available.
*
* @update 5/7/98 gess
*/
NS_IMETHOD WillInterrupt(void)=0;
/**
* This method gets called when the parser i/o gets unblocked,
* and we're about to start dumping content again to the sink.
*
* @update 5/7/98 gess
*/
NS_IMETHOD WillResume(void)=0;
/**
* This method gets called by the parser so that the content
* sink can retain a reference to the parser. The expectation
* is that the content sink will drop the reference when it
* gets the DidBuildModel notification i.e. when parsing is done.
*/
NS_IMETHOD SetParser(nsIParser* aParser)=0;
/**
* Flush all pending notifications so that the content model
* is in sync with the state of the sink.
*/
NS_IMETHOD FlushPendingNotifications()=0;
/**
* Set the document character set. This should be passed on to the
* document itself.
*/
NS_IMETHOD SetDocumentCharset(nsACString& aCharset)=0;
};
#endif /* nsIContentSink_h___ */

Просмотреть файл

@ -1,252 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 ***** */
#ifndef nsIDTD_h___
#define nsIDTD_h___
/**
* MODULE NOTES:
* @update gess 7/20/98
*
* This interface defines standard interface for DTD's. Note that this
* isn't HTML specific. DTD's have several functions within the parser
* system:
* 1) To coordinate the consumption of an input stream via the
* parser
* 2) To serve as proxy to represent the containment rules of the
* underlying document
* 3) To offer autodetection services to the parser (mainly for doc
* conversion)
* */
#include "nsISupports.h"
#include "nsString.h"
#include "prtypes.h"
#include "nsITokenizer.h"
#define NS_IDTD_IID \
{ 0xa6cf9053, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
enum eAutoDetectResult {
eUnknownDetect,
eValidDetect,
ePrimaryDetect,
eInvalidDetect
};
enum nsDTDMode {
eDTDMode_unknown = 0,
eDTDMode_quirks, //pre 4.0 versions
eDTDMode_almost_standards,
eDTDMode_full_standards,
eDTDMode_autodetect,
eDTDMode_fragment
};
class nsIParser;
class CToken;
class nsIURI;
class nsIContentSink;
class CParserContext;
class nsIAtom;
class nsIDTD : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDTD_IID)
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const = 0;
/**
* Call this method if you want the DTD to construct a clone of itself.
* @update gess7/23/98
* @param
* @return
*/
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult) = 0;
/**
* 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 aContentType -- string representing type of doc to be
* converted (ie text/html)
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
*/
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext,
const nsString& aBuffer,
PRInt32 aVersion) = 0;
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
nsITokenizer* aTokenizer,
nsIContentSink* aSink) = 0;
/**
* Called by the parser after the parsing process has concluded
* @update gess5/18/98
* @param anErrorCode - contains error code resulting from parse process
* @return
*/
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
nsIParser* aParser,
nsIContentSink* aSink) = 0;
/**
* Called by the parser after the parsing process has concluded
* @update gess5/18/98
* @param anErrorCode - contains error code resulting from parse process
* @return
*/
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
nsITokenObserver* anObserver,
nsIContentSink* aSink) = 0;
/**
* Called during model building phase of parse process. Each token
* created during the parse phase is stored in a deque (in the
* parser) and are passed to this method so that the DTD can
* process the token. Ultimately, the DTD will transform given
* token into calls onto a contentsink.
* @update gess 3/25/98
* @param aToken -- token object to be put into content model
* @return error code (usually 0)
*/
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser) = 0;
/**
* If the parse process gets interrupted midway, this method is
* called by the parser prior to resuming the process.
* @update gess5/18/98
* @return ignored
*/
NS_IMETHOD WillResumeParse(nsIContentSink* aSink) = 0;
/**
* If the parse process gets interrupted, this method is called by
* the parser to notify the DTD that interruption will occur.
* @update gess5/18/98
* @return ignored
*/
NS_IMETHOD WillInterruptParse(nsIContentSink* aSink) = 0;
/**
* 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
*/
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const = 0;
/**
* 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
*/
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const = 0;
/**
* 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_IMETHOD_(void) Terminate() = 0;
NS_IMETHOD_(PRInt32) GetType() = 0;
NS_IMETHOD CollectSkippedContent(PRInt32 aTag, nsAString& aContent, PRInt32 &aLineNo) = 0;
/* XXX Temporary measure, pending further work by RickG */
// Whaaaa! These are useless methods, use nsIParserService!
/**
* Give rest of world access to our tag enums, so that CanContain(), etc,
* become useful.
*/
NS_IMETHOD StringTagToIntTag(const nsAString &aTag,
PRInt32* aIntTag) const = 0;
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const = 0;
NS_IMETHOD_(nsIAtom *) IntTagToAtom(PRInt32 aIntTag) const = 0;
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
PRInt32 aParentID) const = 0;
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,
PRInt32 aParentID) const = 0;
};
#define NS_DECL_NSIDTD \
NS_IMETHOD_(const nsIID&) GetMostDerivedIID(void) const;\
NS_IMETHOD CreateNewInstance(nsIDTD** aInstancePtrResult);\
NS_IMETHOD_(eAutoDetectResult) CanParse(CParserContext& aParserContext, const nsString& aBuffer, PRInt32 aVersion);\
NS_IMETHOD WillBuildModel( const CParserContext& aParserContext, nsITokenizer* aTokenizer, nsIContentSink* aSink);\
NS_IMETHOD DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink);\
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink);\
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);\
NS_IMETHOD WillResumeParse(nsIContentSink* aSink = 0);\
NS_IMETHOD WillInterruptParse(nsIContentSink* aSink = 0);\
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;\
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;\
NS_IMETHOD CollectSkippedContent(PRInt32 aTag, nsAString& aContent, PRInt32 &aLineNo);\
NS_IMETHOD_(void) Terminate();\
NS_IMETHOD_(PRInt32) GetType(); \
NS_IMETHOD StringTagToIntTag(const nsAString &aTag, PRInt32* aIntTag) const ;\
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const ;\
NS_IMETHOD_(nsIAtom *) IntTagToAtom(PRInt32 aIntTag) const;\
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const;\
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,PRInt32 aParentID) const;
#endif /* nsIDTD_h___ */

Просмотреть файл

@ -1,90 +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) 1999
* 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 rickg 03.23.2000 //removed unused NS_PARSER_SUBJECT and predecl of nsString
*
*/
#ifndef nsIElementObserver_h__
#define nsIElementObserver_h__
#include "nsISupports.h"
#include "prtypes.h"
#include "nsHTMLTags.h"
#include "nsVoidArray.h"
// {4672AA04-F6AE-11d2-B3B7-00805F8A6670}
#define NS_IELEMENTOBSERVER_IID \
{ 0x4672aa04, 0xf6ae, 0x11d2, { 0xb3, 0xb7, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
class nsIElementObserver : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IELEMENTOBSERVER_IID)
enum { IS_DOCUMENT_WRITE = 1U };
/*
* Subject call observer when the parser hit the tag
* @param aDocumentID- ID of the document
* @param aTag- the tag
* @param numOfAttributes - number of attributes
* @param nameArray - array of name.
* @param valueArray - array of value
*/
NS_IMETHOD Notify(PRUint32 aDocumentID, eHTMLTags aTag,
PRUint32 numOfAttributes, const PRUnichar* nameArray[],
const PRUnichar* valueArray[]) = 0;
NS_IMETHOD Notify(PRUint32 aDocumentID, const PRUnichar* aTag,
PRUint32 numOfAttributes, const PRUnichar* nameArray[],
const PRUnichar* valueArray[]) = 0;
NS_IMETHOD Notify(nsISupports* aWebShell,
nsISupports* aChannel,
const PRUnichar* aTag,
const nsStringArray* aKeys,
const nsStringArray* aValues,
const PRUint32 aFlags) = 0;
};
#endif /* nsIElementObserver_h__ */

Просмотреть файл

@ -1,131 +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 "nsISupports.idl"
/**
* This interface should be implemented by any content sink that wants
* to get output from expat and do something with it; in other words,
* by any sink that handles some sort of XML dialect.
*/
[scriptable, uuid(1DEEA160-C661-11d5-84CC-0010A4E0C706)]
interface nsIExpatSink : nsISupports
{
/**
* Called to handle the opening tag of an element.
* @param aName the fully qualified tagname of the element
* @param aAtts the array of attribute names and values. There are
* aAttsCount/2 names and aAttsCount/2 values, so the total number of
* elements in the array is aAttsCount. The names and values
* alternate. Thus, if we number attributes starting with 0,
* aAtts[2*k] is the name of the k-th attribute and aAtts[2*k+1] is
* the value of that attribute Both explicitly specified attributes
* and attributes that are defined to have default values in a DTD are
* present in aAtts.
* @param aAttsCount the number of elements in aAtts.
* @param aIndex If the element has an attribute of type ID, then
* aAtts[aIndex] is the name of that attribute. Otherwise, aIndex
* is -1
* @param aLineNumber the line number of the start tag in the data stream.
*/
void HandleStartElement(in wstring aName,
[array, size_is(aAttsCount)] in wstring aAtts,
in unsigned long aAttsCount,
in long aIndex,
in unsigned long aLineNumber);
/**
* Called to handle the closing tag of an element.
* @param aName the fully qualified tagname of the element
*/
void HandleEndElement(in wstring aName);
/**
* Called to handle a comment
* @param aCommentText the text of the comment (not including the
* "<!--" and "-->")
*/
void HandleComment(in wstring aCommentText);
/**
* Called to handle a CDATA section
* @param aData the text in the CDATA section. This is null-terminated.
* @param aLength the length of the aData string
*/
void HandleCDataSection([size_is(aLength)] in wstring aData,
in unsigned long aLength);
/**
* Called to handle the doctype declaration
*/
void HandleDoctypeDecl(in AString aSubset,
in AString aName,
in AString aSystemId,
in AString aPublicId,
in nsISupports aCatalogData);
/**
* Called to handle character data. Note that this does NOT get
* called for the contents of CDATA sections.
* @param aData the data to handle. aData is NOT NULL-TERMINATED.
* @param aLength the length of the aData string
*/
void HandleCharacterData([size_is(aLength)] in wstring aData,
in unsigned long aLength);
/**
* Called to handle a processing instruction
* @param aTarget the PI target (e.g. xml-stylesheet)
* @param aData all the rest of the data in the PI
*/
void HandleProcessingInstruction(in wstring aTarget,
in wstring aData);
/**
* Handle the XML Declaration.
*
* @param aData The string.
* @param aLength The length of the declaration from
* opening '<' to closing '>'.
**/
void HandleXMLDeclaration([size_is(aLength)] in wstring aData,
in unsigned long aLength);
void ReportError(in wstring aErrorText,
in wstring aSourceText);
};

Просмотреть файл

@ -1,329 +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 Communicator client 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 ***** */
#ifndef nsIHTMLContentSink_h___
#define nsIHTMLContentSink_h___
/**
* MODULE NOTES:
* @update gess 4/1/98
*
* This file declares the concrete HTMLContentSink class.
* This class is used during the parsing process as the
* primary interface between the parser and the content
* model.
*
* After the tokenizer completes, the parser iterates over
* the known token list. As the parser identifies valid
* elements, it calls the contentsink interface to notify
* the content model that a new node or child node is being
* created and added to the content model.
*
* The HTMLContentSink interface assumes 4 underlying
* containers: HTML, HEAD, BODY and FRAMESET. Before
* accessing any these, the parser will call the appropriate
* OpennsIHTMLContentSink method: OpenHTML,OpenHead,OpenBody,OpenFrameSet;
* likewise, the ClosensIHTMLContentSink version will be called when the
* parser is done with a given section.
*
* IMPORTANT: The parser may Open each container more than
* once! This is due to the irregular nature of HTML files.
* For example, it is possible to encounter plain text at
* the start of an HTML document (that preceeds the HTML tag).
* Such text is treated as if it were part of the body.
* In such cases, the parser will Open the body, pass the text-
* node in and then Close the body. The body will likely be
* re-Opened later when the actual <BODY> tag has been seen.
*
* Containers within the body are Opened and Closed
* using the OpenContainer(...) and CloseContainer(...) calls.
* It is assumed that the document or contentSink is
* maintaining its state to manage where new content should
* be added to the underlying document.
*
* NOTE: OpenHTML() and OpenBody() may get called multiple times
* in the same document. That's fine, and it doesn't mean
* that we have multiple bodies or HTML's.
*
* NOTE: I haven't figured out how sub-documents (non-frames)
* are going to be handled. Stay tuned.
*/
#include "nsIParserNode.h"
#include "nsIContentSink.h"
#include "nsHTMLTags.h"
#define NS_IHTML_CONTENT_SINK_IID \
{ 0xa6cf9051, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
#ifdef XP_MAC
#define MAX_REFLOW_DEPTH 75 //setting to 75 to prevent layout from crashing on mac. Bug 55095.
#else
#define MAX_REFLOW_DEPTH 200 //windows and linux (etc) can do much deeper structures.
#endif
class nsIHTMLContentSink : public nsIContentSink
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTML_CONTENT_SINK_IID)
/**
* This method gets called by the parser when it encounters
* a title tag and wants to set the document title in the sink.
*
* @update 4/1/98 gess
* @param nsString reference to new title value
*/
NS_IMETHOD SetTitle(const nsString& aValue) = 0;
/**
* This method is used to open the outer HTML container.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD OpenHTML(const nsIParserNode& aNode) = 0;
/**
* This method is used to close the outer HTML container.
*
*/
NS_IMETHOD CloseHTML() = 0;
/**
* This method is used to open the only HEAD container.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD OpenHead(const nsIParserNode& aNode) = 0;
/**
* This method is used to close the only HEAD container.
*/
NS_IMETHOD CloseHead() = 0;
/**
* This method is used to open the main BODY container.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD OpenBody(const nsIParserNode& aNode) = 0;
/**
* This method is used to close the main BODY container.
*
*/
NS_IMETHOD CloseBody() = 0;
/**
* This method is used to open a new FORM container.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD OpenForm(const nsIParserNode& aNode) = 0;
/**
* This method is used to close the outer FORM container.
*
*/
NS_IMETHOD CloseForm() = 0;
/**
* This method is used to open a new MAP container.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD OpenMap(const nsIParserNode& aNode) = 0;
/**
* This method is used to close the MAP container.
*
*/
NS_IMETHOD CloseMap() = 0;
/**
* This method is used to open the FRAMESET container.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD OpenFrameset(const nsIParserNode& aNode) = 0;
/**
* This method is used to close the FRAMESET container.
*
*/
NS_IMETHOD CloseFrameset() = 0;
/**
* This gets called when handling illegal contents, especially
* in dealing with tables. This method creates a new context.
*
* @update 04/04/99 harishd
* @param aPosition - The position from where the new context begins.
*/
NS_IMETHOD BeginContext(PRInt32 aPosition) = 0;
/**
* This method terminates any new context that got created by
* BeginContext and switches back to the main context.
*
* @update 04/04/99 harishd
* @param aPosition - Validates the end of a context.
*/
NS_IMETHOD EndContext(PRInt32 aPosition) = 0;
/**
* @update 01/09/2003 harishd
* @param aTag - Check if this tag is enabled or not.
*/
NS_IMETHOD IsEnabled(PRInt32 aTag, PRBool* aReturn) = 0;
/**
* This method is called when parser is about to begin
* synchronously processing a chunk of tokens.
*/
NS_IMETHOD WillProcessTokens(void) = 0;
/**
* This method is called when parser has
* completed processing a chunk of tokens. The processing of the
* tokens may be interrupted by returning NS_ERROR_HTMLPARSER_INTERRUPTED from
* DidProcessAToken.
*/
NS_IMETHOD DidProcessTokens() = 0;
/**
* This method is called when parser is about to
* process a single token
*/
NS_IMETHOD WillProcessAToken(void) = 0;
/**
* This method is called when parser has completed
* the processing for a single token.
* @return NS_OK if processing should not be interrupted
* NS_ERROR_HTMLPARSER_INTERRUPTED if the parsing should be interrupted
*/
NS_IMETHOD DidProcessAToken(void) = 0;
/**
* This method is used to open a generic container in the sink.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD OpenContainer(const nsIParserNode& aNode) = 0;
/**
* This method gets called by the parser when a close
* container tag has been consumed and needs to be closed.
*
* @param aTag - The tag to be closed.
*/
NS_IMETHOD CloseContainer(const nsHTMLTag aTag) = 0;
/**
* This gets called by the parser to contents to
* the head container
*
*/
NS_IMETHOD AddHeadContent(const nsIParserNode& aNode) = 0;
/**
* This gets called by the parser when you want to add
* a leaf node to the current container in the content
* model.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD AddLeaf(const nsIParserNode& aNode) = 0;
/**
* This gets called by the parser when you want to add
* a leaf node to the current container in the content
* model.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD AddComment(const nsIParserNode& aNode) = 0;
/**
* This gets called by the parser when you want to add
* a leaf node to the current container in the content
* model.
*
* @update 4/1/98 gess
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) = 0;
/**
* This method is called by the parser when it encounters
* a document type declaration.
*
* XXX Should the parser also part the internal subset?
*
* @param nsIParserNode reference to parser node interface
*/
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode) = 0;
/**
* This gets called by the parser to notify observers of
* the tag
*
* @param aErrorResult the error code
*/
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode) = 0;
/**
* Call this method to determnine if a FORM is on the sink's stack
*
* @return PR_TRUE if found else PR_FALSE
*/
NS_IMETHOD_(PRBool) IsFormOnStack() = 0;
};
#endif /* nsIHTMLContentSink_h___ */

Просмотреть файл

@ -1,75 +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 Communicator client 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 ***** */
#ifndef nsIHTMLFragmentContentSink_h___
#define nsIHTMLFragmentContentSink_h___
#include "nsIHTMLContentSink.h"
#define NS_HTMLFRAGMENTSINK_CONTRACTID "@mozilla.org/layout/htmlfragmentsink;1"
#define NS_HTMLFRAGMENTSINK2_CONTRACTID "@mozilla.org/layout/htmlfragmentsink;2"
class nsIDOMDocumentFragment;
class nsIDocument;
#define NS_IHTML_FRAGMENT_CONTENT_SINK_IID \
{0xa6cf9102, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
class nsIHTMLFragmentContentSink : public nsIHTMLContentSink {
public:
/**
* This method is used to obtain the fragment created by
* a fragment content sink. The value returned will be null
* if the content sink hasn't yet received parser notifications.
*
*/
NS_IMETHOD GetFragment(nsIDOMDocumentFragment** aFragment) = 0;
/**
* This method is used to set the target document for this fragment
* sink. This document's nodeinfo manager will be used to create
* the content objects. This MUST be called before the sink is used.
*
* If aDocument is null or has no nodeinfo manager, the sink will
* create a brand-new nodeinfo manager.
*
* @param aDocument the document the new nodes will belong to
*/
NS_IMETHOD SetTargetDocument(nsIDocument* aDocument) = 0;
};
#endif

Просмотреть файл

@ -1,55 +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 Communicator client 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 ***** */
#ifndef nsILoggingSink_h___
#define nsILoggingSink_h___
#include "nsIHTMLContentSink.h"
#include "nsString.h"
#include "prprf.h"
// IID for nsILoggingSink
#define NS_ILOGGING_SINK_IID \
{0xa6cf9061, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
class nsILoggingSink : public nsIHTMLContentSink {
public:
NS_IMETHOD SetOutputStream(PRFileDesc *aStream,PRBool autoDelete=PR_FALSE) =0;
};
extern "C" nsresult NS_NewHTMLLoggingSink(nsIContentSink** aInstancePtrResult);
#endif /* nsILoggingSink_h___ */

Просмотреть файл

@ -1,387 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 ***** */
#ifndef NS_IPARSER___
#define NS_IPARSER___
/**
* MODULE NOTES:
* @update gess 4/1/98
*
* This class defines the iparser interface. This XPCOM
* inteface is all that parser clients ever need to see.
*
**/
#include "nsISupports.h"
#include "nsIStreamListener.h"
#include "nsIDTD.h"
#include "nsIInputStream.h"
#include "nsHashtable.h"
#include "nsVoidArray.h"
#define NS_IPARSER_IID \
{0x355cbba0, 0xbf7d, 0x11d1, \
{0xaa, 0xd9, 0x00, 0x80, 0x5f, 0x8a, 0x3e, 0x14}}
// {41421C60-310A-11d4-816F-000064657374}
#define NS_IDEBUG_DUMP_CONTENT_IID \
{ 0x41421c60, 0x310a, 0x11d4, { 0x81, 0x6f, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } };
class nsIContentSink;
class nsIRequestObserver;
class nsIParserFilter;
class nsString;
class nsIURI;
class nsIChannel;
enum eParserCommands {
eViewNormal,
eViewSource,
eViewFragment,
eViewErrors
};
enum eCRCQuality {
eCRCGood = 0,
eCRCFair,
eCRCPoor
};
enum eParserDocType {
ePlainText = 0,
eXML,
eHTML_Quirks,
eHTML3_Quirks, // separate, for editor output, since HTML pre-4.0 lacks tbody
eHTML_Strict
};
// define Charset source constants
// note: the value order define the priority
#define kCharsetUninitialized 0
#define kCharsetFromWeakDocTypeDefault 1
#define kCharsetFromUserDefault 2
#define kCharsetFromDocTypeDefault 3
#define kCharsetFromCache 4
#define kCharsetFromParentFrame 5
#define kCharsetFromBookmarks 6
#define kCharsetFromAutoDetection 7
#define kCharsetFromHintPrevDoc 8
#define kCharsetFromMetaTag 9
#define kCharsetFromByteOrderMark 10
#define kCharsetFromChannel 11
#define kCharsetFromParentForced 12
#define kCharsetFromUserForced 13
#define kCharsetFromOtherComponent 14
#define kCharsetFromPreviousLoading 15
enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
/**
* FOR DEBUG PURPOSE ONLY
*
* Use this interface to query objects that contain content information.
* Ex. Parser can trigger dump content by querying the sink that has
* access to the content.
*
* @update harishd 05/25/00
*/
class nsIDebugDumpContent : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDEBUG_DUMP_CONTENT_IID)
NS_IMETHOD DumpContentModel()=0;
};
/**
* This class defines the iparser interface. This XPCOM
* inteface is all that parser clients ever need to see.
*
* @update gess 3/25/98
*/
class nsIParser : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPARSER_IID)
/**
* Call this method if you have a DTD that you want to share with the parser.
* Registered DTD's get remembered until the system shuts down.
*
* @update gess 3/25/98
* @param aDTD -- ptr DTD that you're publishing the services of
*/
NS_IMETHOD RegisterDTD(nsIDTD* aDTD)=0;
/**
* Select given content sink into parser for parser output
* @update gess5/11/98
* @param aSink is the new sink to be used by parser
* @return
*/
NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0;
/**
* retrieve the sink set into the parser
* @update gess5/11/98
* @return current sink
*/
NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0;
/**
* Call this method once you've created a parser, and want to instruct it
* about the command which caused the parser to be constructed. For example,
* this allows us to select a DTD which can do, say, view-source.
*
* @update gess 3/25/98
* @param aCommand -- ptrs to string that contains command
* @return nada
*/
NS_IMETHOD_(void) GetCommand(nsString& aCommand)=0;
NS_IMETHOD_(void) SetCommand(const char* aCommand)=0;
NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0;
/**
* Call this method once you've created a parser, and want to instruct it
* about what charset to load
*
* @update ftang 4/23/99
* @param aCharset- the charest of a document
* @param aCharsetSource- the soure of the chares
* @return nada
*/
NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, PRInt32 aSource)=0;
NS_IMETHOD_(void) GetDocumentCharset(nsACString& oCharset, PRInt32& oSource)=0;
NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter) = 0;
/**
* Get the channel associated with this parser
* @update harishd,gagan 07/17/01
* @param aChannel out param that will contain the result
* @return NS_OK if successful
*/
NS_IMETHOD GetChannel(nsIChannel** aChannel) = 0;
/**
* Get the DTD associated with this parser
* @update vidur 9/29/99
* @param aDTD out param that will contain the result
* @return NS_OK if successful, NS_ERROR_FAILURE for runtime error
*/
NS_IMETHOD GetDTD(nsIDTD** aDTD) = 0;
/******************************************************************************************
* Parse methods always begin with an input source, and perform conversions
* until you wind up being emitted to the given contentsink (which may or may not
* be a proxy for the NGLayout content model).
******************************************************************************************/
// Call this method to resume the parser from the blocked state..
NS_IMETHOD ContinueParsing() = 0;
// Stops parsing temporarily.
NS_IMETHOD_(void) BlockParser() = 0;
// Open up the parser for tokenization, building up content
// model..etc. However, this method does not resume parsing
// automatically. It's the callers' responsibility to restart
// the parsing engine.
NS_IMETHOD_(void) UnblockParser() = 0;
NS_IMETHOD_(PRBool) IsParserEnabled() = 0;
NS_IMETHOD_(PRBool) IsComplete() = 0;
NS_IMETHOD Parse(nsIURI* aURL,
nsIRequestObserver* aListener = nsnull,
PRBool aEnableVerify = PR_FALSE,
void* aKey = 0,
nsDTDMode aMode = eDTDMode_autodetect) = 0;
NS_IMETHOD Parse(nsIInputStream* aStream,
const nsACString& aMimeType,
PRBool aEnableVerify = PR_FALSE,
void* aKey = 0,
nsDTDMode aMode = eDTDMode_autodetect) = 0;
NS_IMETHOD Parse(const nsAString& aSourceBuffer,
void* aKey,
const nsACString& aMimeType,
PRBool aEnableVerify,
PRBool aLastCall,
nsDTDMode aMode = eDTDMode_autodetect) = 0;
NS_IMETHOD Terminate(void) = 0;
NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer,
void* aKey,
nsVoidArray& aTagStack,
PRUint32 anInsertPos,
const nsACString& aContentType,
nsDTDMode aMode = eDTDMode_autodetect) = 0;
/**
* This method gets called when the tokens have been consumed, and it's time
* to build the model via the content sink.
* @update gess5/11/98
* @return error code -- 0 if model building went well .
*/
NS_IMETHOD BuildModel(void) = 0;
/**
* Retrieve the parse mode from the parser...
*
* @update gess 6/9/98
* @return ptr to scanner
*/
NS_IMETHOD_(nsDTDMode) GetParseMode(void) = 0;
/**
* Call this method to cancel any pending parsing events.
* Parsing events may be pending if all of the document's content
* has been passed to the parser but the parser has been interrupted
* because processing the tokens took too long.
*
* @update kmcclusk 05/18/01
* @return NS_OK if succeeded else ERROR.
*/
NS_IMETHOD CancelParsingEvents() = 0;
};
/* ===========================================================*
Some useful constants...
* ===========================================================*/
#include "prtypes.h"
#include "nsError.h"
#define NS_ERROR_HTMLPARSER_EOF NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1000)
#define NS_ERROR_HTMLPARSER_UNKNOWN NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1001)
#define NS_ERROR_HTMLPARSER_CANTPROPAGATE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1002)
#define NS_ERROR_HTMLPARSER_CONTEXTMISMATCH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1003)
#define NS_ERROR_HTMLPARSER_BADFILENAME NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1004)
#define NS_ERROR_HTMLPARSER_BADURL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1005)
#define NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1006)
#define NS_ERROR_HTMLPARSER_INTERRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007)
#define NS_ERROR_HTMLPARSER_BLOCK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008)
#define NS_ERROR_HTMLPARSER_BADTOKENIZER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1009)
#define NS_ERROR_HTMLPARSER_BADATTRIBUTE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1010)
#define NS_ERROR_HTMLPARSER_UNRESOLVEDDTD NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1011)
#define NS_ERROR_HTMLPARSER_MISPLACEDTABLECONTENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1012)
#define NS_ERROR_HTMLPARSER_BADDTD NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1013)
#define NS_ERROR_HTMLPARSER_BADCONTEXT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1014)
#define NS_ERROR_HTMLPARSER_STOPPARSING NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1015)
#define NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1016)
#define NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1017)
#define NS_ERROR_HTMLPARSER_CONTINUE NS_OK
const PRUint32 kEOF = NS_ERROR_HTMLPARSER_EOF;
const PRUint32 kUnknownError = NS_ERROR_HTMLPARSER_UNKNOWN;
const PRUint32 kCantPropagate = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
const PRUint32 kContextMismatch = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
const PRUint32 kBadFilename = NS_ERROR_HTMLPARSER_BADFILENAME;
const PRUint32 kBadURL = NS_ERROR_HTMLPARSER_BADURL;
const PRUint32 kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
const PRUint32 kBlocked = NS_ERROR_HTMLPARSER_BLOCK;
const PRUint32 kBadStringLiteral = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL;
const PRUint32 kHierarchyTooDeep = NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP;
const PRUnichar kNewLine = '\n';
const PRUnichar kCR = '\r';
const PRUnichar kLF = '\n';
const PRUnichar kTab = '\t';
const PRUnichar kSpace = ' ';
const PRUnichar kQuote = '"';
const PRUnichar kApostrophe = '\'';
const PRUnichar kLessThan = '<';
const PRUnichar kGreaterThan = '>';
const PRUnichar kAmpersand = '&';
const PRUnichar kForwardSlash = '/';
const PRUnichar kBackSlash = '\\';
const PRUnichar kEqual = '=';
const PRUnichar kMinus = '-';
const PRUnichar kPlus = '+';
const PRUnichar kExclamation = '!';
const PRUnichar kSemicolon = ';';
const PRUnichar kHashsign = '#';
const PRUnichar kAsterisk = '*';
const PRUnichar kUnderbar = '_';
const PRUnichar kComma = ',';
const PRUnichar kLeftParen = '(';
const PRUnichar kRightParen = ')';
const PRUnichar kLeftBrace = '{';
const PRUnichar kRightBrace = '}';
const PRUnichar kQuestionMark = '?';
const PRUnichar kLeftSquareBracket = '[';
const PRUnichar kRightSquareBracket = ']';
const PRUnichar kNullCh = '\0';
#define kHTMLTextContentType "text/html"
#define kXMLTextContentType "text/xml"
#define kXMLApplicationContentType "application/xml"
#define kXHTMLApplicationContentType "application/xhtml+xml"
#define kXULTextContentType "application/vnd.mozilla.xul+xml"
#define kRDFTextContentType "text/rdf"
#define kXIFTextContentType "text/xif"
#define kPlainTextContentType "text/plain"
#define kViewSourceCommand "view-source"
#define kViewFragmentCommand "view-fragment"
#define kTextCSSContentType "text/css"
#define kApplicationJSContentType "application/x-javascript"
#define kTextJSContentType "text/javascript"
#define kSGMLTextContentType "text/sgml"
#define kSVGTextContentType "image/svg+xml"
#define NS_IPARSER_FLAG_UNKNOWN_MODE 0x00000000
#define NS_IPARSER_FLAG_QUIRKS_MODE 0x00000002
#define NS_IPARSER_FLAG_STRICT_MODE 0x00000004
#define NS_IPARSER_FLAG_AUTO_DETECT_MODE 0x00000010
#define NS_IPARSER_FLAG_VIEW_NORMAL 0x00000020
#define NS_IPARSER_FLAG_VIEW_SOURCE 0x00000040
#define NS_IPARSER_FLAG_VIEW_ERRORS 0x00000080
#define NS_IPARSER_FLAG_PRESERVE_CONTENT 0x00000100
#define NS_IPARSER_FLAG_PLAIN_TEXT 0x00000200
#define NS_IPARSER_FLAG_XML 0x00000400
#define NS_IPARSER_FLAG_HTML 0x00000800
#endif

Просмотреть файл

@ -1,78 +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 jevering 6/17/98
*
* This interface is not yet used; it was intended to allow an observer object
* to "look at" the i/o stream coming into the parser before, during and after
* the parser saw it. The intention of this was to allow an observer to modify
* the stream at various stages.
*/
#ifndef IPARSERFILTER
#define IPARSERFILTER
#include "nsISupports.h"
class CToken;
#define NS_IPARSERFILTER_IID \
{0x14d6ff0, 0x0610, 0x11d2, \
{0x8c, 0x3f, 0x00, 0x80, 0x5f, 0x8a, 0x1d, 0xb7}}
class nsIParserFilter : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPARSERFILTER_IID)
NS_IMETHOD RawBuffer(const char * buffer, PRUint32 * buffer_length) = 0;
NS_IMETHOD WillAddToken(CToken & token) = 0;
NS_IMETHOD ProcessTokens( /* dont know what goes here yet */ void ) = 0;
NS_IMETHOD Finish() = 0;
};
#endif

Просмотреть файл

@ -1,179 +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_IPARSERNODE__
#define NS_IPARSERNODE__
#include "nsISupports.h"
#include "prtypes.h"
#include "nsString.h"
#include "nsDebug.h"
//#define HEAP_ALLOCATED_NODES
//#define DEBUG_TRACK_NODES
class nsIAtom;
class CToken;
// 6e59f160-2717-11d2-9246-00805f8a7ab6
#define NS_IPARSER_NODE_IID \
{0x6e59f160, 0x2717, 0x11d1, \
{0x92, 0x46, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6}}
/**
* Parser nodes are the unit of exchange between the
* parser and the content sink. Nodes offer access to
* the current token, its attributes, and its skipped-
* content if applicable.
*
* @update gess 3/25/98
*/
class nsIParserNode { // XXX Should be nsAParserNode
public:
/**
* Retrieve the name of the node
* @update gess5/11/98
* @return string containing node name
*/
virtual const nsAString& GetTagName() const = 0; //to get name of tag
/**
* Retrieve the text from the given node
* @update gess5/11/98
* @return string containing node text
*/
virtual const nsAString& GetText() const = 0; //get plain text if available
/**
* Retrieve the type of the parser node.
* @update gess5/11/98
* @return node type.
*/
virtual PRInt32 GetNodeType() const =0;
/**
* Retrieve token type of parser node
* @update gess5/11/98
* @return token type
*/
virtual PRInt32 GetTokenType() const =0;
/**
* 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 =0;
/**
* 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 = 0;
/**
* 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 = 0;
/**
* 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 = 0;
virtual void AddAttribute(CToken* aToken)=0;
/**
* 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 =0;
/**
* 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 =0;
virtual void SetGenericState(PRBool aState) =0;
/** Retrieve a string containing the tag and its attributes in "source" form
* @update rickg 06June2000
* @return void
*/
virtual void GetSource(nsString& aString)=0;
/** Release all the objects you're holding
* @update harishd 08/02/00
* @return void
*/
virtual nsresult ReleaseAll()=0;
};
#endif

Просмотреть файл

@ -1,113 +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 Communicator client 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 ***** */
#ifndef nsIParserService_h__
#define nsIParserService_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsHTMLTags.h"
#include "nsIParserNode.h"
#include "nsIParser.h"
#include "nsVoidArray.h"
#include "nsIElementObserver.h"
#define NS_PARSER_CONTRACTID_PREFIX "@mozilla.org/parser"
// {90a92e37-abd6-441b-9b39-4064d98e1ede}
#define NS_IPARSERSERVICE_IID \
{ 0x90a92e37, 0xabd6, 0x441b, { 0x9b, 0x39, 0x40, 0x64, 0xd9, 0x8e, 0x1e, 0xde } };
// {78081E70-AD53-11d5-8498-0010A4E0C706}
#define NS_IOBSERVERENTRY_IID \
{ 0x78081e70, 0xad53, 0x11d5, { 0x84, 0x98, 0x00, 0x10, 0xa4, 0xe0, 0xc7, 0x06 } };
class nsIObserverEntry : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IOBSERVERENTRY_IID)
NS_IMETHOD Notify(nsIParserNode* aNode,
nsIParser* aParser,
nsISupports* aWebShell,
const PRUint32 aFlags) = 0;
};
class nsIParserService : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPARSERSERVICE_IID)
NS_IMETHOD HTMLAtomTagToId(nsIAtom* aAtom, PRInt32* aId) const = 0;
NS_IMETHOD HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom,
PRInt32* aId) const = 0;
NS_IMETHOD HTMLStringTagToId(const nsAString &aTagName,
PRInt32* aId) const = 0;
NS_IMETHOD HTMLIdToStringTag(PRInt32 aId,
const PRUnichar **aTagName) const = 0;
NS_IMETHOD HTMLConvertEntityToUnicode(const nsAString& aEntity,
PRInt32* aUnicode) const = 0;
NS_IMETHOD HTMLConvertUnicodeToEntity(PRInt32 aUnicode,
nsCString& aEntity) const = 0;
NS_IMETHOD IsContainer(PRInt32 aId, PRBool& aIsContainer) const = 0;
NS_IMETHOD IsBlock(PRInt32 aId, PRBool& aIsBlock) const = 0;
// Observer mechanism
NS_IMETHOD RegisterObserver(nsIElementObserver* aObserver,
const nsAString& aTopic,
const eHTMLTags* aTags = nsnull) = 0;
NS_IMETHOD UnregisterObserver(nsIElementObserver* aObserver,
const nsAString& aTopic) = 0;
NS_IMETHOD GetTopicObservers(const nsAString& aTopic,
nsIObserverEntry** aEntry) = 0;
virtual nsresult CheckQName(const nsASingleFragmentString& aQName,
PRBool aNamespaceAware,
const PRUnichar** aColon) = 0;
virtual PRBool IsXMLLetter(PRUnichar aChar) = 0;
virtual PRBool IsXMLNCNameChar(PRUnichar aChar) = 0;
};
#endif // nsIParserService_h__

Просмотреть файл

@ -1,108 +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
*
*/
#ifndef __NSITOKENIZER__
#define __NSITOKENIZER__
#include "nsISupports.h"
#include "prtypes.h"
class CToken;
class nsScanner;
class nsDeque;
class nsTokenAllocator;
#define NS_ITOKENIZER_IID \
{0xe4238ddc, 0x9eb6, 0x11d2, {0xba, 0xa5, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4 }}
/**
* This interface is used as a callback to objects interested
* in observing the token stream created from the parse process.
*/
class nsITokenObserver {
public:
virtual PRBool operator()(CToken* aToken)=0;
};
/***************************************************************
Notes:
***************************************************************/
class nsITokenizer : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITOKENIZER_IID)
NS_IMETHOD WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator)=0;
NS_IMETHOD ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens)=0;
NS_IMETHOD DidTokenize(PRBool aIsFinalChunk)=0;
NS_IMETHOD_(CToken*) PushTokenFront(CToken* aToken)=0;
NS_IMETHOD_(CToken*) PushToken(CToken* aToken)=0;
NS_IMETHOD_(CToken*) PopToken(void)=0;
NS_IMETHOD_(CToken*) PeekToken(void)=0;
NS_IMETHOD_(CToken*) GetTokenAt(PRInt32 anIndex)=0;
NS_IMETHOD_(PRInt32) GetCount(void)=0;
NS_IMETHOD_(nsTokenAllocator*) GetTokenAllocator(void)=0;
NS_IMETHOD_(void) PrependTokens(nsDeque& aDeque)=0;
NS_IMETHOD CopyState(nsITokenizer* aTokenizer) = 0;
};
#define NS_DECL_NSITOKENIZER \
NS_IMETHOD WillTokenize(PRBool aIsFinalChunk,nsTokenAllocator* aTokenAllocator);\
NS_IMETHOD ConsumeToken(nsScanner& aScanner,PRBool& aFlushTokens);\
NS_IMETHOD DidTokenize(PRBool aIsFinalChunk);\
NS_IMETHOD_(CToken*) PushTokenFront(CToken* aToken);\
NS_IMETHOD_(CToken*) PushToken(CToken* aToken);\
NS_IMETHOD_(CToken*) PopToken(void);\
NS_IMETHOD_(CToken*) PeekToken(void);\
NS_IMETHOD_(CToken*) GetTokenAt(PRInt32 anIndex);\
NS_IMETHOD_(PRInt32) GetCount(void);\
NS_IMETHOD_(nsTokenAllocator*) GetTokenAllocator(void);\
NS_IMETHOD_(void) PrependTokens(nsDeque& aDeque);\
NS_IMETHOD CopyState(nsITokenizer* aTokenizer);
#endif

Просмотреть файл

@ -1,83 +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 ***** */
#ifndef nsParserCIID_h__
#define nsParserCIID_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIComponentManager.h"
// {2ce606b0-bee6-11d1-aad9-00805f8a3e14}
#define NS_PARSER_CID \
{ 0x2ce606b0, 0xbee6, 0x11d1, { 0xaa, 0xd9, 0x0, 0x80, 0x5f, 0x8a, 0x3e, 0x14 } }
// XXX: This object should not be exposed outside of the parser.
// Remove when CNavDTD subclasses do not need access
#define NS_PARSER_NODE_IID \
{0x9039c670, 0x2717, 0x11d2, \
{0x92, 0x46, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6}}
// {a6cf9107-15b3-11d2-932e-00805f8add32}
#define NS_CNAVDTD_CID \
{ 0xa6cf9107, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
// Class IID for the logging sink
#define NS_LOGGING_SINK_CID \
{0xa6cf9060, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
// {4611d482-960a-11d4-8eb0-b617661b6f7c}
#define NS_CTRANSITIONAL_DTD_CID \
{ 0x4611d482, 0x960a, 0x11d4, { 0x8e, 0xb0, 0xb6, 0x17, 0x66, 0x1b, 0x6f, 0x7c } }
// {8323FAD0-2102-11d4-8142-000064657374}
#define NS_VIEWSOURCE_DTD_CID \
{ 0x8323fad0, 0x2102, 0x11d4, { 0x81, 0x42, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
// {FFF4FBE9-528A-4b37-819D-FC18F3A401A7}
#define NS_EXPAT_DRIVER_CID \
{ 0xfff4fbe9, 0x528a, 0x4b37, { 0x81, 0x9d, 0xfc, 0x18, 0xf3, 0xa4, 0x1, 0xa7 } }
// {a6cf910f-15b3-11d2-932e-00805f8add32}
#define NS_HTMLCONTENTSINKSTREAM_CID \
{ 0xa6cf910f, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
// {a6cf9112-15b3-11d2-932e-00805f8add32}
#define NS_PARSERSERVICE_CID \
{ 0xa6cf9112, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
#endif

Просмотреть файл

@ -1,64 +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 nra 3/3/99
*
* nsParserError structifies the notion of a parser error.
*/
#ifndef PARSERERROR__
#define PARSERERROR__
#include "prtypes.h"
#include "nsString.h"
typedef struct _nsParserError {
PRInt32 code;
PRInt32 lineNumber;
PRInt32 colNumber;
nsString description;
nsString sourceLine;
nsString sourceURL;
} nsParserError;
#endif

Просмотреть файл

@ -1,583 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** 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.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 ***** */
#ifndef nsScannerString_h___
#define nsScannerString_h___
#include "nsString.h"
#include "nsUnicharUtils.h" // for nsCaseInsensitiveStringComparator
#include "prclist.h"
/**
* NOTE: nsScannerString (and the other classes defined in this file) are
* not related to nsAString or any of the other xpcom/string classes.
*
* nsScannerString is based on the nsSlidingString implementation that used
* to live in xpcom/string. Now that nsAString is limited to representing
* only single fragment strings, nsSlidingString can no longer be used.
*
* An advantage to this design is that it does not employ any virtual
* functions.
*
* This file uses SCC-style indenting in deference to the nsSlidingString
* code from which this code is derived ;-)
*/
class nsScannerIterator;
class nsScannerSubstring;
class nsScannerString;
/**
* nsScannerBufferList
*
* This class maintains a list of heap-allocated Buffer objects. The buffers
* are maintained in a circular linked list. Each buffer has a usage count
* that is decremented by the owning nsScannerSubstring.
*
* The buffer list itself is reference counted. This allows the buffer list
* to be shared by multiple nsScannerSubstring objects. The reference
* counting is not threadsafe, which is not at all a requirement.
*
* When a nsScannerSubstring releases its reference to a buffer list, it
* decrements the usage count of the first buffer in the buffer list that it
* was referencing. It informs the buffer list that it can discard buffers
* starting at that prefix. The buffer list will do so if the usage count of
* that buffer is 0 and if it is the first buffer in the list. It will
* continue to prune buffers starting from the front of the buffer list until
* it finds a buffer that has a usage count that is non-zero.
*/
class nsScannerBufferList
{
public:
/**
* Buffer objects are directly followed by a data segment. The start
* of the data segment is determined by increment the |this| pointer
* by 1 unit.
*/
class Buffer : public PRCList
{
public:
void IncrementUsageCount() { ++mUsageCount; }
void DecrementUsageCount() { --mUsageCount; }
PRBool IsInUse() const { return mUsageCount != 0; }
const PRUnichar* DataStart() const { return (const PRUnichar*) (this+1); }
PRUnichar* DataStart() { return ( PRUnichar*) (this+1); }
const PRUnichar* DataEnd() const { return mDataEnd; }
PRUnichar* DataEnd() { return mDataEnd; }
const Buffer* Next() const { return NS_STATIC_CAST(const Buffer*, next); }
Buffer* Next() { return NS_STATIC_CAST( Buffer*, next); }
const Buffer* Prev() const { return NS_STATIC_CAST(const Buffer*, prev); }
Buffer* Prev() { return NS_STATIC_CAST( Buffer*, prev); }
PRUint32 DataLength() const { return mDataEnd - DataStart(); }
void SetDataLength(PRUint32 len) { mDataEnd = DataStart() + len; }
private:
friend class nsScannerBufferList;
PRInt32 mUsageCount;
PRUnichar* mDataEnd;
};
/**
* Position objects serve as lightweight pointers into a buffer list.
* The mPosition member must be contained with mBuffer->DataStart()
* and mBuffer->DataEnd().
*/
class Position
{
public:
Position() {}
Position( Buffer* buffer, PRUnichar* position )
: mBuffer(buffer)
, mPosition(position)
{}
inline
Position( const nsScannerIterator& aIter );
inline
Position& operator=( const nsScannerIterator& aIter );
static size_t Distance( const Position& p1, const Position& p2 );
Buffer* mBuffer;
PRUnichar* mPosition;
};
static Buffer* AllocBufferFromString( const nsAString& );
static Buffer* AllocBuffer( PRUint32 capacity ); // capacity = number of chars
nsScannerBufferList( Buffer* buf )
: mRefCnt(0)
{
PR_INIT_CLIST(&mBuffers);
PR_APPEND_LINK(buf, &mBuffers);
}
void AddRef() { ++mRefCnt; }
void Release() { if (--mRefCnt == 0) delete this; }
void Append( Buffer* buf ) { PR_APPEND_LINK(buf, &mBuffers); }
void InsertAfter( Buffer* buf, Buffer* prev ) { PR_INSERT_AFTER(buf, prev); }
void SplitBuffer( const Position& );
void DiscardUnreferencedPrefix( Buffer* );
Buffer* Head() { return NS_STATIC_CAST( Buffer*, PR_LIST_HEAD(&mBuffers)); }
const Buffer* Head() const { return NS_STATIC_CAST(const Buffer*, PR_LIST_HEAD(&mBuffers)); }
Buffer* Tail() { return NS_STATIC_CAST( Buffer*, PR_LIST_TAIL(&mBuffers)); }
const Buffer* Tail() const { return NS_STATIC_CAST(const Buffer*, PR_LIST_TAIL(&mBuffers)); }
private:
friend class nsScannerSubstring;
~nsScannerBufferList() { ReleaseAll(); }
void ReleaseAll();
PRInt32 mRefCnt;
PRCList mBuffers;
};
/**
* nsScannerFragment represents a "slice" of a Buffer object.
*/
struct nsScannerFragment
{
typedef nsScannerBufferList::Buffer Buffer;
const Buffer* mBuffer;
const PRUnichar* mFragmentStart;
const PRUnichar* mFragmentEnd;
};
/**
* nsScannerSubstring is the base class for nsScannerString. It provides
* access to iterators and methods to bind the substring to another
* substring or nsAString instance.
*
* This class owns the buffer list.
*/
class nsScannerSubstring
{
public:
typedef nsScannerBufferList::Buffer Buffer;
typedef nsScannerBufferList::Position Position;
typedef PRUint32 size_type;
nsScannerSubstring();
nsScannerSubstring( const nsAString& s );
~nsScannerSubstring();
nsScannerIterator& BeginReading( nsScannerIterator& iter ) const;
nsScannerIterator& EndReading( nsScannerIterator& iter ) const;
size_type Length() const { return mLength; }
PRInt32 CountChar( PRUnichar ) const;
void Rebind( const nsScannerSubstring&, const nsScannerIterator&, const nsScannerIterator& );
void Rebind( const nsAString& );
const nsString& AsString() const;
PRBool GetNextFragment( nsScannerFragment& ) const;
PRBool GetPrevFragment( nsScannerFragment& ) const;
static inline Buffer* AllocBufferFromString( const nsAString& aStr ) { return nsScannerBufferList::AllocBufferFromString(aStr); }
static inline Buffer* AllocBuffer( size_type aCapacity ) { return nsScannerBufferList::AllocBuffer(aCapacity); }
protected:
void acquire_ownership_of_buffer_list() const
{
mBufferList->AddRef();
mStart.mBuffer->IncrementUsageCount();
}
void release_ownership_of_buffer_list()
{
if (mBufferList)
{
mStart.mBuffer->DecrementUsageCount();
mBufferList->DiscardUnreferencedPrefix(mStart.mBuffer);
mBufferList->Release();
}
}
void init_range_from_buffer_list()
{
mStart.mBuffer = mBufferList->Head();
mStart.mPosition = mStart.mBuffer->DataStart();
mEnd.mBuffer = mBufferList->Tail();
mEnd.mPosition = mEnd.mBuffer->DataEnd();
mLength = Position::Distance(mStart, mEnd);
}
Position mStart;
Position mEnd;
nsScannerBufferList *mBufferList;
size_type mLength;
// these fields are used to implement AsString
nsString mFlattenedRep;
PRBool mIsDirty;
};
/**
* nsScannerString provides methods to grow and modify a buffer list.
*/
class nsScannerString : public nsScannerSubstring
{
public:
nsScannerString( Buffer* );
// you are giving ownership to the string, it takes and keeps your
// buffer, deleting it when done.
// Use AllocBuffer or AllocBufferFromString to create a Buffer object
// for use with this function.
void AppendBuffer( Buffer* );
void DiscardPrefix( const nsScannerIterator& );
// any other way you want to do this?
void UngetReadable(const nsAString& aReadable, const nsScannerIterator& aCurrentPosition);
void ReplaceCharacter(nsScannerIterator& aPosition, PRUnichar aChar);
};
/**
* nsScannerIterator works just like nsReadingIterator<CharT> except that
* it knows how to iterate over a list of scanner buffers.
*/
class nsScannerIterator
{
public:
typedef nsScannerIterator self_type;
typedef ptrdiff_t difference_type;
typedef PRUnichar value_type;
typedef const PRUnichar* pointer;
typedef const PRUnichar& reference;
typedef nsScannerSubstring::Buffer Buffer;
protected:
nsScannerFragment mFragment;
const PRUnichar* mPosition;
const nsScannerSubstring* mOwner;
friend class nsScannerSubstring;
public:
nsScannerIterator() {}
// nsScannerIterator( const nsScannerIterator& ); // auto-generated copy-constructor OK
// nsScannerIterator& operator=( const nsScannerIterator& ); // auto-generated copy-assignment operator OK
inline void normalize_forward();
inline void normalize_backward();
pointer get() const
{
return mPosition;
}
PRUnichar operator*() const
{
return *get();
}
const nsScannerFragment& fragment() const
{
return mFragment;
}
const Buffer* buffer() const
{
return mFragment.mBuffer;
}
self_type& operator++()
{
++mPosition;
normalize_forward();
return *this;
}
self_type operator++( int )
{
self_type result(*this);
++mPosition;
normalize_forward();
return result;
}
self_type& operator--()
{
normalize_backward();
--mPosition;
return *this;
}
self_type operator--( int )
{
self_type result(*this);
normalize_backward();
--mPosition;
return result;
}
difference_type size_forward() const
{
return mFragment.mFragmentEnd - mPosition;
}
difference_type size_backward() const
{
return mPosition - mFragment.mFragmentStart;
}
self_type& advance( difference_type n )
{
while ( n > 0 )
{
difference_type one_hop = NS_MIN(n, size_forward());
NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a reading iterator beyond the end of a string");
// perhaps I should |break| if |!one_hop|?
mPosition += one_hop;
normalize_forward();
n -= one_hop;
}
while ( n < 0 )
{
normalize_backward();
difference_type one_hop = NS_MAX(n, -size_backward());
NS_ASSERTION(one_hop<0, "Infinite loop: can't advance (backward) a reading iterator beyond the end of a string");
// perhaps I should |break| if |!one_hop|?
mPosition += one_hop;
n -= one_hop;
}
return *this;
}
};
inline
PRBool
SameFragment( const nsScannerIterator& a, const nsScannerIterator& b )
{
return a.fragment().mFragmentStart == b.fragment().mFragmentStart;
}
/**
* this class is needed in order to make use of the methods in nsAlgorithm.h
*/
NS_SPECIALIZE_TEMPLATE
struct nsCharSourceTraits<nsScannerIterator>
{
typedef nsScannerIterator::difference_type difference_type;
static
PRUint32
readable_distance( const nsScannerIterator& first, const nsScannerIterator& last )
{
return PRUint32(SameFragment(first, last) ? last.get() - first.get() : first.size_forward());
}
static
const nsScannerIterator::value_type*
read( const nsScannerIterator& iter )
{
return iter.get();
}
static
void
advance( nsScannerIterator& s, difference_type n )
{
s.advance(n);
}
};
/**
* inline methods follow
*/
inline
void
nsScannerIterator::normalize_forward()
{
while (mPosition == mFragment.mFragmentEnd && mOwner->GetNextFragment(mFragment))
mPosition = mFragment.mFragmentStart;
}
inline
void
nsScannerIterator::normalize_backward()
{
while (mPosition == mFragment.mFragmentStart && mOwner->GetPrevFragment(mFragment))
mPosition = mFragment.mFragmentEnd;
}
inline
PRBool
operator==( const nsScannerIterator& lhs, const nsScannerIterator& rhs )
{
return lhs.get() == rhs.get();
}
inline
PRBool
operator!=( const nsScannerIterator& lhs, const nsScannerIterator& rhs )
{
return lhs.get() != rhs.get();
}
inline
nsScannerBufferList::Position::Position(const nsScannerIterator& aIter)
: mBuffer(NS_CONST_CAST(Buffer*, aIter.buffer()))
, mPosition(NS_CONST_CAST(PRUnichar*, aIter.get()))
{}
inline
nsScannerBufferList::Position&
nsScannerBufferList::Position::operator=(const nsScannerIterator& aIter)
{
mBuffer = NS_CONST_CAST(Buffer*, aIter.buffer());
mPosition = NS_CONST_CAST(PRUnichar*, aIter.get());
return *this;
}
/**
* scanner string utils
*
* These methods mimic the API provided by nsReadableUtils in xpcom/string.
* Here we provide only the methods that the htmlparser module needs.
*/
inline
size_t
Distance( const nsScannerIterator& aStart, const nsScannerIterator& aEnd )
{
typedef nsScannerBufferList::Position Position;
return Position::Distance(Position(aStart), Position(aEnd));
}
void
CopyUnicodeTo( const nsScannerIterator& aSrcStart,
const nsScannerIterator& aSrcEnd,
nsAString& aDest );
inline
void
CopyUnicodeTo( const nsScannerSubstring& aSrc, nsAString& aDest )
{
nsScannerIterator begin, end;
CopyUnicodeTo(aSrc.BeginReading(begin), aSrc.EndReading(end), aDest);
}
void
AppendUnicodeTo( const nsScannerIterator& aSrcStart,
const nsScannerIterator& aSrcEnd,
nsAString& aDest );
inline
void
AppendUnicodeTo( const nsScannerSubstring& aSrc, nsAString& aDest )
{
nsScannerIterator begin, end;
AppendUnicodeTo(aSrc.BeginReading(begin), aSrc.EndReading(end), aDest);
}
PRBool
FindCharInReadable( PRUnichar aChar,
nsScannerIterator& aStart,
const nsScannerIterator& aEnd );
PRBool
FindInReadable( const nsAString& aPattern,
nsScannerIterator& aStart,
nsScannerIterator& aEnd,
const nsStringComparator& = nsDefaultStringComparator() );
PRBool
RFindInReadable( const nsAString& aPattern,
nsScannerIterator& aStart,
nsScannerIterator& aEnd,
const nsStringComparator& = nsDefaultStringComparator() );
inline
PRBool
CaseInsensitiveFindInReadable( const nsAString& aPattern,
nsScannerIterator& aStart,
nsScannerIterator& aEnd )
{
return FindInReadable(aPattern, aStart, aEnd,
nsCaseInsensitiveStringComparator());
}
#endif // !defined(nsScannerString_h___)

Просмотреть файл

@ -1,296 +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 <start>, </end>, <text>,
* <comment>, <&entity>, <newline>, and <whitespace> 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
*/
void SetTypeID(PRInt32 aValue) {
mTypeID = 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);
/**
* 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

Просмотреть файл

@ -1,2 +0,0 @@
Makefile
htmlrobot

Просмотреть файл

@ -1,356 +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):
* Pierre Phaneuf <pp@ludusdesign.com>
*
* 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 "nsIRobotSink.h"
#include "nsIRobotSinkObserver.h"
#include "nsIParser.h"
#include "nsIDocShell.h"
#include "nsIWebNavigation.h"
#include "nsIWebProgress.h"
#include "nsIWebProgressListener.h"
#include "nsWeakReference.h"
#include "nsVoidArray.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsIURL.h"
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsIIOService.h"
#include "nsNetCID.h"
#include "nsIComponentManager.h"
#include "nsParserCIID.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
class RobotSinkObserver : public nsIRobotSinkObserver {
public:
RobotSinkObserver() {
}
virtual ~RobotSinkObserver() {
}
NS_DECL_ISUPPORTS
NS_IMETHOD ProcessLink(const nsString& aURLSpec);
NS_IMETHOD VerifyDirectory (const char * verify_dir);
};
static nsVoidArray * g_workList;
static nsVoidArray * g_duplicateList;
static int g_iProcessed;
static int g_iMaxProcess = 5000;
static PRBool g_bHitTop;
static PRBool g_bReadyForNextUrl;
NS_IMPL_ISUPPORTS1(RobotSinkObserver, nsIRobotSinkObserver)
NS_IMETHODIMP RobotSinkObserver::VerifyDirectory(const char * verify_dir)
{
return NS_OK;
}
NS_IMETHODIMP RobotSinkObserver::ProcessLink(const nsString& aURLSpec)
{
if (!g_bHitTop) {
nsAutoString str;
// Geez this is ugly. temporary hack to only process html files
str.Truncate();
nsString(aURLSpec).Right(str,1);
if (!str.Equals(NS_LITERAL_STRING("/")))
{
str.Truncate();
nsString(aURLSpec).Right(str,4);
if (!str.Equals(NS_LITERAL_STRING("html")))
{
str.Truncate();
nsString(aURLSpec).Right(str,3);
if (!str.Equals(NS_LITERAL_STRING("htm")))
return NS_OK;
}
}
PRInt32 nCount = g_duplicateList->Count();
if (nCount > 0)
{
for (PRInt32 n = 0; n < nCount; ++n)
{
nsString * pstr = (nsString *)g_duplicateList->ElementAt(n);
if (pstr->Equals(aURLSpec)) {
fputs ("Robot: (duplicate '",stdout);
fputs (NS_LossyConvertUCS2toASCII(aURLSpec).get(),stdout);
fputs ("')\n",stdout);
return NS_OK;
}
}
}
g_duplicateList->AppendElement(new nsString(aURLSpec));
str.Truncate();
nsString(aURLSpec).Left(str,5);
if (str.Equals(NS_LITERAL_STRING("http:"))) {
++g_iProcessed;
if (g_iProcessed == (g_iMaxProcess > 0 ? g_iMaxProcess-1 : 0))
g_bHitTop = PR_TRUE;
g_workList->AppendElement(new nsString(aURLSpec));
}
else {
fputs ("Robot: (cannot process URL types '",stdout);
fputs (NS_LossyConvertUCS2toASCII(aURLSpec).get(),stdout);
fputs ("')\n",stdout);
}
}
return NS_OK;
}
extern "C" NS_EXPORT void SetVerificationDirectory(char * verify_dir);
class CStreamListener: public nsIWebProgressListener,
public nsSupportsWeakReference
{
public:
CStreamListener() {
}
virtual ~CStreamListener() {
}
NS_DECL_ISUPPORTS
// nsIWebProgressListener
NS_DECL_NSIWEBPROGRESSLISTENER
};
// nsIWebProgressListener implementation
NS_IMETHODIMP
CStreamListener::OnStateChange(nsIWebProgress* aWebProgress,
nsIRequest *aRequest,
PRUint32 progressStateFlags,
nsresult aStatus)
{
if (progressStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT)
if (progressStateFlags & nsIWebProgressListener::STATE_STOP) {
fputs("done.\n",stdout);
g_bReadyForNextUrl = PR_TRUE;
}
return NS_OK;
}
NS_IMETHODIMP
CStreamListener::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
NS_IMETHODIMP
CStreamListener::OnLocationChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsIURI *location)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
NS_IMETHODIMP
CStreamListener::OnStatusChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsresult aStatus,
const PRUnichar* aMessage)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
NS_IMETHODIMP
CStreamListener::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 state)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
NS_IMPL_ISUPPORTS2(CStreamListener,
nsIWebProgressListener,
nsISupportsWeakReference)
extern "C" NS_EXPORT void DumpVectorRecord(void);
//----------------------------------------------------------------------
extern "C" NS_EXPORT int DebugRobot(
nsVoidArray * workList,
nsIDocShell * docShell,
int iMaxLoads,
char * verify_dir,
void (*yieldProc )(const char *)
)
{
int iCount = 1;
CStreamListener * pl = new CStreamListener;
NS_ADDREF(pl);
if (nsnull==workList)
return -1;
g_iMaxProcess = iMaxLoads;
g_iProcessed = 0;
g_bHitTop = PR_FALSE;
g_duplicateList = new nsVoidArray();
RobotSinkObserver* myObserver = new RobotSinkObserver();
NS_ADDREF(myObserver);
g_workList = workList;
for (;;) {
PRInt32 n = g_workList->Count();
if (0 == n) {
break;
}
nsString* urlName = (nsString*) g_workList->ElementAt(n - 1);
g_workList->RemoveElementAt(n - 1);
// Create url
nsIURI* url;
nsresult rv;
nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &rv));
if (NS_FAILED(rv)) return rv;
nsIURI *uri = nsnull;
NS_ConvertUCS2toUTF8 uriStr(*urlName);
rv = service->NewURI(uriStr, nsnull, nsnull, &uri);
if (NS_FAILED(rv)) return rv;
rv = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&url);
NS_RELEASE(uri);
if (NS_OK != rv) {
printf("invalid URL: '");
fputs(uriStr.get(), stdout);
printf("'\n");
NS_RELEASE(myObserver);
return -1;
}
char str_num[25];
sprintf (str_num,"%d",iCount++);
fputs ("Robot: parsing(",stdout);
fputs (str_num,stdout);
fputs (") ",stdout);
fputs (NS_LossyConvertUCS2toASCII(*urlName).get(),stdout);
fputs ("...",stdout);
delete urlName;
nsIParser* parser;
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
rv = nsComponentManager::CreateInstance(kCParserCID,
nsnull,
kCParserIID,
(void **)&parser);
if (NS_OK != rv) {
printf("can't make parser\n");
NS_RELEASE(myObserver);
return -1;
}
nsIRobotSink* sink;
rv = NS_NewRobotSink(&sink);
if (NS_OK != rv) {
printf("can't make parser\n");
NS_RELEASE(myObserver);
return -1;
}
sink->Init(url);
sink->AddObserver(myObserver);
parser->SetContentSink(sink);
g_bReadyForNextUrl = PR_FALSE;
parser->Parse(url, nsnull,PR_TRUE);/* XXX hook up stream listener here! */
while (!g_bReadyForNextUrl) {
if (yieldProc != NULL) {
nsCAutoString spec;
(void)url->GetSpec(spec);
(*yieldProc)(spec.get());
}
}
g_bReadyForNextUrl = PR_FALSE;
if (docShell) {
nsCOMPtr<nsIWebProgress> progress(do_GetInterface(docShell, &rv));
if (NS_FAILED(rv)) return rv;
(void) progress->AddProgressListener(pl, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
nsCAutoString spec;
(void)url->GetSpec(spec);
NS_ConvertUTF8toUCS2 theSpec(spec);
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
webNav->LoadURI(theSpec.get(),
nsIWebNavigation::LOAD_FLAGS_NONE,
nsnull,
nsnull,
nsnull);/* XXX hook up stream listener here! */
while (!g_bReadyForNextUrl) {
if (yieldProc != NULL) {
(void)url->GetSpec(spec);
(*yieldProc)(spec.get());
}
}
}
NS_RELEASE(sink);
NS_RELEASE(parser);
NS_RELEASE(url);
}
fputs ("Robot completed.\n", stdout);
NS_RELEASE(pl);
NS_RELEASE(myObserver);
return 0;
}

Просмотреть файл

@ -1,59 +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 ***** */
#ifndef nsIRobotSink_h___
#define nsIRobotSink_h___
#include "nsIHTMLContentSink.h"
class nsIURI;
class nsIRobotSinkObserver;
/* 61256800-cfd8-11d1-9328-00805f8add32 */
#define NS_IROBOTSINK_IID \
{ 0x61256800, 0xcfd8, 0x11d1, \
{0x93, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
class nsIRobotSink : public nsIHTMLContentSink {
public:
NS_IMETHOD Init(nsIURI* aDocumentURL) = 0;
NS_IMETHOD AddObserver(nsIRobotSinkObserver* aObserver) = 0;
NS_IMETHOD RemoveObserver(nsIRobotSinkObserver* aObserver) = 0;
};
extern nsresult NS_NewRobotSink(nsIRobotSink** aInstancePtrResult);
#endif /* nsIRobotSink_h___ */

Просмотреть файл

@ -1,56 +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 ***** */
#ifndef nsIRobotSinkObserver_h___
#define nsIRobotSinkObserver_h___
#include "nsISupports.h"
class nsString;
/* fab1d970-cfda-11d1-9328-00805f8add32 */
#define NS_IROBOTSINKOBSERVER_IID \
{ 0xfab1d970, 0xcfda, 0x11d1, \
{0x93, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
class nsIRobotSinkObserver : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IROBOTSINKOBSERVER_IID)
NS_IMETHOD ProcessLink(const nsString& aURLSpec) = 0;
NS_IMETHOD VerifyDirectory(const char * verify_dir) = 0;
};
#endif /* nsIRobotSinkObserver_h___ */

Просмотреть файл

@ -1,401 +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):
* Pierre Phaneuf <pp@ludusdesign.com>
*
* 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 "nsIRobotSink.h"
#include "nsIRobotSinkObserver.h"
#include "nsIParserNode.h"
#include "nsIParser.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsIURL.h"
#include "nsIURL.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsNetCID.h"
#include "nsCRT.h"
#include "nsVoidArray.h"
class nsIDocument;
// TODO
// - add in base tag support
// - get links from other sources:
// - LINK tag
// - STYLE SRC
// - IMG SRC
// - LAYER SRC
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTML_CONTENT_SINK_IID);
static NS_DEFINE_IID(kIRobotSinkIID, NS_IROBOTSINK_IID);
class RobotSink : public nsIRobotSink {
public:
RobotSink();
virtual ~RobotSink();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
// nsISupports
NS_DECL_ISUPPORTS
// nsIHTMLContentSink
NS_IMETHOD SetTitle(const nsString& aValue);
NS_IMETHOD OpenHTML(const nsIParserNode& aNode);
NS_IMETHOD CloseHTML();
NS_IMETHOD OpenHead(const nsIParserNode& aNode);
NS_IMETHOD CloseHead();
NS_IMETHOD OpenBody(const nsIParserNode& aNode);
NS_IMETHOD CloseBody();
NS_IMETHOD OpenForm(const nsIParserNode& aNode);
NS_IMETHOD CloseForm();
NS_IMETHOD OpenMap(const nsIParserNode& aNode);
NS_IMETHOD CloseMap();
NS_IMETHOD OpenFrameset(const nsIParserNode& aNode);
NS_IMETHOD CloseFrameset();
NS_IMETHOD IsEnabled(PRInt32 aTag, PRBool* aReturn) { return NS_OK; }
NS_IMETHOD_(PRBool) IsFormOnStack() { return PR_FALSE; }
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
NS_IMETHOD CloseContainer(const nsHTMLTag aTag);
NS_IMETHOD CloseTopmostContainer();
NS_IMETHOD AddHeadContent(const nsIParserNode& aNode);
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
NS_IMETHOD AddComment(const nsIParserNode& aNode);
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
NS_IMETHOD WillBuildModel(void) { return NS_OK; }
NS_IMETHOD DidBuildModel(void) { return NS_OK; }
NS_IMETHOD WillInterrupt(void) { return NS_OK; }
NS_IMETHOD WillResume(void) { return NS_OK; }
NS_IMETHOD SetParser(nsIParser* aParser) { return NS_OK; }
NS_IMETHOD FlushPendingNotifications() { return NS_OK; }
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) { return NS_OK; }
NS_IMETHOD WillProcessTokens(void) { return NS_OK; }
NS_IMETHOD DidProcessTokens(void) { return NS_OK; }
NS_IMETHOD WillProcessAToken(void) { return NS_OK; }
NS_IMETHOD DidProcessAToken(void) { return NS_OK; }
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode) { return NS_OK; }
NS_IMETHOD BeginContext(PRInt32 aPosition){ return NS_OK; }
NS_IMETHOD EndContext(PRInt32 aPosition){ return NS_OK; }
// nsIRobotSink
NS_IMETHOD Init(nsIURI* aDocumentURL);
NS_IMETHOD AddObserver(nsIRobotSinkObserver* aObserver);
NS_IMETHOD RemoveObserver(nsIRobotSinkObserver* aObserver);
void ProcessLink(const nsString& aLink);
protected:
nsIURI* mDocumentURL;
nsVoidArray mObservers;
};
nsresult NS_NewRobotSink(nsIRobotSink** aInstancePtrResult)
{
RobotSink* it = new RobotSink();
if(it)
return it->QueryInterface(kIRobotSinkIID, (void**) aInstancePtrResult);
return NS_OK;
}
RobotSink::RobotSink()
{
}
RobotSink::~RobotSink()
{
NS_IF_RELEASE(mDocumentURL);
PRInt32 i, n = mObservers.Count();
for (i = 0; i < n; ++i) {
nsIRobotSinkObserver* cop = (nsIRobotSinkObserver*)mObservers.ElementAt(i);
NS_RELEASE(cop);
}
}
NS_IMPL_ADDREF(RobotSink)
NS_IMPL_RELEASE(RobotSink)
NS_IMETHODIMP RobotSink::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIRobotSinkIID)) {
*aInstancePtr = (void*) this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kIHTMLContentSinkIID)) {
*aInstancePtr = (void*) this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsISupports*)this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP RobotSink::SetTitle(const nsString& aValue)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::OpenHTML(const nsIParserNode& aNode)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::CloseHTML()
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::OpenHead(const nsIParserNode& aNode)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::CloseHead()
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::OpenBody(const nsIParserNode& aNode)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::CloseBody()
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::OpenForm(const nsIParserNode& aNode)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::CloseForm()
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::OpenMap(const nsIParserNode& aNode)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::CloseMap()
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::OpenFrameset(const nsIParserNode& aNode)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::CloseFrameset()
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::OpenContainer(const nsIParserNode& aNode)
{
nsAutoString tmp; tmp.Assign(aNode.GetText());
ToLowerCase(tmp);
if (tmp.Equals(NS_LITERAL_STRING("a"))) {
nsAutoString k, v;
PRInt32 ac = aNode.GetAttributeCount();
for (PRInt32 i = 0; i < ac; ++i) {
// Get upper-cased key
const nsAString& key = aNode.GetKeyAt(i);
k.Assign(key);
ToLowerCase(k);
if (k.Equals(NS_LITERAL_STRING("href"))) {
// Get value and remove mandatory quotes
v.Truncate();
v.Append(aNode.GetValueAt(i));
PRUnichar first = v.First();
if ((first == '"') || (first == '\'')) {
if (v.Last() == first) {
v.Cut(0, 1);
PRInt32 pos = v.Length() - 1;
if (pos >= 0) {
v.Cut(pos, 1);
}
} else {
// Mismatched quotes - leave them in
}
}
ProcessLink(v);
}
}
}
return NS_OK;
}
NS_IMETHODIMP RobotSink::CloseContainer(const nsHTMLTag aTag)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::CloseTopmostContainer()
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::AddHeadContent(const nsIParserNode& aNode)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::AddLeaf(const nsIParserNode& aNode)
{
return NS_OK;
}
/**
* This gets called by the parsing system when we find a comment
* @update gess11/9/98
* @param aNode contains a comment token
* @return error code
*/
NS_IMETHODIMP RobotSink::AddComment(const nsIParserNode& aNode) {
nsresult result= NS_OK;
return result;
}
/**
* This gets called by the parsing system when we find a PI
* @update gess11/9/98
* @param aNode contains a comment token
* @return error code
*/
NS_IMETHODIMP RobotSink::AddProcessingInstruction(const nsIParserNode& aNode) {
nsresult result= NS_OK;
return result;
}
/**
* This gets called by the parser when it encounters
* a DOCTYPE declaration in the HTML document.
*/
NS_IMETHODIMP
RobotSink::AddDocTypeDecl(const nsIParserNode& aNode)
{
return NS_OK;
}
NS_IMETHODIMP RobotSink::Init(nsIURI* aDocumentURL)
{
NS_IF_RELEASE(mDocumentURL);
mDocumentURL = aDocumentURL;
NS_IF_ADDREF(aDocumentURL);
return NS_OK;
}
NS_IMETHODIMP RobotSink::AddObserver(nsIRobotSinkObserver* aObserver)
{
if (mObservers.AppendElement(aObserver)) {
NS_ADDREF(aObserver);
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP RobotSink::RemoveObserver(nsIRobotSinkObserver* aObserver)
{
if (mObservers.RemoveElement(aObserver)) {
NS_RELEASE(aObserver);
return NS_OK;
}
//XXX return NS_ERROR_NOT_FOUND;
return NS_OK;
}
void RobotSink::ProcessLink(const nsString& aLink)
{
nsAutoString absURLSpec; absURLSpec.Assign(aLink);
// Make link absolute
// XXX base tag handling
nsIURI* docURL = mDocumentURL;
if (nsnull != docURL) {
nsIURI* absurl;
nsresult rv;
nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &rv));
if (NS_FAILED(rv)) return;
nsIURI *uri = nsnull, *baseUri = nsnull;
rv = mDocumentURL->QueryInterface(NS_GET_IID(nsIURI), (void**)&baseUri);
if (NS_FAILED(rv)) return;
NS_ConvertUCS2toUTF8 uriStr(aLink);
rv = service->NewURI(uriStr, nsnull, baseUri, &uri);
NS_RELEASE(baseUri);
if (NS_FAILED(rv)) return;
rv = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&absurl);
NS_RELEASE(uri);
if (NS_OK == rv) {
absURLSpec.Truncate();
nsCAutoString str;
absurl->GetSpec(str);
absURLSpec = NS_ConvertUTF8toUCS2(str);
}
}
// Now give link to robot observers
PRInt32 i, n = mObservers.Count();
for (i = 0; i < n; ++i) {
nsIRobotSinkObserver* cop = (nsIRobotSinkObserver*)mObservers.ElementAt(i);
cop->ProcessLink(absURLSpec);
}
}

Просмотреть файл

@ -1,2 +0,0 @@
Makefile
htmlrobot

Просмотреть файл

@ -1,28 +0,0 @@
#include "nsXPCOM.h"
#include "nsVoidArray.h"
#include "nsString.h"
class nsIWebShell;
extern "C" NS_EXPORT int DebugRobot(nsVoidArray * workList, nsIWebShell * ww);
int main(int argc, char **argv)
{
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
if (NS_FAILED(rv)) {
printf("NS_InitXPCOM2 failed\n");
return 1;
}
nsVoidArray * gWorkList = new nsVoidArray();
if(gWorkList) {
int i;
for (i = 1; i < argc; ++i) {
nsString *tempString = new nsString;
tempString->AssignWithConversion(argv[i]);
gWorkList->AppendElement(tempString);
}
}
return DebugRobot(gWorkList, nsnull);
}

Просмотреть файл

@ -1 +0,0 @@
Makefile

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,417 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 7/15/98
*
* NavDTD is an implementation of the nsIDTD interface.
* In particular, this class captures the behaviors of the original
* Navigator parser productions.
*
* This DTD, like any other in NGLayout, provides a few basic services:
* - First, the DTD collaborates with the Parser class to convert plain
* text into a sequence of HTMLTokens.
* - Second, the DTD describes containment rules for known elements.
* - Third the DTD controls and coordinates the interaction between the
* parsing system and content sink. (The content sink is the interface
* that serves as a proxy for content model).
* - Fourth the DTD maintains an internal style-stack to handle residual (leaky)
* style tags.
*
* You're most likely working in this class file because
* you want to add or change a behavior inherent in this DTD. The remainder
* of this section will describe what you need to do to affect the kind of
* change you want in this DTD.
*
* RESIDUAL-STYLE HANDLNG:
* There are a number of ways to represent style in an HTML document.
* 1) explicit style tags (<B>, <I> etc)
* 2) implicit styles (like those implicit in <Hn>)
* 3) CSS based styles
*
* Residual style handling results from explicit style tags that are
* not closed. Consider this example: <p>text <b>bold </p>
* When the <p> tag closes, the <b> tag is NOT automatically closed.
* Unclosed style tags are handled by the process we call residual-style
* tag handling.
*
* There are two aspects to residual style tag handling. The first is the
* construction and managing of a stack of residual style tags. The
* second is the automatic emission of residual style tags onto leaf content
* in subsequent portions of the document.This step is necessary to propagate
* the expected style behavior to subsequent portions of the document.
*
* Construction and managing the residual style stack is an inline process that
* occurs during the model building phase of the parse process. During the model-
* building phase of the parse process, a content stack is maintained which tracks
* the open container hierarchy. If a style tag(s) fails to be closed when a normal
* container is closed, that style tag is placed onto the residual style stack. If
* that style tag is subsequently closed (in most contexts), it is popped off the
* residual style stack -- and are of no further concern.
*
* Residual style tag emission occurs when the style stack is not empty, and leaf
* content occurs. In our earlier example, the <b> tag "leaked" out of the <p>
* container. Just before the next leaf is emitted (in this or another container) the
* style tags that are on the stack are emitted in succession. These same residual
* style tags get closed automatically when the leaf's container closes, or if a
* child container is opened.
*
*
*/
#ifndef NS_NAVHTMLDTD__
#define NS_NAVHTMLDTD__
#include "nsIDTD.h"
#include "nsISupports.h"
#include "nsIParser.h"
#include "nsHTMLTags.h"
#include "nsVoidArray.h"
#include "nsDeque.h"
#include "nsParserCIID.h"
#include "nsTime.h"
#include "nsDTDUtils.h"
#define NS_INAVHTML_DTD_IID \
{0x5c5cce40, 0xcfd6, 0x11d1, \
{0xaa, 0xda, 0x00, 0x80, 0x5f, 0x8a, 0x3e, 0x14}}
class nsIHTMLContentSink;
class nsIParserNode;
class nsParser;
class nsDTDContext;
class nsEntryStack;
class nsITokenizer;
class nsCParserNode;
class nsTokenAllocator;
/***************************************************************
Now the main event: CNavDTD.
This not so simple class performs all the duties of token
construction and model building. It works in conjunction with
an nsParser.
***************************************************************/
#ifdef _MSC_VER
#pragma warning( disable : 4275 )
#endif
class CNavDTD : public nsIDTD
{
#ifdef _MSC_VER
#pragma warning( default : 4275 )
#endif
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDTD
/**
* Common constructor for navdtd. You probably want to call
* NS_NewNavHTMLDTD().
*
* @update gess 7/9/98
*/
CNavDTD();
virtual ~CNavDTD();
/**
* 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
*/
virtual PRBool CanPropagate(eHTMLTags aParent,
eHTMLTags aChild,
PRBool aParentContains) ;
/**
* This method gets called to determine whether a given
* child tag can be omitted by the given parent.
*
* @update gess 3/25/98
* @param aParent -- parent tag being asked about omitting given child
* @param aChild -- child tag being tested for omittability by parent
* @param aParentContains -- can be 0,1,-1 (false,true, unknown)
* @return PR_TRUE if given tag can be omitted
*/
virtual PRBool CanOmit(eHTMLTags aParent,
eHTMLTags aChild,
PRBool& aParentContains);
/**
* This method tries to design a context map (without actually
* changing our parser state) from the parent down to the
* child.
*
* @update gess4/6/98
* @param aParent -- tag type of parent
* @param aChild -- tag type of child
* @return True if closure was achieved -- other false
*/
virtual PRBool ForwardPropagate(nsString& aSequence,
eHTMLTags aParent,
eHTMLTags aChild);
/**
* This method tries to design a context map (without actually
* changing our parser state) from the child up to the parent.
*
* @update gess4/6/98
* @param aParent -- tag type of parent
* @param aChild -- tag type of child
* @return True if closure was achieved -- other false
*/
virtual PRBool BackwardPropagate(nsString& aSequence,
eHTMLTags aParent,
eHTMLTags aChild) const;
/**
* Attempt forward and/or backward propagation for the given
* child within the current context vector stack.
* @update gess5/11/98
* @param aChild -- type of child to be propagated.
* @return TRUE if succeeds, otherwise FALSE
*/
nsresult CreateContextStackFor(eHTMLTags aChild);
/**
* Ask parser if a given container is open ANYWHERE on stack
* @update gess5/11/98
* @param id of container you want to test for
* @return TRUE if the given container type is open -- otherwise FALSE
*/
virtual PRBool HasOpenContainer(eHTMLTags aContainer) const;
/**
* Ask parser if a given container is open ANYWHERE on stack
* @update gess5/11/98
* @param id of container you want to test for
* @return TRUE if the given container type is open -- otherwise FALSE
*/
virtual PRBool HasOpenContainer(const eHTMLTags aTagSet[],PRInt32 aCount) const;
/**
* Accessor that retrieves the tag type of the topmost item on context
* vector stack.
*
* @update gess5/11/98
* @return tag type (may be unknown)
*/
virtual eHTMLTags GetTopNode() const;
/**
* Finds the topmost occurance of given tag within context vector stack.
* @update gess5/11/98
* @param tag to be found
* @return index of topmost tag occurance -- may be -1 (kNotFound).
*/
// virtual PRInt32 GetTopmostIndexOf(eHTMLTags aTag) const;
/**
* Finds the topmost occurance of given tag within context vector stack.
* @update gess5/11/98
* @param tag to be found
* @return index of topmost tag occurance -- may be -1 (kNotFound).
*/
virtual PRInt32 LastOf(eHTMLTags aTagSet[],PRInt32 aCount) const;
/**
* The following set of methods are used to partially construct
* the content model (via the sink) according to the type of token.
* @update gess5/11/98
* @param aToken is the token (of a given type) to be handled
* @return error code representing construction state; usually 0.
*/
nsresult HandleStartToken(CToken* aToken);
nsresult HandleDefaultStartToken(CToken* aToken, eHTMLTags aChildTag,
nsCParserNode *aNode);
nsresult HandleEndToken(CToken* aToken);
nsresult HandleEntityToken(CToken* aToken);
nsresult HandleCommentToken(CToken* aToken);
nsresult HandleAttributeToken(CToken* aToken);
nsresult HandleScriptToken(const nsIParserNode *aNode);
nsresult HandleProcessingInstructionToken(CToken* aToken);
nsresult HandleDocTypeDeclToken(CToken* aToken);
nsresult BuildNeglectedTarget(eHTMLTags aTarget, eHTMLTokenTypes aType,
nsIParser* aParser, nsIContentSink* aSink);
//*************************************************
//these cover methods mimic the sink, and are used
//by the parser to manage its context-stack.
//*************************************************
/**
* The next set of method open given HTML elements of
* various types.
*
* @update gess5/11/98
* @param node to be opened in content sink.
* @return error code representing error condition-- usually 0.
*/
nsresult OpenHTML(const nsCParserNode *aNode);
nsresult OpenHead(const nsIParserNode *aNode);
nsresult OpenBody(const nsCParserNode *aNode);
nsresult OpenForm(const nsIParserNode *aNode);
nsresult OpenMap(const nsCParserNode *aNode);
nsresult OpenFrameset(const nsCParserNode *aNode);
nsresult OpenContainer(const nsCParserNode *aNode,
eHTMLTags aTag,
PRBool aClosedByStartTag,
nsEntryStack* aStyleStack=0);
/**
* The next set of methods close the given HTML element.
*
* @update gess5/11/98
* @param HTML (node) to be opened in content sink.
* @return error code - 0 if all went well.
*/
nsresult CloseHTML();
nsresult CloseHead();
nsresult CloseBody();
nsresult CloseForm();
nsresult CloseMap();
nsresult CloseFrameset();
/**
* The special purpose methods automatically close
* one or more open containers.
* @update gess5/11/98
* @return error code - 0 if all went well.
*/
nsresult CloseContainer(const eHTMLTags aTag,
eHTMLTags aTarget,
PRBool aClosedByStartTag);
nsresult CloseContainersTo(eHTMLTags aTag,
PRBool aClosedByStartTag);
nsresult CloseContainersTo(PRInt32 anIndex,
eHTMLTags aTag,
PRBool aClosedByStartTag);
/**
* Causes leaf to be added to sink at current vector pos.
* @update gess5/11/98
* @param aNode is leaf node to be added.
* @return error code - 0 if all went well.
*/
nsresult AddLeaf(const nsIParserNode *aNode);
nsresult AddHeadLeaf(nsIParserNode *aNode);
/**
* This set of methods is used to create and manage the set of
* transient styles that occur as a result of poorly formed HTML
* or bugs in the original navigator.
*
* @update gess5/11/98
* @param aTag -- represents the transient style tag to be handled.
* @return error code -- usually 0
*/
nsresult OpenTransientStyles(eHTMLTags aChildTag);
nsresult CloseTransientStyles(eHTMLTags aChildTag);
nsresult PopStyle(eHTMLTags aTag);
nsresult PushIntoMisplacedStack(CToken* aToken)
{
NS_ENSURE_ARG_POINTER(aToken);
aToken->SetNewlineCount(0); // Note: We have already counted the newlines for these tokens
mMisplacedContent.Push(aToken);
return NS_OK;
}
protected:
nsresult CollectAttributes(nsIParserNode& aNode,eHTMLTags aTag,PRInt32 aCount);
nsresult CollectSkippedContent(nsIParserNode& aNode,PRInt32& aCount);
nsresult WillHandleStartTag(CToken* aToken,eHTMLTags aChildTag,nsIParserNode& aNode);
nsresult DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag);
nsresult HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags aParent,nsIParserNode *aNode);
nsresult HandleSavedTokens(PRInt32 anIndex);
nsresult HandleKeyGen(nsIParserNode *aNode);
nsDeque mMisplacedContent;
nsDeque mSkippedContent;
nsIHTMLContentSink* mSink;
nsTokenAllocator* mTokenAllocator;
nsDTDContext* mBodyContext;
nsDTDContext* mTempContext;
nsParser* mParser;
nsITokenizer* mTokenizer; // weak
nsString mFilename;
nsString mScratch; //used for various purposes; non-persistent
nsCString mMimeType;
nsNodeAllocator mNodeAllocator;
nsDTDMode mDTDMode;
eParserDocType mDocType;
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...
eHTMLTags mSkipTarget;
PRInt32 mLineNumber;
PRInt32 mOpenMapCount;
PRUint16 mFlags;
#ifdef ENABLE_CRC
PRUint32 mComputedCRC32;
PRUint32 mExpectedCRC32;
#endif
};
inline nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult)
{
NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
return nsComponentManager::CreateInstance(kNavDTDCID,
nsnull,
NS_GET_IID(nsIDTD),
(void**)aInstancePtrResult);
}
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,223 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 7/15/98
*
* NavDTD is an implementation of the nsIDTD interface.
* In particular, this class captures the behaviors of the original
* Navigator parser productions.
*
* This DTD, like any other in NGLayout, provides a few basic services:
* - First, the DTD collaborates with the Parser class to convert plain
* text into a sequence of HTMLTokens.
* - Second, the DTD describes containment rules for known elements.
* - Third the DTD controls and coordinates the interaction between the
* parsing system and content sink. (The content sink is the interface
* that serves as a proxy for content model).
* - Fourth the DTD maintains an internal style-stack to handle residual (leaky)
* style tags.
*
* You're most likely working in this class file because
* you want to add or change a behavior inherent in this DTD. The remainder
* of this section will describe what you need to do to affect the kind of
* change you want in this DTD.
*
* RESIDUAL-STYLE HANDLNG:
* There are a number of ways to represent style in an HTML document.
* 1) explicit style tags (<B>, <I> etc)
* 2) implicit styles (like those implicit in <Hn>)
* 3) CSS based styles
*
* Residual style handling results from explicit style tags that are
* not closed. Consider this example: <p>text <b>bold </p>
* When the <p> tag closes, the <b> tag is NOT automatically closed.
* Unclosed style tags are handled by the process we call residual-style
* tag handling.
*
* There are two aspects to residual style tag handling. The first is the
* construction and managing of a stack of residual style tags. The
* second is the automatic emission of residual style tags onto leaf content
* in subsequent portions of the document.This step is necessary to propagate
* the expected style behavior to subsequent portions of the document.
*
* Construction and managing the residual style stack is an inline process that
* occurs during the model building phase of the parse process. During the model-
* building phase of the parse process, a content stack is maintained which tracks
* the open container hierarchy. If a style tag(s) fails to be closed when a normal
* container is closed, that style tag is placed onto the residual style stack. If
* that style tag is subsequently closed (in most contexts), it is popped off the
* residual style stack -- and are of no further concern.
*
* Residual style tag emission occurs when the style stack is not empty, and leaf
* content occurs. In our earlier example, the <b> tag "leaked" out of the <p>
* container. Just before the next leaf is emitted (in this or another container) the
* style tags that are on the stack are emitted in succession. These same residual
* style tags get closed automatically when the leaf's container closes, or if a
* child container is opened.
*
*
*/
#ifndef NS_OTHERDTD__
#define NS_OTHERDTD__
#include "nsIDTD.h"
#include "nsISupports.h"
#include "nsIParser.h"
#include "nsHTMLTokens.h"
#include "nsVoidArray.h"
#include "nsDeque.h"
#include "nsParserCIID.h"
#define NS_IOTHERHTML_DTD_IID \
{0x8a5e89c0, 0xd16d, 0x11d1, \
{0x80, 0x22, 0x00, 0x60, 0x8, 0x14, 0x98, 0x89}}
class nsIHTMLContentSink;
class nsIParserNode;
class nsParser;
class nsDTDContext;
class nsEntryStack;
class nsITokenizer;
class nsIParserNode;
class nsTokenAllocator;
class nsNodeAllocator;
/***************************************************************
Now the main event: COtherDTD.
This not so simple class performs all the duties of token
construction and model building. It works in conjunction with
an nsParser.
***************************************************************/
#ifdef _MSC_VER
#pragma warning( disable : 4275 )
#endif
class COtherDTD : public nsIDTD
{
#ifdef _MSC_VER
#pragma warning( default : 4275 )
#endif
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDTD
/**
* Common constructor for navdtd. You probably want to call
* NS_NewNavHTMLDTD().
*
* @update gess 7/9/98
*/
COtherDTD();
/**
* Virtual destructor -- you know what to do
* @update gess 7/9/98
*/
virtual ~COtherDTD();
/**
* The following set of methods are used to partially construct
* the content model (via the sink) according to the type of token.
* @update gess5/11/98
* @param aToken is the token (of a given type) to be handled
* @return error code representing construction state; usually 0.
*/
nsresult HandleStartToken(CToken* aToken);
nsresult HandleEndToken(CToken* aToken);
nsresult HandleEntityToken(CToken* aToken);
//*************************************************
//these cover methods mimic the sink, and are used
//by the parser to manage its context-stack.
//*************************************************
protected:
nsresult CollectAttributes(nsIParserNode& aNode,eHTMLTags aTag,PRInt32 aCount);
nsresult WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsIParserNode& aNode);
nsresult DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag);
nsIParserNode* CreateNode(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsTokenAllocator* aTokenAllocator=0);
nsIHTMLContentSink* mSink;
nsDTDContext* mBodyContext;
PRInt32 mHasOpenHead;
PRPackedBool mHasOpenForm;
PRPackedBool mHasOpenMap;
PRPackedBool mHasOpenBody;
PRPackedBool mHadFrameset;
PRPackedBool mHadBody;
PRPackedBool mHasOpenScript;
PRPackedBool mEnableStrict;
nsString mFilename;
PRInt32 mLineNumber;
nsParser* mParser;
nsITokenizer* mTokenizer; // weak
nsTokenAllocator* mTokenAllocator;
nsNodeAllocator* mNodeAllocator;
eHTMLTags mSkipTarget;
nsresult mDTDState;
nsDTDMode mDTDMode;
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...
PRUint32 mComputedCRC32;
PRUint32 mExpectedCRC32;
nsString mScratch; //used for various purposes; non-persistent
eParserDocType mDocType;
};
extern nsresult NS_NewOtherHTMLDTD(nsIDTD** aInstancePtrResult);
class CTransitionalDTD : public COtherDTD
{
public:
CTransitionalDTD();
virtual ~CTransitionalDTD();
};
#endif //NS_OTHERDTD__

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,190 +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 "CParserContext.h"
#include "nsToken.h"
#include "prenv.h"
#include "nsHTMLTokenizer.h"
#include "nsExpatDriver.h"
MOZ_DECL_CTOR_COUNTER(CParserContext)
/**
* Your friendly little constructor. Ok, it's not the friendly, but the only guy
* using it is the parser.
* @update gess7/23/98
* @param aScanner
* @param aKey
* @param aListener
*/
CParserContext::CParserContext(nsScanner* aScanner,
void *aKey,
eParserCommands aCommand,
nsIRequestObserver* aListener,
nsIDTD *aDTD,
eAutoDetectResult aStatus,
PRBool aCopyUnused)
{
MOZ_COUNT_CTOR(CParserContext);
mScanner=aScanner;
mKey=aKey;
mPrevContext=0;
mListener=aListener;
NS_IF_ADDREF(mListener);
mDTDMode=eDTDMode_unknown;
mAutoDetectStatus=aStatus;
mTransferBuffer=0;
mDTD=aDTD;
NS_IF_ADDREF(mDTD);
mTokenizer = 0;
mTransferBufferSize=eTransferBufferSize;
mStreamListenerState=eNone;
mMultipart=PR_TRUE;
mContextType=eCTNone;
mCopyUnused=aCopyUnused;
mParserCommand=aCommand;
mRequest=0;
}
/**
* Your friendly little constructor. Ok, it's not the friendly, but the only guy
* using it is the parser.
* @update gess7/23/98
* @param aScanner
* @param aKey
* @param aListener
*/
CParserContext::CParserContext(const CParserContext &aContext) : mMimeType() {
MOZ_COUNT_CTOR(CParserContext);
mScanner=aContext.mScanner;
mKey=aContext.mKey;
mPrevContext=0;
mListener=aContext.mListener;
NS_IF_ADDREF(mListener);
mDTDMode=aContext.mDTDMode;
mAutoDetectStatus=aContext.mAutoDetectStatus;
mTransferBuffer=aContext.mTransferBuffer;
mDTD=aContext.mDTD;
NS_IF_ADDREF(mDTD);
mTokenizer = aContext.mTokenizer;
NS_IF_ADDREF(mTokenizer);
mTransferBufferSize=eTransferBufferSize;
mStreamListenerState=aContext.mStreamListenerState;
mMultipart=aContext.mMultipart;
mContextType=aContext.mContextType;
mRequest=aContext.mRequest;
mParserCommand=aContext.mParserCommand;
SetMimeType(aContext.mMimeType);
}
/**
* Destructor for parser context
* NOTE: DO NOT destroy the dtd here.
* @update gess7/11/98
*/
CParserContext::~CParserContext(){
MOZ_COUNT_DTOR(CParserContext);
if(mScanner) {
delete mScanner;
mScanner=nsnull;
}
if(mTransferBuffer)
delete [] mTransferBuffer;
NS_IF_RELEASE(mDTD);
NS_IF_RELEASE(mListener);
NS_IF_RELEASE(mTokenizer);
//Remember that it's ok to simply ingore the PrevContext.
}
/**
* Set's the mimetype for this context
* @update rickg 03.18.2000
*/
void CParserContext::SetMimeType(const nsACString& aMimeType){
mMimeType.Assign(aMimeType);
mDocType=ePlainText;
if(mMimeType.Equals(NS_LITERAL_CSTRING(kHTMLTextContentType)))
mDocType=eHTML_Strict;
else if (mMimeType.Equals(NS_LITERAL_CSTRING(kXMLTextContentType)) ||
mMimeType.Equals(NS_LITERAL_CSTRING(kXMLApplicationContentType)) ||
mMimeType.Equals(NS_LITERAL_CSTRING(kXHTMLApplicationContentType)) ||
mMimeType.Equals(NS_LITERAL_CSTRING(kXULTextContentType)) ||
#ifdef MOZ_SVG
mMimeType.Equals(NS_LITERAL_CSTRING(kSVGTextContentType)) ||
#endif
mMimeType.Equals(NS_LITERAL_CSTRING(kRDFTextContentType)))
mDocType=eXML;
}
nsresult
CParserContext::GetTokenizer(PRInt32 aType, nsITokenizer*& aTokenizer) {
nsresult result = NS_OK;
if(!mTokenizer) {
if (aType == NS_IPARSER_FLAG_HTML || mParserCommand == eViewSource) {
result = NS_NewHTMLTokenizer(&mTokenizer,mDTDMode,mDocType,mParserCommand);
// Propagate tokenizer state so that information is preserved
// between document.write. This fixes bug 99467
if (mTokenizer && mPrevContext)
mTokenizer->CopyState(mPrevContext->mTokenizer);
}
else if (aType == NS_IPARSER_FLAG_XML)
{
result = CallQueryInterface(mDTD, &mTokenizer);
}
}
aTokenizer = mTokenizer;
return result;
}

Просмотреть файл

@ -1,110 +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
*
*/
#ifndef __CParserContext
#define __CParserContext
#include "nsIParser.h"
#include "nsIURL.h"
#include "nsIDTD.h"
#include "nsIStreamListener.h"
#include "nsIRequest.h"
#include "nsScanner.h"
#include "nsString.h"
#include "nsCOMPtr.h"
/**
* Note that the parser is given FULL access to all
* data in a parsercontext. Hey, that what it's for!
*/
class CParserContext {
public:
enum {eTransferBufferSize=4096};
enum eContextType {eCTNone,eCTURL,eCTString,eCTStream};
CParserContext( nsScanner* aScanner,
void* aKey=0,
eParserCommands aCommand=eViewNormal,
nsIRequestObserver* aListener=0,
nsIDTD *aDTD=0,
eAutoDetectResult aStatus=eUnknownDetect,
PRBool aCopyUnused=PR_FALSE);
CParserContext( const CParserContext& aContext);
~CParserContext();
nsresult GetTokenizer(PRInt32 aType, nsITokenizer*& aTokenizer);
void SetMimeType(const nsACString& aMimeType);
nsCOMPtr<nsIRequest> mRequest; // provided by necko to differnciate different input streams
// why is mRequest strongly referenced? see bug 102376.
nsIDTD* mDTD;
nsIRequestObserver* mListener;
char* mTransferBuffer;
void* mKey;
nsITokenizer* mTokenizer;
CParserContext* mPrevContext;
nsScanner* mScanner;
nsCString mMimeType;
nsDTDMode mDTDMode;
eParserDocType mDocType;
eStreamState mStreamListenerState; //this is really only here for debug purposes.
eContextType mContextType;
eAutoDetectResult mAutoDetectStatus;
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...
PRPackedBool mMultipart;
PRPackedBool mCopyUnused;
PRUint32 mTransferBufferSize;
};
#endif

Просмотреть файл

@ -1,2 +0,0 @@
en-US.jar:
locale/en-US/communicator/layout/xmlparser.properties

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,656 +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
*
*/
#ifndef DTDUTILS_
#define DTDUTILS_
#include "nsHTMLTags.h"
#include "nsHTMLTokens.h"
#include "nsIParser.h"
#include "nsCRT.h"
#include "nsDeque.h"
#include "nsIDTD.h"
#include "nsITokenizer.h"
#include "nsString.h"
#include "nsIParserNode.h"
#include "nsFixedSizeAllocator.h"
#include "nsVoidArray.h"
#include "nsIParserService.h"
#include "nsReadableUtils.h"
#define IF_HOLD(_ptr) \
PR_BEGIN_MACRO \
if(_ptr) { \
_ptr->AddRef(); \
} \
PR_END_MACRO
// recycles _ptr
#define IF_FREE(_ptr, _allocator) \
PR_BEGIN_MACRO \
if(_ptr && _allocator) { \
_ptr->Release((_allocator)->GetArenaPool()); \
_ptr=0; \
} \
PR_END_MACRO
// release objects and destroy _ptr
#define IF_DELETE(_ptr, _allocator) \
PR_BEGIN_MACRO \
if(_ptr) { \
_ptr->ReleaseAll(_allocator); \
delete(_ptr); \
_ptr=0; \
} \
PR_END_MACRO
class nsIParserNode;
class nsCParserNode;
class nsNodeAllocator;
#ifdef DEBUG
void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* aTitle);
void DebugDumpContainmentRules2(nsIDTD& theDTD,const char* aFilename,const char* aTitle);
#endif
PRUint32 AccumulateCRC(PRUint32 crc_accum, char *data_blk_ptr, int data_blk_size);
/***************************************************************
First, define the tagstack class
***************************************************************/
class nsEntryStack; //forware declare to make compilers happy.
struct nsTagEntry {
nsTagEntry ()
: mTag(eHTMLTag_unknown), mNode(0), mParent(0), mStyles(0){}
eHTMLTags mTag; //for speedier access to tag id
nsCParserNode* mNode;
nsEntryStack* mParent;
nsEntryStack* mStyles;
};
class nsEntryStack {
public:
nsEntryStack();
~nsEntryStack();
nsTagEntry* PopEntry();
void PushEntry(nsTagEntry* aEntry, PRBool aRefCntNode = PR_TRUE);
void EnsureCapacityFor(PRInt32 aNewMax, PRInt32 aShiftOffset=0);
void Push(nsCParserNode* aNode,nsEntryStack* aStyleStack=0, PRBool aRefCntNode = PR_TRUE);
void PushFront(nsCParserNode* aNode,nsEntryStack* aStyleStack=0, PRBool aRefCntNode = PR_TRUE);
void Append(nsEntryStack *aStack);
nsCParserNode* Pop(void);
nsCParserNode* Remove(PRInt32 anIndex,eHTMLTags aTag);
nsCParserNode* NodeAt(PRInt32 anIndex) const;
eHTMLTags First() const;
eHTMLTags TagAt(PRInt32 anIndex) const;
nsTagEntry* EntryAt(PRInt32 anIndex) const;
eHTMLTags operator[](PRInt32 anIndex) const;
eHTMLTags Last() const;
void Empty(void);
/*
* Release all objects in the entry stack
*/
void ReleaseAll(nsNodeAllocator* aNodeAllocator);
/**
* Find the first instance of given tag on the stack.
* @update gess 12/14/99
* @param aTag
* @return index of tag, or kNotFound if not found
*/
inline PRInt32 FirstOf(eHTMLTags aTag) const {
PRInt32 index=-1;
if(0<mCount) {
while(++index<mCount) {
if(aTag==mEntries[index].mTag) {
return index;
}
} //while
}
return kNotFound;
}
/**
* Find the last instance of given tag on the stack.
* @update gess 12/14/99
* @param aTag
* @return index of tag, or kNotFound if not found
*/
inline PRInt32 LastOf(eHTMLTags aTag) const {
PRInt32 index=mCount;
while(--index>=0) {
if(aTag==mEntries[index].mTag) {
return index;
}
}
return kNotFound;
}
nsTagEntry* mEntries;
PRInt32 mCount;
PRInt32 mCapacity;
};
/**********************************************************
The table state class is used to store info about each
table that is opened on the stack. As tables open and
close on the context, we update these objects to track
what has/hasn't been seen on a per table basis.
**********************************************************/
class CTableState {
public:
CTableState(CTableState *aPreviousState=0) {
mHasCaption=PR_FALSE;
mHasCols=PR_FALSE;
mHasTHead=PR_FALSE;
mHasTFoot=PR_FALSE;
mHasTBody=PR_FALSE;
mPrevious=aPreviousState;
}
PRBool CanOpenCaption() {
PRBool result=!(mHasCaption || mHasCols || mHasTHead || mHasTFoot || mHasTBody);
return result;
}
PRBool CanOpenCols() {
PRBool result=!(mHasCols || mHasTHead || mHasTFoot || mHasTBody);
return result;
}
PRBool CanOpenTBody() {
PRBool result=!(mHasTBody);
return result;
}
PRBool CanOpenTHead() {
PRBool result=!(mHasTHead || mHasTFoot || mHasTBody);
return result;
}
PRBool CanOpenTFoot() {
PRBool result=!(mHasTFoot || mHasTBody);
return result;
}
PRPackedBool mHasCaption;
PRPackedBool mHasCols;
PRPackedBool mHasTHead;
PRPackedBool mHasTFoot;
PRPackedBool mHasTBody;
CTableState *mPrevious;
};
#ifdef DEBUG
//used for named entities and counters (XXX debug only)
class CNamedEntity {
public:
CNamedEntity(const nsAString& aName,const nsAString& aValue) : mName(), mValue() {
PRUnichar theFirst=aName.First();
PRUnichar theLast=aName.Last();
PRInt32 theLen=aName.Length();
if((2<theLen) && (theFirst==theLast) && (kQuote==theFirst)) {
mName = Substring(aName, 1, theLen - 2);
}
else mName=aName;
theFirst=aValue.First();
theLast=aValue.Last();
theLen=aValue.Length();
if((2<theLen) && (theFirst==theLast) && (kQuote==theFirst)) {
mValue = Substring(aValue, 1, theLen - 2);
}
else mValue=aValue;
}
nsString mName;
nsString mValue;
PRInt32 mOrdinal;
};
#endif
/************************************************************************
nsTokenAllocator class implementation.
This class is used to recycle tokens.
By using this simple class, we cut WAY down on the number of tokens
that get created during the run of the system.
Note: The allocator is created per document. It's been shared
( but not ref. counted ) by objects, tokenizer,dtd,and dtd context,
that cease to exist when the document is destroyed.
************************************************************************/
class nsTokenAllocator {
public:
nsTokenAllocator();
virtual ~nsTokenAllocator();
virtual CToken* CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag, const nsAString& aString);
virtual CToken* CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag);
nsFixedSizeAllocator& GetArenaPool() { return mArenaPool; }
protected:
nsFixedSizeAllocator mArenaPool;
#ifdef NS_DEBUG
int mTotals[eToken_last-1];
#endif
};
/************************************************************************
CNodeRecycler class implementation.
This class is used to recycle nodes.
By using this simple class, we cut down on the number of nodes
that get created during the run of the system.
************************************************************************/
#ifndef HEAP_ALLOCATED_NODES
class nsCParserNode;
#endif
class nsNodeAllocator {
public:
nsNodeAllocator();
virtual ~nsNodeAllocator();
virtual nsCParserNode* CreateNode(CToken* aToken=nsnull, nsTokenAllocator* aTokenAllocator=0);
nsFixedSizeAllocator& GetArenaPool() { return mNodePool; }
#ifdef HEAP_ALLOCATED_NODES
void Recycle(nsCParserNode* aNode) { mSharedNodes.Push(NS_STATIC_CAST(void*,aNode)); }
protected:
nsDeque mSharedNodes;
#ifdef DEBUG_TRACK_NODES
PRInt32 mCount;
#endif
#endif
protected:
nsFixedSizeAllocator mNodePool;
};
/************************************************************************
The dtdcontext class defines an ordered list of tags (a context).
************************************************************************/
class nsDTDContext {
public:
nsDTDContext();
~nsDTDContext();
nsTagEntry* PopEntry();
void PushEntry(nsTagEntry* aEntry, PRBool aRefCntNode = PR_TRUE);
void MoveEntries(nsDTDContext& aDest, PRInt32 aCount);
void Push(nsCParserNode* aNode,nsEntryStack* aStyleStack=0, PRBool aRefCntNode = PR_TRUE);
nsCParserNode* Pop(nsEntryStack*& aChildStack);
nsCParserNode* Pop();
nsCParserNode* PeekNode() { return mStack.NodeAt(mStack.mCount-1); }
eHTMLTags First(void) const;
eHTMLTags Last(void) const;
nsTagEntry* LastEntry(void) const;
eHTMLTags TagAt(PRInt32 anIndex) const;
eHTMLTags operator[](PRInt32 anIndex) const {return TagAt(anIndex);}
PRBool HasOpenContainer(eHTMLTags aTag) const;
PRInt32 FirstOf(eHTMLTags aTag) const {return mStack.FirstOf(aTag);}
PRInt32 LastOf(eHTMLTags aTag) const {return mStack.LastOf(aTag);}
void Empty(void);
PRInt32 GetCount(void) {return mStack.mCount;}
PRInt32 GetResidualStyleCount(void) {return mResidualStyleCount;}
nsEntryStack* GetStylesAt(PRInt32 anIndex) const;
void PushStyle(nsCParserNode* aNode);
void PushStyles(nsEntryStack *aStyles);
nsCParserNode* PopStyle(void);
nsCParserNode* PopStyle(eHTMLTags aTag);
void RemoveStyle(eHTMLTags aTag);
static void ReleaseGlobalObjects(void);
void SetTokenAllocator(nsTokenAllocator* aTokenAllocator) { mTokenAllocator=aTokenAllocator; }
void SetNodeAllocator(nsNodeAllocator* aNodeAllocator) { mNodeAllocator=aNodeAllocator; }
nsEntryStack mStack; //this will hold a list of tagentries...
PRInt32 mResidualStyleCount;
PRInt32 mContextTopIndex;
//break this struct out separately so that lame compilers don't gack.
//By using these bits instead of bools, we have a bit-o-memory.
struct CFlags {
PRUint8 mHadBody:1;
PRUint8 mHadFrameset:1;
PRUint8 mHasOpenHead:1;
PRUint8 mTransitional:1;
};
union {
PRUint32 mAllBits;
CFlags mFlags;
};
nsTokenAllocator *mTokenAllocator;
nsNodeAllocator *mNodeAllocator;
CTableState *mTableStates;
nsDeque mEntities;
#ifdef NS_DEBUG
enum { eMaxTags = 100 };
eHTMLTags mXTags[eMaxTags];
PRInt32 *mCounters;
void ResetCounters(void);
void AllocateCounters(void);
PRInt32 IncrementCounter(eHTMLTags aTag,nsIParserNode& aNode,nsString& aResult);
CNamedEntity* RegisterEntity(const nsAString& aName,const nsAString& aValue);
CNamedEntity* GetEntity(const nsAString& aName) const;
#endif
};
/**************************************************************
Now define the token deallocator class...
**************************************************************/
class CTokenDeallocator: public nsDequeFunctor{
protected:
nsFixedSizeAllocator& mArenaPool;
public:
CTokenDeallocator(nsFixedSizeAllocator& aArenaPool)
: mArenaPool(aArenaPool) {}
virtual void* operator()(void* anObject) {
CToken* aToken = (CToken*)anObject;
CToken::Destroy(aToken, mArenaPool);
return 0;
}
};
/************************************************************************
ITagHandler class offers an API for taking care of specific tokens.
************************************************************************/
class nsITagHandler {
public:
virtual void SetString(const nsString &aTheString)=0;
virtual nsString* GetString()=0;
virtual PRBool HandleToken(CToken* aToken,nsIDTD* aDTD)=0;
virtual PRBool HandleCapturedTokens(CToken* aToken,nsIDTD* aDTD)=0;
};
/************************************************************************
Here are a few useful utility methods...
************************************************************************/
/**
* This method quickly scans the given set of tags,
* looking for the given tag.
* @update gess8/27/98
* @param aTag -- tag to be search for in set
* @param aTagSet -- set of tags to be searched
* @return
*/
inline PRInt32 IndexOfTagInSet(PRInt32 aTag,const eHTMLTags* aTagSet,PRInt32 aCount) {
const eHTMLTags* theEnd=aTagSet+aCount;
const eHTMLTags* theTag=aTagSet;
while(theTag<theEnd) {
if(aTag==*theTag) {
return theTag-aTagSet;
}
++theTag;
}
return kNotFound;
}
/**
* This method quickly scans the given set of tags,
* looking for the given tag.
* @update gess8/27/98
* @param aTag -- tag to be search for in set
* @param aTagSet -- set of tags to be searched
* @return
*/
inline PRBool FindTagInSet(PRInt32 aTag,const eHTMLTags *aTagSet,PRInt32 aCount) {
return PRBool(-1<IndexOfTagInSet(aTag,aTagSet,aCount));
}
/**
* Called from various DTD's to determine the type of data in the buffer...
* @update gess 06Jun2000
* @param aBuffer: contains a string with first block of html from source document
* @param aHasXMLFragment: tells us whether we detect XML in the buffer (based on PI)
* @return TRUE if we find HTML
*/
// This really doesn't need to be inline!
inline PRBool BufferContainsHTML(const nsString& aBuffer,
PRBool& aHasXMLFragment)
{
PRBool result=PR_FALSE;
aHasXMLFragment=PRBool(-1!=aBuffer.Find("<?XML",PR_TRUE,100));
PRInt32 theDocTypePos=aBuffer.Find("DOCTYPE",PR_TRUE,0,200);
if(-1!=theDocTypePos) {
PRInt32 theHTMLPos=aBuffer.Find("HTML",PR_TRUE,theDocTypePos+8,200);
if(-1==theHTMLPos) {
theHTMLPos=aBuffer.Find("ISO/IEC 15445",PR_TRUE,theDocTypePos+8,200);
if(-1==theHTMLPos) {
theHTMLPos=aBuffer.Find("HYPERTEXT MARKUP",PR_TRUE,theDocTypePos+8,200);
}
}
result=PRBool(-1!=theHTMLPos);
}
else {
//worst case scenario: let's look for a few HTML tags...
PRInt32 theCount = 0;
PRInt32 theTagCount = 0;
nsAString::const_iterator iter, end;
aBuffer.BeginReading(iter);
aBuffer.EndReading(end);
if (Distance(iter, end) > 200) {
end = iter;
end.advance(200);
}
for(theCount = 0; theCount < 5; ++theCount) {
if (!FindCharInReadable('<', iter, end)) {
break;
}
// we found what may be a start tag...
++iter; // step over the '<' character
nsAString::const_iterator tag_end(iter);
aBuffer.EndReading(end);
while (tag_end != end) {
const PRUnichar c = *tag_end;
if (c == ' ' || c == '>' || c == '"') {
break;
}
++tag_end;
}
nsHTMLTag theTag = nsHTMLTags::LookupTag(Substring(iter, tag_end));
if (theTag != eHTMLTag_userdefined) {
++theTagCount;
}
iter = tag_end;
}
// Claim HTML if we find at least 2 real html tags...
result = (2 <= theTagCount);
}
return result;
}
/******************************************************************************
This little structure is used to compute CRC32 values for our debug validator
******************************************************************************/
struct CRCStruct {
CRCStruct(eHTMLTags aTag,PRInt32 anOp) {mTag=aTag; mOperation=anOp;}
eHTMLTags mTag;
PRInt32 mOperation; //usually open or close
};
/**************************************************************
This defines the topic object used by the observer service.
The observerService uses a list of these, 1 per topic when
registering tags.
**************************************************************/
class nsObserverEntry : public nsIObserverEntry {
public:
NS_DECL_ISUPPORTS
nsObserverEntry(const nsAString& aString);
virtual ~nsObserverEntry();
NS_IMETHOD Notify(nsIParserNode* aNode,
nsIParser* aParser,
nsISupports* aWebShell,
const PRUint32 aFlags);
nsresult AddObserver(nsIElementObserver* aObserver,eHTMLTags aTag);
void RemoveObserver(nsIElementObserver* aObserver);
PRBool Matches(const nsAString& aTopic);
protected:
nsAutoString mTopic; // This will rarely be empty, so make it an auto string
nsVoidArray* mObservers[NS_HTML_TAG_MAX + 1];
friend class nsMatchesTopic;
};
/*********************************************************************************************/
struct TagList {
PRUint32 mCount;
const eHTMLTags *mTags;
};
/**
* Find the last member of given taglist on the given context
* @update gess 12/14/99
* @param aContext
* @param aTagList
* @return index of tag, or kNotFound if not found
*/
inline PRInt32 LastOf(nsDTDContext& aContext, const TagList& aTagList){
int max = aContext.GetCount();
int index;
for(index=max-1;index>=0;index--){
PRBool result=FindTagInSet(aContext[index],aTagList.mTags,aTagList.mCount);
if(result) {
return index;
}
}
return kNotFound;
}
/**
* Find the first member of given taglist on the given context
* @update gess 12/14/99
* @param aContext
* @param aStartOffset
* @param aTagList
* @return index of tag, or kNotFound if not found
*/
inline PRInt32 FirstOf(nsDTDContext& aContext,PRInt32 aStartOffset,TagList& aTagList){
int max = aContext.GetCount();
int index;
for(index=aStartOffset;index<max;++index){
PRBool result=FindTagInSet(aContext[index],aTagList.mTags,aTagList.mCount);
if(result) {
return index;
}
}
return kNotFound;
}
/**
* Call this to find out whether the DTD thinks the tag requires an END tag </xxx>
* @update gess 01/04/99
* @param id of tag
* @return TRUE of the element's end tag is optional
*/
inline PRBool HasOptionalEndTag(eHTMLTags aTag) {
static eHTMLTags gHasOptionalEndTags[]={eHTMLTag_body,eHTMLTag_colgroup,eHTMLTag_dd,eHTMLTag_dt,
eHTMLTag_head,eHTMLTag_li,eHTMLTag_option,
eHTMLTag_p,eHTMLTag_tbody,eHTMLTag_td,eHTMLTag_tfoot,
eHTMLTag_th,eHTMLTag_thead,eHTMLTag_tr,
eHTMLTag_userdefined,eHTMLTag_unknown};
return FindTagInSet(aTag,gHasOptionalEndTags,sizeof(gHasOptionalEndTags)/sizeof(eHTMLTag_body));
}
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,277 +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
*
*/
#ifndef _NSELEMENTABLE
#define _NSELEMENTABLE
#include "nsHTMLTokens.h"
#include "nsDTDUtils.h"
//*********************************************************************************************
// The following ints define the standard groups of HTML elements...
//*********************************************************************************************
static const int kNone= 0x0;
static const int kHTMLContent = 0x0001; // HEAD, (FRAMESET | BODY)
static const int kHeadContent = 0x0002; // TITLE, ISINDEX, BASE
static const int kHeadMisc = 0x0004; // SCRIPT, STYLE, META, LINK, OBJECT
static const int kSpecial = 0x0008; // A, IMG, APPLET, OBJECT, FONT, BASEFONT, BR, SCRIPT,
// MAP, Q, SUB, SUP, SPAN, BDO, IFRAME
static const int kFormControl = 0x0010; // INPUT SELECT TEXTAREA LABEL BUTTON
static const int kPreformatted = 0x0020; // PRE
static const int kPreExclusion = 0x0040; // IMG, OBJECT, APPLET, BIG, SMALL, SUB, SUP, FONT, BASEFONT
static const int kFontStyle = 0x0080; // TT, I, B, U, S, STRIKE, BIG, SMALL, BLINK
static const int kPhrase = 0x0100; // EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM
static const int kHeading = 0x0200; // H1..H6
static const int kBlockMisc = 0x0400; // OBJECT, SCRIPT
static const int kBlock = 0x0800; // ADDRESS, BLOCKQUOTE, CENTER, DIV, DL, FIELDSET, FORM,
// ISINDEX, HR, NOSCRIPT, NOFRAMES, P, TABLE
static const int kList = 0x1000; // UL, OL, DIR, MENU
static const int kPCDATA = 0x2000; // plain text and entities...
static const int kSelf = 0x4000; // whatever THIS tag is...
static const int kExtensions = 0x8000; // BGSOUND, WBR, NOBR
static const int kTable = 0x10000;// TR,TD,THEAD,TBODY,TFOOT,CAPTION,TH
static const int kDLChild = 0x20000;// DL, DT
static const int kCDATA = 0x40000;// just plain text...
static const int kInlineEntity = (kPCDATA|kFontStyle|kPhrase|kSpecial|kFormControl|kExtensions); // #PCDATA, %fontstyle, %phrase, %special, %formctrl
static const int kBlockEntity = (kHeading|kList|kPreformatted|kBlock); // %heading, %list, %preformatted, %block
static const int kFlowEntity = (kBlockEntity|kInlineEntity); // %blockentity, %inlineentity
static const int kAllTags = 0xffffff;
//*********************************************************************************************
// The following ints define the standard groups of HTML elements...
//*********************************************************************************************
extern void InitializeElementTable(void);
extern void DeleteElementTable(void);
typedef PRBool (*ContainFunc)(eHTMLTags aTag,nsDTDContext &aContext);
/**
* We're asking the question: is aTest a member of bitset.
*
* @update gess 01/04/99
* @param
* @return TRUE or FALSE
*/
inline PRBool TestBits(int aBitset,int aTest) {
if(aTest) {
PRInt32 result=(aBitset & aTest);
return PRBool(result==aTest);
}
return PR_FALSE;
}
/**
*
* @update gess 01/04/99
* @param
* @return
*/
struct nsHTMLElement {
#ifdef DEBUG
static void DebugDumpMembership(const char* aFilename);
static void DebugDumpContainment(const char* aFilename,const char* aTitle);
static void DebugDumpContainType(const char* aFilename);
#endif
static PRBool IsInlineEntity(eHTMLTags aTag);
static PRBool IsFlowEntity(eHTMLTags aTag);
static PRBool IsBlockCloser(eHTMLTags aTag);
inline PRBool IsBlock(void) {
if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
return TestBits(mParentBits,kBlock);
}
return PR_FALSE;
}
inline PRBool IsBlockEntity(void) {
if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
return TestBits(mParentBits,kBlockEntity);
}
return PR_FALSE;
}
inline PRBool IsSpecialEntity(void) {
if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
return TestBits(mParentBits,kSpecial);
}
return PR_FALSE;
}
inline PRBool IsPhraseEntity(void) {
if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
return TestBits(mParentBits,kPhrase);
}
return PR_FALSE;
}
inline PRBool IsFontStyleEntity(void) {
if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
return TestBits(mParentBits,kFontStyle);
}
return PR_FALSE;
}
inline PRBool IsTableElement(void) { //return yes if it's a table or child of a table...
PRBool result=PR_FALSE;
switch(mTagID) {
case eHTMLTag_table:
case eHTMLTag_thead:
case eHTMLTag_tbody:
case eHTMLTag_tfoot:
case eHTMLTag_caption:
case eHTMLTag_tr:
case eHTMLTag_td:
case eHTMLTag_th:
case eHTMLTag_col:
case eHTMLTag_colgroup:
result=PR_TRUE;
break;
default:
result=PR_FALSE;
}
return result;
}
static int GetSynonymousGroups(eHTMLTags aTag);
static PRInt32 GetIndexOfChildOrSynonym(nsDTDContext& aContext,eHTMLTags aChildTag);
const TagList* GetSynonymousTags(void) const {return mSynonymousTags;}
const TagList* GetRootTags(void) const {return mRootNodes;}
const TagList* GetEndRootTags(void) const {return mEndRootNodes;}
const TagList* GetAutoCloseStartTags(void) const {return mAutocloseStart;}
const TagList* GetAutoCloseEndTags(void) const {return mAutocloseEnd;}
eHTMLTags GetCloseTargetForEndTag(nsDTDContext& aContext,PRInt32 anIndex,nsDTDMode aMode) const;
const TagList* GetSpecialChildren(void) const {return mSpecialKids;}
const TagList* GetSpecialParents(void) const {return mSpecialParents;}
PRBool IsMemberOf(PRInt32 aType) const;
PRBool ContainsSet(PRInt32 aType) const;
PRBool CanContainType(PRInt32 aType) const;
eHTMLTags GetTag(void) const {return mTagID;}
PRBool CanContain(eHTMLTags aChild,nsDTDMode aMode) const;
PRBool CanExclude(eHTMLTags aChild) const;
PRBool CanOmitStartTag(eHTMLTags aChild) const;
PRBool CanOmitEndTag(void) const;
PRBool CanContainSelf(void) const;
PRBool CanAutoCloseTag(nsDTDContext& aContext,eHTMLTags aTag) const;
PRBool HasSpecialProperty(PRInt32 aProperty) const;
PRBool IsSpecialParent(eHTMLTags aTag) const;
PRBool IsExcludableParent(eHTMLTags aParent) const;
PRBool SectionContains(eHTMLTags aTag,PRBool allowDepthSearch);
PRBool ShouldVerifyHierarchy();
PRBool CanBeContained(eHTMLTags aParentTag,nsDTDContext &aContext); //default version
static PRBool CanContain(eHTMLTags aParent,eHTMLTags aChild,nsDTDMode aMode);
static PRBool IsContainer(eHTMLTags aTag) ;
static PRBool IsResidualStyleTag(eHTMLTags aTag) ;
static PRBool IsTextTag(eHTMLTags aTag);
static PRBool IsWhitespaceTag(eHTMLTags aTag);
static PRBool IsBlockParent(eHTMLTags aTag);
static PRBool IsInlineParent(eHTMLTags aTag);
static PRBool IsFlowParent(eHTMLTags aTag);
static PRBool IsSectionTag(eHTMLTags aTag);
static PRBool IsChildOfHead(eHTMLTags aTag,PRBool& aExclusively) ;
eHTMLTags mTagID;
eHTMLTags mRequiredAncestor;
eHTMLTags mExcludingAncestor; //If set, the presence of the excl-ancestor prevents this from opening.
const TagList* mRootNodes; //These are the tags above which you many not autoclose a START tag
const TagList* mEndRootNodes; //These are the tags above which you many not autoclose an END tag
const TagList* mAutocloseStart; //these are the start tags that you can automatically close with this START tag
const TagList* mAutocloseEnd; //these are the start tags that you can automatically close with this END tag
const TagList* mSynonymousTags; //These are morally equivalent; an end tag for one can close a start tag for another (like <Hn>)
const TagList* mExcludableParents; //These are the TAGS that cannot contain you
int mParentBits; //defines groups that can contain this element
int mInclusionBits; //defines parental and containment rules
int mExclusionBits; //defines things you CANNOT contain
int mSpecialProperties; //used for various special purposes...
PRUint32 mPropagateRange; //tells us how far a parent is willing to prop. badly formed children
const TagList* mSpecialParents; //These are the special tags that contain this tag (directly)
const TagList* mSpecialKids; //These are the extra things you can contain
eHTMLTags mSkipTarget; //If set, then we skip all content until this tag is seen
ContainFunc mCanBeContained;
};
extern nsHTMLElement* gHTMLElements;
//special property bits...
static const int kDiscardTag = 0x0001; //tells us to toss this tag
static const int kOmitEndTag = 0x0002; //safely ignore end tag
static const int kLegalOpen = 0x0004; //Lets BODY, TITLE, SCRIPT to reopen
static const int kNoPropagate = 0x0008; //If set, this tag won't propagate as a child
static const int kBadContentWatch = 0x0010;
static const int kNoStyleLeaksIn = 0x0020;
static const int kNoStyleLeaksOut = 0x0040;
static const int kMustCloseSelf = 0x0080;
static const int kSaveMisplaced = 0x0100; //If set, then children this tag can't contain are pushed onto the misplaced stack
static const int kNonContainer = 0x0200; //If set, then this tag is not a container.
static const int kHandleStrayTag = 0x0400; //If set, we automatically open a start tag
static const int kRequiresBody = 0x0800; //If set, then in case of no BODY one will be opened up immediately.
static const int kVerifyHierarchy = 0x1000; //If set, check to see if the tag is a child or a sibling..
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,107 +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 ***** */
#ifndef NS_EXPAT_DRIVER__
#define NS_EXPAT_DRIVER__
#include "xmlparse.h"
#include "nsString.h"
#include "nsIDTD.h"
#include "nsITokenizer.h"
#include "nsIInputStream.h"
class nsIExpatSink;
struct nsCatalogData;
class nsExpatDriver : public nsIDTD,
public nsITokenizer
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDTD
NS_DECL_NSITOKENIZER
nsExpatDriver();
virtual ~nsExpatDriver();
int HandleExternalEntityRef(const PRUnichar *openEntityNames,
const PRUnichar *base,
const PRUnichar *systemId,
const PRUnichar *publicId);
nsresult HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts);
nsresult HandleEndElement(const PRUnichar *aName);
nsresult HandleCharacterData(const PRUnichar *aCData, const PRUint32 aLength);
nsresult HandleComment(const PRUnichar *aName);
nsresult HandleProcessingInstruction(const PRUnichar *aTarget, const PRUnichar *aData);
nsresult HandleXMLDeclaration(const PRUnichar *aData, const PRUint32 aLength);
nsresult HandleDefault(const PRUnichar *aData, const PRUint32 aLength);
nsresult HandleStartCdataSection();
nsresult HandleEndCdataSection();
nsresult HandleStartDoctypeDecl();
nsresult HandleEndDoctypeDecl();
protected:
// Load up an external stream to get external entity information
nsresult OpenInputStreamFromExternalDTD(const PRUnichar* aFPIStr,
const PRUnichar* aURLStr,
const PRUnichar* aBaseURL,
nsIInputStream** in,
nsAString& aAbsURL);
nsresult ParseBuffer(const char* aBuffer, PRUint32 aLength, PRBool aIsFinal);
nsresult HandleError(const char *aBuffer, PRUint32 aLength, PRBool aIsFinal);
void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString& aLine);
XML_Parser mExpatParser;
nsString mLastLine;
nsString mCDataText;
nsString mDoctypeText;
PRPackedBool mInCData;
PRPackedBool mInDoctype;
PRPackedBool mInExternalDTD;
PRPackedBool mHandledXMLDeclaration;
PRInt32 mBytePosition;
nsresult mInternalState;
PRUint32 mBytesParsed;
nsIExpatSink* mSink;
const nsCatalogData* mCatalogData; // weak
};
nsresult NS_NewExpatDriver(nsIDTD** aDriver);
#endif

Просмотреть файл

@ -1,280 +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 Communicator client 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 "nsHTMLEntities.h"
#include "nsString.h"
#include "nsCRT.h"
#include "prtypes.h"
#include "pldhash.h"
struct EntityNode {
const char* mStr; // never owns buffer
PRInt32 mUnicode;
};
struct EntityNodeEntry : public PLDHashEntryHdr
{
const EntityNode* node;
};
PR_STATIC_CALLBACK(const void*)
getStringKey(PLDHashTable*, PLDHashEntryHdr* aHdr)
{
const EntityNodeEntry* entry = NS_STATIC_CAST(const EntityNodeEntry*, aHdr);
return entry->node->mStr;
}
PR_STATIC_CALLBACK(const void*)
getUnicodeKey(PLDHashTable*, PLDHashEntryHdr* aHdr)
{
const EntityNodeEntry* entry = NS_STATIC_CAST(const EntityNodeEntry*, aHdr);
return NS_INT32_TO_PTR(entry->node->mUnicode);
}
PR_STATIC_CALLBACK(PRBool)
matchNodeString(PLDHashTable*, const PLDHashEntryHdr* aHdr,
const void* key)
{
const EntityNodeEntry* entry = NS_STATIC_CAST(const EntityNodeEntry*, aHdr);
const char* str = NS_STATIC_CAST(const char*, key);
return (nsCRT::strcmp(entry->node->mStr, str) == 0);
}
PR_STATIC_CALLBACK(PRBool)
matchNodeUnicode(PLDHashTable*, const PLDHashEntryHdr* aHdr,
const void* key)
{
const EntityNodeEntry* entry = NS_STATIC_CAST(const EntityNodeEntry*, aHdr);
const PRInt32 ucode = NS_PTR_TO_INT32(key);
return (entry->node->mUnicode == ucode);
}
PR_STATIC_CALLBACK(PLDHashNumber)
hashUnicodeValue(PLDHashTable*, const void* key)
{
// key is actually the unicode value
return PLDHashNumber(NS_PTR_TO_INT32(key));
}
static const PLDHashTableOps EntityToUnicodeOps = {
PL_DHashAllocTable,
PL_DHashFreeTable,
getStringKey,
PL_DHashStringKey,
matchNodeString,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PL_DHashFinalizeStub,
nsnull,
};
static const PLDHashTableOps UnicodeToEntityOps = {
PL_DHashAllocTable,
PL_DHashFreeTable,
getUnicodeKey,
hashUnicodeValue,
matchNodeUnicode,
PL_DHashMoveEntryStub,
PL_DHashClearEntryStub,
PL_DHashFinalizeStub,
nsnull,
};
static PLDHashTable gEntityToUnicode = { 0 };
static PLDHashTable gUnicodeToEntity = { 0 };
static nsrefcnt gTableRefCnt = 0;
#define HTML_ENTITY(_name, _value) { #_name, _value },
static const EntityNode gEntityArray[] = {
#include "nsHTMLEntityList.h"
};
#undef HTML_ENTITY
#define NS_HTML_ENTITY_COUNT ((PRInt32)NS_ARRAY_LENGTH(gEntityArray))
nsresult
nsHTMLEntities::AddRefTable(void)
{
if (!gTableRefCnt) {
if (!PL_DHashTableInit(&gEntityToUnicode, &EntityToUnicodeOps,
nsnull, sizeof(EntityNodeEntry),
PRUint32(NS_HTML_ENTITY_COUNT / 0.75))) {
gEntityToUnicode.ops = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
if (!PL_DHashTableInit(&gUnicodeToEntity, &UnicodeToEntityOps,
nsnull, sizeof(EntityNodeEntry),
PRUint32(NS_HTML_ENTITY_COUNT / 0.75))) {
PL_DHashTableFinish(&gEntityToUnicode);
gEntityToUnicode.ops = gUnicodeToEntity.ops = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
for (const EntityNode *node = gEntityArray,
*node_end = gEntityArray + NS_ARRAY_LENGTH(gEntityArray);
node < node_end; ++node) {
// add to Entity->Unicode table
EntityNodeEntry* entry =
NS_STATIC_CAST(EntityNodeEntry*,
PL_DHashTableOperate(&gEntityToUnicode,
node->mStr,
PL_DHASH_ADD));
NS_ASSERTION(entry, "Error adding an entry");
// Prefer earlier entries when we have duplication.
if (!entry->node)
entry->node = node;
// add to Unicode->Entity table
entry = NS_STATIC_CAST(EntityNodeEntry*,
PL_DHashTableOperate(&gUnicodeToEntity,
NS_INT32_TO_PTR(node->mUnicode),
PL_DHASH_ADD));
NS_ASSERTION(entry, "Error adding an entry");
// Prefer earlier entries when we have duplication.
if (!entry->node)
entry->node = node;
}
}
++gTableRefCnt;
return NS_OK;
}
void
nsHTMLEntities::ReleaseTable(void)
{
if (--gTableRefCnt != 0)
return;
if (gEntityToUnicode.ops) {
PL_DHashTableFinish(&gEntityToUnicode);
gEntityToUnicode.ops = nsnull;
}
if (gUnicodeToEntity.ops) {
PL_DHashTableFinish(&gUnicodeToEntity);
gUnicodeToEntity.ops = nsnull;
}
}
PRInt32
nsHTMLEntities::EntityToUnicode(const nsCString& aEntity)
{
NS_ASSERTION(gEntityToUnicode.ops, "no lookup table, needs addref");
if (!gEntityToUnicode.ops)
return -1;
//this little piece of code exists because entities may or may not have the terminating ';'.
//if we see it, strip if off for this test...
if(';'==aEntity.Last()) {
nsCAutoString temp(aEntity);
temp.Truncate(aEntity.Length()-1);
return EntityToUnicode(temp);
}
EntityNodeEntry* entry =
NS_STATIC_CAST(EntityNodeEntry*,
PL_DHashTableOperate(&gEntityToUnicode, aEntity.get(), PL_DHASH_LOOKUP));
if (!entry || PL_DHASH_ENTRY_IS_FREE(entry))
return -1;
return entry->node->mUnicode;
}
PRInt32
nsHTMLEntities::EntityToUnicode(const nsAString& aEntity) {
nsCAutoString theEntity; theEntity.AssignWithConversion(aEntity);
if(';'==theEntity.Last()) {
theEntity.Truncate(theEntity.Length()-1);
}
return EntityToUnicode(theEntity);
}
const char*
nsHTMLEntities::UnicodeToEntity(PRInt32 aUnicode)
{
NS_ASSERTION(gUnicodeToEntity.ops, "no lookup table, needs addref");
EntityNodeEntry* entry =
NS_STATIC_CAST(EntityNodeEntry*,
PL_DHashTableOperate(&gUnicodeToEntity, NS_INT32_TO_PTR(aUnicode), PL_DHASH_LOOKUP));
if (!entry || PL_DHASH_ENTRY_IS_FREE(entry))
return nsnull;
return entry->node->mStr;
}
#ifdef NS_DEBUG
#include <stdio.h>
class nsTestEntityTable {
public:
nsTestEntityTable() {
PRInt32 value;
nsHTMLEntities::AddRefTable();
// Make sure we can find everything we are supposed to
for (int i = 0; i < NS_HTML_ENTITY_COUNT; ++i) {
nsAutoString entity; entity.AssignWithConversion(gEntityArray[i].mStr);
value = nsHTMLEntities::EntityToUnicode(entity);
NS_ASSERTION(value != -1, "can't find entity");
NS_ASSERTION(value == gEntityArray[i].mUnicode, "bad unicode value");
entity.AssignWithConversion(nsHTMLEntities::UnicodeToEntity(value));
NS_ASSERTION(entity.EqualsWithConversion(gEntityArray[i].mStr), "bad entity name");
}
// Make sure we don't find things that aren't there
value = nsHTMLEntities::EntityToUnicode(nsCAutoString("@"));
NS_ASSERTION(value == -1, "found @");
value = nsHTMLEntities::EntityToUnicode(nsCAutoString("zzzzz"));
NS_ASSERTION(value == -1, "found zzzzz");
nsHTMLEntities::ReleaseTable();
}
};
//nsTestEntityTable validateEntityTable;
#endif

Просмотреть файл

@ -1,67 +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 Communicator client 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 ***** */
#ifndef nsHTMLEntities_h___
#define nsHTMLEntities_h___
#include "nsString.h"
class nsHTMLEntities {
public:
static nsresult AddRefTable(void);
static void ReleaseTable(void);
/**
* Translate an entity string into it's unicode value. This call
* returns -1 if the entity cannot be mapped. Note that the string
* passed in must NOT have the leading "&" nor the trailing ";"
* in it.
*/
static PRInt32 EntityToUnicode(const nsAString& aEntity);
static PRInt32 EntityToUnicode(const nsCString& aEntity);
/**
* Translate a unicode value into an entity string. This call
* returns null if the entity cannot be mapped.
* Note that the string returned DOES NOT have the leading "&" nor
* the trailing ";" in it.
*/
static const char* UnicodeToEntity(PRInt32 aUnicode);
};
#endif /* nsHTMLEntities_h___ */

Просмотреть файл

@ -1,333 +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) 1999
* 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 ***** */
/******
This file contains the list of all HTML entities
See nsHTMLEntities.h for access to the enum values for entities
It is designed to be used as inline input to nsHTMLEntities.cpp *only*
through the magic of C preprocessing.
All entires must be enclosed in the macro HTML_ENTITY which will have cruel
and unusual things done to it
It is recommended (but not strictly necessary) to keep all entries
in alphabetical order
The first argument to HTML_ENTITY is the string value of the entity
The second argument it HTML_ENTITY is the unicode value of the entity
******/
// ISO 8859-1 entities.
// See the HTML4.0 spec for this list in it's DTD form
HTML_ENTITY(nbsp, 160)
HTML_ENTITY(iexcl, 161)
HTML_ENTITY(cent, 162)
HTML_ENTITY(pound, 163)
HTML_ENTITY(curren, 164)
HTML_ENTITY(yen, 165)
HTML_ENTITY(brvbar, 166)
HTML_ENTITY(sect, 167)
HTML_ENTITY(uml, 168)
HTML_ENTITY(copy, 169)
HTML_ENTITY(ordf, 170)
HTML_ENTITY(laquo, 171)
HTML_ENTITY(not, 172)
HTML_ENTITY(shy, 173)
HTML_ENTITY(reg, 174)
HTML_ENTITY(macr, 175)
HTML_ENTITY(deg, 176)
HTML_ENTITY(plusmn, 177)
HTML_ENTITY(sup2, 178)
HTML_ENTITY(sup3, 179)
HTML_ENTITY(acute, 180)
HTML_ENTITY(micro, 181)
HTML_ENTITY(para, 182)
HTML_ENTITY(middot, 183)
HTML_ENTITY(cedil, 184)
HTML_ENTITY(sup1, 185)
HTML_ENTITY(ordm, 186)
HTML_ENTITY(raquo, 187)
HTML_ENTITY(frac14, 188)
HTML_ENTITY(frac12, 189)
HTML_ENTITY(frac34, 190)
HTML_ENTITY(iquest, 191)
HTML_ENTITY(Agrave, 192)
HTML_ENTITY(Aacute, 193)
HTML_ENTITY(Acirc, 194)
HTML_ENTITY(Atilde, 195)
HTML_ENTITY(Auml, 196)
HTML_ENTITY(Aring, 197)
HTML_ENTITY(AElig, 198)
HTML_ENTITY(Ccedil, 199)
HTML_ENTITY(Egrave, 200)
HTML_ENTITY(Eacute, 201)
HTML_ENTITY(Ecirc, 202)
HTML_ENTITY(Euml, 203)
HTML_ENTITY(Igrave, 204)
HTML_ENTITY(Iacute, 205)
HTML_ENTITY(Icirc, 206)
HTML_ENTITY(Iuml, 207)
HTML_ENTITY(ETH, 208)
HTML_ENTITY(Ntilde, 209)
HTML_ENTITY(Ograve, 210)
HTML_ENTITY(Oacute, 211)
HTML_ENTITY(Ocirc, 212)
HTML_ENTITY(Otilde, 213)
HTML_ENTITY(Ouml, 214)
HTML_ENTITY(times, 215)
HTML_ENTITY(Oslash, 216)
HTML_ENTITY(Ugrave, 217)
HTML_ENTITY(Uacute, 218)
HTML_ENTITY(Ucirc, 219)
HTML_ENTITY(Uuml, 220)
HTML_ENTITY(Yacute, 221)
HTML_ENTITY(THORN, 222)
HTML_ENTITY(szlig, 223)
HTML_ENTITY(agrave, 224)
HTML_ENTITY(aacute, 225)
HTML_ENTITY(acirc, 226)
HTML_ENTITY(atilde, 227)
HTML_ENTITY(auml, 228)
HTML_ENTITY(aring, 229)
HTML_ENTITY(aelig, 230)
HTML_ENTITY(ccedil, 231)
HTML_ENTITY(egrave, 232)
HTML_ENTITY(eacute, 233)
HTML_ENTITY(ecirc, 234)
HTML_ENTITY(euml, 235)
HTML_ENTITY(igrave, 236)
HTML_ENTITY(iacute, 237)
HTML_ENTITY(icirc, 238)
HTML_ENTITY(iuml, 239)
HTML_ENTITY(eth, 240)
HTML_ENTITY(ntilde, 241)
HTML_ENTITY(ograve, 242)
HTML_ENTITY(oacute, 243)
HTML_ENTITY(ocirc, 244)
HTML_ENTITY(otilde, 245)
HTML_ENTITY(ouml, 246)
HTML_ENTITY(divide, 247)
HTML_ENTITY(oslash, 248)
HTML_ENTITY(ugrave, 249)
HTML_ENTITY(uacute, 250)
HTML_ENTITY(ucirc, 251)
HTML_ENTITY(uuml, 252)
HTML_ENTITY(yacute, 253)
HTML_ENTITY(thorn, 254)
HTML_ENTITY(yuml, 255)
// Symbols, mathematical symbols and Greek letters
// See the HTML4.0 spec for this list in it's DTD form
HTML_ENTITY(fnof, 402)
HTML_ENTITY(Alpha, 913)
HTML_ENTITY(Beta, 914)
HTML_ENTITY(Gamma, 915)
HTML_ENTITY(Delta, 916)
HTML_ENTITY(Epsilon, 917)
HTML_ENTITY(Zeta, 918)
HTML_ENTITY(Eta, 919)
HTML_ENTITY(Theta, 920)
HTML_ENTITY(Iota, 921)
HTML_ENTITY(Kappa, 922)
HTML_ENTITY(Lambda, 923)
HTML_ENTITY(Mu, 924)
HTML_ENTITY(Nu, 925)
HTML_ENTITY(Xi, 926)
HTML_ENTITY(Omicron, 927)
HTML_ENTITY(Pi, 928)
HTML_ENTITY(Rho, 929)
HTML_ENTITY(Sigma, 931)
HTML_ENTITY(Tau, 932)
HTML_ENTITY(Upsilon, 933)
HTML_ENTITY(Phi, 934)
HTML_ENTITY(Chi, 935)
HTML_ENTITY(Psi, 936)
HTML_ENTITY(Omega, 937)
HTML_ENTITY(alpha, 945)
HTML_ENTITY(beta, 946)
HTML_ENTITY(gamma, 947)
HTML_ENTITY(delta, 948)
HTML_ENTITY(epsilon, 949)
HTML_ENTITY(zeta, 950)
HTML_ENTITY(eta, 951)
HTML_ENTITY(theta, 952)
HTML_ENTITY(iota, 953)
HTML_ENTITY(kappa, 954)
HTML_ENTITY(lambda, 955)
HTML_ENTITY(mu, 956)
HTML_ENTITY(nu, 957)
HTML_ENTITY(xi, 958)
HTML_ENTITY(omicron, 959)
HTML_ENTITY(pi, 960)
HTML_ENTITY(rho, 961)
HTML_ENTITY(sigmaf, 962)
HTML_ENTITY(sigma, 963)
HTML_ENTITY(tau, 964)
HTML_ENTITY(upsilon, 965)
HTML_ENTITY(phi, 966)
HTML_ENTITY(chi, 967)
HTML_ENTITY(psi, 968)
HTML_ENTITY(omega, 969)
HTML_ENTITY(thetasym, 977)
HTML_ENTITY(upsih, 978)
HTML_ENTITY(piv, 982)
HTML_ENTITY(bull, 8226)
HTML_ENTITY(hellip, 8230)
HTML_ENTITY(prime, 8242)
HTML_ENTITY(Prime, 8243)
HTML_ENTITY(oline, 8254)
HTML_ENTITY(frasl, 8260)
HTML_ENTITY(weierp, 8472)
HTML_ENTITY(image, 8465)
HTML_ENTITY(real, 8476)
HTML_ENTITY(trade, 8482)
HTML_ENTITY(alefsym, 8501)
HTML_ENTITY(larr, 8592)
HTML_ENTITY(uarr, 8593)
HTML_ENTITY(rarr, 8594)
HTML_ENTITY(darr, 8595)
HTML_ENTITY(harr, 8596)
HTML_ENTITY(crarr, 8629)
HTML_ENTITY(lArr, 8656)
HTML_ENTITY(uArr, 8657)
HTML_ENTITY(rArr, 8658)
HTML_ENTITY(dArr, 8659)
HTML_ENTITY(hArr, 8660)
HTML_ENTITY(forall, 8704)
HTML_ENTITY(part, 8706)
HTML_ENTITY(exist, 8707)
HTML_ENTITY(empty, 8709)
HTML_ENTITY(nabla, 8711)
HTML_ENTITY(isin, 8712)
HTML_ENTITY(notin, 8713)
HTML_ENTITY(ni, 8715)
HTML_ENTITY(prod, 8719)
HTML_ENTITY(sum, 8721)
HTML_ENTITY(minus, 8722)
HTML_ENTITY(lowast, 8727)
HTML_ENTITY(radic, 8730)
HTML_ENTITY(prop, 8733)
HTML_ENTITY(infin, 8734)
HTML_ENTITY(ang, 8736)
HTML_ENTITY(and, 8743)
HTML_ENTITY(or, 8744)
HTML_ENTITY(cap, 8745)
HTML_ENTITY(cup, 8746)
HTML_ENTITY(int, 8747)
HTML_ENTITY(there4, 8756)
HTML_ENTITY(sim, 8764)
HTML_ENTITY(cong, 8773)
HTML_ENTITY(asymp, 8776)
HTML_ENTITY(ne, 8800)
HTML_ENTITY(equiv, 8801)
HTML_ENTITY(le, 8804)
HTML_ENTITY(ge, 8805)
HTML_ENTITY(sub, 8834)
HTML_ENTITY(sup, 8835)
HTML_ENTITY(nsub, 8836)
HTML_ENTITY(sube, 8838)
HTML_ENTITY(supe, 8839)
HTML_ENTITY(oplus, 8853)
HTML_ENTITY(otimes, 8855)
HTML_ENTITY(perp, 8869)
HTML_ENTITY(sdot, 8901)
HTML_ENTITY(lceil, 8968)
HTML_ENTITY(rceil, 8969)
HTML_ENTITY(lfloor, 8970)
HTML_ENTITY(rfloor, 8971)
HTML_ENTITY(lang, 9001)
HTML_ENTITY(rang, 9002)
HTML_ENTITY(loz, 9674)
HTML_ENTITY(spades, 9824)
HTML_ENTITY(clubs, 9827)
HTML_ENTITY(hearts, 9829)
HTML_ENTITY(diams, 9830)
// Markup-significant and internationalization characters
// See the HTML4.0 spec for this list in it's DTD form
HTML_ENTITY(quot, 34)
HTML_ENTITY(amp, 38)
HTML_ENTITY(lt, 60)
HTML_ENTITY(gt, 62)
HTML_ENTITY(OElig, 338)
HTML_ENTITY(oelig, 339)
HTML_ENTITY(Scaron, 352)
HTML_ENTITY(scaron, 353)
HTML_ENTITY(Yuml, 376)
HTML_ENTITY(circ, 710)
HTML_ENTITY(tilde, 732)
HTML_ENTITY(ensp, 8194)
HTML_ENTITY(emsp, 8195)
HTML_ENTITY(thinsp, 8201)
HTML_ENTITY(zwnj, 8204)
HTML_ENTITY(zwj, 8205)
HTML_ENTITY(lrm, 8206)
HTML_ENTITY(rlm, 8207)
HTML_ENTITY(ndash, 8211)
HTML_ENTITY(mdash, 8212)
HTML_ENTITY(lsquo, 8216)
HTML_ENTITY(rsquo, 8217)
HTML_ENTITY(sbquo, 8218)
HTML_ENTITY(ldquo, 8220)
HTML_ENTITY(rdquo, 8221)
HTML_ENTITY(bdquo, 8222)
HTML_ENTITY(dagger, 8224)
HTML_ENTITY(Dagger, 8225)
HTML_ENTITY(permil, 8240)
HTML_ENTITY(lsaquo, 8249)
HTML_ENTITY(rsaquo, 8250)
HTML_ENTITY(euro, 8364)
// Navigator entity extensions
// This block of entities needs to be at the bottom of the list since it
// contains duplicate Unicode codepoints. The codepoint to entity name
// mapping (used by Composer) must ignores them, which occurs only
// because they are listed later.
// apos is from XML
HTML_ENTITY(apos, 39)
// The capitalized versions are required to handle non-standard input.
HTML_ENTITY(AMP, 38)
HTML_ENTITY(COPY, 169)
HTML_ENTITY(GT, 62)
HTML_ENTITY(LT, 60)
HTML_ENTITY(QUOT, 34)
HTML_ENTITY(REG, 174)

Просмотреть файл

@ -1,528 +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 Communicator client 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 "nsHTMLTags.h"
#include "nsCRT.h"
#include "nsReadableUtils.h"
#include "plhash.h"
#include "nsString.h"
#include "nsStaticAtom.h"
// C++ sucks! There's no way to do this with a macro, at least not
// that I know, if you know how to do this with a macro then please do
// so...
static const PRUnichar sHTMLTagUnicodeName_a[] =
{'a', '\0'};
static const PRUnichar sHTMLTagUnicodeName_abbr[] =
{'a', 'b', 'b', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_acronym[] =
{'a', 'c', 'r', 'o', 'n', 'y', 'm', '\0'};
static const PRUnichar sHTMLTagUnicodeName_address[] =
{'a', 'd', 'd', 'r', 'e', 's', 's', '\0'};
static const PRUnichar sHTMLTagUnicodeName_applet[] =
{'a', 'p', 'p', 'l', 'e', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_area[] =
{'a', 'r', 'e', 'a', '\0'};
static const PRUnichar sHTMLTagUnicodeName_b[] =
{'b', '\0'};
static const PRUnichar sHTMLTagUnicodeName_base[] =
{'b', 'a', 's', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_basefont[] =
{'b', 'a', 's', 'e', 'f', 'o', 'n', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_bdo[] =
{'b', 'd', 'o', '\0'};
static const PRUnichar sHTMLTagUnicodeName_bgsound[] =
{'b', 'g', 's', 'o', 'u', 'n', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_big[] =
{'b', 'i', 'g', '\0'};
static const PRUnichar sHTMLTagUnicodeName_blink[] =
{'b', 'l', 'i', 'n', 'k', '\0'};
static const PRUnichar sHTMLTagUnicodeName_blockquote[] =
{'b', 'l', 'o', 'c', 'k', 'q', 'u', 'o', 't', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_body[] =
{'b', 'o', 'd', 'y', '\0'};
static const PRUnichar sHTMLTagUnicodeName_br[] =
{'b', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_button[] =
{'b', 'u', 't', 't', 'o', 'n', '\0'};
static const PRUnichar sHTMLTagUnicodeName_caption[] =
{'c', 'a', 'p', 't', 'i', 'o', 'n', '\0'};
static const PRUnichar sHTMLTagUnicodeName_center[] =
{'c', 'e', 'n', 't', 'e', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_cite[] =
{'c', 'i', 't', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_code[] =
{'c', 'o', 'd', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_col[] =
{'c', 'o', 'l', '\0'};
static const PRUnichar sHTMLTagUnicodeName_colgroup[] =
{'c', 'o', 'l', 'g', 'r', 'o', 'u', 'p', '\0'};
static const PRUnichar sHTMLTagUnicodeName_counter[] =
{'c', 'o', 'u', 'n', 't', 'e', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_dd[] =
{'d', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_del[] =
{'d', 'e', 'l', '\0'};
static const PRUnichar sHTMLTagUnicodeName_dfn[] =
{'d', 'f', 'n', '\0'};
static const PRUnichar sHTMLTagUnicodeName_dir[] =
{'d', 'i', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_div[] =
{'d', 'i', 'v', '\0'};
static const PRUnichar sHTMLTagUnicodeName_dl[] =
{'d', 'l', '\0'};
static const PRUnichar sHTMLTagUnicodeName_dt[] =
{'d', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_em[] =
{'e', 'm', '\0'};
static const PRUnichar sHTMLTagUnicodeName_embed[] =
{'e', 'm', 'b', 'e', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_endnote[] =
{'e', 'n', 'd', 'n', 'o', 't', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_fieldset[] =
{'f', 'i', 'e', 'l', 'd', 's', 'e', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_font[] =
{'f', 'o', 'n', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_form[] =
{'f', 'o', 'r', 'm', '\0'};
static const PRUnichar sHTMLTagUnicodeName_frame[] =
{'f', 'r', 'a', 'm', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_frameset[] =
{'f', 'r', 'a', 'm', 'e', 's', 'e', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_h1[] =
{'h', '1', '\0'};
static const PRUnichar sHTMLTagUnicodeName_h2[] =
{'h', '2', '\0'};
static const PRUnichar sHTMLTagUnicodeName_h3[] =
{'h', '3', '\0'};
static const PRUnichar sHTMLTagUnicodeName_h4[] =
{'h', '4', '\0'};
static const PRUnichar sHTMLTagUnicodeName_h5[] =
{'h', '5', '\0'};
static const PRUnichar sHTMLTagUnicodeName_h6[] =
{'h', '6', '\0'};
static const PRUnichar sHTMLTagUnicodeName_head[] =
{'h', 'e', 'a', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_hr[] =
{'h', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_html[] =
{'h', 't', 'm', 'l', '\0'};
static const PRUnichar sHTMLTagUnicodeName_i[] =
{'i', '\0'};
static const PRUnichar sHTMLTagUnicodeName_iframe[] =
{'i', 'f', 'r', 'a', 'm', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_image[] =
{'i', 'm', 'a', 'g', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_img[] =
{'i', 'm', 'g', '\0'};
static const PRUnichar sHTMLTagUnicodeName_input[] =
{'i', 'n', 'p', 'u', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_ins[] =
{'i', 'n', 's', '\0'};
static const PRUnichar sHTMLTagUnicodeName_isindex[] =
{'i', 's', 'i', 'n', 'd', 'e', 'x', '\0'};
static const PRUnichar sHTMLTagUnicodeName_kbd[] =
{'k', 'b', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_keygen[] =
{'k', 'e', 'y', 'g', 'e', 'n', '\0'};
static const PRUnichar sHTMLTagUnicodeName_label[] =
{'l', 'a', 'b', 'e', 'l', '\0'};
static const PRUnichar sHTMLTagUnicodeName_legend[] =
{'l', 'e', 'g', 'e', 'n', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_li[] =
{'l', 'i', '\0'};
static const PRUnichar sHTMLTagUnicodeName_link[] =
{'l', 'i', 'n', 'k', '\0'};
static const PRUnichar sHTMLTagUnicodeName_listing[] =
{'l', 'i', 's', 't', 'i', 'n', 'g', '\0'};
static const PRUnichar sHTMLTagUnicodeName_map[] =
{'m', 'a', 'p', '\0'};
static const PRUnichar sHTMLTagUnicodeName_marquee[] =
{'m', 'a', 'r', 'q', 'u', 'e', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_menu[] =
{'m', 'e', 'n', 'u', '\0'};
static const PRUnichar sHTMLTagUnicodeName_meta[] =
{'m', 'e', 't', 'a', '\0'};
static const PRUnichar sHTMLTagUnicodeName_multicol[] =
{'m', 'u', 'l', 't', 'i', 'c', 'o', 'l', '\0'};
static const PRUnichar sHTMLTagUnicodeName_nobr[] =
{'n', 'o', 'b', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_noembed[] =
{'n', 'o', 'e', 'm', 'b', 'e', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_noframes[] =
{'n', 'o', 'f', 'r', 'a', 'm', 'e', 's', '\0'};
static const PRUnichar sHTMLTagUnicodeName_noscript[] =
{'n', 'o', 's', 'c', 'r', 'i', 'p', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_object[] =
{'o', 'b', 'j', 'e', 'c', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_ol[] =
{'o', 'l', '\0'};
static const PRUnichar sHTMLTagUnicodeName_optgroup[] =
{'o', 'p', 't', 'g', 'r', 'o', 'u', 'p', '\0'};
static const PRUnichar sHTMLTagUnicodeName_option[] =
{'o', 'p', 't', 'i', 'o', 'n', '\0'};
static const PRUnichar sHTMLTagUnicodeName_p[] =
{'p', '\0'};
static const PRUnichar sHTMLTagUnicodeName_param[] =
{'p', 'a', 'r', 'a', 'm', '\0'};
static const PRUnichar sHTMLTagUnicodeName_parsererror[] =
{'p', 'a', 'r', 's', 'e', 'r', 'e', 'r', 'r', 'o', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_plaintext[] =
{'p', 'l', 'a', 'i', 'n', 't', 'e', 'x', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_pre[] =
{'p', 'r', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_q[] =
{'q', '\0'};
static const PRUnichar sHTMLTagUnicodeName_s[] =
{'s', '\0'};
static const PRUnichar sHTMLTagUnicodeName_samp[] =
{'s', 'a', 'm', 'p', '\0'};
static const PRUnichar sHTMLTagUnicodeName_script[] =
{'s', 'c', 'r', 'i', 'p', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_select[] =
{'s', 'e', 'l', 'e', 'c', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_server[] =
{'s', 'e', 'r', 'v', 'e', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_small[] =
{'s', 'm', 'a', 'l', 'l', '\0'};
static const PRUnichar sHTMLTagUnicodeName_sound[] =
{'s', 'o', 'u', 'n', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_sourcetext[] =
{'s', 'o', 'u', 'r', 'c', 'e', 't', 'e', 'x', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_spacer[] =
{'s', 'p', 'a', 'c', 'e', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_span[] =
{'s', 'p', 'a', 'n', '\0'};
static const PRUnichar sHTMLTagUnicodeName_strike[] =
{'s', 't', 'r', 'i', 'k', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_strong[] =
{'s', 't', 'r', 'o', 'n', 'g', '\0'};
static const PRUnichar sHTMLTagUnicodeName_style[] =
{'s', 't', 'y', 'l', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_sub[] =
{'s', 'u', 'b', '\0'};
static const PRUnichar sHTMLTagUnicodeName_sup[] =
{'s', 'u', 'p', '\0'};
static const PRUnichar sHTMLTagUnicodeName_table[] =
{'t', 'a', 'b', 'l', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_tbody[] =
{'t', 'b', 'o', 'd', 'y', '\0'};
static const PRUnichar sHTMLTagUnicodeName_td[] =
{'t', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_textarea[] =
{'t', 'e', 'x', 't', 'a', 'r', 'e', 'a', '\0'};
static const PRUnichar sHTMLTagUnicodeName_tfoot[] =
{'t', 'f', 'o', 'o', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_th[] =
{'t', 'h', '\0'};
static const PRUnichar sHTMLTagUnicodeName_thead[] =
{'t', 'h', 'e', 'a', 'd', '\0'};
static const PRUnichar sHTMLTagUnicodeName_title[] =
{'t', 'i', 't', 'l', 'e', '\0'};
static const PRUnichar sHTMLTagUnicodeName_tr[] =
{'t', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_tt[] =
{'t', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_u[] =
{'u', '\0'};
static const PRUnichar sHTMLTagUnicodeName_ul[] =
{'u', 'l', '\0'};
static const PRUnichar sHTMLTagUnicodeName_var[] =
{'v', 'a', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_wbr[] =
{'w', 'b', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_xmp[] =
{'x', 'm', 'p', '\0'};
// static array of unicode tag names
#define HTML_TAG(_tag, _classname) sHTMLTagUnicodeName_##_tag,
#define HTML_OTHER(_tag, _classname)
static const PRUnichar* const kTagUnicodeTable[] = {
#include "nsHTMLTagList.h"
};
#undef HTML_TAG
// static array of tag atoms
static nsIAtom* kTagAtomTable[eHTMLTag_userdefined - 1];
// static array of tag StaticAtom structs
#define HTML_TAG(_tag, _classname) { #_tag, &kTagAtomTable[eHTMLTag_##_tag - 1] },
static const nsStaticAtom kTagAtoms_info[] = {
#include "nsHTMLTagList.h"
};
#undef HTML_TAG
#undef HTML_OTHER
static PRInt32 gTableRefCount;
static PLHashTable* gTagTable;
PR_STATIC_CALLBACK(PLHashNumber)
HTMLTagsHashCodeUCPtr(const void *key)
{
const PRUnichar *str = (const PRUnichar *)key;
return nsCRT::HashCode(str);
}
PR_STATIC_CALLBACK(PRIntn)
HTMLTagsKeyCompareUCPtr(const void *key1, const void *key2)
{
const PRUnichar *str1 = (const PRUnichar *)key1;
const PRUnichar *str2 = (const PRUnichar *)key2;
return nsCRT::strcmp(str1, str2) == 0;
}
static PRUint32 sMaxTagNameLength;
#define NS_HTMLTAG_NAME_MAX_LENGTH 11
// static
nsresult
nsHTMLTags::AddRefTable(void)
{
if (gTableRefCount++ == 0) {
NS_ASSERTION(!gTagTable, "pre existing hash!");
gTagTable = PL_NewHashTable(64, HTMLTagsHashCodeUCPtr,
HTMLTagsKeyCompareUCPtr, PL_CompareValues,
nsnull, nsnull);
NS_ENSURE_TRUE(gTagTable, NS_ERROR_OUT_OF_MEMORY);
// Fill in gTagTable with the above static PRUnichar strings as
// keys and the value of the corresponding enum as the value in
// the table.
PRInt32 i;
for (i = 0; i < NS_HTML_TAG_MAX; ++i) {
PRUint32 len = nsCRT::strlen(kTagUnicodeTable[i]);
PL_HashTableAdd(gTagTable, kTagUnicodeTable[i],
NS_INT32_TO_PTR(i + 1));
if (len > sMaxTagNameLength) {
sMaxTagNameLength = len;
}
}
NS_ASSERTION(sMaxTagNameLength == NS_HTMLTAG_NAME_MAX_LENGTH,
"NS_HTMLTAG_NAME_MAX_LENGTH not set correctly!");
// Fill in our static atom pointers
NS_RegisterStaticAtoms(kTagAtoms_info, NS_ARRAY_LENGTH(kTagAtoms_info));
#ifdef DEBUG
{
// let's verify that all names in the the table are lowercase...
for (i = 0; i < NS_HTML_TAG_MAX; ++i) {
nsCAutoString temp1(kTagAtoms_info[i].mString);
nsCAutoString temp2(kTagAtoms_info[i].mString);
ToLowerCase(temp1);
NS_ASSERTION(temp1.Equals(temp2), "upper case char in table");
}
// let's verify that all names in the unicode strings above are
// correct.
for (i = 0; i < NS_HTML_TAG_MAX; ++i) {
nsAutoString temp1(kTagUnicodeTable[i]);
nsAutoString temp2; temp2.AssignWithConversion(kTagAtoms_info[i].mString);
NS_ASSERTION(temp1.Equals(temp2), "Bad unicode tag name!");
}
}
#endif
}
return NS_OK;
}
// static
void
nsHTMLTags::ReleaseTable(void)
{
if (0 == --gTableRefCount) {
if (gTagTable) {
// Nothing to delete/free in this table, just destroy the table.
PL_HashTableDestroy(gTagTable);
gTagTable = nsnull;
}
}
}
// static
nsHTMLTag
nsHTMLTags::CaseSensitiveLookupTag(const PRUnichar* aTagName)
{
NS_ASSERTION(gTagTable, "no lookup table, needs addref");
NS_ASSERTION(aTagName, "null tagname!");
PRUint32 tag = NS_PTR_TO_INT32(PL_HashTableLookupConst(gTagTable, aTagName));
return (nsHTMLTag)tag;
}
// static
nsHTMLTag
nsHTMLTags::LookupTag(const nsAString& aTagName)
{
PRUint32 length = aTagName.Length();
if (length > sMaxTagNameLength) {
return eHTMLTag_userdefined;
}
static PRUnichar buf[NS_HTMLTAG_NAME_MAX_LENGTH + 1];
nsAString::const_iterator iter;
PRUint32 i = 0;
PRUnichar c;
aTagName.BeginReading(iter);
// Fast lowercasing-while-copying of ASCII characters into a
// PRUnichar buffer
while (i < length) {
c = *iter;
if (c <= 'Z' && c >= 'A') {
c |= 0x20; // Lowercase the ASCII character.
}
buf[i] = c; // Copy ASCII character.
++i;
++iter;
}
buf[i] = 0;
nsHTMLTag tag = CaseSensitiveLookupTag(buf);
// hack: this can come out when rickg provides a way for the editor to ask
// CanContain() questions without having to first fetch the parsers
// internal enum values for a tag name.
// Hmm, this hack would be faster if we'd put these strings in the
// hash table. But maybe it's not worth it...
if (tag == eHTMLTag_unknown) {
// "__moz_text"
static const PRUnichar moz_text[] =
{'_', '_', 'm', 'o', 'z', '_', 't', 'e', 'x', 't', PRUnichar(0) };
// "#text"
static const PRUnichar text[] =
{'#', 't', 'e', 'x', 't', PRUnichar(0) };
if (nsCRT::strcmp(buf, moz_text) == 0) {
tag = eHTMLTag_text;
} else if (nsCRT::strcmp(buf, text) == 0) {
tag = eHTMLTag_text;
} else {
tag = eHTMLTag_userdefined;
}
}
return tag;
}
// static
const PRUnichar *
nsHTMLTags::GetStringValue(nsHTMLTag aEnum)
{
if (aEnum <= eHTMLTag_unknown || aEnum > NS_HTML_TAG_MAX) {
return nsnull;
}
return kTagUnicodeTable[aEnum - 1];
}
// static
nsIAtom *
nsHTMLTags::GetAtom(nsHTMLTag aEnum)
{
if (aEnum <= eHTMLTag_unknown || aEnum > NS_HTML_TAG_MAX) {
return nsnull;
}
return kTagAtomTable[aEnum - 1];
}
#ifdef NS_DEBUG
// tag table verification class.
class nsTestTagTable {
public:
nsTestTagTable() {
const PRUnichar *tag;
nsHTMLTag id;
nsHTMLTags::AddRefTable();
// Make sure we can find everything we are supposed to
for (int i = 0; i < NS_HTML_TAG_MAX; ++i) {
tag = kTagUnicodeTable[i];
id = nsHTMLTags::LookupTag(nsDependentString(tag));
NS_ASSERTION(id != eHTMLTag_userdefined, "can't find tag id");
const PRUnichar* check = nsHTMLTags::GetStringValue(id);
NS_ASSERTION(0 == nsCRT::strcmp(check, tag), "can't map id back to tag");
}
// Make sure we don't find things that aren't there
id = nsHTMLTags::LookupTag(NS_LITERAL_STRING("@"));
NS_ASSERTION(id == eHTMLTag_userdefined, "found @");
id = nsHTMLTags::LookupTag(NS_LITERAL_STRING("zzzzz"));
NS_ASSERTION(id == eHTMLTag_userdefined, "found zzzzz");
tag = nsHTMLTags::GetStringValue((nsHTMLTag) 0);
NS_ASSERTION(!tag, "found enum 0");
tag = nsHTMLTags::GetStringValue((nsHTMLTag) -1);
NS_ASSERTION(!tag, "found enum -1");
tag = nsHTMLTags::GetStringValue((nsHTMLTag) (NS_HTML_TAG_MAX + 1));
NS_ASSERTION(!tag, "found past max enum");
nsHTMLTags::ReleaseTable();
}
};
static const nsTestTagTable validateTagTable;
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,114 +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
*
*/
#ifndef __NSHTMLTOKENIZER
#define __NSHTMLTOKENIZER
#include "nsISupports.h"
#include "nsITokenizer.h"
#include "nsIDTD.h"
#include "prtypes.h"
#include "nsDeque.h"
#include "nsScanner.h"
#include "nsHTMLTokens.h"
#include "nsDTDUtils.h"
#define NS_HTMLTOKENIZER_IID \
{0xe4238ddd, 0x9eb6, 0x11d2, \
{0xba, 0xa5, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4 }}
/***************************************************************
Notes:
***************************************************************/
#ifdef _MSC_VER
#pragma warning( disable : 4275 )
#endif
class nsHTMLTokenizer : public nsITokenizer {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSITOKENIZER
nsHTMLTokenizer(PRInt32 aParseMode = eDTDMode_quirks,
eParserDocType aDocType = eHTML3_Quirks,
eParserCommands aCommand = eViewNormal);
virtual ~nsHTMLTokenizer();
protected:
virtual nsresult ConsumeTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner,PRBool& aFlushTokens);
virtual nsresult ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner,PRBool& aFlushTokens);
virtual nsresult ConsumeEndTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
virtual nsresult ConsumeAttributes(PRUnichar aChar, CToken* aToken, nsScanner& aScanner);
virtual nsresult ConsumeEntity(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
virtual nsresult ConsumeWhitespace(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
virtual nsresult ConsumeComment(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
virtual nsresult ConsumeNewline(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
virtual nsresult ConsumeText(CToken*& aToken,nsScanner& aScanner);
virtual nsresult ConsumeSpecialMarkup(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
virtual nsresult ConsumeProcessingInstruction(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
nsresult ScanDocStructure(PRBool aIsFinalChunk);
virtual void PreserveToken(CStartToken* aStartToken, nsScanner& aScanner, nsScannerIterator aOrigin);
static void AddToken(CToken*& aToken,nsresult aResult,nsDeque* aDeque,nsTokenAllocator* aTokenAllocator);
nsDeque mTokenDeque;
PRPackedBool mIsFinalChunk;
nsTokenAllocator* mTokenAllocator;
PRInt32 mTokenScanPos;
PRUint32 mFlags;
eHTMLTags mPreserveTarget; // Tag whose content is preserved
};
extern nsresult NS_NewHTMLTokenizer(nsITokenizer** aInstancePtrResult,
PRInt32 aMode,eParserDocType aDocType,
eParserCommands aCommand);
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,811 +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 Communicator client 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 "nsLoggingSink.h"
#include "nsHTMLTags.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "prprf.h"
static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENT_SINK_IID);
static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTML_CONTENT_SINK_IID);
static NS_DEFINE_IID(kILoggingSinkIID, NS_ILOGGING_SINK_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
// list of tags that have skipped content
static const char gSkippedContentTags[] = {
eHTMLTag_style,
eHTMLTag_script,
eHTMLTag_server,
eHTMLTag_textarea,
eHTMLTag_title,
0
};
nsresult
NS_NewHTMLLoggingSink(nsIContentSink** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsLoggingSink* it = new nsLoggingSink();
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIContentSinkIID, (void**) aInstancePtrResult);
}
nsLoggingSink::nsLoggingSink() {
mOutput = 0;
mLevel=-1;
mSink=0;
mParser=0;
}
nsLoggingSink::~nsLoggingSink() {
mSink=0;
if(mOutput && mAutoDeleteOutput) {
delete mOutput;
}
mOutput=0;
}
NS_IMPL_ADDREF(nsLoggingSink)
NS_IMPL_RELEASE(nsLoggingSink)
nsresult
nsLoggingSink::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_PRECONDITION(nsnull != aInstancePtr, "null ptr");
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
nsISupports* tmp = this;
*aInstancePtr = (void*) tmp;
}
else if (aIID.Equals(kIContentSinkIID)) {
nsIContentSink* tmp = this;
*aInstancePtr = (void*) tmp;
}
else if (aIID.Equals(kIHTMLContentSinkIID)) {
nsIHTMLContentSink* tmp = this;
*aInstancePtr = (void*) tmp;
}
else if (aIID.Equals(kILoggingSinkIID)) {
nsILoggingSink* tmp = this;
*aInstancePtr = (void*) tmp;
}
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF(this);
return NS_OK;
}
NS_IMETHODIMP
nsLoggingSink::SetOutputStream(PRFileDesc *aStream,PRBool autoDeleteOutput) {
mOutput = aStream;
mAutoDeleteOutput=autoDeleteOutput;
return NS_OK;
}
static
void WriteTabs(PRFileDesc * out,int aTabCount) {
int tabs;
for(tabs=0;tabs<aTabCount;++tabs)
PR_fprintf(out, " ");
}
NS_IMETHODIMP
nsLoggingSink::WillBuildModel() {
WriteTabs(mOutput,++mLevel);
PR_fprintf(mOutput, "<begin>\n");
//proxy the call to the real sink if you have one.
if(mSink) {
mSink->WillBuildModel();
}
return NS_OK;
}
NS_IMETHODIMP
nsLoggingSink::DidBuildModel() {
WriteTabs(mOutput,--mLevel);
PR_fprintf(mOutput, "</begin>\n");
//proxy the call to the real sink if you have one.
nsresult theResult=NS_OK;
if(mSink) {
theResult=mSink->DidBuildModel();
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::WillInterrupt() {
nsresult theResult=NS_OK;
//proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->WillInterrupt();
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::WillResume() {
nsresult theResult=NS_OK;
//proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->WillResume();
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::SetParser(nsIParser* aParser) {
nsresult theResult=NS_OK;
//proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->SetParser(aParser);
}
NS_IF_RELEASE(mParser);
mParser = aParser;
NS_IF_ADDREF(mParser);
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::OpenContainer(const nsIParserNode& aNode) {
OpenNode("container", aNode); //do the real logging work...
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->OpenContainer(aNode);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::CloseContainer(const nsHTMLTag aTag) {
nsresult theResult=NS_OK;
nsHTMLTag nodeType = nsHTMLTag(aTag);
if ((nodeType >= eHTMLTag_unknown) &&
(nodeType <= nsHTMLTag(NS_HTML_TAG_MAX))) {
const PRUnichar* tag = nsHTMLTags::GetStringValue(nodeType);
theResult = CloseNode(NS_ConvertUCS2toUTF8(tag).get());
}
else theResult= CloseNode("???");
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->CloseContainer(aTag);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::AddHeadContent(const nsIParserNode& aNode) {
LeafNode(aNode);
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->AddHeadContent(aNode);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::AddLeaf(const nsIParserNode& aNode) {
LeafNode(aNode);
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->AddLeaf(aNode);
}
return theResult;
}
/**
* This gets called by the parser when you want to add
* a PI node to the current container in the content
* model.
*
* @updated gess 3/25/98
* @param
* @return
*/
NS_IMETHODIMP
nsLoggingSink::AddProcessingInstruction(const nsIParserNode& aNode){
#ifdef VERBOSE_DEBUG
DebugDump("<",aNode.GetText(),(mNodeStackPos)*2);
#endif
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->AddProcessingInstruction(aNode);
}
return theResult;
}
/**
* This gets called by the parser when it encounters
* a DOCTYPE declaration in the HTML document.
*/
NS_IMETHODIMP
nsLoggingSink::AddDocTypeDecl(const nsIParserNode& aNode) {
#ifdef VERBOSE_DEBUG
DebugDump("<",aNode.GetText(),(mNodeStackPos)*2);
#endif
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->AddDocTypeDecl(aNode);
}
return theResult;
}
/**
* This gets called by the parser when you want to add
* a comment node to the current container in the content
* model.
*
* @updated gess 3/25/98
* @param
* @return
*/
NS_IMETHODIMP
nsLoggingSink::AddComment(const nsIParserNode& aNode){
#ifdef VERBOSE_DEBUG
DebugDump("<",aNode.GetText(),(mNodeStackPos)*2);
#endif
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->AddComment(aNode);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::SetTitle(const nsString& aValue) {
char* tmp = nsnull;
GetNewCString(aValue, &tmp);
WriteTabs(mOutput,++mLevel);
if(tmp) {
PR_fprintf(mOutput, "<title value=\"%s\"/>\n", tmp);
nsMemory::Free(tmp);
}
--mLevel;
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->SetTitle(aValue);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::OpenHTML(const nsIParserNode& aNode) {
OpenNode("html", aNode);
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->OpenHTML(aNode);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::CloseHTML() {
CloseNode("html");
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->CloseHTML();
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::OpenHead(const nsIParserNode& aNode) {
OpenNode("head", aNode);
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->OpenHead(aNode);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::CloseHead() {
CloseNode("head");
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->CloseHead();
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::OpenBody(const nsIParserNode& aNode) {
OpenNode("body", aNode);
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->OpenBody(aNode);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::CloseBody() {
CloseNode("body");
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->CloseBody();
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::OpenForm(const nsIParserNode& aNode) {
OpenNode("form", aNode);
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->OpenForm(aNode);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::CloseForm() {
CloseNode("form");
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->CloseForm();
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::OpenMap(const nsIParserNode& aNode) {
OpenNode("map", aNode);
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->OpenMap(aNode);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::CloseMap() {
CloseNode("map");
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->CloseMap();
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::OpenFrameset(const nsIParserNode& aNode) {
OpenNode("frameset", aNode);
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->OpenFrameset(aNode);
}
return theResult;
}
NS_IMETHODIMP
nsLoggingSink::CloseFrameset() {
CloseNode("frameset");
nsresult theResult=NS_OK;
//then proxy the call to the real sink if you have one.
if(mSink) {
theResult=mSink->CloseFrameset();
}
return theResult;
}
nsresult
nsLoggingSink::OpenNode(const char* aKind, const nsIParserNode& aNode) {
WriteTabs(mOutput,++mLevel);
PR_fprintf(mOutput,"<open container=");
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
if ((nodeType >= eHTMLTag_unknown) &&
(nodeType <= nsHTMLTag(NS_HTML_TAG_MAX))) {
const PRUnichar* tag = nsHTMLTags::GetStringValue(nodeType);
PR_fprintf(mOutput, "\"%s\"", NS_ConvertUCS2toUTF8(tag).get());
}
else {
char* text;
GetNewCString(aNode.GetText(), &text);
if(text) {
PR_fprintf(mOutput, "\"%s\"", text);
nsMemory::Free(text);
}
}
if (WillWriteAttributes(aNode)) {
PR_fprintf(mOutput, ">\n");
WriteAttributes(aNode);
PR_fprintf(mOutput, "</open>\n");
}
else {
PR_fprintf(mOutput, ">\n");
}
return NS_OK;
}
nsresult
nsLoggingSink::CloseNode(const char* aKind) {
WriteTabs(mOutput,mLevel--);
PR_fprintf(mOutput, "<close container=\"%s\">\n", aKind);
return NS_OK;
}
nsresult
nsLoggingSink::WriteAttributes(const nsIParserNode& aNode) {
WriteTabs(mOutput,1+mLevel);
nsAutoString tmp;
PRInt32 ac = aNode.GetAttributeCount();
for (PRInt32 i = 0; i < ac; ++i) {
char* key=nsnull;
char* value=nsnull;
const nsAString& k = aNode.GetKeyAt(i);
const nsAString& v = aNode.GetValueAt(i);
GetNewCString(k, &key);
if(key) {
PR_fprintf(mOutput, " <attr key=\"%s\" value=\"", key);
nsMemory::Free(key);
}
tmp.Truncate();
tmp.Append(v);
if(!tmp.IsEmpty()) {
PRUnichar first = tmp.First();
if ((first == '"') || (first == '\'')) {
if (tmp.Last() == first) {
tmp.Cut(0, 1);
PRInt32 pos = tmp.Length() - 1;
if (pos >= 0) {
tmp.Cut(pos, 1);
}
} else {
// Mismatched quotes - leave them in
}
}
GetNewCString(tmp, &value);
if(value) {
PR_fprintf(mOutput, "%s\"/>\n", value);
WriteTabs(mOutput,1+mLevel);
nsMemory::Free(value);
}
}
}
if (0 != strchr(gSkippedContentTags, aNode.GetNodeType())) {
nsCOMPtr<nsIDTD> dtd;
mParser->GetDTD(getter_AddRefs(dtd));
NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE);
nsString theString;
PRInt32 lineNo = 0;
dtd->CollectSkippedContent(aNode.GetNodeType(), theString, lineNo);
char* content = nsnull;
GetNewCString(theString, &content);
if(content) {
PR_fprintf(mOutput, " <content value=\"");
PR_fprintf(mOutput, "%s\"/>\n", content) ;
nsMemory::Free(content);
}
}
WriteTabs(mOutput,1+mLevel);
return NS_OK;
}
PRBool
nsLoggingSink::WillWriteAttributes(const nsIParserNode& aNode)
{
PRInt32 ac = aNode.GetAttributeCount();
if (0 != ac) {
return PR_TRUE;
}
if (0 != strchr(gSkippedContentTags, aNode.GetNodeType())) {
nsCOMPtr<nsIDTD> dtd;
mParser->GetDTD(getter_AddRefs(dtd));
NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE);
nsString content;
PRInt32 lineNo = 0;
dtd->CollectSkippedContent(aNode.GetNodeType(), content, lineNo);
if (!content.IsEmpty()) {
return PR_TRUE;
}
}
return PR_FALSE;
}
nsresult
nsLoggingSink::LeafNode(const nsIParserNode& aNode)
{
WriteTabs(mOutput,1+mLevel);
nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
if ((nodeType >= eHTMLTag_unknown) &&
(nodeType <= nsHTMLTag(NS_HTML_TAG_MAX))) {
const PRUnichar* tag = nsHTMLTags::GetStringValue(nodeType);
if(tag)
PR_fprintf(mOutput, "<leaf tag=\"%s\"", NS_ConvertUCS2toUTF8(tag).get());
else PR_fprintf(mOutput, "<leaf tag=\"???\"");
if (WillWriteAttributes(aNode)) {
PR_fprintf(mOutput, ">\n");
WriteAttributes(aNode);
PR_fprintf(mOutput, "</leaf>\n");
}
else {
PR_fprintf(mOutput, "/>\n");
}
}
else {
PRInt32 pos;
nsAutoString tmp;
char* str;
switch (nodeType) {
case eHTMLTag_whitespace:
case eHTMLTag_text:
GetNewCString(aNode.GetText(), &str);
if(str) {
PR_fprintf(mOutput, "<text value=\"%s\"/>\n", str);
nsMemory::Free(str);
}
break;
case eHTMLTag_newline:
PR_fprintf(mOutput, "<newline/>\n");
break;
case eHTMLTag_entity:
tmp.Append(aNode.GetText());
tmp.Cut(0, 1);
pos = tmp.Length() - 1;
if (pos >= 0) {
tmp.Cut(pos, 1);
}
PR_fprintf(mOutput, "<entity value=\"%s\"/>\n", NS_LossyConvertUCS2toASCII(tmp).get());
break;
default:
NS_NOTREACHED("unsupported leaf node type");
}//switch
}
return NS_OK;
}
nsresult
nsLoggingSink::QuoteText(const nsAString& aValue, nsString& aResult) {
aResult.Truncate();
/*
if you're stepping through the string anyway, why not use iterators instead of forcing the string to copy?
*/
const nsPromiseFlatString& flat = PromiseFlatString(aValue);
const PRUnichar* cp = flat.get();
const PRUnichar* end = cp + aValue.Length();
while (cp < end) {
PRUnichar ch = *cp++;
if (ch == '"') {
aResult.Append(NS_LITERAL_STRING("&quot;"));
}
else if (ch == '&') {
aResult.Append(NS_LITERAL_STRING("&amp;"));
}
else if ((ch < 32) || (ch >= 127)) {
aResult.Append(NS_LITERAL_STRING("&#"));
aResult.AppendInt(PRInt32(ch), 10);
aResult.Append(PRUnichar(';'));
}
else {
aResult.Append(ch);
}
}
return NS_OK;
}
/**
* Use this method to convert nsString to char*.
* REMEMBER: Match this call with nsMemory::Free(aResult);
*
* @update 04/04/99 harishd
* @param aValue - The string value
* @param aResult - String coverted to char*.
*/
nsresult
nsLoggingSink::GetNewCString(const nsAString& aValue, char** aResult)
{
nsresult result=NS_OK;
nsAutoString temp;
result=QuoteText(aValue,temp);
if(NS_SUCCEEDED(result)) {
if(!temp.IsEmpty()) {
*aResult = ToNewCString(temp);
}
}
return result;
}
/**
* This gets called when handling illegal contents, especially
* in dealing with tables. This method creates a new context.
*
* @update 04/04/99 harishd
* @param aPosition - The position from where the new context begins.
*/
NS_IMETHODIMP
nsLoggingSink::BeginContext(PRInt32 aPosition)
{
return NS_OK;
}
/**
* This method terminates any new context that got created by
* BeginContext and switches back to the main context.
*
* @update 04/04/99 harishd
* @param aPosition - Validates the end of a context.
*/
NS_IMETHODIMP
nsLoggingSink::EndContext(PRInt32 aPosition)
{
return NS_OK;
}

Просмотреть файл

@ -1,123 +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 Communicator client 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 ***** */
#ifndef NS_LOGGING_SINK_H__
#define NS_LOGGING_SINK_H__
#include "nsILoggingSink.h"
#include "nsIParser.h"
class nsLoggingSink : public nsILoggingSink {
public:
nsLoggingSink();
virtual ~nsLoggingSink();
void SetProxySink(nsIHTMLContentSink *aSink) {
mSink=aSink;
}
void ReleaseProxySink() {
NS_IF_RELEASE(mSink);
mSink=0;
}
// nsISupports
NS_DECL_ISUPPORTS
// nsIContentSink
NS_IMETHOD WillBuildModel();
NS_IMETHOD DidBuildModel();
NS_IMETHOD WillInterrupt();
NS_IMETHOD WillResume();
NS_IMETHOD SetParser(nsIParser* aParser);
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
NS_IMETHOD CloseContainer(const nsHTMLTag aTag);
NS_IMETHOD AddHeadContent(const nsIParserNode& aNode);
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
NS_IMETHOD AddComment(const nsIParserNode& aNode);
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
NS_IMETHOD FlushPendingNotifications() { return NS_OK; }
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) { return NS_OK; }
NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode) { return NS_OK; }
// nsIHTMLContentSink
NS_IMETHOD SetTitle(const nsString& aValue);
NS_IMETHOD OpenHTML(const nsIParserNode& aNode);
NS_IMETHOD CloseHTML();
NS_IMETHOD OpenHead(const nsIParserNode& aNode);
NS_IMETHOD CloseHead();
NS_IMETHOD OpenBody(const nsIParserNode& aNode);
NS_IMETHOD CloseBody();
NS_IMETHOD OpenForm(const nsIParserNode& aNode);
NS_IMETHOD CloseForm();
NS_IMETHOD OpenMap(const nsIParserNode& aNode);
NS_IMETHOD CloseMap();
NS_IMETHOD OpenFrameset(const nsIParserNode& aNode);
NS_IMETHOD CloseFrameset();
NS_IMETHOD IsEnabled(PRInt32 aTag, PRBool* aReturn) { return NS_OK; }
NS_IMETHOD_(PRBool) IsFormOnStack() { return PR_FALSE; }
NS_IMETHOD BeginContext(PRInt32 aPosition);
NS_IMETHOD EndContext(PRInt32 aPosition);
NS_IMETHOD WillProcessTokens(void) { return NS_OK; }
NS_IMETHOD DidProcessTokens(void) { return NS_OK; }
NS_IMETHOD WillProcessAToken(void) { return NS_OK; }
NS_IMETHOD DidProcessAToken(void) { return NS_OK; }
// nsILoggingSink
NS_IMETHOD SetOutputStream(PRFileDesc *aStream,PRBool autoDelete=PR_FALSE);
nsresult OpenNode(const char* aKind, const nsIParserNode& aNode);
nsresult CloseNode(const char* aKind);
nsresult LeafNode(const nsIParserNode& aNode);
nsresult WriteAttributes(const nsIParserNode& aNode);
nsresult QuoteText(const nsAString& aValue, nsString& aResult);
nsresult GetNewCString(const nsAString& aValue, char** aResult);
PRBool WillWriteAttributes(const nsIParserNode& aNode);
protected:
PRFileDesc *mOutput;
int mLevel;
nsIHTMLContentSink *mSink;
PRBool mAutoDeleteOutput;
nsIParser* mParser;
};
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,468 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 does two primary jobs:
* 1) It iterates the tokens provided during the
* tokenization process, identifing where elements
* begin and end (doing validation and normalization).
* 2) It controls and coordinates with an instance of
* the IContentSink interface, to coordinate the
* the production of the content model.
*
* The basic operation of this class assumes that an HTML
* document is non-normalized. Therefore, we don't process
* the document in a normalized way. Don't bother to look
* for methods like: doHead() or doBody().
*
* Instead, in order to be backward compatible, we must
* scan the set of tokens and perform this basic set of
* operations:
* 1) Determine the token type (easy, since the tokens know)
* 2) Determine the appropriate section of the HTML document
* each token belongs in (HTML,HEAD,BODY,FRAMESET).
* 3) Insert content into our document (via the sink) into
* the correct section.
* 4) In the case of tags that belong in the BODY, we must
* ensure that our underlying document state reflects
* the appropriate context for our tag.
*
* For example,if we see a <TR>, we must ensure our
* document contains a table into which the row can
* be placed. This may result in "implicit containers"
* created to ensure a well-formed document.
*
*/
#ifndef NS_PARSER__
#define NS_PARSER__
#include "nsIParser.h"
#include "nsDeque.h"
#include "nsParserNode.h"
#include "nsIURL.h"
#include "CParserContext.h"
#include "nsParserCIID.h"
#include "nsITokenizer.h"
#include "nsHTMLTags.h"
#include "nsDTDUtils.h"
#include "nsTimer.h"
#include "nsIEventQueue.h"
#include "nsIContentSink.h"
#include "nsIParserFilter.h"
class nsIDTD;
class nsScanner;
class nsIProgressEventSink;
#ifdef _MSC_VER
#pragma warning( disable : 4275 )
#endif
class nsParser : public nsIParser,
public nsIStreamListener{
public:
friend class CTokenHandler;
static void FreeSharedObjects(void);
NS_DECL_ISUPPORTS
/**
* default constructor
* @update gess5/11/98
*/
nsParser();
/**
* Destructor
* @update gess5/11/98
*/
virtual ~nsParser();
/**
* Select given content sink into parser for parser output
* @update gess5/11/98
* @param aSink is the new sink to be used by parser
* @return old sink, or NULL
*/
NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink);
/**
* retrive the sink set into the parser
* @update gess5/11/98
* @param aSink is the new sink to be used by parser
* @return old sink, or NULL
*/
NS_IMETHOD_(nsIContentSink*) GetContentSink(void);
/**
* Call this method once you've created a parser, and want to instruct it
* about the command which caused the parser to be constructed. For example,
* this allows us to select a DTD which can do, say, view-source.
*
* @update gess 3/25/98
* @param aCommand -- ptrs to string that contains command
* @return nada
*/
NS_IMETHOD_(void) GetCommand(nsString& aCommand);
NS_IMETHOD_(void) SetCommand(const char* aCommand);
NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand);
/**
* Call this method once you've created a parser, and want to instruct it
* about what charset to load
*
* @update ftang 4/23/99
* @param aCharset- the charset of a document
* @param aCharsetSource- the source of the charset
* @return nada
*/
NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, PRInt32 aSource);
NS_IMETHOD_(void) GetDocumentCharset(nsACString& aCharset, PRInt32& aSource)
{
aCharset = mCharset;
aSource = mCharsetSource;
}
NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter);
NS_IMETHOD RegisterDTD(nsIDTD* aDTD);
/**
* Retrieve the scanner from the topmost parser context
*
* @update gess 6/9/98
* @return ptr to scanner
*/
NS_IMETHOD_(nsDTDMode) GetParseMode(void);
/**
* Cause parser to parse input from given URL
* @update gess5/11/98
* @param aURL is a descriptor for source document
* @param aListener is a listener to forward notifications to
* @return TRUE if all went well -- FALSE otherwise
*/
NS_IMETHOD Parse(nsIURI* aURL,
nsIRequestObserver* aListener = nsnull,
PRBool aEnableVerify = PR_FALSE,
void* aKey = 0,
nsDTDMode aMode = eDTDMode_autodetect);
/**
* Cause parser to parse input from given stream
* @update gess5/11/98
* @param aStream is the i/o source
* @return TRUE if all went well -- FALSE otherwise
*/
NS_IMETHOD Parse(nsIInputStream* aStream,
const nsACString& aMimeType,
PRBool aEnableVerify = PR_FALSE,
void* aKey = 0,
nsDTDMode aMode = eDTDMode_autodetect);
/**
* @update gess5/11/98
* @param anHTMLString contains a string-full of real HTML
* @param appendTokens tells us whether we should insert tokens inline, or append them.
* @return TRUE if all went well -- FALSE otherwise
*/
NS_IMETHOD Parse(const nsAString& aSourceBuffer,
void* aKey,
const nsACString& aContentType,
PRBool aEnableVerify,
PRBool aLastCall,
nsDTDMode aMode = eDTDMode_autodetect);
NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer,
void* aKey,
nsVoidArray& aTagStack,
PRUint32 anInsertPos,
const nsACString& aContentType,
nsDTDMode aMode = eDTDMode_autodetect);
/**
* This method gets called when the tokens have been consumed, and it's time
* to build the model via the content sink.
* @update gess5/11/98
* @return YES if model building went well -- NO otherwise.
*/
NS_IMETHOD BuildModel(void);
/**
* Call this when you want control whether or not the parser will parse
* and tokenize input (TRUE), or whether it just caches input to be
* parsed later (FALSE).
*
* @update gess 9/1/98
* @param aState determines whether we parse/tokenize or just cache.
* @return current state
*/
NS_IMETHOD ContinueParsing();
NS_IMETHOD_(void) BlockParser();
NS_IMETHOD_(void) UnblockParser();
NS_IMETHOD Terminate(void);
/**
* Call this to query whether the parser is enabled or not.
*
* @update vidur 4/12/99
* @return current state
*/
NS_IMETHOD_(PRBool) IsParserEnabled();
/**
* Call this to query whether the parser thinks it's done with parsing.
*
* @update rickg 5/12/01
* @return complete state
*/
NS_IMETHOD_(PRBool) IsComplete();
/**
* This rather arcane method (hack) is used as a signal between the
* DTD and the parser. It allows the DTD to tell the parser that content
* that comes through (parser::parser(string)) but not consumed should
* propagate into the next string based parse call.
*
* @update gess 9/1/98
* @param aState determines whether we propagate unused string content.
* @return current state
*/
void SetUnusedInput(nsString& aBuffer);
/**
* This method gets called (automatically) during incremental parsing
* @update gess5/11/98
* @return TRUE if all went well, otherwise FALSE
*/
virtual nsresult ResumeParse(PRBool allowIteration = PR_TRUE,
PRBool aIsFinalChunk = PR_FALSE,
PRBool aCanInterrupt = PR_TRUE);
//*********************************************
// These methods are callback methods used by
// net lib to let us know about our inputstream.
//*********************************************
// nsIRequestObserver methods:
NS_DECL_NSIREQUESTOBSERVER
// nsIStreamListener methods:
NS_DECL_NSISTREAMLISTENER
void PushContext(CParserContext& aContext);
CParserContext* PopContext();
CParserContext* PeekContext() {return mParserContext;}
/**
*
* @update gess 1/22/99
* @param
* @return
*/
nsresult GetTokenizer(nsITokenizer*& aTokenizer);
/**
* Get the channel associated with this parser
* @update harishd,gagan 07/17/01
* @param aChannel out param that will contain the result
* @return NS_OK if successful
*/
NS_IMETHOD GetChannel(nsIChannel** aChannel);
/**
* Get the DTD associated with this parser
* @update vidur 9/29/99
* @param aDTD out param that will contain the result
* @return NS_OK if successful, NS_ERROR_FAILURE for runtime error
*/
NS_IMETHOD GetDTD(nsIDTD** aDTD);
/**
* Detects the existence of a META tag with charset information in
* the given buffer.
*/
PRBool DetectMetaTag(const char* aBytes,
PRInt32 aLen,
nsCString& oCharset,
PRInt32& oCharsetSource);
void SetSinkCharset(nsACString& aCharset);
/**
* Removes continue parsing events
* @update kmcclusk 5/18/98
*/
NS_IMETHODIMP CancelParsingEvents();
/**
* Indicates whether the parser is in a state where it
* can be interrupted.
* @return PR_TRUE if parser can be interrupted, PR_FALSE if it can not be interrupted.
* @update kmcclusk 5/18/98
*/
PRBool CanInterrupt(void);
/**
* Set to parser state to indicate whether parsing tokens can be interrupted
* @param aCanInterrupt PR_TRUE if parser can be interrupted, PR_FALSE if it can not be interrupted.
* @update kmcclusk 5/18/98
*/
void SetCanInterrupt(PRBool aCanInterrupt);
/**
* This is called when the final chunk has been
* passed to the parser and the content sink has
* interrupted token processing. It schedules
* a ParserContinue PL_Event which will ask the parser
* to HandleParserContinueEvent when it is handled.
* @update kmcclusk6/1/2001
*/
nsresult PostContinueEvent();
/**
* Fired when the continue parse event is triggered.
* @update kmcclusk 5/18/98
*/
void HandleParserContinueEvent(void);
protected:
/**
*
* @update gess5/18/98
* @param
* @return
*/
nsresult WillBuildModel(nsString& aFilename);
/**
*
* @update gess5/18/98
* @param
* @return
*/
nsresult DidBuildModel(nsresult anErrorCode);
private:
/*******************************************
These are the tokenization methods...
*******************************************/
/**
* Part of the code sandwich, this gets called right before
* the tokenization process begins. The main reason for
* this call is to allow the delegate to do initialization.
*
* @update gess 3/25/98
* @param
* @return TRUE if it's ok to proceed
*/
PRBool WillTokenize(PRBool aIsFinalChunk = PR_FALSE);
/**
* This is the primary control routine. It iteratively
* consumes tokens until an error occurs or you run out
* of data.
*
* @update gess 3/25/98
* @return error code
*/
nsresult Tokenize(PRBool aIsFinalChunk = PR_FALSE);
/**
* This is the tail-end of the code sandwich for the
* tokenization process. It gets called once tokenziation
* has completed.
*
* @update gess 3/25/98
* @param
* @return TRUE if all went well
*/
PRBool DidTokenize(PRBool aIsFinalChunk = PR_FALSE);
protected:
//*********************************************
// And now, some data members...
//*********************************************
nsCOMPtr<nsIEventQueue> mEventQueue;
CParserContext* mParserContext;
nsCOMPtr<nsIRequestObserver> mObserver;
nsCOMPtr<nsIContentSink> mSink;
nsCOMPtr<nsIParserFilter> mParserFilter;
nsTokenAllocator mTokenAllocator;
eParserCommands mCommand;
nsresult mInternalState;
PRInt32 mStreamStatus;
PRInt32 mCharsetSource;
PRUint16 mFlags;
nsString mUnusedInput;
nsCString mCharset;
nsString mCommandStr;
public:
MOZ_TIMER_DECLARE(mParseTime)
MOZ_TIMER_DECLARE(mDTDTime)
MOZ_TIMER_DECLARE(mTokenizeTime)
};
#endif

Просмотреть файл

@ -1,136 +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 Communicator client 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):
* Pierre Phaneuf <pp@ludusdesign.com>
*
* 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 "nsString.h"
#include "nspr.h"
#include "nsCOMPtr.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsParserCIID.h"
#include "nsParser.h"
#include "CNavDTD.h"
#include "COtherDTD.h"
#include "nsHTMLEntities.h"
#include "nsHTMLTokenizer.h"
//#include "nsTextTokenizer.h"
#include "nsElementTable.h"
#include "nsParserService.h"
#ifdef MOZ_VIEW_SOURCE
#include "nsViewSourceHTML.h"
#endif
#ifdef NS_DEBUG
#include "nsLoggingSink.h"
#include "nsExpatDriver.h"
#endif
//----------------------------------------------------------------------
#ifdef NS_DEBUG
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLoggingSink)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsExpatDriver)
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParser)
NS_GENERIC_FACTORY_CONSTRUCTOR(CNavDTD)
NS_GENERIC_FACTORY_CONSTRUCTOR(CTransitionalDTD)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParserService)
#ifdef MOZ_VIEW_SOURCE
NS_GENERIC_FACTORY_CONSTRUCTOR(CViewSourceHTML)
#endif
static const nsModuleComponentInfo gComponents[] = {
#ifdef NS_DEBUG
{ "Logging sink", NS_LOGGING_SINK_CID, NULL, nsLoggingSinkConstructor },
{ "Expat Driver", NS_EXPAT_DRIVER_CID, NULL, nsExpatDriverConstructor },
#endif
{ "Parser", NS_PARSER_CID, NULL, nsParserConstructor },
{ "Navigator HTML DTD", NS_CNAVDTD_CID, NULL, CNavDTDConstructor },
{ "Transitional DTD", NS_CTRANSITIONAL_DTD_CID, NULL,
CTransitionalDTDConstructor },
#ifdef MOZ_VIEW_SOURCE
{ "ViewSource DTD", NS_VIEWSOURCE_DTD_CID, NULL, CViewSourceHTMLConstructor },
#endif
{ "ParserService",
NS_PARSERSERVICE_CID,
NS_PARSER_CONTRACTID_PREFIX "/parser-service;1",
nsParserServiceConstructor
}
};
static PRBool gInitialized = PR_FALSE;
PR_STATIC_CALLBACK(nsresult)
Initialize(nsIModule* aSelf)
{
if (!gInitialized) {
nsresult rv = nsHTMLTags::AddRefTable();
NS_ENSURE_SUCCESS(rv, rv);
rv = nsHTMLEntities::AddRefTable();
if (NS_FAILED(rv)) {
nsHTMLTags::ReleaseTable();
return rv;
}
InitializeElementTable();
CNewlineToken::AllocNewline();
gInitialized = PR_TRUE;
}
return NS_OK;
}
PR_STATIC_CALLBACK(void)
Shutdown(nsIModule* aSelf)
{
if (gInitialized) {
nsHTMLTags::ReleaseTable();
nsHTMLEntities::ReleaseTable();
nsDTDContext::ReleaseGlobalObjects();
nsParser::FreeSharedObjects();
DeleteElementTable();
CNewlineToken::FreeNewline();
gInitialized = PR_FALSE;
}
}
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsParserModule, gComponents, Initialize, Shutdown)

Просмотреть файл

@ -1,101 +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 "nsIServiceManager.h"
#include "nsIStringBundle.h"
#include "nsXPIDLString.h"
#include "nsParserMsgUtils.h"
#include "nsNetCID.h"
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
// This code is derived from nsFormControlHelper::GetLocalizedString()
static nsresult GetBundle(const char * aPropFileName, nsIStringBundle **aBundle)
{
NS_ENSURE_ARG_POINTER(aPropFileName);
NS_ENSURE_ARG_POINTER(aBundle);
// Create a bundle for the localization
nsresult rv;
nsCOMPtr<nsIStringBundleService> stringService =
do_GetService(kStringBundleServiceCID, &rv);
if (NS_SUCCEEDED(rv))
rv = stringService->CreateBundle(aPropFileName, aBundle);
return rv;
}
nsresult
nsParserMsgUtils::GetLocalizedStringByName(const char * aPropFileName, const char* aKey, nsString& oVal)
{
oVal.Truncate();
NS_ENSURE_ARG_POINTER(aKey);
nsCOMPtr<nsIStringBundle> bundle;
nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle));
if (NS_SUCCEEDED(rv) && bundle) {
nsXPIDLString valUni;
nsAutoString key; key.AssignWithConversion(aKey);
rv = bundle->GetStringFromName(key.get(), getter_Copies(valUni));
if (NS_SUCCEEDED(rv) && valUni) {
oVal.Assign(valUni);
}
}
return rv;
}
nsresult
nsParserMsgUtils::GetLocalizedStringByID(const char * aPropFileName, PRUint32 aID, nsString& oVal)
{
oVal.Truncate();
nsCOMPtr<nsIStringBundle> bundle;
nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle));
if (NS_SUCCEEDED(rv) && bundle) {
nsXPIDLString valUni;
rv = bundle->GetStringFromID(aID, getter_Copies(valUni));
if (NS_SUCCEEDED(rv) && valUni) {
oVal.Assign(valUni);
}
}
return rv;
}

Просмотреть файл

@ -1,53 +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 ***** */
#ifndef nsParserMsgUtils_h
#define nsParserMsgUtils_h
#include "nsString.h"
#define XMLPARSER_PROPERTIES "chrome://communicator/locale/layout/xmlparser.properties"
class nsParserMsgUtils {
nsParserMsgUtils(); // Currently this is not meant to be created, use the static methods
~nsParserMsgUtils(); // If perf required, change this to cache values etc.
public:
static nsresult GetLocalizedStringByName(const char * aPropFileName, const char* aKey, nsString& aVal);
static nsresult GetLocalizedStringByID(const char * aPropFileName, PRUint32 aID, nsString& aVal);
};
#endif

Просмотреть файл

@ -1,387 +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 <string.h>
#include "nsHTMLTokens.h"
#include "nsITokenizer.h"
#include "nsDTDUtils.h"
/**
* Default Constructor
*/
nsCParserNode::nsCParserNode()
: mRefCnt(0), mGenericState(PR_FALSE), mUseCount(0), mToken(nsnull),
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)
: mRefCnt(0), mGenericState(PR_FALSE), mUseCount(0), mToken(aToken),
mTokenAllocator(aTokenAllocator)
{
MOZ_COUNT_CTOR(nsCParserNode);
static int theNodeCount = 0;
++theNodeCount;
IF_HOLD(mToken);
#ifdef HEAP_ALLOCATED_NODES
mNodeAllocator = aNodeAllocator;
#endif
}
/**
* 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;
}

Просмотреть файл

@ -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();
PRPackedBool mGenericState;
PRInt32 mUseCount;
CToken* mToken;
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

Просмотреть файл

@ -1,274 +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 Communicator client 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 "nsDOMError.h"
#include "nsIAtom.h"
#include "nsParserService.h"
#include "nsHTMLEntities.h"
#include "nsElementTable.h"
#include "nsICategoryManager.h"
#include "nsCategoryManagerUtils.h"
extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
int ns_aware, const char** colon);
nsParserService::nsParserService() : mEntries(0)
{
mHaveNotifiedCategoryObservers = PR_FALSE;
}
nsParserService::~nsParserService()
{
nsObserverEntry *entry = nsnull;
while( (entry = NS_STATIC_CAST(nsObserverEntry*,mEntries.Pop())) ) {
NS_RELEASE(entry);
}
}
NS_IMPL_ISUPPORTS1(nsParserService, nsIParserService)
NS_IMETHODIMP
nsParserService::HTMLAtomTagToId(nsIAtom* aAtom, PRInt32* aId) const
{
nsAutoString tagName;
aAtom->ToString(tagName);
*aId = nsHTMLTags::LookupTag(tagName);
return NS_OK;
}
NS_IMETHODIMP
nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom,
PRInt32* aId) const
{
nsAutoString tagName;
aAtom->ToString(tagName);
*aId = nsHTMLTags::CaseSensitiveLookupTag(tagName.get());
return NS_OK;
}
NS_IMETHODIMP
nsParserService::HTMLStringTagToId(const nsAString &aTagName,
PRInt32* aId) const
{
*aId = nsHTMLTags::LookupTag(aTagName);
return NS_OK;
}
NS_IMETHODIMP
nsParserService::HTMLIdToStringTag(PRInt32 aId,
const PRUnichar **aTagName) const
{
*aTagName = nsHTMLTags::GetStringValue((nsHTMLTag)aId);
return NS_OK;
}
NS_IMETHODIMP
nsParserService::HTMLConvertEntityToUnicode(const nsAString& aEntity,
PRInt32* aUnicode) const
{
*aUnicode = nsHTMLEntities::EntityToUnicode(aEntity);
return NS_OK;
}
NS_IMETHODIMP
nsParserService::HTMLConvertUnicodeToEntity(PRInt32 aUnicode,
nsCString& aEntity) const
{
const char* str = nsHTMLEntities::UnicodeToEntity(aUnicode);
if (str) {
aEntity.Assign(str);
}
return NS_OK;
}
NS_IMETHODIMP
nsParserService::IsContainer(PRInt32 aId, PRBool& aIsContainer) const
{
aIsContainer = nsHTMLElement::IsContainer((eHTMLTags)aId);
return NS_OK;
}
NS_IMETHODIMP
nsParserService::IsBlock(PRInt32 aId, PRBool& aIsBlock) const
{
if((aId>eHTMLTag_unknown) && (aId<eHTMLTag_userdefined)) {
aIsBlock=((gHTMLElements[aId].IsMemberOf(kBlock)) ||
(gHTMLElements[aId].IsMemberOf(kBlockEntity)) ||
(gHTMLElements[aId].IsMemberOf(kHeading)) ||
(gHTMLElements[aId].IsMemberOf(kPreformatted))||
(gHTMLElements[aId].IsMemberOf(kList)));
}
else {
aIsBlock = PR_FALSE;
}
return NS_OK;
}
NS_IMETHODIMP
nsParserService::RegisterObserver(nsIElementObserver* aObserver,
const nsAString& aTopic,
const eHTMLTags* aTags)
{
nsresult result = NS_OK;
nsObserverEntry* entry = GetEntry(aTopic);
if(!entry) {
result = CreateEntry(aTopic,&entry);
NS_ENSURE_SUCCESS(result,result);
}
while (*aTags) {
if(*aTags != eHTMLTag_userdefined && *aTags <= NS_HTML_TAG_MAX) {
entry->AddObserver(aObserver,*aTags);
}
++aTags;
}
return result;
}
NS_IMETHODIMP
nsParserService::UnregisterObserver(nsIElementObserver* aObserver,
const nsAString& aTopic)
{
PRInt32 count = mEntries.GetSize();
for (PRInt32 i=0; i < count; ++i) {
nsObserverEntry* entry = NS_STATIC_CAST(nsObserverEntry*,mEntries.ObjectAt(i));
if (entry && entry->Matches(aTopic)) {
entry->RemoveObserver(aObserver);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsParserService::GetTopicObservers(const nsAString& aTopic,
nsIObserverEntry** aEntry) {
nsresult result = NS_OK;
nsObserverEntry* entry = GetEntry(aTopic);
if (!entry) {
return NS_ERROR_NULL_POINTER;
}
NS_ADDREF(*aEntry = entry);
return result;
}
nsresult
nsParserService::CheckQName(const nsASingleFragmentString& aQName,
PRBool aNamespaceAware,
const PRUnichar** aColon)
{
const char* colon;
const PRUnichar *begin, *end;
aQName.BeginReading(begin);
aQName.EndReading(end);
int result = MOZ_XMLCheckQName(NS_REINTERPRET_CAST(const char*, begin),
NS_REINTERPRET_CAST(const char*, end),
aNamespaceAware, &colon);
*aColon = NS_REINTERPRET_CAST(const PRUnichar*, colon);
if (result == 0) {
return NS_OK;
}
// MOZ_EXPAT_EMPTY_QNAME || MOZ_EXPAT_INVALID_CHARACTER
if (result & (1 << 0) || result & (1 << 1)) {
return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
}
return NS_ERROR_DOM_NAMESPACE_ERR;
}
class nsMatchesTopic : public nsDequeFunctor{
const nsAString& mString;
public:
PRBool matched;
nsObserverEntry* entry;
nsMatchesTopic(const nsAString& aString):mString(aString),matched(PR_FALSE){};
virtual void* operator()(void* anObject){
entry=NS_STATIC_CAST(nsObserverEntry*, anObject);
matched=mString.Equals(entry->mTopic);
return matched ? nsnull : anObject;
};
};
// XXX This may be more efficient as a HashTable instead of linear search
nsObserverEntry*
nsParserService::GetEntry(const nsAString& aTopic)
{
if (!mHaveNotifiedCategoryObservers) {
mHaveNotifiedCategoryObservers = PR_TRUE;
NS_CreateServicesFromCategory("parser-service-category",
NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(void*,this)),
"parser-service-start");
}
nsMatchesTopic matchesTopic(aTopic);
mEntries.FirstThat(*&matchesTopic);
return matchesTopic.matched?matchesTopic.entry:nsnull;
}
nsresult
nsParserService::CreateEntry(const nsAString& aTopic, nsObserverEntry** aEntry)
{
*aEntry = new nsObserverEntry(aTopic);
if (!aEntry) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aEntry);
mEntries.Push(*aEntry);
return NS_OK;
}

Просмотреть файл

@ -1,102 +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 Communicator client 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 ***** */
#ifndef NS_PARSERSERVICE_H__
#define NS_PARSERSERVICE_H__
#include "nsIParserService.h"
#include "nsDTDUtils.h"
#include "nsVoidArray.h"
extern "C" int MOZ_XMLIsLetter(const char* ptr);
extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
class nsParserService : public nsIParserService {
public:
nsParserService();
virtual ~nsParserService();
NS_DECL_ISUPPORTS
NS_IMETHOD HTMLAtomTagToId(nsIAtom* aAtom, PRInt32* aId) const;
NS_IMETHOD HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom, PRInt32* aId) const;
NS_IMETHOD HTMLStringTagToId(const nsAString &aTagName,
PRInt32* aId) const;
NS_IMETHOD HTMLIdToStringTag(PRInt32 aId, const PRUnichar **aTagName) const;
NS_IMETHOD HTMLConvertEntityToUnicode(const nsAString& aEntity,
PRInt32* aUnicode) const;
NS_IMETHOD HTMLConvertUnicodeToEntity(PRInt32 aUnicode,
nsCString& aEntity) const;
NS_IMETHOD IsContainer(PRInt32 aId, PRBool& aIsContainer) const;
NS_IMETHOD IsBlock(PRInt32 aId, PRBool& aIsBlock) const;
// Observer mechanism
NS_IMETHOD RegisterObserver(nsIElementObserver* aObserver,
const nsAString& aTopic,
const eHTMLTags* aTags = nsnull);
NS_IMETHOD UnregisterObserver(nsIElementObserver* aObserver,
const nsAString& aTopic);
NS_IMETHOD GetTopicObservers(const nsAString& aTopic,
nsIObserverEntry** aEntry);
nsresult CheckQName(const nsASingleFragmentString& aQName,
PRBool aNamespaceAware, const PRUnichar** aColon);
PRBool IsXMLLetter(PRUnichar aChar)
{
return MOZ_XMLIsLetter(NS_REINTERPRET_CAST(const char*, &aChar));
}
PRBool IsXMLNCNameChar(PRUnichar aChar)
{
return MOZ_XMLIsNCNameChar(NS_REINTERPRET_CAST(const char*, &aChar));
}
protected:
nsObserverEntry* GetEntry(const nsAString& aTopic);
nsresult CreateEntry(const nsAString& aTopic,
nsObserverEntry** aEntry);
nsDeque mEntries; //each topic holds a list of observers per tag.
PRBool mHaveNotifiedCategoryObservers;
};
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -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 ***** */
/**
* MODULE NOTES:
* @update gess 4/1/98
*
* The scanner is a low-level service class that knows
* how to consume characters out of an (internal) stream.
* This class also offers a series of utility methods
* that most tokenizers want, such as readUntil(),
* readWhile() and SkipWhitespace().
*/
#ifndef SCANNER
#define SCANNER
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIParser.h"
#include "prtypes.h"
#include "nsIUnicodeDecoder.h"
#include "nsScannerString.h"
#include "nsIInputStream.h"
class nsReadEndCondition {
public:
const PRUnichar *mChars;
PRUnichar mFilter;
explicit nsReadEndCondition(const PRUnichar* aTerminateChars);
private:
nsReadEndCondition(const nsReadEndCondition& aOther); // No copying
void operator=(const nsReadEndCondition& aOther); // No assigning
};
class nsScanner {
public:
/**
* Use this constructor if you want i/o to be based on
* a single string you hand in during construction.
* This short cut was added for Javascript.
*
* @update ftang 3/02/99
* @param aCharset charset
* @param aCharsetSource - where the charset info came from
* @param aMode represents the parser mode (nav, other)
* @return
*/
nsScanner(const nsAString& anHTMLString, const nsACString& aCharset, PRInt32 aSource);
/**
* Use this constructor if you want i/o to be based on
* a file (therefore a stream) or just data you provide via Append().
*
* @update ftang 3/02/99
* @param aCharset charset
* @param aCharsetSource - where the charset info came from
* @param aMode represents the parser mode (nav, other)
* @return
*/
nsScanner(nsString& aFilename,PRBool aCreateStream, const nsACString& aCharset, PRInt32 aSource);
/**
* Use this constructor if you want i/o to be stream based.
*
* @update ftang 3/02/99
* @param aCharset charset
* @param aCharsetSource - where the charset info came from
* @param aMode represents the parser mode (nav, other)
* @return
*/
nsScanner(const nsAString& aFilename, nsIInputStream* aStream, const nsACString& aCharset, PRInt32 aSource);
~nsScanner();
/**
* retrieve next char from internal input stream
*
* @update gess 3/25/98
* @param ch is the char to accept new value
* @return error code reflecting read status
*/
nsresult GetChar(PRUnichar& ch);
/**
* peek ahead to consume next char from scanner's internal
* input buffer
*
* @update gess 3/25/98
* @param ch is the char to accept new value
* @return error code reflecting read status
*/
nsresult Peek(PRUnichar& ch, PRUint32 aOffset=0);
nsresult Peek(nsAString& aStr, PRInt32 aNumChars);
/**
* Skip over chars as long as they're in aSkipSet
*
* @update gess 3/25/98
* @param set of chars to be skipped
* @return error code
*/
nsresult SkipOver(nsString& SkipChars);
/**
* Skip over chars as long as they equal given char
*
* @update gess 3/25/98
* @param char to be skipped
* @return error code
*/
nsresult SkipOver(PRUnichar aSkipChar);
/**
* Skip over chars until they're in aValidSet
*
* @update gess 3/25/98
* @param aValid set contains chars you're looking for
* @return error code
*/
nsresult SkipTo(nsString& aValidSet);
/**
* Skip over chars as long as they're in aSequence
*
* @update gess 3/25/98
* @param contains sequence to be skipped
* @return error code
*/
nsresult SkipPast(nsString& aSequence);
/**
* Skip whitespace on scanner input stream
*
* @update gess 3/25/98
* @return error status
*/
nsresult SkipWhitespace(PRInt32& aNewlinesSkipped);
/**
* Determine if the scanner has reached EOF.
* This method can also cause the buffer to be filled
* if it happens to be empty
*
* @update gess 3/25/98
* @return PR_TRUE upon eof condition
*/
nsresult Eof(void);
/**
* Consume characters until you run into space, a '<', a '>', or a '/'.
*
* @param aString - receives new data from stream
* @return error code
*/
nsresult ReadTagIdentifier(nsString& aString);
/**
* Consume characters until you run into a char that's not valid in an
* entity name
*
* @param aString - receives new data from stream
* @return error code
*/
nsresult ReadEntityIdentifier(nsString& aString);
nsresult ReadNumber(nsString& aString,PRInt32 aBase);
nsresult ReadWhitespace(nsString& aString,
PRInt32& aNewlinesSkipped);
nsresult ReadWhitespace(nsScannerIterator& aStart,
nsScannerIterator& aEnd,
PRInt32& aNewlinesSkipped);
/**
* Consume characters until you find the terminal char
*
* @update gess 3/25/98
* @param aString receives new data from stream
* @param aTerminal contains terminating char
* @param addTerminal tells us whether to append terminal to aString
* @return error code
*/
nsresult ReadUntil(nsAString& aString,
PRUnichar aTerminal,
PRBool addTerminal);
/**
* Consume characters until you find one contained in given
* terminal set.
*
* @update gess 3/25/98
* @param aString receives new data from stream
* @param aTermSet contains set of terminating chars
* @param addTerminal tells us whether to append terminal to aString
* @return error code
*/
nsresult ReadUntil(nsAString& aString,
const nsReadEndCondition& aEndCondition,
PRBool addTerminal);
nsresult ReadUntil(nsScannerIterator& aStart,
nsScannerIterator& aEnd,
const nsReadEndCondition& aEndCondition,
PRBool addTerminal);
/**
* Consume characters while they're members of anInputSet
*
* @update gess 3/25/98
* @param aString receives new data from stream
* @param anInputSet contains valid chars
* @param addTerminal tells us whether to append terminal to aString
* @return error code
*/
nsresult ReadWhile(nsString& aString,nsString& anInputSet,PRBool addTerminal);
/**
* Records current offset position in input stream. This allows us
* to back up to this point if the need should arise, such as when
* tokenization gets interrupted.
*
* @update gess 5/12/98
* @param
* @return
*/
void Mark(void);
/**
* Resets current offset position of input stream to marked position.
* This allows us to back up to this point if the need should arise,
* such as when tokenization gets interrupted.
* NOTE: IT IS REALLY BAD FORM TO CALL RELEASE WITHOUT CALLING MARK FIRST!
*
* @update gess 5/12/98
* @param
* @return
*/
void RewindToMark(void);
/**
*
*
* @update harishd 01/12/99
* @param
* @return
*/
PRBool UngetReadable(const nsAString& aBuffer);
/**
*
*
* @update gess 5/13/98
* @param
* @return
*/
nsresult Append(const nsAString& aBuffer);
/**
*
*
* @update gess 5/21/98
* @param
* @return
*/
nsresult Append(const char* aBuffer, PRUint32 aLen);
/**
* Call this to copy bytes out of the scanner that have not yet been consumed
* by the tokenization process.
*
* @update gess 5/12/98
* @param aCopyBuffer is where the scanner buffer will be copied to
* @return nada
*/
void CopyUnusedData(nsString& aCopyBuffer);
/**
* Retrieve the name of the file that the scanner is reading from.
* In some cases, it's just a given name, because the scanner isn't
* really reading from a file.
*
* @update gess 5/12/98
* @return
*/
nsString& GetFilename(void);
static void SelfTest();
/**
* Use this setter to change the scanner's unicode decoder
*
* @update ftang 3/02/99
* @param aCharset a normalized (alias resolved) charset name
* @param aCharsetSource- where the charset info came from
* @return
*/
nsresult SetDocumentCharset(const nsACString& aCharset, PRInt32 aSource);
void BindSubstring(nsScannerSubstring& aSubstring, const nsScannerIterator& aStart, const nsScannerIterator& aEnd);
void CurrentPosition(nsScannerIterator& aPosition);
void EndReading(nsScannerIterator& aPosition);
void SetPosition(nsScannerIterator& aPosition,
PRBool aTruncate = PR_FALSE,
PRBool aReverse = PR_FALSE);
void ReplaceCharacter(nsScannerIterator& aPosition,
PRUnichar aChar);
/**
* Internal method used to cause the internal buffer to
* be filled with data.
*
* @update gess4/3/98
*/
PRBool IsIncremental(void) {return mIncremental;}
void SetIncremental(PRBool anIncrValue) {mIncremental=anIncrValue;}
protected:
enum {eBufferSizeThreshold=0x1000}; //4K
/**
* Internal method used to cause the internal buffer to
* be filled with data.
*
* @update gess4/3/98
*/
nsresult FillBuffer(void);
void AppendToBuffer(nsScannerString::Buffer*);
void AppendToBuffer(const nsAString& aStr) { AppendToBuffer(nsScannerString::AllocBufferFromString(aStr)); }
void AppendASCIItoBuffer(const char* aData, PRUint32 aLen);
nsCOMPtr<nsIInputStream> mInputStream;
nsScannerString* mSlidingBuffer;
nsScannerIterator mCurrentPosition; // The position we will next read from in the scanner buffer
nsScannerIterator mMarkPosition; // The position last marked (we may rewind to here)
nsScannerIterator mEndPosition; // The current end of the scanner buffer
nsString mFilename;
PRUint32 mCountRemaining; // The number of bytes still to be read
// from the scanner buffer
PRUint32 mTotalRead;
PRPackedBool mIncremental;
PRInt32 mCharsetSource;
nsCString mCharset;
nsIUnicodeDecoder *mUnicodeDecoder;
};
#endif

Просмотреть файл

@ -1,578 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** 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.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 <stdlib.h>
#include "nsScannerString.h"
/**
* nsScannerBufferList
*/
nsScannerBufferList::Buffer*
nsScannerBufferList::AllocBufferFromString( const nsAString& aString )
{
PRUint32 len = aString.Length();
Buffer* buf = (Buffer*) malloc(sizeof(Buffer) + (len + 1) * sizeof(PRUnichar));
if (buf)
{
// leave PRCList members of Buffer uninitialized
buf->mUsageCount = 0;
buf->mDataEnd = buf->DataStart() + len;
nsAString::const_iterator source;
aString.BeginReading(source);
nsCharTraits<PRUnichar>::copy(buf->DataStart(), source.get(), len);
// XXX null terminate. this shouldn't be required, but we do it because
// nsScanner erroneously thinks it can dereference DataEnd :-(
*buf->mDataEnd = PRUnichar(0);
}
return buf;
}
nsScannerBufferList::Buffer*
nsScannerBufferList::AllocBuffer( PRUint32 capacity )
{
Buffer* buf = (Buffer*) malloc(sizeof(Buffer) + (capacity + 1) * sizeof(PRUnichar));
if (buf)
{
// leave PRCList members of Buffer uninitialized
buf->mUsageCount = 0;
buf->mDataEnd = buf->DataStart() + capacity;
// XXX null terminate. this shouldn't be required, but we do it because
// nsScanner erroneously thinks it can dereference DataEnd :-(
*buf->mDataEnd = PRUnichar(0);
}
return buf;
}
void
nsScannerBufferList::ReleaseAll()
{
while (!PR_CLIST_IS_EMPTY(&mBuffers))
{
PRCList* node = PR_LIST_HEAD(&mBuffers);
PR_REMOVE_LINK(node);
//printf(">>> freeing buffer @%p\n", node);
free(NS_STATIC_CAST(Buffer*, node));
}
}
void
nsScannerBufferList::SplitBuffer( const Position& pos )
{
// splitting to the right keeps the work string and any extant token
// pointing to and holding a reference count on the same buffer.
Buffer* bufferToSplit = pos.mBuffer;
NS_ASSERTION(bufferToSplit, "null pointer");
PRUint32 splitOffset = pos.mPosition - bufferToSplit->DataStart();
NS_ASSERTION(pos.mPosition >= bufferToSplit->DataStart() &&
splitOffset <= bufferToSplit->DataLength(),
"split offset is outside buffer");
PRUint32 len = bufferToSplit->DataLength() - splitOffset;
Buffer* new_buffer = AllocBuffer(len);
if (new_buffer)
{
nsCharTraits<PRUnichar>::copy(new_buffer->DataStart(),
bufferToSplit->DataStart() + splitOffset,
len);
InsertAfter(new_buffer, bufferToSplit);
bufferToSplit->SetDataLength(splitOffset);
}
}
void
nsScannerBufferList::DiscardUnreferencedPrefix( Buffer* aBuf )
{
if (aBuf == Head())
{
while (!PR_CLIST_IS_EMPTY(&mBuffers) && !Head()->IsInUse())
{
Buffer* buffer = Head();
PR_REMOVE_LINK(buffer);
free(buffer);
}
}
}
size_t
nsScannerBufferList::Position::Distance( const Position& aStart, const Position& aEnd )
{
size_t result = 0;
if (aStart.mBuffer == aEnd.mBuffer)
{
result = aEnd.mPosition - aStart.mPosition;
}
else
{
result = aStart.mBuffer->DataEnd() - aStart.mPosition;
for (Buffer* b = aStart.mBuffer->Next(); b != aEnd.mBuffer; b = b->Next())
result += b->DataLength();
result += aEnd.mPosition - aEnd.mBuffer->DataStart();
}
return result;
}
/**
* nsScannerSubstring
*/
nsScannerSubstring::nsScannerSubstring()
: mStart(nsnull, nsnull)
, mEnd(nsnull, nsnull)
, mBufferList(nsnull)
, mLength(0)
, mIsDirty(PR_TRUE)
{
}
nsScannerSubstring::nsScannerSubstring( const nsAString& s )
: mBufferList(nsnull)
, mIsDirty(PR_TRUE)
{
Rebind(s);
}
nsScannerSubstring::~nsScannerSubstring()
{
release_ownership_of_buffer_list();
}
PRInt32
nsScannerSubstring::CountChar( PRUnichar c ) const
{
/*
re-write this to use a counting sink
*/
size_type result = 0;
size_type lengthToExamine = Length();
nsScannerIterator iter;
for ( BeginReading(iter); ; )
{
PRInt32 lengthToExamineInThisFragment = iter.size_forward();
const PRUnichar* fromBegin = iter.get();
result += size_type(NS_COUNT(fromBegin, fromBegin+lengthToExamineInThisFragment, c));
if ( !(lengthToExamine -= lengthToExamineInThisFragment) )
return result;
iter.advance(lengthToExamineInThisFragment);
}
// never reached; quiets warnings
return 0;
}
void
nsScannerSubstring::Rebind( const nsScannerSubstring& aString,
const nsScannerIterator& aStart,
const nsScannerIterator& aEnd )
{
// allow for the case where &aString == this
aString.acquire_ownership_of_buffer_list();
release_ownership_of_buffer_list();
mStart = aStart;
mEnd = aEnd;
mBufferList = aString.mBufferList;
mLength = Distance(aStart, aEnd);
mIsDirty = PR_TRUE;
}
void
nsScannerSubstring::Rebind( const nsAString& aString )
{
release_ownership_of_buffer_list();
mBufferList = new nsScannerBufferList(AllocBufferFromString(aString));
mIsDirty = PR_TRUE;
init_range_from_buffer_list();
acquire_ownership_of_buffer_list();
}
const nsString&
nsScannerSubstring::AsString() const
{
if (mIsDirty)
{
nsScannerSubstring* mutable_this = NS_CONST_CAST(nsScannerSubstring*, this);
nsScannerIterator start, end;
CopyUnicodeTo(BeginReading(start), EndReading(end), mutable_this->mFlattenedRep);
mutable_this->mIsDirty = PR_FALSE;
}
return mFlattenedRep;
}
nsScannerIterator&
nsScannerSubstring::BeginReading( nsScannerIterator& iter ) const
{
iter.mOwner = this;
iter.mFragment.mBuffer = mStart.mBuffer;
iter.mFragment.mFragmentStart = mStart.mPosition;
if (mStart.mBuffer == mEnd.mBuffer)
iter.mFragment.mFragmentEnd = mEnd.mPosition;
else
iter.mFragment.mFragmentEnd = mStart.mBuffer->DataEnd();
iter.mPosition = mStart.mPosition;
iter.normalize_forward();
return iter;
}
nsScannerIterator&
nsScannerSubstring::EndReading( nsScannerIterator& iter ) const
{
iter.mOwner = this;
iter.mFragment.mBuffer = mEnd.mBuffer;
iter.mFragment.mFragmentEnd = mEnd.mPosition;
if (mStart.mBuffer == mEnd.mBuffer)
iter.mFragment.mFragmentStart = mStart.mPosition;
else
iter.mFragment.mFragmentStart = mEnd.mBuffer->DataStart();
iter.mPosition = mEnd.mPosition;
// must not |normalize_backward| as that would likely invalidate tests like |while ( first != last )|
return iter;
}
PRBool
nsScannerSubstring::GetNextFragment( nsScannerFragment& frag ) const
{
// check to see if we are at the end of the buffer list
if (frag.mBuffer == mEnd.mBuffer)
return PR_FALSE;
frag.mBuffer = NS_STATIC_CAST(const Buffer*, PR_NEXT_LINK(frag.mBuffer));
if (frag.mBuffer == mStart.mBuffer)
frag.mFragmentStart = mStart.mPosition;
else
frag.mFragmentStart = frag.mBuffer->DataStart();
if (frag.mBuffer == mEnd.mBuffer)
frag.mFragmentEnd = mEnd.mPosition;
else
frag.mFragmentEnd = frag.mBuffer->DataEnd();
return PR_TRUE;
}
PRBool
nsScannerSubstring::GetPrevFragment( nsScannerFragment& frag ) const
{
// check to see if we are at the beginning of the buffer list
if (frag.mBuffer == mStart.mBuffer)
return PR_FALSE;
frag.mBuffer = NS_STATIC_CAST(const Buffer*, PR_PREV_LINK(frag.mBuffer));
if (frag.mBuffer == mStart.mBuffer)
frag.mFragmentStart = mStart.mPosition;
else
frag.mFragmentStart = frag.mBuffer->DataStart();
if (frag.mBuffer == mEnd.mBuffer)
frag.mFragmentEnd = mEnd.mPosition;
else
frag.mFragmentEnd = frag.mBuffer->DataEnd();
return PR_TRUE;
}
/**
* nsScannerString
*/
nsScannerString::nsScannerString( Buffer* aBuf )
{
mBufferList = new nsScannerBufferList(aBuf);
init_range_from_buffer_list();
acquire_ownership_of_buffer_list();
}
void
nsScannerString::AppendBuffer( Buffer* aBuf )
{
mBufferList->Append(aBuf);
mLength += aBuf->DataLength();
mEnd.mBuffer = aBuf;
mEnd.mPosition = aBuf->DataEnd();
mIsDirty = PR_TRUE;
}
void
nsScannerString::DiscardPrefix( const nsScannerIterator& aIter )
{
Position old_start(mStart);
mStart = aIter;
mLength -= Position::Distance(old_start, mStart);
mStart.mBuffer->IncrementUsageCount();
old_start.mBuffer->DecrementUsageCount();
mBufferList->DiscardUnreferencedPrefix(old_start.mBuffer);
mIsDirty = PR_TRUE;
}
void
nsScannerString::UngetReadable( const nsAString& aReadable, const nsScannerIterator& aInsertPoint )
/*
* Warning: this routine manipulates the shared buffer list in an unexpected way.
* The original design did not really allow for insertions, but this call promises
* that if called for a point after the end of all extant token strings, that no token string
* or the work string will be invalidated.
*
* This routine is protected because it is the responsibility of the derived class to keep those promises.
*/
{
Position insertPos(aInsertPoint);
mBufferList->SplitBuffer(insertPos);
// splitting to the right keeps the work string and any extant token pointing to and
// holding a reference count on the same buffer
Buffer* new_buffer = AllocBufferFromString(aReadable);
// make a new buffer with all the data to insert...
// BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost
// of this and decide if we should do the work to fill it
Buffer* buffer_to_split = insertPos.mBuffer;
mBufferList->InsertAfter(new_buffer, buffer_to_split);
mLength += aReadable.Length();
mEnd.mBuffer = mBufferList->Tail();
mEnd.mPosition = mEnd.mBuffer->DataEnd();
mIsDirty = PR_TRUE;
}
void
nsScannerString::ReplaceCharacter(nsScannerIterator& aPosition, PRUnichar aChar)
{
// XXX Casting a const to non-const. Unless the base class
// provides support for writing iterators, this is the best
// that can be done.
PRUnichar* pos = NS_CONST_CAST(PRUnichar*, aPosition.get());
*pos = aChar;
mIsDirty = PR_TRUE;
}
/**
* utils -- based on code from nsReadableUtils.cpp
*/
void
CopyUnicodeTo( const nsScannerIterator& aSrcStart,
const nsScannerIterator& aSrcEnd,
nsAString& aDest )
{
nsAString::iterator writer;
aDest.SetLength(Distance(aSrcStart, aSrcEnd));
aDest.BeginWriting(writer);
nsScannerIterator fromBegin(aSrcStart);
copy_string(fromBegin, aSrcEnd, writer);
}
void
AppendUnicodeTo( const nsScannerIterator& aSrcStart,
const nsScannerIterator& aSrcEnd,
nsAString& aDest )
{
nsAString::iterator writer;
PRUint32 oldLength = aDest.Length();
aDest.SetLength(oldLength + Distance(aSrcStart, aSrcEnd));
aDest.BeginWriting(writer).advance(oldLength);
nsScannerIterator fromBegin(aSrcStart);
copy_string(fromBegin, aSrcEnd, writer);
}
PRBool
FindCharInReadable( PRUnichar aChar,
nsScannerIterator& aSearchStart,
const nsScannerIterator& aSearchEnd )
{
while ( aSearchStart != aSearchEnd )
{
PRInt32 fragmentLength;
if ( SameFragment(aSearchStart, aSearchEnd) )
fragmentLength = aSearchEnd.get() - aSearchStart.get();
else
fragmentLength = aSearchStart.size_forward();
const PRUnichar* charFoundAt = nsCharTraits<PRUnichar>::find(aSearchStart.get(), fragmentLength, aChar);
if ( charFoundAt ) {
aSearchStart.advance( charFoundAt - aSearchStart.get() );
return PR_TRUE;
}
aSearchStart.advance(fragmentLength);
}
return PR_FALSE;
}
PRBool
FindInReadable( const nsAString& aPattern,
nsScannerIterator& aSearchStart,
nsScannerIterator& aSearchEnd,
const nsStringComparator& compare )
{
PRBool found_it = PR_FALSE;
// only bother searching at all if we're given a non-empty range to search
if ( aSearchStart != aSearchEnd )
{
nsAString::const_iterator aPatternStart, aPatternEnd;
aPattern.BeginReading(aPatternStart);
aPattern.EndReading(aPatternEnd);
// outer loop keeps searching till we find it or run out of string to search
while ( !found_it )
{
// fast inner loop (that's what it's called, not what it is) looks for a potential match
while ( aSearchStart != aSearchEnd &&
compare(*aPatternStart, *aSearchStart) )
++aSearchStart;
// if we broke out of the `fast' loop because we're out of string ... we're done: no match
if ( aSearchStart == aSearchEnd )
break;
// otherwise, we're at a potential match, let's see if we really hit one
nsAString::const_iterator testPattern(aPatternStart);
nsScannerIterator testSearch(aSearchStart);
// slow inner loop verifies the potential match (found by the `fast' loop) at the current position
for(;;)
{
// we already compared the first character in the outer loop,
// so we'll advance before the next comparison
++testPattern;
++testSearch;
// if we verified all the way to the end of the pattern, then we found it!
if ( testPattern == aPatternEnd )
{
found_it = PR_TRUE;
aSearchEnd = testSearch; // return the exact found range through the parameters
break;
}
// if we got to end of the string we're searching before we hit the end of the
// pattern, we'll never find what we're looking for
if ( testSearch == aSearchEnd )
{
aSearchStart = aSearchEnd;
break;
}
// else if we mismatched ... it's time to advance to the next search position
// and get back into the `fast' loop
if ( compare(*testPattern, *testSearch) )
{
++aSearchStart;
break;
}
}
}
}
return found_it;
}
/**
* This implementation is simple, but does too much work.
* It searches the entire string from left to right, and returns the last match found, if any.
* This implementation will be replaced when I get |reverse_iterator|s working.
*/
PRBool
RFindInReadable( const nsAString& aPattern,
nsScannerIterator& aSearchStart,
nsScannerIterator& aSearchEnd,
const nsStringComparator& aComparator )
{
PRBool found_it = PR_FALSE;
nsScannerIterator savedSearchEnd(aSearchEnd);
nsScannerIterator searchStart(aSearchStart), searchEnd(aSearchEnd);
while ( searchStart != searchEnd )
{
if ( FindInReadable(aPattern, searchStart, searchEnd, aComparator) )
{
found_it = PR_TRUE;
// this is the best match so far, so remember it
aSearchStart = searchStart;
aSearchEnd = searchEnd;
// ...and get ready to search some more
// (it's tempting to set |searchStart=searchEnd| ... but that misses overlapping patterns)
++searchStart;
searchEnd = savedSearchEnd;
}
}
// if we never found it, return an empty range
if ( !found_it )
aSearchStart = aSearchEnd;
return found_it;
}

Просмотреть файл

@ -1,176 +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());
}
/**
* 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;
}
/**
*
* @update gess 3/25/98
*/
void CToken::SelfTest(void) {
#ifdef _DEBUG
#endif
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,143 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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/8/98
*
*
*/
#ifndef __NS_VIEWSOURCE_HTML_
#define __NS_VIEWSOURCE_HTML_
#include "nsIDTD.h"
#include "nsISupports.h"
#include "nsHTMLTokens.h"
#include "nsIHTMLContentSink.h"
#include "nsDTDUtils.h"
#include "nsParserNode.h"
#define NS_VIEWSOURCE_HTML_IID \
{0xb6003010, 0x7932, 0x11d2, \
{0x80, 0x1b, 0x0, 0x60, 0x8, 0xbf, 0xc4, 0x89 }}
class nsIParserNode;
class nsParser;
class nsITokenizer;
class nsCParserNode;
class CViewSourceHTML: public nsIDTD
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDTD
CViewSourceHTML();
virtual ~CViewSourceHTML();
/**
* Set this to TRUE if you want the DTD to verify its
* context stack.
* @update gess 7/23/98
* @param
* @return
*/
virtual void SetVerification(PRBool aEnable);
private:
nsresult WriteTag(PRInt32 tagType,
const nsAString &aText,
PRInt32 attrCount,
PRBool aNewlineRequired);
nsresult WriteAttributes(PRInt32 attrCount);
nsresult GenerateSummary();
void StartNewPreBlock(void);
// Utility method for adding attributes to the nodes we generate
void AddAttrToNode(nsCParserStartNode& aNode,
nsTokenAllocator* aAllocator,
const nsAString& aAttrName,
const nsAString& aAttrValue);
protected:
nsParser* mParser;
nsIHTMLContentSink* mSink;
PRInt32 mLineNumber;
nsITokenizer* mTokenizer; // weak
PRInt32 mStartTag;
PRInt32 mEndTag;
PRInt32 mCommentTag;
PRInt32 mCDATATag;
PRInt32 mMarkupDeclaration;
PRInt32 mDocTypeTag;
PRInt32 mPITag;
PRInt32 mEntityTag;
PRInt32 mText;
PRInt32 mKey;
PRInt32 mValue;
PRInt32 mPopupTag;
PRInt32 mSummaryTag;
PRPackedBool mSyntaxHighlight;
PRPackedBool mWrapLongLines;
PRPackedBool mHasOpenRoot;
PRPackedBool mHasOpenBody;
nsDTDMode mDTDMode;
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...
eParserDocType mDocType;
nsCString mMimeType;
PRInt32 mErrorCount;
PRInt32 mTagCount;
nsString mFilename;
nsString mTags;
nsString mErrors;
PRUint32 mTokenCount;
};
extern nsresult NS_NewViewSourceHTML(nsIDTD** aInstancePtrResult);
#endif

Просмотреть файл

@ -1,42 +0,0 @@
[gecko]
#if SHARED_LIBRARY
dist/bin/components/@SHARED_LIBRARY@
#else
!staticcomp @LIBRARY@ @MODULE_NAME@
#endif
!xpt dist/bin/components/htmlparser.xpt
#if ENABLE_TESTS
[gecko-tests]
dist/bin/htmlrobot@BINS@
dist/bin/TestOutput@BINS@
dist/bin/TestOutSinks.pl
dist/bin/grabpage@BINS@
dist/bin/TestParser@BINS@
#if OS_ARCH==WINNT
dist/bin/@DLLP@dbgrobot@DLLS@
#else
dist/bin/@DLLP@DebugRobot@DLLS@
#endif
dist/bin/OutTestData/plain.html
dist/bin/OutTestData/plainwrap.out
dist/bin/OutTestData/plainnowrap.out
dist/bin/OutTestData/simple.html
dist/bin/OutTestData/simplecopy.out
dist/bin/OutTestData/simplefmt.out
dist/bin/OutTestData/entityxif.xif
dist/bin/OutTestData/entityxif.out
dist/bin/OutTestData/mailquote.html
dist/bin/OutTestData/mailquote.out
dist/bin/OutTestData/htmltable.html
dist/bin/OutTestData/htmltable.out
dist/bin/OutTestData/xifstuff.xif
dist/bin/OutTestData/xifstuff.out
dist/bin/OutTestData/doctype.xif
dist/bin/OutTestData/xifdtplain.out
dist/bin/OutTestData/xifdthtml.out
dist/bin/OutTestData/simplemail.html
dist/bin/OutTestData/simplemail.out
#endif

Просмотреть файл

@ -1,69 +0,0 @@
# ***** 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) 2001
# 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 *****
# Map Expat error codes to error strings
1 = out of memory
2 = syntax error
3 = no element found
4 = not well-formed
5 = unclosed token
6 = unclosed token
7 = mismatched tag
8 = duplicate attribute
9 = junk after document element
10 = illegal parameter entity reference
11 = undefined entity
12 = recursive entity reference
13 = asynchronous entity
14 = reference to invalid character number
15 = reference to binary entity
16 = reference to external entity in attribute
17 = xml processing instruction not at start of external entity
18 = unknown encoding
19 = encoding specified in XML declaration is incorrect
20 = unclosed CDATA section
21 = error in processing external entity reference
22 = document is not standalone
# %1$S is replaced by the Expat error string, may be followed by Expected (see below)
# %2$S is replaced by URL
# %3$d is replaced by line number
# %4$d is replaced by column number
XMLParsingError = XML Parsing Error: %1$S\nLocation: %2$S\nLine Number %3$d, Column %4$d:
# %S is replaced by a tag name.
# This gets appended to the error string if the error is mismatched tag.
Expected = . Expected: </%S>.

Просмотреть файл

@ -1 +0,0 @@
Makefile

Просмотреть файл

@ -1 +0,0 @@
Makefile

Просмотреть файл

@ -1,308 +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 Communicator client 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 "nsIStreamListener.h"
#include "nsIInputStream.h"
#include "nsIURL.h"
#include "nsNetCID.h"
#include "nsCOMPtr.h"
#include "nsIIOService.h"
#include "nsIChannel.h"
#include "nsILocalFile.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#include "nsIEventQueueService.h"
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static nsIEventQueue* gEventQ = nsnull;
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "prprf.h"
#ifdef XP_WIN
#include <windows.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif
#ifdef XP_UNIX
#include <sys/types.h>
#include <sys/stat.h>
#endif
#ifdef XP_OS2
#include <os2.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif
class StreamToFile : public nsIStreamListener {
public:
StreamToFile(FILE* fp);
NS_DECL_ISUPPORTS
NS_IMETHOD GetBindInfo(nsIURI* aURL);
NS_IMETHOD OnProgress(nsIURI* aURL, PRInt32 Progress, PRInt32 ProgressMax);
NS_IMETHOD OnStatus(nsIURI* aURL, const nsString& aMsg);
NS_IMETHOD OnStartRequest(nsIRequest* aRequest, nsISupports *);
NS_IMETHOD OnDataAvailable(nsIRequest* aRequest, nsISupports *, nsIInputStream *pIStream, PRUint32 aOffset, PRUint32 aCount);
NS_IMETHOD OnStopRequest(nsIRequest* aRequest, nsISupports *, PRUint32 status);
PRBool IsDone() const { return mDone; }
PRBool HaveError() const { return mError; }
protected:
virtual ~StreamToFile();
PRBool mDone;
PRBool mError;
FILE* mFile;
};
StreamToFile::StreamToFile(FILE* fp)
{
mDone = PR_FALSE;
mError = PR_FALSE;
mFile = fp;
}
NS_IMPL_ISUPPORTS1(StreamToFile, nsIStreamListener)
StreamToFile::~StreamToFile()
{
if (nsnull != mFile) {
fclose(mFile);
}
}
NS_IMETHODIMP
StreamToFile::GetBindInfo(nsIURI* aURL)
{
return 0;
}
NS_IMETHODIMP
StreamToFile::OnProgress(nsIURI* aURL, PRInt32 Progress, PRInt32 ProgressMax)
{
return 0;
}
NS_IMETHODIMP
StreamToFile::OnStatus(nsIURI* aURL, const nsString& aMsg)
{
return 0;
}
NS_IMETHODIMP
StreamToFile::OnStartRequest(nsIRequest *aRequest, nsISupports *aSomething)
{
return 0;
}
NS_IMETHODIMP
StreamToFile::OnDataAvailable(
nsIRequest* aRequest,
nsISupports *,
nsIInputStream *pIStream,
PRUint32 aOffset,
PRUint32 aCount)
{
PRUint32 len;
do {
char buffer[4000];
nsresult err = pIStream->Read(buffer, sizeof(buffer), &len);
if (NS_SUCCEEDED(err)) {
if (nsnull != mFile) {
fwrite(buffer, 1, len, mFile);
}
}
} while (len > 0);
return 0;
}
NS_IMETHODIMP
StreamToFile::OnStopRequest(nsIRequest *aRequest, nsISupports *aSomething, PRUint32 status)
{
mDone = PR_TRUE;
if (0 != status) {
mError = PR_TRUE;
}
return 0;
}
//----------------------------------------------------------------------
// This could turn into a handy utility someday...
class PageGrabber {
public:
PageGrabber();
~PageGrabber();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
nsresult Init(nsILocalFile *aDirectory);
nsresult Grab(const nsAFlatCString& aURL);
protected:
nsILocalFile* NextFile(const char* aExtension);
nsILocalFile *mDirectory;
PRInt32 mFileNum;
};
PageGrabber::PageGrabber()
{
}
PageGrabber::~PageGrabber()
{
}
nsresult
PageGrabber::Init(nsILocalFile *aDirectory)
{
mDirectory = aDirectory;
return NS_OK;
}
nsILocalFile*
PageGrabber::NextFile(const char* aExtension)
{
nsCAutoString name(NS_LITERAL_CSTRING("grab."));
name += nsDependentCString(aExtension);
nsIFile *cfile;
mDirectory->Clone(&cfile);
nsCOMPtr<nsILocalFile> file = do_QueryInterface(cfile);
file->AppendRelativeNativePath(name);
file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0660);
return file;
}
nsresult
PageGrabber::Grab(const nsAFlatCString& aURL)
{
nsresult rv;
// Create the Event Queue for this thread...
// Unix needs this
nsCOMPtr<nsIEventQueueService> eventQService =
do_GetService(kEventQueueServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
nsCOMPtr<nsILocalFile> file = NextFile("html");
if (!file) {
return NS_ERROR_OUT_OF_MEMORY;
}
FILE* fp;
rv = file->OpenANSIFileDesc("wb", &fp);
if (NS_FAILED(rv)) {
return rv;
}
printf("Copying ");
fputs(aURL.get(), stdout);
nsAutoString path;
file->GetPath(path);
NS_ConvertUCS2toUTF8 cpath(path);
printf(" to %s\n", cpath.get());
// Create the URL object...
nsCOMPtr<nsIURI> url;
nsCOMPtr<nsIIOService> ioService(do_GetService(kIOServiceCID, &rv));
if (NS_FAILED(rv)) return rv;
rv = ioService->NewURI(aURL, nsnull, nsnull, getter_AddRefs(url));
nsIChannel *channel = nsnull;
rv = ioService->NewChannelFromURI(url, &channel);
if (NS_FAILED(rv)) return rv;
// Start the URL load...
StreamToFile* copier = new StreamToFile(fp);
if (!copier)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(copier);
rv = channel->AsyncOpen(copier, nsnull);
if (NS_FAILED(rv)) {
NS_RELEASE(copier);
return rv;
}
// Enter the message pump to allow the URL load to proceed.
while ( !copier->IsDone() ) {
PLEvent *gEvent;
gEventQ->WaitForEvent(&gEvent);
gEventQ->HandleEvent(gEvent);
}
rv = copier->HaveError() ? NS_ERROR_FAILURE : NS_OK;
NS_RELEASE(copier);
return rv;
}
//----------------------------------------------------------------------
int
main(int argc, char **argv)
{
nsString url_address;
if (argc != 3) {
fprintf(stderr, "Usage: grabpage url directory\n");
return -1;
}
PageGrabber* grabber = new PageGrabber();
if(grabber) {
nsCOMPtr <nsILocalFile> directory(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));;
if (NS_FAILED(directory->InitWithNativePath(nsDependentCString(argv[2])))) {
fprintf(stderr, "InitWithNativePath failed\n");
return -2;
}
grabber->Init(directory);
if (NS_OK != grabber->Grab(nsDependentCString(argv[1]))) {
return -1;
}
}
return 0;
}

Просмотреть файл

@ -1 +0,0 @@
Makefile

Просмотреть файл

@ -1,35 +0,0 @@
<html>
<head>
<title>font test</title>
</head>
<body>
<font face="Arial" size="1">
This is just a font element: 01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</font>
<H1><font face="Arial" size="1">
01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</font></H1>
<H2><font face="Arial" size="1">
01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</font></H2>
<H3><font face="Arial" size="1">
01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</font></H3>
<H4><font face="Arial" size="1">
01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</font></H4>
<H5><font face="Arial" size="1">
01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</font></H5>
<H6><font face="Arial" size="1">
01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</font></H6>
01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<br>
<font face="Arial" size="1">
This is just a font element: 01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
<H1>01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</H1>
<H2>01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</H2>
<H3>01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</H3>
<H4>01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</H4>
<H5>01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</H5>
<H6>01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</H6>
</font>
</body>
</html>

Просмотреть файл

@ -1,18 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<body>
<DL>
<DT style="background-color:red">A line (unclosed)
<DL>
<DT>Should be indented</DT>
</DL>
</DL>
<DL>
<DT>B line (closed)</dt>
<DL>
<DT>Should be indented</DT>
</DL>
</DL>
</body>
</html>

Просмотреть файл

@ -1,14 +0,0 @@
<html><head><title>Testcase for bug 102370</title></head>
<body>
<dl>
<a name="a1">
<dd style="background-color:red">First DD
<dt>First DT
<a name="a2">
<dt>Second DT
<dd>Second DD
</dl>
</body></html>

Просмотреть файл

@ -1,17 +0,0 @@
<html><head></head>
<body>
<table>
<tbody><tr>
<td colspan="2">
<br>
<form>
sometexthere<textarea>&lt;TR&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea><table border="0">
</table></form></td></tr></tbody></table></body></html>

Просмотреть файл

@ -1,8 +0,0 @@
<html><body>
<table>
<p><h3>Please Enter your Homesite Login, E-mail and Password to delete</h3></p>
<form method="POST">
<input type=submit>
</form>
</table>
</body></html>

Просмотреть файл

@ -1,12 +0,0 @@
<html>
<body>
<table border="1" width="100px">
<tr>
<p><caption>caption
<td>
cell
</td>
</tr>
</table>
</body>
</html>

Просмотреть файл

@ -1,20 +0,0 @@
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Developer Studio">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<script>
var value = "should ";
</script>
<!-- Insert HTML here -->
<iframe>
<script language="javascript"> value += "not ";</script>
</iframe>
<script>
value += "see this content";
document.write(value);
</script>
</HTML>

Просмотреть файл

@ -1,18 +0,0 @@
<html>
<head><title> &lt </title></head>
<body>
<FORM>
<TEXTAREA ROWS=8 COLS=50>&lt
<table width="100%"; >
bgcolor= #FFFFFF ;
<tr> &lt
<td> a </td>
</tr>
</table>
</TEXTAREA>
</FORM>
<script>
err()
</script>
</body>
</html>

Просмотреть файл

@ -1,11 +0,0 @@
<html>
<body>
<textarea onclick="dump(this.childNodes.length);">
&gt;<table><tr><td>hellothere</td></tr></table>
Click on the textarea to see it's number of childNodes...
(Should be "1" for the child text)
</textarea>
fdfd
</body>
</html>

Просмотреть файл

@ -1,14 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>parserspace.html</title></head>
<body>
The head and body tags appear side by side in this test: <br>&lt;/HEAD&gt;&lt;BODY&gt;<br> so you <b>should not</b> see an [object Text] between the ending head and beginning body tags.
<br><br>
<script type="text/javascript">
for(i=0; i<3; i++){
var oWhat=document.firstChild.childNodes[i];
document.write(oWhat +"<BR>");
}
</script>undefined<br>undefined<br>undefined<br>
</body></html>

Просмотреть файл

@ -1,24 +0,0 @@
<html>
<head>
<title>MSN Hotmail - Compose</title>
</head>
<body>
<table cellpadding=0 cellspacing=0 bgcolor="#93BEE2" width=100% style="border-left:4px solid #93BEE2;">
<form name="hiddentext"><input type="hidden" name="sigtext" value=""></form>
<form name="composeform" method="POST" action="http://lw9fd.law9.hotmail.msn.com/cgi-bin/premail">
</table>
</td>
</tr>
</form>
</table>
<SCRIPT>
document.write("This is an HTMLFormElement: " + document.composeform);
</SCRIPT>
</body>
</html>

Просмотреть файл

@ -1,12 +0,0 @@
<html>
<head>
<title></title>
</head>
<body>
<iframe src="184029_iframe.html">
</iframe>
</body>
</html>

Просмотреть файл

@ -1,9 +0,0 @@
<SCRIPT>
document.write('\<script\>');
document.write(' document.write(\'\<iframe\>\');');
document.write(' document.write(\'\<script\>\');');
document.write(' document.write(\'\</scr\');');
document.write(' document.write(\'ipt\>\');');
document.write(' document.write(\'\</iframe\>\');');
document.write('<\/script>');
</SCRIPT>

Просмотреть файл

@ -1,5 +0,0 @@
<html>
<script language=Javascript>
document.write("outside of body");
</script>
</html>

Просмотреть файл

@ -1,10 +0,0 @@
<html>
<body>
<form>
<table bgcolor=red>
<input>
<tr><td><input></td></tr>
</table>
</form>
</body>
</html>

Просмотреть файл

@ -1,17 +0,0 @@
<html><head></head>
<body><form>
<table>
<tbody><tr><td>
test
<table><tbody><tr>
</tr>
</tbody></table>
</td></tr>
</tbody></table>
</form>
</body></html>

Просмотреть файл

@ -1,8 +0,0 @@
<html><head></head>
<body><ul>
<li>A
</li><li>B
</li><li>C</li>
</ul>
</body></html>

Просмотреть файл

@ -1,8 +0,0 @@
<html>
<body>
<form>
<input type=text><p>
<input type=submit>
</form>This text block should be on the next line
</body>
</html>

Просмотреть файл

@ -1,11 +0,0 @@
<html>
<body>
<h5>H5_1
<li>LI_1
<h5>H5_2
<li>LI_2
<h5>H5_3
<li>LI_3
</body>
</html>

Просмотреть файл

@ -1,38 +0,0 @@
<HTML><HEAD>
<style type="text/css">
span:before { content: "<" attr(class) ">" }
span:after { content: "</" attr(class) ">" }
span.a {
font-size: 130%;
color: blue;
}
span.z {
padding-left: 50px;
display: block;
color: green;
}
</style>
</HEAD>
<BODY><FONT FACE="Arial"><!-- Deleting this font tag fixes the bug -->
<P>testcase 4</P><!-- Deleting this paragraph or adding a space
before or after this comment fixes the bug -->
<SPAN CLASS="z">[span class z]</SPAN><br>
<P><SPAN CLASS="a">[span class a]</SPAN></P>
<SPAN CLASS="z">[span class z]</SPAN><br>
<P><SPAN CLASS="a">[span class a]</SPAN></P>
<SPAN CLASS="z">[span class z]</SPAN><br>
<P><SPAN CLASS="a">[span class a]</SPAN></P>
<SPAN CLASS="z">[span class z]</SPAN>
<P><SPAN CLASS="a">[span class a]</SPAN></P>
</font></body></html>

Просмотреть файл

@ -1,20 +0,0 @@
<HTML>
<BODY>
<TABLE width=500>
<TR>
<TD width=100 bgcolor=yellow>
<B>
<FORM>
<NOBR>
<IMG SRC="http://bugzilla.mozilla.org/ant.jpg" width=100 HEIGHT=30>
</NOBR>
</FORM>
UNSER ANGEBOT
</TD>
<TD width=400>
Foo
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

Просмотреть файл

@ -1,4 +0,0 @@
<html><head><title>Testcase for bug 68674</title></head><body>
<A HREF="http://www.mozilla.org">www.<STRONG>mozilla.org</A></STRONG>
STRONG - This text should not be part of the link <BR>
</body></html>

Просмотреть файл

@ -1,2 +0,0 @@
<A href=foo.html><B>foo<A href=bar.html>bar</A></B></A>
<DL><DD><LI>one<DD><LI>two

Просмотреть файл

@ -1,17 +0,0 @@
<HTML>
<TABLE BORDER="1">
<tr>
<td>
<b>
Test
</td>
</tr>
<TD>
Test
</TD>
</TR>
</TABLE>
</html>

Просмотреть файл

@ -1,25 +0,0 @@
<html><head></head>
<body bgcolor="#ffffff" text="#000000">
<font face="geneva, arial, helvetica">
<font size="-1">
This text, in the body, is in "Font Face A"
<table>
<tbody><tr>
<td align="center">
<font face="arial, helvetica" color="#404040" size="5">
This text, in a table, is in "Font Face B". Immediately following
this text is a close font tag, and another erroneously placed close font
tag. </font>
</td>
</tr>
</tbody></table> This text, back in the body, should be in Font Face A,
but is not because Mozilla incorrectly heeded the second close-font tag in
the above table. </font>
</font></body></html>

Просмотреть файл

@ -1,17 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML lang="en">
<HEAD>
<base href=http://www.bath.ac.uk/%7Epy8ieh/internet/eviltests/cascade/>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK type="text/css" href="c.css" rel=stylesheet>
</HEAD>
<BODY>
<OL>
<LI class=a>Should be green - Linked with <code>LINK</code> HTTP Header.</LI>
<LI class=c>Should be green - Linked with <code>LINK</code></LI>
</OL>
</BODY></HTML>

Просмотреть файл

@ -1,8 +0,0 @@
<html><head></head>
<body>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="540">
<tbody><tr>
<td>***</td></tr><tr><td>***</td></tr>
</tbody></table>
</body></html>

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше