Commit 3e489ff5 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

blink: recreate layout when clamping changes

Adds logic to switch between LayoutFlexibleBox and
LayoutDeprecatedFlexibleBox when clamping changes.

This is necessary as LayoutDeprecatedFlexibleBox is the only
place that currently provides support for clamping.

BUG=993813
TEST=none

Change-Id: I88dc4ce0195faf08870afeb9e8e5fce338a29476
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1754922
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688209}
parent aef0c113
...@@ -255,7 +255,8 @@ LayoutObject* LayoutObject::CreateObject(Element* element, ...@@ -255,7 +255,8 @@ LayoutObject* LayoutObject::CreateObject(Element* element,
case EDisplay::kWebkitBox: case EDisplay::kWebkitBox:
case EDisplay::kWebkitInlineBox: case EDisplay::kWebkitInlineBox:
if (RuntimeEnabledFeatures::WebkitBoxLayoutUsesFlexLayoutEnabled() && if (RuntimeEnabledFeatures::WebkitBoxLayoutUsesFlexLayoutEnabled() &&
!style.HasLineClamp()) { (!style.HasLineClamp() ||
style.BoxOrient() == EBoxOrient::kHorizontal)) {
return new LayoutFlexibleBox(element); return new LayoutFlexibleBox(element);
} }
return new LayoutDeprecatedFlexibleBox(*element); return new LayoutDeprecatedFlexibleBox(*element);
......
...@@ -211,6 +211,16 @@ bool ComputedStyle::NeedsReattachLayoutTree(const ComputedStyle* old_style, ...@@ -211,6 +211,16 @@ bool ComputedStyle::NeedsReattachLayoutTree(const ComputedStyle* old_style,
return true; return true;
if (old_style->HasTextCombine() != new_style->HasTextCombine()) if (old_style->HasTextCombine() != new_style->HasTextCombine())
return true; return true;
// line-clamping is currently only handled by LayoutDeprecatedFlexibleBox,
// so that if line-clamping changes then the LayoutObject needs to be
// recreated.
if (RuntimeEnabledFeatures::WebkitBoxLayoutUsesFlexLayoutEnabled() &&
(new_style->Display() == EDisplay::kWebkitBox ||
new_style->Display() == EDisplay::kWebkitInlineBox) &&
(old_style->HasLineClamp() != new_style->HasLineClamp() &&
new_style->BoxOrient() == EBoxOrient::kVertical)) {
return true;
}
// We need to perform a reattach if a "display: layout(foo)" has changed to a // We need to perform a reattach if a "display: layout(foo)" has changed to a
// "display: layout(bar)". This is because one custom layout could be // "display: layout(bar)". This is because one custom layout could be
// registered and the other may not, affecting the box-tree construction. // registered and the other may not, affecting the box-tree construction.
......
<!DOCTYPE html>
<script src="../../resources/ahem.js"></script>
<p>There should only be two lines below as the third line is hidden via -webkit-line-clamp.</p>
<div style="font: 20px/1 Ahem; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; -webkit-line-clamp: 2" id="webkitbox">
xxx<br>
xxx<br>
xxx<br>
</div>
<!DOCTYPE html>
<script src="../../resources/ahem.js"></script>
<p>There should only be two lines below as the third line is hidden via -webkit-line-clamp.</p>
<div style="font: 20px/1 Ahem; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden" id="webkitbox">
xxx<br>
xxx<br>
xxx<br>
</div>
<script>
var webkitbox = document.getElementById("webkitbox");
// Referencing |offsetWidth| ensures a layout happens before changing the
// line-clamp. This is done to ensure toggling line-clamp works.
webkitbox.offsetWidth;
webkitbox.style.webkitLineClamp = 2;
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment