forked from mirrors/gecko-dev
Bug 1842549 - Remove dom.mutation-events.cssom.disabled pref r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D212588
This commit is contained in:
parent
49e71b90c7
commit
e6b70d8c47
6 changed files with 23 additions and 161 deletions
|
|
@ -15,7 +15,6 @@
|
||||||
#include "mozilla/dom/MutationEventBinding.h"
|
#include "mozilla/dom/MutationEventBinding.h"
|
||||||
#include "mozilla/dom/MutationObservers.h"
|
#include "mozilla/dom/MutationObservers.h"
|
||||||
#include "mozilla/InternalMutationEvent.h"
|
#include "mozilla/InternalMutationEvent.h"
|
||||||
#include "mozilla/StaticPrefs_dom.h"
|
|
||||||
#include "nsDOMCSSDeclaration.h"
|
#include "nsDOMCSSDeclaration.h"
|
||||||
#include "nsDOMCSSAttrDeclaration.h"
|
#include "nsDOMCSSAttrDeclaration.h"
|
||||||
#include "nsServiceManagerUtils.h"
|
#include "nsServiceManagerUtils.h"
|
||||||
|
|
@ -69,19 +68,8 @@ void nsStyledElement::InlineStyleDeclarationWillChange(
|
||||||
"Should be inside document update!");
|
"Should be inside document update!");
|
||||||
bool modification = false;
|
bool modification = false;
|
||||||
if (MayHaveStyle()) {
|
if (MayHaveStyle()) {
|
||||||
bool needsOldValue = !StaticPrefs::dom_mutation_events_cssom_disabled() &&
|
CustomElementDefinition* definition = GetCustomElementDefinition();
|
||||||
nsContentUtils::HasMutationListeners(
|
if (definition && definition->IsInObservedAttributeList(nsGkAtoms::style)) {
|
||||||
this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED, this);
|
|
||||||
|
|
||||||
if (!needsOldValue) {
|
|
||||||
CustomElementDefinition* definition = GetCustomElementDefinition();
|
|
||||||
if (definition &&
|
|
||||||
definition->IsInObservedAttributeList(nsGkAtoms::style)) {
|
|
||||||
needsOldValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needsOldValue) {
|
|
||||||
nsAutoString oldValueStr;
|
nsAutoString oldValueStr;
|
||||||
modification = GetAttr(nsGkAtoms::style, oldValueStr);
|
modification = GetAttr(nsGkAtoms::style, oldValueStr);
|
||||||
if (modification) {
|
if (modification) {
|
||||||
|
|
@ -110,9 +98,8 @@ nsresult nsStyledElement::SetInlineStyleDeclaration(
|
||||||
MOZ_ASSERT(OwnerDoc()->UpdateNestingLevel(),
|
MOZ_ASSERT(OwnerDoc()->UpdateNestingLevel(),
|
||||||
"Should be inside document update!");
|
"Should be inside document update!");
|
||||||
|
|
||||||
bool hasListeners = !StaticPrefs::dom_mutation_events_cssom_disabled() &&
|
// Avoid dispatching mutation events for style attribute changes from CSSOM
|
||||||
nsContentUtils::HasMutationListeners(
|
const bool hasMutationEventListeners = false;
|
||||||
this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED, this);
|
|
||||||
|
|
||||||
nsAttrValue attrValue(do_AddRef(&aDeclaration), nullptr);
|
nsAttrValue attrValue(do_AddRef(&aDeclaration), nullptr);
|
||||||
SetMayHaveStyle();
|
SetMayHaveStyle();
|
||||||
|
|
@ -121,7 +108,7 @@ nsresult nsStyledElement::SetInlineStyleDeclaration(
|
||||||
mozAutoDocUpdate updateBatch(document, true);
|
mozAutoDocUpdate updateBatch(document, true);
|
||||||
return SetAttrAndNotify(kNameSpaceID_None, nsGkAtoms::style, nullptr,
|
return SetAttrAndNotify(kNameSpaceID_None, nsGkAtoms::style, nullptr,
|
||||||
aData.mOldValue.ptrOr(nullptr), attrValue, nullptr,
|
aData.mOldValue.ptrOr(nullptr), attrValue, nullptr,
|
||||||
aData.mModType, hasListeners, true,
|
aData.mModType, hasMutationEventListeners, true,
|
||||||
kDontCallAfterSetAttr, document, updateBatch);
|
kDontCallAfterSetAttr, document, updateBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -380,8 +380,6 @@ skip-if = [
|
||||||
"http2",
|
"http2",
|
||||||
]
|
]
|
||||||
|
|
||||||
["test_bug338679.html"]
|
|
||||||
|
|
||||||
["test_bug339494.html"]
|
["test_bug339494.html"]
|
||||||
|
|
||||||
["test_bug339494.xhtml"]
|
["test_bug339494.xhtml"]
|
||||||
|
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<!--
|
|
||||||
https://bugzilla.mozilla.org/show_bug.cgi?id=338679
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<title>Bug 338679: correct reporting of newValue/prevValue in
|
|
||||||
DOMAttrModified events</title>
|
|
||||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
||||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<a target="_blank"
|
|
||||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=338679">Bug
|
|
||||||
338679: correct reporting of newValue/prevValue in
|
|
||||||
DOMAttrModified events</a>
|
|
||||||
|
|
||||||
<div id="test" style="width:20em"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
var testDiv = document.getElementById("test");
|
|
||||||
var e_new, e_prev = testDiv.getAttribute("style");
|
|
||||||
var phase, recursive = false;
|
|
||||||
|
|
||||||
/* driver */
|
|
||||||
var tests = [ test_1, test_2, test_3 ];
|
|
||||||
var i = 0;
|
|
||||||
function nextTest() {
|
|
||||||
if (i < tests.length) {
|
|
||||||
phase = tests[i];
|
|
||||||
i++;
|
|
||||||
phase();
|
|
||||||
} else {
|
|
||||||
SimpleTest.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
is(ev.newValue, e_new,
|
|
||||||
phase.name + (recursive ? " recursive" : "") + ": newValue");
|
|
||||||
is(ev.prevValue, e_prev,
|
|
||||||
phase.name + (recursive ? " recursive" : "") + ": prevValue");
|
|
||||||
|
|
||||||
e_prev = e_new;
|
|
||||||
if (!recursive) {
|
|
||||||
recursive = true;
|
|
||||||
e_new = "width: 0px;";
|
|
||||||
testDiv.style.width = "0";
|
|
||||||
} else {
|
|
||||||
recursive = false;
|
|
||||||
setTimeout(nextTest, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* tests */
|
|
||||||
function test_1() {
|
|
||||||
e_new = "width: auto;";
|
|
||||||
testDiv.style.width = "auto";
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_2() {
|
|
||||||
e_new = "width: 15%;";
|
|
||||||
testDiv.style.width = "15%";
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_3() {
|
|
||||||
window.getComputedStyle(testDiv).width; // force style resolution
|
|
||||||
e_new = "width: inherit;";
|
|
||||||
testDiv.style.width = "inherit";
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,52 +1,20 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Test for Bug 338679 (from bug 1340341)</title>
|
<title>Test for Bug 1460295</title>
|
||||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div style=""></div>
|
<div></div>
|
||||||
<script>
|
<script>
|
||||||
SimpleTest.waitForExplicitFinish();
|
let div = document.querySelector("div");
|
||||||
|
let count = 0;
|
||||||
// Run the test first with mutation events enabled and then disabled.
|
div.addEventListener("DOMAttrModified", function () {
|
||||||
SpecialPowers.pushPrefEnv(
|
count++;
|
||||||
{ 'set': [['dom.mutation-events.cssom.disabled', false]] },
|
});
|
||||||
runTest
|
div.style.color = "green";
|
||||||
);
|
is(count, 0, "No DOMAttrModified event should be triggered");
|
||||||
|
</script>
|
||||||
function runTest(stop) {
|
</body>
|
||||||
let div = document.querySelector('div');
|
|
||||||
let expectation;
|
|
||||||
let count = 0;
|
|
||||||
div.style.color = "red";
|
|
||||||
div.addEventListener('DOMAttrModified', function(evt) {
|
|
||||||
count++;
|
|
||||||
is(evt.prevValue, expectation.prevValue, `Previous value for event ${count}`);
|
|
||||||
is(evt.newValue, expectation.newValue, `New value for event ${count}`);
|
|
||||||
});
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stop) {
|
|
||||||
div.setAttribute("style", "");
|
|
||||||
SpecialPowers.pushPrefEnv(
|
|
||||||
{ 'set': [['dom.mutation-events.cssom.disabled', true]] },
|
|
||||||
function() {
|
|
||||||
runTest(true);
|
|
||||||
SimpleTest.finish();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -3165,15 +3165,6 @@
|
||||||
value: true
|
value: true
|
||||||
mirror: always
|
mirror: always
|
||||||
|
|
||||||
# Whether we disable triggering mutation events for changes to style
|
|
||||||
# attribute via CSSOM.
|
|
||||||
# NOTE: This preference is used in unit tests. If it is removed or its default
|
|
||||||
# value changes, please update test_sharedMap_static_prefs.js accordingly.
|
|
||||||
- name: dom.mutation-events.cssom.disabled
|
|
||||||
type: bool
|
|
||||||
value: true
|
|
||||||
mirror: always
|
|
||||||
|
|
||||||
# Limit of location change caused by content scripts in a time span per
|
# Limit of location change caused by content scripts in a time span per
|
||||||
# BrowsingContext. This includes calls to History and Location APIs.
|
# BrowsingContext. This includes calls to History and Location APIs.
|
||||||
- name: dom.navigation.locationChangeRateLimit.count
|
- name: dom.navigation.locationChangeRateLimit.count
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
const PREF1_NAME = "dom.webcomponents.shadowdom.report_usage";
|
const PREF1_NAME = "dom.webcomponents.shadowdom.report_usage";
|
||||||
const PREF1_VALUE = false;
|
const PREF1_VALUE = false;
|
||||||
|
|
||||||
const PREF2_NAME = "dom.mutation-events.cssom.disabled";
|
const PREF2_NAME = "full-screen-api.enabled";
|
||||||
const PREF2_VALUE = true;
|
const PREF2_VALUE = true;
|
||||||
|
|
||||||
const { XPCShellContentUtils } = ChromeUtils.importESModule(
|
const { XPCShellContentUtils } = ChromeUtils.importESModule(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue