Changeset 231847 in webkit


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

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

Reviewed by Antti Koivisto.

Replaced width for block, inline and float elements compute the same way.

  • layout/FormattingContext.cpp:

(WebCore::Layout::FormattingContext::computeWidth const):
(WebCore::Layout::FormattingContext::computeFloatingWidth const):
(WebCore::Layout::FormattingContext::computeInFlowReplacedWidth const):

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

(WebCore::Layout::BlockFormattingContext::computeInFlowWidth const):

  • layout/layouttree/LayoutBox.cpp:

(WebCore::Layout::Box::hasIntrinsicWidth const):
(WebCore::Layout::Box::hasIntrinsicHeight const):
(WebCore::Layout::Box::hasIntrinsicRatio const):
(WebCore::Layout::Box::intrinsicWidth const):
(WebCore::Layout::Box::intrinsicHeight const):
(WebCore::Layout::Box::intrinsicRatio const):

  • layout/layouttree/LayoutBox.h:
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r231846 r231847  
     12018-05-16  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Implement width computation for replaced inflow elements.
     4        https://bugs.webkit.org/show_bug.cgi?id=185672
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Replaced width for block, inline and float elements compute the same way.
     9
     10        * layout/FormattingContext.cpp:
     11        (WebCore::Layout::FormattingContext::computeWidth const):
     12        (WebCore::Layout::FormattingContext::computeFloatingWidth const):
     13        (WebCore::Layout::FormattingContext::computeInFlowReplacedWidth const):
     14        * layout/FormattingContext.h:
     15        * layout/blockformatting/BlockFormattingContext.cpp:
     16        (WebCore::Layout::BlockFormattingContext::computeInFlowWidth const):
     17        * layout/layouttree/LayoutBox.cpp:
     18        (WebCore::Layout::Box::hasIntrinsicWidth const):
     19        (WebCore::Layout::Box::hasIntrinsicHeight const):
     20        (WebCore::Layout::Box::hasIntrinsicRatio const):
     21        (WebCore::Layout::Box::intrinsicWidth const):
     22        (WebCore::Layout::Box::intrinsicHeight const):
     23        (WebCore::Layout::Box::intrinsicRatio const):
     24        * layout/layouttree/LayoutBox.h:
     25
    1262018-05-16  Zalan Bujtas  <zalan@apple.com>
    227
  • trunk/Source/WebCore/layout/FormattingContext.cpp

    r231786 r231847  
    6666        return computeOutOfFlowWidth(layoutContext, layoutBox, displayBox);
    6767    if (layoutBox.isFloatingPositioned())
    68         return computeFloatingWidth(layoutBox, displayBox);
     68        return computeFloatingWidth(layoutContext, layoutBox, displayBox);
    6969    return computeInFlowWidth(layoutContext, layoutBox, displayBox);
    7070}
     
    8888}
    8989
    90 void FormattingContext::computeFloatingWidth(const Box&, Display::Box&) const
    91 {
     90void FormattingContext::computeFloatingWidth(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
     91{
     92    if (!layoutBox.isReplaced()) {
     93        ASSERT_NOT_REACHED();
     94        return;
     95    }
     96    computeInFlowReplacedWidth(layoutContext, layoutBox, displayBox);
    9297}
    9398
     
    204209}
    205210
     211void FormattingContext::computeInFlowReplacedWidth(LayoutContext&, const Box& layoutBox, Display::Box& displayBox) const
     212{
     213    // 10.3.4 Block-level, replaced elements in normal flow: The used value of 'width' is determined as for inline replaced elements
     214    // 10.3.6 Floating, replaced elements: The used value of 'width' is determined as for inline replaced elements.   
     215
     216    // 10.3.2 Inline, replaced elements
     217    //
     218    // 1. If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width, then that intrinsic width is the used value of 'width'.
     219    //
     220    // 2. If 'height' and 'width' both have computed values of 'auto' and the element has no intrinsic width, but does have an intrinsic height and intrinsic ratio;
     221    //    or if 'width' has a computed value of 'auto', 'height' has some other computed value, and the element does have an intrinsic ratio;
     222    //    then the used value of 'width' is: (used height) * (intrinsic ratio)
     223    //
     224    // 3. If 'height' and 'width' both have computed values of 'auto' and the element has an intrinsic ratio but no intrinsic height or width,
     225    //    then the used value of 'width' is undefined in CSS 2.2. However, it is suggested that, if the containing block's width does not itself depend on the replaced
     226    //    element's width, then the used value of 'width' is calculated from the constraint equation used for block-level, non-replaced elements in normal flow.
     227    //
     228    // 4. Otherwise, if 'width' has a computed value of 'auto', and the element has an intrinsic width, then that intrinsic width is the used value of 'width'.
     229    //
     230    // 5. Otherwise, if 'width' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'width' becomes 300px.
     231    //    If 300px is too wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead.
     232    auto& style = layoutBox.style();
     233    auto width = style.logicalWidth();
     234    auto height = style.logicalHeight();
     235
     236    LayoutUnit computedWidthValue;
     237
     238    if (width.isAuto() && height.isAuto() && layoutBox.hasIntrinsicWidth()) {
     239        // #1
     240        computedWidthValue = layoutBox.intrinsicWidth();
     241    } else if (width.isAuto() && (height.isCalculated() || layoutBox.hasIntrinsicHeight()) && layoutBox.hasIntrinsicRatio()) {
     242        // #2
     243        auto usedHeight = height.isCalculated() ? LayoutUnit(height.value()) : layoutBox.intrinsicHeight();   
     244        computedWidthValue = usedHeight * layoutBox.intrinsicRatio();
     245    } else if (width.isAuto() && height.isAuto() && layoutBox.hasIntrinsicRatio()) {
     246        // #3
     247        // FIXME: undefined but surely doable.
     248        ASSERT_NOT_REACHED();
     249    } else if (width.isAuto() && layoutBox.hasIntrinsicWidth()) {
     250        // #4
     251        computedWidthValue = layoutBox.intrinsicWidth();
     252    } else {
     253        // #5
     254        computedWidthValue = 300;
     255    }
     256
     257    displayBox.setWidth(computedWidthValue);   
     258}
     259
    206260LayoutUnit FormattingContext::contentHeightForFormattingContextRoot(LayoutContext& layoutContext, const Box& layoutBox) const
    207261{
  • trunk/Source/WebCore/layout/FormattingContext.h

    r231786 r231847  
    7373
    7474    virtual void computeOutOfFlowWidth(LayoutContext&, const Box&, Display::Box&) const;
    75     virtual void computeFloatingWidth(const Box&, Display::Box&) const;
     75    virtual void computeFloatingWidth(LayoutContext&, const Box&, Display::Box&) const;
    7676    virtual void computeInFlowWidth(LayoutContext&, const Box&, Display::Box&) const = 0;
    7777
     
    8888    void layoutOutOfFlowDescendants(LayoutContext&s) const;
    8989
     90    void computeInFlowReplacedWidth(LayoutContext&, const Box&, Display::Box&) const;
     91
    9092private:
    9193    void computeOutOfFlowNonReplacedHeight(LayoutContext&, const Box&, Display::Box&) const;
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r231786 r231847  
    150150        return;
    151151    }
    152     ASSERT_NOT_REACHED();
     152    computeInFlowReplacedWidth(layoutContext, layoutBox, displayBox);
    153153}
    154154
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp

    r231642 r231847  
    231231}
    232232
     233bool Box::hasIntrinsicWidth() const
     234{
     235    return false;
     236}
     237
     238bool Box::hasIntrinsicHeight() const
     239{
     240    return false;
     241}
     242
     243bool Box::hasIntrinsicRatio() const
     244{
     245    return false;
     246}
     247
     248LayoutUnit Box::intrinsicWidth() const
     249{
     250    ASSERT(hasIntrinsicWidth());
     251    return { };
     252}
     253
     254LayoutUnit Box::intrinsicHeight() const
     255{
     256    ASSERT(hasIntrinsicHeight());
     257    return { };
     258}
     259
     260LayoutUnit Box::intrinsicRatio() const
     261{
     262    ASSERT(hasIntrinsicRatio());
     263    return { };
     264}
     265
    233266}
    234267}
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.h

    r231642 r231847  
    7373    bool isBlockContainerBox() const;
    7474    bool isInitialContainingBlock() const;
    75     bool isReplaced() const;
    7675
    7776    const Container* parent() const { return m_parent; }
     
    9190    const RenderStyle& style() const { return m_style; }
    9291    auto& weakPtrFactory() const { return m_weakFactory; }
     92
     93    bool isReplaced() const;
     94    // FIXME: find out how to not pollute the Box interface
     95    bool hasIntrinsicWidth() const;
     96    bool hasIntrinsicHeight() const;
     97    bool hasIntrinsicRatio() const;
     98    LayoutUnit intrinsicWidth() const;
     99    LayoutUnit intrinsicHeight() const;
     100    LayoutUnit intrinsicRatio() const;
    93101
    94102protected:
Note: See TracChangeset for help on using the changeset viewer.