Title: [294217] trunk/Source/WebCore
Revision
294217
Author
za...@apple.com
Date
2022-05-15 09:53:19 -0700 (Sun, 15 May 2022)

Log Message

[LFC][FFC] Introduce logical direction based flex layout
https://bugs.webkit.org/show_bug.cgi?id=240424

Reviewed by Antti Koivisto.

This is in preparation for ensuring that core flex layout only needs to deal with
one direction for flex content progression (row vs. column vs. reversed etc).

* WebCore.xcodeproj/project.pbxproj:
* layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
* layout/integration/LayoutIntegrationCoverage.cpp:
(WebCore::LayoutIntegration::canUseForFlexLayout):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (294216 => 294217)


--- trunk/Source/WebCore/ChangeLog	2022-05-15 15:49:21 UTC (rev 294216)
+++ trunk/Source/WebCore/ChangeLog	2022-05-15 16:53:19 UTC (rev 294217)
@@ -1,3 +1,19 @@
+2022-05-15  Alan Bujtas  <za...@apple.com>
+
+        [LFC][FFC] Introduce logical direction based flex layout
+        https://bugs.webkit.org/show_bug.cgi?id=240424
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for ensuring that core flex layout only needs to deal with
+        one direction for flex content progression (row vs. column vs. reversed etc).
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/formattingContexts/flex/FlexFormattingContext.cpp:
+        (WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
+        * layout/integration/LayoutIntegrationCoverage.cpp:
+        (WebCore::LayoutIntegration::canUseForFlexLayout):
+
 2022-05-15  Kimmo Kinnunen  <kkinnu...@apple.com>
 
         WebCore::IOSurface has WebCore::GraphicsContext as its property, it should be the other way around

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (294216 => 294217)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-05-15 15:49:21 UTC (rev 294216)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-05-15 16:53:19 UTC (rev 294217)
@@ -2257,6 +2257,7 @@
 		6FB5E214221F2453003989CF /* ContentChangeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB5E212221F2447003989CF /* ContentChangeObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6FB7D2DD250FD828000207AA /* FlexFormattingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB7D2D9250FD7FC000207AA /* FlexFormattingContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6FB7D2DE250FD82E000207AA /* FlexFormattingState.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB7D2DA250FD7FC000207AA /* FlexFormattingState.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		6FB9105C2830BC8A00004929 /* FlexRect.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB9105B2830BC8A00004929 /* FlexRect.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6FC3F9472516756700A49BEA /* InlineDisplayBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FC3F9452516756600A49BEA /* InlineDisplayBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6FCBDB97265DF2C80021EA7B /* LayoutContainingBlockChainIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FCBDB95265DF2C70021EA7B /* LayoutContainingBlockChainIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6FD09543251115220098877D /* LayoutGeometryRect.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FD09541251115220098877D /* LayoutGeometryRect.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11092,6 +11093,7 @@
 		6FB7D2D8250FD7EF000207AA /* FlexFormattingState.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FlexFormattingState.cpp; sourceTree = "<group>"; };
 		6FB7D2D9250FD7FC000207AA /* FlexFormattingContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlexFormattingContext.h; sourceTree = "<group>"; };
 		6FB7D2DA250FD7FC000207AA /* FlexFormattingState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlexFormattingState.h; sourceTree = "<group>"; };
+		6FB9105B2830BC8A00004929 /* FlexRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlexRect.h; sourceTree = "<group>"; };
 		6FBB860520B464B600DAD938 /* FormattingGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FormattingGeometry.cpp; sourceTree = "<group>"; };
 		6FC3F9452516756600A49BEA /* InlineDisplayBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineDisplayBox.h; sourceTree = "<group>"; };
 		6FC53AEB24AF7A8E006059FE /* TableFormattingQuirks.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableFormattingQuirks.cpp; sourceTree = "<group>"; };
@@ -24666,6 +24668,7 @@
 				6FF911F626487FC8002021DF /* FlexFormattingGeometry.h */,
 				6FB7D2D8250FD7EF000207AA /* FlexFormattingState.cpp */,
 				6FB7D2DA250FD7FC000207AA /* FlexFormattingState.h */,
+				6FB9105B2830BC8A00004929 /* FlexRect.h */,
 			);
 			path = flex;
 			sourceTree = "<group>";
@@ -34809,6 +34812,7 @@
 				6FB7D2DD250FD828000207AA /* FlexFormattingContext.h in Headers */,
 				6FF911F726487FC8002021DF /* FlexFormattingGeometry.h in Headers */,
 				6FB7D2DE250FD82E000207AA /* FlexFormattingState.h in Headers */,
+				6FB9105C2830BC8A00004929 /* FlexRect.h in Headers */,
 				6FFDC442212EFF1700A9CA91 /* FloatAvoider.h in Headers */,
 				BC073BAA0C399B1F000F5979 /* FloatConversion.h in Headers */,
 				115CFA86208B9066001E6991 /* FloatingContext.h in Headers */,

Modified: trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp (294216 => 294217)


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-15 15:49:21 UTC (rev 294216)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-15 16:53:19 UTC (rev 294217)
@@ -30,6 +30,7 @@
 
 #include "FlexFormattingGeometry.h"
 #include "FlexFormattingState.h"
+#include "FlexRect.h"
 #include "InlineRect.h"
 #include "LayoutBoxGeometry.h"
 #include "LayoutChildIterator.h"
@@ -118,17 +119,44 @@
     }
 }
 
+struct FlexItemLogicalBox {
+    FlexRect rect;
+    const ContainerBox& flexItem;
+};
+
 void FlexFormattingContext::layoutInFlowContentForIntegration(const ConstraintsForInFlowContent& constraints)
 {
     auto& formattingState = this->formattingState();
-    auto mainAxisPosition = constraints.horizontal().logicalLeft;
-    auto crossAxisPosition = constraints.logicalTop();
-    for (auto& flexItem : childrenOfType<ContainerBox>(root())) {
-        auto& flexItemGeometry = formattingState.boxGeometry(flexItem);
+    Vector<FlexItemLogicalBox> logicalFlexItemList;
 
-        flexItemGeometry.setLogicalTopLeft({ mainAxisPosition, crossAxisPosition });
-        mainAxisPosition = BoxGeometry::borderBoxRect(flexItemGeometry).right();
+    auto logicalLeft = LayoutUnit { };
+    auto logicalTop = LayoutUnit { };
+
+    auto convertVisualToLogical = [&] {
+        // FIXME: Convert visual (row/column) direction to logical.
+        logicalLeft = constraints.horizontal().logicalLeft;
+        logicalTop = constraints.logicalTop();
+    
+        for (auto& flexItem : childrenOfType<ContainerBox>(root())) {
+            auto& flexItemGeometry = formattingState.boxGeometry(flexItem);
+            logicalFlexItemList.append({ { LayoutSize { flexItemGeometry.marginBoxWidth(), flexItemGeometry.marginBoxHeight() } }, flexItem });
+        }
+    };
+    convertVisualToLogical();
+
+    for (auto& logicalFlexItem : logicalFlexItemList) {
+        logicalFlexItem.rect.setTopLeft({ logicalLeft, logicalTop });
+        logicalLeft = logicalFlexItem.rect.right();
     }
+
+    auto convertLogicalToVisual = [&] {
+        // FIXME: Convert logical coordinates to visual.
+        for (auto& logicalFlexItem : logicalFlexItemList) {
+            auto& flexItemGeometry = formattingState.boxGeometry(logicalFlexItem.flexItem);
+            flexItemGeometry.setLogicalTopLeft(logicalFlexItem.rect.topLeft());
+        }
+    };
+    convertLogicalToVisual();
 }
 
 IntrinsicWidthConstraints FlexFormattingContext::computedIntrinsicWidthConstraintsForIntegration()

Added: trunk/Source/WebCore/layout/formattingContexts/flex/FlexRect.h (0 => 294217)


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexRect.h	                        (rev 0)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexRect.h	2022-05-15 16:53:19 UTC (rev 294217)
@@ -0,0 +1,268 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "LayoutRect.h"
+
+namespace WebCore {
+namespace Layout {
+
+class FlexRect {
+public:
+    FlexRect() = default;
+    FlexRect(LayoutUnit top, LayoutUnit left, LayoutUnit width, LayoutUnit height);
+    FlexRect(const LayoutRect&);
+    FlexRect(const LayoutSize&);
+    
+    LayoutUnit top() const;
+    LayoutUnit left() const;
+    LayoutPoint topLeft() const;
+
+    LayoutUnit bottom() const;
+    LayoutUnit right() const;        
+
+    LayoutUnit width() const;
+    LayoutUnit height() const;
+    LayoutSize size() const;
+
+    void setTop(LayoutUnit);
+    void setBottom(LayoutUnit);
+    void setLeft(LayoutUnit);
+    void setRight(LayoutUnit);
+    void setTopLeft(const LayoutPoint&);
+    void setWidth(LayoutUnit);
+    void setHeight(LayoutUnit);
+
+    void moveHorizontally(LayoutUnit);
+    void moveVertically(LayoutUnit);
+
+    bool isEmpty() const;
+
+    operator LayoutRect() const;
+
+private:
+#if ASSERT_ENABLED
+    void invalidateTop() { m_hasValidTop = false; }
+    void invalidateLeft() { m_hasValidLeft = false; }
+    void invalidateWidth() { m_hasValidWidth = false; }
+    void invalidateHeight() { m_hasValidHeight = false; }
+    void invalidatePosition();
+
+    bool hasValidPosition() const { return m_hasValidTop && m_hasValidLeft; }
+    bool hasValidSize() const { return m_hasValidWidth && m_hasValidHeight; }
+    bool hasValidGeometry() const { return hasValidPosition() && hasValidSize(); }
+
+    void setHasValidPosition();
+    void setHasValidSize();
+
+    bool m_hasValidTop { false };
+    bool m_hasValidLeft { false };
+    bool m_hasValidWidth { false };
+    bool m_hasValidHeight { false };
+#endif // ASSERT_ENABLED
+    LayoutRect m_rect;
+};
+
+inline FlexRect::FlexRect(LayoutUnit top, LayoutUnit left, LayoutUnit width, LayoutUnit height)
+    : m_rect(left, top, width, height)
+{
+#if ASSERT_ENABLED
+    m_hasValidTop = true;
+    m_hasValidLeft = true;
+    m_hasValidWidth = true;
+    m_hasValidHeight = true;
+#endif
+}
+
+inline FlexRect::FlexRect(const LayoutRect& rect)
+    : FlexRect(rect.y(), rect.x(), rect.width(), rect.height())
+{
+}
+
+inline FlexRect::FlexRect(const LayoutSize& size)
+    : m_rect({ }, size)
+{
+#if ASSERT_ENABLED
+    m_hasValidWidth = true;
+    m_hasValidHeight = true;
+#endif
+}
+
+#if ASSERT_ENABLED
+inline void FlexRect::invalidatePosition()
+{
+    invalidateTop();
+    invalidateLeft();
+}
+
+inline void FlexRect::setHasValidPosition()
+{
+    m_hasValidTop = true;
+    m_hasValidLeft = true;
+}
+
+inline void FlexRect::setHasValidSize()
+{
+    m_hasValidWidth = true;
+    m_hasValidHeight = true;
+}
+#endif // ASSERT_ENABLED
+
+inline LayoutUnit FlexRect::top() const
+{
+    ASSERT(m_hasValidTop);
+    return m_rect.y();
+}
+
+inline LayoutUnit FlexRect::left() const
+{
+    ASSERT(m_hasValidLeft);
+    return m_rect.x();
+}
+
+inline LayoutUnit FlexRect::bottom() const
+{
+    ASSERT(m_hasValidTop && m_hasValidHeight);
+    return m_rect.maxY();
+}
+
+inline LayoutUnit FlexRect::right() const
+{
+    ASSERT(m_hasValidLeft && m_hasValidWidth);
+    return m_rect.maxX();
+}
+
+inline LayoutPoint FlexRect::topLeft() const
+{
+    ASSERT(hasValidPosition());
+    return m_rect.minXMinYCorner();
+}
+
+inline LayoutSize FlexRect::size() const
+{
+    ASSERT(hasValidSize());
+    return m_rect.size();
+}
+
+inline LayoutUnit FlexRect::width() const
+{
+    ASSERT(m_hasValidWidth);
+    return m_rect.width();
+}
+
+inline LayoutUnit FlexRect::height() const
+{
+    ASSERT(m_hasValidHeight);
+    return m_rect.height();
+}
+
+inline void FlexRect::setTopLeft(const LayoutPoint& topLeft)
+{
+#if ASSERT_ENABLED
+    setHasValidPosition();
+#endif
+    m_rect.setLocation(topLeft);
+}
+
+inline void FlexRect::setTop(LayoutUnit top)
+{
+#if ASSERT_ENABLED
+    m_hasValidTop = true;
+#endif
+    m_rect.setY(top);
+}
+
+inline void FlexRect::setBottom(LayoutUnit bottom)
+{
+#if ASSERT_ENABLED
+    m_hasValidTop = true;
+    m_hasValidHeight = true;
+#endif
+    m_rect.shiftMaxYEdgeTo(bottom);
+}
+
+inline void FlexRect::setLeft(LayoutUnit left)
+{
+#if ASSERT_ENABLED
+    m_hasValidLeft = true;
+#endif
+    m_rect.setX(left);
+}
+
+inline void FlexRect::setRight(LayoutUnit right)
+{
+#if ASSERT_ENABLED
+    m_hasValidLeft = true;
+    m_hasValidWidth = true;
+#endif
+    m_rect.shiftMaxXEdgeTo(right);
+}
+
+inline void FlexRect::setWidth(LayoutUnit width)
+{
+#if ASSERT_ENABLED
+    m_hasValidWidth = true;
+#endif
+    m_rect.setWidth(width);
+}
+
+inline void FlexRect::setHeight(LayoutUnit height)
+{
+#if ASSERT_ENABLED
+    m_hasValidHeight = true;
+#endif
+    m_rect.setHeight(height);
+}
+
+inline void FlexRect::moveHorizontally(LayoutUnit offset)
+{
+    ASSERT(m_hasValidLeft);
+    m_rect.move(LayoutSize { offset, 0 });
+}
+
+inline void FlexRect::moveVertically(LayoutUnit offset)
+{
+    ASSERT(m_hasValidTop);
+    m_rect.move(LayoutSize { 0, offset });
+}
+
+inline bool FlexRect::isEmpty() const
+{
+    ASSERT(hasValidGeometry());
+    return m_rect.isEmpty();
+}
+
+inline FlexRect::operator LayoutRect() const
+{
+    ASSERT(hasValidGeometry()); 
+    return m_rect;
+}
+
+}
+}
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to