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

Changeset 232154 in webkit


Ignore:
Timestamp:
May 24, 2018, 9:57:24 AM (8 years ago)
Author:
Alan Bujtas
Message:

[LFC] Implement position computation for inflow positioned elements
​https://bugs.webkit.org/show_bug.cgi?id=185936

Reviewed by Antti Koivisto.

  • layout/blockformatting/BlockFormattingContext.cpp:

(WebCore::Layout::BlockFormattingContext::computeInFlowPositionedPosition const):

  • layout/blockformatting/BlockFormattingContext.h:
  • layout/blockformatting/BlockFormattingContextGeometry.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::inFlowPositionedPosition):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232152 r232154  
     12018-05-24  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Implement position computation for inflow positioned elements
     4        https://bugs.webkit.org/show_bug.cgi?id=185936
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * layout/blockformatting/BlockFormattingContext.cpp:
     9        (WebCore::Layout::BlockFormattingContext::computeInFlowPositionedPosition const):
     10        * layout/blockformatting/BlockFormattingContext.h:
     11        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     12        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowPositionedPosition):
     13
    1142018-05-24  Zalan Bujtas  <zalan@apple.com>
    215
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r232152 r232154  
    135135}
    136136
     137void BlockFormattingContext::computeInFlowPositionedPosition(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
     138{
     139    auto topLeft = Geometry::inFlowPositionedPosition(layoutContext, layoutBox);
     140    displayBox.setTopLeft(topLeft);
     141}
     142
    137143void BlockFormattingContext::computeInFlowHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
    138144{
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r232114 r232154  
    5353private:
    5454    void computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const override;
     55    void computeInFlowPositionedPosition(LayoutContext&, const Box&, Display::Box&) const override;
    5556    void computeInFlowWidth(LayoutContext&, const Box&, Display::Box&) const override;
    5657    void computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const override;
    … …  
    6667
    6768        static LayoutPoint staticPosition(LayoutContext&, const Box&);
     69        static LayoutPoint inFlowPositionedPosition(LayoutContext&, const Box&);
    6870    };
    6971};
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r232114 r232154  
    138138}
    139139
     140LayoutPoint BlockFormattingContext::Geometry::inFlowPositionedPosition(LayoutContext& layoutContext, const Box& layoutBox)
     141{
     142    ASSERT(layoutBox.isInFlowPositioned());
     143    // 9.4.3 Relative positioning
     144    //
     145    // The 'top' and 'bottom' properties move relatively positioned element(s) up or down without changing their size.
     146    // Top' moves the boxes down, and 'bottom' moves them up. Since boxes are not split or stretched as a result of 'top' or 'bottom', the used values are always: top = -bottom.
     147    //
     148    // 1. If both are 'auto', their used values are both '0'.
     149    // 2. If one of them is 'auto', it becomes the negative of the other.
     150    // 3. If neither is 'auto', 'bottom' is ignored (i.e., the used value of 'bottom' will be minus the value of 'top').
     151    auto& displayBox = *layoutContext.displayBoxForLayoutBox(layoutBox);
     152    auto& style = layoutBox.style();
     153
     154    auto top = style.logicalTop();
     155    auto bottom = style.logicalBottom();
     156    LayoutUnit topDelta;
     157
     158    if (top.isAuto() && bottom.isAuto()) {
     159        // #1
     160        topDelta = 0;
     161    } else if (top.isAuto()) {
     162        // #2
     163        topDelta = -bottom.value();
     164    } else if (bottom.isAuto()) {
     165        // #3 #4
     166        topDelta = top.value();
     167    }
     168
     169    // For relatively positioned elements, 'left' and 'right' move the box(es) horizontally, without changing their size.
     170    // 'Left' moves the boxes to the right, and 'right' moves them to the left.
     171    // Since boxes are not split or stretched as a result of 'left' or 'right', the used values are always: left = -right.
     172    //
     173    // 1. If both 'left' and 'right' are 'auto' (their initial values), the used values are '0' (i.e., the boxes stay in their original position).
     174    // 2. If 'left' is 'auto', its used value is minus the value of 'right' (i.e., the boxes move to the left by the value of 'right').
     175    // 3. If 'right' is specified as 'auto', its used value is minus the value of 'left'.
     176    // 4. If neither 'left' nor 'right' is 'auto', the position is over-constrained, and one of them has to be ignored.
     177    //    If the 'direction' property of the containing block is 'ltr', the value of 'left' wins and 'right' becomes -'left'.
     178    //    If 'direction' of the containing block is 'rtl', 'right' wins and 'left' is ignored.
     179    //
     180    auto left = style.logicalLeft();
     181    auto right = style.logicalRight();
     182    LayoutUnit leftDelta;
     183
     184    if (left.isAuto() && right.isAuto()) {
     185        // #1
     186        leftDelta = 0;
     187    } else if (left.isAuto()) {
     188        // #2
     189        leftDelta = -right.value();
     190    } else if (right.isAuto()) {
     191        // #3
     192        leftDelta = left.value();
     193    } else {
     194        // #4
     195        // FIXME: take direction into account
     196        leftDelta = left.value();
     197    }
     198
     199    return { displayBox.left() + leftDelta, displayBox.top() + topDelta };
     200}
     201
    140202}
    141203}
Note: See TracChangeset for help on using the changeset viewer.