tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit b7e1499bbcf76678201f41b969d5cc081201141d
parent 99e34a1b2e8b244ff32e078a15c3b6568e0e1cdf
Author: Boris Chiou <boris.chiou@gmail.com>
Date:   Thu, 30 Oct 2025 19:25:07 +0000

Bug 1997145 - Add pseudo element identifier to selector_matches_element(). r=firefox-style-system-reviewers,emilio

In order to support view transition pseudo-element, we have to pass the
pseudo element identifier to this function to retrive the correct
pseudo-element.

Differential Revision: https://phabricator.services.mozilla.com/D270626

Diffstat:
Mlayout/style/CSSStyleRule.cpp | 24+++++++++---------------
Mservo/ports/geckolib/glue.rs | 14+++++++++++++-
2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/layout/style/CSSStyleRule.cpp b/layout/style/CSSStyleRule.cpp @@ -276,12 +276,6 @@ uint64_t CSSStyleRule::SelectorSpecificityAt(uint32_t aSelectorIndex, return s; } -static Maybe<PseudoStyleType> GetPseudoType(const nsAString& aPseudo) { - return nsCSSPseudoElements::ParsePseudoElement( - aPseudo, CSSEnabledState::IgnoreEnabledState) - .map([](const PseudoStyleRequest& aRequest) { return aRequest.mType; }); -} - static void GetHosts(StyleSheet* aSheet, const Element& aElement, nsTArray<Element*>& aHosts) { if (!aSheet) { @@ -316,7 +310,8 @@ bool CSSStyleRule::SelectorMatchesElement(uint32_t aSelectorIndex, Element& aElement, const nsAString& aPseudo, bool aRelevantLinkVisited) { - const auto pseudo = GetPseudoType(aPseudo); + const auto pseudo = nsCSSPseudoElements::ParsePseudoElement( + aPseudo, CSSEnabledState::IgnoreEnabledState); if (!pseudo) { return false; } @@ -332,11 +327,9 @@ bool CSSStyleRule::SelectorMatchesElement(uint32_t aSelectorIndex, } for (auto* host : hosts) { - // FIXME: Bug 1909173. This function is used for DevTools, so we may need - // to revist here once we finish the support of view-transitions. - if (Servo_StyleRule_SelectorMatchesElement(&rules, &scopes, &aElement, - aSelectorIndex, host, *pseudo, - aRelevantLinkVisited)) { + if (Servo_StyleRule_SelectorMatchesElement( + &rules, &scopes, &aElement, aSelectorIndex, host, pseudo->mType, + pseudo->mIdentifier, aRelevantLinkVisited)) { return true; } } @@ -348,7 +341,8 @@ Element* CSSStyleRule::GetScopeRootFor(uint32_t aSelectorIndex, dom::Element& aElement, const nsAString& aPseudo, bool aRelevantLinkVisited) { - const auto pseudo = GetPseudoType(aPseudo); + const auto pseudo = nsCSSPseudoElements::ParsePseudoElement( + aPseudo, CSSEnabledState::IgnoreEnabledState); if (!pseudo) { return nullptr; } @@ -358,8 +352,8 @@ Element* CSSStyleRule::GetScopeRootFor(uint32_t aSelectorIndex, AutoTArray<StyleScopeRuleData, 1> scopes; CollectStyleRules(*this, /* aDesugared = */ true, rules, &scopes); return const_cast<Element*>(Servo_StyleRule_GetScopeRootFor( - &rules, &scopes, &aElement, aSelectorIndex, host, *pseudo, - aRelevantLinkVisited)); + &rules, &scopes, &aElement, aSelectorIndex, host, pseudo->mType, + pseudo->mIdentifier, aRelevantLinkVisited)); } SelectorWarningKind ToWebIDLSelectorWarningKind( diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs @@ -2770,6 +2770,7 @@ fn selector_matches_element<F, R>( index: u32, host: Option<&RawGeckoElement>, pseudo_type: PseudoStyleType, + pseudo_id: *const nsAtom, relevant_link_visited: bool, on_match: F, ) -> Option<R> @@ -2787,7 +2788,14 @@ where return None; }; let mut matching_mode = MatchingMode::Normal; - match PseudoElement::from_pseudo_type(pseudo_type, None) { + let pseudo_id = if pseudo_id.is_null() { + None + } else { + Some(AtomIdent::new(unsafe { + Atom::from_raw(pseudo_id as *mut nsAtom) + })) + }; + match PseudoElement::from_pseudo_type(pseudo_type, pseudo_id) { Some(pseudo) => { // We need to make sure that the requested pseudo element type // matches the selector pseudo element type before proceeding. @@ -2854,6 +2862,7 @@ pub extern "C" fn Servo_StyleRule_SelectorMatchesElement( index: u32, host: Option<&RawGeckoElement>, pseudo_type: PseudoStyleType, + pseudo_id: *const nsAtom, relevant_link_visited: bool, ) -> bool { selector_matches_element( @@ -2863,6 +2872,7 @@ pub extern "C" fn Servo_StyleRule_SelectorMatchesElement( index, host, pseudo_type, + pseudo_id, relevant_link_visited, |_| true, ) @@ -2877,6 +2887,7 @@ pub extern "C" fn Servo_StyleRule_GetScopeRootFor( index: u32, host: Option<&RawGeckoElement>, pseudo_type: PseudoStyleType, + pseudo_id: *const nsAtom, relevant_link_visited: bool, ) -> *const RawGeckoElement { let element = GeckoElement(element); @@ -2887,6 +2898,7 @@ pub extern "C" fn Servo_StyleRule_GetScopeRootFor( index, host, pseudo_type, + pseudo_id, relevant_link_visited, |candidate| { candidate