implement revert keyword
Categories
(Core :: CSS Parsing and Computation, enhancement, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox67 | --- | fixed |
People
(Reporter: heycam, Assigned: emilio)
References
(Blocks 2 open bugs, )
Details
(Keywords: dev-doc-complete, parity-safari)
Attachments
(4 files, 1 obsolete file)
Updated•10 years ago
|
Comment 1•9 years ago
|
||
| Reporter | ||
Updated•9 years ago
|
Comment 4•9 years ago
|
||
Comment 5•8 years ago
|
||
Comment 6•8 years ago
|
||
Updated•7 years ago
|
Comment 7•7 years ago
|
||
Comment 8•7 years ago
|
||
| Assignee | ||
Comment 9•7 years ago
|
||
| Assignee | ||
Comment 10•7 years ago
|
||
| Assignee | ||
Comment 11•7 years ago
|
||
| Assignee | ||
Comment 12•7 years ago
|
||
Comment 13•7 years ago
|
||
| Assignee | ||
Comment 14•7 years ago
|
||
| Reporter | ||
Updated•7 years ago
|
Comment 15•6 years ago
|
||
Comment 16•6 years ago
|
||
Comment 17•6 years ago
|
||
Comment 18•6 years ago
|
||
revert would be particularly useful for WebExtensions that use browser.tabs.insertCSS and need to be defensive of element styling. I do hope revert is added.
| Assignee | ||
Comment 19•6 years ago
|
||
I just realized I did a bunch of refactoring over bug 1491620 and co. to implement this and I never looked it again.
This is a draft of how it should look. I don't know why this approach wouldn't work. Probably just a matter of writing tests and filling it the patch, but gotta have lunch first.
| Assignee | ||
Updated•6 years ago
|
| Assignee | ||
Updated•6 years ago
|
| Assignee | ||
Comment 20•6 years ago
|
||
The only fishy bit is the animation stuff. In particular, there are two places
where we just mint the revert behavior:
-
When serializing web-animations keyframes (the custom properties stuff in
declaration_block.rs). That codepath is already not sound and I wanted to
get rid of it in bug 1501530, but what do I know. -
When getting an animation value from a property declaration. At that point
we no longer have the CSS rules that apply to the element to compute the
right revert value handy. It'd also use the wrong style anyway, I think,
given the way StyleBuilder::for_animation works.We could probably get them out of somewhere, but it seems like a whole lot
of code reinventing the wheel which is probably not useful, and that Blink
and WebKit just cannot implement either since they don't have a rule tree,
so it just doesn't seem worth the churn.
The custom properties code looks a bit different in order to minimize hash
lookups in the common case. FWIW, revert for custom properties doesn't seem
very useful either, but oh well.
| Assignee | ||
Comment 21•6 years ago
|
||
The way the copy-on-write stuff works, and the way that we have to apply
properties from most specific to less specific guarantees that always that we're
going to inherit an inherited property, or reset a reset property, we have
already the right value on the style.
Revert relies on that, so there doesn't seem to be a reason to not use that fact
more often and skip useless work earlier.
Font-size is still special of course... I think I have a way to move the
specialness outside of the style, but piece by piece.
| Assignee | ||
Comment 22•6 years ago
|
||
https://treeherder.mozilla.org/#/jobs?repo=try&revision=18aad3aca9bdb07765a2de8c40463869dd01e171 for the first patch (the failing devtools test is updated already).
https://treeherder.mozilla.org/#/jobs?repo=try&revision=d4a268597f9dbc14e8c930c7aa0382352f8a0c1d for the second, which I just pushed but that should be green, if I didn't mess up the font-size specialness.
Comment 23•6 years ago
|
||
Comment 24•6 years ago
|
||
Comment 25•6 years ago
|
||
Comment 26•6 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/1ae26ce1cf09
https://hg.mozilla.org/mozilla-central/rev/0d33ffb859fa
Comment 27•6 years ago
|
||
| bugherder | ||
Comment 30•6 years ago
|
||
Comment 31•6 years ago
|
||
Note to MDN writers:
revert keyword has been give its own page, added to the all page, and mentioned in the Fx 67 rel notes:
https://developer.mozilla.org/en-US/docs/Web/CSS/revert
https://developer.mozilla.org/en-US/docs/Web/CSS/all
https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/67#CSS
On the all page, the BCD says it isn't supported, so that needs to be updated.
I also have a sinking feeling that we ought to add this to the list of global property values that appears on EVERY CSS property page ;-|
Comment 32•6 years ago
|
||
BCD has been updated by someone in the last few days. I went in and made some changes to the revert article to be more detailed and to ensure that terms were being defined usefully, and I added a glossary entry for the term "style origin"
And yes, this keyword needs to be added to every page that mentions things like unset and such. So yeah. Ugh.
Chris, how do we proceed with that? It should be done relatively soon probably, but it's not realistic to expect it for the 67 sprint we're doing now.
Comment 33•6 years ago
|
||
(In reply to Eric Shepherd [:sheppy] from comment #32)
And yes, this keyword needs to be added to every page that mentions things like
unsetand such. So yeah. Ugh.
I don't think enumerating these CSS-wide values for every
property adds much value. We could at least shorten
it down to something like:
font-size:<defaulting-keyword>
(which will save time the next time we add a new value ;-))
Comment 34•6 years ago
|
||
:mats - Well, I think they should be listed, but we need to set things up so it happens automatically where appropriate instead of having to manually update the content. Heck, it might already do that. I'm not sure. :)
Comment 35•6 years ago
|
||
(In reply to Eric Shepherd [:sheppy] from comment #34)
:mats - Well, I think they should be listed, but we need to set things up so it happens automatically where appropriate instead of having to manually update the content. Heck, it might already do that. I'm not sure. :)
I don't think it does. This is one of those "why oh why didn't we use a macro" situations.
Maybe for now you could create a macro that adds the global property values in, then in the next sprint we could add it to the top 100 properties according to the docs maintenance sheet? This gives us about 75-80% of property page views, I'd estimate.
then we can fix the others as we get to them.
Comment 36•6 years ago
|
||
I'm confused. You say this was implemented but the example on MDN page doesn't work (tested on FF dev and Nightly). I mean I assume the text in the .widget should be black and thin.
https://developer.mozilla.org/en-US/docs/Web/CSS/revert
From devtools I can see that revert does seem to do something, but it seems that the effects are not inherited...
Comment 37•6 years ago
|
||
The inheritance problem mentioned above. Devtools shows that all: revert overridden properties from section but only on .widget and not on .widget p.
The screen also shows that text in .widget is still blue and bold. Note that using .widget p {all:revert} doesn't help (styles are still applied).
| Assignee | ||
Comment 38•6 years ago
|
||
I think the example (or your expectation of how the example should render) is just wrong. WebKit renders it the same, and it also supports revert.
revert is working as intended in that example (reverting to the previous level of the cascade, preventing other declarations from applying).
Turns out that there's no other declaration for color, and color is an inherited property, so it inherits as usual. I think that example is pretty poor, because it doesn't use the feature at all in any meaningful way. I think what you expected is what you'd get with all: initial.
Comment 39•6 years ago
|
||
Quote from: https://www.w3.org/TR/css-cascade-4/#valdef-all-revert
"author origin
Rolls back the cascaded value to the user level, so that the specified value is calculated as if no author-level rules were specified for this property on this element."
When adding any CSS to a webpage I'm in the author origin. Hence revert should revert all declarations from author origin (and revert them to user origin).
In user origin color is black. In author origin color is blue. Reverting to user origin should make the color black again.
So I think the MDN example is correct. The implementation is wrong.
| Assignee | ||
Comment 40•6 years ago
|
||
That's not how it works?
Rolls back the cascaded value to the user level, so that the specified value is calculated as if no author-level rules were specified for this property on this element.
This is exactly right, so it's 100% as if no author rules existed.
In user origin color is black. In author origin color is blue. Reverting to user origin should make the color black again.
This is wrong however, there's no user origin declaration (unless you have a user stylesheet), so the value is inherited.
Comment 41•6 years ago
|
||
This is wrong however, there's no user origin declaration (unless you have a user stylesheet), so the value is inherited.
I have just tried playing around with revert, including applying a user stylesheet to Firefox and then trying to rollback the styling it applies using revert. But even that doesn't seem to work in the way I'd expect.
Can you give me an idea of an example that would show an effective use of revert, so I can try to correct the reference page to show something more useful? Thanks!
| Assignee | ||
Comment 42•6 years ago
|
||
Revert is pretty similar to unset, except it applies previous origins of the cascade. You can see it in action everywhere there's UA rules.
For example, the following should apply the default margins for an <h1> element:
<!doctype html>
<style>
h1 {
margin: 0;
}
</style>
<h1 style="margin: revert">Should have margins</h1>
It's more useful with display or such, since revert makes it go back to the default display value of the element accounting for user / UA sheets, unlike unset / initial. So <div style="display: revert"> is a block, while with initial / unset it'd be an inline.
Not sure about more practical examples in the web-components space. Maybe Mats or Cameron know?
Comment 43•6 years ago
|
||
(In reply to Emilio Cobos Álvarez (:emilio) from comment #42)
Revert is pretty similar to
unset, except it applies previous origins of the cascade. You can see it in action everywhere there's UA rules.For example, the following should apply the default margins for an
<h1>element:<!doctype html> <style> h1 { margin: 0; } </style> <h1 style="margin: revert">Should have margins</h1>It's more useful with
displayor such, sincerevertmakes it go back to the default display value of the element accounting for user / UA sheets, unlikeunset/initial. So<div style="display: revert">is a block, while withinitial/unsetit'd be an inline.Not sure about more practical examples in the web-components space. Maybe Mats or Cameron know?
OK, thanks, I get this now.
For the moment, I've just added something based on your example here to the revert page, so that it isn't wrong. I had a bit of a play with using it in web components, but ran out of time.
Comment 44•6 years ago
|
||
(In reply to Emilio Cobos Álvarez (:emilio) from comment #40)
That's not how it works?
Rolls back the cascaded value to the user level, so that the specified value is calculated as if no author-level rules were specified for this property on this element.
This is exactly right, so it's 100% as if no author rules existed.
No. That is not how it works. color: blue in the example is in the author origin and it is not reverted.
In user origin color is black. In author origin color is blue. Reverting to user origin should make the color black again.
This is wrong however, there's no user origin declaration (unless you have a user stylesheet), so the value is inherited.
Inherited from what? When I revert It can only be inherited from user origin and from browser origin. Neither of them define color: blue.
Another question -- why is color declaration striked out if it still applies in the .widget?
Please have another look the screen from comment #37. I really think there is something wrong.
The standard was changes recently. Maybe the implementation reflect previous version of the upcoming standard? See:
https://www.w3.org/TR/css-cascade-4/#valdef-all-revert
(In reply to Emilio Cobos Álvarez (:emilio) from comment #42)
Revert is pretty similar to
unset, except it applies previous origins of the cascade. You can see it in action everywhere there's UA rules.For example, the following should apply the default margins for an
<h1>element:<!doctype html> <style> h1 { margin: 0; } </style> <h1 style="margin: revert">Should have margins</h1>
Isin't <style> and style="..." both in the same origin? Seems to me that they are both in the author origin. Same as two declarations in <style> would be. So in terms of origin there is no difference in the example from MDN and to your example.
Note that the updated spec says:
Rolls back the cascaded value to the user level, so that the specified value is calculated as if no author-level rules were specified for this property on this element.
| Assignee | ||
Comment 45•6 years ago
|
||
No. That is not how it works. color: blue in the example is in the author origin and it is not reverted.
Because color: blue isn't a declaration applying to the .widget, it's inherited from the parent (section). If you change the selector in that test-case to be .widget instead of section, then it wouldn't become blue.
Another question -- why is color declaration striked out if it still applies in the .widget?
That's probably a devtools issue of not understanding the revert keyword well enough. Probably happens with unset as well.
Isin't <style> and style="..." both in the same origin? Seems to me that they are both in the author origin. Same as two declarations in <style> would be. So in terms of origin there is no difference in the example from MDN and to your example.
Right, the difference is that margin is not inherited, it applies to the h1 directly, and thus gets reversed. In the old MDN example, the color was inherited from the parent <section>.
| Assignee | ||
Comment 46•6 years ago
|
||
I filed bug 1552949 to consider making devtools understand css-wide-keywords so that declarations don't appear crossed-out.
Comment 47•6 years ago
|
||
(In reply to Emilio Cobos Álvarez (:emilio) from comment #45)
No. That is not how it works. color: blue in the example is in the author origin and it is not reverted.
Because
color: blueisn't a declaration applying to the.widget, it's inherited from the parent (section). If you change the selector in that test-case to be.widgetinstead ofsection, then it wouldn't become blue.Another question -- why is color declaration striked out if it still applies in the .widget?
That's probably a devtools issue of not understanding the
revertkeyword well enough. Probably happens withunsetas well.Isin't <style> and style="..." both in the same origin? Seems to me that they are both in the author origin. Same as two declarations in <style> would be. So in terms of origin there is no difference in the example from MDN and to your example.
Right, the difference is that
marginis not inherited, it applies to theh1directly, and thus gets reversed. In the old MDN example, the color was inherited from the parent<section>.
I think I understand what you are trying to say... But aren't you describing unset? I can't think of an example were unset and revert would behave differently. Cold you provide some example? From what I understand on author level unset and revert should behave differently. Or am I reading it wrong?
Here are some things I tried:
https://codepen.io/eccenux/pen/joGaMp
| Assignee | ||
Comment 48•6 years ago
|
||
<div style="display: revert"> computes to block. <div style="display: unset"> computes to inline.
Comment 49•6 years ago
|
||
OK. Sorry about that. It does seem fine.
Added more examples on MDN and I hope I clarified the description as well.
https://developer.mozilla.org/en-US/docs/Web/CSS/revert
Originally I just didn't got the part about revert being applied only to the currently selected element. So it's just a value and not some magic directive that resets everything. So not really for widgets (as some seemed to hope here).
| Assignee | ||
Comment 50•6 years ago
|
||
Just went through the examples on MDN and they look great, thanks! :)
Description
•