From 11bf7acee3dfb34ff6f3a564ca8e4b223c4101db Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 1 Jun 2012 00:30:42 -0400 Subject: [PATCH] Bug 748692. Don't reparse inline stylesheets on random attribute changes. r=sicking --- .../html/content/src/nsHTMLLinkElement.cpp | 33 +++++++++++-------- .../html/content/src/nsHTMLStyleElement.cpp | 22 ++++++------- layout/reftests/bugs/748692-1-ref.html | 9 +++++ layout/reftests/bugs/748692-1a.html | 13 ++++++++ layout/reftests/bugs/748692-1b.html | 13 ++++++++ layout/reftests/bugs/reftest.list | 2 ++ 6 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 layout/reftests/bugs/748692-1-ref.html create mode 100644 layout/reftests/bugs/748692-1a.html create mode 100644 layout/reftests/bugs/748692-1b.html diff --git a/content/html/content/src/nsHTMLLinkElement.cpp b/content/html/content/src/nsHTMLLinkElement.cpp index b59d87053f54..6ae52fb16cd8 100644 --- a/content/html/content/src/nsHTMLLinkElement.cpp +++ b/content/html/content/src/nsHTMLLinkElement.cpp @@ -274,20 +274,23 @@ nsHTMLLinkElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, Link::ResetLinkState(!!aNotify); } - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None && + (aName == nsGkAtoms::href || + aName == nsGkAtoms::rel || + aName == nsGkAtoms::title || + aName == nsGkAtoms::media || + aName == nsGkAtoms::type)) { bool dropSheet = false; - if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::rel && - GetStyleSheet()) { + if (aName == nsGkAtoms::rel && GetStyleSheet()) { PRUint32 linkTypes = nsStyleLinkElement::ParseLinkTypes(aValue); dropSheet = !(linkTypes & STYLESHEET); } UpdateStyleSheetInternal(nsnull, dropSheet || - (aNameSpaceID == kNameSpaceID_None && - (aName == nsGkAtoms::title || - aName == nsGkAtoms::media || - aName == nsGkAtoms::type))); + (aName == nsGkAtoms::title || + aName == nsGkAtoms::media || + aName == nsGkAtoms::type)); } return rv; @@ -299,13 +302,15 @@ nsHTMLLinkElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, { nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute, aNotify); - if (NS_SUCCEEDED(rv)) { - UpdateStyleSheetInternal(nsnull, - aNameSpaceID == kNameSpaceID_None && - (aAttribute == nsGkAtoms::rel || - aAttribute == nsGkAtoms::title || - aAttribute == nsGkAtoms::media || - aAttribute == nsGkAtoms::type)); + // Since removing href or rel makes us no longer link to a + // stylesheet, force updates for those too. + if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None && + (aAttribute == nsGkAtoms::href || + aAttribute == nsGkAtoms::rel || + aAttribute == nsGkAtoms::title || + aAttribute == nsGkAtoms::media || + aAttribute == nsGkAtoms::type)) { + UpdateStyleSheetInternal(nsnull, true); } // The ordering of the parent class's UnsetAttr call and Link::ResetLinkState diff --git a/content/html/content/src/nsHTMLStyleElement.cpp b/content/html/content/src/nsHTMLStyleElement.cpp index 95b4f9547430..c6124d67e4bb 100644 --- a/content/html/content/src/nsHTMLStyleElement.cpp +++ b/content/html/content/src/nsHTMLStyleElement.cpp @@ -237,12 +237,11 @@ nsHTMLStyleElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, { nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue, aNotify); - if (NS_SUCCEEDED(rv)) { - UpdateStyleSheetInternal(nsnull, - aNameSpaceID == kNameSpaceID_None && - (aName == nsGkAtoms::title || - aName == nsGkAtoms::media || - aName == nsGkAtoms::type)); + if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None && + (aName == nsGkAtoms::title || + aName == nsGkAtoms::media || + aName == nsGkAtoms::type)) { + UpdateStyleSheetInternal(nsnull, true); } return rv; @@ -254,12 +253,11 @@ nsHTMLStyleElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, { nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute, aNotify); - if (NS_SUCCEEDED(rv)) { - UpdateStyleSheetInternal(nsnull, - aNameSpaceID == kNameSpaceID_None && - (aAttribute == nsGkAtoms::title || - aAttribute == nsGkAtoms::media || - aAttribute == nsGkAtoms::type)); + if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None && + (aAttribute == nsGkAtoms::title || + aAttribute == nsGkAtoms::media || + aAttribute == nsGkAtoms::type)) { + UpdateStyleSheetInternal(nsnull, true); } return rv; diff --git a/layout/reftests/bugs/748692-1-ref.html b/layout/reftests/bugs/748692-1-ref.html new file mode 100644 index 000000000000..2276bf148155 --- /dev/null +++ b/layout/reftests/bugs/748692-1-ref.html @@ -0,0 +1,9 @@ + + + + + + This text should be green + diff --git a/layout/reftests/bugs/748692-1a.html b/layout/reftests/bugs/748692-1a.html new file mode 100644 index 000000000000..9e07d09c23ee --- /dev/null +++ b/layout/reftests/bugs/748692-1a.html @@ -0,0 +1,13 @@ + + + + + + + This text should be green + diff --git a/layout/reftests/bugs/748692-1b.html b/layout/reftests/bugs/748692-1b.html new file mode 100644 index 000000000000..6e017694bc83 --- /dev/null +++ b/layout/reftests/bugs/748692-1b.html @@ -0,0 +1,13 @@ + + + + + + + This text should be green + diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index 04aa277ea6bb..2e1258d0cea9 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -1704,3 +1704,5 @@ needs-focus == 731726-1.html 731726-1-ref.html == 751012-1a.html 751012-1-ref.html == 751012-1b.html 751012-1-ref.html == 690643-1.html 690643-1-ref.html +== 748692-1a.html 748692-1-ref.html +== 748692-1b.html 748692-1-ref.html