Changeset 249439 in webkit


Ignore:
Timestamp:
Sep 3, 2019 12:53:49 PM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC] FloatingState should not need to query for display boxes.
https://bugs.webkit.org/show_bug.cgi?id=201408
<rdar://problem/54958348>

Reviewed by Antti Koivisto.

This is in preparation for transitioning the floating codebase to use the formatting context for
retrieving display boxes.
FloatingContext should be responsible for adding/removing the new/existing float boxes to the state.

  • layout/blockformatting/BlockFormattingContext.cpp:

(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot):

  • layout/floats/FloatingContext.cpp:

(WebCore::Layout::FloatingContext::append):
(WebCore::Layout::FloatingContext::remove):

  • layout/floats/FloatingContext.h:
  • layout/floats/FloatingState.cpp:

(WebCore::Layout::FloatingState::append):
(WebCore::Layout::belongsToThisFloatingContext): Deleted.

  • layout/floats/FloatingState.h:

(WebCore::Layout::FloatingState::FloatItem::horizontalMargin const):

  • layout/inlineformatting/InlineFormattingContextLineLayout.cpp:

(WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns const):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249438 r249439  
     12019-09-03  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] FloatingState should not need to query for display boxes.
     4        https://bugs.webkit.org/show_bug.cgi?id=201408
     5        <rdar://problem/54958348>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This is in preparation for transitioning the floating codebase to use the formatting context for
     10        retrieving display boxes.
     11        FloatingContext should be responsible for adding/removing the new/existing float boxes to the state.
     12
     13        * layout/blockformatting/BlockFormattingContext.cpp:
     14        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot):
     15        * layout/floats/FloatingContext.cpp:
     16        (WebCore::Layout::FloatingContext::append):
     17        (WebCore::Layout::FloatingContext::remove):
     18        * layout/floats/FloatingContext.h:
     19        * layout/floats/FloatingState.cpp:
     20        (WebCore::Layout::FloatingState::append):
     21        (WebCore::Layout::belongsToThisFloatingContext): Deleted.
     22        * layout/floats/FloatingState.h:
     23        (WebCore::Layout::FloatingState::FloatItem::horizontalMargin const):
     24        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
     25        (WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns const):
     26
    1272019-09-03  Zalan Bujtas  <zalan@apple.com>
    228
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r249433 r249439  
    181181    if (layoutBox.isFloatingPositioned()) {
    182182        computeFloatingPosition(floatingContext, layoutBox);
    183         floatingContext.floatingState().append(layoutBox);
     183        floatingContext.append(layoutBox);
    184184    } else if (layoutBox.establishesBlockFormattingContext())
    185185        computePositionToAvoidFloats(floatingContext, layoutBox);
  • trunk/Source/WebCore/layout/floats/FloatingContext.cpp

    r249437 r249439  
    342342}
    343343
     344void FloatingContext::append(const Box& floatBox)
     345{
     346    floatingState().append(FloatingState::FloatItem { floatBox, FormattingContext::mapBoxToAncestor(layoutState(), floatBox, downcast<Container>(floatingState().root())) });
     347}
     348
     349void FloatingContext::remove(const Box& floatBox)
     350{
     351    floatingState().remove(floatBox);
     352}
     353
    344354static FloatPair::LeftRightIndex findAvailablePosition(FloatAvoider& floatAvoider, const FloatingState::FloatList& floats)
    345355{
  • trunk/Source/WebCore/layout/floats/FloatingContext.h

    r249433 r249439  
    6767    };
    6868    Constraints constraints(PositionInContextRoot verticalPosition) const;
     69    void append(const Box&);
     70    void remove(const Box&);
    6971
    7072private:
  • trunk/Source/WebCore/layout/floats/FloatingState.cpp

    r249438 r249439  
    5252}
    5353
    54 #ifndef NDEBUG
    55 static bool belongsToThisFloatingContext(const Box& layoutBox, const Box& floatingStateRoot)
    56 {
    57     auto& formattingContextRoot = layoutBox.formattingContextRoot();
    58     if (&formattingContextRoot == &floatingStateRoot)
    59         return true;
    60 
    61     // Maybe the layout box belongs to an inline formatting context that inherits the floating state from the parent (block) formatting context.
    62     if (!formattingContextRoot.establishesInlineFormattingContext())
    63         return false;
    64 
    65     return &formattingContextRoot.formattingContextRoot() == &floatingStateRoot;
    66 }
    67 #endif
    68 
    6954void FloatingState::remove(const Box& layoutBox)
    7055{
     
    7863}
    7964
    80 void FloatingState::append(const Box& layoutBox)
     65void FloatingState::append(FloatItem floatItem)
    8166{
    8267    ASSERT(is<Container>(*m_formattingContextRoot));
    83     ASSERT(belongsToThisFloatingContext(layoutBox, *m_formattingContextRoot));
    84     ASSERT(is<Container>(*m_formattingContextRoot));
    8568
    86     auto newFloatItem = FloatItem { layoutBox, FormattingContext::mapBoxToAncestor(layoutState(), layoutBox, downcast<Container>(root()))};
    8769    if (m_floats.isEmpty())
    88         return m_floats.append(newFloatItem);
     70        return m_floats.append(floatItem);
    8971
    90     auto& displayBox = m_layoutState.displayBoxForLayoutBox(layoutBox);
    91     auto isLeftPositioned = layoutBox.isLeftFloatingPositioned();
     72    auto isLeftPositioned = floatItem.isLeftPositioned();
    9273    // When adding a new float item to the list, we have to ensure that it is definitely the left(right)-most item.
    9374    // Normally it is, but negative horizontal margins can push the float box beyond another float box.
    9475    // Float items in m_floats list should stay in horizontal position order (left/right edge) on the same vertical position.
    95     auto hasNegativeHorizontalMargin = (isLeftPositioned && displayBox.marginStart() < 0) || (!isLeftPositioned && displayBox.marginEnd() < 0);
     76    auto horizontalMargin = floatItem.horizontalMargin();
     77    auto hasNegativeHorizontalMargin = (isLeftPositioned && horizontalMargin.start < 0) || (!isLeftPositioned && horizontalMargin.end < 0);
    9678    if (!hasNegativeHorizontalMargin)
    97         return m_floats.append(newFloatItem);
     79        return m_floats.append(floatItem);
    9880
    9981    for (int i = m_floats.size() - 1; i >= 0; --i) {
     
    10183        if (isLeftPositioned != floatItem.isLeftPositioned())
    10284            continue;
    103         if (newFloatItem.rectWithMargin().top() < floatItem.rectWithMargin().bottom())
     85        if (floatItem.rectWithMargin().top() < floatItem.rectWithMargin().bottom())
    10486            continue;
    105         if ((isLeftPositioned && newFloatItem.rectWithMargin().right() >= floatItem.rectWithMargin().right())
    106             || (!isLeftPositioned && newFloatItem.rectWithMargin().left() <= floatItem.rectWithMargin().left()))
    107             return m_floats.insert(i + 1, newFloatItem);
     87        if ((isLeftPositioned && floatItem.rectWithMargin().right() >= floatItem.rectWithMargin().right())
     88            || (!isLeftPositioned && floatItem.rectWithMargin().left() <= floatItem.rectWithMargin().left()))
     89            return m_floats.insert(i + 1, floatItem);
    10890    }
    109     return m_floats.insert(0, newFloatItem);
     91    return m_floats.insert(0, floatItem);
    11092}
    11193
  • trunk/Source/WebCore/layout/floats/FloatingState.h

    r249438 r249439  
    3939namespace Layout {
    4040
     41class FloatingContext;
    4142class FormattingState;
    4243class LayoutState;
     
    4748public:
    4849    static Ref<FloatingState> create(LayoutState& layoutState, const Box& formattingContextRoot) { return adoptRef(*new FloatingState(layoutState, formattingContextRoot)); }
    49 
    50     void append(const Box& layoutBox);
    51     void remove(const Box& layoutBox);
    5250
    5351    const Box& root() const { return *m_formattingContextRoot; }
     
    6866
    6967        Display::Rect rectWithMargin() const { return m_absoluteDisplayBox.rectWithMargin(); }
     68        UsedHorizontalMargin horizontalMargin() const { return m_absoluteDisplayBox.horizontalMargin(); }
    7069        PositionInContextRoot bottom() const { return { m_absoluteDisplayBox.bottom() }; }
    7170
     
    8180    friend class FloatingContext;
    8281    FloatingState(LayoutState&, const Box& formattingContextRoot);
     82
     83    void append(FloatItem);
     84    void remove(const Box& layoutBox);
    8385
    8486    LayoutState& layoutState() const { return m_layoutState; }
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp

    r249433 r249439  
    365365    auto& formattingContext = this->formattingContext();
    366366    auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(formattingRoot()));
    367     auto& floatingState = formattingState.floatingState();
    368     auto floatingContext = FloatingContext { formattingRoot(), floatingState };
     367    auto floatingContext = FloatingContext { formattingRoot(), formattingState.floatingState() };
    369368
    370369    // Move floats to their final position.
     
    377376        // Float it.
    378377        displayBox.setTopLeft(floatingContext.positionForFloat(floatBox));
    379         floatingState.append(floatBox);
     378        floatingContext.append(floatBox);
    380379    }
    381380
Note: See TracChangeset for help on using the changeset viewer.