Skip to content

[css-display][css-flexbox][css-grid] Interaction of 'display: contents' and 'run of text' #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Loirooriol opened this issue Apr 23, 2017 · 14 comments

Comments

@Loirooriol
Copy link
Contributor

Various specifications use the term 'run of text'. For example, CSS Flexbox and CSS Grid:

each contiguous run of text that is directly contained inside a flex container is wrapped in an anonymous flex item.

Each contiguous run of text that is directly contained inside a grid container is wrapped in an anonymous grid item.

But as far as I know, this term is not defined anywhere. So I don't know how it should interact with display: contents. For example, https://jsfiddle.net/p63c5uyt/

div {
  display: flex;
  flex-direction: column;
}
span {
  display: contents;
}
<div>Foo<span>Bar</span></div>

Should Bar appear next to or below Foo?

Both Firefox and Chrome consider that display: contents makes both Foo and Bar to be in the same run of text. This is not obvious to me.

Tab wants (#1118 (comment))

to define "text" as an object in the element tree that has properties (only set via inheritance), and which generates "text" in the box tree accordingly

not sure if this has any impact, given that Foo and Bar are different text nodes in the DOM.

@MatsPalmgren
Copy link

The CSS Display spec says:

For the purposes of box generation and layout, the element must be treated as if it had been replaced in the element tree by its contents [...]

which I think makes it's clear that Firefox and Chrome is implementing the intent of the spec for the given example (there's only one flex item).

@Loirooriol
Copy link
Contributor Author

OK, but since I can't find any definition of "run of text", I was not sure if it was a box-generation-and-layout thingie, or a element-tree thingie.

@FremyCompany
Copy link
Contributor

Hum that's weird. They would occupy in the same grid/flex area but have two different formattings? This seems a bit contradictory but I have no strong opinion. https://jsfiddle.net/p63c5uyt/1/

@Loirooriol
Copy link
Contributor Author

Yes, it also seems a bit strange to me that text nodes with different styles become a single run of text. I think display: contents would be more sane if text directly contained in a display: contents element was wrapped in an anonymous inline box. In that case they would become different flex items.

@bradkemper
Copy link
Contributor

Doesn't that defeat the purpose of it? It isn't supposed to generate any boxes. I don't see how it could take any styling of its own, once it was display:contents, if it didn't have its own box. Even font-size could affect layout. If it was just text, it wouldn't have its own color either.

I don't think this value is described very completely.

@bradkemper
Copy link
Contributor

I mean, it is supposed to react to some things, like 'flex' as if it was a contiguous part of its parent and taking on its parent's non-inherited property values, but react to other properties as though it still was its own element.

@Loirooriol
Copy link
Contributor Author

@bradkemper Yes, currently display: contents is not well defined, see #1118 and #1249. I think it might have worked if inheritance skipped elements with display: contents, but it doesn't. So there must be some thing which inherits the styles. Tab proposes introducing text boxes that inherit from the parent element, which presumably require rewriting the inline layout algorithm to take them into account. Then, I wonder if 'run of text' would mean 'run of text boxes' or 'run of text nodes in a text box'.

@SelenIT
Copy link
Collaborator

SelenIT commented Apr 26, 2017

I see no problem with text of different formatting occupiying the same flex/grid area. Single runs of text with different formatting aren't new in CSS, they occur quite often because of the font fallbacks. Can we generalize the rules of this behavior and reuse it for our case?

Making element with display:content the separate flex/grid item seems much more problematic to me. I consider display:contents as a way to separate the visual hierarchy of boxes from the DOM hierarchy, with the ability of effectively converting the children of the element to the siblings of its siblings as one of the biggest advantage. So if the siblings of the element with display:contents end up in the inline formatting context, I strictly prefer to see the text content of this element in the same inline formatting context, and creating the separate flex/grid item for it — as if it was the inline-level element box — feels like it's against the purpose of display:contents.

So my suggestion is to treat 'run of text' as 'run of text nodes in a text box', or even just as 'run of differently formatted text fragments in a text box' — in the similar way as text rendered with different fonts of the font stack or bidirectional text is treated.

@Loirooriol
Copy link
Contributor Author

@SelenIT From your description it seems you meant you want a run of text to be a run of multiple text box instead of a single text box, right? In the example from the first comment, Foo and Bar will need to be in different text boxes, because that's the mechanism which allows different styles, or that's what I understood.

I'm not interested in fonts so I don't know about font fallbacks. But I'm not convinced it's exactly the same, even if some character is not supported by the font and a fallback is used, its text box will still have the same specified font. display: contents allows adjacent text boxes to have different specified styles. So I believe the former is an intra text box phenomenon, and the latter is an inter one.

Anyways, I don't have a strong opinion, I just think some spec should clarify the meaning of 'run of text' when mixed with display:contents. Possibly this will need the 'text box' concept or whatever mechanism used to style text in display:contents.

@bradkemper
Copy link
Contributor

Even though I find inheriting from a box that has been removed a bit surprising, I could see it being useful. I agree with @Loirooriol. Foo and Bar in the example should be in the same run of text, and children should become siblings.

@SelenIT
Copy link
Collaborator

SelenIT commented Apr 27, 2017

@Loirooriol I can agree with any interpretation that would not require 'Foo' and 'Bar' in the example becoming separate flex items :). I believe that the ability to place content of different elements in the same 'run of text' (whatever that means) is one of the key advantages of display:contents (comparing to old values like display:inline), and I strongly disagree to remove it. The contents of the element with display:contents may be implemented as a separate text box, but this text box should never be 'blockified' etc. by itself. In my opinion, if the content of the element with display:contents ends up being a separate flex/grid item, it directly contradicts the requirement that 'the element creates no boxes'.

I agree with @MatsPalmgren that the current implementations of Gecko and Blink match the intent of the spec. I believe that the spec should reflect this behavior and this behavior should not be changed.

As I understand the comment by @bzbarsky, we already have the concept of styleable 'text', separate from 'anonymous inline box', in reality. May be we should specify it?

even if some character is not supported by the font and a fallback is used, its text box will still have the same specified font. display: contents allows adjacent text boxes to have different specified styles.

I didn't suggest it's exactly the same, but I see many similarities between these situations from the rendering perspective. Different characters in the same run of text already can have different actual values of line-height which affects the layout, and browsers are able to handle this. Maybe introducing something like 'text box' concept would be useful for both cases?

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Apr 28, 2017
…combine. r=xidorn

Instead of the parent style context itself. This also fixes bug 1360530.

It's not clear what should we use in this case, it depends on the resolution in
[1] and [2].

While those get resolved, this is probably ok, and gets rid of the only
styleContext->GetParent() outside nsRuleNode.

[1]: w3c/csswg-drafts#1249
[2]: w3c/csswg-drafts#1281

MozReview-Commit-ID: LSOgFCwQi1W
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
JerryShih pushed a commit to JerryShih/gecko-dev that referenced this issue May 2, 2017
…combine. r=xidorn

Instead of the parent style context itself. This also fixes bug 1360530.

It's not clear what should we use in this case, it depends on the resolution in
[1] and [2].

While those get resolved, this is probably ok, and gets rid of the only
styleContext->GetParent() outside nsRuleNode.

[1]: w3c/csswg-drafts#1249
[2]: w3c/csswg-drafts#1281

MozReview-Commit-ID: LSOgFCwQi1W
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
@fantasai fantasai added the css-display-3 Current Work label May 2, 2017
jryans pushed a commit to jryans/gecko-dev that referenced this issue May 3, 2017
…combine. r=xidorn

Instead of the parent style context itself. This also fixes bug 1360530.

It's not clear what should we use in this case, it depends on the resolution in
[1] and [2].

While those get resolved, this is probably ok, and gets rid of the only
styleContext->GetParent() outside nsRuleNode.

[1]: w3c/csswg-drafts#1249
[2]: w3c/csswg-drafts#1281

MozReview-Commit-ID: LSOgFCwQi1W
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
@tabatkins
Copy link
Member

I agree in general: "Foo" and "Bar" should be in a single flex item, because there's no inline box to get blockified into a flex item in the first place! When #1118 is fixed, the layout algos will have a properly defined concept of "text" which we'll fix up flexbox and others to reference (probably we'll define the term "text run", meaning a maximal contiguous sequence of sibling texts in the box tree, and use that in most places).

@tabatkins
Copy link
Member

Okay, we've proposed a diff in #1118 (comment) that resolves this issue. Let us know if there's something not accounted for.

(It supports the "Foo and Bar wind up in a single flex item" interpretation.)

@tabatkins
Copy link
Member

I've committed the diff, so closing this issue as solved.

gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 1, 2019
…combine. r=xidorn

Instead of the parent style context itself. This also fixes bug 1360530.

It's not clear what should we use in this case, it depends on the resolution in
[1] and [2].

While those get resolved, this is probably ok, and gets rid of the only
styleContext->GetParent() outside nsRuleNode.

[1]: w3c/csswg-drafts#1249
[2]: w3c/csswg-drafts#1281

MozReview-Commit-ID: LSOgFCwQi1W
Signed-off-by: Emilio Cobos Álvarez <emiliocrisal.io>

UltraBlame original commit: 7ac1b8bcb88f5ce4f2644d195af6608d304daa6d
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 1, 2019
…combine. r=xidorn

Instead of the parent style context itself. This also fixes bug 1360530.

It's not clear what should we use in this case, it depends on the resolution in
[1] and [2].

While those get resolved, this is probably ok, and gets rid of the only
styleContext->GetParent() outside nsRuleNode.

[1]: w3c/csswg-drafts#1249
[2]: w3c/csswg-drafts#1281

MozReview-Commit-ID: LSOgFCwQi1W
Signed-off-by: Emilio Cobos Álvarez <emiliocrisal.io>

UltraBlame original commit: 7ac1b8bcb88f5ce4f2644d195af6608d304daa6d
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 1, 2019
…combine. r=xidorn

Instead of the parent style context itself. This also fixes bug 1360530.

It's not clear what should we use in this case, it depends on the resolution in
[1] and [2].

While those get resolved, this is probably ok, and gets rid of the only
styleContext->GetParent() outside nsRuleNode.

[1]: w3c/csswg-drafts#1249
[2]: w3c/csswg-drafts#1281

MozReview-Commit-ID: LSOgFCwQi1W
Signed-off-by: Emilio Cobos Álvarez <emiliocrisal.io>

UltraBlame original commit: 7ac1b8bcb88f5ce4f2644d195af6608d304daa6d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants