Skip to content

Commit

Permalink
Implement CSS attr() fallback
Browse files Browse the repository at this point in the history
Implemented support for fallback values in CSS attr():
`attr(<attr-name>, <attr-fallback>)`

Full syntax supported as of this rev:
`[namespace? `|`]? ident [`,` fallback]?`

Spec: https://drafts.csswg.org/css-values-5/#attr-notation

Also added a new WPT reftest for attr fallback without a type,
and some new attr serialization WPTs (namespace and fallback).

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

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1448248
gecko-commit: a14395d9ad06c9f7462430341d4c7874020a58d0
gecko-reviewers: emilio
  • Loading branch information
CanadaHonk authored and pull[bot] committed Oct 10, 2023
1 parent 9e1de77 commit 1446864
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
33 changes: 33 additions & 0 deletions css/css-values/attr-notype-fallback-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<style>
#one::after {
content: "Fallback value";
}

#two::after {
content: "Not fallback value";
}

#three::after {
content: "";
}

#four::after {
content: "";
}

#five::after {
content: "";
}

#six::after {
content: "";
}
</style>

<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<div id="four"></div>
<div id="five"></div>
<div id="six"></div>
35 changes: 35 additions & 0 deletions css/css-values/attr-notype-fallback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-values-5/#attr-notation">
<link rel="match" href="attr-notype-fallback-ref.html">
<style>
#one::after {
content: attr(does-not-exist, "Fallback value");
}

#two::after {
content: attr(does-exist, "Fallback value");
}

#three::after {
content: attr(does-not-exist, invalid);
}

#four::after {
content: attr(does-exist, invalid);
}

#five::after {
content: attr(does-exist, "Fallback value");
}

#six::after {
content: attr(does-exist, "Fallback value");
}
</style>

<div id="one"></div>
<div id="two" does-exist="Not fallback value"></div>
<div id="three"></div>
<div id="four" does-exist="Not fallback value"></div>
<div id="five" does-exist=""></div>
<div id="six" does-exist></div>
14 changes: 12 additions & 2 deletions css/cssom/serialize-values.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@
}

function attr() {
var values = ['attr(foo-bar)', 'attr(foo_bar)'];
var values = ['attr(foo-bar)', 'attr(foo_bar)',
{actual: "attr(|bar)", serialized: "attr(bar)"},
{actual: "attr( |bar )", serialized: "attr(bar)"}];
return iterable(values);
}

function attr_fallback() {
var values = ['attr(foo-bar, "fallback")', 'attr(foo_bar, "fallback")',
{actual: 'attr(|bar, "fallback")', serialized: 'attr(bar, "fallback")'},
{actual: 'attr(foo, "")', serialized: 'attr(foo)'},
{actual: 'attr( |foo , "" )', serialized: 'attr(foo)'}];
return iterable(values);
}

Expand Down Expand Up @@ -377,7 +387,7 @@
'initial': 'black', //FIXME depends on user agent
}],
['content', {
'values': ['normal', 'none', string, uri, counter, attr, 'inherit'], //FIXME
'values': ['normal', 'none', string, uri, counter, attr, attr_fallback, 'inherit'], //FIXME
'initial': 'normal',
}],
//counter-increment
Expand Down

0 comments on commit 1446864

Please sign in to comment.