Bug 1460295 - Don't dispatch mutation event for style attribute change from CSSOM. r=bz

MozReview-Commit-ID: JWDpyg7czXI

--HG--
extra : rebase_source : 1bf116ff3c016da126dae7ba89282cf31f16660a
This commit is contained in:
Xidorn Quan 2018-05-22 16:34:23 +10:00
parent 518362d207
commit 2b53237243
4 changed files with 22 additions and 3 deletions

View File

@ -12,6 +12,7 @@
#include "mozilla/dom/ElementInlines.h"
#include "mozilla/dom/MutationEventBinding.h"
#include "mozilla/InternalMutationEvent.h"
#include "mozilla/StaticPrefs.h"
#include "nsDOMCSSDeclaration.h"
#include "nsDOMCSSAttrDeclaration.h"
#include "nsServiceManagerUtils.h"
@ -77,6 +78,7 @@ nsStyledElement::SetInlineStyleDeclaration(DeclarationBlock* aDeclaration,
bool oldValueSet = false;
bool hasListeners = aNotify &&
!StaticPrefs::dom_mutation_events_cssom_disabled() &&
nsContentUtils::HasMutationListeners(this,
NS_EVENT_BITS_MUTATION_ATTRMODIFIED,
this);

View File

@ -35,9 +35,13 @@ function nextTest() {
}
}
SimpleTest.waitForExplicitFinish();
testDiv.addEventListener("DOMAttrModified", attr_modified);
nextTest();
if (SpecialPowers.getBoolPref("dom.mutation-events.cssom.disabled")) {
ok(true, "DOMAttrModified event from CSSOM change is disabled");
} else {
SimpleTest.waitForExplicitFinish();
testDiv.addEventListener("DOMAttrModified", attr_modified);
nextTest();
}
/* event handler */
function attr_modified(ev) {

View File

@ -21,6 +21,11 @@ expectation = { prevValue: 'color: red;', newValue: 'color: green;' };
div.style.color = "green";
expectation = { prevValue: 'color: green;', newValue: '' };
div.style.color = '';
if (SpecialPowers.getBoolPref("dom.mutation-events.cssom.disabled")) {
is(count, 0, "No DOMAttrModified event should be triggered");
} else {
is(count, 2, "DOMAttrModified events should have been triggered");
}
</script>
</body>
</html>

View File

@ -97,6 +97,14 @@ VARCACHE_PREF(
bool, false
)
// Whether we disable triggering mutation events for changes to style
// attribute via CSSOM.
VARCACHE_PREF(
"dom.mutation-events.cssom.disabled",
dom_mutation_events_cssom_disabled,
bool, true
)
//---------------------------------------------------------------------------
// Full-screen prefs
//---------------------------------------------------------------------------