Bug 589615 part 1. Get rid of the non-HTML preshint level. r=dbaron
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 14 Jan 2011 21:14:41 -0500
changeset 60633 1133df9783f4c77fef6d2c227263443515775129
parent 60632 09941c7a591f2bf761d9d0e17101a645723d5db4
child 60634 65dfc25b1cae0d8b43556bdb20c17ea9927e57ef
push idunknown
push userunknown
push dateunknown
reviewersdbaron
bugs589615
milestone2.0b10pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 589615 part 1. Get rid of the non-HTML preshint level. r=dbaron
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
content/html/document/src/nsHTMLDocument.cpp
content/html/document/src/nsHTMLDocument.h
layout/reftests/bugs/589615-1-ref.html
layout/reftests/bugs/589615-1a.xhtml
layout/reftests/bugs/589615-1b.html
layout/reftests/bugs/reftest.list
layout/style/nsStyleSet.cpp
layout/style/nsStyleSet.h
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -2215,22 +2215,22 @@ nsDocument::ResetStylesheetsToURI(nsIURI
   // Release all the sheets
   mStyleSheets.Clear();
   // NOTE:  We don't release the catalog sheets.  It doesn't really matter
   // now, but it could in the future -- in which case not releasing them
   // is probably the right thing to do.
 
   // Now reset our inline style and attribute sheets.
   nsresult rv = NS_OK;
-  nsStyleSet::sheetType attrSheetType = GetAttrSheetType();
   if (mAttrStyleSheet) {
     // Remove this sheet from all style sets
     nsCOMPtr<nsIPresShell> shell = GetShell();
     if (shell) {
-      shell->StyleSet()->RemoveStyleSheet(attrSheetType, mAttrStyleSheet);
+      shell->StyleSet()->RemoveStyleSheet(nsStyleSet::eHTMLPresHintSheet,
+                                          mAttrStyleSheet);
     }
     mAttrStyleSheet->Reset(aURI);
   } else {
     rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aURI, this);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Don't use AddStyleSheet, since it'll put the sheet into style
@@ -2260,38 +2260,30 @@ nsDocument::ResetStylesheetsToURI(nsIURI
   nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     FillStyleSet(shell->StyleSet());
   }
 
   return rv;
 }
 
-nsStyleSet::sheetType
-nsDocument::GetAttrSheetType()
-{
-  return nsStyleSet::ePresHintSheet;
-}
-
 void
 nsDocument::FillStyleSet(nsStyleSet* aStyleSet)
 {
   NS_PRECONDITION(aStyleSet, "Must have a style set");
-  NS_PRECONDITION(aStyleSet->SheetCount(nsStyleSet::ePresHintSheet) == 0,
-                  "Style set already has a preshint sheet?");
   NS_PRECONDITION(aStyleSet->SheetCount(nsStyleSet::eHTMLPresHintSheet) == 0,
                   "Style set already has a HTML preshint sheet?");
   NS_PRECONDITION(aStyleSet->SheetCount(nsStyleSet::eDocSheet) == 0,
                   "Style set already has document sheets?");
   NS_PRECONDITION(aStyleSet->SheetCount(nsStyleSet::eStyleAttrSheet) == 0,
                   "Style set already has style attr sheets?");
   NS_PRECONDITION(mStyleAttrStyleSheet, "No style attr stylesheet?");
   NS_PRECONDITION(mAttrStyleSheet, "No attr stylesheet?");
   
-  aStyleSet->AppendStyleSheet(GetAttrSheetType(), mAttrStyleSheet);
+  aStyleSet->AppendStyleSheet(nsStyleSet::eHTMLPresHintSheet, mAttrStyleSheet);
 
   aStyleSet->AppendStyleSheet(nsStyleSet::eStyleAttrSheet,
                               mStyleAttrStyleSheet);
 
   PRInt32 i;
   for (i = mStyleSheets.Count() - 1; i >= 0; --i) {
     nsIStyleSheet* sheet = mStyleSheets[i];
     if (sheet->IsApplicable()) {
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -1030,17 +1030,16 @@ protected:
   void GetTitleFromElement(PRUint32 aNodeType, nsAString& aTitle);
 
   nsresult doCreateShell(nsPresContext* aContext,
                          nsIViewManager* aViewManager, nsStyleSet* aStyleSet,
                          nsCompatibility aCompatMode,
                          nsIPresShell** aInstancePtrResult);
 
   nsresult ResetStylesheetsToURI(nsIURI* aURI);
-  virtual nsStyleSet::sheetType GetAttrSheetType();
   void FillStyleSet(nsStyleSet* aStyleSet);
 
   // Return whether all the presshells for this document are safe to flush
   PRBool IsSafeToFlush() const;
   
   virtual PRInt32 GetDefaultNamespaceID() const
   {
     return kNameSpaceID_None;
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -373,26 +373,16 @@ nsHTMLDocument::ResetToURI(nsIURI *aURI,
   mWyciwygChannel = nsnull;
 
   // Make the content type default to "text/html", we are a HTML
   // document, after all. Once we start getting data, this may be
   // changed.
   SetContentTypeInternal(nsDependentCString("text/html"));
 }
 
-nsStyleSet::sheetType
-nsHTMLDocument::GetAttrSheetType()
-{
-  if (IsHTML()) {
-    return nsStyleSet::eHTMLPresHintSheet;
-  }
-
-  return nsDocument::GetAttrSheetType();
-}
-
 nsresult
 nsHTMLDocument::CreateShell(nsPresContext* aContext,
                             nsIViewManager* aViewManager,
                             nsStyleSet* aStyleSet,
                             nsIPresShell** aInstancePtrResult)
 {
   return doCreateShell(aContext, aViewManager, aStyleSet, mCompatMode,
                        aInstancePtrResult);
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -80,17 +80,16 @@ public:
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
 
   NS_IMETHOD_(nsrefcnt) AddRef(void);
   NS_IMETHOD_(nsrefcnt) Release(void);
 
   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
   virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
                           nsIPrincipal* aPrincipal);
-  virtual nsStyleSet::sheetType GetAttrSheetType();
 
   virtual nsresult CreateShell(nsPresContext* aContext,
                                nsIViewManager* aViewManager,
                                nsStyleSet* aStyleSet,
                                nsIPresShell** aInstancePtrResult);
 
   virtual nsresult StartDocumentLoad(const char* aCommand,
                                      nsIChannel* aChannel,
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/589615-1-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <style>
+      * { color: pink ! important }
+    </style>
+  </head>
+  <body>
+    <a href="">This should be pink</a>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/589615-1a.xhtml
@@ -0,0 +1,5 @@
+<html xmlns='http://www.w3.org/1999/xhtml'>
+  <body link="pink" vlink="pink">
+    <a href="">This should be pink</a>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/589615-1b.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body link="pink" vlink="pink">
+    <a href="">This should be pink</a>
+  </body>
+</html>
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -1518,16 +1518,18 @@ random-if(layersGPUAccelerated) fails-if
 == 582037-2a.html 582037-2-ref.html
 == 582037-2b.html 582037-2-ref.html
 asserts(0-1) == 582146-1.html about:blank
 == 582476-1.svg 582476-1-ref.svg
 == 584400-dash-length.svg 584400-dash-length-ref.svg
 == 584699-1.html 584699-1-ref.html
 == 585598-2.xhtml 585598-2-ref.xhtml
 == 586400-1.html 586400-1-ref.html
+== 589615-1a.xhtml 589615-1-ref.html
+== 589615-1b.html 589615-1-ref.html
 == 589672-1.html 589672-1-ref.html
 == 593544-1.html 593544-1-ref.html
 == 594333-1.html 594333-1-ref.html
 == 594624-1.html 594624-1-ref.html
 == 594737-1.html 594737-1-ref.html
 == 597721-1.html 597721-1-ref.html
 == 599113-1.html 599113-1-ref.html
 fails-if(!haveTestPlugin) == 599476.html 599476-ref.html
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -186,17 +186,16 @@ nsStyleSet::SetQuirkStyleSheet(nsIStyleS
   mQuirkStyleSheet = aQuirkStyleSheet;
 }
 
 nsresult
 nsStyleSet::GatherRuleProcessors(sheetType aType)
 {
   mRuleProcessors[aType] = nsnull;
   if (mAuthorStyleDisabled && (aType == eDocSheet || 
-                               aType == ePresHintSheet ||
                                aType == eHTMLPresHintSheet ||
                                aType == eStyleAttrSheet)) {
     //don't regather if this level is disabled
     return NS_OK;
   }
   if (aType == eTransitionSheet) {
     // We have no sheet for the transitions level; just a rule
     // processor.  (XXX: We should probably do this for the other
@@ -304,17 +303,16 @@ nsStyleSet::GetAuthorStyleDisabled()
 
 nsresult
 nsStyleSet::SetAuthorStyleDisabled(PRBool aStyleDisabled)
 {
   if (aStyleDisabled == !mAuthorStyleDisabled) {
     mAuthorStyleDisabled = aStyleDisabled;
     BeginUpdate();
     mDirty |= 1 << eDocSheet |
-              1 << ePresHintSheet |
               1 << eHTMLPresHintSheet |
               1 << eStyleAttrSheet;
     return EndUpdate();
   }
   return NS_OK;
 }
 
 // -------- Doc Sheets
@@ -576,42 +574,32 @@ nsStyleSet::AssertNoCSSRules(nsRuleNode*
 void
 nsStyleSet::FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc, 
                       void* aData, nsIContent* aContent,
                       nsRuleWalker* aRuleWalker)
 {
   // Cascading order:
   // [least important]
   //  1. UA normal rules                    = Agent        normal
-  //  2. Presentation hints                 = PresHint     normal
-  //  3. User normal rules                  = User         normal
-  //  4. HTML Presentation hints            = HTMLPresHint normal
-  //  5. Author normal rules                = Document     normal
-  //  6. Override normal rules              = Override     normal
-  //  7. Author !important rules            = Document     !important
-  //  8. Override !important rules          = Override     !important
-  //  9. User !important rules              = User         !important
-  // 10. UA !important rules                = Agent        !important
+  //  2. User normal rules                  = User         normal
+  //  3. HTML Presentation hints            = HTMLPresHint normal
+  //  4. Author normal rules                = Document     normal
+  //  5. Override normal rules              = Override     normal
+  //  6. Author !important rules            = Document     !important
+  //  7. Override !important rules          = Override     !important
+  //  8. User !important rules              = User         !important
+  //  9. UA !important rules                = Agent        !important
   // [most important]
 
-  NS_PRECONDITION(SheetCount(ePresHintSheet) == 0 ||
-                  SheetCount(eHTMLPresHintSheet) == 0,
-                  "Can't have both types of preshint sheets at once!");
-  
   aRuleWalker->SetLevel(eAgentSheet, PR_FALSE, PR_TRUE);
   if (mRuleProcessors[eAgentSheet])
     (*aCollectorFunc)(mRuleProcessors[eAgentSheet], aData);
   nsRuleNode* lastAgentRN = aRuleWalker->CurrentNode();
   PRBool haveImportantUARules = !aRuleWalker->GetCheckForImportantRules();
 
-  aRuleWalker->SetLevel(ePresHintSheet, PR_FALSE, PR_FALSE);
-  if (mRuleProcessors[ePresHintSheet])
-    (*aCollectorFunc)(mRuleProcessors[ePresHintSheet], aData);
-  nsRuleNode* lastPresHintRN = aRuleWalker->CurrentNode();
-
   aRuleWalker->SetLevel(eUserSheet, PR_FALSE, PR_TRUE);
   PRBool skipUserStyles =
     aContent && aContent->IsInNativeAnonymousSubtree();
   if (!skipUserStyles && mRuleProcessors[eUserSheet]) // NOTE: different
     (*aCollectorFunc)(mRuleProcessors[eUserSheet], aData);
   nsRuleNode* lastUserRN = aRuleWalker->CurrentNode();
   PRBool haveImportantUserRules = !aRuleWalker->GetCheckForImportantRules();
 
@@ -666,29 +654,24 @@ nsStyleSet::FileRules(nsIStyleRuleProces
 
 #ifdef DEBUG
   AssertNoCSSRules(lastHTMLPresHintRN, lastUserRN);
   AssertNoImportantRules(lastHTMLPresHintRN, lastUserRN); // HTML preshints
 #endif
 
   if (haveImportantUserRules) {
     aRuleWalker->SetLevel(eUserSheet, PR_TRUE, PR_FALSE);
-    AddImportantRules(lastUserRN, lastPresHintRN, aRuleWalker); //user
+    AddImportantRules(lastUserRN, lastAgentRN, aRuleWalker); //user
   }
 #ifdef DEBUG
   else {
-    AssertNoImportantRules(lastUserRN, lastPresHintRN);
+    AssertNoImportantRules(lastUserRN, lastAgentRN);
   }
 #endif
 
-#ifdef DEBUG
-  AssertNoCSSRules(lastPresHintRN, lastAgentRN);
-  AssertNoImportantRules(lastPresHintRN, lastAgentRN); // preshints
-#endif
-
   if (haveImportantUARules) {
     aRuleWalker->SetLevel(eAgentSheet, PR_TRUE, PR_FALSE);
     AddImportantRules(lastAgentRN, mRuleTree, aRuleWalker);     //agent
   }
 #ifdef DEBUG
   else {
     AssertNoImportantRules(lastAgentRN, mRuleTree);
   }
@@ -708,24 +691,18 @@ nsStyleSet::FileRules(nsIStyleRuleProces
 
 // Enumerate all the rules in a way that doesn't care about the order
 // of the rules and doesn't walk !important-rules.
 void
 nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc,
                                RuleProcessorData* aData,
                                PRBool aWalkAllXBLStylesheets)
 {
-  NS_PRECONDITION(SheetCount(ePresHintSheet) == 0 ||
-                  SheetCount(eHTMLPresHintSheet) == 0,
-                  "Can't have both types of preshint sheets at once!");
-  
   if (mRuleProcessors[eAgentSheet])
     (*aFunc)(mRuleProcessors[eAgentSheet], aData);
-  if (mRuleProcessors[ePresHintSheet])
-    (*aFunc)(mRuleProcessors[ePresHintSheet], aData);
 
   PRBool skipUserStyles = aData->mElement->IsInNativeAnonymousSubtree();
   if (!skipUserStyles && mRuleProcessors[eUserSheet]) // NOTE: different
     (*aFunc)(mRuleProcessors[eUserSheet], aData);
 
   if (mRuleProcessors[eHTMLPresHintSheet])
     (*aFunc)(mRuleProcessors[eHTMLPresHintSheet], aData);
   
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -212,17 +212,16 @@ class nsStyleSet
   {
     mBindingManager = aBindingManager;
   }
 
   // The "origins" of the CSS cascade, from lowest precedence to
   // highest (for non-!important rules).
   enum sheetType {
     eAgentSheet, // CSS
-    ePresHintSheet,
     eUserSheet, // CSS
     eHTMLPresHintSheet,
     eDocSheet, // CSS
     eStyleAttrSheet,
     eOverrideSheet, // CSS
     eTransitionSheet,
     eSheetTypeCount
     // be sure to keep the number of bits in |mDirty| below and in
@@ -233,17 +232,17 @@ class nsStyleSet
   // APIs to manipulate the style sheet lists.  The sheets in each
   // list are stored with the most significant sheet last.
   nsresult AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
   nsresult PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
   nsresult RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
   nsresult ReplaceSheets(sheetType aType,
                          const nsCOMArray<nsIStyleSheet> &aNewSheets);
 
-  //Enable/Disable entire author style level (Doc & PresHint levels)
+  // Enable/Disable entire author style level (Doc & PresHint levels)
   PRBool GetAuthorStyleDisabled();
   nsresult SetAuthorStyleDisabled(PRBool aStyleDisabled);
 
   PRInt32 SheetCount(sheetType aType) const {
     return mSheets[aType].Count();
   }
 
   nsIStyleSheet* StyleSheetAt(sheetType aType, PRInt32 aIndex) const {
@@ -317,17 +316,17 @@ class nsStyleSet
   // Just like AddImportantRules except it doesn't actually add anything; it
   // just asserts that there are no important rules between aCurrLevelNode and
   // aLastPrevLevelNode.
   void AssertNoImportantRules(nsRuleNode* aCurrLevelNode,
                               nsRuleNode* aLastPrevLevelNode);
   
   // Just like AddImportantRules except it doesn't actually add anything; it
   // just asserts that there are no CSS rules between aCurrLevelNode and
-  // aLastPrevLevelNode.  Mostly useful for the preshint levels.
+  // aLastPrevLevelNode.  Mostly useful for the preshint level.
   void AssertNoCSSRules(nsRuleNode* aCurrLevelNode,
                         nsRuleNode* aLastPrevLevelNode);
 #endif
   
   // Enumerate the rules in a way that cares about the order of the
   // rules.
   // aContent is the node the rules are for.  It might be null.  aData
   // is the closure to pass to aCollectorFunc.  If aContent is not null,