Bug 210419

Summary: [CSS Selectors] Selectors Level 4 specificity calculation for pseudo classes
Product: WebKit Reporter: Antti Koivisto <koivisto>
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: allan.jensen, cdumez, commit-queue, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, hi, joepeck, kangil.han, macpherson, menard, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 210480    
Bug Blocks:    
Attachments:
Description Flags
patch
none
patch
none
patch
none
patch
none
patch
simon.fraser: review+
patch
none
patch none

Description Antti Koivisto 2020-04-13 02:46:52 PDT
CSS selector specification drafts at some point had a concept of "dynamic specificity" where the specificity of a selector depended on the element it matched. It was only ever used with :matches and :nth-child pseudo classes and has subsequently been removed. Selector specificity can now always be computed statically.

There is a ton of code to support this obsolete feature. It can be removed.
Comment 1 Antti Koivisto 2020-04-13 03:21:02 PDT
Created attachment 396264 [details]
patch
Comment 2 Antti Koivisto 2020-04-13 03:42:30 PDT
Created attachment 396265 [details]
patch
Comment 3 Antti Koivisto 2020-04-13 04:34:56 PDT
Created attachment 396266 [details]
patch
Comment 4 Antti Koivisto 2020-04-13 06:26:50 PDT
Created attachment 396267 [details]
patch
Comment 5 Antti Koivisto 2020-04-13 06:32:03 PDT
Created attachment 396268 [details]
patch
Comment 6 Simon Fraser (smfr) 2020-04-13 09:40:07 PDT
Comment on attachment 396268 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=396268&action=review

> LayoutTests/fast/css/is-specificity-3-expected.html:6
> +<div style="color: purple; background-color: blue;">Text</nottarget>

Mixing div and nottarget tags?

> LayoutTests/fast/css/matches-specificity-3-expected.html:6
> +<div style="color: purple; background-color: blue;">Text</nottarget>

Ditto.

> Source/WebCore/css/CSSSelector.cpp:95
> +static unsigned selectorSpecificity(const CSSSelector& firstSimpleSelector)

Would be nice to have a typedef for "specificity" rather than using 'unsigned' everywhere.
Comment 7 Antti Koivisto 2020-04-13 09:58:59 PDT
Created attachment 396298 [details]
patch
Comment 8 Antti Koivisto 2020-04-13 10:01:08 PDT
> Would be nice to have a typedef for "specificity" rather than using
> 'unsigned' everywhere.

Or even wrap it into a class.
Comment 9 EWS 2020-04-13 10:46:00 PDT
Committed r260024: <https://trac.webkit.org/changeset/260024>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 396298 [details].
Comment 10 Radar WebKit Bug Importer 2020-04-13 10:46:24 PDT
<rdar://problem/61724793>
Comment 11 WebKit Commit Bot 2020-04-14 00:05:25 PDT
Re-opened since this is blocked by bug 210480
Comment 12 Antti Koivisto 2020-04-14 03:20:13 PDT
Created attachment 396398 [details]
patch

Reduces scope a bit so compiled selectors still cache the specificity.
Comment 13 EWS 2020-04-14 04:37:45 PDT
Committed r260069: <https://trac.webkit.org/changeset/260069>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 396398 [details].