Fixing bug 111514. In an XHTML document served as application/xhtml+xml, |document| is not an HTML document object, but an XML document object. r=bugmail@sicking.cc, sr=peterv@netscape.com

This commit is contained in:
jst%netscape.com 2003-04-19 00:28:09 +00:00
Родитель f11a7a6813
Коммит 3ce5ccf835
17 изменённых файлов: 364 добавлений и 297 удалений

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

@ -457,6 +457,19 @@ public:
NS_IMETHOD GetContainer(nsISupports **aContainer) = 0;
NS_IMETHOD GetScriptEventManager(nsIScriptEventManager **aResult) = 0;
/**
* Set and get XML declaration. Notice that if version is empty,
* there can be no XML declaration (it is a required part).
*/
NS_IMETHOD SetXMLDeclaration(const nsAString& aVersion,
const nsAString& aEncoding,
const nsAString& Standalone) = 0;
NS_IMETHOD GetXMLDeclaration(nsAString& aVersion,
nsAString& aEncoding,
nsAString& Standalone) = 0;
NS_IMETHOD_(PRBool) IsCaseSensitive() = 0;
};

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

@ -686,6 +686,8 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
mPrincipal = do_QueryInterface(owner);
}
mXMLDeclarationBits = 0;
return rv;
}
@ -811,8 +813,6 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
if (NS_SUCCEEDED(rv)) {
mContentLanguage.AssignWithConversion(prefLanguage);
have_contentLanguage = PR_TRUE;
}
}
}
@ -2449,12 +2449,23 @@ nsDocument::CreateAttribute(const nsAString& aName,
}
NS_IMETHODIMP
nsDocument::CreateAttributeNS(const nsAString & namespaceURI,
const nsAString & qualifiedName,
nsIDOMAttr **_retval)
nsDocument::CreateAttributeNS(const nsAString & aNamespaceURI,
const nsAString & aQualifiedName,
nsIDOMAttr **aResult)
{
// Should be implemented by subclass
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
nsCOMPtr<nsINodeInfo> nodeInfo;
nsresult rv = mNodeInfoManager->GetNodeInfo(aQualifiedName, aNamespaceURI,
*getter_AddRefs(nodeInfo));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString value;
nsDOMAttribute* attribute = new nsDOMAttribute(nsnull, nodeInfo, value);
NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY);
return CallQueryInterface(attribute, aResult);
}
NS_IMETHODIMP
@ -3936,6 +3947,71 @@ nsDocument::GetScriptEventManager(nsIScriptEventManager **aResult)
return NS_OK;
}
NS_IMETHODIMP
nsDocument::SetXMLDeclaration(const nsAString& aVersion,
const nsAString& aEncoding,
const nsAString& aStandalone)
{
if (aVersion.IsEmpty()) {
mXMLDeclarationBits = 0;
return NS_OK;
}
mXMLDeclarationBits = XML_DECLARATION_BITS_DECLARATION_EXISTS;
if (!aEncoding.IsEmpty()) {
mXMLDeclarationBits |= XML_DECLARATION_BITS_ENCODING_EXISTS;
}
if (aStandalone.Equals(NS_LITERAL_STRING("yes"))) {
mXMLDeclarationBits |= XML_DECLARATION_BITS_STANDALONE_EXISTS |
XML_DECLARATION_BITS_STANDALONE_YES;
} else if (aStandalone.Equals(NS_LITERAL_STRING("no"))) {
mXMLDeclarationBits |= XML_DECLARATION_BITS_STANDALONE_EXISTS;
}
return NS_OK;
}
NS_IMETHODIMP
nsDocument::GetXMLDeclaration(nsAString& aVersion, nsAString& aEncoding,
nsAString& aStandalone)
{
aVersion.Truncate();
aEncoding.Truncate();
aStandalone.Truncate();
if (!(mXMLDeclarationBits & XML_DECLARATION_BITS_DECLARATION_EXISTS)) {
return NS_OK;
}
// always until we start supporting 1.1 etc.
aVersion.Assign(NS_LITERAL_STRING("1.0"));
if (mXMLDeclarationBits & XML_DECLARATION_BITS_ENCODING_EXISTS) {
// This is what we have stored, not necessarily what was written
// in the original
GetDocumentCharacterSet(aEncoding);
}
if (mXMLDeclarationBits & XML_DECLARATION_BITS_STANDALONE_EXISTS) {
if (mXMLDeclarationBits & XML_DECLARATION_BITS_STANDALONE_YES) {
aStandalone.Assign(NS_LITERAL_STRING("yes"));
} else {
aStandalone.Assign(NS_LITERAL_STRING("no"));
}
}
return NS_OK;
}
NS_IMETHODIMP_(PRBool)
nsDocument::IsCaseSensitive()
{
return PR_TRUE;
}
nsresult
nsDocument::GetRadioGroup(const nsAString& aName,
nsRadioGroupStruct **aRadioGroup)

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

@ -81,6 +81,13 @@
#include "pldhash.h"
#define XML_DECLARATION_BITS_DECLARATION_EXISTS (1 << 0)
#define XML_DECLARATION_BITS_ENCODING_EXISTS (1 << 1)
#define XML_DECLARATION_BITS_STANDALONE_EXISTS (1 << 2)
#define XML_DECLARATION_BITS_STANDALONE_YES (1 << 3)
class nsIEventListenerManager;
class nsDOMStyleSheetList;
class nsIOutputStream;
@ -489,6 +496,13 @@ public:
NS_IMETHOD SetContainer(nsISupports *aContainer);
NS_IMETHOD GetContainer(nsISupports **aContainer);
NS_IMETHOD GetScriptEventManager(nsIScriptEventManager **aResult);
NS_IMETHOD SetXMLDeclaration(const nsAString& aVersion,
const nsAString& aEncoding,
const nsAString& Standalone);
NS_IMETHOD GetXMLDeclaration(nsAString& aVersion,
nsAString& aEncoding,
nsAString& Standalone);
NS_IMETHOD_(PRBool) IsCaseSensitive();
// nsIRadioGroupContainer
NS_IMETHOD WalkRadioGroup(const nsAString& aName,
@ -641,6 +655,8 @@ protected:
// True if the document is being destroyed.
PRPackedBool mInDestructor;
PRUint8 mXMLDeclarationBits;
nsSupportsHashtable* mBoxObjectTable;
nsSupportsHashtable mContentWrapperHash;

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

@ -55,7 +55,6 @@
#include "prprf.h"
#include "nsUnicharUtils.h"
#include "nsCRT.h"
#include "nsIXMLDocument.h"
#include "nsContentUtils.h"
typedef struct {
@ -757,13 +756,13 @@ nsXMLContentSerializer::AppendDocumentStart(nsIDOMDocument *aDocument,
{
NS_ENSURE_ARG_POINTER(aDocument);
nsCOMPtr<nsIXMLDocument> xml(do_QueryInterface(aDocument));
if (!xml) {
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aDocument));
if (!doc) {
return NS_OK;
}
nsAutoString version, encoding, standalone;
xml->GetXMLDeclaration(version, encoding, standalone);
doc->GetXMLDeclaration(version, encoding, standalone);
if (version.IsEmpty())
return NS_OK; // A declaration must have version, or there is no decl

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

@ -48,6 +48,7 @@
#include "nsHTMLDocument.h"
#include "nsIParserFilter.h"
#include "nsIHTMLContentSink.h"
#include "nsIXMLContentSink.h"
#include "nsHTMLParts.h"
#include "nsIHTMLStyleSheet.h"
#include "nsIHTMLCSSStyleSheet.h"
@ -74,6 +75,7 @@
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIDocShell.h"
#include "nsIWebShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIWebNavigation.h"
#include "nsIBaseWindow.h"
@ -159,6 +161,11 @@ static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
static PRBool
IsNamedItem(nsIContent* aContent, nsIAtom *aTag, nsAString& aName);
// MatchElementId is defined in nsXMLDocument.cpp
nsIContent *
MatchElementId(nsIContent *aContent, const nsAString& aId);
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
nsIRDFService* nsHTMLDocument::gRDF;
@ -818,7 +825,24 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
PRBool aReset,
nsIContentSink* aSink)
{
PRBool needsParser=PR_TRUE;
nsCAutoString contentType;
aChannel->GetContentType(contentType);
if (contentType.Equals("application/xhtml+xml") &&
(!aCommand || nsCRT::strcmp(aCommand, "view-source") != 0)) {
// We're parsing XHTML as XML, remember that.
mDefaultNamespaceID = kNameSpaceID_XHTML;
mCompatMode = eCompatibility_FullStandards;
}
#ifdef DEBUG
else {
NS_ASSERTION(mDefaultNamespaceID == kNameSpaceID_None,
"Hey, someone forgot to reset mDefaultNamespaceID!!!");
}
#endif
PRBool needsParser = PR_TRUE;
if (aCommand)
{
if (!nsCRT::strcmp(aCommand, "view delayedContentLoad")) {
@ -997,15 +1021,29 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
mParser->SetCommand(aCommand);
// create the content sink
nsCOMPtr<nsIHTMLContentSink> sink;
nsCOMPtr<nsIContentSink> sink;
if (aSink)
sink = do_QueryInterface(aSink);
sink = aSink;
else {
rv = NS_NewHTMLContentSink(getter_AddRefs(sink), this, aURL, aContainer,
aChannel);
if (NS_FAILED(rv)) {
return rv;
if (IsXHTML()) {
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(aContainer));
nsCOMPtr<nsIXMLContentSink> xmlsink;
rv = NS_NewXMLContentSink(getter_AddRefs(xmlsink), this, aURL,
webShell, aChannel);
sink = xmlsink;
} else {
nsCOMPtr<nsIHTMLContentSink> htmlsink;
rv = NS_NewHTMLContentSink(getter_AddRefs(htmlsink), this, aURL,
docShell, aChannel);
sink = htmlsink;
}
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(sink,
"null sink with successful result from factory method");
}
@ -1147,7 +1185,15 @@ nsHTMLDocument::GetImageMap(const nsAString& aMapName,
for (i = 0; i < n; i++) {
nsCOMPtr<nsIDOMHTMLMapElement> map = mImageMaps[i];
if (map && NS_SUCCEEDED(map->GetName(name))) {
if (name.Equals(aMapName, nsCaseInsensitiveStringComparator())) {
PRBool match;
if (IsXHTML()) {
match = name.Equals(aMapName);
} else {
match = name.Equals(aMapName, nsCaseInsensitiveStringComparator());
}
if (match) {
*aResult = map;
NS_ADDREF(*aResult);
return NS_OK;
@ -1304,7 +1350,7 @@ nsHTMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
NS_ENSURE_SUCCESS(rv, rv);
}
mCSSLoader->SetCaseSensitive(PR_FALSE);
mCSSLoader->SetCaseSensitive(IsXHTML());
mCSSLoader->SetCompatibilityMode(mCompatMode);
aLoader = mCSSLoader;
@ -1324,6 +1370,9 @@ nsHTMLDocument::GetCompatibilityMode(nsCompatibility& aMode)
NS_IMETHODIMP
nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode)
{
NS_ASSERTION(!IsXHTML() || aMode == eCompatibility_FullStandards,
"Bad compat mode for XHTML document!");
mCompatMode = aMode;
if (mCSSLoader) {
mCSSLoader->SetCompatibilityMode(mCompatMode);
@ -1421,9 +1470,8 @@ nsHTMLDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
{
NS_ABORT_IF_FALSE(aContent, "Null content!");
// XXX: Check namespaces!!!
if (aAttribute == nsHTMLAtoms::name) {
if (!IsXHTML() && aAttribute == nsHTMLAtoms::name &&
aNameSpaceID == kNameSpaceID_None) {
nsCOMPtr<nsIAtom> tag;
nsAutoString value;
@ -1436,7 +1484,8 @@ nsHTMLDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
return rv;
}
}
} else if (aAttribute == nsHTMLAtoms::id) {
} else if (aAttribute == nsHTMLAtoms::id &&
aNameSpaceID == kNameSpaceID_None) {
nsresult rv = RemoveFromIdTable(aContent);
if (NS_FAILED(rv)) {
@ -1449,13 +1498,13 @@ nsHTMLDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
NS_IMETHODIMP
nsHTMLDocument::AttributeChanged(nsIContent* aContent, PRInt32 aNameSpaceID,
nsIAtom* aAttribute, PRInt32 aModType, nsChangeHint aHint)
nsIAtom* aAttribute, PRInt32 aModType,
nsChangeHint aHint)
{
NS_ABORT_IF_FALSE(aContent, "Null content!");
// XXX: Check namespaces!
if (aAttribute == nsHTMLAtoms::name) {
if (!IsXHTML() && aAttribute == nsHTMLAtoms::name &&
aNameSpaceID == kNameSpaceID_None) {
nsCOMPtr<nsIAtom> tag;
nsAutoString value;
@ -1468,7 +1517,8 @@ nsHTMLDocument::AttributeChanged(nsIContent* aContent, PRInt32 aNameSpaceID,
return rv;
}
}
} else if (aAttribute == nsHTMLAtoms::id) {
} else if (aAttribute == nsHTMLAtoms::id &&
aNameSpaceID == kNameSpaceID_None) {
nsAutoString value;
aContent->GetAttr(aNameSpaceID, nsHTMLAtoms::id, value);
@ -1520,6 +1570,12 @@ nsHTMLDocument::FlushPendingNotifications(PRBool aFlushReflows,
return nsDocument::FlushPendingNotifications(aFlushReflows, aUpdateViews);
}
NS_IMETHODIMP_(PRBool)
nsHTMLDocument::IsCaseSensitive()
{
return IsXHTML();
}
NS_IMETHODIMP
nsHTMLDocument::CreateElementNS(const nsAString& aNamespaceURI,
const nsAString& aQualifiedName,
@ -1567,20 +1623,23 @@ nsHTMLDocument::CreateElement(const nsAString& aTagName,
NS_ENSURE_TRUE(!aTagName.IsEmpty(), NS_ERROR_DOM_INVALID_CHARACTER_ERR);
nsCOMPtr<nsINodeInfo> nodeInfo;
nsAutoString tmp(aTagName);
ToLowerCase(tmp);
mNodeInfoManager->GetNodeInfo(tmp, nsnull, kNameSpaceID_None,
*getter_AddRefs(nodeInfo));
nsAutoString tmp(aTagName);
if (!IsXHTML()) {
ToLowerCase(tmp);
}
nsresult rv = mNodeInfoManager->GetNodeInfo(tmp, nsnull, mDefaultNamespaceID,
*getter_AddRefs(nodeInfo));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIHTMLContent> content;
nsresult rv = NS_CreateHTMLElement(getter_AddRefs(content), nodeInfo,
PR_FALSE);
if (NS_SUCCEEDED(rv)) {
content->SetContentID(mNextContentID++);
rv = CallQueryInterface(content, aReturn);
}
return rv;
rv = NS_CreateHTMLElement(getter_AddRefs(content), nodeInfo, IsXHTML());
NS_ENSURE_SUCCESS(rv, rv);
content->SetContentID(mNextContentID++);
return CallQueryInterface(content, aReturn);
}
NS_IMETHODIMP
@ -1864,16 +1923,14 @@ NS_IMETHODIMP
nsHTMLDocument::LookupNamespacePrefix(const nsAString& aNamespaceURI,
nsAString& aPrefix)
{
aPrefix.Truncate();
return NS_OK;
return nsDocument::LookupNamespacePrefix(aNamespaceURI, aPrefix);
}
NS_IMETHODIMP
nsHTMLDocument::LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI)
{
aNamespaceURI.Truncate();
return NS_OK;
return nsDocument::LookupNamespaceURI(aNamespacePrefix, aNamespaceURI);
}
@ -2044,6 +2101,8 @@ nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
nsCOMPtr<nsIDOMNodeList> nodeList;
// XXX: This is not quite right, and we should deal with XHTML
// here too.
nsresult rv = GetElementsByTagName(NS_LITERAL_STRING("frameset"),
getter_AddRefs(nodeList));
if (NS_FAILED(rv))
@ -2066,6 +2125,9 @@ nsHTMLDocument::SetBody(nsIDOMHTMLElement* aBody)
{
nsCOMPtr<nsIDOMHTMLBodyElement> bodyElement(do_QueryInterface(aBody));
// Hmm, this is wrong, and not XHTML cool. The body can be a
// frameset too!
// The body element must be of type nsIDOMHTMLBodyElement.
if (!bodyElement) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
@ -2113,7 +2175,7 @@ NS_IMETHODIMP
nsHTMLDocument::GetImages(nsIDOMHTMLCollection** aImages)
{
if (!mImages) {
mImages = new nsContentList(this, nsHTMLAtoms::img, kNameSpaceID_Unknown);
mImages = new nsContentList(this, nsHTMLAtoms::img, mDefaultNamespaceID);
if (!mImages) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -2130,7 +2192,7 @@ nsHTMLDocument::GetApplets(nsIDOMHTMLCollection** aApplets)
{
if (!mApplets) {
mApplets = new nsContentList(this, nsHTMLAtoms::applet,
kNameSpaceID_None);
mDefaultNamespaceID);
if (!mApplets) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -2142,14 +2204,42 @@ nsHTMLDocument::GetApplets(nsIDOMHTMLCollection** aApplets)
return NS_OK;
}
PRInt32
GetHTMLDocumentNamespace(nsIContent *aContent)
{
nsCOMPtr<nsIDocument> doc;
aContent->GetDocument(*getter_AddRefs(doc));
NS_ASSERTION(doc, "This method should never be called on content nodes "
"that are not in a document!");
#ifdef DEBUG
{
nsCOMPtr<nsIHTMLDocument> htmldoc(do_QueryInterface(doc));
if (!htmldoc) {
NS_ERROR("Huh, how did this happen? This should only be used with "
"HTML documents!");
}
}
#endif
return doc->IsCaseSensitive() ? kNameSpaceID_XHTML : kNameSpaceID_None;
}
PRBool
nsHTMLDocument::MatchLinks(nsIContent *aContent, nsString* aData)
{
nsCOMPtr<nsIAtom> name;
aContent->GetTag(*getter_AddRefs(name));
nsCOMPtr<nsINodeInfo> ni;
aContent->GetNodeInfo(*getter_AddRefs(ni));
if (name == nsHTMLAtoms::area || name == nsHTMLAtoms::a) {
return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::href);
if (ni) {
PRInt32 namespaceID = GetHTMLDocumentNamespace(aContent);
if (ni->Equals(nsHTMLAtoms::a, namespaceID) ||
ni->Equals(nsHTMLAtoms::area, namespaceID)) {
return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::href);
}
}
return PR_FALSE;
@ -2174,11 +2264,15 @@ nsHTMLDocument::GetLinks(nsIDOMHTMLCollection** aLinks)
PRBool
nsHTMLDocument::MatchAnchors(nsIContent *aContent, nsString* aData)
{
nsCOMPtr<nsIAtom> name;
aContent->GetTag(*getter_AddRefs(name));
nsCOMPtr<nsINodeInfo> ni;
aContent->GetNodeInfo(*getter_AddRefs(ni));
if (name == nsHTMLAtoms::a) {
return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::name);
if (ni) {
PRInt32 namespaceID = GetHTMLDocumentNamespace(aContent);
if (ni->Equals(nsHTMLAtoms::a, namespaceID)) {
return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::name);
}
}
return PR_FALSE;
@ -2337,8 +2431,15 @@ nsresult
nsHTMLDocument::OpenCommon(nsIURI* aSourceURL)
{
// If we already have a parser we ignore the document.open call.
if (mParser)
if (mParser) {
if (IsXHTML()) {
// No calling document.open() while we're parsing XHTML
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
return NS_OK;
}
nsCOMPtr<nsIDocShell> docshell;
@ -2589,6 +2690,10 @@ nsHTMLDocument::WriteCommon(const nsAString& aText,
if (NS_FAILED(rv)) {
return rv;
}
} else if (IsXHTML()) {
// No calling document.write*() while parsing XHTML!
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
mWriteLevel++;
@ -2737,37 +2842,6 @@ nsHTMLDocument::Writeln()
return ScriptWriteCommon(PR_TRUE);
}
nsIContent *
nsHTMLDocument::MatchId(nsIContent *aContent, const nsAString& aId)
{
// Most elements don't have an id, so lets call the faster HasAttr()
// method before we create a string object and call GetAttr().
if (aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::id)) {
nsAutoString value;
nsresult rv = aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, value);
if (rv == NS_CONTENT_ATTR_HAS_VALUE && aId.Equals(value)) {
return aContent;
}
}
nsIContent *result = nsnull;
PRInt32 i, count;
aContent->ChildCount(count);
for (i = 0; i < count && !result; i++) {
nsIContent *child;
aContent->ChildAt(i, child);
result = MatchId(child, aId);
NS_RELEASE(child);
}
return result;
}
NS_IMETHODIMP
nsHTMLDocument::GetElementById(const nsAString& aElementId,
nsIDOMElement** aReturn)
@ -2794,7 +2868,7 @@ nsHTMLDocument::GetElementById(const nsAString& aElementId,
"getElementById(\"\") called, fix caller?");
if (mRootContent && !aElementId.IsEmpty()) {
e = MatchId(mRootContent, aElementId);
e = MatchElementId(mRootContent, aElementId);
}
if (!e) {
@ -2825,8 +2899,7 @@ nsHTMLDocument::CreateAttributeNS(const nsAString& aNamespaceURI,
const nsAString& aQualifiedName,
nsIDOMAttr** aReturn)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
return nsDocument::CreateAttributeNS(aNamespaceURI, aQualifiedName, aReturn);
}
NS_IMETHODIMP
@ -2835,9 +2908,12 @@ nsHTMLDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
nsIDOMNodeList** aReturn)
{
nsAutoString tmp(aLocalName);
ToLowerCase(tmp); // HTML elements are lower case internally.
return nsDocument::GetElementsByTagNameNS(aNamespaceURI, tmp,
aReturn);
if (!IsXHTML()) {
ToLowerCase(tmp); // HTML elements are lower case internally.
}
return nsDocument::GetElementsByTagNameNS(aNamespaceURI, tmp, aReturn);
}
PRBool
@ -3226,8 +3302,7 @@ NS_IMETHODIMP
nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds)
{
if (!mEmbeds) {
mEmbeds = new nsContentList(this, nsHTMLAtoms::embed,
kNameSpaceID_Unknown);
mEmbeds = new nsContentList(this, nsHTMLAtoms::embed, mDefaultNamespaceID);
if (!mEmbeds) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -3458,6 +3533,8 @@ nsresult
nsHTMLDocument::UpdateNameTableEntry(const nsAString& aName,
nsIContent *aContent)
{
NS_ASSERTION(!IsXHTML(), "Don't call me on an XHTML document!!!");
IdAndNameMapEntry *entry =
NS_STATIC_CAST(IdAndNameMapEntry *,
PL_DHashTableOperate(&mIdAndNameHashTable, &aName,
@ -3521,6 +3598,8 @@ nsresult
nsHTMLDocument::RemoveFromNameTable(const nsAString& aName,
nsIContent *aContent)
{
NS_ASSERTION(!IsXHTML(), "Don't call me on an XHTML document!!!");
IdAndNameMapEntry *entry =
NS_STATIC_CAST(IdAndNameMapEntry *,
PL_DHashTableOperate(&mIdAndNameHashTable, &aName,
@ -3579,7 +3658,7 @@ nsHTMLDocument::UnregisterNamedItems(nsIContent *aContent)
nsAutoString value;
nsresult rv = NS_OK;
if (IsNamedItem(aContent, tag, value)) {
if (!IsXHTML() && IsNamedItem(aContent, tag, value)) {
rv = RemoveFromNameTable(value, aContent);
if (NS_FAILED(rv)) {
@ -3625,7 +3704,7 @@ nsHTMLDocument::RegisterNamedItems(nsIContent *aContent)
nsAutoString value;
if (IsNamedItem(aContent, tag, value)) {
if (!IsXHTML() && IsNamedItem(aContent, tag, value)) {
UpdateNameTableEntry(value, aContent);
}
@ -3658,7 +3737,7 @@ nsHTMLDocument::RegisterNamedItems(nsIContent *aContent)
static void
FindNamedItems(const nsAString& aName, nsIContent *aContent,
IdAndNameMapEntry& aEntry)
IdAndNameMapEntry& aEntry, PRBool aIsXHTML)
{
NS_ASSERTION(aEntry.mContentList,
"Entry w/o content list passed to FindNamedItems()!");
@ -3674,7 +3753,7 @@ FindNamedItems(const nsAString& aName, nsIContent *aContent,
nsAutoString value;
if (IsNamedItem(aContent, tag, value) && value.Equals(aName)) {
if (!aIsXHTML && IsNamedItem(aContent, tag, value) && value.Equals(aName)) {
aEntry.mContentList->AppendElement(aContent);
}
@ -3695,7 +3774,7 @@ FindNamedItems(const nsAString& aName, nsIContent *aContent,
for (i = 0; i < count; i++) {
aContent->ChildAt(i, *getter_AddRefs(child));
FindNamedItems(aName, child, aEntry);
FindNamedItems(aName, child, aEntry, aIsXHTML);
}
}
@ -3706,6 +3785,12 @@ nsHTMLDocument::ResolveName(const nsAString& aName,
{
*aResult = nsnull;
if (IsXHTML()) {
// We don't dynamically resolve names on XHTML documents.
return NS_OK;
}
// Bug 69826 - Make sure to flush the content model if the document
// is still loading.
@ -3737,8 +3822,10 @@ nsHTMLDocument::ResolveName(const nsAString& aName,
entry->mContentList = list;
NS_ADDREF(entry->mContentList);
if(mRootContent && !aName.IsEmpty()) {
FindNamedItems(aName, mRootContent, *entry);
if (mRootContent && !aName.IsEmpty()) {
// We'll never get here if !IsXHTML(), so we can just pass
// PR_FALSE to FindNamedItems().
FindNamedItems(aName, mRootContent, *entry, PR_FALSE);
}
}
@ -3864,7 +3951,7 @@ nsHTMLDocument::GetBodyContent()
nsCOMPtr<nsINodeInfo> ni;
child->GetNodeInfo(*getter_AddRefs(ni));
if (ni->Equals(nsHTMLAtoms::body)) {
if (ni->Equals(nsHTMLAtoms::body, mDefaultNamespaceID)) {
mBodyContent = do_QueryInterface(child);
return PR_TRUE;
@ -3895,7 +3982,7 @@ NS_IMETHODIMP
nsHTMLDocument::GetForms(nsIDOMHTMLCollection** aForms)
{
if (!mForms) {
mForms = new nsContentList(this, nsHTMLAtoms::form, kNameSpaceID_Unknown);
mForms = new nsContentList(this, nsHTMLAtoms::form, mDefaultNamespaceID);
if (!mForms) {
return NS_ERROR_OUT_OF_MEMORY;
}

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

@ -126,7 +126,10 @@ public:
NS_IMETHOD GetCompatibilityMode(nsCompatibility& aMode);
NS_IMETHOD SetCompatibilityMode(nsCompatibility aMode);
NS_IMETHOD_(PRBool) IsWriting() { return mWriteLevel != PRUint32(0); }
NS_IMETHOD_(PRBool) IsWriting()
{
return mWriteLevel != PRUint32(0);
}
NS_IMETHOD ContentAppended(nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
@ -152,6 +155,8 @@ public:
NS_IMETHOD FlushPendingNotifications(PRBool aFlushReflows = PR_TRUE,
PRBool aUpdateViews = PR_FALSE);
NS_IMETHOD_(PRBool) IsCaseSensitive();
// nsIDOMDocument interface
NS_DECL_NSIDOMDOCUMENT
@ -199,6 +204,11 @@ public:
NS_IMETHOD RemovedForm();
NS_IMETHOD GetNumFormsSynchronous(PRInt32* aNumForms);
PRBool IsXHTML()
{
return mDefaultNamespaceID == kNameSpaceID_XHTML;
}
protected:
nsresult GetPixelDimensions(nsIPresShell* aShell,
PRInt32* aWidth,
@ -342,6 +352,10 @@ protected:
nsresult DoClipboardSecurityCheck(PRBool aPaste);
static jsval sCutCopyInternal_id;
static jsval sPasteInternal_id;
// kNameSpaceID_None for good ol' HTML documents, and
// kNameSpaceID_XHTML for spiffy new XHTML documents.
PRInt32 mDefaultNamespaceID;
};
#endif /* nsHTMLDocument_h___ */

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

@ -108,7 +108,6 @@ public:
NS_IMETHOD GetNumFormsSynchronous(PRInt32* aNumForms) = 0;
NS_IMETHOD_(PRBool) IsWriting() = 0;
};
#endif /* nsIHTMLDocument_h___ */

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

@ -1,73 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIXMLDocument_h___
#define nsIXMLDocument_h___
#include "nsISupports.h"
class nsIURI;
#define NS_IXMLDOCUMENT_IID \
{ 0xa6cf90ca, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
#define NS_STYLESHEET_FROM_CATALOG 0x1
/**
* XML document extensions to nsIDocument
*/
class nsIXMLDocument : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXMLDOCUMENT_IID)
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl)=0;
/**
* Set and get XML declaration. Notice that if version is empty,
* there can be no XML declaration (it is a required part).
*/
NS_IMETHOD SetXMLDeclaration(const nsAString& aVersion,
const nsAString& aEncoding,
const nsAString& Standalone)=0;
NS_IMETHOD GetXMLDeclaration(nsAString& aVersion,
nsAString& aEncoding,
nsAString& Standalone)=0;
};
#endif // nsIXMLDocument_h___

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

@ -2011,11 +2011,6 @@ nsXMLContentSink::HandleXMLDeclaration(const PRUnichar *aData,
// strlen("<?xml version='a'?>") == 19, shortest decl
NS_ENSURE_TRUE(aLength >= 19, NS_ERROR_INVALID_ARG);
nsCOMPtr<nsIXMLDocument> xml(do_QueryInterface(mDocument));
NS_WARN_IF_FALSE(xml, "why is XML sink building non-XML document?");
if (!xml)
return NS_OK;
// <?xml version="a" encoding="a" standalone="yes|no"?>
const nsAString& data = Substring(aData + 6, aData + aLength - 2); // strip out "<?xml " and "?>"
@ -2026,7 +2021,7 @@ nsXMLContentSink::HandleXMLDeclaration(const PRUnichar *aData,
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("encoding"), encoding);
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("standalone"), standalone);
return xml->SetXMLDeclaration(version, encoding, standalone);
return mDocument->SetXMLDeclaration(version, encoding, standalone);
}
NS_IMETHODIMP

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

@ -990,35 +990,41 @@ nsXMLDocument::CreateElementNS(const nsAString& aNamespaceURI,
return CreateElement(nodeInfo, aReturn);
}
static nsIContent *
MatchId(nsIContent *aContent, const nsAString& aName)
// Id attribute matching function used by nsXMLDocument and
// nsHTMLDocument.
nsIContent *
MatchElementId(nsIContent *aContent, const nsAString& aId)
{
nsAutoString value;
nsIContent *result = nsnull;
PRInt32 ns;
if (aContent->IsContentOfType(nsIContent::eHTML)) {
if (aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::id)) {
nsAutoString value;
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, value);
aContent->GetNameSpaceID(ns);
if (kNameSpaceID_XHTML == ns) {
if ((NS_CONTENT_ATTR_HAS_VALUE == aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, value)) &&
aName.Equals(value)) {
return aContent;
if (aId.Equals(value)) {
return aContent;
}
}
}
else {
else if (aContent->IsContentOfType(nsIContent::eELEMENT)) {
nsCOMPtr<nsIXMLContent> xmlContent = do_QueryInterface(aContent);
nsCOMPtr<nsIAtom> IDValue;
if (xmlContent && NS_SUCCEEDED(xmlContent->GetID(*getter_AddRefs(IDValue))) && IDValue) {
if (IDValue->Equals(aName))
if (xmlContent) {
nsCOMPtr<nsIAtom> value;
if (NS_SUCCEEDED(xmlContent->GetID(*getter_AddRefs(value))) &&
value && value->Equals(aId)) {
return aContent;
}
}
}
nsIContent *result = nsnull;
PRInt32 i, count;
aContent->ChildCount(count);
for (i = 0; i < count && result == nsnull; i++) {
nsIContent *child;
aContent->ChildAt(i, child);
result = MatchId(child, aName);
result = MatchElementId(child, aId);
NS_RELEASE(child);
}
@ -1027,12 +1033,12 @@ MatchId(nsIContent *aContent, const nsAString& aName)
NS_IMETHODIMP
nsXMLDocument::GetElementById(const nsAString& aElementId,
nsIDOMElement** aReturn)
nsIDOMElement** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
*aReturn = nsnull;
NS_WARN_IF_FALSE(!aElementId.IsEmpty(),"getElementById(\"\"), fix caller?");
NS_WARN_IF_FALSE(!aElementId.IsEmpty(), "getElementById(\"\"), fix caller?");
if (aElementId.IsEmpty())
return NS_OK;
@ -1044,14 +1050,14 @@ nsXMLDocument::GetElementById(const nsAString& aElementId,
// XXX For now, we do a brute force search of the content tree.
// We should come up with a more efficient solution.
nsCOMPtr<nsIContent> content(do_QueryInterface(MatchId(mRootContent,aElementId)));
// Note that content is *not* refcounted here, so do *not* release it!
nsIContent *content = MatchElementId(mRootContent, aElementId);
nsresult rv = NS_OK;
if (content) {
rv = CallQueryInterface(content, aReturn);
if (!content) {
return NS_OK;
}
return rv;
return CallQueryInterface(content, aReturn);
}
// nsIXMLDocument
@ -1073,63 +1079,6 @@ nsXMLDocument::SetDefaultStylesheets(nsIURI* aUrl)
return result;
}
NS_IMETHODIMP
nsXMLDocument::SetXMLDeclaration(const nsAString& aVersion,
const nsAString& aEncoding,
const nsAString& aStandalone)
{
if (aVersion.IsEmpty()) {
mXMLDeclarationBits = 0;
return NS_OK;
}
mXMLDeclarationBits = XML_DECLARATION_BITS_DECLARATION_EXISTS;
if (!aEncoding.IsEmpty()) {
mXMLDeclarationBits |= XML_DECLARATION_BITS_ENCODING_EXISTS;
}
if (aStandalone.Equals(NS_LITERAL_STRING("yes"))) {
mXMLDeclarationBits |= XML_DECLARATION_BITS_STANDALONE_EXISTS |
XML_DECLARATION_BITS_STANDALONE_YES;
} else if (aStandalone.Equals(NS_LITERAL_STRING("no"))) {
mXMLDeclarationBits |= XML_DECLARATION_BITS_STANDALONE_EXISTS;
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocument::GetXMLDeclaration(nsAString& aVersion,
nsAString& aEncoding,
nsAString& aStandalone)
{
aVersion.Truncate();
aEncoding.Truncate();
aStandalone.Truncate();
if (!(mXMLDeclarationBits & XML_DECLARATION_BITS_DECLARATION_EXISTS)) {
return NS_OK;
}
aVersion.Assign(NS_LITERAL_STRING("1.0")); // always until we start supporting 1.1 etc.
if (mXMLDeclarationBits & XML_DECLARATION_BITS_ENCODING_EXISTS) {
GetDocumentCharacterSet(aEncoding); // This is what we have stored, not necessarily what was written in the original
}
if (mXMLDeclarationBits & XML_DECLARATION_BITS_STANDALONE_EXISTS) {
if (mXMLDeclarationBits & XML_DECLARATION_BITS_STANDALONE_YES) {
aStandalone.Assign(NS_LITERAL_STRING("yes"));
} else {
aStandalone.Assign(NS_LITERAL_STRING("no"));
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocument::SetBaseTarget(const nsAString &aBaseTarget)
{

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

@ -56,11 +56,6 @@ class nsIDOMNode;
class nsICSSLoader;
class nsIURI;
#define XML_DECLARATION_BITS_DECLARATION_EXISTS 1
#define XML_DECLARATION_BITS_ENCODING_EXISTS 2
#define XML_DECLARATION_BITS_STANDALONE_EXISTS 4
#define XML_DECLARATION_BITS_STANDALONE_YES 8
class nsXMLDocument : public nsDocument,
public nsIXMLDocument,
public nsIHTMLContentContainer,
@ -116,12 +111,6 @@ public:
// nsIXMLDocument interface
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl);
NS_IMETHOD SetXMLDeclaration(const nsAString& aVersion,
const nsAString& aEncoding,
const nsAString& Standalone);
NS_IMETHOD GetXMLDeclaration(nsAString& aVersion,
nsAString& aEncoding,
nsAString& Standalone);
// nsIHTMLContentContainer
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult);
@ -167,8 +156,6 @@ protected:
PRPackedBool mLoadedAsData;
PRPackedBool mAsync;
PRPackedBool mLoopingForSyncLoad;
PRUint8 mXMLDeclarationBits;
};

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

@ -243,7 +243,7 @@ nsXULPrototypeDocument::Init()
rv = NS_NewISupportsArray(getter_AddRefs(mOverlayReferences));
NS_ENSURE_SUCCESS(rv, rv);
mNodeInfoManager = do_CreateInstance(NS_NODEINFOMANAGER_CONTRACTID, &rv);
rv = NS_NewNodeInfoManager(getter_AddRefs(mNodeInfoManager));
NS_ENSURE_SUCCESS(rv, rv);
rv = mNodeInfoManager->Init(nsnull);

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

@ -49,7 +49,7 @@
#include "ExprParser.h"
#include "nsDOMError.h"
#include "txURIUtils.h"
#include "nsIHTMLDocument.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
extern nsINameSpaceManager* gTxNameSpaceManager;
@ -76,8 +76,8 @@ nsXPathEvaluator::CreateExpression(const nsAString & aExpression,
nsIDOMXPathNSResolver *aResolver,
nsIDOMXPathExpression **aResult)
{
nsCOMPtr<nsIHTMLDocument> html = do_QueryReferent(mDocument);
ParseContextImpl pContext(aResolver, !!html);
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
ParseContextImpl pContext(aResolver, doc->IsCaseSensitive());
Expr* expression = ExprParser::createExpr(PromiseFlatString(aExpression),
&pContext);
if (!expression)
@ -176,7 +176,7 @@ nsresult nsXPathEvaluator::ParseContextImpl::resolveFunctionCall(nsIAtom* aName,
PRBool nsXPathEvaluator::ParseContextImpl::caseInsensitiveNameTests()
{
return mIsHTML;
return !mIsCaseSensitive;
}
void nsXPathEvaluator::ParseContextImpl::receiveError(const nsAString& aMsg,

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

@ -71,8 +71,10 @@ private:
class ParseContextImpl : public txIParseContext
{
public:
ParseContextImpl(nsIDOMXPathNSResolver* aResolver, PRBool aIsHTML)
: mResolver(aResolver), mLastError(NS_OK), mIsHTML(aIsHTML)
ParseContextImpl(nsIDOMXPathNSResolver* aResolver,
PRBool aIsCaseSensitive)
: mResolver(aResolver), mLastError(NS_OK),
mIsCaseSensitive(aIsCaseSensitive)
{
}
@ -94,7 +96,7 @@ private:
private:
nsIDOMXPathNSResolver* mResolver;
nsresult mLastError;
PRBool mIsHTML;
PRBool mIsCaseSensitive;
};
nsWeakPtr mDocument;

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

@ -116,8 +116,8 @@ txMozillaXMLOutput::txMozillaXMLOutput(txOutputFormat* aFormat,
aFragment->GetOwnerDocument(getter_AddRefs(mDocument));
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
mDocumentIsHTML = !!htmlDoc;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
mDocumentIsHTML = doc && !doc->IsCaseSensitive();
mCurrentNode = aFragment;
}
@ -710,8 +710,8 @@ txMozillaXMLOutput::createResultDocument(const nsAString& aName, PRInt32 aNsID,
mDocument = aResultDocument;
doc = do_QueryInterface(aResultDocument);
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(aResultDocument);
mDocumentIsHTML = !!htmlDoc;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aResultDocument);
mDocumentIsHTML = doc && !doc->IsCaseSensitive();
}
mCurrentNode = mDocument;

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

@ -52,7 +52,6 @@
#include "XMLUtils.h"
#include "txUnknownHandler.h"
#include "txXSLTProcessor.h"
#include "nsIHTMLDocument.h"
/**
* Output Handler Factories
@ -180,13 +179,17 @@ txToFragmentHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
{
txOutputFormat format;
format.merge(*aFormat);
nsCOMPtr<nsIDOMDocument> doc;
mFragment->GetOwnerDocument(getter_AddRefs(doc));
NS_ASSERTION(doc, "unable to get ownerdocument");
// Need a way for testing xhtml vs. html. But this is the best
// we can do for now.
nsCOMPtr<nsIHTMLDocument> htmldoc = do_QueryInterface(doc);
format.mMethod = htmldoc ? eHTMLOutput : eXMLOutput;
nsCOMPtr<nsIDOMDocument> domdoc;
mFragment->GetOwnerDocument(getter_AddRefs(domdoc));
NS_ASSERTION(domdoc, "unable to get ownerdocument");
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
if (!doc && doc->IsCaseSensitive()) {
format.mMethod = eXMLOutput;
} else {
format.mMethod = eHTMLOutput;
}
*aHandler = new txMozillaXMLOutput(&format, mFragment);
break;
}

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

@ -96,13 +96,13 @@ static const char* const gHTMLTypes[] = {
"text/javascript",
"application/x-javascript",
"application/x-view-source", //XXX I wish I could just use nsMimeTypes.h here
"application/xhtml+xml",
0
};
static const char* const gXMLTypes[] = {
"text/xml",
"application/xml",
"application/xhtml+xml",
0
};