-
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.
cssText setter should change style attribute when the serialization d…
…iffers https://bugs.webkit.org/show_bug.cgi?id=166716 rdar://29861252 Reviewed by Antti Koivisto. 173663@main regressed our behavior with regards to the standard. This attempts to correct it while preserving as much of the optimization as possible. WPT css/cssom is synchronized up to and including: web-platform-tests/wpt#45019 * LayoutTests/imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet-constructable-invalidation-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet-constructable-invalidation.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-setter.window-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-setter.window.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-setter.window.js: Added. (document.createElement.string_appeared_here.forEach.element.cssText.setter.should.set style): * LayoutTests/imported/w3c/web-platform-tests/css/cssom/w3c-import.log: * Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp: (WebCore::PropertySetCSSStyleDeclaration::setCssText): (WebCore::PropertySetCSSStyleDeclaration::setProperty): (WebCore::PropertySetCSSStyleDeclaration::removeProperty): (WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal): (WebCore::StyleRuleCSSStyleDeclaration::didMutate): (WebCore::InlineCSSStyleDeclaration::didMutate): * Source/WebCore/css/PropertySetCSSStyleDeclaration.h: * Source/WebCore/dom/StyledElement.cpp: (WebCore::StyledElement::dirtyStyleAttribute): * Source/WebCore/dom/StyledElement.h: * Source/WebCore/style/StyleScopeRuleSets.cpp: (WebCore::Style::ScopeRuleSets::hasSimpleSelectorsForStyleAttribute const): * Source/WebCore/style/StyleScopeRuleSets.h: Canonical link: https://commits.webkit.org/276176@main
- Loading branch information
Showing
12 changed files
with
167 additions
and
9 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
...ed/w3c/web-platform-tests/css/cssom/CSSStyleSheet-constructable-invalidation-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,6 @@ | ||
Should be green. Should be green. | ||
|
||
PASS mutating constructed CSSStyleSheet applied to root invalidates styles | ||
PASS mutating constructed CSSStyleSheet applied to shadowdom invalidates styles | ||
PASS mutating dependent constructed CSSStyleSheet applied to shadowdom invalidates styles | ||
|
49 changes: 49 additions & 0 deletions
49
...s/imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet-constructable-invalidation.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,49 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title>CSSStyleSheet rule mutation invalidation</title> | ||
<link rel="author" href="mailto:wpt@keithcirkel.co.uk" title="Keith Cirkel"> | ||
<link rel="help" href="https://drafts.csswg.org/cssom/#extensions-to-the-document-or-shadow-root-interface"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<span id="span1">Should be green.</span> | ||
<span id="span2">Should be green.</span> | ||
<script> | ||
promise_test(async function(t) { | ||
const sheet = new CSSStyleSheet(); | ||
sheet.replaceSync('span {color:var(--color, red);}'); | ||
document.adoptedStyleSheets = [sheet]; | ||
t.add_cleanup(() => { | ||
document.adoptedStyleSheets = []; | ||
}) | ||
assert_equals(getComputedStyle(span1).color, "rgb(255, 0, 0)", "Sheet should apply"); | ||
sheet.rules[0].style.setProperty('--color', 'green'); | ||
assert_equals(getComputedStyle(span1).color, "rgb(0, 128, 0)", "Sheet should invalidate style"); | ||
document.adoptedStyleSheets = []; | ||
assert_equals(getComputedStyle(span1).color, "rgb(0, 0, 0)", "Removing sheet should apply"); | ||
}, "mutating constructed CSSStyleSheet applied to root invalidates styles"); | ||
|
||
promise_test(async function() { | ||
span1.attachShadow({mode:'open'}) | ||
span1.shadowRoot.append(document.createElement('slot')) | ||
const sheet = new CSSStyleSheet(); | ||
sheet.replaceSync(':host {color:var(--color, red);}'); | ||
span1.shadowRoot.adoptedStyleSheets = [sheet]; | ||
assert_equals(getComputedStyle(span1).color, "rgb(255, 0, 0)", "Sheet should apply"); | ||
sheet.rules[0].style.setProperty('--color', 'green'); | ||
assert_equals(getComputedStyle(span1).color, "rgb(0, 128, 0)", "Sheet should invalidate style"); | ||
}, "mutating constructed CSSStyleSheet applied to shadowdom invalidates styles"); | ||
|
||
promise_test(async function() { | ||
span2.attachShadow({mode:'open'}) | ||
span2.shadowRoot.append(document.createElement('slot')) | ||
const sheet1 = new CSSStyleSheet(); | ||
const sheet2 = new CSSStyleSheet(); | ||
sheet1.replaceSync(':host {color:var(--color, hotpink);}'); | ||
sheet2.replaceSync(':host {--color: blue}'); | ||
const style2 = sheet2.rules[0].style; | ||
span2.shadowRoot.adoptedStyleSheets = [sheet1, sheet2]; | ||
assert_equals(getComputedStyle(span2).color, "rgb(0, 0, 255)", "Sheet should apply"); | ||
style2.setProperty('--color', 'green'); | ||
assert_equals(getComputedStyle(span2).color, "rgb(0, 128, 0)", "Sheet should invalidate style"); | ||
}, "mutating dependent constructed CSSStyleSheet applied to shadowdom invalidates styles"); | ||
</script> |
11 changes: 11 additions & 0 deletions
11
...d/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-setter.window-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,11 @@ | ||
|
||
PASS cssText setter should set style attribute even when there are no style changes (body) | ||
PASS cssText setter should set style attribute even when there are no style changes, part 2 (body) | ||
PASS cssText setter should set style attribute even when there are no style changes, part 3 (body) | ||
PASS cssText setter should set style attribute even when there are no style changes, part 4 (body) | ||
PASS cssText setter should set style attribute even when there are no style changes (cool-beans) | ||
PASS cssText setter should set style attribute even when there are no style changes, part 2 (cool-beans) | ||
PASS cssText setter should set style attribute even when there are no style changes, part 3 (cool-beans) | ||
PASS cssText setter should set style attribute even when there are no style changes, part 4 (cool-beans) | ||
PASS cssText setter and selector invalidation | ||
|
1 change: 1 addition & 0 deletions
1
.../imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-setter.window.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 @@ | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> |
64 changes: 64 additions & 0 deletions
64
...ts/imported/w3c/web-platform-tests/css/cssom/cssstyledeclaration-csstext-setter.window.js
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,64 @@ | ||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext | ||
|
||
[ | ||
document.body, | ||
document.createElement("cool-beans") | ||
].forEach(element => { | ||
test(t => { | ||
t.add_cleanup(() => element.removeAttribute("style")); | ||
|
||
element.style.background = "red"; | ||
assert_equals(element.getAttribute("style"), "background: red;"); | ||
|
||
element.style.cssText = "background:red"; | ||
assert_equals(element.getAttribute("style"), "background: red;"); | ||
}, `cssText setter should set style attribute even when there are no style changes (${element.localName})`); | ||
|
||
test(t => { | ||
t.add_cleanup(() => element.removeAttribute("style")); | ||
|
||
element.setAttribute("style", "background: red"); | ||
assert_equals(element.getAttribute("style"), "background: red"); | ||
|
||
element.style.cssText = "background:red"; | ||
assert_equals(element.getAttribute("style"), "background: red;"); | ||
}, `cssText setter should set style attribute even when there are no style changes, part 2 (${element.localName})`); | ||
|
||
test(t => { | ||
t.add_cleanup(() => element.removeAttribute("style")); | ||
|
||
element.setAttribute("style", "background: red"); | ||
assert_equals(element.getAttribute("style"), "background: red"); | ||
|
||
element.style.cssText = "background:red "; // trailing space | ||
assert_equals(element.getAttribute("style"), "background: red;"); | ||
}, `cssText setter should set style attribute even when there are no style changes, part 3 (${element.localName})`); | ||
|
||
test(t => { | ||
t.add_cleanup(() => element.removeAttribute("style")); | ||
|
||
element.setAttribute("style", "background: red"); | ||
assert_equals(element.getAttribute("style"), "background: red"); | ||
|
||
element.style.cssText = "background:red;"; | ||
assert_equals(element.getAttribute("style"), "background: red;"); | ||
}, `cssText setter should set style attribute even when there are no style changes, part 4 (${element.localName})`); | ||
}); | ||
|
||
test(t => { | ||
const style = document.createElement("style"); | ||
t.add_cleanup(() => { | ||
document.body.removeAttribute("style"); | ||
style.remove(); | ||
}); | ||
style.textContent = `[style="background: red;"] { background:white !important; }`; | ||
document.body.appendChild(style); | ||
|
||
document.body.setAttribute("style", "background:red"); | ||
assert_true(document.body.matches("[style=\"background:red\"]")); | ||
assert_equals(getComputedStyle(document.body).backgroundColor, "rgb(255, 0, 0)"); | ||
|
||
document.body.style.cssText = "background:red"; | ||
assert_equals(getComputedStyle(document.body).backgroundColor, "rgb(255, 255, 255)"); | ||
assert_true(document.body.matches("[style=\"background: red;\"]")); | ||
}, `cssText setter and selector invalidation`); |
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
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