Bug 210525 - CSS :visited color taken on non-visited link when using CSS variables
Summary: CSS :visited color taken on non-visited link when using CSS variables
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: Safari 13
Hardware: Mac macOS 10.14
: P2 Major
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-04-14 17:38 PDT by Adam_Dierkens
Modified: 2020-09-04 23:43 PDT (History)
7 users (show)

See Also:


Attachments
Patch (4.47 KB, patch)
2020-09-04 11:27 PDT, Tyler Wilcock
no flags Details | Formatted Diff | Diff
Patch (4.46 KB, patch)
2020-09-04 13:37 PDT, Tyler Wilcock
no flags Details | Formatted Diff | Diff
Patch (4.95 KB, patch)
2020-09-04 18:06 PDT, Tyler Wilcock
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam_Dierkens 2020-04-14 17:38:06 PDT
When setting colors for anchor tags using css-vars, the visited color in a css-variable override is taken even if other anchor tags on the same page (that are not using css-vars) don't exhibit the same behavior.

https://jsfiddle.net/rf1njobm/3/

The first link on the page gets its styles from a --link-color-visited variable. An identical anchor tag (with the same href) that doesn't use a variable (only raw colors) doesn't appear to be visited.
Comment 1 Radar WebKit Bug Importer 2020-04-14 18:10:41 PDT
<rdar://problem/61800412>
Comment 2 Tyler Wilcock 2020-09-04 11:27:32 PDT
Created attachment 408005 [details]
Patch
Comment 3 Tyler Wilcock 2020-09-04 13:37:19 PDT
Created attachment 408018 [details]
Patch
Comment 4 Darin Adler 2020-09-04 17:08:22 PDT
Comment on attachment 408018 [details]
Patch

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

> Source/WebCore/style/StyleBuilder.cpp:190
> +    auto originalLinkMatch = m_state.m_linkMatch;

This won’t do the right thing if the "return" below is done after changing m_state.m_linkMatch.

We have a class SetForScope designed for this kind of thing, that could make sure we get that right.
Comment 5 Tyler Wilcock 2020-09-04 18:06:30 PDT
Created attachment 408059 [details]
Patch
Comment 6 Tyler Wilcock 2020-09-04 19:43:01 PDT
TIL of SetForScope, thanks Darin!  I think I've fixed it -- can you take another look?
Comment 7 Darin Adler 2020-09-04 23:20:15 PDT
Comment on attachment 408059 [details]
Patch

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

> Source/WebCore/style/StyleBuilder.cpp:43
>  #include "StylePropertyShorthand.h"
>  
> +#include <wtf/SetForScope.h>

WebKit coding style does not leave a space between these making it two paragraphs. But fine to land like this for now.

> Source/WebCore/style/StyleBuilder.cpp:220
> +            SetForScope<SelectorChecker::LinkMatchMask> scopedLinkMatchMutation(m_state.m_linkMatch, index);

Oh, looks like there is a better way to write it:

    auto scopedLinkMatchMutation = SetForScope(m_state.m_linkMatch, index);

That way we don’t have to write out the type. But fine to land like this for now.
Comment 8 EWS 2020-09-04 23:43:41 PDT
Committed r266656: <https://trac.webkit.org/changeset/266656>

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