Bug 1013936, part 1 - Add various methods to nsIDocument to help determine its type. r=bz

This commit is contained in:
Jonathan Watt 2014-05-24 20:28:48 +01:00
parent b6253e4965
commit 5dcf597768
7 changed files with 46 additions and 20 deletions

View File

@ -1221,15 +1221,23 @@ public:
*/
bool IsHTML() const
{
return mIsRegularHTML;
return mType == eHTML;
}
bool IsHTMLOrXHTML() const
{
return mType == eHTML || mType == eXHTML;
}
bool IsXML() const
{
return !IsHTML();
}
bool IsSVG() const
{
return mType == eSVG;
}
bool IsXUL() const
{
return mIsXUL;
return mType == eXUL;
}
bool IsUnstyledDocument()
{
@ -2402,15 +2410,6 @@ protected:
// document in it.
bool mIsInitialDocumentInWindow;
bool mIsRegularHTML;
bool mIsXUL;
enum {
eTriUnset = 0,
eTriFalse,
eTriTrue
} mAllowXULXBL;
// True if we're loaded as data and therefor has any dangerous stuff, such
// as scripts and plugins, disabled.
bool mLoadedAsData;
@ -2514,6 +2513,27 @@ protected:
bool mIsLinkUpdateRegistrationsForbidden;
#endif
enum Type {
eUnknown, // should never be used
eHTML,
eXHTML,
eGenericXML,
eSVG,
eXUL
};
uint8_t mType;
uint8_t mDefaultElementType;
enum {
eTriUnset = 0,
eTriFalse,
eTriTrue
};
uint8_t mAllowXULXBL;
// The document's script global object, the object from which the
// document can get its script context and scope. This is the
// *inner* window object.
@ -2596,8 +2616,6 @@ protected:
nsCOMPtr<nsIStructuredCloneContainer> mStateObjectContainer;
nsCOMPtr<nsIVariant> mStateObjectCached;
uint8_t mDefaultElementType;
uint32_t mInSyncOperationCount;
nsRefPtr<mozilla::dom::XPathEvaluator> mXPathEvaluator;

View File

@ -9114,7 +9114,7 @@ nsDocument::CloneDocHelper(nsDocument* clone) const
clone->mSecurityInfo = mSecurityInfo;
// State from nsDocument
clone->mIsRegularHTML = mIsRegularHTML;
clone->mType = mType;
clone->mXMLDeclarationBits = mXMLDeclarationBits;
clone->mBaseTarget = mBaseTarget;
return NS_OK;

View File

@ -190,7 +190,7 @@ nsHTMLDocument::nsHTMLDocument()
// NOTE! nsDocument::operator new() zeroes out all members, so don't
// bother initializing members to 0.
mIsRegularHTML = true;
mType = eHTML;
mDefaultElementType = kNameSpaceID_XHTML;
mCompatMode = eCompatibility_NavQuirks;
}
@ -535,7 +535,8 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
MOZ_ASSERT(false, "Got a sink override. Should not happen for HTML doc.");
return NS_ERROR_INVALID_ARG;
}
if (!mIsRegularHTML) {
if (mType != eHTML) {
MOZ_ASSERT(mType == eXHTML);
MOZ_ASSERT(false, "Must not set HTML doc to XHTML mode before load start.");
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
@ -565,7 +566,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
if (!viewSource && xhtml) {
// We're parsing XHTML as XML, remember that.
mIsRegularHTML = false;
mType = eXHTML;
mCompatMode = eCompatibility_FullStandards;
loadAsHtml5 = false;
}
@ -3575,7 +3576,8 @@ nsHTMLDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const
bool
nsHTMLDocument::WillIgnoreCharsetOverride()
{
if (!mIsRegularHTML) {
if (mType != eHTML) {
MOZ_ASSERT(mType == eXHTML);
return true;
}
if (mCharacterSetSource == kCharsetFromByteOrderMark) {

View File

@ -111,7 +111,10 @@ public:
virtual void RemovedForm() MOZ_OVERRIDE;
virtual int32_t GetNumFormsSynchronous() MOZ_OVERRIDE;
virtual void TearingDownEditor(nsIEditor *aEditor) MOZ_OVERRIDE;
virtual void SetIsXHTML(bool aXHTML) MOZ_OVERRIDE { mIsRegularHTML = !aXHTML; }
virtual void SetIsXHTML(bool aXHTML) MOZ_OVERRIDE
{
mType = (aXHTML ? eXHTML : eHTML);
}
virtual void SetDocWriteDisabled(bool aDisabled) MOZ_OVERRIDE
{
mDisableDocWrite = aDisabled;

View File

@ -20,6 +20,7 @@ public:
SVGDocument()
: XMLDocument("image/svg+xml")
{
mType = eSVG;
}
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;

View File

@ -219,6 +219,8 @@ XMLDocument::XMLDocument(const char* aContentType)
{
// NOTE! nsDocument::operator new() zeroes out all members, so don't
// bother initializing members to 0.
mType = eGenericXML;
}
XMLDocument::~XMLDocument()

View File

@ -202,7 +202,7 @@ XULDocument::XULDocument(void)
mCharacterSet.AssignLiteral("UTF-8");
mDefaultElementType = kNameSpaceID_XUL;
mIsXUL = true;
mType = eXUL;
mDelayFrameLoaderInitialization = true;