quirks icon indicating copy to clipboard operation
quirks copied to clipboard

Simplifying the hover and active quirks?

Open emilio opened this issue 2 years ago • 2 comments

What is the issue with the Quirks Mode Standard?

https://quirks.spec.whatwg.org/#the-active-and-hover-quirk has a list of conditions that doesn't keep up with new CSS features.

It seems implementations do subtly different things that end up in subtle bugs like https://bugzilla.mozilla.org/show_bug.cgi?id=1856285:

  • Gecko: https://searchfox.org/mozilla-central/rev/47a0a01e1f7ad0451c6ba6c790d5c6855df512c1/servo/components/selectors/matching.rs#624
  • Blink: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/css/selector_checker.cc;l=185;drc=e7a3efac5cc6bb943f7943fe3ef0569b8aa77d7d
  • WebKit: https://searchfox.org/wubkat/rev/fe11bcadadbf8b7ad5f95d337b6842b4b42982ec/Source/WebCore/css/SelectorChecker.cpp#624

I think Blink's behavior (which if I understand correctly is "only apply the quirk if the only thing in the selector is :hover or :active and it's not nested) is simpler, and I think we should change the spec to match that, if my understanding is correct.

@lilles / @andruud: Could you confirm my read of Blink's source is correct? @annevk: Would WebKit be fine with that change? If so I'd be happy to send a PR.

cc @whatwg/css, I assume making stuff less quirky is generally good if we can get away with it...

emilio avatar Mar 26 '24 17:03 emilio

Tests would be good to verify that's indeed Chromium's behavior. I think WebKit would be okay with attempting to align with that, yes.

annevk avatar Mar 27 '24 09:03 annevk

Here's a test-case. One quirk here is that at least Blink and Gecko parse *:hover and :hover to exactly the same thing. So ignoring that * special-case, yes, I think the chromium behavior is as I described above (for simple selectors at least). Not sure what the is_sub_selector in chromium conveys, it seems a mix of "being used for pseudo-elements" and "being in a nested pseudo-class / slotted / etc thing".

<!doctype html>
<body>
<script>
  let selectors = [
    `*:hover`,
    `:hover`,
    `span:hover`,
    `:is(a, span):hover`,
    `:is(span):hover`,
    `:not(div):hover`,
    `[data-attr]:hover`,
    `:hover:nth-child(1)`,
    `:hover:first-child`,
  ];

  for (let selector of selectors) {
    let frame = document.createElement("iframe");
    frame.src = `data:text/html,` + encodeURIComponent(`
      <style>${selector} { background-color: rgba(0, 0, 0, .2) }</style>
      <div id=root>
        <p><strong>${selector}</strong>
        <p><a data-attr href="#">Link</a>
        <p><span data-attr>Non-link</span>
      </div>
    `);
    document.body.appendChild(frame);
  }
</script>

emilio avatar Mar 27 '24 10:03 emilio