Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[IFC][Integration][Line clamp] LineClamp.currentLineCount should be…
… propagated to the parent layoutState.

https://bugs.webkit.org/show_bug.cgi?id=255487

Reviewed by Alan Baradlay.

Since multiple children share the same parent context for line clamp,
`LineClamp.currentLineCount` set to the individual child should be propagated to
their parent layoutState. Otherwise, subsequent children may not see the current
state of this value during layout, causing incorrect line clamp results.

* LayoutTests/fast/block/line-clamp-nested-blocks-with-layout-state-expected.html: Added.
* LayoutTests/fast/block/line-clamp-nested-blocks-with-layout-state.html: Added.
* Source/WebCore/page/LocalFrameViewLayoutContext.cpp:
(WebCore::LocalFrameViewLayoutContext::popLayoutState):

Canonical link: https://commits.webkit.org/263360@main
  • Loading branch information
GetToSet authored and Ahmad Saleem committed Apr 25, 2023
1 parent f6cad2b commit 59088ba
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
@@ -0,0 +1,15 @@
<style>
.clamped {
font-family: Ahem;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
</style>
<body>
<div class="clamped">
<span>TEST<br />CASE</span>
<div>FAIL</div>
</div>
</body>
@@ -0,0 +1,22 @@
<style>
.clamped {
font-family: Ahem;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
</style>
<body>
<div class="clamped">
<span id="test">TEST</span>
<div>FAIL</div>
</div>
</body>
<script>
if (window.testRunner) testRunner.waitUntilDone();
setTimeout(() => {
document.getElementById("test").innerHTML = "TEST<br />CASE";
if (window.testRunner) testRunner.notifyDone();
}, 0);
</script>
13 changes: 13 additions & 0 deletions Source/WebCore/page/LocalFrameViewLayoutContext.cpp
Expand Up @@ -621,7 +621,20 @@ bool LocalFrameViewLayoutContext::pushLayoutState(RenderBox& renderer, const Lay

void LocalFrameViewLayoutContext::popLayoutState()
{
if (!layoutState())
return;

auto currentLineClamp = layoutState()->lineClamp();

m_layoutStateStack.removeLast();

if (currentLineClamp) {
// Propagates the current line clamp state to the parent.
if (auto* layoutState = this->layoutState(); layoutState && layoutState->lineClamp()) {
ASSERT(layoutState->lineClamp()->maximumLineCount == currentLineClamp->maximumLineCount);
layoutState->setLineClamp(currentLineClamp);
}
}
}

#ifndef NDEBUG
Expand Down

0 comments on commit 59088ba

Please sign in to comment.