Changeset 232109 in webkit


Ignore:
Timestamp:
May 23, 2018 7:46:39 AM (6 years ago)
Author:
Alan Bujtas
Message:

[LFC] Implement positioning for replaced out-of-flow elements
https://bugs.webkit.org/show_bug.cgi?id=185902

Reviewed by Antti Koivisto.

  • layout/FormattingContext.cpp:

(WebCore::Layout::FormattingContext::computeOutOfFlowReplacedPosition const):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232103 r232109  
     12018-05-23  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Implement positioning for replaced out-of-flow elements
     4        https://bugs.webkit.org/show_bug.cgi?id=185902
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * layout/FormattingContext.cpp:
     9        (WebCore::Layout::FormattingContext::computeOutOfFlowReplacedPosition const):
     10
    1112018-05-22  Myles C. Maxfield  <mmaxfield@apple.com>
    212
  • trunk/Source/WebCore/layout/FormattingContext.cpp

    r232065 r232109  
    544544}
    545545
    546 void FormattingContext::computeOutOfFlowReplacedPosition(LayoutContext&, const Box&, Display::Box&) const
    547 {
    548 
     546void FormattingContext::computeOutOfFlowReplacedPosition(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
     547{
     548    // 10.6.5 Absolutely positioned, replaced elements (top/bottom)
     549    // 10.3.8 Absolutely positioned, replaced elements (left/right)
     550
     551    // At this point we've the size computed.
     552    auto size = displayBox.size();
     553    auto& style = layoutBox.style();
     554
     555    // 10.6.5 Absolutely positioned, replaced elements
     556    //
     557    // This situation is similar to the previous one, except that the element has an intrinsic height. The sequence of substitutions is now:
     558    // The used value of 'height' is determined as for inline replaced elements. If 'margin-top' or 'margin-bottom' is specified as 'auto'
     559    // its used value is determined by the rules below.
     560    //
     561    // 1. If both 'top' and 'bottom' have the value 'auto', replace 'top' with the element's static position.
     562    // 2. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or 'margin-bottom' with '0'.
     563    // 3. If at this point both 'margin-top' and 'margin-bottom' are still 'auto', solve the equation under the extra constraint that the two margins must get equal values.
     564    // 4. If at this point there is only one 'auto' left, solve the equation for that value.
     565    // 5. If at this point the values are over-constrained, ignore the value for 'bottom' and solve for that value.
     566    auto top = style.logicalTop();
     567    auto bottom = style.logicalBottom();
     568    auto containingBlockHeight = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->height();
     569    LayoutUnit computedTopValue;
     570
     571    if (!top.isAuto())
     572        computedTopValue = valueForLength(top, containingBlockHeight);
     573    else if (bottom.isAuto()) {
     574        // #1
     575        computedTopValue = displayBox.top();
     576    } else {
     577        // #4
     578        auto marginTop = displayBox.marginTop();
     579        auto marginBottom = displayBox.marginBottom();
     580
     581        auto paddingTop = displayBox.paddingTop();
     582        auto paddingBottom = displayBox.paddingBottom();
     583
     584        auto borderTop = displayBox.borderTop();
     585        auto borderBottom = displayBox.borderBottom();
     586
     587        computedTopValue = containingBlockHeight - (marginTop + borderTop + paddingTop + size.height() + paddingBottom + borderBottom + marginBottom + bottom.value());
     588    }
     589
     590    displayBox.setTop(computedTopValue);
     591
     592
     593    // 10.3.8 Absolutely positioned, replaced elements
     594    //
     595    // In this case, section 10.3.7 applies up through and including the constraint equation, but the rest of section 10.3.7 is replaced by the following rules:
     596    //
     597    // The used value of 'width' is determined as for inline replaced elements.
     598    //
     599    // 1. If 'margin-left' or 'margin-right' is specified as 'auto' its used value is determined by the rules below.
     600    // 2. If both 'left' and 'right' have the value 'auto', then if the 'direction' property of the element establishing the
     601    //    static-position containing block is 'ltr', set 'left' to the static position; else if 'direction' is 'rtl', set 'right' to the static position.
     602    // 3. If 'left' or 'right' are 'auto', replace any 'auto' on 'margin-left' or 'margin-right' with '0'.
     603    // 4. If at this point both 'margin-left' and 'margin-right' are still 'auto', solve the equation under the extra constraint
     604    //    that the two margins must get equal values, unless this would make them negative, in which case when the direction of
     605    //    the containing block is 'ltr' ('rtl'), set 'margin-left' ('margin-right') to zero and solve for 'margin-right' ('margin-left').
     606    // 5. If at this point there is an 'auto' left, solve the equation for that value.
     607    // 6. If at this point the values are over-constrained, ignore the value for either 'left' (in case the 'direction'
     608    //    property of the containing block is 'rtl') or 'right' (in case 'direction' is 'ltr') and solve for that value.
     609    auto left = style.logicalLeft();
     610    auto right = style.logicalRight();
     611    auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width();
     612    LayoutUnit computedLeftValue;
     613
     614    if (!left.isAuto())   
     615        computedLeftValue = valueForLength(left, containingBlockWidth);
     616    else if (right.isAuto()) {
     617        // FIXME: take direction into account
     618        computedLeftValue = displayBox.left();
     619    } else {
     620        // #5
     621        auto marginLeft = displayBox.marginLeft();
     622        auto marginRight = displayBox.marginRight();
     623   
     624        auto paddingLeft = displayBox.paddingLeft();
     625        auto paddingRight = displayBox.paddingRight();
     626
     627        auto borderLeft = displayBox.borderLeft();
     628        auto borderRight = displayBox.borderRight();
     629
     630        computedLeftValue = containingBlockWidth - (marginLeft + borderLeft + paddingLeft + size.width() + paddingRight + borderRight + marginRight + right.value());
     631    }
     632
     633    displayBox.setLeft(computedLeftValue);
    549634}
    550635
Note: See TracChangeset for help on using the changeset viewer.