Title: [294412] trunk/Source/WebCore/layout/formattingContexts/flex
- Revision
- 294412
- Author
- za...@apple.com
- Date
- 2022-05-18 11:37:30 -0700 (Wed, 18 May 2022)
Log Message
Move visual/logical code to dedicated functions
https://bugs.webkit.org/show_bug.cgi?id=240560
Reviewed by Antti Koivisto.
This is in preparation for adding more pre/post core layout logic.
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::convertFlexItemsToLogicalSpace):
(WebCore::Layout::FlexFormattingContext::setFlexItemsGeometry):
(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
(): Deleted.
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h:
Canonical link: https://commits.webkit.org/250704@main
Modified Paths
Diff
Modified: trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp (294411 => 294412)
--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp 2022-05-18 18:33:44 UTC (rev 294411)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp 2022-05-18 18:37:30 UTC (rev 294412)
@@ -119,20 +119,13 @@
}
}
-struct FlexItemLogicalBox {
- FlexRect rect;
- int logicalOrder { 0 };
- CheckedPtr<const ContainerBox> flexItem;
-};
-
-void FlexFormattingContext::layoutInFlowContentForIntegration(const ConstraintsForInFlowContent& constraints)
+FlexFormattingContext::LogicalFlexItems FlexFormattingContext::convertFlexItemsToLogicalSpace()
{
auto& formattingState = this->formattingState();
- Vector<FlexItemLogicalBox> logicalFlexItemList;
+ LogicalFlexItems logicalFlexItemList;
auto flexItemsNeedReordering = false;
auto convertVisualToLogical = [&] {
- // FIXME: Convert visual (row/column) direction to logical.
auto direction = root().style().flexDirection();
auto previousLogicalOrder = std::optional<int> { };
@@ -158,7 +151,6 @@
previousLogicalOrder = flexItemOrder;
logicalFlexItemList.append({ { logicalSize }, flexItemOrder, &flexItem });
-
}
};
convertVisualToLogical();
@@ -173,6 +165,45 @@
};
reorderFlexItemsIfApplicable();
+ return logicalFlexItemList;
+}
+
+void FlexFormattingContext::setFlexItemsGeometry(const LogicalFlexItems& logicalFlexItemList, const ConstraintsForInFlowContent& constraints)
+{
+ auto& formattingState = this->formattingState();
+ auto logicalWidth = logicalFlexItemList.last().rect.right() - logicalFlexItemList.first().rect.left();
+ auto direction = root().style().flexDirection();
+ for (auto& logicalFlexItem : logicalFlexItemList) {
+ auto& flexItemGeometry = formattingState.boxGeometry(*logicalFlexItem.layoutBox);
+ auto topLeft = LayoutPoint { };
+
+ switch (direction) {
+ case FlexDirection::Row:
+ topLeft = { constraints.horizontal().logicalLeft + logicalFlexItem.rect.left(), constraints.logicalTop() + logicalFlexItem.rect.top() };
+ break;
+ case FlexDirection::RowReverse:
+ topLeft = { constraints.horizontal().logicalRight() - logicalFlexItem.rect.right(), constraints.logicalTop() + logicalFlexItem.rect.top() };
+ break;
+ case FlexDirection::Column: {
+ auto flippedTopLeft = logicalFlexItem.rect.topLeft().transposedPoint();
+ topLeft = { constraints.horizontal().logicalLeft + flippedTopLeft.x(), constraints.logicalTop() + flippedTopLeft.y() };
+ break;
+ }
+ case FlexDirection::ColumnReverse:
+ topLeft = { constraints.horizontal().logicalLeft + logicalFlexItem.rect.top(), constraints.logicalTop() + logicalWidth - logicalFlexItem.rect.right() };
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ flexItemGeometry.setLogicalTopLeft(topLeft);
+ }
+}
+
+void FlexFormattingContext::layoutInFlowContentForIntegration(const ConstraintsForInFlowContent& constraints)
+{
+ auto logicalFlexItemList = convertFlexItemsToLogicalSpace();
+
auto logicalLeft = LayoutUnit { };
auto logicalTop = LayoutUnit { };
@@ -180,38 +211,7 @@
logicalFlexItem.rect.setTopLeft({ logicalLeft, logicalTop });
logicalLeft = logicalFlexItem.rect.right();
}
-
- auto convertLogicalToVisual = [&] {
- // FIXME: Convert logical coordinates to visual.
- auto logicalWidth = logicalFlexItemList.last().rect.right() - logicalFlexItemList.first().rect.left();
- auto direction = root().style().flexDirection();
- for (auto& logicalFlexItem : logicalFlexItemList) {
- auto& flexItemGeometry = formattingState.boxGeometry(*logicalFlexItem.flexItem);
- auto topLeft = LayoutPoint { };
-
- switch (direction) {
- case FlexDirection::Row:
- topLeft = { constraints.horizontal().logicalLeft + logicalFlexItem.rect.left(), constraints.logicalTop() + logicalFlexItem.rect.top() };
- break;
- case FlexDirection::RowReverse:
- topLeft = { constraints.horizontal().logicalRight() - logicalFlexItem.rect.right(), constraints.logicalTop() + logicalFlexItem.rect.top() };
- break;
- case FlexDirection::Column: {
- auto flippedTopLeft = logicalFlexItem.rect.topLeft().transposedPoint();
- topLeft = { constraints.horizontal().logicalLeft + flippedTopLeft.x(), constraints.logicalTop() + flippedTopLeft.y() };
- break;
- }
- case FlexDirection::ColumnReverse:
- topLeft = { constraints.horizontal().logicalLeft + logicalFlexItem.rect.top(), constraints.logicalTop() + logicalWidth - logicalFlexItem.rect.right() };
- break;
- default:
- ASSERT_NOT_REACHED();
- break;
- }
- flexItemGeometry.setLogicalTopLeft(topLeft);
- }
- };
- convertLogicalToVisual();
+ setFlexItemsGeometry(logicalFlexItemList, constraints);
}
IntrinsicWidthConstraints FlexFormattingContext::computedIntrinsicWidthConstraintsForIntegration()
Modified: trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h (294411 => 294412)
--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h 2022-05-18 18:33:44 UTC (rev 294411)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h 2022-05-18 18:37:30 UTC (rev 294412)
@@ -29,6 +29,7 @@
#include "FlexFormattingGeometry.h"
#include "FlexFormattingState.h"
+#include "FlexRect.h"
#include "FormattingQuirks.h"
#include <wtf/IsoMalloc.h>
@@ -55,6 +56,15 @@
void sizeAndPlaceFlexItems(const ConstraintsForInFlowContent&);
void computeIntrinsicWidthConstraintsForFlexItems();
+ struct LogicalFlexItem {
+ FlexRect rect;
+ int logicalOrder { 0 };
+ CheckedPtr<const ContainerBox> layoutBox;
+ };
+ using LogicalFlexItems = Vector<LogicalFlexItem>;
+ LogicalFlexItems convertFlexItemsToLogicalSpace();
+ void setFlexItemsGeometry(const LogicalFlexItems&, const ConstraintsForInFlowContent&);
+
const FlexFormattingState& formattingState() const { return downcast<FlexFormattingState>(FormattingContext::formattingState()); }
FlexFormattingState& formattingState() { return downcast<FlexFormattingState>(FormattingContext::formattingState()); }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes