⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 237452 in webkit


Ignore:
Timestamp:
Oct 26, 2018, 7:29:22 AM (8 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Find floating constraints for a given vertical position
​https://bugs.webkit.org/show_bug.cgi?id=190928

Reviewed by Antti Koivisto.

​https://www.w3.org/TR/CSS22/visuren.html#inline-formatting

"In general, the left edge of a line box touches the left edge of its containing block and the right edge touches the right edge of its containing block.
However, floating boxes may come between the containing block edge and the line box edge.
Thus, although line boxes in the same inline formatting context generally have the same width
(that of the containing block), they may vary in width if available horizontal space is reduced due to floats."

This patch adds support for retrieving left/right constraints for a given line (vertical position).

  • layout/floats/FloatingState.cpp:

(WebCore::Layout::FloatingState::constraints const):

  • layout/floats/FloatingState.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r237451 r237452  
     12018-10-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Find floating constraints for a given vertical position
     4        https://bugs.webkit.org/show_bug.cgi?id=190928
     5
     6        Reviewed by Antti Koivisto.
     7
     8        https://www.w3.org/TR/CSS22/visuren.html#inline-formatting
     9
     10        "In general, the left edge of a line box touches the left edge of its containing block and the right edge touches the right edge of its containing block.
     11        However, floating boxes may come between the containing block edge and the line box edge.
     12        Thus, although line boxes in the same inline formatting context generally have the same width
     13        (that of the containing block), they may vary in width if available horizontal space is reduced due to floats."
     14
     15        This patch adds support for retrieving left/right constraints for a given line (vertical position).
     16
     17        * layout/floats/FloatingState.cpp:
     18        (WebCore::Layout::FloatingState::constraints const):
     19        * layout/floats/FloatingState.h:
     20
    1212018-10-26  Zalan Bujtas  <zalan@apple.com>
    222
  • trunk/Source/WebCore/layout/floats/FloatingState.cpp

    r235735 r237452  
    8787}
    8888
     89FloatingState::Constraints FloatingState::constraints(LayoutUnit verticalPosition, const Box& formattingContextRoot) const
     90{
     91    if (isEmpty())
     92        return { };
     93
     94    // 1. Convert vertical position if this floating context is inherited.
     95    // 2. Find the inner left/right floats at verticalPosition.
     96    // 3. Convert left/right positions back to formattingContextRoot's cooridnate system.
     97    auto coordinateMappingIsRequired = &root() != &formattingContextRoot;
     98    auto adjustedPosition = Position { 0, verticalPosition };
     99
     100    if (coordinateMappingIsRequired)
     101        adjustedPosition = FormattingContext::mapCoordinateToAncestor(m_layoutContext, adjustedPosition, downcast<Container>(formattingContextRoot), downcast<Container>(root()));
     102
     103    Constraints constraints;
     104    for (int index = m_floats.size() - 1; index >= 0; --index) {
     105        auto& floatItem = m_floats[index];
     106
     107        if (constraints.left && floatItem.isLeftPositioned())
     108            continue;
     109
     110        if (constraints.right && !floatItem.isLeftPositioned())
     111            continue;
     112
     113        auto rect = floatItem.rectWithMargin();
     114        if (!(rect.top() <= verticalPosition && verticalPosition < rect.bottom()))
     115            continue;
     116
     117        if (floatItem.isLeftPositioned())
     118            constraints.left = rect.right();
     119        else
     120            constraints.right = rect.left();
     121
     122        if (constraints.left && constraints.right)
     123            break;
     124    }
     125
     126    if (coordinateMappingIsRequired) {
     127        if (constraints.left)
     128            constraints.left = *constraints.left - adjustedPosition.x;
     129
     130        if (constraints.right)
     131            constraints.right = *constraints.right - adjustedPosition.x;
     132    }
     133
     134    return constraints;
     135}
     136
    89137std::optional<LayoutUnit> FloatingState::bottom(const Box& formattingContextRoot, Clear type) const
    90138{
  • trunk/Source/WebCore/layout/floats/FloatingState.h

    r235735 r237452  
    5858    std::optional<LayoutUnit> rightBottom(const Box& formattingContextRoot) const;
    5959    std::optional<LayoutUnit> bottom(const Box& formattingContextRoot) const;
     60
     61    struct Constraints {
     62        std::optional<LayoutUnit> left;
     63        std::optional<LayoutUnit> right;
     64    };
     65    Constraints constraints(LayoutUnit verticalPosition, const Box& formattingContextRoot) const;
    6066
    6167    class FloatItem {
Note: See TracChangeset for help on using the changeset viewer.