Skip to content

Commit

Permalink
[line-clamp] Always clamp immediately after a line box
Browse files Browse the repository at this point in the history
In our initial implementation of `line-clamp: auto`, we allowed
clamping after lineless boxes, in order to better match the behavior
of `line-clamp` as it follows from the spec's `continue: discard`
model, even though our implementation uses a different model which is
not yet in the specification (see
w3c/csswg-drafts#7708).

However, in hallway conversations in TPAC 2024, we agreed that it
would be better for this model to instead only allow clamping
immediately after a line. If the first line does not fit, we calmp at
the first line even if that overflows the clamp height. If there are
no lines, we do not clamp. This patch implements this.

Additionally, a previous patch (https://crrev.com/c/5868971) had
increased the memory size of `LineClampData` from 8 to 20 bytes,
causing a memory regression. This patch shrinks it to 12 bytes, since
`LineClampData` no longer needs to keep track of how many block boxes
there are between the last line and the clmap point, and now OOFs
after the clamped line behave the same when clamping by a number of
lines or by a height, so there is no need for a flag to distinguish
these behaviors. This patch also adds a size assertion for
`LineClampData`.

This patch also changes or removes some WPT tests that were written
assuming the previous behavior.

Bug: 40336192, 368114054
Change-Id: I8c8afebb5dc566de92112cee2fcf24a2e60b42c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5904459
Reviewed-by: Ian Kilpatrick <[email protected]>
Commit-Queue: Andreu Botella <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1364495}
  • Loading branch information
andreubotella authored and chromium-wpt-export-bot committed Oct 4, 2024
1 parent 2bbd336 commit 1563c1e
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<link rel="author" title="Andreu Botella" href="mailto:[email protected]">
<link rel="help" href="https://drafts.csswg.org/css-overflow-4/#line-clamp">
<link rel="match" href="reference/line-clamp-auto-011-ref.html">
<meta name="assert" content="When line-clamp: auto is used with max-height: 0, it should not show any lines and its content box's intrinsic size should be zero">
<meta name="assert" content="When line-clamp: auto is used with max-height: 0, it should still show the first line">
<style>
.clamp {
line-clamp: auto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Overflow: abspos exactly at the clamp point is visible</title>
<title>CSS Overflow: abspos exactly at the clamp point is hidden</title>
<link rel="author" title="Andreu Botella" href="mailto:[email protected]">
<link rel="help" href="https://drafts.csswg.org/css-overflow-4/#line-clamp">
<link rel="match" href="reference/line-clamp-auto-025-ref.html">
<meta name="assert" content="The chosen clamp point with line-clamp: auto is the last one where the box size doesn't overflow. Since non-inline abspos have a clamp point after them, and they don't take up any space in the container, an abspos right at the boundary should be visible.">
<link rel="match" href="reference/webkit-line-clamp-005-ref.html">
<meta name="assert" content="The chosen clamp point with line-clamp: auto is at the last line where the box size doesn't overflow. An immediately following box, even if it's an abspos that takes up no block size, should still be hidden.">
<style>
.clamp {
line-clamp: auto;
max-height: 4lh;
font: 16px / 32px serif;
padding: 0 4px;
background-color: yellow;
}
.inner {
Expand Down
40 changes: 0 additions & 40 deletions css/css-overflow/line-clamp/line-clamp-auto-026.tentative.html

This file was deleted.

50 changes: 0 additions & 50 deletions css/css-overflow/line-clamp/line-clamp-auto-032.tentative.html

This file was deleted.

11 changes: 5 additions & 6 deletions css/css-overflow/line-clamp/line-clamp-auto-034.tentative.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Overflow: `line-clamp: auto` clamp between IFCs</title>
<title>CSS Overflow: `line-clamp: auto` clamp height after IFC</title>
<link rel="author" title="Andreu Botella" href="mailto:[email protected]">
<link rel="help" href="https://drafts.csswg.org/css-overflow-4/#line-clamp">
<link rel="match" href="reference/line-clamp-auto-034-ref.html">
<meta name="assert" content="With `line-clamp: auto`, there can be a clamp point between two IFCs. In that case, no line will have an ellipsis.">
<link rel="match" href="reference/webkit-line-clamp-005-ref.html">
<meta name="assert" content="With `line-clamp: auto`, if the clamp height is after an IFC, the clamp point will be set after the last line before that.">
<style>
.clamp {
line-clamp: auto;
Expand All @@ -28,6 +28,5 @@
Line 2
Line 3
Line 4
<div class="ifc">Line 5
Line 6</div><div class="ifc red">Line 7
Line 8</div>Line 9</div>
<div class="ifc red">Line 5
Line 6</div>Line 7</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>CSS Overflow: `line-clamp: auto` with non-zero max-height that doesn't fit any content</title>
<link rel="author" title="Andreu Botella" href="mailto:[email protected]">
<link rel="help" href="https://drafts.csswg.org/css-overflow-4/#line-clamp">
<link rel="match" href="reference/line-clamp-auto-011-ref.html">
<link rel="match" href="reference/line-clamp-auto-037-ref.html">
<meta name="assert" content="When line-clamp: auto is used with a max-height that isn't enough for any contained boxes or line boxes, then it should not show any content and its content box's intrinsic size should be zero">
<style>
.clamp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
<title>CSS Reference</title>
<style>
.clamp {
height: 0;
font: 16px / 32px serif;
white-space: pre;
background-color: yellow;
border: 1px solid black;
padding: 4px;
}
</style>
<div class="clamp"></div>
<div class="clamp">Line 1…</div>
<p>Following content.</p>
27 changes: 0 additions & 27 deletions css/css-overflow/line-clamp/reference/line-clamp-auto-025-ref.html

This file was deleted.

32 changes: 0 additions & 32 deletions css/css-overflow/line-clamp/reference/line-clamp-auto-026-ref.html

This file was deleted.

34 changes: 0 additions & 34 deletions css/css-overflow/line-clamp/reference/line-clamp-auto-032-ref.html

This file was deleted.

23 changes: 0 additions & 23 deletions css/css-overflow/line-clamp/reference/line-clamp-auto-034-ref.html

This file was deleted.

15 changes: 15 additions & 0 deletions css/css-overflow/line-clamp/reference/line-clamp-auto-037-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Reference</title>
<style>
.clamp {
height: 0.5lh;
font: 16px / 32px serif;
white-space: pre;
background-color: yellow;
border: 1px solid black;
padding: 4px;
}
</style>
<div class="clamp">Line 1…</div>
<p>Following content.</p>

0 comments on commit 1563c1e

Please sign in to comment.