Bug 487023. Refactor IsCaseSensitive() into non-virtual inline IsHTML(). r=hsivonen, sr=jst

This commit is contained in:
David Zbarsky 2009-08-25 13:15:55 -04:00
Родитель 2932d72611
Коммит d02ac4482c
13 изменённых файлов: 47 добавлений и 60 удалений

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

@ -217,7 +217,7 @@ public:
{
nsIDocument* doc = GetOwnerDoc();
return doc && // XXX clean up after bug 335998 lands
!doc->IsCaseSensitive();
doc->IsHTML();
}
/**

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

@ -723,9 +723,9 @@ public:
nsAString& aEncoding,
nsAString& Standalone) = 0;
virtual PRBool IsCaseSensitive()
PRBool IsHTML() const
{
return PR_TRUE;
return mIsRegularHTML;
}
virtual PRBool IsScriptEnabled() = 0;
@ -1233,6 +1233,8 @@ protected:
PRPackedBool mShellsAreHidden;
PRPackedBool mIsRegularHTML;
// True if we're loaded as data and therefor has any dangerous stuff, such
// as scripts and plugins, disabled.
PRPackedBool mLoadedAsData;

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

@ -3588,7 +3588,7 @@ nsContentUtils::CreateContextualFragment(nsIDOMNode* aContextNode,
nsCOMPtr<nsIDocument> document = node->GetOwnerDoc();
NS_ENSURE_TRUE(document, NS_ERROR_NOT_AVAILABLE);
PRBool bCaseSensitive = document->IsCaseSensitive();
PRBool bCaseSensitive = !document->IsHTML();
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(document));
PRBool isHTML = htmlDoc && !bCaseSensitive;

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

@ -383,7 +383,7 @@ nsresult nsCopySupport::IsPlainTextContext(nsISelection *aSel, nsIDocument *aDoc
// copy it properly (all the copy code for non-plaintext assumes using HTML
// serializers and parsers is OK, and those mess up XHTML).
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(aDoc);
if (!htmlDoc || aDoc->IsCaseSensitive())
if (!(htmlDoc && aDoc->IsHTML()))
*aIsPlainTextContext = PR_TRUE;
return NS_OK;
@ -541,7 +541,7 @@ static nsresult AppendDOMNode(nsITransferable *aTransferable,
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(domDocument, &rv);
NS_ENSURE_SUCCESS(rv, NS_OK);
NS_ENSURE_TRUE(!(document->IsCaseSensitive()), NS_OK);
NS_ENSURE_TRUE(document->IsHTML(), NS_OK);
// init encoder with document and node
rv = docEncoder->Init(domDocument, NS_LITERAL_STRING(kHTMLMime),

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

@ -4080,7 +4080,7 @@ nsDocument::CreateElement(const nsAString& aTagName,
nsresult rv = nsContentUtils::CheckQName(aTagName, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(IsCaseSensitive(),
NS_ASSERTION(!IsHTML(),
"nsDocument::CreateElement() called on document that is not "
"case sensitive. Fix caller, or fix "
"nsDocument::CreateElement()!");
@ -6367,7 +6367,7 @@ nsDocument::GetRadioGroup(const nsAString& aName,
nsRadioGroupStruct **aRadioGroup)
{
nsAutoString tmKey(aName);
if(!IsCaseSensitive())
if(IsHTML())
ToLowerCase(tmKey); //should case-insensitive.
if (mRadioGroups.Get(tmKey, aRadioGroup))
return NS_OK;

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

@ -1055,6 +1055,7 @@ protected:
nsIContent* GetHeadContent() {
return GetHtmlChildContent(nsGkAtoms::head);
}
// Get the first <title> element with the given IsNodeOfType type, or
// return null if there isn't one
nsIContent* GetTitleContent(PRUint32 aNodeType);
@ -1172,10 +1173,7 @@ protected:
PRPackedBool mVisible:1;
// True if document has ever had script handling object.
PRPackedBool mHasHadScriptHandlingObject:1;
// True if this is a regular (non-XHTML) HTML document
// XXXbz should this be reset if someone manually calls
// SetContentType() on this document?
PRPackedBool mIsRegularHTML:1;
// True if this document has ever had an HTML or SVG <title> element
// bound to it
PRPackedBool mMayHaveTitleElement:1;

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

@ -1185,7 +1185,7 @@ nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection)
// also consider ourselves in a text widget if we can't find an html document
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
if (!htmlDoc || mDocument->IsCaseSensitive())
if (!(htmlDoc && mDocument->IsHTML()))
mIsTextWidget = PR_TRUE;
// normalize selection if we are not in a widget

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

@ -121,9 +121,8 @@ nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
// HTML5 parser stored them in the order they were parsed so we want to
// loop forward in that case.
nsIDocument* doc = aContent->GetOwnerDocument();
PRBool caseSensitive = doc && doc->IsCaseSensitive();
PRBool loopForward = PR_FALSE;
if (!caseSensitive) {
if (!doc || doc->IsHTML()) {
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(doc));
if (htmlDoc) {
loopForward = nsHtml5Module::sEnabled;

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

@ -652,7 +652,7 @@ nsGenericHTMLElement::GetInnerHTML(nsAString& aInnerHTML)
nsDependentCString(NS_DOC_ENCODER_CONTRACTID_BASE) +
NS_ConvertUTF16toUTF8(contentType)
).get());
if (!docEncoder && doc->IsCaseSensitive()) {
if (!(docEncoder || doc->IsHTML())) {
// This could be some type for which we create a synthetic document. Try
// again as XML
contentType.AssignLiteral("application/xml");

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

@ -277,7 +277,7 @@ nsHTMLDocument::Init()
// Now reset the case-sensitivity of the CSSLoader, since we default
// to being HTML, not XHTML. Also, reset the compatibility mode to
// match our compat mode.
CSSLoader()->SetCaseSensitive(IsXHTML());
CSSLoader()->SetCaseSensitive(!IsHTML());
CSSLoader()->SetCompatibilityMode(mCompatMode);
PrePopulateIdentifierMap();
@ -328,11 +328,11 @@ nsHTMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup,
nsStyleSet::sheetType
nsHTMLDocument::GetAttrSheetType()
{
if (IsXHTML()) {
return nsDocument::GetAttrSheetType();
if (IsHTML()) {
return nsStyleSet::eHTMLPresHintSheet;
}
return nsStyleSet::eHTMLPresHintSheet;
return nsDocument::GetAttrSheetType();
}
nsresult
@ -682,7 +682,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
}
#endif
CSSLoader()->SetCaseSensitive(IsXHTML());
CSSLoader()->SetCaseSensitive(!IsHTML());
CSSLoader()->SetCompatibilityMode(mCompatMode);
PRBool needsParser = PR_TRUE;
@ -740,7 +740,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
// No support yet for docshell-less HTML
NS_ENSURE_TRUE(docShell || IsXHTML(), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(docShell || !IsHTML(), NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
@ -800,7 +800,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIWyciwygChannel> wyciwygChannel;
if (IsXHTML()) {
if (!IsHTML()) {
charsetSource = kCharsetFromDocTypeDefault;
charset.AssignLiteral("UTF-8");
TryChannelCharset(aChannel, charsetSource, charset);
@ -944,7 +944,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
NS_ASSERTION(!loadAsHtml5, "Panic: We are loading as HTML5 and someone tries to set an external sink!");
sink = aSink;
} else {
if (IsXHTML()) {
if (!IsHTML()) {
nsCOMPtr<nsIXMLContentSink> xmlsink;
rv = NS_NewXMLContentSink(getter_AddRefs(xmlsink), this, uri,
docShell, aChannel);
@ -1145,7 +1145,7 @@ nsHTMLDocument::GetImageMap(const nsAString& aMapName)
PRBool match;
nsresult rv;
if (IsXHTML()) {
if (!IsHTML()) {
rv = map->GetId(name);
match = name.Equals(aMapName);
@ -1182,7 +1182,7 @@ nsHTMLDocument::GetImageMap(const nsAString& aMapName)
void
nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode)
{
NS_ASSERTION(!IsXHTML() || aMode == eCompatibility_FullStandards,
NS_ASSERTION(IsHTML() || aMode == eCompatibility_FullStandards,
"Bad compat mode for XHTML document!");
mCompatMode = aMode;
@ -1196,12 +1196,6 @@ nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode)
}
}
PRBool
nsHTMLDocument::IsCaseSensitive()
{
return IsXHTML();
}
//
// nsIDOMDocument interface implementation
//
@ -1225,7 +1219,7 @@ nsHTMLDocument::CreateElement(const nsAString& aTagName,
rv = nsContentUtils::CheckQName(tagName, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
if (!IsXHTML()) {
if (IsHTML()) {
ToLowerCase(tagName);
}
@ -1252,7 +1246,7 @@ nsHTMLDocument::CreateProcessingInstruction(const nsAString& aTarget,
const nsAString& aData,
nsIDOMProcessingInstruction** aReturn)
{
if (IsXHTML()) {
if (!IsHTML()) {
return nsDocument::CreateProcessingInstruction(aTarget, aData, aReturn);
}
@ -1266,7 +1260,7 @@ NS_IMETHODIMP
nsHTMLDocument::CreateCDATASection(const nsAString& aData,
nsIDOMCDATASection** aReturn)
{
if (IsXHTML()) {
if (!IsHTML()) {
return nsDocument::CreateCDATASection(aData, aReturn);
}
@ -1280,7 +1274,7 @@ NS_IMETHODIMP
nsHTMLDocument::CreateEntityReference(const nsAString& aName,
nsIDOMEntityReference** aReturn)
{
if (IsXHTML()) {
if (!IsHTML()) {
return nsDocument::CreateEntityReference(aName, aReturn);
}
@ -1337,7 +1331,7 @@ nsHTMLDocument::GetElementsByTagName(const nsAString& aTagname,
nsIDOMNodeList** aReturn)
{
nsAutoString tmp(aTagname);
if (!IsXHTML()) {
if (IsHTML()) {
ToLowerCase(tmp); // HTML elements are lower case internally.
}
return nsDocument::GetElementsByTagName(tmp, aReturn);
@ -1367,7 +1361,7 @@ nsHTMLDocument::GetBaseURI(nsAString &aURI)
NS_IMETHODIMP
nsHTMLDocument::GetXmlEncoding(nsAString& aXmlEncoding)
{
if (IsXHTML()) {
if (!IsHTML()) {
return nsDocument::GetXmlEncoding(aXmlEncoding);
}
@ -1379,7 +1373,7 @@ nsHTMLDocument::GetXmlEncoding(nsAString& aXmlEncoding)
NS_IMETHODIMP
nsHTMLDocument::GetXmlStandalone(PRBool *aXmlStandalone)
{
if (IsXHTML()) {
if (!IsHTML()) {
return nsDocument::GetXmlStandalone(aXmlStandalone);
}
@ -1391,7 +1385,7 @@ nsHTMLDocument::GetXmlStandalone(PRBool *aXmlStandalone)
NS_IMETHODIMP
nsHTMLDocument::SetXmlStandalone(PRBool aXmlStandalone)
{
if (IsXHTML()) {
if (!IsHTML()) {
return nsDocument::SetXmlStandalone(aXmlStandalone);
}
@ -1402,7 +1396,7 @@ nsHTMLDocument::SetXmlStandalone(PRBool aXmlStandalone)
NS_IMETHODIMP
nsHTMLDocument::GetXmlVersion(nsAString& aXmlVersion)
{
if (IsXHTML()) {
if (!IsHTML()) {
return nsDocument::GetXmlVersion(aXmlVersion);
}
@ -1414,7 +1408,7 @@ nsHTMLDocument::GetXmlVersion(nsAString& aXmlVersion)
NS_IMETHODIMP
nsHTMLDocument::SetXmlVersion(const nsAString& aXmlVersion)
{
if (IsXHTML()) {
if (!IsHTML()) {
return nsDocument::SetXmlVersion(aXmlVersion);
}
@ -1565,13 +1559,13 @@ nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
nsCOMPtr<nsIDOMNodeList> nodeList;
nsresult rv;
if (IsXHTML()) {
if (IsHTML()) {
rv = GetElementsByTagName(NS_LITERAL_STRING("frameset"),
getter_AddRefs(nodeList));
} else {
rv = GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"),
NS_LITERAL_STRING("frameset"),
getter_AddRefs(nodeList));
} else {
rv = GetElementsByTagName(NS_LITERAL_STRING("frameset"),
getter_AddRefs(nodeList));
}
NS_ENSURE_SUCCESS(rv, rv);
@ -1799,7 +1793,7 @@ nsHTMLDocument::SetCookie(const nsAString& aCookie)
nsresult
nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace)
{
if (IsXHTML()) {
if (!IsHTML()) {
// No calling document.open() on XHTML
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
@ -2059,7 +2053,7 @@ nsHTMLDocument::Clear()
NS_IMETHODIMP
nsHTMLDocument::Close()
{
if (IsXHTML()) {
if (!IsHTML()) {
// No calling document.close() on XHTML!
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
@ -2124,7 +2118,7 @@ nsHTMLDocument::WriteCommon(const nsAString& aText,
(mWriteLevel > NS_MAX_DOCUMENT_WRITE_DEPTH || mTooDeepWriteRecursion);
NS_ENSURE_STATE(!mTooDeepWriteRecursion);
if (IsXHTML()) {
if (!IsHTML()) {
// No calling document.write*() on XHTML!
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;

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

@ -123,8 +123,6 @@ public:
virtual NS_HIDDEN_(nsContentList*) GetFormControls();
virtual PRBool IsCaseSensitive();
// nsIDOMDocument interface
NS_DECL_NSIDOMDOCUMENT
@ -179,10 +177,6 @@ public:
virtual PRInt32 GetNumFormsSynchronous();
virtual void TearingDownEditor(nsIEditor *aEditor);
virtual void SetIsXHTML(PRBool aXHTML) { mIsRegularHTML = !aXHTML; }
PRBool IsXHTML()
{
return !mIsRegularHTML;
}
nsresult ChangeContentEditableCount(nsIContent *aElement, PRInt32 aChange);

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

@ -224,7 +224,7 @@ nsXPathEvaluator::CreateExpression(const nsAString & aExpression,
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
nsXPathEvaluatorParseContext pContext(*this, aResolver, aNamespaceIDs,
aContractIDs, aState,
!doc || doc->IsCaseSensitive());
!(doc && doc->IsHTML()));
nsAutoPtr<Expr> expression;
rv = txExprParser::createExpr(PromiseFlatString(aExpression), &pContext,

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

@ -193,10 +193,10 @@ txToFragmentHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
NS_ASSERTION(domdoc, "unable to get ownerdocument");
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
if (!doc || doc->IsCaseSensitive()) {
format.mMethod = eXMLOutput;
} else {
if (doc && doc->IsHTML()) {
format.mMethod = eHTMLOutput;
} else {
format.mMethod = eXMLOutput;
}
*aHandler = new txMozillaXMLOutput(&format, mFragment, PR_FALSE);