1998-04-13 20:24:54 +00:00
|
|
|
/* -*- 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 "nsIHTMLContentSink.h"
|
|
|
|
#include "nsIStyleSheet.h"
|
|
|
|
#include "nsIUnicharInputStream.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsHTMLDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-06-23 01:34:25 +00:00
|
|
|
#include "nsIViewManager.h"
|
1998-06-23 00:52:21 +00:00
|
|
|
#include "nsHTMLTokens.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsTablePart.h"
|
|
|
|
#include "nsTableRow.h"
|
|
|
|
#include "nsTableCell.h"
|
1998-06-27 22:57:52 +00:00
|
|
|
#include "nsIDOMText.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
#include "nsHTMLForms.h"
|
|
|
|
#include "nsIFormManager.h"
|
1998-05-08 20:18:06 +00:00
|
|
|
#include "nsIFormControl.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIImageMap.h"
|
|
|
|
|
1998-04-22 22:12:24 +00:00
|
|
|
#include "nsRepository.h"
|
1998-06-23 22:25:28 +00:00
|
|
|
#include "nsIWebWidget.h"
|
1998-04-22 22:12:24 +00:00
|
|
|
|
1998-06-11 16:46:33 +00:00
|
|
|
extern nsresult NS_NewHTMLIFrame(nsIHTMLContent** aInstancePtrResult,
|
1998-06-23 22:25:28 +00:00
|
|
|
nsIAtom* aTag, nsIWebWidget* aWebWidget); // XXX move
|
1998-04-13 20:24:54 +00:00
|
|
|
// XXX attribute values have entities in them - use the parsers expander!
|
|
|
|
|
|
|
|
// XXX Go through a factory for this one
|
|
|
|
#include "nsICSSParser.h"
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
1998-06-30 23:51:53 +00:00
|
|
|
static PRLogModuleInfo* gSinkLogModuleInfo;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
#define SINK_TRACE_CALLS 0x1
|
|
|
|
#define SINK_TRACE_REFLOW 0x2
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
#define SINK_LOG_TEST(_lm,_bit) (PRIntn((_lm)->level) & (_bit))
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
#define SINK_TRACE(_bit,_args) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (SINK_LOG_TEST(gSinkLogModuleInfo,_bit)) { \
|
|
|
|
PR_LogPrint _args; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
#else
|
|
|
|
#define SINK_TRACE(_bit,_args)
|
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTMLCONTENTSINK_IID);
|
1998-05-08 20:18:06 +00:00
|
|
|
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
class HTMLContentSink : public nsIHTMLContentSink {
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
HTMLContentSink();
|
|
|
|
~HTMLContentSink();
|
|
|
|
|
|
|
|
void* operator new(size_t size) {
|
|
|
|
void* rv = ::operator new(size);
|
|
|
|
nsCRT::zero(rv, size);
|
|
|
|
return (void*) rv;
|
|
|
|
}
|
|
|
|
|
1998-06-23 22:25:28 +00:00
|
|
|
nsresult Init(nsIDocument* aDoc, nsIURL* aURL, nsIWebWidget* aWebWidget);
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIHTMLContent* GetCurrentContainer(eHTMLTags* aType);
|
|
|
|
|
|
|
|
virtual PRBool SetTitle(const nsString& aValue);
|
|
|
|
|
|
|
|
// Called when Opening or closing the main HTML container
|
|
|
|
virtual PRBool OpenHTML(const nsIParserNode& aNode);
|
|
|
|
virtual PRBool CloseHTML(const nsIParserNode& aNode);
|
|
|
|
|
|
|
|
// Called when Opening or closing the main HEAD container
|
|
|
|
virtual PRBool OpenHead(const nsIParserNode& aNode);
|
|
|
|
virtual PRBool CloseHead(const nsIParserNode& aNode);
|
|
|
|
|
|
|
|
// Called when Opening or closing the main BODY container
|
|
|
|
virtual PRBool OpenBody(const nsIParserNode& aNode);
|
|
|
|
virtual PRBool CloseBody(const nsIParserNode& aNode);
|
|
|
|
|
|
|
|
// Called when Opening or closing FORM containers
|
|
|
|
virtual PRBool OpenForm(const nsIParserNode& aNode);
|
|
|
|
virtual PRBool CloseForm(const nsIParserNode& aNode);
|
|
|
|
|
|
|
|
// Called when Opening or closing the main FRAMESET container
|
|
|
|
virtual PRBool OpenFrameset(const nsIParserNode& aNode);
|
|
|
|
virtual PRBool 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,
|
|
|
|
// FORMS, FRAME, SCRIPT, etc. here too!
|
|
|
|
virtual PRBool OpenContainer(const nsIParserNode& aNode);
|
|
|
|
virtual PRBool CloseContainer(const nsIParserNode& aNode);
|
|
|
|
virtual PRBool CloseTopmostContainer();
|
|
|
|
|
|
|
|
// Called for text, comments and so on...
|
|
|
|
virtual PRBool AddLeaf(const nsIParserNode& aNode);
|
|
|
|
|
1998-05-07 21:11:07 +00:00
|
|
|
virtual void WillBuildModel(void);
|
1998-06-23 01:34:25 +00:00
|
|
|
virtual void DidBuildModel(PRInt32 aQualityLevel);
|
1998-05-07 21:11:07 +00:00
|
|
|
virtual void WillInterrupt(void);
|
|
|
|
virtual void WillResume(void);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void StartLayout();
|
|
|
|
|
|
|
|
void ReflowNewContent();
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Leaf tag handler routines that translate a leaf tag into a
|
|
|
|
// content object, processing all of the tag attributes.
|
|
|
|
|
|
|
|
nsresult ProcessAREATag(const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessBASETag(const nsIParserNode& aNode);
|
1998-06-26 15:08:55 +00:00
|
|
|
nsresult ProcessMETATag(const nsIParserNode& aNode);
|
1998-04-13 20:24:54 +00:00
|
|
|
nsresult ProcessSTYLETag(const nsIParserNode& aNode);
|
1998-06-25 22:26:52 +00:00
|
|
|
nsresult ProcessSCRIPTTag(const nsIParserNode& aNode);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
nsresult ProcessBRTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessHRTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessINPUTTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessIMGTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessSPACERTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
1998-04-22 22:12:24 +00:00
|
|
|
nsresult ProcessTEXTAREATag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
1998-04-13 20:24:54 +00:00
|
|
|
nsresult ProcessWBRTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-04-22 23:24:43 +00:00
|
|
|
nsresult ProcessOpenSELECTTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessCloseSELECTTag(const nsIParserNode& aNode);
|
1998-05-08 23:08:43 +00:00
|
|
|
nsresult ProcessOpenOPTIONTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
1998-04-22 23:24:43 +00:00
|
|
|
nsresult ProcessCloseOPTIONTag(const nsIParserNode& aNode);
|
|
|
|
nsresult ProcessOPTIONTagContent(const nsIParserNode& aNode);
|
|
|
|
|
1998-06-11 16:46:33 +00:00
|
|
|
nsresult ProcessIFRAMETag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode);
|
1998-04-22 23:24:43 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
void FlushText();
|
|
|
|
|
|
|
|
nsresult AddText(const nsString& aText, nsIHTMLContent** aContent);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
void GetAttributeValueAt(const nsIParserNode& aNode,
|
|
|
|
PRInt32 aIndex,
|
|
|
|
nsString& aResult);
|
|
|
|
|
1998-04-22 22:12:24 +00:00
|
|
|
PRBool FindAttribute(const nsIParserNode& aNode,
|
|
|
|
const nsString& aKeyName,
|
|
|
|
nsString& aResult);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsresult AddAttributes(const nsIParserNode& aNode,
|
|
|
|
nsIHTMLContent* aInstancePtrResult);
|
|
|
|
|
|
|
|
nsresult LoadStyleSheet(nsIURL* aURL,
|
|
|
|
nsIUnicharInputStream* aUIN);
|
|
|
|
|
|
|
|
nsIDocument* mDocument;
|
|
|
|
nsIURL* mDocumentURL;
|
|
|
|
|
|
|
|
eHTMLTags mNodeStack[100];/* XXX */
|
|
|
|
nsIHTMLContent* mContainerStack[100];/* XXX */
|
|
|
|
PRInt32 mStackPos;
|
|
|
|
nsString* mTitle;
|
|
|
|
nsString mBaseHREF;
|
|
|
|
nsString mBaseTarget;
|
|
|
|
nsIStyleSheet* mStyleSheet;
|
|
|
|
nsIFormManager* mCurrentForm;
|
|
|
|
nsIImageMap* mCurrentMap;
|
1998-05-08 20:18:06 +00:00
|
|
|
nsIHTMLContent* mCurrentSelect;
|
|
|
|
nsIHTMLContent* mCurrentOption;
|
1998-06-27 22:57:52 +00:00
|
|
|
nsIDOMText* mCurrentText;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
nsIHTMLContent* mRoot;
|
|
|
|
nsIHTMLContent* mBody;
|
1998-06-04 21:33:44 +00:00
|
|
|
nsIHTMLContent* mHead;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
PRTime mLastUpdateTime;
|
|
|
|
PRTime mUpdateDelta;
|
|
|
|
PRBool mLayoutStarted;
|
1998-06-03 15:58:52 +00:00
|
|
|
PRInt32 mInMonolithicContainer;
|
1998-06-23 22:25:28 +00:00
|
|
|
nsIWebWidget* mWebWidget;
|
1998-04-13 20:24:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Note: operator new zeros our memory
|
|
|
|
HTMLContentSink::HTMLContentSink()
|
|
|
|
{
|
1998-06-30 23:51:53 +00:00
|
|
|
if (nsnull == gSinkLogModuleInfo) {
|
|
|
|
gSinkLogModuleInfo = PR_NewLogModule("htmlcontentsink");
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the first update delta to be 50ms
|
|
|
|
LL_I2L(mUpdateDelta, PR_USEC_PER_MSEC * 50);
|
|
|
|
}
|
1998-05-21 20:37:41 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
HTMLContentSink::~HTMLContentSink()
|
|
|
|
{
|
1998-06-04 21:33:44 +00:00
|
|
|
NS_IF_RELEASE(mHead);
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_IF_RELEASE(mBody);
|
|
|
|
NS_IF_RELEASE(mRoot);
|
1998-04-16 21:49:49 +00:00
|
|
|
NS_IF_RELEASE(mDocument);
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_IF_RELEASE(mDocumentURL);
|
|
|
|
NS_IF_RELEASE(mStyleSheet);
|
|
|
|
NS_IF_RELEASE(mCurrentForm);
|
|
|
|
NS_IF_RELEASE(mCurrentMap);
|
1998-04-22 23:24:43 +00:00
|
|
|
NS_IF_RELEASE(mCurrentSelect);
|
|
|
|
NS_IF_RELEASE(mCurrentOption);
|
1998-06-23 22:25:28 +00:00
|
|
|
NS_IF_RELEASE(mWebWidget);
|
1998-05-08 20:18:06 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
if (nsnull != mTitle) {
|
|
|
|
delete mTitle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-23 22:25:28 +00:00
|
|
|
nsresult HTMLContentSink::Init(nsIDocument* aDoc, nsIURL* aDocURL, nsIWebWidget* aWebWidget)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-04-16 21:49:49 +00:00
|
|
|
NS_IF_RELEASE(mDocument);
|
1998-04-13 20:24:54 +00:00
|
|
|
mDocument = aDoc;
|
1998-04-16 21:49:49 +00:00
|
|
|
NS_IF_ADDREF(mDocument);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-16 21:49:49 +00:00
|
|
|
NS_IF_RELEASE(mDocumentURL);
|
1998-04-13 20:24:54 +00:00
|
|
|
mDocumentURL = aDocURL;
|
1998-04-16 21:49:49 +00:00
|
|
|
NS_IF_ADDREF(mDocumentURL);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-23 22:25:28 +00:00
|
|
|
NS_IF_RELEASE(mWebWidget);
|
|
|
|
mWebWidget = aWebWidget;
|
|
|
|
NS_IF_ADDREF(mWebWidget);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// Make root part
|
1998-04-16 21:49:49 +00:00
|
|
|
NS_IF_RELEASE(mRoot);
|
1998-04-13 20:24:54 +00:00
|
|
|
nsresult rv = NS_NewRootPart(&mRoot, aDoc);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(HTMLContentSink,kIHTMLContentSinkIID)
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::OpenHTML(const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::OpenHTML"));
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_PRECONDITION(0 == mStackPos, "bad stack pos");
|
|
|
|
|
|
|
|
mNodeStack[0] = (eHTMLTags)aNode.GetNodeType();
|
|
|
|
mContainerStack[0] = mRoot;
|
|
|
|
mStackPos = 1;
|
|
|
|
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::CloseHTML(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::CloseHTML"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(mStackPos > 0, "bad bad");
|
|
|
|
mNodeStack[--mStackPos] = eHTMLTag_unknown;
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mCurrentForm);
|
|
|
|
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::OpenHead(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::OpenHead"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-04 21:33:44 +00:00
|
|
|
if (nsnull == mHead) {
|
|
|
|
nsIAtom* atom = NS_NewAtom("HEAD");
|
|
|
|
nsresult rv = NS_NewHTMLHead(&mHead, atom);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
mRoot->InsertChildAt(mHead, 0, PR_FALSE);
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
mNodeStack[mStackPos] = (eHTMLTags)aNode.GetNodeType();
|
|
|
|
mContainerStack[mStackPos] = mHead;
|
|
|
|
mStackPos++;
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::CloseHead(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::CloseHead"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(mStackPos > 0, "bad bad");
|
|
|
|
mNodeStack[--mStackPos] = eHTMLTag_unknown;
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::SetTitle(const nsString& aValue)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
if (nsnull == mTitle) {
|
|
|
|
mTitle = new nsString(aValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*mTitle = aValue;
|
|
|
|
}
|
|
|
|
mTitle->CompressWhitespace(PR_TRUE, PR_TRUE);
|
|
|
|
((nsHTMLDocument*)mDocument)->SetTitle(*mTitle);
|
1998-06-26 16:12:51 +00:00
|
|
|
|
|
|
|
if (nsnull == mHead) {
|
|
|
|
nsIAtom* atom = NS_NewAtom("HEAD");
|
|
|
|
nsresult rv = NS_NewHTMLHead(&mHead, atom);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
mRoot->InsertChildAt(mHead, 0, PR_FALSE);
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom* atom = NS_NewAtom("TITLE");
|
|
|
|
nsIHTMLContent* it = nsnull;
|
|
|
|
nsresult rv = NS_NewHTMLTitle(&it, atom, aValue);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
mHead->AppendChild(it, PR_FALSE);
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::OpenBody(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::OpenBody"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
PRBool startLayout = PR_FALSE;
|
|
|
|
if (nsnull == mBody) {
|
|
|
|
nsIAtom* atom = NS_NewAtom("BODY");
|
|
|
|
nsresult rv = NS_NewBodyPart(&mBody, atom);
|
|
|
|
if (NS_OK == rv) {
|
1998-06-03 15:58:52 +00:00
|
|
|
mRoot->AppendChild(mBody, PR_FALSE);
|
1998-04-13 20:24:54 +00:00
|
|
|
startLayout = PR_TRUE;
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
mNodeStack[mStackPos] = (eHTMLTags)aNode.GetNodeType();
|
|
|
|
mContainerStack[mStackPos] = mBody;
|
|
|
|
mStackPos++;
|
|
|
|
|
|
|
|
// Add attributes to the body content object, but only if it's really a body
|
|
|
|
// tag that is triggering the OpenBody.
|
|
|
|
if (aNode.GetText().EqualsIgnoreCase("body")) {
|
|
|
|
AddAttributes(aNode, mBody);
|
|
|
|
// XXX If the body already existed and has been reflowed somewhat
|
|
|
|
// then we need to trigger a style change
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startLayout) {
|
|
|
|
// XXX This has to be done now that the body is in because we
|
|
|
|
// don't know how to handle a content-appended reflow if the
|
|
|
|
// root has no children
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::OpenBody: start layout"));
|
1998-04-13 20:24:54 +00:00
|
|
|
StartLayout();
|
|
|
|
}
|
|
|
|
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::CloseBody(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::CloseBody"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(mStackPos > 0, "bad bad");
|
|
|
|
mNodeStack[--mStackPos] = eHTMLTag_unknown;
|
|
|
|
|
|
|
|
// Reflow any lingering content
|
|
|
|
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-04-22 22:12:24 +00:00
|
|
|
static NS_DEFINE_IID(kIFormManagerIID, NS_IFORMMANAGER_IID);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::OpenForm(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::OpenForm"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
// Close out previous form if it's there
|
|
|
|
if (nsnull != mCurrentForm) {
|
|
|
|
NS_RELEASE(mCurrentForm);
|
|
|
|
mCurrentForm = nsnull;
|
|
|
|
}
|
|
|
|
|
1998-04-22 22:12:24 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsAutoString classID;
|
|
|
|
if (FindAttribute(aNode, "classid", classID)) {
|
|
|
|
// Translate classid string into an nsID
|
|
|
|
char cbuf[50];
|
|
|
|
classID.ToCString(cbuf, sizeof(cbuf));
|
|
|
|
nsID clid;
|
|
|
|
if (clid.Parse(cbuf)) {
|
|
|
|
// Create a form manager using the repository
|
|
|
|
nsIFactory* fac;
|
|
|
|
rv = NSRepository::FindFactory(clid, &fac);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
rv = fac->CreateInstance(nsnull, kIFormManagerIID,
|
|
|
|
(void**)&mCurrentForm);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
printf("OpenForm: can't create form manager instance: %d\n", rv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
NS_RELEASE(fac);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("OpenForm: can't find '%s' in the repository\n", cbuf);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("OpenForm: classID is invalid: '%s'\n", cbuf);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull == mCurrentForm) {
|
|
|
|
// Create new form
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
rv = NS_NewHTMLForm(&mCurrentForm, atom);
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Add tag attributes to the form
|
|
|
|
nsAutoString k, v;
|
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
|
|
|
for (PRInt32 i = 0; i < ac; i++) {
|
|
|
|
// Get upper-cased key
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
k.SetLength(0);
|
|
|
|
k.Append(key);
|
|
|
|
k.ToUpperCase();
|
|
|
|
|
|
|
|
// Get value and remove mandatory quotes
|
|
|
|
GetAttributeValueAt(aNode, i, v);
|
|
|
|
mCurrentForm->SetAttribute(k, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::CloseForm(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::CloseForm"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
if (nsnull != mCurrentForm) {
|
|
|
|
NS_RELEASE(mCurrentForm);
|
|
|
|
mCurrentForm = nsnull;
|
|
|
|
}
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::OpenFrameset(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::OpenFrameset"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
mNodeStack[mStackPos++] = (eHTMLTags)aNode.GetNodeType();
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::CloseFrameset(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::CloseFrameset"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
mNodeStack[--mStackPos] = eHTMLTag_unknown;
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::OpenContainer(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::OpenContainer"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
|
1998-04-22 23:24:43 +00:00
|
|
|
eHTMLTags parentType;
|
|
|
|
nsIHTMLContent* parent = GetCurrentContainer(&parentType);
|
|
|
|
switch (parentType) {
|
|
|
|
case eHTMLTag_select:
|
|
|
|
break;
|
|
|
|
case eHTMLTag_option:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsIHTMLContent* container = nsnull;
|
|
|
|
if (aNode.GetTokenType() == eToken_start) {
|
|
|
|
switch (aNode.GetNodeType()) {
|
|
|
|
case eHTMLTag_map:
|
|
|
|
NS_IF_RELEASE(mCurrentMap);
|
|
|
|
rv = NS_NewImageMap(&mCurrentMap, atom);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Look for name attribute and set the map name
|
1998-04-22 22:12:24 +00:00
|
|
|
nsAutoString name;
|
|
|
|
if (FindAttribute(aNode, "name", name)) {
|
|
|
|
name.StripWhitespace(); // XXX leading, trailing, interior non=-space ws is removed
|
|
|
|
mCurrentMap->SetName(name);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
// Add the map to the document
|
|
|
|
((nsHTMLDocument*)mDocument)->AddImageMap(mCurrentMap);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
case eHTMLTag_table:
|
|
|
|
rv = NS_NewTablePart(&container, atom);
|
1998-06-03 15:58:52 +00:00
|
|
|
mInMonolithicContainer++;
|
1998-04-13 20:24:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_caption:
|
|
|
|
rv = NS_NewTableCaptionPart(&container, atom);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_tr:
|
|
|
|
rv = NS_NewTableRowPart(&container, atom);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_tbody:
|
|
|
|
case eHTMLTag_thead:
|
|
|
|
case eHTMLTag_tfoot:
|
|
|
|
rv = NS_NewTableRowGroupPart(&container, atom);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_colgroup:
|
|
|
|
rv = NS_NewTableColGroupPart(&container, atom);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_col:
|
|
|
|
rv = NS_NewTableColPart(&container, atom);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_td:
|
|
|
|
case eHTMLTag_th:
|
|
|
|
rv = NS_NewTableCellPart(&container, atom);
|
|
|
|
break;
|
|
|
|
|
1998-04-22 23:24:43 +00:00
|
|
|
case eHTMLTag_select:
|
|
|
|
rv = ProcessOpenSELECTTag(&container, aNode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_option:
|
1998-05-08 23:08:43 +00:00
|
|
|
rv = ProcessOpenOPTIONTag(&container, aNode);
|
1998-04-22 23:24:43 +00:00
|
|
|
break;
|
|
|
|
|
1998-06-11 16:46:33 +00:00
|
|
|
case eHTMLTag_iframe:
|
|
|
|
rv = ProcessIFRAMETag(&container, aNode);
|
|
|
|
break;
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
default:
|
|
|
|
rv = NS_NewHTMLContainer(&container, atom);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX for now assume that if it's a container, it's a simple container
|
|
|
|
mNodeStack[mStackPos] = (eHTMLTags) aNode.GetNodeType();
|
|
|
|
mContainerStack[mStackPos] = container;
|
|
|
|
|
|
|
|
if (nsnull != container) {
|
|
|
|
container->SetDocument(mDocument);
|
|
|
|
rv = AddAttributes(aNode, container);
|
|
|
|
mStackPos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(atom);
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32
|
|
|
|
HTMLContentSink::CloseContainer(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::CloseContainer"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
switch (aNode.GetNodeType()) {
|
|
|
|
case eHTMLTag_map:
|
|
|
|
NS_IF_RELEASE(mCurrentMap);
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX we could assert things about the top tag name == aNode.getText
|
|
|
|
if (0 == mStackPos) {
|
|
|
|
// Can't pop empty stack
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
--mStackPos;
|
|
|
|
nsIHTMLContent* container = mContainerStack[mStackPos];
|
|
|
|
mNodeStack[mStackPos] = eHTMLTag_unknown;
|
|
|
|
mContainerStack[mStackPos] = nsnull;
|
|
|
|
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-05-13 17:43:35 +00:00
|
|
|
nsIHTMLContent* parent = nsnull;
|
|
|
|
|
1998-04-22 23:24:43 +00:00
|
|
|
switch (aNode.GetNodeType()) {
|
|
|
|
case eHTMLTag_option:
|
|
|
|
ProcessCloseOPTIONTag(aNode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eHTMLTag_select:
|
1998-05-13 17:43:35 +00:00
|
|
|
ProcessCloseSELECTTag(aNode); // add fall through
|
1998-06-03 15:58:52 +00:00
|
|
|
break;
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-06-03 15:58:52 +00:00
|
|
|
case eHTMLTag_table:
|
|
|
|
mInMonolithicContainer--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != container) {
|
|
|
|
// Now that this container is complete, append it to it's parent
|
|
|
|
eHTMLTags parentType;
|
|
|
|
parent = GetCurrentContainer(&parentType);
|
|
|
|
container->Compact();
|
|
|
|
|
|
|
|
if (nsnull != parent) {
|
1998-06-30 23:51:53 +00:00
|
|
|
PRBool allowReflow = parent == mBody;
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (allowReflow) {
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::CloseContainer: reflow after append"));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
parent->AppendChild(container, allowReflow);
|
1998-06-03 15:58:52 +00:00
|
|
|
#if XXX
|
|
|
|
if (parent == mBody) {
|
|
|
|
// We just closed a child of the body off. Trigger a
|
|
|
|
// content-appended reflow if enough time has elapsed
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
/* XXX this expression doesn't compile on the Mac
|
|
|
|
kipp said it had to do with a type issue.
|
|
|
|
if (now - mLastUpdateTime >= mUpdateDelta) {
|
|
|
|
mLastUpdateTime = now;
|
|
|
|
mUpdateDelta += mUpdateDelta;
|
|
|
|
ReflowNewContent();
|
|
|
|
}*/
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-03 15:58:52 +00:00
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-03 15:58:52 +00:00
|
|
|
NS_RELEASE(container);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
PRBool HTMLContentSink::CloseTopmostContainer()
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
HTMLContentSink::WillBuildModel(void)
|
|
|
|
{
|
|
|
|
mDocument->BeginLoad();
|
1998-06-30 23:51:53 +00:00
|
|
|
#if XXX
|
1998-06-27 22:57:52 +00:00
|
|
|
// XXX temporary
|
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
|
|
|
nsIPresShell* shell = mDocument->GetShellAt(i);
|
|
|
|
if (nsnull != shell) {
|
|
|
|
shell->BeginObservingDocument();
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::WillBuildModel: start layout"));
|
1998-06-27 22:57:52 +00:00
|
|
|
StartLayout();
|
1998-06-30 23:51:53 +00:00
|
|
|
#endif
|
1998-06-27 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 6/21/98 gess
|
|
|
|
*/
|
1998-06-30 23:51:53 +00:00
|
|
|
void
|
|
|
|
HTMLContentSink::DidBuildModel(PRInt32 aQualityLevel)
|
|
|
|
{
|
1998-06-27 22:57:52 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::DidBuildModel: layout new content"));
|
1998-06-27 22:57:52 +00:00
|
|
|
ReflowNewContent();
|
|
|
|
mDocument->EndLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
HTMLContentSink::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
|
|
|
|
HTMLContentSink::WillResume(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
void HTMLContentSink::StartLayout()
|
|
|
|
{
|
|
|
|
if (!mLayoutStarted) {
|
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
|
|
|
nsIPresShell* shell = mDocument->GetShellAt(i);
|
|
|
|
if (nsnull != shell) {
|
1998-06-30 23:51:53 +00:00
|
|
|
// Make shell an observer for next time
|
|
|
|
shell->BeginObservingDocument();
|
|
|
|
|
|
|
|
// Resize-reflow this time
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIPresContext* cx = shell->GetPresContext();
|
1998-05-22 18:38:33 +00:00
|
|
|
nsRect r;
|
|
|
|
cx->GetVisibleArea(r);
|
1998-04-13 20:24:54 +00:00
|
|
|
shell->ResizeReflow(r.width, r.height);
|
|
|
|
NS_RELEASE(cx);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mLayoutStarted = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLContentSink::ReflowNewContent()
|
|
|
|
{
|
1998-06-03 15:58:52 +00:00
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
|
|
|
nsIPresShell* shell = mDocument->GetShellAt(i);
|
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIPresContext* cx = shell->GetPresContext();
|
|
|
|
nsRect r;
|
|
|
|
cx->GetVisibleArea(r);
|
|
|
|
shell->ResizeReflow(r.width, r.height);
|
|
|
|
NS_RELEASE(cx);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if XXX
|
1998-04-13 20:24:54 +00:00
|
|
|
printf("reflow body\n");
|
|
|
|
|
|
|
|
// Trigger reflows in each of the presentation shells
|
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
|
|
|
nsIPresShell* shell = mDocument->GetShellAt(i);
|
|
|
|
if (nsnull != shell) {
|
|
|
|
shell->ContentAppended(mBody);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
}
|
1998-06-03 15:58:52 +00:00
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIHTMLContent* HTMLContentSink::GetCurrentContainer(eHTMLTags* aType)
|
|
|
|
{
|
|
|
|
nsIHTMLContent* parent;
|
|
|
|
if (mStackPos <= 2) { // assume HTML and BODY are on the stack
|
|
|
|
parent = mBody;
|
|
|
|
*aType = eHTMLTag_body;
|
|
|
|
} else {
|
|
|
|
parent = mContainerStack[mStackPos - 1];
|
|
|
|
*aType = mNodeStack[mStackPos - 1];
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Leaf tag handling code
|
|
|
|
|
1998-05-21 20:37:41 +00:00
|
|
|
PRInt32 HTMLContentSink::AddLeaf(const nsIParserNode& aNode)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-30 23:51:53 +00:00
|
|
|
SINK_TRACE(SINK_TRACE_CALLS,
|
|
|
|
("HTMLContentSink::AddLeaf"));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
// Check for nodes that require special handling
|
|
|
|
switch (aNode.GetNodeType()) {
|
|
|
|
case eHTMLTag_style:
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-04-13 20:24:54 +00:00
|
|
|
ProcessSTYLETag(aNode);
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
case eHTMLTag_script:
|
1998-06-25 22:26:52 +00:00
|
|
|
// XXX SCRIPT tag evaluation is currently turned off till we
|
|
|
|
// get more scripts working.
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-06-25 22:26:52 +00:00
|
|
|
#if 0
|
|
|
|
ProcessSCRIPTTag(aNode);
|
|
|
|
#endif
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
case eHTMLTag_area:
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-04-13 20:24:54 +00:00
|
|
|
ProcessAREATag(aNode);
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-06-26 15:08:55 +00:00
|
|
|
|
|
|
|
case eHTMLTag_meta:
|
|
|
|
// Add meta objects to the head object
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-06-26 15:08:55 +00:00
|
|
|
ProcessMETATag(aNode);
|
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
eHTMLTags parentType;
|
|
|
|
nsIHTMLContent* parent = GetCurrentContainer(&parentType);
|
|
|
|
|
1998-05-08 20:18:06 +00:00
|
|
|
switch (parentType) {
|
|
|
|
/*case eHTMLTag_table:
|
1998-04-13 20:24:54 +00:00
|
|
|
case eHTMLTag_tr:
|
1998-04-22 23:24:43 +00:00
|
|
|
case eHTMLTag_tbody:
|
1998-04-21 16:36:46 +00:00
|
|
|
case eHTMLTag_thead:
|
|
|
|
case eHTMLTag_tfoot:
|
1998-04-13 20:24:54 +00:00
|
|
|
// XXX Discard leaf content (those annoying \n's really) in
|
|
|
|
// table's or table rows
|
|
|
|
return PR_TRUE;
|
1998-05-08 20:18:06 +00:00
|
|
|
*/
|
1998-04-22 23:24:43 +00:00
|
|
|
case eHTMLTag_option:
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-04-22 23:24:43 +00:00
|
|
|
ProcessOPTIONTagContent(aNode);
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-22 23:24:43 +00:00
|
|
|
|
|
|
|
case eHTMLTag_select:
|
|
|
|
// Discard content in a select that's not an option
|
|
|
|
if (eHTMLTag_option != aNode.GetNodeType()) {
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-22 23:24:43 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-05-08 20:18:06 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIHTMLContent* leaf = nsnull;
|
|
|
|
switch (aNode.GetTokenType()) {
|
|
|
|
case eToken_start:
|
|
|
|
switch (aNode.GetNodeType()) {
|
|
|
|
case eHTMLTag_br:
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-04-13 20:24:54 +00:00
|
|
|
rv = ProcessBRTag(&leaf, aNode);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_hr:
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-04-13 20:24:54 +00:00
|
|
|
rv = ProcessHRTag(&leaf, aNode);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_input:
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-04-13 20:24:54 +00:00
|
|
|
rv = ProcessINPUTTag(&leaf, aNode);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_img:
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-04-13 20:24:54 +00:00
|
|
|
rv = ProcessIMGTag(&leaf, aNode);
|
|
|
|
break;
|
|
|
|
case eHTMLTag_spacer:
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-04-13 20:24:54 +00:00
|
|
|
rv = ProcessSPACERTag(&leaf, aNode);
|
|
|
|
break;
|
1998-04-22 22:12:24 +00:00
|
|
|
case eHTMLTag_textarea:
|
1998-06-27 22:57:52 +00:00
|
|
|
FlushText();
|
1998-04-22 22:12:24 +00:00
|
|
|
ProcessTEXTAREATag(&leaf, aNode);
|
|
|
|
break;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eToken_text:
|
|
|
|
case eToken_whitespace:
|
|
|
|
case eToken_newline:
|
1998-06-27 22:57:52 +00:00
|
|
|
rv = AddText(aNode.GetText(), &leaf);
|
1998-04-13 20:24:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eToken_entity:
|
|
|
|
{
|
|
|
|
nsAutoString tmp;
|
1998-06-27 22:57:52 +00:00
|
|
|
PRInt32 unicode = aNode.TranslateToUnicodeStr(tmp);
|
1998-04-13 20:24:54 +00:00
|
|
|
if (unicode < 0) {
|
1998-06-27 22:57:52 +00:00
|
|
|
rv = AddText(aNode.GetText(), &leaf);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = AddText(tmp, &leaf);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eToken_skippedcontent:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
if (nsnull != leaf) {
|
|
|
|
if (nsnull != parent) {
|
1998-06-30 23:51:53 +00:00
|
|
|
PRBool allowReflow = parent == mBody;
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (allowReflow) {
|
|
|
|
SINK_TRACE(SINK_TRACE_REFLOW,
|
|
|
|
("HTMLContentSink::CloseContainer: reflow after append"));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
parent->AppendChild(leaf, allowReflow);
|
1998-04-13 20:24:54 +00:00
|
|
|
} else {
|
|
|
|
// XXX drop stuff on the floor that doesn't have a container!
|
|
|
|
// Bad parser!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(leaf);
|
|
|
|
|
1998-05-21 20:37:41 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-27 22:57:52 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::AddText(const nsString& aText, nsIHTMLContent** aContent)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (nsnull != mCurrentText) {
|
|
|
|
mCurrentText->Append((nsString&)aText);/* XXX fix dom text api!!! */
|
|
|
|
*aContent = nsnull;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
|
|
|
|
rv = NS_NewHTMLText(aContent, aText.GetUnicode(), aText.Length());
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
(*aContent)->QueryInterface(kIDOMTextIID, (void**) &mCurrentText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLContentSink::FlushText()
|
|
|
|
{
|
|
|
|
if (nsnull != mCurrentText) {
|
|
|
|
NS_RELEASE(mCurrentText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
void HTMLContentSink::GetAttributeValueAt(const nsIParserNode& aNode,
|
|
|
|
PRInt32 aIndex,
|
|
|
|
nsString& aResult)
|
|
|
|
{
|
|
|
|
// Copy value
|
|
|
|
const nsString& value = aNode.GetValueAt(aIndex);
|
|
|
|
aResult.Truncate();
|
|
|
|
aResult.Append(value);
|
|
|
|
|
|
|
|
// strip quotes if present
|
|
|
|
PRUnichar first = aResult.First();
|
|
|
|
if ((first == '"') || (first == '\'')) {
|
|
|
|
if (aResult.Last() == first) {
|
|
|
|
aResult.Cut(0, 1);
|
|
|
|
PRInt32 pos = aResult.Length() - 1;
|
|
|
|
if (pos >= 0) {
|
|
|
|
aResult.Cut(pos, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Mismatched quotes - leave them in
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-22 22:12:24 +00:00
|
|
|
PRBool HTMLContentSink::FindAttribute(const nsIParserNode& aNode,
|
|
|
|
const nsString& aKeyName,
|
|
|
|
nsString& aResult)
|
|
|
|
{
|
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
|
|
|
for (PRInt32 i = 0; i < ac; i++) {
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
if (key.EqualsIgnoreCase(aKeyName)) {
|
|
|
|
// Get value and remove mandatory quotes
|
|
|
|
GetAttributeValueAt(aNode, i, aResult);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsresult HTMLContentSink::AddAttributes(const nsIParserNode& aNode,
|
|
|
|
nsIHTMLContent* aInstancePtrResult)
|
|
|
|
{
|
|
|
|
nsIContent* content = (nsIContent*) aInstancePtrResult;
|
|
|
|
|
|
|
|
// Add tag attributes to the content attributes
|
|
|
|
nsAutoString k, v;
|
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
|
|
|
for (PRInt32 i = 0; i < ac; i++) {
|
|
|
|
// Get upper-cased key
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
k.Truncate();
|
|
|
|
k.Append(key);
|
|
|
|
k.ToUpperCase();
|
|
|
|
|
|
|
|
// Get value and remove mandatory quotes
|
|
|
|
GetAttributeValueAt(aNode, i, v);
|
|
|
|
|
|
|
|
content->SetAttribute(k, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
if (nsnull != mCurrentMap) {
|
|
|
|
nsAutoString shape, coords, href, target(mBaseTarget), alt;
|
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
|
|
|
PRBool suppress = PR_FALSE;
|
|
|
|
for (PRInt32 i = 0; i < ac; i++) {
|
|
|
|
// Get upper-cased key
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
if (key.EqualsIgnoreCase("shape")) {
|
|
|
|
GetAttributeValueAt(aNode, i, shape);
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("coords")) {
|
|
|
|
GetAttributeValueAt(aNode, i, coords);
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("href")) {
|
|
|
|
GetAttributeValueAt(aNode, i, href);
|
|
|
|
href.StripWhitespace();
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("target")) {
|
|
|
|
GetAttributeValueAt(aNode, i, target);
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("alt")) {
|
|
|
|
GetAttributeValueAt(aNode, i, alt);
|
|
|
|
}
|
|
|
|
else if (key.EqualsIgnoreCase("suppress")) {
|
|
|
|
suppress = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mCurrentMap->AddArea(mBaseHREF, shape, coords, href, target, alt,
|
|
|
|
suppress);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
PRInt32 ac = aNode.GetAttributeCount();
|
|
|
|
for (PRInt32 i = 0; i < ac; i++) {
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
if (key.EqualsIgnoreCase("href")) {
|
|
|
|
const nsString& href = aNode.GetValueAt(i);
|
|
|
|
if (href.Length() > 0) {
|
|
|
|
mBaseHREF = href;
|
|
|
|
}
|
|
|
|
} else if (key.EqualsIgnoreCase("target")) {
|
|
|
|
|
|
|
|
const nsString& target= aNode.GetValueAt(i);
|
|
|
|
if (target.Length() > 0) {
|
|
|
|
mBaseTarget = target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-06-26 15:08:55 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mHead, "bad parser: meta before head");
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (nsnull != mHead) {
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
|
|
|
|
nsIHTMLContent* it = nsnull;
|
|
|
|
rv = NS_NewHTMLMeta(&it, atom) ;
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
rv = AddAttributes(aNode, it);
|
|
|
|
mHead->AppendChild(it, PR_FALSE);
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsresult HTMLContentSink::ProcessBRTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
rv = NS_NewHTMLBreak(aInstancePtrResult, atom);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
rv = AddAttributes(aNode, *aInstancePtrResult);
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult HTMLContentSink::ProcessHRTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
rv = NS_NewHRulePart(aInstancePtrResult, atom);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
rv = AddAttributes(aNode, *aInstancePtrResult);
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult HTMLContentSink::ProcessIMGTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
nsresult rv = NS_NewHTMLImage(aInstancePtrResult, atom);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
rv = AddAttributes(aNode, *aInstancePtrResult);
|
|
|
|
// XXX get base url to image
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult HTMLContentSink::ProcessSPACERTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
nsresult rv = NS_NewHTMLSpacer(aInstancePtrResult, atom);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
rv = AddAttributes(aNode, *aInstancePtrResult);
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-06-25 22:26:52 +00:00
|
|
|
#define SCRIPT_BUF_SIZE 1024
|
|
|
|
|
|
|
|
nsresult HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRInt32 i, ac = aNode.GetAttributeCount();
|
|
|
|
|
|
|
|
// Look for SRC attribute
|
|
|
|
nsString* src = nsnull;
|
|
|
|
for (i = 0; i < ac; i++) {
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
if (key.EqualsIgnoreCase("src")) {
|
|
|
|
src = new nsString(aNode.GetValueAt(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *script = nsnull;
|
|
|
|
PRInt32 len = 0;
|
|
|
|
|
|
|
|
// If there is a SRC attribute, (for now) read from the
|
|
|
|
// stream synchronously and hold the data in a string.
|
|
|
|
if (nsnull != src) {
|
|
|
|
// Use the SRC attribute value to open a blocking stream
|
|
|
|
nsIURL* url = nsnull;
|
|
|
|
char* spec = src->ToNewCString();
|
|
|
|
rv = NS_NewURL(&url, nsnull, spec);
|
|
|
|
delete spec;
|
|
|
|
delete src;
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
PRInt32 ec;
|
|
|
|
nsIInputStream* iin = url->Open(&ec);
|
|
|
|
if (nsnull == iin) {
|
|
|
|
NS_RELEASE(url);
|
|
|
|
return (nsresult) ec;/* XXX fix url->Open */
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drain the stream by reading from it a chunk at a time
|
|
|
|
nsString data;
|
|
|
|
PRInt32 err, nb;
|
|
|
|
do {
|
|
|
|
char buf[SCRIPT_BUF_SIZE];
|
|
|
|
|
|
|
|
nb = iin->Read(&err, buf, 0, SCRIPT_BUF_SIZE);
|
|
|
|
if (0 == err) {
|
|
|
|
data.Append((const char *)buf, nb);
|
|
|
|
}
|
|
|
|
} while (err == 0);
|
|
|
|
|
|
|
|
if (NS_INPUTSTREAM_EOF == err) {
|
|
|
|
script = data.ToNewCString();
|
|
|
|
len = data.Length();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(iin);
|
|
|
|
NS_RELEASE(url);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Otherwise, get the text content of the script tag
|
|
|
|
const nsString& content = aNode.GetSkippedContent();
|
|
|
|
script = content.ToNewCString();
|
|
|
|
len = content.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != script) {
|
|
|
|
nsIScriptContextOwner *owner;
|
|
|
|
nsIScriptContext *context;
|
|
|
|
owner = mDocument->GetScriptContextOwner();
|
|
|
|
if (nsnull != owner) {
|
|
|
|
|
|
|
|
rv = owner->GetScriptContext(&context);
|
|
|
|
if (rv != NS_OK) {
|
|
|
|
NS_RELEASE(owner);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsval val;
|
|
|
|
PRBool result = context->EvaluateString(script, len, &val);
|
|
|
|
|
|
|
|
if (PR_FALSE == result) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(context);
|
|
|
|
NS_RELEASE(owner);
|
|
|
|
}
|
|
|
|
delete script;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// 3 ways to load a style sheet: inline, style src=, link tag
|
|
|
|
// XXX What does nav do if we have SRC= and some style data inline?
|
|
|
|
nsresult HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRInt32 i, ac = aNode.GetAttributeCount();
|
|
|
|
|
|
|
|
nsString* src = nsnull;
|
|
|
|
for (i = 0; i < ac; i++) {
|
|
|
|
const nsString& key = aNode.GetKeyAt(i);
|
|
|
|
if (key.EqualsIgnoreCase("src")) {
|
|
|
|
src = new nsString(aNode.GetValueAt(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The skipped content contains the inline style data
|
|
|
|
const nsString& content = aNode.GetSkippedContent();
|
|
|
|
|
|
|
|
nsIURL* url = nsnull;
|
|
|
|
nsIUnicharInputStream* uin = nsnull;
|
|
|
|
if (nsnull == src) {
|
|
|
|
// Create a string to hold the data and wrap it up in a unicode
|
|
|
|
// input stream.
|
|
|
|
rv = NS_NewStringUnicharInputStream(&uin, new nsString(content));
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the document's url since the style data came from there
|
|
|
|
url = mDocumentURL;
|
|
|
|
NS_IF_ADDREF(url);
|
|
|
|
} else {
|
|
|
|
// src with immediate style data doesn't add up
|
|
|
|
// XXX what does nav do?
|
|
|
|
char* spec = src->ToNewCString();
|
|
|
|
rv = NS_NewURL(&url, nsnull, spec);
|
|
|
|
delete spec;
|
|
|
|
delete src;
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
PRInt32 ec;
|
|
|
|
nsIInputStream* iin = url->Open(&ec);
|
|
|
|
if (nsnull == iin) {
|
|
|
|
NS_RELEASE(url);
|
|
|
|
return (nsresult) ec;/* XXX fix url->Open */
|
|
|
|
}
|
|
|
|
rv = NS_NewConverterStream(&uin, nsnull, iin);
|
|
|
|
NS_RELEASE(iin);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_RELEASE(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that we have a url and a unicode input stream, parse the
|
|
|
|
// style sheet.
|
|
|
|
rv = LoadStyleSheet(url, uin);
|
|
|
|
NS_RELEASE(uin);
|
|
|
|
NS_RELEASE(url);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult HTMLContentSink::LoadStyleSheet(nsIURL* aURL,
|
|
|
|
nsIUnicharInputStream* aUIN)
|
|
|
|
{
|
|
|
|
/* XXX use repository */
|
|
|
|
nsICSSParser* parser;
|
|
|
|
nsresult rv = NS_NewCSSParser(&parser);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
if (nsnull != mStyleSheet) {
|
|
|
|
parser->SetStyleSheet(mStyleSheet);
|
|
|
|
// XXX we do probably need to trigger a style change reflow
|
|
|
|
// when we are finished if this is adding data to the same sheet
|
|
|
|
}
|
1998-05-28 18:40:23 +00:00
|
|
|
nsIStyleSheet* sheet = nsnull;
|
|
|
|
// XXX note: we are ignoring rv until the error code stuff in the
|
|
|
|
// input routines is converted to use nsresult's
|
|
|
|
parser->Parse(aUIN, mDocumentURL, sheet);
|
1998-04-13 20:24:54 +00:00
|
|
|
if (nsnull != sheet) {
|
|
|
|
if (nsnull == mStyleSheet) {
|
|
|
|
// Add in the sheet the first time; if we update the sheet
|
|
|
|
// with new data (mutliple style tags in the same document)
|
|
|
|
// then the sheet will be updated by the css parser and
|
|
|
|
// therefore we don't need to add it to the document)
|
|
|
|
mDocument->AddStyleSheet(sheet);
|
|
|
|
mStyleSheet = sheet;
|
|
|
|
}
|
|
|
|
rv = NS_OK;
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;/* XXX */
|
|
|
|
}
|
|
|
|
NS_RELEASE(parser);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult HTMLContentSink::ProcessINPUTTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
// Find type attribute and then create the appropriate form element
|
1998-04-22 22:12:24 +00:00
|
|
|
nsAutoString val;
|
|
|
|
if (FindAttribute(aNode, "type", val)) {
|
|
|
|
if (val.EqualsIgnoreCase("submit")) {
|
|
|
|
rv = NS_NewHTMLInputSubmit(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("reset")) {
|
|
|
|
rv = NS_NewHTMLInputReset(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("button")) {
|
|
|
|
rv = NS_NewHTMLInputButton(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("checkbox")) {
|
|
|
|
rv = NS_NewHTMLInputCheckbox(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("file")) {
|
|
|
|
rv = NS_NewHTMLInputFile(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("hidden")) {
|
|
|
|
rv = NS_NewHTMLInputHidden(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("image")) {
|
|
|
|
rv = NS_NewHTMLInputImage(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("password")) {
|
|
|
|
rv = NS_NewHTMLInputPassword(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("radio")) {
|
|
|
|
rv = NS_NewHTMLInputRadio(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("text")) {
|
|
|
|
rv = NS_NewHTMLInputText(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
1998-04-24 21:37:30 +00:00
|
|
|
else if (val.EqualsIgnoreCase("select1")) { // TEMP hack
|
|
|
|
rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 1);
|
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("select2")) { // TEMP hack
|
|
|
|
rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 2);
|
|
|
|
}
|
1998-04-28 18:59:38 +00:00
|
|
|
else if (val.EqualsIgnoreCase("select3")) { // TEMP hack
|
|
|
|
rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 3);
|
|
|
|
}
|
1998-04-22 22:12:24 +00:00
|
|
|
else {
|
|
|
|
rv = NS_NewHTMLInputSubmit(aInstancePtrResult, atom, mCurrentForm);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_ERROR_NOT_INITIALIZED == rv) {
|
|
|
|
// Create textfield when no type is specified
|
|
|
|
rv = NS_NewHTMLInputText(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((NS_OK == rv) && (nsnull != *aInstancePtrResult)) {
|
|
|
|
// Add remaining attributes from the tag
|
|
|
|
rv = AddAttributes(aNode, *aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-04-22 22:12:24 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessTEXTAREATag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
|
|
|
|
const nsString& content = aNode.GetSkippedContent();
|
|
|
|
|
|
|
|
nsresult rv = NS_NewHTMLTextArea(aInstancePtrResult, atom, mCurrentForm);
|
|
|
|
if ((NS_OK == rv) && (nsnull != *aInstancePtrResult)) {
|
|
|
|
// Add remaining attributes from the tag
|
|
|
|
rv = AddAttributes(aNode, *aInstancePtrResult);
|
1998-05-08 20:18:06 +00:00
|
|
|
if (0 < content.Length()) {
|
|
|
|
nsIFormControl* control;
|
|
|
|
rv = (*aInstancePtrResult)->QueryInterface(kIFormControlIID, (void **)&control);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
control->SetContent(content);
|
|
|
|
}
|
|
|
|
}
|
1998-04-22 22:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-04-22 23:24:43 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessOpenSELECTTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
|
|
|
|
if (nsnull != mCurrentSelect) {
|
|
|
|
NS_RELEASE(mCurrentSelect);
|
|
|
|
}
|
1998-05-08 20:18:06 +00:00
|
|
|
nsresult rv = NS_NewHTMLSelect(&mCurrentSelect, atom, mCurrentForm);
|
1998-04-22 23:24:43 +00:00
|
|
|
if ((NS_OK == rv) && (nsnull != mCurrentSelect)) {
|
|
|
|
// Add remaining attributes from the tag
|
1998-05-08 23:08:43 +00:00
|
|
|
//rv = AddAttributes(aNode, mCurrentSelect);
|
1998-04-22 23:24:43 +00:00
|
|
|
*aInstancePtrResult = mCurrentSelect;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessCloseSELECTTag(const nsIParserNode& aNode)
|
|
|
|
{
|
1998-05-08 20:18:06 +00:00
|
|
|
NS_IF_RELEASE(mCurrentSelect);
|
|
|
|
mCurrentSelect = nsnull;
|
1998-04-22 23:24:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1998-05-08 23:08:43 +00:00
|
|
|
HTMLContentSink::ProcessOpenOPTIONTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
1998-04-22 23:24:43 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (nsnull != mCurrentSelect) {
|
|
|
|
if (nsnull != mCurrentOption) {
|
|
|
|
NS_RELEASE(mCurrentOption);
|
|
|
|
}
|
1998-05-08 20:18:06 +00:00
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
rv = NS_NewHTMLOption(&mCurrentOption, atom);
|
|
|
|
if ((NS_OK == rv) && (nsnull != mCurrentSelect)) {
|
|
|
|
// Add remaining attributes from the tag
|
1998-05-08 23:08:43 +00:00
|
|
|
//rv = AddAttributes(aNode, mCurrentOption);
|
1998-05-13 17:43:35 +00:00
|
|
|
*aInstancePtrResult = mCurrentOption;
|
1998-05-08 20:18:06 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
1998-04-22 23:24:43 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessCloseOPTIONTag(const nsIParserNode& aNode)
|
|
|
|
{
|
1998-05-08 20:18:06 +00:00
|
|
|
NS_IF_RELEASE(mCurrentOption);
|
|
|
|
mCurrentOption = nsnull;
|
1998-04-22 23:24:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessOPTIONTagContent(const nsIParserNode& aNode)
|
|
|
|
{
|
1998-05-08 20:18:06 +00:00
|
|
|
if ((nsnull != mCurrentSelect) && (nsnull != mCurrentOption)) {
|
1998-06-06 20:25:11 +00:00
|
|
|
nsIFormControl* control = nsnull;
|
|
|
|
mCurrentOption->QueryInterface(kIFormControlIID, (void **)&control);
|
|
|
|
if (nsnull != control) {
|
|
|
|
// Get current content and append on the new content
|
|
|
|
nsAutoString currentText;
|
|
|
|
control->GetContent(currentText);
|
|
|
|
|
|
|
|
switch (aNode.GetTokenType()) {
|
|
|
|
case eToken_text:
|
|
|
|
case eToken_whitespace:
|
|
|
|
case eToken_newline:
|
|
|
|
currentText.Append(aNode.GetText());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eToken_entity:
|
|
|
|
{
|
|
|
|
nsAutoString tmp2("");
|
|
|
|
PRInt32 unicode = aNode.TranslateToUnicodeStr(tmp2);
|
|
|
|
if (unicode < 0) {
|
|
|
|
currentText.Append(aNode.GetText());
|
|
|
|
} else {
|
|
|
|
currentText.Append(tmp2);
|
|
|
|
}
|
1998-04-22 23:24:43 +00:00
|
|
|
}
|
1998-06-06 20:25:11 +00:00
|
|
|
break;
|
1998-04-22 23:24:43 +00:00
|
|
|
}
|
1998-06-06 20:25:11 +00:00
|
|
|
control->SetContent(currentText);
|
1998-04-22 23:24:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-06-11 16:46:33 +00:00
|
|
|
nsresult
|
|
|
|
HTMLContentSink::ProcessIFRAMETag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
|
1998-06-23 22:25:28 +00:00
|
|
|
nsresult rv = NS_NewHTMLIFrame(aInstancePtrResult, atom, mWebWidget);
|
1998-06-11 16:46:33 +00:00
|
|
|
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsresult HTMLContentSink::ProcessWBRTag(nsIHTMLContent** aInstancePtrResult,
|
|
|
|
const nsIParserNode& aNode)
|
|
|
|
{
|
|
|
|
nsAutoString tmp(aNode.GetText());
|
|
|
|
tmp.ToUpperCase();
|
|
|
|
nsIAtom* atom = NS_NewAtom(tmp);
|
|
|
|
nsresult rv = NS_NewHTMLWordBreak(aInstancePtrResult, atom);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
rv = AddAttributes(aNode, *aInstancePtrResult);
|
|
|
|
}
|
|
|
|
NS_RELEASE(atom);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-06-23 01:34:25 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult NS_NewHTMLContentSink(nsIHTMLContentSink** aInstancePtrResult,
|
|
|
|
nsIDocument* aDoc,
|
1998-06-23 22:25:28 +00:00
|
|
|
nsIURL* aURL,
|
|
|
|
nsIWebWidget* aWebWidget)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
HTMLContentSink* it = new HTMLContentSink();
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-06-23 22:25:28 +00:00
|
|
|
nsresult rv = it->Init(aDoc, aURL, aWebWidget);
|
1998-04-13 20:24:54 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
delete it;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return it->QueryInterface(kIHTMLContentSinkIID, (void **)aInstancePtrResult);
|
|
|
|
}
|