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

Changeset 238667 in webkit


Ignore:
Timestamp:
Nov 29, 2018, 7:28:20 AM (8 years ago)
Author:
Alan Bujtas
Message:

[LFC][Quirk] Move quirk functions to dedicated classes.
https://bugs.webkit.org/show_bug.cgi?id=192133

Reviewed by Antti Koivisto.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • layout/FormattingContext.h:
  • layout/FormattingContextGeometry.cpp:

(WebCore::Layout::FormattingContext::Geometry::computedHeightValue):

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

(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowHeightAndMargin):
(WebCore::Layout::initialContainingBlock): Deleted.
(WebCore::Layout::isStretchedToInitialContainingBlock): Deleted.
(WebCore::Layout::stretchHeightToInitialContainingBlockQuirk): Deleted.
(WebCore::Layout::stretchWidthToInitialContainingBlock): Deleted.

  • layout/blockformatting/BlockFormattingState.cpp:
  • layout/blockformatting/BlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::isMarginTopCollapsedWithParent):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginTop):
(WebCore::Layout::isQuirkContainer): Deleted.
(WebCore::Layout::hasMarginTopQuirkValue): Deleted.
(WebCore::Layout::shouldIgnoreMarginTopInQuirkContext): Deleted.
(WebCore::Layout::isMarginTopCollapsedWithParent): Deleted.

  • layout/inlineformatting/InlineFormattingContext.cpp:
  • layout/inlineformatting/text/TextUtil.h:
Location:
trunk/Source/WebCore
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r238666 r238667  
     12018-11-29  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][Quirk] Move quirk functions to dedicated classes.
     4        https://bugs.webkit.org/show_bug.cgi?id=192133
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * Sources.txt:
     9        * WebCore.xcodeproj/project.pbxproj:
     10        * layout/FormattingContext.h:
     11        * layout/FormattingContextGeometry.cpp:
     12        (WebCore::Layout::FormattingContext::Geometry::computedHeightValue):
     13        * layout/blockformatting/BlockFormattingContext.h:
     14        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     15        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
     16        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowHeightAndMargin):
     17        (WebCore::Layout::initialContainingBlock): Deleted.
     18        (WebCore::Layout::isStretchedToInitialContainingBlock): Deleted.
     19        (WebCore::Layout::stretchHeightToInitialContainingBlockQuirk): Deleted.
     20        (WebCore::Layout::stretchWidthToInitialContainingBlock): Deleted.
     21        * layout/blockformatting/BlockFormattingState.cpp:
     22        * layout/blockformatting/BlockMarginCollapse.cpp:
     23        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::isMarginTopCollapsedWithParent):
     24        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginTop):
     25        (WebCore::Layout::isQuirkContainer): Deleted.
     26        (WebCore::Layout::hasMarginTopQuirkValue): Deleted.
     27        (WebCore::Layout::shouldIgnoreMarginTopInQuirkContext): Deleted.
     28        (WebCore::Layout::isMarginTopCollapsedWithParent): Deleted.
     29        * layout/inlineformatting/InlineFormattingContext.cpp:
     30        * layout/inlineformatting/text/TextUtil.h:
     31
    1322018-11-29  Rob Buis  <rbuis@igalia.com>
    233
  • trunk/Source/WebCore/Sources.txt

    r238629 r238667  
    12631263layout/FormattingContext.cpp
    12641264layout/FormattingContextGeometry.cpp
     1265layout/FormattingContextQuirks.cpp
    12651266layout/FormattingState.cpp
    12661267layout/LayoutFormattingState.cpp
     
    12681269layout/blockformatting/BlockFormattingContext.cpp
    12691270layout/blockformatting/BlockFormattingContextGeometry.cpp
     1271layout/blockformatting/BlockFormattingContextQuirks.cpp
    12701272layout/blockformatting/BlockFormattingState.cpp
    12711273layout/blockformatting/BlockMarginCollapse.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r238657 r238667  
    91869186                6F7CA3C8208C2B2E002F29AB /* InlineFormattingContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InlineFormattingContext.h; sourceTree = "<group>"; };
    91879187                6F7CA3C9208C2B2E002F29AB /* InlineFormattingContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineFormattingContext.cpp; sourceTree = "<group>"; };
     9188                6F8F460121B03BB40041AC3A /* FormattingContextQuirks.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FormattingContextQuirks.cpp; sourceTree = "<group>"; };
     9189                6F8F460321B03BC60041AC3A /* BlockFormattingContextQuirks.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BlockFormattingContextQuirks.cpp; sourceTree = "<group>"; };
    91889190                6F995A091A7070E600A735F4 /* WebGLQuery.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebGLQuery.idl; sourceTree = "<group>"; };
    91899191                6F995A0A1A7070E600A735F4 /* WebGLSampler.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebGLSampler.idl; sourceTree = "<group>"; };
     
    1616616168                                115CFA68208AF7D0001E6991 /* FormattingContext.h */,
    1616716169                                6FBB860520B464B600DAD938 /* FormattingContextGeometry.cpp */,
     16170                                6F8F460121B03BB40041AC3A /* FormattingContextQuirks.cpp */,
    1616816171                                115CFA75208AFE30001E6991 /* FormattingState.cpp */,
    1616916172                                115CFA74208AFE30001E6991 /* FormattingState.h */,
     
    1621016213                                115CFA6C208AFAB6001E6991 /* BlockFormattingContext.h */,
    1621116214                                6F0830DF20B46951008A945B /* BlockFormattingContextGeometry.cpp */,
     16215                                6F8F460321B03BC60041AC3A /* BlockFormattingContextQuirks.cpp */,
    1621216216                                115CFA79208B8D9D001E6991 /* BlockFormattingState.cpp */,
    1621316217                                115CFA78208B8D9D001E6991 /* BlockFormattingState.h */,
  • trunk/Source/WebCore/layout/FormattingContext.h

    r238481 r238667  
    123123    };
    124124
     125    class Quirks {
     126    public:
     127        static LayoutUnit heightValueOfNearestContainingBlockWithFixedHeight(const LayoutState&, const Box&);
     128    };
     129
    125130private:
    126131    void computeOutOfFlowVerticalGeometry(const Box&) const;
  • trunk/Source/WebCore/layout/FormattingContextGeometry.cpp

    r238482 r238667  
    7373        containingBlockHeightValue = layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).height();
    7474    } else {
    75         auto computedHeightValueForQuirksMode = [&]() -> LayoutUnit {
    76             // In quirks mode, we go and travers the containing block chain to find a block level box with fixed height value, even if it means leaving
    77             // the current formatting context. FIXME: surely we need to do some tricks here when block direction support is added.
    78             auto* containingBlock = layoutBox.containingBlock();
    79             LayoutUnit bodyAndDocumentVerticalMarginsPaddingsAndBorders;
    80             while (containingBlock) {
    81                 auto containingBlockHeight = containingBlock->style().logicalHeight();
    82                 if (containingBlockHeight.isFixed())
    83                     return containingBlockHeight.value() - bodyAndDocumentVerticalMarginsPaddingsAndBorders;
    84 
    85                 // If the only fixed value box we find is the ICB, then ignore the body and the document (vertical) margin, padding and border. So much quirkiness.
    86                 // -and it's totally insane because now we freely travel across formatting context boundaries and computed margins are nonexistent.
    87                 if (containingBlock->isBodyBox() || containingBlock->isDocumentBox()) {
    88                     auto& displayBox = layoutState.displayBoxForLayoutBox(*containingBlock);
    89 
    90                     auto verticalMargins = computedNonCollapsedVerticalMarginValue(layoutState, *containingBlock);
    91                     auto verticalPaddings = displayBox.paddingTop().value_or(0) + displayBox.paddingBottom().value_or(0);
    92                     auto verticalBorders = displayBox.borderTop() + displayBox.borderBottom();
    93                     bodyAndDocumentVerticalMarginsPaddingsAndBorders += verticalMargins.top + verticalMargins.bottom + verticalPaddings + verticalBorders;
    94                 }
    95 
    96                 containingBlock = containingBlock->containingBlock();
    97             }
    98             // Initial containing block has to have a height.
    99             return layoutState.displayBoxForLayoutBox(layoutBox.initialContainingBlock()).contentBox().height() - bodyAndDocumentVerticalMarginsPaddingsAndBorders;
    100         };
    101 
    10275        if (layoutState.inQuirksMode())
    103             containingBlockHeightValue = computedHeightValueForQuirksMode();
     76            containingBlockHeightValue = FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight(layoutState, layoutBox);
    10477        else {
    10578            auto containingBlockHeight = layoutBox.containingBlock()->style().logicalHeight();
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r238481 r238667  
    101101            static LayoutUnit collapsedMarginTopFromFirstChild(const LayoutState&, const Box&);
    102102            static LayoutUnit nonCollapsedMarginTop(const LayoutState&, const Box&);
     103
     104            static bool isMarginTopCollapsedWithParent(const LayoutState&, const Box&);
    103105        };
    104106
     
    108110        static Point staticPositionForOutOfFlowPositioned(const LayoutState&, const Box&);
    109111    };
     112
     113    class Quirks {
     114    public:
     115        static bool isStretchedToInitialContainingBlock(const LayoutState&, const Box&);
     116        static HeightAndMargin stretchedHeight(const LayoutState&, const Box&, HeightAndMargin);
     117        static WidthAndMargin stretchedWidth(const LayoutState&, const Box&, WidthAndMargin);
     118        static bool shouldIgnoreMarginTop(const LayoutState&, const Box&);
     119    };
    110120};
    111121
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r238613 r238667  
    3838namespace Layout {
    3939
    40 static const Container& initialContainingBlock(const Box& layoutBox)
    41 {
    42     auto* containingBlock = layoutBox.containingBlock();
    43     while (containingBlock->containingBlock())
    44         containingBlock = containingBlock->containingBlock();
    45     return *containingBlock;
    46 }
    47 
    48 static bool isStretchedToInitialContainingBlock(const LayoutState& layoutState, const Box& layoutBox)
    49 {
    50     ASSERT(layoutBox.isInFlow());
    51     // In quirks mode, body and html stretch to the viewport.
    52     if (!layoutState.inQuirksMode())
    53         return false;
    54 
    55     if (!layoutBox.isDocumentBox() && !layoutBox.isBodyBox())
    56         return false;
    57 
    58     return layoutBox.style().logicalHeight().isAuto();
    59 }
    60 
    61 static HeightAndMargin stretchHeightToInitialContainingBlockQuirk(HeightAndMargin heightAndMargin, LayoutUnit initialContainingBlockHeight)
    62 {
    63     // This quirk happens when the body height is 0 which means its vertical margins collapse through (top and bottom margins are adjoining).
    64     // However now that we stretch the body they don't collapse through anymore, so we need to use the non-collapsed values instead.
    65     ASSERT(initialContainingBlockHeight);
    66     auto verticalMargins = heightAndMargin.height ? heightAndMargin.usedMarginValues() : heightAndMargin.margin;
    67     auto totalVerticalMargins = verticalMargins.top + verticalMargins.bottom;
    68     // Stretch but never overstretch with the margins.
    69     if (heightAndMargin.height + totalVerticalMargins < initialContainingBlockHeight)
    70         heightAndMargin.height = initialContainingBlockHeight - totalVerticalMargins;
    71 
    72     return heightAndMargin;
    73 }
    74 
    75 static WidthAndMargin stretchWidthToInitialContainingBlock(WidthAndMargin widthAndMargin, LayoutUnit initialContainingBlockWidth)
    76 {
    77     auto horizontalMargins = widthAndMargin.margin.left + widthAndMargin.margin.right;
    78     // Stretch but never overstretch with the margins.
    79     if (widthAndMargin.width + horizontalMargins < initialContainingBlockWidth)
    80         widthAndMargin.width = initialContainingBlockWidth - horizontalMargins;
    81 
    82     return widthAndMargin;
    83 }
    84 
    8540HeightAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin(const LayoutState& layoutState, const Box& layoutBox, std::optional<LayoutUnit> usedHeight)
    8641{
     
    241196
    242197    auto widthAndMargin = compute();
    243     if (!isStretchedToInitialContainingBlock(layoutState, layoutBox)) {
     198    if (!Quirks::isStretchedToInitialContainingBlock(layoutState, layoutBox)) {
    244199        LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow non-replaced -> width(" << widthAndMargin.width << "px) margin(" << widthAndMargin.margin.left << "px, " << widthAndMargin.margin.right << "px) -> layoutBox(" << &layoutBox << ")");
    245200        return widthAndMargin;
    246201    }
    247202
    248     auto initialContainingBlockWidth = layoutState.displayBoxForLayoutBox(initialContainingBlock(layoutBox)).contentBoxWidth();
    249     widthAndMargin = stretchWidthToInitialContainingBlock(widthAndMargin, initialContainingBlockWidth);
     203    widthAndMargin = Quirks::stretchedWidth(layoutState, layoutBox, widthAndMargin);
    250204
    251205    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow non-replaced -> streched to viewport-> width(" << widthAndMargin.width << "px) margin(" << widthAndMargin.margin.left << "px, " << widthAndMargin.margin.right << "px) -> layoutBox(" << &layoutBox << ")");
     
    311265    }
    312266
    313     if (!isStretchedToInitialContainingBlock(layoutState, layoutBox))
     267    if (!Quirks::isStretchedToInitialContainingBlock(layoutState, layoutBox))
    314268        return heightAndMargin;
    315269
    316     auto initialContainingBlockHeight = layoutState.displayBoxForLayoutBox(initialContainingBlock(layoutBox)).contentBoxHeight();
    317     heightAndMargin = stretchHeightToInitialContainingBlockQuirk(heightAndMargin, initialContainingBlockHeight);
     270    heightAndMargin = Quirks::stretchedHeight(layoutState, layoutBox, heightAndMargin);
    318271
    319272    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow non-replaced -> streched to viewport -> height(" << heightAndMargin.height << "px) margin(" << heightAndMargin.margin.top << "px, " << heightAndMargin.margin.bottom << "px) -> layoutBox(" << &layoutBox << ")");
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingState.cpp

    r237633 r238667  
    2929#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    3030
    31 #include "FormattingContext.h"
     31#include "BlockFormattingContext.h"
    3232#include "LayoutBox.h"
    3333#include <wtf/IsoMallocInlines.h>
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r238611 r238667  
    3737namespace Layout {
    3838
    39 static bool isQuirkContainer(const Box& layoutBox)
    40 {
    41     return layoutBox.isBodyBox() || layoutBox.isDocumentBox() || layoutBox.isTableCell();
    42 }
    43 
    44 static bool hasMarginTopQuirkValue(const Box& layoutBox)
    45 {
    46     return layoutBox.style().hasMarginBeforeQuirk();
    47 }
    48 
    49 static bool shouldIgnoreMarginTopInQuirkContext(const LayoutState& layoutState, const Box& layoutBox)
    50 {
    51     if (!layoutBox.parent())
    52         return false;
    53     return layoutState.inQuirksMode() && isQuirkContainer(*layoutBox.parent()) && hasMarginTopQuirkValue(layoutBox);
    54 }
    55 
    5639static LayoutUnit marginValue(LayoutUnit currentMarginValue, LayoutUnit candidateMarginValue)
    5740{
     
    10083}
    10184
    102 static bool isMarginTopCollapsedWithParent(const LayoutState& layoutState, const Box& layoutBox)
     85bool BlockFormattingContext::Geometry::MarginCollapse::isMarginTopCollapsedWithParent(const LayoutState& layoutState, const Box& layoutBox)
    10386{
    10487    // The first inflow child could propagate its top margin to parent.
     
    133116        return false;
    134117
    135     if (shouldIgnoreMarginTopInQuirkContext(layoutState, layoutBox))
     118    if (BlockFormattingContext::Quirks::shouldIgnoreMarginTop(layoutState, layoutBox))
    136119        return false;
    137120
     
    233216
    234217    // FIXME: Find out the logic behind this.
    235     if (shouldIgnoreMarginTopInQuirkContext(layoutState, layoutBox))
     218    if (BlockFormattingContext::Quirks::shouldIgnoreMarginTop(layoutState, layoutBox))
    236219        return 0;
    237220
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r238493 r238667  
    2929#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    3030
     31#include "FloatingContext.h"
    3132#include "FloatingState.h"
    3233#include "InlineFormattingState.h"
  • trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.h

    r238403 r238667  
    2929
    3030#include "InlineItem.h"
     31#include "InlineRunProvider.h"
    3132
    3233namespace WebCore {
Note: See TracChangeset for help on using the changeset viewer.