Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
:has(:lang(~)) doesn't get invalidated
https://bugs.webkit.org/show_bug.cgi?id=243172 Reviewed by Antti Koivistso. Make container query work with :lang pseudo class. This patch introduces ElementRareData::effectiveLang to store the language of each element, and uses Style::PseudoClassChangeInvalidation to invalidate styles for :lang pseudo class. As an optimization, this patch also introduces Document::effectiveDocumentElementLanguage which is the effective language of the document element as many websites specify a language there. This avoids creating ElementRareData on all elements in the vast majority of cases. * LayoutTests/fast/css/lang-pseudo-container-query-document-element-invalidation-expected.html: Added. * LayoutTests/fast/css/lang-pseudo-container-query-document-element-invalidation.html: Added.pee * LayoutTests/fast/css/lang-pseudo-container-query-invalidation-expected.html: Added. * LayoutTests/fast/css/lang-pseudo-container-query-invalidation-xhtml-expected.html: Added. * LayoutTests/fast/css/lang-pseudo-container-query-invalidation-xhtml.xhtml: Added. * LayoutTests/fast/css/lang-pseudo-container-query-invalidation.html: Added. * LayoutTests/fast/css/lang-pseudo-container-query-multiple-document-elements-invalidation-expected.html: Added. * LayoutTests/fast/css/lang-pseudo-container-query-multiple-document-elements-invalidation.html: Added. * Source/WebCore/css/SelectorCheckerTestFunctions.h: (WebCore::matchesLangPseudoClass): Use newly introduced effectiveLang. * Source/WebCore/dom/Document.cpp: (WebCore::Document::childrenChanged): (WebCore::Document::effectiveDocumentElementLanguage): Added. (WebCore::Document::setDocumentElementLanguage): Added. * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Element.cpp: (WebCore::effectiveLangFromAttribute): (WebCore::Element::attributeChanged): Added the style invalidation logic for :lang. (WebCore::Element::insertedIntoAncestor): Propagate the lang attribute from the parent. (WebCore::Element::removedFromAncestor): Clear the effective lang when appropriate. (WebCore::Element::computeInheritedLanguage const): Deleted. (WebCore::Element::effectiveLang const): Added. (WebCore::Element::langFromAttribute const): Added. (WebCore::Element::locale const): * Source/WebCore/dom/Element.h: * Source/WebCore/dom/ElementRareData.cpp: (WebCore::SameSizeAsElementRareData): * Source/WebCore/dom/ElementRareData.h: (WebCore::ElementRareData::effectiveLang const): Added. (WebCore::ElementRareData::setEffectiveLang): Added. (WebCore::ElementRareData::useTypes const): * Source/WebCore/dom/NodeRareData.h: * Source/WebCore/style/PseudoClassChangeInvalidation.cpp: (WebCore::Style::PseudoClassChangeInvalidation::computeInvalidation): (WebCore::Style::PseudoClassChangeInvalidation::collectRuleSets): * Source/WebCore/style/PseudoClassChangeInvalidation.h: (WebCore::Style::PseudoClassChangeInvalidation::Value): Added. (WebCore::Style::PseudoClassChangeInvalidation::PseudoClassChangeInvalidation): Added a new variant which takes AnyValueTag as an argument. * Source/WebCore/html/BaseDateAndTimeInputType.cpp: (WebCore::BaseDateAndTimeInputType::localeIdentifier const): (WebCore::BaseDateAndTimeInputType::setupDateTimeChooserParameters): * Tools/TestWebKitAPI/Tests/WebCore/DocumentOrder.cpp: (TestWebKitAPI::createDocument): Initialize XMLNames via ProcessWarming. Canonical link: https://commits.webkit.org/253764@main
- Loading branch information
Showing
20 changed files
with
268 additions
and
26 deletions.
There are no files selected for viewing
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 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div style="width: 100px; height: 100px; background-color: green;"></div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html class="reftest-wait"> | ||
<head> | ||
<meta http-equiv="content-language" content="fr"> | ||
</head> | ||
<body> | ||
<div><span></span></div> | ||
<style> | ||
div { width: 100px; height: 100px; } | ||
div:has(*:lang(fr)) { background: red; } | ||
div:has(*:lang(en)) { background: green; } | ||
</style> | ||
<script> | ||
requestAnimationFrame(() => { | ||
setTimeout(() => { | ||
document.documentElement.lang = 'en'; | ||
document.documentElement.className = ''; | ||
}, 0); | ||
}); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div style="width: 100px; height: 100px; background-color: green;"></div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div style="width: 100px; height: 100px; background-color: green;"></div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html class="reftest-wait" xmlns="http://www.w3.org/1999/xhtml"> | ||
<body> | ||
<section class="lang"><div xml:lang="zh" lang="ja"></div></section> | ||
<section class="lang"><div id="ja" xml:lang="ja" lang="ja"></div></section> | ||
<div><section class="lang" id="fr" lang="fr" style="-webkit-locale: 'en'"><div></div></section></div> | ||
<div><section class="lang" id="es" xml:lang="es"><div></div></section></div> | ||
<section class="lang"><div id="kr" xml:lang="kr" lang="en"></div></section> | ||
<style> | ||
body > * { background: red; } | ||
section, div { width: 100px; height: 20px; } | ||
.lang:has(:lang(zh)) { background: green; } | ||
.lang:has(:lang(ja)) { background: red; } | ||
div:has(.lang:lang(fr)) { background: red; } | ||
div:has(.lang:lang(en)) { background: green; } | ||
div:has(#es:lang(es)) { background: red; } | ||
div:has(#es:lang(en)) { background: green; } | ||
.lang:has(#kr:lang(kr)) { background: red; } | ||
.lang:has(#kr:lang(kr)) { background: green; } | ||
div:has(.lang > :lang(pt)) { background: red; } | ||
</style> | ||
<script> | ||
requestAnimationFrame(() => { | ||
setTimeout(() => { | ||
document.getElementById('ja').setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', 'zh'); | ||
document.getElementById('fr').setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', 'en'); | ||
document.getElementById('es').setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', 'en'); | ||
document.getElementById('kr').removeAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang'); | ||
document.documentElement.className = ''; | ||
}, 0); | ||
}); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<html class="reftest-wait"> | ||
<body> | ||
<section class="lang"><div lang="en"></div></section> | ||
<section class="lang" id="fr" lang="fr"><div></div></section> | ||
<section class="lang" id="ja" lang="ja" style="-webkit-locale: 'en'"><div></div></section> | ||
<div><section class="lang" id="zh" lang="zh" style="-webkit-locale: 'en'"><span></span></section></div> | ||
<div id="kr" class="lang" lang="kr"></div> | ||
<style> | ||
div { width: 100px; height: 20px; } | ||
.lang div:lang(en) { background: green; } | ||
.lang div:lang(fr) { background: red; } | ||
.lang div:lang(ja) { background: red; } | ||
div:has(.lang :lang(zh)) { background: red; } | ||
div:has(.lang :lang(en)) { background: green; } | ||
.lang:lang(kr) { background: red; } | ||
.lang div:lang(kr) { background: green; } | ||
</style> | ||
<script> | ||
requestAnimationFrame(() => { | ||
setTimeout(() => { | ||
fr.lang = 'en'; | ||
ja.lang = 'en'; | ||
zh.lang = 'en'; | ||
kr.appendChild(document.createElement('div')); | ||
document.documentElement.className = ''; | ||
}, 0); | ||
}); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div style="width: 100px; height: 100px; background-color: green;"></div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<html lang="fr" class="reftest-wait"> | ||
<div><span></span></div> | ||
<script> | ||
|
||
const test = document.querySelector('div').matches('*:has(:lang(fr))') ? 'PASS' : 'FAIL'; | ||
|
||
const newDocumentElement = document.createElement('html'); | ||
newDocumentElement.lang = 'en'; | ||
document.replaceChild(newDocumentElement, document.documentElement); | ||
document.documentElement.innerHTML = ` | ||
<head> | ||
<style> | ||
div { width: 100px; height: 100px; } | ||
div:has(*:lang(fr)) { background: red; } | ||
div:has(*:lang(en)) { background: green; } | ||
span.pass { color: green; } | ||
span.fail { color: red; } | ||
</style> | ||
</head> | ||
<body> | ||
<div><span class="${test}">${test}</span></div> | ||
</body>`; | ||
|
||
</script> | ||
</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
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
Oops, something went wrong.