[css-grid] Small refactoring adding RenderGrid::contentAlignment()
authorrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Sep 2017 08:39:48 +0000 (08:39 +0000)
committerrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Sep 2017 08:39:48 +0000 (08:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177130

Reviewed by Sergio Villar Senin.

As a follow-up of r221931, this patch does a small refactoring
adding a new method RenderGrid::contentAlignment()
that is used from RenderGrid and GridTrackSizingAlgorithm.

No new tests, no change of behavior.

* rendering/GridTrackSizingAlgorithm.cpp:
(WebCore::GridTrackSizingAlgorithm::stretchAutoTracks):
* rendering/RenderGrid.cpp:
(WebCore::contentAlignmentNormalBehaviorGrid):
(WebCore::RenderGrid::contentAlignment const):
(WebCore::RenderGrid::computeContentPositionAndDistributionOffset const):
(WebCore::RenderGrid::contentAlignmentNormalBehaviorGrid): Deleted.
* rendering/RenderGrid.h:
* rendering/style/RenderStyle.cpp:
(WebCore::resolvedContentAlignment):
(WebCore::RenderStyle::resolvedAlignContent const):
(WebCore::RenderStyle::resolvedJustifyContent const):
* rendering/style/RenderStyle.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222441 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp
Source/WebCore/rendering/RenderGrid.cpp
Source/WebCore/rendering/RenderGrid.h
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h

index 6a60f71..a7f34c2 100644 (file)
@@ -1,5 +1,32 @@
 2017-09-25  Manuel Rego Casasnovas  <rego@igalia.com>
 
+        [css-grid] Small refactoring adding RenderGrid::contentAlignment()
+        https://bugs.webkit.org/show_bug.cgi?id=177130
+
+        Reviewed by Sergio Villar Senin.
+
+        As a follow-up of r221931, this patch does a small refactoring
+        adding a new method RenderGrid::contentAlignment()
+        that is used from RenderGrid and GridTrackSizingAlgorithm.
+
+        No new tests, no change of behavior.
+
+        * rendering/GridTrackSizingAlgorithm.cpp:
+        (WebCore::GridTrackSizingAlgorithm::stretchAutoTracks):
+        * rendering/RenderGrid.cpp:
+        (WebCore::contentAlignmentNormalBehaviorGrid):
+        (WebCore::RenderGrid::contentAlignment const):
+        (WebCore::RenderGrid::computeContentPositionAndDistributionOffset const):
+        (WebCore::RenderGrid::contentAlignmentNormalBehaviorGrid): Deleted.
+        * rendering/RenderGrid.h:
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::resolvedContentAlignment):
+        (WebCore::RenderStyle::resolvedAlignContent const):
+        (WebCore::RenderStyle::resolvedJustifyContent const):
+        * rendering/style/RenderStyle.h:
+
+2017-09-25  Manuel Rego Casasnovas  <rego@igalia.com>
+
         [css-grid] fit-content() tracks shouldn't stretch
         https://bugs.webkit.org/show_bug.cgi?id=177300
 
index 4e37aa3..ffef9ab 100644 (file)
@@ -1071,14 +1071,11 @@ void GridTrackSizingAlgorithm::stretchFlexibleTracks(std::optional<LayoutUnit> f
 
 void GridTrackSizingAlgorithm::stretchAutoTracks()
 {
-    if (m_autoSizedTracksForStretchIndex.isEmpty())
-        return;
-
     auto currentFreeSpace = freeSpace(m_direction);
-    if (!currentFreeSpace
+    if (m_autoSizedTracksForStretchIndex.isEmpty()
+        || !currentFreeSpace
         || currentFreeSpace.value() <= 0
-        || (m_direction == ForColumns && m_renderGrid->style().resolvedJustifyContentDistribution(m_renderGrid->contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch)
-        || (m_direction == ForRows && m_renderGrid->style().resolvedAlignContentDistribution(m_renderGrid->contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch))
+        || (m_renderGrid->contentAlignment(m_direction).distribution() != ContentDistributionStretch))
         return;
 
     Vector<GridTrack>& allTracks = tracks(m_direction);
index 6cfc37b..e437ad7 100644 (file)
@@ -877,7 +877,7 @@ Vector<LayoutUnit> RenderGrid::trackSizesForComputedStyle(GridTrackSizingDirecti
     return tracks;
 }
 
-const StyleContentAlignmentData& RenderGrid::contentAlignmentNormalBehaviorGrid()
+static const StyleContentAlignmentData& contentAlignmentNormalBehaviorGrid()
 {
     static const StyleContentAlignmentData normalBehavior = {ContentPositionNormal, ContentDistributionStretch};
     return normalBehavior;
@@ -1581,19 +1581,23 @@ static ContentAlignmentData contentDistributionOffset(const LayoutUnit& availabl
     return ContentAlignmentData::defaultOffsets();
 }
 
+StyleContentAlignmentData RenderGrid::contentAlignment(GridTrackSizingDirection direction) const
+{
+    return direction == ForColumns ? style().resolvedJustifyContent(contentAlignmentNormalBehaviorGrid()) : style().resolvedAlignContent(contentAlignmentNormalBehaviorGrid());
+}
+
 ContentAlignmentData RenderGrid::computeContentPositionAndDistributionOffset(GridTrackSizingDirection direction, const LayoutUnit& availableFreeSpace, unsigned numberOfGridTracks) const
 {
     bool isRowAxis = direction == ForColumns;
-    auto position = isRowAxis ? style().resolvedJustifyContentPosition(contentAlignmentNormalBehaviorGrid()) : style().resolvedAlignContentPosition(contentAlignmentNormalBehaviorGrid());
-    auto distribution = isRowAxis ? style().resolvedJustifyContentDistribution(contentAlignmentNormalBehaviorGrid()) : style().resolvedAlignContentDistribution(contentAlignmentNormalBehaviorGrid());
+    auto contentAlignmentData = contentAlignment(direction);
+    auto position = contentAlignmentData.position();
     // If <content-distribution> value can't be applied, 'position' will become the associated
     // <content-position> fallback value.
-    auto contentAlignment = contentDistributionOffset(availableFreeSpace, position, distribution, numberOfGridTracks);
+    auto contentAlignment = contentDistributionOffset(availableFreeSpace, position, contentAlignmentData.distribution(), numberOfGridTracks);
     if (contentAlignment.isValid())
         return contentAlignment;
 
-    auto overflow = (isRowAxis ? style().justifyContent() : style().alignContent()).overflow();
-    if (availableFreeSpace <= 0 && overflow == OverflowAlignmentSafe)
+    if (availableFreeSpace <= 0 && contentAlignmentData.overflow() == OverflowAlignmentSafe)
         return {0, 0};
 
     switch (position) {
index 48b44cf..ca025e6 100644 (file)
@@ -65,7 +65,7 @@ public:
     bool isOrthogonalChild(const RenderBox&) const;
     LayoutUnit guttersSize(const Grid&, GridTrackSizingDirection, unsigned startLine, unsigned span, std::optional<LayoutUnit> availableSize) const;
 
-    static const StyleContentAlignmentData& contentAlignmentNormalBehaviorGrid();
+    StyleContentAlignmentData contentAlignment(GridTrackSizingDirection) const;
 
 protected:
     ItemPosition selfAlignmentNormalBehavior(const RenderBox* child = nullptr) const override
index 53a86d8..1ef468b 100644 (file)
@@ -280,6 +280,23 @@ StyleSelfAlignmentData RenderStyle::resolvedJustifySelf(const RenderStyle* paren
     return parentStyle->resolvedJustifyItems(normalValueBehaviour);
 }
 
+static inline StyleContentAlignmentData resolvedContentAlignment(const StyleContentAlignmentData& value, const StyleContentAlignmentData& normalValueBehavior)
+{
+    return (value.position() == ContentPositionNormal && value.distribution() == ContentDistributionDefault) ? normalValueBehavior : value;
+}
+
+StyleContentAlignmentData RenderStyle::resolvedAlignContent(const StyleContentAlignmentData& normalValueBehavior) const
+{
+    // We will return the behaviour of 'normal' value if needed, which is specific of each layout model.
+    return resolvedContentAlignment(alignContent(), normalValueBehavior);
+}
+
+StyleContentAlignmentData RenderStyle::resolvedJustifyContent(const StyleContentAlignmentData& normalValueBehavior) const
+{
+    // We will return the behaviour of 'normal' value if needed, which is specific of each layout model.
+    return resolvedContentAlignment(justifyContent(), normalValueBehavior);
+}
+
 static inline ContentPosition resolvedContentAlignmentPosition(const StyleContentAlignmentData& value, const StyleContentAlignmentData& normalValueBehavior)
 {
     return (value.position() == ContentPositionNormal && value.distribution() == ContentDistributionDefault) ? normalValueBehavior.position() : value.position();
index e286248..764e092 100644 (file)
@@ -166,8 +166,10 @@ public:
     ContentDistributionType resolvedAlignContentDistribution(const StyleContentAlignmentData& normalValueBehavior) const;
     StyleSelfAlignmentData resolvedAlignItems(ItemPosition normalValueBehaviour) const;
     StyleSelfAlignmentData resolvedAlignSelf(const RenderStyle* parentStyle, ItemPosition normalValueBehaviour) const;
+    StyleContentAlignmentData resolvedAlignContent(const StyleContentAlignmentData& normalValueBehaviour) const;
     StyleSelfAlignmentData resolvedJustifyItems(ItemPosition normalValueBehaviour) const;
     StyleSelfAlignmentData resolvedJustifySelf(const RenderStyle* parentStyle, ItemPosition normalValueBehaviour) const;
+    StyleContentAlignmentData resolvedJustifyContent(const StyleContentAlignmentData& normalValueBehaviour) const;
 
     PseudoId styleType() const { return static_cast<PseudoId>(m_nonInheritedFlags.styleType); }
     void setStyleType(PseudoId styleType) { m_nonInheritedFlags.styleType = styleType; }