Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CustomStateSet and :state() selector #20012

Merged
merged 1 commit into from Dec 6, 2023

Conversation

keithamus
Copy link
Member

@keithamus keithamus commented Nov 5, 2023

59cb7cb

Add CustomStateSet and :state() selector
https://bugs.webkit.org/show_bug.cgi?id=215911

Reviewed by Tim Nguyen.

This adds the CustomStateSet idl definitions, and the `states` getter in
the ElementInternals IDL. The gatter laziliy initialises a
CustomStateSet object in ElementRareData which behaves like a
setlike<DOMString>.

This also adds the `:state()` pseudo selector, which can take an ident
and matches when the ident matches one of the given states in the
CustomStateSet for the element.

Any states set by CustomStateSet need to invalidate styles for the
element, so the `:state()` pseudo can match.

* LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/state-in-has-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/state-in-has.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/selectors/parsing/parse-state-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/state/tentative/ElementInternals-states-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/state/tentative/ElementInternals-states.html:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/state/tentative/state-pseudo-class-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/state/tentative/state-pseudo-class.html:
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/custom-state-set-strong-ref.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/idlharness.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/state-css-selector-shadow-dom.tentative-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/state-css-selector-shadow-dom.tentative.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/state-css-selector.tentative-expected.txt:
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources-output.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/bindings/js/WebCoreBuiltinNames.h:
* Source/WebCore/css/CSSSelector.cpp:
(WebCore::CSSSelector::selectorText const):
* Source/WebCore/css/CSSSelector.h:
* Source/WebCore/css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne const):
* Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in:
* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::add):
* Source/WebCore/css/parser/CSSParserContext.h:
* Source/WebCore/css/parser/CSSSelectorParser.cpp:
(WebCore::isOnlyPseudoClassFunction):
(WebCore::CSSSelectorParser::consumePseudo):
* Source/WebCore/css/parser/CSSSelectorParserContext.cpp:
(WebCore::CSSSelectorParserContext::CSSSelectorParserContext):
(WebCore::add):
* Source/WebCore/css/parser/CSSSelectorParserContext.h:
* Source/WebCore/cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoClassType):
* Source/WebCore/dom/CustomStateSet.cpp: Added.
(WebCore::CustomStateSet::addToSetLike):
(WebCore::CustomStateSet::removeFromSetLike):
(WebCore::CustomStateSet::clearFromSetLike):
(WebCore::CustomStateSet::has):
* Source/WebCore/dom/CustomStateSet.h: Added.
* Source/WebCore/dom/CustomStateSet.idl: Added.
* Source/WebCore/dom/Element.cpp:
(WebCore::Element::hasCustomState const):
(WebCore::Element::ensureCustomStateSet):
* Source/WebCore/dom/Element.h:
* Source/WebCore/dom/ElementInternals.cpp:
(WebCore::ElementInternals::states):
* Source/WebCore/dom/ElementInternals.h:
* Source/WebCore/dom/ElementInternals.idl:
* Source/WebCore/dom/ElementRareData.cpp:
* Source/WebCore/dom/ElementRareData.h:
(WebCore::ElementRareData::customStateSet):
(WebCore::ElementRareData::setCustomStateSet):
(WebCore::ElementRareData::useTypes const):
* Source/WebCore/dom/NodeRareData.h:

Canonical link: https://commits.webkit.org/271600@main

e495b9d

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug   πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2   πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
  πŸ§ͺ ios-wk2-wpt   πŸ§ͺ mac-wk1 βœ… πŸ›  gtk
  πŸ›  πŸ§ͺ jsc   πŸ§ͺ api-ios   πŸ§ͺ mac-wk2   πŸ§ͺ gtk-wk2
  πŸ›  πŸ§ͺ jsc-arm64   πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv-sim   πŸ§ͺ mac-wk2-stress βœ… πŸ›  jsc-armv7
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch βœ… πŸ§ͺ jsc-armv7-tests
  πŸ›  watch-sim

Copy link
Member

@nt1m nt1m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to add a special case at: https://searchfox.org/wubkat/rev/023c54054092dc68c5df3b230ed3137cbd753b16/Source/WebCore/css/parser/CSSSelectorParser.cpp#743-763

Otherwise, :state with no argument won't be rejected.

Source/WebCore/css/CSSSelector.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/CustomStateSet.h Outdated Show resolved Hide resolved
Source/WebCore/dom/Element.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/CustomStateSet.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/CustomStateSet.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/CustomStateSet.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/CustomStateSet.cpp Outdated Show resolved Hide resolved
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 5, 2023
@rniwa
Copy link
Member

rniwa commented Nov 5, 2023

https://bugs.webkit.org/show_bug.cgi?id=215911

There should be the but title right above it.

This adds the CustomStateSet idl definitions, and the states getter in the ElementInternals IDL. The gatter laziliy initialises a CustomStateSet object in ElementRareData which behaves like a setlike.

Please insert a line break after 100 characters or so.

@rniwa
Copy link
Member

rniwa commented Nov 6, 2023

We should add a test for invalidating :host:state(foo).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do a WPT resync of custom-elements/ and custom-state-pseudo-class separately ? I think it'll make it easier for you to export, and it's easier to review generally since it's clear which ones are new tests.

Source/WebCore/cssjit/SelectorCompiler.cpp Outdated Show resolved Hide resolved
Source/WebCore/css/CSSSelector.cpp Outdated Show resolved Hide resolved
@Ahmad-S792 Ahmad-S792 added DOM For bugs specific to XML/HTML DOM elements (including parsing). and removed merging-blocked Applied to prevent a change from being merged labels Nov 12, 2023
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Dec 4, 2023
@nt1m nt1m removed the merging-blocked Applied to prevent a change from being merged label Dec 4, 2023
Source/WebCore/dom/CustomStateSet.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/CustomStateSet.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/CustomStateSet.idl Outdated Show resolved Hide resolved
Source/WebCore/dom/CustomStateSet.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/CustomStateSet.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/Element.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/Element.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/ElementInternals.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/Element.cpp Outdated Show resolved Hide resolved
Source/WebCore/dom/Element.cpp Outdated Show resolved Hide resolved
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Dec 5, 2023
@keithamus keithamus removed the merging-blocked Applied to prevent a change from being merged label Dec 5, 2023
@keithamus keithamus requested review from cdumez and nt1m December 5, 2023 10:33
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Dec 5, 2023
Source/WebCore/dom/CustomStateSet.idl Outdated Show resolved Hide resolved
@keithamus keithamus added request-merge-queue Request a pull request to be added to merge-queue once ready and removed merging-blocked Applied to prevent a change from being merged labels Dec 6, 2023
@Ahmad-S792 Ahmad-S792 added merge-queue Applied to send a pull request to merge-queue and removed request-merge-queue Request a pull request to be added to merge-queue once ready labels Dec 6, 2023
https://bugs.webkit.org/show_bug.cgi?id=215911

Reviewed by Tim Nguyen.

This adds the CustomStateSet idl definitions, and the `states` getter in
the ElementInternals IDL. The gatter laziliy initialises a
CustomStateSet object in ElementRareData which behaves like a
setlike<DOMString>.

This also adds the `:state()` pseudo selector, which can take an ident
and matches when the ident matches one of the given states in the
CustomStateSet for the element.

Any states set by CustomStateSet need to invalidate styles for the
element, so the `:state()` pseudo can match.

* LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/state-in-has-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/state-in-has.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/selectors/parsing/parse-state-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/state/tentative/ElementInternals-states-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/state/tentative/ElementInternals-states.html:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/state/tentative/state-pseudo-class-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/state/tentative/state-pseudo-class.html:
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/custom-state-set-strong-ref.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/idlharness.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/state-css-selector-shadow-dom.tentative-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/state-css-selector-shadow-dom.tentative.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/custom-state-pseudo-class/state-css-selector.tentative-expected.txt:
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources-output.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/bindings/js/WebCoreBuiltinNames.h:
* Source/WebCore/css/CSSSelector.cpp:
(WebCore::CSSSelector::selectorText const):
* Source/WebCore/css/CSSSelector.h:
* Source/WebCore/css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne const):
* Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in:
* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::add):
* Source/WebCore/css/parser/CSSParserContext.h:
* Source/WebCore/css/parser/CSSSelectorParser.cpp:
(WebCore::isOnlyPseudoClassFunction):
(WebCore::CSSSelectorParser::consumePseudo):
* Source/WebCore/css/parser/CSSSelectorParserContext.cpp:
(WebCore::CSSSelectorParserContext::CSSSelectorParserContext):
(WebCore::add):
* Source/WebCore/css/parser/CSSSelectorParserContext.h:
* Source/WebCore/cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoClassType):
* Source/WebCore/dom/CustomStateSet.cpp: Added.
(WebCore::CustomStateSet::addToSetLike):
(WebCore::CustomStateSet::removeFromSetLike):
(WebCore::CustomStateSet::clearFromSetLike):
(WebCore::CustomStateSet::has):
* Source/WebCore/dom/CustomStateSet.h: Added.
* Source/WebCore/dom/CustomStateSet.idl: Added.
* Source/WebCore/dom/Element.cpp:
(WebCore::Element::hasCustomState const):
(WebCore::Element::ensureCustomStateSet):
* Source/WebCore/dom/Element.h:
* Source/WebCore/dom/ElementInternals.cpp:
(WebCore::ElementInternals::states):
* Source/WebCore/dom/ElementInternals.h:
* Source/WebCore/dom/ElementInternals.idl:
* Source/WebCore/dom/ElementRareData.cpp:
* Source/WebCore/dom/ElementRareData.h:
(WebCore::ElementRareData::customStateSet):
(WebCore::ElementRareData::setCustomStateSet):
(WebCore::ElementRareData::useTypes const):
* Source/WebCore/dom/NodeRareData.h:

Canonical link: https://commits.webkit.org/271600@main
@webkit-commit-queue
Copy link
Collaborator

Committed 271600@main (59cb7cb): https://commits.webkit.org/271600@main

Reviewed commits have been landed. Closing PR #20012 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Dec 6, 2023
@keithamus keithamus deleted the custom-state-set branch December 6, 2023 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DOM For bugs specific to XML/HTML DOM elements (including parsing).
Projects
None yet
8 participants