-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSS Typed OM doesn't schedule mutation records
https://bugs.webkit.org/show_bug.cgi?id=267063 Reviewed by Antti Koivisto. This PR fixes the bug that mutating element's inline style with attributeStyleMap does not enqueue mutation record for mutation observers. To do this, this PR extracts StyleAttributeMutationScope out of PropertySetCSSStyleDeclaration.cpp into its own cpp/h files and generalizes it to support both CSSStyleDeclaration and attributeStyleMap. * LayoutTests/fast/custom-elements/mutation-observer-for-style-attribute-on-custom-elements-expected.txt: Added. * LayoutTests/fast/custom-elements/mutation-observer-for-style-attribute-on-custom-elements.html: Added. * LayoutTests/fast/dom/MutationObserver/observe-attributes-expected.txt: * LayoutTests/fast/dom/MutationObserver/observe-attributes.html: Added test cases. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp: (WebCore::PropertySetCSSStyleDeclaration::setCssText): (WebCore::PropertySetCSSStyleDeclaration::setProperty): (WebCore::PropertySetCSSStyleDeclaration::removeProperty): (WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal): (WebCore::InlineCSSStyleDeclaration::didMutate): (WebCore::StyleAttributeMutationScope::StyleAttributeMutationScope): Deleted. (WebCore::StyleAttributeMutationScope::~StyleAttributeMutationScope): Deleted. (WebCore::StyleAttributeMutationScope::enqueueMutationRecord): Deleted. (WebCore::StyleAttributeMutationScope::didInvalidateStyleAttr): Deleted. * Source/WebCore/css/StyleAttributeMutationScope.cpp: Added. * Source/WebCore/css/StyleAttributeMutationScope.h: Added. (WebCore::StyleAttributeMutationScope::StyleAttributeMutationScope): Added. (WebCore::StyleAttributeMutationScope::~StyleAttributeMutationScope): Added. (WebCore::StyleAttributeMutationScope::enqueueMutationRecord): Added. * Source/WebCore/css/typedom/InlineStylePropertyMap.cpp: (WebCore::InlineStylePropertyMap::removeProperty): (WebCore::InlineStylePropertyMap::setShorthandProperty): (WebCore::InlineStylePropertyMap::setProperty): (WebCore::InlineStylePropertyMap::setCustomProperty): (WebCore::InlineStylePropertyMap::removeCustomProperty): (WebCore::InlineStylePropertyMap::clear): * Source/WebCore/css/typedom/InlineStylePropertyMap.h: Canonical link: https://commits.webkit.org/276782@main
- Loading branch information
Showing
10 changed files
with
428 additions
and
111 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...ast/custom-elements/mutation-observer-for-style-attribute-on-custom-elements-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
This tests observing a custom element, which observes "style" content attribute, with a MutationObserver. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS observer.takeRecords().length is 0 | ||
PASS attributeChanges.length is 0 | ||
element = document.createElement("some-element"); observer.observe(element, {attributes: true}); | ||
element.style.width = "100px"; | ||
PASS records = observer.takeRecords(); records.length is 1 | ||
PASS records[0].target is element | ||
PASS records[0].type is "attributes" | ||
PASS records[0].oldValue is null | ||
PASS attributeChanges.length is 1 | ||
PASS attributeChanges[0].name is "style" | ||
PASS attributeChanges[0].oldValue is null | ||
PASS attributeChanges[0].newValue is "width: 100px;" | ||
element.style.color = "red"; | ||
PASS records = observer.takeRecords(); records.length is 1 | ||
PASS records[0].target is element | ||
PASS records[0].type is "attributes" | ||
PASS records[0].oldValue is null | ||
PASS attributeChanges.length is 2 | ||
PASS attributeChanges[1].name is "style" | ||
PASS attributeChanges[1].oldValue is "width: 100px;" | ||
PASS attributeChanges[1].newValue is "width: 100px; color: red;" | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
46 changes: 46 additions & 0 deletions
46
...tTests/fast/custom-elements/mutation-observer-for-style-attribute-on-custom-elements.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<script src="../../resources/js-test.js"></script> | ||
<script> | ||
|
||
description('This tests observing a custom element, which observes "style" content attribute, with a MutationObserver.'); | ||
|
||
let attributeChanges = []; | ||
class SomeElement extends HTMLElement { | ||
static observedAttributes = ["style"]; | ||
constructor() { | ||
super(); | ||
} | ||
attributeChangedCallback(name, oldValue, newValue) { | ||
attributeChanges.push({name, oldValue, newValue}); | ||
} | ||
}; | ||
customElements.define('some-element', SomeElement); | ||
|
||
const observer = new MutationObserver((records) => { }); | ||
shouldBe('observer.takeRecords().length', '0'); | ||
shouldBe('attributeChanges.length', '0'); | ||
evalAndLog('element = document.createElement("some-element"); observer.observe(element, {attributes: true});'); | ||
evalAndLog('element.style.width = "100px";'); | ||
shouldBe('records = observer.takeRecords(); records.length', '1'); | ||
shouldBe('records[0].target', 'element'); | ||
shouldBeEqualToString('records[0].type', 'attributes'); | ||
shouldBe('records[0].oldValue', 'null'); | ||
shouldBe('attributeChanges.length', '1'); | ||
shouldBeEqualToString('attributeChanges[0].name', 'style'); | ||
shouldBe('attributeChanges[0].oldValue', 'null'); | ||
shouldBeEqualToString('attributeChanges[0].newValue', 'width: 100px;'); | ||
evalAndLog('element.style.color = "red";'); | ||
shouldBe('records = observer.takeRecords(); records.length', '1'); | ||
shouldBe('records[0].target', 'element'); | ||
shouldBeEqualToString('records[0].type', 'attributes'); | ||
shouldBe('records[0].oldValue', 'null'); | ||
shouldBe('attributeChanges.length', '2'); | ||
shouldBeEqualToString('attributeChanges[1].name', 'style'); | ||
shouldBeEqualToString('attributeChanges[1].oldValue', 'width: 100px;'); | ||
shouldBeEqualToString('attributeChanges[1].newValue', 'width: 100px; color: red;'); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.