Bugs 53615 and 51815. XHTML title element did not change window title, and textarea did not have default text. r=harishd, sr=vidur.

This commit is contained in:
heikki%netscape.com 2001-02-03 01:16:20 +00:00
Родитель 89cc46a2cf
Коммит 0d215946ad
16 изменённых файлов: 145 добавлений и 260 удалений

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

@ -24,10 +24,7 @@
#define nsIXMLDocument_h___
#include "nsISupports.h"
#include "nsString.h"
class nsIAtom;
class nsICSSLoader;
class nsIURI;
#define NS_IXMLDOCUMENT_IID \
{ 0xa6cf90ca, 0x15b3, 0x11d2, \
@ -41,6 +38,8 @@ public:
static const nsIID& GetIID() { static nsIID iid = NS_IXMLDOCUMENT_IID; return iid; }
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl)=0;
NS_IMETHOD SetTitle(const PRUnichar *aTitle)=0;
};
#endif // nsIXMLDocument_h___

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

@ -149,6 +149,7 @@ nsXMLContentSink::nsXMLContentSink()
mTextSize = 0;
mConstrainSize = PR_TRUE;
mInScript = PR_FALSE;
mInTitle = PR_FALSE;
mStyleSheetCount = 0;
mCSSLoader = nsnull;
mXSLTransformMediator = nsnull;
@ -573,7 +574,7 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode)
tag.Assign(aNode.GetText());
nameSpacePrefix = getter_AddRefs(CutNameSpacePrefix(tag));
nsCOMPtr<nsIAtom> tagAtom = dont_AddRef(NS_NewAtom(tag));
nsCOMPtr<nsIAtom> tagAtom(dont_AddRef(NS_NewAtom(tag)));
// We must register namespace declarations found in the attribute list
// of an element before creating the element. This is because the
@ -591,13 +592,20 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode)
isHTML = IsHTMLNameSpace(nameSpaceID);
if (isHTML) {
if (nsHTMLAtoms::script == tagAtom.get()) {
if (tagAtom.get() == nsHTMLAtoms::script) {
result = ProcessStartSCRIPTTag(aNode);
} else if (tagAtom.get() == nsHTMLAtoms::title) {
if (mTitleText.IsEmpty())
mInTitle = PR_TRUE; // The first title wins
}
nsCOMPtr<nsIHTMLContent> htmlContent;
result = NS_CreateHTMLElement(getter_AddRefs(htmlContent), nodeInfo);
content = do_QueryInterface(htmlContent);
if (tagAtom.get() == nsHTMLAtoms::textarea) {
mTextAreaElement = do_QueryInterface(htmlContent);
}
}
else {
// The first step here is to see if someone has provided their
@ -683,11 +691,26 @@ nsXMLContentSink::CloseContainer(const nsIParserNode& aNode)
FlushText();
if (isHTML) {
nsIAtom* tagAtom = NS_NewAtom(tag);
if (nsHTMLAtoms::script == tagAtom) {
nsCOMPtr<nsIAtom> tagAtom(dont_AddRef(NS_NewAtom(tag)));
if (tagAtom.get() == nsHTMLAtoms::script) {
result = ProcessEndSCRIPTTag(aNode);
} else if (tagAtom.get() == nsHTMLAtoms::title) {
if (mInTitle) { // The first title wins
nsCOMPtr<nsIXMLDocument> xmlDoc(do_QueryInterface(mDocument));
if (xmlDoc) {
mTitleText.CompressWhitespace();
xmlDoc->SetTitle(mTitleText.GetUnicode());
}
mInTitle = PR_FALSE;
}
} else if (tagAtom.get() == nsHTMLAtoms::textarea) {
if (mTextAreaElement) {
mTextAreaElement->SetDefaultValue(mTextareaText);
mTextAreaElement = nsnull;
mTextareaText.Truncate();
}
}
NS_RELEASE(tagAtom);
}
nsCOMPtr<nsIContent> content;
@ -1306,6 +1329,10 @@ nsXMLContentSink::AddText(const nsAReadableString& aString)
if (mInScript) {
mScriptText.Append(aString);
} else if (mInTitle) {
mTitleText.Append(aString);
} else if (mTextAreaElement) {
mTextareaText.Append(aString);
}
// Create buffer when we first need it

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

@ -33,6 +33,7 @@
#include "nsIStreamLoader.h"
#include "nsISupportsArray.h"
#include "nsINodeInfo.h"
#include "nsIDOMHTMLTextAreaElement.h"
class nsIDocument;
class nsIScriptObjectOwner;
@ -178,6 +179,7 @@ protected:
// XXX Special processing for HTML SCRIPT tags. We may need
// something similar for STYLE.
PRPackedBool mInScript;
PRPackedBool mInTitle;
nsString mScriptText;
PRUint32 mScriptLineNo;
@ -187,7 +189,10 @@ protected:
nsCOMPtr<nsINodeInfoManager> mNodeInfoManager;
nsCOMPtr<nsITransformMediator> mXSLTransformMediator;
nsString mRef; // ScrollTo #ref
nsString mRef; // ScrollTo #ref
nsString mTitleText;
nsString mTextareaText;
nsCOMPtr<nsIDOMHTMLTextAreaElement> mTextAreaElement;
};
#endif // nsXMLContentSink_h__

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

@ -46,7 +46,7 @@
#include "nsIDOMComment.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
#include "nsIBaseWindow.h"
#include "nsIDOMCDATASection.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMDocumentType.h"
@ -1039,6 +1039,29 @@ nsXMLDocument::SetDefaultStylesheets(nsIURI* aUrl)
return result;
}
NS_IMETHODIMP
nsXMLDocument::SetTitle(const PRUnichar *aTitle)
{
// Pass on to any interested containers
PRInt32 i, n = mPresShells.Count();
for (i = 0; i < n; i++) {
nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(i);
nsCOMPtr<nsIPresContext> cx;
shell->GetPresContext(getter_AddRefs(cx));
nsCOMPtr<nsISupports> container;
if (NS_OK == cx->GetContainer(getter_AddRefs(container))) {
if (container) {
nsCOMPtr<nsIBaseWindow> docShell(do_QueryInterface(container));
if(docShell) {
docShell->SetTitle(aTitle);
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
{

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

@ -85,6 +85,7 @@ public:
// nsIXMLDocument interface
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl);
NS_IMETHOD SetTitle(const PRUnichar *aTitle);
// nsIHTMLContentContainer
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult);

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

@ -33,9 +33,8 @@
#ifndef nsIXULDocument_h___
#define nsIXULDocument_h___
class nsIContent; // XXX nsIXMLDocument.h is bad and doesn't declare this class...
#include "nsIXMLDocument.h"
#include "nsString.h"
class nsForwardReference;
class nsIAtom;
@ -47,6 +46,7 @@ class nsIRDFResource;
class nsISupportsArray;
class nsIXULPrototypeDocument;
class nsIURI;
class nsIContent;
// {954F0811-81DC-11d2-B52A-000000000000}
#define NS_IRDFDOCUMENT_IID \

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

@ -2046,6 +2046,14 @@ nsXULDocument::SetDefaultStylesheets(nsIURI* aUrl)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULDocument::SetTitle(const PRUnichar *aTitle)
{
NS_ASSERTION(0,"not implemented");
NS_NOTREACHED("nsXULDocument::SetTitle");
return NS_ERROR_NOT_IMPLEMENTED;
}
//----------------------------------------------------------------------
//
// nsIXULDocument interface

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

@ -284,6 +284,7 @@ public:
// nsIXMLDocument interface
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl);
NS_IMETHOD SetTitle(const PRUnichar *aTitle);
// nsIXULDocument interface
NS_IMETHOD AddElementForID(const nsAReadableString& aID, nsIContent* aElement);

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

@ -1,46 +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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIXMLDocument_h___
#define nsIXMLDocument_h___
#include "nsISupports.h"
#include "nsString.h"
class nsIAtom;
class nsICSSLoader;
#define NS_IXMLDOCUMENT_IID \
{ 0xa6cf90ca, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
/**
* XML document extensions to nsIDocument
*/
class nsIXMLDocument : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IXMLDOCUMENT_IID; return iid; }
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl)=0;
};
#endif // nsIXMLDocument_h___

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

@ -149,6 +149,7 @@ nsXMLContentSink::nsXMLContentSink()
mTextSize = 0;
mConstrainSize = PR_TRUE;
mInScript = PR_FALSE;
mInTitle = PR_FALSE;
mStyleSheetCount = 0;
mCSSLoader = nsnull;
mXSLTransformMediator = nsnull;
@ -573,7 +574,7 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode)
tag.Assign(aNode.GetText());
nameSpacePrefix = getter_AddRefs(CutNameSpacePrefix(tag));
nsCOMPtr<nsIAtom> tagAtom = dont_AddRef(NS_NewAtom(tag));
nsCOMPtr<nsIAtom> tagAtom(dont_AddRef(NS_NewAtom(tag)));
// We must register namespace declarations found in the attribute list
// of an element before creating the element. This is because the
@ -591,13 +592,20 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode)
isHTML = IsHTMLNameSpace(nameSpaceID);
if (isHTML) {
if (nsHTMLAtoms::script == tagAtom.get()) {
if (tagAtom.get() == nsHTMLAtoms::script) {
result = ProcessStartSCRIPTTag(aNode);
} else if (tagAtom.get() == nsHTMLAtoms::title) {
if (mTitleText.IsEmpty())
mInTitle = PR_TRUE; // The first title wins
}
nsCOMPtr<nsIHTMLContent> htmlContent;
result = NS_CreateHTMLElement(getter_AddRefs(htmlContent), nodeInfo);
content = do_QueryInterface(htmlContent);
if (tagAtom.get() == nsHTMLAtoms::textarea) {
mTextAreaElement = do_QueryInterface(htmlContent);
}
}
else {
// The first step here is to see if someone has provided their
@ -683,11 +691,26 @@ nsXMLContentSink::CloseContainer(const nsIParserNode& aNode)
FlushText();
if (isHTML) {
nsIAtom* tagAtom = NS_NewAtom(tag);
if (nsHTMLAtoms::script == tagAtom) {
nsCOMPtr<nsIAtom> tagAtom(dont_AddRef(NS_NewAtom(tag)));
if (tagAtom.get() == nsHTMLAtoms::script) {
result = ProcessEndSCRIPTTag(aNode);
} else if (tagAtom.get() == nsHTMLAtoms::title) {
if (mInTitle) { // The first title wins
nsCOMPtr<nsIXMLDocument> xmlDoc(do_QueryInterface(mDocument));
if (xmlDoc) {
mTitleText.CompressWhitespace();
xmlDoc->SetTitle(mTitleText.GetUnicode());
}
mInTitle = PR_FALSE;
}
} else if (tagAtom.get() == nsHTMLAtoms::textarea) {
if (mTextAreaElement) {
mTextAreaElement->SetDefaultValue(mTextareaText);
mTextAreaElement = nsnull;
mTextareaText.Truncate();
}
}
NS_RELEASE(tagAtom);
}
nsCOMPtr<nsIContent> content;
@ -1306,6 +1329,10 @@ nsXMLContentSink::AddText(const nsAReadableString& aString)
if (mInScript) {
mScriptText.Append(aString);
} else if (mInTitle) {
mTitleText.Append(aString);
} else if (mTextAreaElement) {
mTextareaText.Append(aString);
}
// Create buffer when we first need it

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

@ -1,193 +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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsXMLContentSink_h__
#define nsXMLContentSink_h__
#include "nsIXMLContentSink.h"
#include "nsIViewManager.h"
#include "nsIScrollableView.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsITransformMediator.h"
#include "nsIUnicharInputStream.h"
#include "nsIStreamLoader.h"
#include "nsISupportsArray.h"
#include "nsINodeInfo.h"
class nsIDocument;
class nsIScriptObjectOwner;
class nsIURI;
class nsIWebShell;
class nsIContent;
class nsVoidArray;
class nsIXMLDocument;
class nsIUnicharInputStream;
class nsIParser;
class nsINameSpace;
class nsICSSLoader;
class nsINameSpaceManager;
class nsIElementFactory;
typedef enum {
eXMLContentSinkState_InProlog,
eXMLContentSinkState_InDocumentElement,
eXMLContentSinkState_InEpilog
} XMLContentSinkState;
// XXX Till the parser knows a little bit more about XML,
// this is a HTMLContentSink.
class nsXMLContentSink : public nsIXMLContentSink,
public nsIObserver,
public nsSupportsWeakReference,
public nsIStreamLoaderObserver
{
public:
nsXMLContentSink();
virtual ~nsXMLContentSink();
nsresult Init(nsIDocument* aDoc,
nsIURI* aURL,
nsIWebShell* aContainer);
// nsISupports
NS_DECL_ISUPPORTS
NS_DECL_NSISTREAMLOADEROBSERVER
// nsIContentSink
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);
NS_IMETHOD SetParser(nsIParser* aParser);
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
NS_IMETHOD AddComment(const nsIParserNode& aNode);
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
NS_IMETHOD AddCDATASection(const nsIParserNode& aNode);
NS_IMETHOD NotifyError(const nsParserError* aError);
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0);
NS_IMETHOD FlushPendingNotifications() { return NS_OK; }
// nsIXMLContentSink
NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode);
NS_IMETHOD AddCharacterData(const nsIParserNode& aNode);
NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode);
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
// nsIObserver
NS_IMETHOD Observe(nsISupports *aSubject,
const PRUnichar *aTopic,
const PRUnichar *someData);
NS_IMETHOD ResumeParsing();
NS_IMETHOD EvaluateScript(nsString& aScript, nsIURI *aScriptURI, PRUint32 aLineNo, const char* aVersion);
const char* mScriptLanguageVersion;
protected:
void StartLayout();
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
PRBool* aDidFlush=nsnull);
nsresult AddAttributes(const nsIParserNode& aNode,
nsIContent* aContent,
PRBool aIsHTML);
nsresult AddContentAsLeaf(nsIContent *aContent);
void PushNameSpacesFrom(const nsIParserNode& aNode);
nsIAtom* CutNameSpacePrefix(nsString& aString);
PRInt32 GetNameSpaceId(nsIAtom* aPrefix);
nsINameSpace* PopNameSpaces();
PRBool IsHTMLNameSpace(PRInt32 aId);
nsIContent* GetCurrentContent();
PRInt32 PushContent(nsIContent *aContent);
nsIContent* PopContent();
nsresult ProcessEndSCRIPTTag(const nsIParserNode& aNode);
nsresult ProcessStartSCRIPTTag(const nsIParserNode& aNode);
nsresult RefreshIfEnabled(nsIViewManager* vm);
nsresult ProcessCSSStyleLink(nsIContent* aElement,
const nsString& aHref, PRBool aAlternate,
const nsString& aTitle, const nsString& aType,
const nsString& aMedia);
nsresult ProcessStyleLink(nsIContent* aElement,
const nsString& aHref, PRBool aAlternate,
const nsString& aTitle, const nsString& aType,
const nsString& aMedia);
nsresult ProcessXSLStyleLink(nsIContent* aElement,
const nsString& aHref, PRBool aAlternate,
const nsString& aTitle, const nsString& aType,
const nsString& aMedia);
nsresult CreateStyleSheetURL(nsIURI** aUrl, const nsAReadableString& aHref);
nsresult LoadXSLStyleSheet(nsIURI* aUrl, const nsString& aType);
nsresult SetupTransformMediator();
nsresult AddText(const nsAReadableString& aString);
static void
GetElementFactory(PRInt32 aNameSpaceID, nsIElementFactory** aResult);
void ScrollToRef();
static nsINameSpaceManager* gNameSpaceManager;
static PRUint32 gRefCnt;
nsIDocument* mDocument;
nsIURI* mDocumentURL;
nsIURI* mDocumentBaseURL; // can be set via HTTP headers
nsIWebShell* mWebShell;
nsIParser* mParser;
nsIContent* mRootElement;
nsIContent* mDocElement;
XMLContentSinkState mState;
nsCOMPtr<nsISupportsArray> mContentStack;
nsVoidArray* mNameSpaceStack;
nsScrollPreference mOriginalScrollPreference;
PRUnichar* mText;
PRInt32 mTextLength;
PRInt32 mTextSize;
PRPackedBool mConstrainSize;
// XXX Special processing for HTML SCRIPT tags. We may need
// something similar for STYLE.
PRPackedBool mInScript;
nsString mScriptText;
PRUint32 mScriptLineNo;
nsString mPreferredStyle;
PRInt32 mStyleSheetCount;
nsICSSLoader* mCSSLoader;
nsCOMPtr<nsINodeInfoManager> mNodeInfoManager;
nsCOMPtr<nsITransformMediator> mXSLTransformMediator;
nsString mRef; // ScrollTo #ref
};
#endif // nsXMLContentSink_h__

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

@ -46,7 +46,7 @@
#include "nsIDOMComment.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
#include "nsIBaseWindow.h"
#include "nsIDOMCDATASection.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMDocumentType.h"
@ -1039,6 +1039,29 @@ nsXMLDocument::SetDefaultStylesheets(nsIURI* aUrl)
return result;
}
NS_IMETHODIMP
nsXMLDocument::SetTitle(const PRUnichar *aTitle)
{
// Pass on to any interested containers
PRInt32 i, n = mPresShells.Count();
for (i = 0; i < n; i++) {
nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(i);
nsCOMPtr<nsIPresContext> cx;
shell->GetPresContext(getter_AddRefs(cx));
nsCOMPtr<nsISupports> container;
if (NS_OK == cx->GetContainer(getter_AddRefs(container))) {
if (container) {
nsCOMPtr<nsIBaseWindow> docShell(do_QueryInterface(container));
if(docShell) {
docShell->SetTitle(aTitle);
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
{

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

@ -85,6 +85,7 @@ public:
// nsIXMLDocument interface
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl);
NS_IMETHOD SetTitle(const PRUnichar *aTitle);
// nsIHTMLContentContainer
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult);

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

@ -33,9 +33,8 @@
#ifndef nsIXULDocument_h___
#define nsIXULDocument_h___
class nsIContent; // XXX nsIXMLDocument.h is bad and doesn't declare this class...
#include "nsIXMLDocument.h"
#include "nsString.h"
class nsForwardReference;
class nsIAtom;
@ -47,6 +46,7 @@ class nsIRDFResource;
class nsISupportsArray;
class nsIXULPrototypeDocument;
class nsIURI;
class nsIContent;
// {954F0811-81DC-11d2-B52A-000000000000}
#define NS_IRDFDOCUMENT_IID \

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

@ -2046,6 +2046,14 @@ nsXULDocument::SetDefaultStylesheets(nsIURI* aUrl)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULDocument::SetTitle(const PRUnichar *aTitle)
{
NS_ASSERTION(0,"not implemented");
NS_NOTREACHED("nsXULDocument::SetTitle");
return NS_ERROR_NOT_IMPLEMENTED;
}
//----------------------------------------------------------------------
//
// nsIXULDocument interface

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

@ -284,6 +284,7 @@ public:
// nsIXMLDocument interface
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl);
NS_IMETHOD SetTitle(const PRUnichar *aTitle);
// nsIXULDocument interface
NS_IMETHOD AddElementForID(const nsAReadableString& aID, nsIContent* aElement);