From 77302e9320998c7bbed6e3480dc641245f9d09c0 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 25 Aug 2006 22:33:17 +0000 Subject: [PATCH] Fix bug 349695 by taking a different approach to setting display:none on HTML forms inside tables; this approach overrides author styles. r+sr=dbaron --- layout/style/html.css | 7 ++++ layout/style/nsCSSPseudoClassList.h | 3 ++ layout/style/nsCSSRuleProcessor.cpp | 4 +++ layout/style/nsHTMLStyleSheet.cpp | 52 ++--------------------------- layout/style/nsHTMLStyleSheet.h | 18 ---------- 5 files changed, 16 insertions(+), 68 deletions(-) diff --git a/layout/style/html.css b/layout/style/html.css index 58f6cc369d6..160f11995f4 100644 --- a/layout/style/html.css +++ b/layout/style/html.css @@ -252,6 +252,13 @@ th { padding: 1px; } +tr > form:-moz-is-html, tbody > form:-moz-is-html, +thead > form:-moz-is-html, tfoot > form:-moz-is-html, +table > form:-moz-is-html { + /* Important: don't show these forms in HTML */ + display: none !important; +} + /* inlines */ q:before { diff --git a/layout/style/nsCSSPseudoClassList.h b/layout/style/nsCSSPseudoClassList.h index a810fc31dec..123e186ad24 100644 --- a/layout/style/nsCSSPseudoClassList.h +++ b/layout/style/nsCSSPseudoClassList.h @@ -88,6 +88,9 @@ CSS_PSEUDO_CLASS(mozTypeUnsupported, ":-moz-type-unsupported") CSS_PSEUDO_CLASS(mozHasHandlerRef, ":-moz-has-handlerref") +// Match nodes that are HTML but not XHTML +CSS_PSEUDO_CLASS(mozIsHTML, ":-moz-is-html") + // CSS 3 UI // http://www.w3.org/TR/2004/CR-css3-ui-20040511/#pseudo-classes CSS_PSEUDO_CLASS(required, ":required") diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index eae62f15f66..b24dfe51341 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -1256,6 +1256,10 @@ static PRBool SelectorMatches(RuleProcessorData &data, else if (nsCSSPseudoClasses::mozReadWrite == pseudoClass->mAtom) { stateToCheck = NS_EVENT_STATE_MOZ_READWRITE; } + else if (nsCSSPseudoClasses::mozIsHTML == pseudoClass->mAtom) { + result = data.mIsHTMLContent && + data.mContent->GetNameSpaceID() == kNameSpaceID_None; + } else { NS_ERROR("CSS parser parsed a pseudo-class that we do not handle"); result = PR_FALSE; // unknown pseudo class diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index 2b4c2c02416..fb31159f31b 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -90,28 +90,7 @@ nsHTMLStyleSheet::HTMLColorRule::List(FILE* out, PRInt32 aIndent) const } #endif - -NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet::TableFormRule, nsIStyleRule) - -NS_IMETHODIMP -nsHTMLStyleSheet::TableFormRule::MapRuleInfoInto(nsRuleData* aRuleData) -{ - if (aRuleData->mSID == eStyleStruct_Display && - aRuleData->mDisplayData->mDisplay.GetUnit() == eCSSUnit_Null) { - nsCSSValue none(NS_STYLE_DISPLAY_NONE, eCSSUnit_Enumerated); - aRuleData->mDisplayData->mDisplay = none; - } - return NS_OK; -} - -#ifdef DEBUG -NS_IMETHODIMP -nsHTMLStyleSheet::TableFormRule::List(FILE* out, PRInt32 aIndent) const -{ - return NS_OK; -} -#endif - + NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet::GenericTableRule, nsIStyleRule) NS_IMETHODIMP @@ -352,8 +331,7 @@ nsHTMLStyleSheet::nsHTMLStyleSheet(void) mLinkRule(nsnull), mVisitedRule(nsnull), mActiveRule(nsnull), - mDocumentColorRule(nsnull), - mTableFormRule(nsnull) + mDocumentColorRule(nsnull) { mMappedAttrTable.ops = nsnull; } @@ -385,11 +363,6 @@ nsHTMLStyleSheet::Init() if (!mTableTHRule) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(mTableTHRule); - - mTableFormRule = new TableFormRule(); - if (!mTableFormRule) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(mTableFormRule); return NS_OK; } @@ -401,7 +374,6 @@ nsHTMLStyleSheet::~nsHTMLStyleSheet() NS_IF_RELEASE(mVisitedRule); NS_IF_RELEASE(mActiveRule); NS_IF_RELEASE(mDocumentColorRule); - NS_IF_RELEASE(mTableFormRule); NS_IF_RELEASE(mTableTbodyRule); NS_IF_RELEASE(mTableRowRule); NS_IF_RELEASE(mTableColgroupRule); @@ -498,25 +470,6 @@ nsHTMLStyleSheet::RulesMatching(ElementRuleProcessorData* aData) ruleWalker->Forward(mDocumentColorRule); } } - else if (tag == nsHTMLAtoms::form) { - // suppress in html documents empty forms inside tables, - // they have been used as a hack - // to avoid the form top and bottom margin - nsIDocument* doc = content->GetOwnerDoc(); - nsIContent* parent = content->GetParent(); - if (!content->GetChildCount() && // form is empty - doc && !doc->IsCaseSensitive() && // document is not XHTML - parent && parent->IsNodeOfType(nsINode::eHTML)) { // parent is HTML - nsIAtom* parentTag = parent->Tag(); - if ((nsHTMLAtoms::table == parentTag) || - (nsHTMLAtoms::tr == parentTag) || - (nsHTMLAtoms::tbody == parentTag) || - (nsHTMLAtoms::thead == parentTag) || - (nsHTMLAtoms::tfoot == parentTag)) { - ruleWalker->Forward(mTableFormRule); - } - } - } } // end html element // just get the style rules from the content @@ -707,7 +660,6 @@ nsHTMLStyleSheet::Reset(nsIURI* aURL) NS_IF_RELEASE(mVisitedRule); NS_IF_RELEASE(mActiveRule); NS_IF_RELEASE(mDocumentColorRule); - NS_IF_RELEASE(mTableFormRule); if (mMappedAttrTable.ops) { PL_DHashTableFinish(&mMappedAttrTable); diff --git a/layout/style/nsHTMLStyleSheet.h b/layout/style/nsHTMLStyleSheet.h index 152d804d490..dff7b3a93ec 100644 --- a/layout/style/nsHTMLStyleSheet.h +++ b/layout/style/nsHTMLStyleSheet.h @@ -125,23 +125,6 @@ private: }; - // this rule supresses forms inside table tags in html - class TableFormRule; - friend class TableFormRule; - class TableFormRule: public nsIStyleRule { - public: - TableFormRule() {} - - NS_DECL_ISUPPORTS - - // nsIStyleRule interface - NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData); - #ifdef DEBUG - NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const; - #endif - }; - - class GenericTableRule; friend class GenericTableRule; class GenericTableRule: public nsIStyleRule { @@ -214,7 +197,6 @@ private: HTMLColorRule* mVisitedRule; HTMLColorRule* mActiveRule; HTMLColorRule* mDocumentColorRule; - TableFormRule* mTableFormRule; TableTbodyRule* mTableTbodyRule; TableRowRule* mTableRowRule; TableColgroupRule* mTableColgroupRule;