From 9d34cfcfa01733eb0677a5e5802a1c96bfa3b7dc Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Wed, 7 Sep 2005 03:35:58 +0000 Subject: [PATCH] bug 307122: Restore compatibility for where we open userdefined elements when neither a head nor a body has been explicitly opened. r=jst sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@179781 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/parser/htmlparser/src/CNavDTD.cpp | 24 +++++++++++-------- .../parser/htmlparser/src/nsElementTable.cpp | 2 +- .../parser/htmlparser/src/nsElementTable.h | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp index af7071d850b..319769965e1 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.cpp +++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp @@ -1358,10 +1358,6 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsIParserNode START_TIMER() if(NS_SUCCEEDED(result)) { - if(NS_OK==result) { - result=gHTMLElements[aTag].HasSpecialProperty(kDiscardTag) ? 1 : NS_OK; - } - // This code is here to make sure the head is closed before we deal // with any tags that don't belong in the head. If the tag is not exclusive // then we do not have enough information, and we have to trust the logic @@ -1651,13 +1647,21 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) { }//switch if(!isTokenHandled) { - if(theHeadIsParent && - (isExclusive || !(mFlags & NS_DTD_FLAG_HAD_BODY))) { + PRBool prefersBody = + gHTMLElements[theChildTag].HasSpecialProperty(kPreferBody); + + // If this tag prefers to be in the head (when neither the head nor the + // body have been explicitly opened) then check that we haven't seen the + // body (true until the tag has really been seen). Otherwise, + // check if the head has been explicitly opened. See bug 307122. + theHeadIsParent = theHeadIsParent && + (isExclusive || + (prefersBody + ? (mFlags & NS_DTD_FLAG_HAS_OPEN_HEAD) + : !(mFlags & NS_DTD_FLAG_HAD_BODY))); + + if(theHeadIsParent) { // These tokens prefer to be in the head. - // Note: I changed the above test to be against NS_DTD_FLAG_HAD_BODY - // instead of NS_DTD_FLAG_HAS_OPEN_HEAD because if neither the body - // nor the head have been opened, we should assume the tag wants to - // be in the head. result = AddHeadLeaf(theNode); } else { diff --git a/mozilla/parser/htmlparser/src/nsElementTable.cpp b/mozilla/parser/htmlparser/src/nsElementTable.cpp index ed33b4279c4..f99a93a33fd 100644 --- a/mozilla/parser/htmlparser/src/nsElementTable.cpp +++ b/mozilla/parser/htmlparser/src/nsElementTable.cpp @@ -1392,7 +1392,7 @@ const nsHTMLElement gHTMLElements[] = { /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ &gBodyAutoClose,0,0,0, /*parent,incl,exclgroups*/ (kFlowEntity|kHeadMisc), (kInlineEntity|kSelf), kNone, // Treat userdefined as inline element - Ref bug 56245,66772 - /*special props, prop-range*/ kNone, kBodyPropRange, + /*special props, prop-range*/ kPreferBody, kBodyPropRange, /*special parents,kids,skip*/ &gInNoframes,&gBodyKids,eHTMLTag_unknown, /*contain-func*/ 0 } diff --git a/mozilla/parser/htmlparser/src/nsElementTable.h b/mozilla/parser/htmlparser/src/nsElementTable.h index c51c966752a..5afc9d5dcb1 100644 --- a/mozilla/parser/htmlparser/src/nsElementTable.h +++ b/mozilla/parser/htmlparser/src/nsElementTable.h @@ -257,7 +257,7 @@ struct nsHTMLElement { extern const nsHTMLElement gHTMLElements[]; //special property bits... -static const int kDiscardTag = 0x0001; //tells us to toss this tag +static const int kPreferBody = 0x0001; //this kHeadMisc tag prefers to be in the body if there isn't an explicit static const int kOmitEndTag = 0x0002; //safely ignore end tag static const int kLegalOpen = 0x0004; //Lets BODY, TITLE, SCRIPT to reopen static const int kNoPropagate = 0x0008; //If set, this tag won't propagate as a child