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(~:dir(~)) should work
https://bugs.webkit.org/show_bug.cgi?id=243093 Reviewed by Antti Koivisto. Implement :dir pseudo class invalidation. This patch introduces the notion of effective text direction which is stored in Node's rareDataBitfields. To signify whether this is used for text direction or not, another boolean value usesEffectiveTextDirection has been added to rareDataBitfields. Like https://commits.webkit.org/253764@main for :lang, this patch has an optimization to avoid using rareDataBitfields when the text direction matches that of the document element. * LayoutTests/TestExpectations: Removed image only failures from tests that are now passing. * LayoutTests/fast/css/dir-pseudo-container-query-expected.html: Added. * LayoutTests/fast/css/dir-pseudo-container-query-invalidation-expected.html: Added. * LayoutTests/fast/css/dir-pseudo-container-query-invalidation.html: Added. * LayoutTests/fast/css/dir-pseudo-container-query.html: Added. * LayoutTests/platform/win/TestExpectations: Skip the newly added tests since :dir isn't enabled yet. * Source/WebCore/css/SelectorCheckerTestFunctions.h (WebCore::matchesDirPseudoClass): Now uses effectiveTextDirection instead of computeDirectionality. * Source/WebCore/dom/Document.cpp: (WebCore::Document::childrenChanged): Calls setDocumentElementTextDirection. Note we need to explicitly check usesEffectiveTextDirection since effectiveTextDirection falls back to documentElementTextDirection. * Source/WebCore/dom/Document.h: (WebCore::Document::documentElementTextDirection const): Added. (WebCore::Document::setDocumentElementTextDirection): Added. * Source/WebCore/dom/Node.cpp: (WebCore::Node::incrementConnectedSubframeCount): (WebCore::Node::effectiveTextDirection const): Added. (WebCore::Node::setEffectiveTextDirection): Added. (WebCore::Node::setUsesEffectiveTextDirection): Added. * Source/WebCore/dom/Node.h: (WebCore::Node::usesEffectiveTextDirection const): Added. * Source/WebCore/html/HTMLElement.cpp: (WebCore::TextDirectionDirective): Added. (WebCore::parseTextDirection): Added. (WebCore::isValidDirValue): Now uses parseTextDirection. (WebCore::elementAffectsDirectionality): Moved up to be used in insertedIntoAncestor. (WebCore::HTMLElement::insertedIntoAncestor): Inherit the effective text direction from parent unless this is an input type=telephone. (WebCore::HTMLElement::removedFromAncestor): Added. Clear the inherited effective text direction. (WebCore::HTMLElement::computeDirectionality const): Removed. (WebCore::HTMLElement::dirAttributeChanged): Added the invalidation logic for each value type. Notably, when the new value is invalid, we inherit from the parent node unless this is an input type=telephone. (WebCore::HTMLElement::updateEffectiveDirectionality): Added. Implements the recursive invalidation for :dir pseudo class. (WebCore::HTMLElement::adjustDirectionalityIfNeededAfterChildAttributeChanged): Update the effective text direction instead of simply invalidating the style. (WebCore::HTMLElement::updateEffectiveDirectionalityOfDirAuto): Ditto. (WebCore::HTMLElement::adjustDirectionalityIfNeededAfterChildrenChanged): * Source/WebCore/html/HTMLElement.h: * Source/WebCore/html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::subtreeHasChanged): Don't call updateEffectiveDirectionalityOfDirAuto if this element hasn't been marked with selfOrPrecedingNodesAffectDirAuto. Otherwise, we'd set selfOrPrecedingNodesAffectDirAuto on input element without dir=auto. This was caught by new assertions. (WebCore::HTMLInputElement::setValue): Added a call to updateEffectiveDirectionalityOfDirAuto when selfOrPrecedingNodesAffectDirAuto is set. This is needed now that the effective text direction is cached as opposed to re-computed each time in computeDirectionality. * Source/WebCore/html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::subtreeHasChanged): Same as HTMLInputElement. (WebCore::HTMLTextAreaElement::setValueCommon): Ditto. Canonical link: https://commits.webkit.org/254017@main
- Loading branch information
Showing
15 changed files
with
228 additions
and
58 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
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: 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: 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,29 @@ | ||
<!DOCTYPE html> | ||
<html class="reftest-wait"> | ||
<body> | ||
<section><div id="ltr1" class="ltr"></div></section> | ||
<section id="ltr2" dir="rtl"><div class="ltr"><span></span></div></section> | ||
<section dir="ltr"><div class="ltr"><span></span></div></section> | ||
<section><div id="rtl1" class="rtl"><span></span></div></section> | ||
<section id="rtl2"><div class="rtl"><span></span></div></section> | ||
<style> | ||
div, section { width: 100px; height: 20px; } | ||
section { background: red; } | ||
.ltr:has(*:dir(ltr)) { background: green; } | ||
.ltr:has(*:dir(rtl)) { background: red; } | ||
.rtl:has(*:dir(rtl)) { background: green; } | ||
.rtl:has(*:dir(ltr)) { background: red; } | ||
</style> | ||
<script> | ||
requestAnimationFrame(() => { | ||
setTimeout(() => { | ||
ltr1.appendChild(document.createElement('span')); | ||
ltr2.dir = 'ltr'; | ||
rtl1.dir = 'rtl'; | ||
rtl2.dir = 'rtl'; | ||
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,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<section><div class="ltr"><span></span></div></section> | ||
<section><div dir="ltr" class="ltr"><span></span></div></section> | ||
<section dir="ltr"><div class="ltr"><span></span></div></section> | ||
<section><div dir="rtl" class="rtl"><span></span></div></section> | ||
<section dir="rtl"><div class="rtl"><span></span></div></section> | ||
<style> | ||
div, section { width: 100px; height: 20px; } | ||
section { background: red; } | ||
.ltr:has(*:dir(ltr)) { background: green; } | ||
.ltr:has(*:dir(rtl)) { background: red; } | ||
.rtl:has(*:dir(rtl)) { background: green; } | ||
.rtl:has(*:dir(ltr)) { background: red; } | ||
</style> | ||
</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
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.