Implement CSS :root selector matching to apply styles to layout view
#259
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements support for the CSS
:rootpseudo-class selector, enabling styles to be applied to the document's root element (layout view). Previously,:rootselectors could be parsed but were not matched during style computation, making them effectively non-functional.Problem
The CSS selector parser already supported parsing
:rootselectors, but the matching logic inmatchesSelectorComponentNonCombinator()had the:rootcase commented out:This meant that CSS rules like the following would be parsed but never applied:
Solution
Core Implementation
Added
isRootElement()helper function inmatching.cpp:document.documentElement()Enabled
:rootselector matching::rootcase inmatchesSelectorComponentNonCombinator()Integration Flow
The implementation works through the existing style computation pipeline:
RenderHTMLDocument::onExecute()processes elementsWindow::getComputedStyle()iterates through CSS rulesmatchesSelectorList()calls the new:rootmatching logicadoptStyle()Testing
Added comprehensive test cases covering:
:rootselector parsing:rootwith other components (e.g.,:root.theme-dark):rootImpact
This change enables:
:root:rootclass combinationsExample Usage
These styles will now be properly applied to the layout view's root element, providing the foundation for the entire document's styling system.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
registry.npmmirror.comnpm ci(dns block)npm install(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.