Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions
CViewSourceHTML Class Reference

#include <nsViewSourceHTML.h>

Inheritance diagram for CViewSourceHTML:
Inheritance graph
[legend]
Collaboration diagram for CViewSourceHTML:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS NS_DECL_NSIDTD CViewSourceHTML ()
 Default constructor.
virtual ~CViewSourceHTML ()
 Default destructor.
virtual void SetVerification (PRBool aEnable)
 Set this to TRUE if you want the DTD to verify its context stack.
 NS_IMETHOD_ (const nsIID &) GetMostDerivedIID(void) const =0
 NS_IMETHOD_ (eAutoDetectResult) CanParse(CParserContext &aParserContext)=0
 This method is called to determine if the given DTD can parse a document in a given source-type.
 NS_IMETHOD_ (PRBool) CanContain(PRInt32 aParent
 This method is called to determine whether or not a tag of one type can contain a tag of another type.
 NS_IMETHOD_ (PRBool) IsContainer(PRInt32 aTag) const =0
 This method gets called to determine whether a given tag is itself a container.
 NS_IMETHOD_ (void) Terminate()=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.
 NS_IMETHOD_ (PRInt32) GetType()=0
NS_IMETHOD CreateNewInstance (nsIDTD **aInstancePtrResult)=0
 Call this method if you want the DTD to construct a clone of itself.
NS_IMETHOD WillBuildModel (const CParserContext &aParserContext, nsITokenizer *aTokenizer, nsIContentSink *aSink)=0
NS_IMETHOD DidBuildModel (nsresult anErrorCode, PRBool aNotifySink, nsIParser *aParser, nsIContentSink *aSink)=0
 Called by the parser after the parsing process has concluded gess5/18/98.
NS_IMETHOD BuildModel (nsIParser *aParser, nsITokenizer *aTokenizer, nsITokenObserver *anObserver, nsIContentSink *aSink)=0
 Called by the parser after the parsing process has concluded gess5/18/98.
NS_IMETHOD HandleToken (CToken *aToken, nsIParser *aParser)=0
 Called during model building phase of parse process.
NS_IMETHOD WillResumeParse (nsIContentSink *aSink)=0
 If the parse process gets interrupted midway, this method is called by the parser prior to resuming the process.
NS_IMETHOD WillInterruptParse (nsIContentSink *aSink)=0
 If the parse process gets interrupted, this method is called by the parser to notify the DTD that interruption will occur.
NS_IMETHOD CollectSkippedContent (PRInt32 aTag, nsAString &aContent, PRInt32 &aLineNo)=0

Public Attributes

PRInt32 aChild const = 0

Protected Attributes

nsParsermParser
nsIHTMLContentSinkmSink
PRInt32 mLineNumber
nsITokenizermTokenizer
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
eParserDocType mDocType
nsCString mMimeType
PRInt32 mErrorCount
PRInt32 mTagCount
nsString mFilename
nsString mTags
nsString mErrors
PRUint32 mTokenCount

Private Member Functions

nsresult WriteTag (PRInt32 tagType, const nsSubstring &aText, PRInt32 attrCount, PRBool aTagInError)
 This method gets called when a tag needs to be sent out.
nsresult WriteAttributes (PRInt32 attrCount, PRBool aOwnerInError)
 This method gets called when a tag needs to write it's attributes.
nsresult GenerateSummary ()
 Call this to display an error summary regarding the page.
void StartNewPreBlock (void)
 Call this to start a new PRE block.
void AddAttrToNode (nsCParserStartNode &aNode, nsTokenAllocator *aAllocator, const nsAString &aAttrName, const nsAString &aAttrValue)

Detailed Description

Definition at line 65 of file nsViewSourceHTML.h.


Constructor & Destructor Documentation

Default constructor.

gess 4/9/98

Parameters:
@return

Definition at line 327 of file nsViewSourceHTML.cpp.

Here is the call graph for this function:

Default destructor.

gess 4/9/98

Parameters:
@return

Definition at line 379 of file nsViewSourceHTML.cpp.

                                 {
  mParser=0; //just to prove we destructed...
}

Member Function Documentation

void CViewSourceHTML::AddAttrToNode ( nsCParserStartNode aNode,
nsTokenAllocator aAllocator,
const nsAString &  aAttrName,
const nsAString &  aAttrValue 
) [private]

Definition at line 718 of file nsViewSourceHTML.cpp.

{
  NS_PRECONDITION(aAllocator, "Must have a token allocator!");
  
  CAttributeToken* theAttr =
    (CAttributeToken*) aAllocator->CreateTokenOfType(eToken_attribute,
                                                     eHTMLTag_unknown,
                                                     aAttrValue);
  if (!theAttr) {
    NS_ERROR("Failed to allocate attribute token");
    return;
  }

  theAttr->SetKey(aAttrName);
  aNode.AddAttribute(theAttr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::BuildModel ( nsIParser aParser,
nsITokenizer aTokenizer,
nsITokenObserver anObserver,
nsIContentSink aSink 
) [pure virtual, inherited]

Called by the parser after the parsing process has concluded gess5/18/98.

Parameters:
anErrorCode- contains error code resulting from parse process
Returns:

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::CollectSkippedContent ( PRInt32  aTag,
nsAString &  aContent,
PRInt32 aLineNo 
) [pure virtual, inherited]

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::CreateNewInstance ( nsIDTD **  aInstancePtrResult) [pure virtual, inherited]

Call this method if you want the DTD to construct a clone of itself.

gess7/23/98

Parameters:
@return

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::DidBuildModel ( nsresult  anErrorCode,
PRBool  aNotifySink,
nsIParser aParser,
nsIContentSink aSink 
) [pure virtual, inherited]

Called by the parser after the parsing process has concluded gess5/18/98.

Parameters:
anErrorCode- contains error code resulting from parse process
Returns:

Here is the caller graph for this function:

Call this to display an error summary regarding the page.

rickg 6June2000

Returns:
nsresult

Definition at line 664 of file nsViewSourceHTML.cpp.

                                           {
  nsresult result=NS_OK;

  if(mErrorCount && mTagCount) {

    mErrors.AppendLiteral("\n\n ");
    mErrors.AppendInt(mErrorCount);
    mErrors.Append(NS_LITERAL_STRING(" error(s) detected -- see highlighted portions.\n"));

    result=WriteTag(mSummaryTag,mErrors,0,PR_FALSE);
  }

  return result;
}

Here is the call graph for this function:

NS_IMETHOD nsIDTD::HandleToken ( CToken aToken,
nsIParser aParser 
) [pure virtual, inherited]

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. gess 3/25/98

Parameters:
aToken-- token object to be put into content model
Returns:
error code (usually 0)

Here is the caller graph for this function:

nsIDTD::NS_IMETHOD_ ( const nsIID ) const [pure virtual, inherited]
nsIDTD::NS_IMETHOD_ ( eAutoDetectResult  ) [pure virtual, inherited]

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.

Parameters:
aParserContext-- the context for this document (knows the content type, document type, parser command, etc).
Returns:
eUnknownDetect if you don't know how to parse it, eValidDetect if you do, but someone may have a better idea, ePrimaryDetect if you think you know best
nsIDTD::NS_IMETHOD_ ( PRBool  ) [inherited]

This method is called to determine whether or not a tag of one type can contain a tag of another type.

gess 3/25/98

Parameters:
aParent-- int tag of parent container
aChild-- int tag of child container
Returns:
PR_TRUE if parent can contain child
nsIDTD::NS_IMETHOD_ ( PRBool  ) const [pure virtual, inherited]

This method gets called to determine whether a given tag is itself a container.

gess 3/25/98

Parameters:
aTag-- tag to test for containership
Returns:
PR_TRUE if given tag can contain other tags
nsIDTD::NS_IMETHOD_ ( void  ) [pure virtual, inherited]

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.

harishd 07/22/99

Parameters:
@return
nsIDTD::NS_IMETHOD_ ( PRInt32  ) [pure virtual, inherited]
void CViewSourceHTML::SetVerification ( PRBool  aEnabled) [virtual]

Set this to TRUE if you want the DTD to verify its context stack.

Called by the parser to enable/disable dtd verification of the internal context stack.

gess 7/23/98

Parameters:
@return

Definition at line 857 of file nsViewSourceHTML.cpp.

{
}

Call this to start a new PRE block.

See bug 86355 for why this makes some pages much faster.

Definition at line 683 of file nsViewSourceHTML.cpp.

                                          {
  CEndToken endToken(eHTMLTag_pre);
  nsCParserNode endNode(&endToken, 0/*stack token*/);
  mSink->CloseContainer(eHTMLTag_pre);

  nsTokenAllocator* theAllocator = mTokenizer->GetTokenAllocator();
  if (!theAllocator) {
    return;
  }
  
  CStartToken* theToken =
    NS_STATIC_CAST(CStartToken*,
                   theAllocator->CreateTokenOfType(eToken_start,
                                                   eHTMLTag_pre,
                                                   NS_LITERAL_STRING("PRE")));
  if (!theToken) {
    return;
  }

  nsCParserStartNode startNode(theToken, theAllocator);
  AddAttrToNode(startNode, theAllocator,
                NS_LITERAL_STRING("id"),
                NS_ConvertASCIItoUCS2(nsPrintfCString("line%d", mLineNumber)));
  mSink->OpenContainer(startNode);
  
#ifdef DUMP_TO_FILE
  if (gDumpFile) {
    fprintf(gDumpFile, "</pre>\n");
    fprintf(gDumpFile, "<pre id=\"line%d\">\n", mLineNumber);
  }
#endif // DUMP_TO_FILE

  mTokenCount = 0;
}

Here is the call graph for this function:

NS_IMETHOD nsIDTD::WillBuildModel ( const CParserContext aParserContext,
nsITokenizer aTokenizer,
nsIContentSink aSink 
) [pure virtual, inherited]

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::WillInterruptParse ( nsIContentSink aSink) [pure virtual, inherited]

If the parse process gets interrupted, this method is called by the parser to notify the DTD that interruption will occur.

gess5/18/98

Returns:
ignored

Here is the caller graph for this function:

NS_IMETHOD nsIDTD::WillResumeParse ( nsIContentSink aSink) [pure virtual, inherited]

If the parse process gets interrupted midway, this method is called by the parser prior to resuming the process.

gess5/18/98

Returns:
ignored

Here is the caller graph for this function:

nsresult CViewSourceHTML::WriteAttributes ( PRInt32  attrCount,
PRBool  aOwnerInError 
) [private]

This method gets called when a tag needs to write it's attributes.

gess 3/25/98

Parameters:
@returnresult status

Definition at line 895 of file nsViewSourceHTML.cpp.

                                                                                 {
  nsresult result=NS_OK;
  
  if(attrCount){ //go collect the attributes...

    CSharedVSContext& theContext=CSharedVSContext::GetSharedContext();

    int attr = 0;
    for(attr = 0; attr < attrCount; ++attr){
      CToken* theToken = mTokenizer->PeekToken();
      if(theToken)  {
        eHTMLTokenTypes theType = eHTMLTokenTypes(theToken->GetTokenType());
        if(eToken_attribute == theType){
          mTokenizer->PopToken(); //pop it for real...
          theContext.mTokenNode.AddAttribute(theToken);  //and add it to the node.

          CAttributeToken* theAttrToken = (CAttributeToken*)theToken;
          const nsSubstring& theKey = theAttrToken->GetKey();
          
          // The attribute is only in error if its owner is NOT in error.
          const PRBool attributeInError =
            !aOwnerInError && theAttrToken->IsInError();

          result = WriteTag(mKey,theKey,0,attributeInError);
          const nsSubstring& theValue = theAttrToken->GetValue();

          if(!theValue.IsEmpty() || theAttrToken->mHasEqualWithoutValue){
            result = WriteTag(mValue,theValue,0,attributeInError);
          }
        } 
      }
      else return kEOF;
    }
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult CViewSourceHTML::WriteTag ( PRInt32  aTagType,
const nsSubstring aText,
PRInt32  attrCount,
PRBool  aTagInError 
) [private]

This method gets called when a tag needs to be sent out.

gess 3/25/98

Parameters:
@returnresult status

Definition at line 940 of file nsViewSourceHTML.cpp.

                                                                                                                  {
  nsresult result=NS_OK;

  // adjust line number to what it will be after we finish writing this tag
  // XXXbz life here sucks.  We can't use the GetNewlineCount on the token,
  // because Text tokens in <style>, <script>, etc lie through their teeth.
  // On the other hand, the parser messes up newline counting in some token
  // types (bug 137315).  So our line numbers will disagree with the parser's
  // in some cases...
  mLineNumber += aText.CountChar(PRUnichar('\n'));
  
  CSharedVSContext& theContext=CSharedVSContext::GetSharedContext();

  nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
  NS_ASSERTION(0!=theAllocator,"Error: no allocator");
  if(0==theAllocator)
    return NS_ERROR_FAILURE;

  // Highlight all parts of all erroneous tags.
  if (mSyntaxHighlight && aTagInError) {
    CStartToken* theTagToken=
      NS_STATIC_CAST(CStartToken*,
                     theAllocator->CreateTokenOfType(eToken_start,
                                                     eHTMLTag_span,
                                                     NS_LITERAL_STRING("SPAN")));
    theContext.mErrorNode.Init(theTagToken, theAllocator);
    AddAttrToNode(theContext.mErrorNode, theAllocator,
                  NS_LITERAL_STRING("class"),
                  NS_LITERAL_STRING("error"));
    mSink->OpenContainer(theContext.mErrorNode);
#ifdef DUMP_TO_FILE
    if (gDumpFile) {
      fprintf(gDumpFile, "<span class=\"error\">");
    }
#endif
  }

  if (kBeforeText[aTagType][0] != 0) {
    NS_ConvertASCIItoUTF16 beforeText(kBeforeText[aTagType]);
    theContext.mITextToken.SetIndirectString(beforeText);
    nsCParserNode theNode(&theContext.mITextToken, 0/*stack token*/);
    mSink->AddLeaf(theNode);
  }
#ifdef DUMP_TO_FILE
  if (gDumpFile && kDumpFileBeforeText[aTagType][0])
    fprintf(gDumpFile, kDumpFileBeforeText[aTagType]);
#endif // DUMP_TO_FILE
  
  if (mSyntaxHighlight && aTagType != mText) {
    CStartToken* theTagToken=
      NS_STATIC_CAST(CStartToken*,
                     theAllocator->CreateTokenOfType(eToken_start,
                                                     eHTMLTag_span,
                                                     NS_LITERAL_STRING("SPAN")));
    theContext.mStartNode.Init(theTagToken, theAllocator);
    AddAttrToNode(theContext.mStartNode, theAllocator,
                  NS_LITERAL_STRING("class"),
                  NS_ConvertASCIItoUCS2(kElementClasses[aTagType]));
    mSink->OpenContainer(theContext.mStartNode);  //emit <starttag>...
#ifdef DUMP_TO_FILE
    if (gDumpFile) {
      fprintf(gDumpFile, "<span class=\"");
      fprintf(gDumpFile, kElementClasses[aTagType]);
      fprintf(gDumpFile, "\">");
    }
#endif // DUMP_TO_FILE
  }

  STOP_TIMER();

  theContext.mITextToken.SetIndirectString(aText);  //now emit the tag name...

  nsCParserNode theNode(&theContext.mITextToken, 0/*stack token*/);
  mSink->AddLeaf(theNode);
#ifdef DUMP_TO_FILE
  if (gDumpFile) {
    fputs(NS_ConvertUCS2toUTF8(aText).get(), gDumpFile);
  }
#endif // DUMP_TO_FILE

  if (mSyntaxHighlight && aTagType != mText) {
    theContext.mStartNode.ReleaseAll(); 
    CEndToken theEndToken(eHTMLTag_span);
    theContext.mEndNode.Init(&theEndToken, 0/*stack token*/);
    mSink->CloseContainer(eHTMLTag_span);  //emit </endtag>...
#ifdef DUMP_TO_FILE
    if (gDumpFile)
      fprintf(gDumpFile, "</span>");
#endif //DUMP_TO_FILE
  }

  if(attrCount){
    result=WriteAttributes(attrCount, aTagInError);
  }

  // Tokens are set in error if their ending > is not there, so don't output 
  // the after-text
  if (!aTagInError && kAfterText[aTagType][0] != 0) {
    NS_ConvertASCIItoUTF16 afterText(kAfterText[aTagType]);
    theContext.mITextToken.SetIndirectString(afterText);
    nsCParserNode theNode(&theContext.mITextToken, 0/*stack token*/);
    mSink->AddLeaf(theNode);
  }
#ifdef DUMP_TO_FILE
  if (!aTagInError && gDumpFile && kDumpFileAfterText[aTagType][0])
    fprintf(gDumpFile, kDumpFileAfterText[aTagType]);
#endif // DUMP_TO_FILE

  if (mSyntaxHighlight && aTagInError) {
    theContext.mErrorNode.ReleaseAll(); 
    CEndToken theEndToken(eHTMLTag_span);
    theContext.mEndErrorNode.Init(&theEndToken, 0/*stack token*/);
    mSink->CloseContainer(eHTMLTag_span);  //emit </endtag>...
#ifdef DUMP_TO_FILE
    if (gDumpFile)
      fprintf(gDumpFile, "</span>");
#endif //DUMP_TO_FILE
  }

  START_TIMER();

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

PRInt32 aChild nsIDTD::const = 0 [inherited]

Definition at line 178 of file nsIDTD.h.

Definition at line 109 of file nsViewSourceHTML.h.

Definition at line 108 of file nsViewSourceHTML.h.

Definition at line 126 of file nsViewSourceHTML.h.

Definition at line 111 of file nsViewSourceHTML.h.

Definition at line 124 of file nsViewSourceHTML.h.

Definition at line 107 of file nsViewSourceHTML.h.

Definition at line 113 of file nsViewSourceHTML.h.

Definition at line 128 of file nsViewSourceHTML.h.

Definition at line 133 of file nsViewSourceHTML.h.

Definition at line 131 of file nsViewSourceHTML.h.

Definition at line 122 of file nsViewSourceHTML.h.

Definition at line 121 of file nsViewSourceHTML.h.

Definition at line 115 of file nsViewSourceHTML.h.

Definition at line 103 of file nsViewSourceHTML.h.

Definition at line 110 of file nsViewSourceHTML.h.

Definition at line 127 of file nsViewSourceHTML.h.

Definition at line 101 of file nsViewSourceHTML.h.

Definition at line 125 of file nsViewSourceHTML.h.

Definition at line 112 of file nsViewSourceHTML.h.

Definition at line 117 of file nsViewSourceHTML.h.

Definition at line 102 of file nsViewSourceHTML.h.

Definition at line 106 of file nsViewSourceHTML.h.

Definition at line 118 of file nsViewSourceHTML.h.

Definition at line 119 of file nsViewSourceHTML.h.

Definition at line 129 of file nsViewSourceHTML.h.

Definition at line 132 of file nsViewSourceHTML.h.

Definition at line 114 of file nsViewSourceHTML.h.

Definition at line 135 of file nsViewSourceHTML.h.

Definition at line 104 of file nsViewSourceHTML.h.

Definition at line 116 of file nsViewSourceHTML.h.

Definition at line 120 of file nsViewSourceHTML.h.


The documentation for this class was generated from the following files: