Hi,
I threw my display:contents implementation ideas at
mste...@opera.com
and I've summarized it in an intent below.
I have a couple of ongoing projects, so I didn't intend to start this
now. Others are free to pick it up if it's a priority. This is just a
dump.
====
Intent to Implement: display:contents
Contact emails:
ru...@opera.com
Spec:
https://drafts.csswg.org/css-display/#valdef-display-contents
Summary
Implement support for the contents keyword value for the display
property. The contents keyword suppresses generation of layout boxes
for elements which have a computed display of contents. In contrast to
display:none, descendants of elements with display:contents will still
generate layout boxes.
Based on preliminary explorations, it seems we can implement this by
modifying the LayoutTreeBuilder and the LayoutTreeBuilderTraversal to
skip display:contents elements when finding next/previous/parent
LayoutObjects.
Other identified TODOs:
Include <slot> in FlatTreeTraversal.
Store ComputedStyle in rare data for display:contents elements like we
do for display:none elements with getComputedStyle called.
get(Un)CachedPseudoStyles needs to be moved off LayoutObject. For
display:contents, we may still have rendered ::before/::after
elements. An extreme case is a document full of divs with “div {
display: contents } div::before { content: ‘X’ }” which yields a flat
layout tree under body only containing layout boxes for ::before
generated content.
StyleAdjuster needs to consider ComputedStyle for the parent layout
box instead of the inherit (flat-tree) parent for things like
align-self: auto. Gecko does that in their implementation. If you have
a display:flex element and with display:contents descendants, the
closest descendants with layout boxes have their align-self:auto
computed according to the align-items of the display:flex element, not
its inherit parent.
Motivation
The <slot> element introduced by Shadow DOM v1 should be part of the
flat tree and be rendered as display:contents by default. Since we
currently do not support display:contents, we have shipped an
implementation of Shadow DOM v1 which does not include <slot> in the
flat tree which means:
Inheritance through <slot> does not work correctly
You cannot display <slot> elements by setting the display property in
author style
Both points above will cause interop issues with other implementations
when shipped. See next section.
Interoperability and Compatibility Risk
Gecko has shipped display:contents. When Gecko ships Shadow DOM v1,
they will presumable implement <slot> correctly in this regard.
It looks like WebKit (based on looking at commits) so far includes
<slot> in the flat-tree, but implemented the display:contents-ness as
a special case for <slot> without exposing it for author styling, and
without the possibility to override the display value for <slot>.
Need to check Edge/IE.
Ongoing technical constraints
No constraints as such, but an implementation may interfere with 595137
Will this feature be supported on all six Blink platforms (Windows,
Mac, Linux, Chrome OS, Android, and Android WebView)?
Yes.
OWP launch tracking bug
593328 (Add link to an OWP launch tracking bug)
Link to entry on the feature dashboard
Requesting approval to ship?
No.
--
Rune Lillesveen