Title: [279274] trunk/Source/WebCore
Revision
279274
Author
[email protected]
Date
2021-06-25 04:22:59 -0700 (Fri, 25 Jun 2021)

Log Message

[css-flexbox] Cleanup OverridingSizesScope RAII class
https://bugs.webkit.org/show_bug.cgi?id=227394

Reviewed by Rob Buis.

In r279268 we added a new RAII class which adds an overriding sizes free scope to perform
layout computations. That class heavily uses the different set/get/clear methods for overriding
sizes. We can use a macro with subsitutions there to reduce the amount of required code.

Also moving the computeChildIntrinsicLogicalWidths() method to the private section as it does
not require protected visibility.

No new tests as it's just a code refactoring that does not modify the functionality.

* rendering/RenderFlexibleBox.cpp:
(WebCore::OverridingSizesScope::OverridingSizesScope):
(WebCore::OverridingSizesScope::~OverridingSizesScope):
(WebCore::OverridingSizesScope::setOrClearOverridingSize): Deleted.
* rendering/RenderFlexibleBox.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (279273 => 279274)


--- trunk/Source/WebCore/ChangeLog	2021-06-25 09:55:57 UTC (rev 279273)
+++ trunk/Source/WebCore/ChangeLog	2021-06-25 11:22:59 UTC (rev 279274)
@@ -1,3 +1,25 @@
+2021-06-25  Sergio Villar Senin  <[email protected]>
+
+        [css-flexbox] Cleanup OverridingSizesScope RAII class
+        https://bugs.webkit.org/show_bug.cgi?id=227394
+
+        Reviewed by Rob Buis.
+
+        In r279268 we added a new RAII class which adds an overriding sizes free scope to perform
+        layout computations. That class heavily uses the different set/get/clear methods for overriding
+        sizes. We can use a macro with subsitutions there to reduce the amount of required code.
+
+        Also moving the computeChildIntrinsicLogicalWidths() method to the private section as it does
+        not require protected visibility.
+
+        No new tests as it's just a code refactoring that does not modify the functionality.
+
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::OverridingSizesScope::OverridingSizesScope):
+        (WebCore::OverridingSizesScope::~OverridingSizesScope):
+        (WebCore::OverridingSizesScope::setOrClearOverridingSize): Deleted.
+        * rendering/RenderFlexibleBox.h:
+
 2021-06-25  Martin Robinson  <[email protected]>
 
         [css-scroll-snap] Simplify snap point selection helpers

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp (279273 => 279274)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2021-06-25 09:55:57 UTC (rev 279273)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2021-06-25 11:22:59 UTC (rev 279274)
@@ -153,6 +153,14 @@
     addScrollbarWidth();
 }
 
+#define SET_OR_CLEAR_OVERRIDING_SIZE(box, SizeType, size)   \
+    {                                                       \
+        if (size)                                           \
+            box.setOverridingLogical##SizeType(*size);      \
+        else                                                \
+            box.clearOverridingLogical##SizeType();         \
+    }
+
 // RAII class which defines a scope in which overriding sizes of a box are either:
 //   1) replaced by other size in one axis if size is specified
 //   2) cleared in both axis if size == std::nullopt
@@ -175,40 +183,24 @@
         if (axis == Axis::Both || axis == Axis::Inline) {
             if (box.hasOverridingLogicalWidth())
                 m_overridingWidth = box.overridingLogicalWidth();
-            setOrClearOverridingSize(size, Axis::Inline);
+            SET_OR_CLEAR_OVERRIDING_SIZE(m_box, Width, size);
         }
         if (axis == Axis::Both || axis == Axis::Block) {
             if (box.hasOverridingLogicalHeight())
                 m_overridingHeight = box.overridingLogicalHeight();
-            setOrClearOverridingSize(size, Axis::Block);
+            SET_OR_CLEAR_OVERRIDING_SIZE(m_box, Height, size);
         }
     }
     ~OverridingSizesScope()
     {
-        if (m_axis == Axis::Both || m_axis == Axis::Inline)
-            setOrClearOverridingSize(m_overridingWidth, Axis::Inline);
+        if (m_axis == Axis::Inline || m_axis == Axis::Both)
+            SET_OR_CLEAR_OVERRIDING_SIZE(m_box, Width, m_overridingWidth);
 
-        if (m_axis == Axis::Both || m_axis == Axis::Block)
-            setOrClearOverridingSize(m_overridingHeight, Axis::Block);
+        if (m_axis == Axis::Block || m_axis == Axis::Both)
+            SET_OR_CLEAR_OVERRIDING_SIZE(m_box, Height, m_overridingHeight);
     }
 
 private:
-    void setOrClearOverridingSize(std::optional<LayoutUnit> size, Axis axis)
-    {
-        ASSERT(axis != Axis::Both);
-        if (size) {
-            if (axis == Axis::Inline)
-                m_box.setOverridingLogicalWidth(*size);
-            else
-                m_box.setOverridingLogicalHeight(*size);
-            return;
-        }
-        if (axis == Axis::Inline)
-            m_box.clearOverridingLogicalWidth();
-        else
-            m_box.clearOverridingLogicalHeight();
-    }
-
     RenderBox& m_box;
     Axis m_axis;
     std::optional<LayoutUnit> m_overridingWidth;

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.h (279273 => 279274)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2021-06-25 09:55:57 UTC (rev 279273)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2021-06-25 11:22:59 UTC (rev 279274)
@@ -89,7 +89,6 @@
 
 protected:
     void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
-    void computeChildIntrinsicLogicalWidths(RenderObject&, LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
 
     bool shouldResetChildLogicalHeightBeforeLayout(const RenderBox&) const override { return m_shouldResetChildLogicalHeightBeforeLayout; }
 
@@ -146,6 +145,7 @@
     bool childHasComputableAspectRatio(const RenderBox&) const;
     bool childHasComputableAspectRatioAndCrossSizeIsConsideredDefinite(const RenderBox&);
     bool childCrossSizeShouldUseContainerCrossSize(const RenderBox& child) const;
+    void computeChildIntrinsicLogicalWidths(RenderObject&, LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
     LayoutUnit computeMainSizeFromAspectRatioUsing(const RenderBox& child, Length crossSizeLength) const;
     void setFlowAwareLocationForChild(RenderBox& child, const LayoutPoint&);
     LayoutUnit computeInnerFlexBaseSizeForChild(RenderBox& child, LayoutUnit mainAxisBorderAndPadding);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to