Changeset 231953 in webkit


Ignore:
Timestamp:
May 18, 2018 7:31:02 AM (6 years ago)
Author:
Alan Bujtas
Message:

[LFC] Implement height computation for replaced elements.
https://bugs.webkit.org/show_bug.cgi?id=185756

Reviewed by Antti Koivisto.

  • layout/FormattingContext.cpp:

(WebCore::Layout::FormattingContext::computeHeight const):
(WebCore::Layout::FormattingContext::computeOutOfFlowWidth const):
(WebCore::Layout::FormattingContext::computeOutOfFlowHeight const):
(WebCore::Layout::FormattingContext::computeFloatingHeight const):
(WebCore::Layout::FormattingContext::computeReplacedHeight const):
(WebCore::Layout::FormattingContext::computeReplacedWidth const):
(WebCore::Layout::FormattingContext::computeOutOfFlowReplacedHeight const):

  • layout/FormattingContext.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r231952 r231953  
     12018-05-18  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Implement height computation for replaced elements.
     4        https://bugs.webkit.org/show_bug.cgi?id=185756
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * layout/FormattingContext.cpp:
     9        (WebCore::Layout::FormattingContext::computeHeight const):
     10        (WebCore::Layout::FormattingContext::computeOutOfFlowWidth const):
     11        (WebCore::Layout::FormattingContext::computeOutOfFlowHeight const):
     12        (WebCore::Layout::FormattingContext::computeFloatingHeight const):
     13        (WebCore::Layout::FormattingContext::computeReplacedHeight const):
     14        (WebCore::Layout::FormattingContext::computeReplacedWidth const):
     15        (WebCore::Layout::FormattingContext::computeOutOfFlowReplacedHeight const):
     16        * layout/FormattingContext.h:
     17
    1182018-05-18  Zalan Bujtas  <zalan@apple.com>
    219
  • trunk/Source/WebCore/layout/FormattingContext.cpp

    r231952 r231953  
    7575        return computeOutOfFlowHeight(layoutContext, layoutBox, displayBox);
    7676    if (layoutBox.isFloatingPositioned())
    77         return computeFloatingHeight(layoutBox, displayBox);
     77        return computeFloatingHeight(layoutContext, layoutBox, displayBox);
    7878    return computeInFlowHeight(layoutContext, layoutBox, displayBox);
    7979}
     
    8585        return;
    8686    }
    87     ASSERT_NOT_IMPLEMENTED_YET();
     87    computeOutOfFlowReplacedWidth(layoutContext, layoutBox, displayBox);
    8888}
    8989
     
    103103        return;
    104104    }
    105     ASSERT_NOT_IMPLEMENTED_YET();
    106 }
    107 
    108 void FormattingContext::computeFloatingHeight(const Box&, Display::Box&) const
    109 {
     105    computeOutOfFlowReplacedHeight(layoutContext, layoutBox, displayBox);
     106}
     107
     108void FormattingContext::computeFloatingHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
     109{
     110    if (!layoutBox.replaced()) {
     111        ASSERT_NOT_IMPLEMENTED_YET();
     112        return;
     113    }
     114    computeReplacedHeight(layoutContext, layoutBox, displayBox);
    110115}
    111116
     
    209214    else
    210215        ASSERT_NOT_REACHED();
     216
     217    displayBox.setHeight(computedHeightValue);
     218}
     219
     220void FormattingContext::computeReplacedHeight(LayoutContext&, const Box& layoutBox, Display::Box& displayBox) const
     221{
     222    ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
     223    // 10.6.5 Absolutely positioned, replaced elements. The used value of 'height' is determined as for inline replaced elements.
     224
     225    // 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements
     226    //
     227    // 1. If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic height, then that intrinsic height is the used value of 'height'.
     228    //
     229    // 2. Otherwise, if 'height' has a computed value of 'auto', and the element has an intrinsic ratio then the used value of 'height' is:
     230    //    (used width) / (intrinsic ratio)
     231    //
     232    // 3. Otherwise, if 'height' has a computed value of 'auto', and the element has an intrinsic height, then that intrinsic height is the used value of 'height'.
     233    //
     234    // 4. Otherwise, if 'height' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'height' must be set to
     235    //    the height of the largest rectangle that has a 2:1 ratio, has a height not greater than 150px, and has a width not greater than the device width.
     236    auto& style = layoutBox.style();
     237    auto width = style.logicalWidth();
     238    auto height = style.logicalHeight();
     239
     240    LayoutUnit computedHeightValue;
     241    auto replaced = layoutBox.replaced();
     242    ASSERT(replaced);
     243
     244    if (height.isAuto()) {
     245        if (width.isAuto() && replaced->hasIntrinsicHeight()) {
     246            // #1
     247            computedHeightValue = replaced->intrinsicHeight();
     248        } else if (replaced->hasIntrinsicRatio()) {
     249            // #2
     250            computedHeightValue = width.value() / replaced->intrinsicRatio();
     251        } else if (replaced->hasIntrinsicHeight()) {
     252            // #3
     253            computedHeightValue = replaced->intrinsicHeight();
     254        } else {
     255            // #4
     256            computedHeightValue = 150;
     257        }
     258    } else
     259        computedHeightValue = height.value();
    211260
    212261    displayBox.setHeight(computedHeightValue);
     
    264313    }
    265314
    266     displayBox.setWidth(computedWidthValue);   
     315    displayBox.setWidth(computedWidthValue);
    267316}
    268317
     
    360409}
    361410
     411void FormattingContext::computeOutOfFlowReplacedHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
     412{
     413    ASSERT(layoutBox.isOutOfFlowPositioned() && layoutBox.replaced());
     414    // 10.6.5 Absolutely positioned, replaced elements
     415    //
     416    // The used value of 'height' is determined as for inline replaced elements.
     417    computeReplacedHeight(layoutContext, layoutBox, displayBox);
     418}
     419
    362420void FormattingContext::computeOutOfFlowReplacedWidth(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
    363421{
  • trunk/Source/WebCore/layout/FormattingContext.h

    r231952 r231953  
    7777
    7878    virtual void computeOutOfFlowHeight(LayoutContext&, const Box&, Display::Box&) const;
    79     virtual void computeFloatingHeight(const Box&, Display::Box&) const;
     79    virtual void computeFloatingHeight(LayoutContext&, const Box&, Display::Box&) const;
    8080    virtual void computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const = 0;
    8181
     
    8888    void layoutOutOfFlowDescendants(LayoutContext&s) const;
    8989
     90    void computeReplacedHeight(LayoutContext&, const Box&, Display::Box&) const;
    9091    void computeReplacedWidth(LayoutContext&, const Box&, Display::Box&) const;
    9192
     
    9394    void computeOutOfFlowNonReplacedHeight(LayoutContext&, const Box&, Display::Box&) const;
    9495    void computeOutOfFlowNonReplacedWidth(LayoutContext&, const Box&, Display::Box&) const;
     96    void computeOutOfFlowReplacedHeight(LayoutContext&, const Box&, Display::Box&) const;
    9597    void computeOutOfFlowReplacedWidth(LayoutContext&, const Box&, Display::Box&) const;
    9698
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r231897 r231953  
    190190        return;
    191191    }
    192     ASSERT_NOT_IMPLEMENTED_YET();
     192    computeReplacedHeight(layoutContext, layoutBox, displayBox);
    193193}
    194194
Note: See TracChangeset for help on using the changeset viewer.