зеркало из https://github.com/mozilla/pjs.git
added support for doc quality
This commit is contained in:
Родитель
d96642568c
Коммит
7c82c6b547
|
@ -23,6 +23,7 @@
|
|||
#include "nsHTMLDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsHTMLTokens.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prtime.h"
|
||||
|
@ -132,7 +133,7 @@ public:
|
|||
virtual PRBool AddLeaf(const nsIParserNode& aNode);
|
||||
|
||||
virtual void WillBuildModel(void);
|
||||
virtual void DidBuildModel(void);
|
||||
virtual void DidBuildModel(PRInt32 aQualityLevel);
|
||||
virtual void WillInterrupt(void);
|
||||
virtual void WillResume(void);
|
||||
|
||||
|
@ -1367,16 +1368,31 @@ HTMLContentSink::WillBuildModel(void)
|
|||
StartLayout();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
* @param aQualityLevel describes how well formed the doc was.
|
||||
* 0=GOOD; 1=FAIR; 2=POOR;
|
||||
* @update 6/21/98 gess
|
||||
*/
|
||||
void
|
||||
HTMLContentSink::DidBuildModel(void)
|
||||
{
|
||||
void HTMLContentSink::DidBuildModel(PRInt32 aQualityLevel) {
|
||||
PR_LogPrint("DidBuildModel");
|
||||
|
||||
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
||||
for (i = 0; i < ns; i++) {
|
||||
nsIPresShell* shell = mDocument->GetShellAt(i);
|
||||
if (nsnull != shell) {
|
||||
nsIViewManager* vm = shell->GetViewManager();
|
||||
if(vm) {
|
||||
vm->SetQuality(nsContentQuality(aQualityLevel));
|
||||
}
|
||||
NS_RELEASE(vm);
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
}
|
||||
|
||||
ReflowNewContent();
|
||||
mDocument->EndLoad();
|
||||
}
|
||||
|
@ -1404,6 +1420,7 @@ HTMLContentSink::WillResume(void)
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
nsresult NS_NewHTMLContentSink(nsIHTMLContentSink** aInstancePtrResult,
|
||||
|
|
|
@ -301,7 +301,7 @@ PRInt32 CNavDTD::DidBuildModel(PRInt32 anErrorCode){
|
|||
CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE);
|
||||
}
|
||||
if(mSink) {
|
||||
mSink->DidBuildModel();
|
||||
mSink->DidBuildModel(1);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -303,7 +303,7 @@ PRInt32 COtherDTD::DidBuildModel(PRInt32 anErrorCode){
|
|||
CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE);
|
||||
}
|
||||
if(mSink) {
|
||||
mSink->DidBuildModel();
|
||||
mSink->DidBuildModel(0);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -1,467 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsHTMLContentSink.h"
|
||||
#include "nsHTMLTokens.h"
|
||||
#include "nsParserTypes.h"
|
||||
#include "prtypes.h"
|
||||
#include <iostream.h>
|
||||
|
||||
#define VERBOSE_DEBUG
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENTSINK_IID);
|
||||
static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTMLCONTENTSINK_IID);
|
||||
static NS_DEFINE_IID(kClassIID, NS_HTMLCONTENTSINK_IID);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* "Fakey" factory method used to create an instance of
|
||||
* this class.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult NS_NewHTMLContentSink(nsIContentSink** aInstancePtrResult)
|
||||
{
|
||||
nsHTMLContentSink *it = new nsHTMLContentSink();
|
||||
|
||||
if (it == 0) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kClassIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsHTMLContentSink::nsHTMLContentSink() : nsIHTMLContentSink(), mTitle("") {
|
||||
mNodeStackPos=0;
|
||||
memset(mNodeStack,0,sizeof(mNodeStack));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default destructor. Probably not a good idea to call
|
||||
* this if you created your instance via the factor method.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsHTMLContentSink::~nsHTMLContentSink() {
|
||||
}
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
static void DebugDump(const char* str1,const nsString& str2,PRInt32 tabs) {
|
||||
for(PRInt32 i=0;i<tabs;i++)
|
||||
cout << " "; //add some tabbing to debug output...
|
||||
char* cp = str2.ToNewCString();
|
||||
cout << str1 << cp << ">" << endl;
|
||||
delete cp;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* This bit of magic creates the addref and release
|
||||
* methods for this class.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMPL_ADDREF(nsHTMLContentSink)
|
||||
NS_IMPL_RELEASE(nsHTMLContentSink)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Standard XPCOM query interface implementation. I used
|
||||
* my own version because this class is a subclass of both
|
||||
* ISupports and IContentSink. Perhaps there's a macro for
|
||||
* this, but I didn't see it.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult nsHTMLContentSink::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if(aIID.Equals(kISupportsIID)) { //do IUnknown...
|
||||
*aInstancePtr = (nsIContentSink*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kIContentSinkIID)) { //do nsIContentSink base class...
|
||||
*aInstancePtr = (nsIContentSink*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kIHTMLContentSinkIID)) { //do nsIHTMLContentSink base class...
|
||||
*aInstancePtr = (nsIHTMLContentSink*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kClassIID)) { //do this class...
|
||||
*aInstancePtr = (nsHTMLContentSink*)(this);
|
||||
}
|
||||
else {
|
||||
*aInstancePtr=0;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
((nsISupports*) *aInstancePtr)->AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a <HTML>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenHTML(const nsIParserNode& aNode) {
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </HTML>
|
||||
* tag has been consumed.
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseHTML(const nsIParserNode& aNode){
|
||||
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser <i>any time</i>
|
||||
* head data gets consumed by the parser. Currently, that
|
||||
* list includes <META>, <ISINDEX>, <LINK>, <SCRIPT>,
|
||||
* <STYLE>, <TITLE>.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenHead(const nsIParserNode& aNode) {
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </HEAD>
|
||||
* tag has been seen (either implicitly or explicitly).
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseHead(const nsIParserNode& aNode) {
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets called by the parser when a <TITLE> tag
|
||||
* gets consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::SetTitle(const nsString& aValue){
|
||||
PRInt32 result=kNoError;
|
||||
mTitle=aValue;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a <BODY>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenBody(const nsIParserNode& aNode) {
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </BODY>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseBody(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a <FORM>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenForm(const nsIParserNode& aNode) {
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </FORM>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseForm(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a <FRAMESET>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenFrameset(const nsIParserNode& aNode) {
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </FRAMESET>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseFrameset(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when any general
|
||||
* type of container has been consumed and needs to be
|
||||
* opened. This includes things like <OL>, <Hn>, etc...
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenContainer(const nsIParserNode& aNode){
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a close
|
||||
* container tag has been consumed and needs to be closed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseContainer(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This causes the topmost container to be closed,
|
||||
* regardless of its type.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseTopmostContainer(){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos--]=eHTMLTag_unknown;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::AddLeaf(const nsIParserNode& aNode){
|
||||
PRInt32 result=kNoError;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when the parser begins the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
void nsHTMLContentSink::WillBuildModel(void){
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
void nsHTMLContentSink::DidBuildModel(void){
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void nsHTMLContentSink::WillInterrupt(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void nsHTMLContentSink::WillResume(void) {
|
||||
}
|
||||
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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
|
||||
* OpenXXX method: OpenHTML,OpenHead,OpenBody,OpenFrameSet;
|
||||
* likewise, the CloseXXX 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.
|
||||
*/
|
||||
|
||||
#ifndef NS_HTMLCONTENTSINK
|
||||
#define NS_HTMLCONTENTSINK
|
||||
|
||||
#include "nsIParserNode.h"
|
||||
#include "nsIHTMLContentSink.h"
|
||||
#include "nsIContentSink.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#define NS_HTMLCONTENTSINK_IID \
|
||||
{0x803f8110, 0xc287, 0x11d1, \
|
||||
{0x80, 0x22, 0x00, 0x60, 0x08, 0x14, 0x98, 0x89}}
|
||||
|
||||
|
||||
class nsHTMLContentSink : public nsIHTMLContentSink {
|
||||
public:
|
||||
|
||||
enum eSection {eNone=0,eHTML,eHead,eBody,eContainer};
|
||||
|
||||
nsHTMLContentSink();
|
||||
~nsHTMLContentSink();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
PRBool SetTitle(const nsString& aValue);
|
||||
|
||||
// Called when Opening or closing the main HTML container
|
||||
PRInt32 OpenHTML(const nsIParserNode& aNode);
|
||||
PRInt32 CloseHTML(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing the main HEAD container
|
||||
PRInt32 OpenHead(const nsIParserNode& aNode);
|
||||
PRInt32 CloseHead(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing the main BODY container
|
||||
PRInt32 OpenBody(const nsIParserNode& aNode);
|
||||
PRInt32 CloseBody(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing FORM containers
|
||||
PRInt32 OpenForm(const nsIParserNode& aNode);
|
||||
PRInt32 CloseForm(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing the main FRAMESET container
|
||||
PRInt32 OpenFrameset(const nsIParserNode& aNode);
|
||||
PRInt32 CloseFrameset(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing a general container
|
||||
// This includes: OL,UL,DIR,SPAN,TABLE,H[1..6],etc.
|
||||
// Until proven otherwise, I also plan to toss STYLE,
|
||||
// FRAME, SCRIPT, etc. here too!
|
||||
virtual PRInt32 OpenContainer(const nsIParserNode& aNode);
|
||||
virtual PRInt32 CloseContainer(const nsIParserNode& aNode);
|
||||
virtual PRInt32 CloseTopmostContainer();
|
||||
virtual PRInt32 AddLeaf(const nsIParserNode& aNode);
|
||||
|
||||
/**
|
||||
* This method gets called when the parser begins the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void WillBuildModel(void);
|
||||
|
||||
/**
|
||||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void DidBuildModel(void);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
virtual void WillInterrupt(void);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
virtual void WillResume(void);
|
||||
|
||||
|
||||
PRInt32 NodeAt(PRInt32 aPos) {return mNodeStack[aPos];}
|
||||
PRInt32 TopNode() {return mNodeStack[mNodeStackPos-1];}
|
||||
PRInt32 GetStackPos() {return mNodeStackPos;}
|
||||
|
||||
protected:
|
||||
PRInt32 mNodeStack[100];
|
||||
PRInt32 mNodeStackPos;
|
||||
nsString mTitle;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -92,9 +92,11 @@ class nsIContentSink : public nsISupports {
|
|||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @param aQualityLevel describes how well formed the doc was.
|
||||
* 0=GOOD; 1=FAIR; 2=POOR;
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void DidBuildModel(void)=0;
|
||||
virtual void DidBuildModel(PRInt32 aQualityLevel)=0;
|
||||
|
||||
/**
|
||||
* This method gets called when the parser gets i/o blocked,
|
||||
|
|
|
@ -226,9 +226,11 @@ class nsIHTMLContentSink : public nsIContentSink {
|
|||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @param aQualityLevel describes how well formed the doc was.
|
||||
* 0=GOOD; 1=FAIR; 2=POOR;
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void DidBuildModel(void)=0;
|
||||
virtual void DidBuildModel(PRInt32 aQualityLevel)=0;
|
||||
|
||||
/**
|
||||
* This method gets called when the parser gets i/o blocked,
|
||||
|
@ -246,6 +248,7 @@ class nsIHTMLContentSink : public nsIContentSink {
|
|||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void WillResume(void)=0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "nsHTMLDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsHTMLTokens.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prtime.h"
|
||||
|
@ -132,7 +133,7 @@ public:
|
|||
virtual PRBool AddLeaf(const nsIParserNode& aNode);
|
||||
|
||||
virtual void WillBuildModel(void);
|
||||
virtual void DidBuildModel(void);
|
||||
virtual void DidBuildModel(PRInt32 aQualityLevel);
|
||||
virtual void WillInterrupt(void);
|
||||
virtual void WillResume(void);
|
||||
|
||||
|
@ -1367,16 +1368,31 @@ HTMLContentSink::WillBuildModel(void)
|
|||
StartLayout();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
* @param aQualityLevel describes how well formed the doc was.
|
||||
* 0=GOOD; 1=FAIR; 2=POOR;
|
||||
* @update 6/21/98 gess
|
||||
*/
|
||||
void
|
||||
HTMLContentSink::DidBuildModel(void)
|
||||
{
|
||||
void HTMLContentSink::DidBuildModel(PRInt32 aQualityLevel) {
|
||||
PR_LogPrint("DidBuildModel");
|
||||
|
||||
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
||||
for (i = 0; i < ns; i++) {
|
||||
nsIPresShell* shell = mDocument->GetShellAt(i);
|
||||
if (nsnull != shell) {
|
||||
nsIViewManager* vm = shell->GetViewManager();
|
||||
if(vm) {
|
||||
vm->SetQuality(nsContentQuality(aQualityLevel));
|
||||
}
|
||||
NS_RELEASE(vm);
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
}
|
||||
|
||||
ReflowNewContent();
|
||||
mDocument->EndLoad();
|
||||
}
|
||||
|
@ -1404,6 +1420,7 @@ HTMLContentSink::WillResume(void)
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
nsresult NS_NewHTMLContentSink(nsIHTMLContentSink** aInstancePtrResult,
|
||||
|
|
|
@ -301,7 +301,7 @@ PRInt32 CNavDTD::DidBuildModel(PRInt32 anErrorCode){
|
|||
CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE);
|
||||
}
|
||||
if(mSink) {
|
||||
mSink->DidBuildModel();
|
||||
mSink->DidBuildModel(1);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -303,7 +303,7 @@ PRInt32 COtherDTD::DidBuildModel(PRInt32 anErrorCode){
|
|||
CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE);
|
||||
}
|
||||
if(mSink) {
|
||||
mSink->DidBuildModel();
|
||||
mSink->DidBuildModel(0);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -1,467 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsHTMLContentSink.h"
|
||||
#include "nsHTMLTokens.h"
|
||||
#include "nsParserTypes.h"
|
||||
#include "prtypes.h"
|
||||
#include <iostream.h>
|
||||
|
||||
#define VERBOSE_DEBUG
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENTSINK_IID);
|
||||
static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTMLCONTENTSINK_IID);
|
||||
static NS_DEFINE_IID(kClassIID, NS_HTMLCONTENTSINK_IID);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* "Fakey" factory method used to create an instance of
|
||||
* this class.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult NS_NewHTMLContentSink(nsIContentSink** aInstancePtrResult)
|
||||
{
|
||||
nsHTMLContentSink *it = new nsHTMLContentSink();
|
||||
|
||||
if (it == 0) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kClassIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsHTMLContentSink::nsHTMLContentSink() : nsIHTMLContentSink(), mTitle("") {
|
||||
mNodeStackPos=0;
|
||||
memset(mNodeStack,0,sizeof(mNodeStack));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default destructor. Probably not a good idea to call
|
||||
* this if you created your instance via the factor method.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsHTMLContentSink::~nsHTMLContentSink() {
|
||||
}
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
static void DebugDump(const char* str1,const nsString& str2,PRInt32 tabs) {
|
||||
for(PRInt32 i=0;i<tabs;i++)
|
||||
cout << " "; //add some tabbing to debug output...
|
||||
char* cp = str2.ToNewCString();
|
||||
cout << str1 << cp << ">" << endl;
|
||||
delete cp;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* This bit of magic creates the addref and release
|
||||
* methods for this class.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_IMPL_ADDREF(nsHTMLContentSink)
|
||||
NS_IMPL_RELEASE(nsHTMLContentSink)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Standard XPCOM query interface implementation. I used
|
||||
* my own version because this class is a subclass of both
|
||||
* ISupports and IContentSink. Perhaps there's a macro for
|
||||
* this, but I didn't see it.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult nsHTMLContentSink::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if(aIID.Equals(kISupportsIID)) { //do IUnknown...
|
||||
*aInstancePtr = (nsIContentSink*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kIContentSinkIID)) { //do nsIContentSink base class...
|
||||
*aInstancePtr = (nsIContentSink*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kIHTMLContentSinkIID)) { //do nsIHTMLContentSink base class...
|
||||
*aInstancePtr = (nsIHTMLContentSink*)(this);
|
||||
}
|
||||
else if(aIID.Equals(kClassIID)) { //do this class...
|
||||
*aInstancePtr = (nsHTMLContentSink*)(this);
|
||||
}
|
||||
else {
|
||||
*aInstancePtr=0;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
((nsISupports*) *aInstancePtr)->AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a <HTML>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenHTML(const nsIParserNode& aNode) {
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </HTML>
|
||||
* tag has been consumed.
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseHTML(const nsIParserNode& aNode){
|
||||
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser <i>any time</i>
|
||||
* head data gets consumed by the parser. Currently, that
|
||||
* list includes <META>, <ISINDEX>, <LINK>, <SCRIPT>,
|
||||
* <STYLE>, <TITLE>.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenHead(const nsIParserNode& aNode) {
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </HEAD>
|
||||
* tag has been seen (either implicitly or explicitly).
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseHead(const nsIParserNode& aNode) {
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets called by the parser when a <TITLE> tag
|
||||
* gets consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::SetTitle(const nsString& aValue){
|
||||
PRInt32 result=kNoError;
|
||||
mTitle=aValue;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a <BODY>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenBody(const nsIParserNode& aNode) {
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </BODY>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseBody(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a <FORM>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenForm(const nsIParserNode& aNode) {
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </FORM>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseForm(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a <FRAMESET>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenFrameset(const nsIParserNode& aNode) {
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a </FRAMESET>
|
||||
* tag has been consumed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseFrameset(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when any general
|
||||
* type of container has been consumed and needs to be
|
||||
* opened. This includes things like <OL>, <Hn>, etc...
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::OpenContainer(const nsIParserNode& aNode){
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos-1)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called by the parser when a close
|
||||
* container tag has been consumed and needs to be closed.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseContainer(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[--mNodeStackPos]=eHTMLTag_unknown;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("</",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This causes the topmost container to be closed,
|
||||
* regardless of its type.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::CloseTopmostContainer(){
|
||||
NS_PRECONDITION(mNodeStackPos > 0, "node stack empty");
|
||||
PRInt32 result=kNoError;
|
||||
mNodeStack[mNodeStackPos--]=eHTMLTag_unknown;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets called by the parser when you want to add
|
||||
* a leaf node to the current container in the content
|
||||
* model.
|
||||
*
|
||||
* @updated gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLContentSink::AddLeaf(const nsIParserNode& aNode){
|
||||
PRInt32 result=kNoError;
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
DebugDump("<",aNode.GetText(),(mNodeStackPos)*2);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when the parser begins the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
void nsHTMLContentSink::WillBuildModel(void){
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
void nsHTMLContentSink::DidBuildModel(void){
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void nsHTMLContentSink::WillInterrupt(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void nsHTMLContentSink::WillResume(void) {
|
||||
}
|
||||
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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
|
||||
* OpenXXX method: OpenHTML,OpenHead,OpenBody,OpenFrameSet;
|
||||
* likewise, the CloseXXX 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.
|
||||
*/
|
||||
|
||||
#ifndef NS_HTMLCONTENTSINK
|
||||
#define NS_HTMLCONTENTSINK
|
||||
|
||||
#include "nsIParserNode.h"
|
||||
#include "nsIHTMLContentSink.h"
|
||||
#include "nsIContentSink.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#define NS_HTMLCONTENTSINK_IID \
|
||||
{0x803f8110, 0xc287, 0x11d1, \
|
||||
{0x80, 0x22, 0x00, 0x60, 0x08, 0x14, 0x98, 0x89}}
|
||||
|
||||
|
||||
class nsHTMLContentSink : public nsIHTMLContentSink {
|
||||
public:
|
||||
|
||||
enum eSection {eNone=0,eHTML,eHead,eBody,eContainer};
|
||||
|
||||
nsHTMLContentSink();
|
||||
~nsHTMLContentSink();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
PRBool SetTitle(const nsString& aValue);
|
||||
|
||||
// Called when Opening or closing the main HTML container
|
||||
PRInt32 OpenHTML(const nsIParserNode& aNode);
|
||||
PRInt32 CloseHTML(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing the main HEAD container
|
||||
PRInt32 OpenHead(const nsIParserNode& aNode);
|
||||
PRInt32 CloseHead(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing the main BODY container
|
||||
PRInt32 OpenBody(const nsIParserNode& aNode);
|
||||
PRInt32 CloseBody(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing FORM containers
|
||||
PRInt32 OpenForm(const nsIParserNode& aNode);
|
||||
PRInt32 CloseForm(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing the main FRAMESET container
|
||||
PRInt32 OpenFrameset(const nsIParserNode& aNode);
|
||||
PRInt32 CloseFrameset(const nsIParserNode& aNode);
|
||||
|
||||
// Called when Opening or closing a general container
|
||||
// This includes: OL,UL,DIR,SPAN,TABLE,H[1..6],etc.
|
||||
// Until proven otherwise, I also plan to toss STYLE,
|
||||
// FRAME, SCRIPT, etc. here too!
|
||||
virtual PRInt32 OpenContainer(const nsIParserNode& aNode);
|
||||
virtual PRInt32 CloseContainer(const nsIParserNode& aNode);
|
||||
virtual PRInt32 CloseTopmostContainer();
|
||||
virtual PRInt32 AddLeaf(const nsIParserNode& aNode);
|
||||
|
||||
/**
|
||||
* This method gets called when the parser begins the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void WillBuildModel(void);
|
||||
|
||||
/**
|
||||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void DidBuildModel(void);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
virtual void WillInterrupt(void);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
virtual void WillResume(void);
|
||||
|
||||
|
||||
PRInt32 NodeAt(PRInt32 aPos) {return mNodeStack[aPos];}
|
||||
PRInt32 TopNode() {return mNodeStack[mNodeStackPos-1];}
|
||||
PRInt32 GetStackPos() {return mNodeStackPos;}
|
||||
|
||||
protected:
|
||||
PRInt32 mNodeStack[100];
|
||||
PRInt32 mNodeStackPos;
|
||||
nsString mTitle;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -92,9 +92,11 @@ class nsIContentSink : public nsISupports {
|
|||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @param aQualityLevel describes how well formed the doc was.
|
||||
* 0=GOOD; 1=FAIR; 2=POOR;
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void DidBuildModel(void)=0;
|
||||
virtual void DidBuildModel(PRInt32 aQualityLevel)=0;
|
||||
|
||||
/**
|
||||
* This method gets called when the parser gets i/o blocked,
|
||||
|
|
|
@ -226,9 +226,11 @@ class nsIHTMLContentSink : public nsIContentSink {
|
|||
* This method gets called when the parser concludes the process
|
||||
* of building the content model via the content sink.
|
||||
*
|
||||
* @param aQualityLevel describes how well formed the doc was.
|
||||
* 0=GOOD; 1=FAIR; 2=POOR;
|
||||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void DidBuildModel(void)=0;
|
||||
virtual void DidBuildModel(PRInt32 aQualityLevel)=0;
|
||||
|
||||
/**
|
||||
* This method gets called when the parser gets i/o blocked,
|
||||
|
@ -246,6 +248,7 @@ class nsIHTMLContentSink : public nsIContentSink {
|
|||
* @update 5/7/98 gess
|
||||
*/
|
||||
virtual void WillResume(void)=0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче