Skip to content

Commit 1446864

Browse files
CanadaHonkpull[bot]
authored andcommitted
Implement CSS attr() fallback
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
1 parent 9e1de77 commit 1446864

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<style>
3+
#one::after {
4+
content: "Fallback value";
5+
}
6+
7+
#two::after {
8+
content: "Not fallback value";
9+
}
10+
11+
#three::after {
12+
content: "";
13+
}
14+
15+
#four::after {
16+
content: "";
17+
}
18+
19+
#five::after {
20+
content: "";
21+
}
22+
23+
#six::after {
24+
content: "";
25+
}
26+
</style>
27+
28+
<div id="one"></div>
29+
<div id="two"></div>
30+
<div id="three"></div>
31+
<div id="four"></div>
32+
<div id="five"></div>
33+
<div id="six"></div>
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<link rel="help" href="https://drafts.csswg.org/css-values-5/#attr-notation">
3+
<link rel="match" href="attr-notype-fallback-ref.html">
4+
<style>
5+
#one::after {
6+
content: attr(does-not-exist, "Fallback value");
7+
}
8+
9+
#two::after {
10+
content: attr(does-exist, "Fallback value");
11+
}
12+
13+
#three::after {
14+
content: attr(does-not-exist, invalid);
15+
}
16+
17+
#four::after {
18+
content: attr(does-exist, invalid);
19+
}
20+
21+
#five::after {
22+
content: attr(does-exist, "Fallback value");
23+
}
24+
25+
#six::after {
26+
content: attr(does-exist, "Fallback value");
27+
}
28+
</style>
29+
30+
<div id="one"></div>
31+
<div id="two" does-exist="Not fallback value"></div>
32+
<div id="three"></div>
33+
<div id="four" does-exist="Not fallback value"></div>
34+
<div id="five" does-exist=""></div>
35+
<div id="six" does-exist></div>

css/cssom/serialize-values.html

+12-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@
9797
}
9898

9999
function attr() {
100-
var values = ['attr(foo-bar)', 'attr(foo_bar)'];
100+
var values = ['attr(foo-bar)', 'attr(foo_bar)',
101+
{actual: "attr(|bar)", serialized: "attr(bar)"},
102+
{actual: "attr( |bar )", serialized: "attr(bar)"}];
103+
return iterable(values);
104+
}
105+
106+
function attr_fallback() {
107+
var values = ['attr(foo-bar, "fallback")', 'attr(foo_bar, "fallback")',
108+
{actual: 'attr(|bar, "fallback")', serialized: 'attr(bar, "fallback")'},
109+
{actual: 'attr(foo, "")', serialized: 'attr(foo)'},
110+
{actual: 'attr( |foo , "" )', serialized: 'attr(foo)'}];
101111
return iterable(values);
102112
}
103113

@@ -377,7 +387,7 @@
377387
'initial': 'black', //FIXME depends on user agent
378388
}],
379389
['content', {
380-
'values': ['normal', 'none', string, uri, counter, attr, 'inherit'], //FIXME
390+
'values': ['normal', 'none', string, uri, counter, attr, attr_fallback, 'inherit'], //FIXME
381391
'initial': 'normal',
382392
}],
383393
//counter-increment

0 commit comments

Comments
 (0)