Changeset 294240 in webkit


Ignore:
Timestamp:
May 16, 2022 10:35:40 AM (2 years ago)
Author:
Alan Bujtas
Message:

[LFC][FFC] Add support for logical ordering
https://bugs.webkit.org/show_bug.cgi?id=240442

Reviewed by Antti Koivisto.

Let's reorder the logicalFlexItemList when the 'order' property has a non-initial value.

  • layout/formattingContexts/flex/FlexFormattingContext.cpp:

(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r294237 r294240  
     12022-05-16  Alan Bujtas  <zalan@apple.com>
     2
     3        [LFC][FFC] Add support for logical ordering
     4        https://bugs.webkit.org/show_bug.cgi?id=240442
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Let's reorder the logicalFlexItemList when the 'order' property has a non-initial value.
     9
     10        * layout/formattingContexts/flex/FlexFormattingContext.cpp:
     11        (WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
     12
    1132022-05-16  Alan Bujtas  <zalan@apple.com>
    214
  • trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp

    r294237 r294240  
    122122struct FlexItemLogicalBox {
    123123    FlexRect rect;
    124     const ContainerBox& flexItem;
     124    int logicalOrder { 0 };
     125    CheckedPtr<const ContainerBox> flexItem;
    125126};
    126127
     
    129130    auto& formattingState = this->formattingState();
    130131    Vector<FlexItemLogicalBox> logicalFlexItemList;
    131 
     132    auto flexItemsNeedReordering = false;
    132133
    133134    auto convertVisualToLogical = [&] {
    134135        // FIXME: Convert visual (row/column) direction to logical.
    135136        auto direction = root().style().flexDirection();
     137        auto previousLogicalOrder = std::optional<int> { };
    136138
    137139        for (auto& flexItem : childrenOfType<ContainerBox>(root())) {
     
    152154                break;
    153155            }
    154             logicalFlexItemList.append({ { logicalSize }, flexItem });
     156            auto flexItemOrder = flexItem.style().order();
     157            flexItemsNeedReordering = flexItemsNeedReordering || flexItemOrder != previousLogicalOrder.value_or(0);
     158            previousLogicalOrder = flexItemOrder;
     159
     160            logicalFlexItemList.append({ { logicalSize }, flexItemOrder, &flexItem });
     161
    155162        }
    156163    };
    157164    convertVisualToLogical();
     165
     166    auto reorderFlexItemsIfApplicable = [&] {
     167        if (!flexItemsNeedReordering)
     168            return;
     169
     170        std::stable_sort(logicalFlexItemList.begin(), logicalFlexItemList.end(), [&] (auto& a, auto& b) {
     171            return a.logicalOrder < b.logicalOrder;
     172        });
     173    };
     174    reorderFlexItemsIfApplicable();
    158175
    159176    auto logicalLeft = LayoutUnit { };
     
    170187        auto direction = root().style().flexDirection();
    171188        for (auto& logicalFlexItem : logicalFlexItemList) {
    172             auto& flexItemGeometry = formattingState.boxGeometry(logicalFlexItem.flexItem);
     189            auto& flexItemGeometry = formattingState.boxGeometry(*logicalFlexItem.flexItem);
    173190            auto topLeft = LayoutPoint { };
    174191
Note: See TracChangeset for help on using the changeset viewer.