Changing text color and removing line-clamp on hover causes text to disappear permanently
https://bugs.webkit.org/show_bug.cgi?id=240410

Reviewed by Simon Fraser.

Source/WebCore:

Invalidate the flex items' line layout path when line-clamp property value changes.

While the line clamp property is set on the flex box, it is "forced on" the flex items' inline content.
(i.e. the property is not inherited, it is propagated to the flex children)
It means dynamic value change only runs on the flex box renderer.

Test: fast/block/dynamic-line-clamp-empty-content.html

* rendering/RenderDeprecatedFlexibleBox.cpp:
(WebCore::RenderDeprecatedFlexibleBox::styleWillChange):

LayoutTests:

* fast/block/dynamic-line-clamp-empty-content-expected.html: Added.
* fast/block/dynamic-line-clamp-empty-content.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@294211 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index fc4726c..b578d40 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,5 +1,15 @@
 2022-05-14  Alan Bujtas  <zalan@apple.com>
 
+        Changing text color and removing line-clamp on hover causes text to disappear permanently
+        https://bugs.webkit.org/show_bug.cgi?id=240410
+
+        Reviewed by Simon Fraser.
+
+        * fast/block/dynamic-line-clamp-empty-content-expected.html: Added.
+        * fast/block/dynamic-line-clamp-empty-content.html: Added.
+
+2022-05-14  Alan Bujtas  <zalan@apple.com>
+
         [Repaint] Border ignores currentColor change when hovering
         https://bugs.webkit.org/show_bug.cgi?id=240401
 
diff --git a/LayoutTests/fast/block/dynamic-line-clamp-empty-content-expected.html b/LayoutTests/fast/block/dynamic-line-clamp-empty-content-expected.html
new file mode 100644
index 0000000..aac14f2
--- /dev/null
+++ b/LayoutTests/fast/block/dynamic-line-clamp-empty-content-expected.html
@@ -0,0 +1,10 @@
+<style>
+#clamp {
+  width: 100px;
+  overflow: hidden;
+  display: -webkit-box;
+  -webkit-box-orient: block-axis;
+  -webkit-line-clamp: 2;
+}
+</style>
+<div id=clamp>This text should stay visible after setting line clamp on it.</div>
diff --git a/LayoutTests/fast/block/dynamic-line-clamp-empty-content.html b/LayoutTests/fast/block/dynamic-line-clamp-empty-content.html
new file mode 100644
index 0000000..4724322
--- /dev/null
+++ b/LayoutTests/fast/block/dynamic-line-clamp-empty-content.html
@@ -0,0 +1,13 @@
+<style>
+#clamp {
+  width: 100px;
+  overflow: hidden;
+  display: -webkit-box;
+  -webkit-box-orient: block-axis;
+}
+</style>
+<div id=clamp>This text should stay visible after setting line clamp on it.</div>
+<script>
+document.body.offsetHeight;
+clamp.style.webkitLineClamp = '2';
+</script>
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 6928085..dbb887d 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,5 +1,23 @@
 2022-05-14  Alan Bujtas  <zalan@apple.com>
 
+        Changing text color and removing line-clamp on hover causes text to disappear permanently
+        https://bugs.webkit.org/show_bug.cgi?id=240410
+
+        Reviewed by Simon Fraser.
+
+        Invalidate the flex items' line layout path when line-clamp property value changes.
+
+        While the line clamp property is set on the flex box, it is "forced on" the flex items' inline content.
+        (i.e. the property is not inherited, it is propagated to the flex children)
+        It means dynamic value change only runs on the flex box renderer.
+
+        Test: fast/block/dynamic-line-clamp-empty-content.html
+
+        * rendering/RenderDeprecatedFlexibleBox.cpp:
+        (WebCore::RenderDeprecatedFlexibleBox::styleWillChange):
+
+2022-05-14  Alan Bujtas  <zalan@apple.com>
+
         Unreviewed win build fix.
 
         * layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
diff --git a/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp b/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp
index 5f29df1..38b00dd 100644
--- a/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp
+++ b/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp
@@ -179,9 +179,17 @@
 void RenderDeprecatedFlexibleBox::styleWillChange(StyleDifference diff, const RenderStyle& newStyle)
 {
     auto* oldStyle = hasInitializedStyle() ? &style() : nullptr;
-    if (oldStyle && !oldStyle->lineClamp().isNone() && newStyle.lineClamp().isNone())
-        clearLineClamp();
+    if (oldStyle) {
+        auto hadLineClamp = !oldStyle->lineClamp().isNone();
+        auto hasLineClamp = !newStyle.lineClamp().isNone(); 
+        if (hasLineClamp != hadLineClamp) {
+            for (auto& child : childrenOfType<RenderBlockFlow>(*this))
+                child.invalidateLineLayoutPath();
 
+            if (hadLineClamp && !hasLineClamp)
+                clearLineClamp();
+        }
+    }
     RenderBlock::styleWillChange(diff, newStyle);
 }