Title: [294275] trunk
Revision
294275
Author
obru...@igalia.com
Date
2022-05-16 16:03:23 -0700 (Mon, 16 May 2022)

Log Message

Take intrinsicBorderForFieldset() into account in intrinsically sized fieldset
https://bugs.webkit.org/show_bug.cgi?id=240388

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Add test.

* web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size-expected.txt: Added.
* web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html: Added.

Source/WebCore:

With 'box-sizing: content-box', computeIntrinsicLogicalContentHeightUsing
was not taking intrinsicBorderForFieldset() into account. So a fieldset
with 'height: min-content' would ignore the extra space required by the
legend, and the contents would overflow.

This patch adds a RenderBox::adjustIntrinsicLogicalHeightForBoxSizing
method with the logic, and overrides it in RenderBlock to take
intrinsicBorderForFieldset() into account.

Test: imported/w3c/web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::adjustIntrinsicLogicalHeightForBoxSizing const):
Take intrinsicBorderForFieldset() into account.

* rendering/RenderBlock.h:
Override adjustIntrinsicLogicalHeightForBoxSizing.

* rendering/RenderBox.cpp:
(WebCore::RenderBox::adjustIntrinsicLogicalHeightForBoxSizing const):
(WebCore::RenderBox::computeIntrinsicLogicalContentHeightUsing const):
Move logic into a new method so that RenderBlock can override it.

* rendering/RenderBox.h:
Declare adjustIntrinsicLogicalHeightForBoxSizing as virtual.
No need for computeIntrinsicLogicalContentHeightUsing to be virtual.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (294274 => 294275)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-05-16 22:59:07 UTC (rev 294274)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-05-16 23:03:23 UTC (rev 294275)
@@ -1,3 +1,15 @@
+2022-05-16  Oriol Brufau  <obru...@igalia.com>
+
+        Take intrinsicBorderForFieldset() into account in intrinsically sized fieldset
+        https://bugs.webkit.org/show_bug.cgi?id=240388
+
+        Reviewed by Darin Adler.
+
+        Add test.
+
+        * web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size-expected.txt: Added.
+        * web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html: Added.
+
 2022-05-16  Tim Nguyen  <n...@apple.com>
 
         [css-ui] Unexpose attachment and borderless-attachment appearance values

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size-expected.txt (0 => 294275)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size-expected.txt	2022-05-16 23:03:23 UTC (rev 294275)
@@ -0,0 +1,19 @@
+
+PASS auto content-box
+PASS auto border-box
+PASS min-content content-box
+PASS min-content border-box
+PASS max-content content-box
+PASS max-content border-box
+Legend
+Contents
+Legend
+Contents
+Legend
+Contents
+Legend
+Contents
+Legend
+Contents
+Legend
+Contents

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html (0 => 294275)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html	2022-05-16 23:03:23 UTC (rev 294275)
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Fieldset with intrinsic size</title>
+<link rel="author" title="Oriol Brufau" href=""
+<link rel="help" href=""
+<link rel="help" href=""
+<meta name="assert" content="A fieldset with an intrinsic size should be as big as required by the contents.">
+<style>
+fieldset {
+  height: min-content;
+  padding: 7px;
+  border: 3px solid cyan;
+}
+fieldset > div {
+  border: 3px solid orange;
+}
+.auto {
+  height: auto;
+}
+.min-content {
+  height: min-content;
+}
+.max-content {
+  height: max-content;
+}
+.content-box {
+  box-sizing: content-box;
+}
+.border-box {
+  box-sizing: border-box;
+}
+</style>
+
+<div id="log"></div>
+
+<fieldset class="auto content-box">
+  <legend>Legend</legend>
+  <div>Contents</div>
+</fieldset>
+<fieldset class="auto border-box">
+  <legend>Legend</legend>
+  <div>Contents</div>
+</fieldset>
+<fieldset class="min-content content-box">
+  <legend>Legend</legend>
+  <div>Contents</div>
+</fieldset>
+<fieldset class="min-content border-box">
+  <legend>Legend</legend>
+  <div>Contents</div>
+</fieldset>
+<fieldset class="max-content content-box">
+  <legend>Legend</legend>
+  <div>Contents</div>
+</fieldset>
+<fieldset class="max-content border-box">
+  <legend>Legend</legend>
+  <div>Contents</div>
+</fieldset>
+
+<script src=""
+<script src=""
+<script>
+for (let fieldset of document.querySelectorAll("fieldset")) {
+  test(function() {
+    const fieldsetRect = fieldset.getBoundingClientRect();
+    const contentsRect = fieldset.querySelector("div").getBoundingClientRect();
+    const fieldsetOuterEnd = fieldsetRect.y + fieldsetRect.height;
+    const fieldsetInnerEnd = fieldsetOuterEnd - 10;
+    const contentsOuterEnd = contentsRect.y + contentsRect.height;
+    assert_equals(fieldsetInnerEnd, contentsOuterEnd);
+  }, fieldset.className);
+}
+</script>

Modified: trunk/Source/WebCore/ChangeLog (294274 => 294275)


--- trunk/Source/WebCore/ChangeLog	2022-05-16 22:59:07 UTC (rev 294274)
+++ trunk/Source/WebCore/ChangeLog	2022-05-16 23:03:23 UTC (rev 294275)
@@ -1,3 +1,37 @@
+2022-05-16  Oriol Brufau  <obru...@igalia.com>
+
+        Take intrinsicBorderForFieldset() into account in intrinsically sized fieldset
+        https://bugs.webkit.org/show_bug.cgi?id=240388
+
+        Reviewed by Darin Adler.
+
+        With 'box-sizing: content-box', computeIntrinsicLogicalContentHeightUsing
+        was not taking intrinsicBorderForFieldset() into account. So a fieldset
+        with 'height: min-content' would ignore the extra space required by the
+        legend, and the contents would overflow.
+
+        This patch adds a RenderBox::adjustIntrinsicLogicalHeightForBoxSizing
+        method with the logic, and overrides it in RenderBlock to take
+        intrinsicBorderForFieldset() into account.
+
+        Test: imported/w3c/web-platform-tests/html/semantics/forms/the-fieldset-element/fieldset-intrinsic-size.html
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::adjustIntrinsicLogicalHeightForBoxSizing const):
+        Take intrinsicBorderForFieldset() into account.
+
+        * rendering/RenderBlock.h:
+        Override adjustIntrinsicLogicalHeightForBoxSizing.
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::adjustIntrinsicLogicalHeightForBoxSizing const):
+        (WebCore::RenderBox::computeIntrinsicLogicalContentHeightUsing const):
+        Move logic into a new method so that RenderBlock can override it.
+
+        * rendering/RenderBox.h:
+        Declare adjustIntrinsicLogicalHeightForBoxSizing as virtual.
+        No need for computeIntrinsicLogicalContentHeightUsing to be virtual.
+
 2022-05-16  Fujii Hironori  <hironori.fu...@sony.com>
 
         [CMake][VS] PrivateHeaders/WebCore/WebCoreJSBuiltinInternals.h is not updated in incremental build

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (294274 => 294275)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2022-05-16 22:59:07 UTC (rev 294274)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2022-05-16 23:03:23 UTC (rev 294275)
@@ -3450,6 +3450,13 @@
     return std::max(0_lu, result);
 }
 
+LayoutUnit RenderBlock::adjustIntrinsicLogicalHeightForBoxSizing(LayoutUnit height) const
+{
+    if (style().boxSizing() == BoxSizing::BorderBox)
+        return height + borderAndPaddingLogicalHeight();
+    return height + intrinsicBorderForFieldset();
+}
+
 void RenderBlock::paintExcludedChildrenInBorder(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
 {
     if (!isFieldset())

Modified: trunk/Source/WebCore/rendering/RenderBlock.h (294274 => 294275)


--- trunk/Source/WebCore/rendering/RenderBlock.h	2022-05-16 22:59:07 UTC (rev 294274)
+++ trunk/Source/WebCore/rendering/RenderBlock.h	2022-05-16 23:03:23 UTC (rev 294275)
@@ -228,6 +228,7 @@
     LayoutUnit borderBefore() const override;
     LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const override;
     LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(std::optional<LayoutUnit> height) const override;
+    LayoutUnit adjustIntrinsicLogicalHeightForBoxSizing(LayoutUnit height) const override;
     void paintExcludedChildrenInBorder(PaintInfo&, const LayoutPoint&);
     
     LayoutSize clientLogicalRightAndBottomAfterRepositioning() const;

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (294274 => 294275)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2022-05-16 22:59:07 UTC (rev 294274)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2022-05-16 23:03:23 UTC (rev 294275)
@@ -1436,6 +1436,13 @@
     return std::max(0_lu, result);
 }
 
+LayoutUnit RenderBox::adjustIntrinsicLogicalHeightForBoxSizing(LayoutUnit height) const
+{
+    if (style().boxSizing() == BoxSizing::BorderBox)
+        return height + borderAndPaddingLogicalHeight();
+    return height;
+}
+
 // Hit Testing
 bool RenderBox::hitTestVisualOverflow(const HitTestLocation& hitTestLocation, const LayoutPoint& accumulatedOffset) const
 {
@@ -3257,8 +3264,8 @@
     // FIXME: The CSS sizing spec is considering changing what min-content/max-content should resolve to.
     // If that happens, this code will have to change.
     if (logicalHeightLength.isMinContent() || logicalHeightLength.isMaxContent() || logicalHeightLength.isFitContent() || logicalHeightLength.isLegacyIntrinsic()) {
-        if (intrinsicContentHeight && style().boxSizing() == BoxSizing::BorderBox)
-            return intrinsicContentHeight.value() + borderAndPaddingLogicalHeight();
+        if (intrinsicContentHeight)
+            return adjustIntrinsicLogicalHeightForBoxSizing(intrinsicContentHeight.value());
         return intrinsicContentHeight;
     }
     if (logicalHeightLength.isFillAvailable())

Modified: trunk/Source/WebCore/rendering/RenderBox.h (294274 => 294275)


--- trunk/Source/WebCore/rendering/RenderBox.h	2022-05-16 22:59:07 UTC (rev 294274)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2022-05-16 23:03:23 UTC (rev 294275)
@@ -371,6 +371,7 @@
     // Overridden by fieldsets to subtract out the intrinsic border.
     virtual LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
     virtual LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(std::optional<LayoutUnit> height) const;
+    virtual LayoutUnit adjustIntrinsicLogicalHeightForBoxSizing(LayoutUnit height) const;
 
     struct ComputedMarginValues {
         LayoutUnit m_before;
@@ -702,7 +703,7 @@
     void computePositionedLogicalWidth(LogicalExtentComputedValues&, RenderFragmentContainer* = nullptr) const;
 
     LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
-    virtual std::optional<LayoutUnit> computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, std::optional<LayoutUnit> intrinsicContentHeight, LayoutUnit borderAndPadding) const;
+    std::optional<LayoutUnit> computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, std::optional<LayoutUnit> intrinsicContentHeight, LayoutUnit borderAndPadding) const;
     
     virtual bool shouldComputeSizeAsReplaced() const { return isReplacedOrInlineBlock() && !isInlineBlockOrInlineTable(); }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to