- Revision
- 249172
- Author
- za...@apple.com
- Date
- 2019-08-27 14:24:40 -0700 (Tue, 27 Aug 2019)
Log Message
[LFC][TFC] Align table formatting context code with the existing layout logic.
https://bugs.webkit.org/show_bug.cgi?id=201168
<rdar://problem/54732633>
Reviewed by Antti Koivisto.
Let's make the TFC go through the exisint shrink-to-fit computation. Tables behave slightly different from
other shrink-to-fit boxes as they are streched to their minimum width(MIN) even when 'width' is non-auto and computed to less than MIN.
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::contentHeightForFormattingContextRoot):
* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/BlockFormattingContextGeometry.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):
* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::layout const):
(WebCore::Layout::TableFormattingContext::computedIntrinsicWidthConstraints const):
(WebCore::Layout::TableFormattingContext::computedTableWidth const):
(WebCore::Layout::TableFormattingContext::computeTableWidth const): Deleted.
(WebCore::Layout::TableFormattingContext::computeTableHeight const): Deleted.
(WebCore::Layout::TableFormattingContext::distributeAvailableHeight const): Deleted.
* layout/tableformatting/TableFormattingContext.h:
* layout/tableformatting/TableGrid.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (249171 => 249172)
--- trunk/Source/WebCore/ChangeLog 2019-08-27 21:14:56 UTC (rev 249171)
+++ trunk/Source/WebCore/ChangeLog 2019-08-27 21:24:40 UTC (rev 249172)
@@ -1,3 +1,29 @@
+2019-08-27 Zalan Bujtas <za...@apple.com>
+
+ [LFC][TFC] Align table formatting context code with the existing layout logic.
+ https://bugs.webkit.org/show_bug.cgi?id=201168
+ <rdar://problem/54732633>
+
+ Reviewed by Antti Koivisto.
+
+ Let's make the TFC go through the exisint shrink-to-fit computation. Tables behave slightly different from
+ other shrink-to-fit boxes as they are streched to their minimum width(MIN) even when 'width' is non-auto and computed to less than MIN.
+
+ * layout/FormattingContextGeometry.cpp:
+ (WebCore::Layout::contentHeightForFormattingContextRoot):
+ * layout/blockformatting/BlockFormattingContext.h:
+ * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+ (WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):
+ * layout/tableformatting/TableFormattingContext.cpp:
+ (WebCore::Layout::TableFormattingContext::layout const):
+ (WebCore::Layout::TableFormattingContext::computedIntrinsicWidthConstraints const):
+ (WebCore::Layout::TableFormattingContext::computedTableWidth const):
+ (WebCore::Layout::TableFormattingContext::computeTableWidth const): Deleted.
+ (WebCore::Layout::TableFormattingContext::computeTableHeight const): Deleted.
+ (WebCore::Layout::TableFormattingContext::distributeAvailableHeight const): Deleted.
+ * layout/tableformatting/TableFormattingContext.h:
+ * layout/tableformatting/TableGrid.h:
+
2019-08-27 Simon Fraser <simon.fra...@apple.com>
Minor optimization in InlineFlowBox::paintBoxDecorations()
Modified: trunk/Source/WebCore/layout/FormattingContextGeometry.cpp (249171 => 249172)
--- trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2019-08-27 21:14:56 UTC (rev 249171)
+++ trunk/Source/WebCore/layout/FormattingContextGeometry.cpp 2019-08-27 21:24:40 UTC (rev 249172)
@@ -31,6 +31,8 @@
#include "FloatingState.h"
#include "FormattingState.h"
#include "InlineFormattingState.h"
+#include "TableFormattingState.h"
+#include "TableGrid.h"
namespace WebCore {
namespace Layout {
@@ -101,7 +103,7 @@
// then the height is increased to include those edges. Only floats that participate in this block formatting context are taken
// into account, e.g., floats inside absolutely positioned descendants or other floats are not.
if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowOrFloatingChild())
- return 0;
+ return { };
auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
auto borderAndPaddingTop = displayBox.borderTop() + displayBox.paddingTop().valueOr(0);
@@ -121,7 +123,14 @@
top = firstDisplayBox.rectWithMargin().top();
bottom = lastDisplayBox.rectWithMargin().bottom();
}
- }
+ } else if (formattingRootContainer.establishesTableFormattingContext()) {
+ auto& rowList = downcast<TableFormattingState>(layoutState.establishedFormattingState(formattingRootContainer)).tableGrid().rows();
+ ASSERT(!rowList.isEmpty());
+ top += rowList.first().offset;
+ auto& lastRow = rowList.last();
+ bottom += lastRow.offset + lastRow.height;
+ } else
+ ASSERT_NOT_REACHED();
auto* formattingContextRoot = &layoutBox;
// TODO: The document renderer is not a formatting context root by default at all. Need to find out what it is.
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (249171 => 249172)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2019-08-27 21:14:56 UTC (rev 249171)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2019-08-27 21:24:40 UTC (rev 249172)
@@ -76,7 +76,7 @@
class Geometry : public FormattingContext::Geometry {
public:
static HeightAndMargin inFlowHeightAndMargin(const LayoutState&, const Box&, UsedVerticalValues);
- static WidthAndMargin inFlowWidthAndMargin(const LayoutState&, const Box&, UsedHorizontalValues);
+ static WidthAndMargin inFlowWidthAndMargin(LayoutState&, const Box&, UsedHorizontalValues);
static Point staticPosition(const LayoutState&, const Box&);
static LayoutUnit staticVerticalPosition(const LayoutState&, const Box&);
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (249171 => 249172)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2019-08-27 21:14:56 UTC (rev 249171)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp 2019-08-27 21:24:40 UTC (rev 249172)
@@ -276,12 +276,18 @@
return heightAndMargin;
}
-WidthAndMargin BlockFormattingContext::Geometry::inFlowWidthAndMargin(const LayoutState& layoutState, const Box& layoutBox, UsedHorizontalValues usedValues)
+WidthAndMargin BlockFormattingContext::Geometry::inFlowWidthAndMargin(LayoutState& layoutState, const Box& layoutBox, UsedHorizontalValues usedValues)
{
ASSERT(layoutBox.isInFlow());
- if (!layoutBox.replaced())
+ if (!layoutBox.replaced()) {
+ if (layoutBox.establishesTableFormattingContext()) {
+ // This is a special table "fit-content size" behavior handling. Not in the spec though.
+ // Table returns its final width as min/max. Use this final width value to computed horizontal margins etc.
+ usedValues.width = Geometry::shrinkToFitWidth(layoutState, layoutBox, usedValues);
+ }
return inFlowNonReplacedWidthAndMargin(layoutState, layoutBox, usedValues);
+ }
return inFlowReplacedWidthAndMargin(layoutState, layoutBox, usedValues);
}
Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (249171 => 249172)
--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp 2019-08-27 21:14:56 UTC (rev 249171)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp 2019-08-27 21:24:40 UTC (rev 249172)
@@ -37,6 +37,7 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(TableFormattingContext);
+// https://www.w3.org/TR/css-tables-3/#table-layout-algorithm
TableFormattingContext::TableFormattingContext(const Box& formattingContextRoot, TableFormattingState& formattingState)
: FormattingContext(formattingContextRoot, formattingState)
{
@@ -44,26 +45,25 @@
void TableFormattingContext::layout() const
{
- // https://www.w3.org/TR/css-tables-3/#table-layout-algorithm
- // To layout a table, user agents must apply the following actions:
+ ASSERT(!formattingState().tableGrid().cells().isEmpty());
+}
+FormattingContext::IntrinsicWidthConstraints TableFormattingContext::computedIntrinsicWidthConstraints() const
+{
+ // Tables have a slighty different concept of shrink to fit. It's really only different with non-auto "width" values, where
+ // a generic shrink-to fit block level box like a float box would be just sized to the computed value of "width", tables
+ // can actually be streched way over.
+
// 1. Ensure each cell slot is occupied by at least one cell.
ensureTableGrid();
// 2. Compute the minimum width of each column.
computePreferredWidthForColumns();
// 3. Compute the width of the table.
- computeTableWidth();
- // 4. Compute the height of the table.
- computeTableHeight();
- // 5. Distribute the height of the table among rows.
- distributeAvailableHeight();
+ auto width = computedTableWidth();
+ // This is the actual computed table width that we want to present as min/max width.
+ return { width, width };
}
-FormattingContext::IntrinsicWidthConstraints TableFormattingContext::computedIntrinsicWidthConstraints() const
-{
- return { };
-}
-
void TableFormattingContext::ensureTableGrid() const
{
auto& tableWrapperBox = downcast<Container>(root());
@@ -120,7 +120,7 @@
// FIXME: Take column group elements into account.
}
-void TableFormattingContext::computeTableWidth() const
+LayoutUnit TableFormattingContext::computedTableWidth() const
{
// Column and caption widths influence the final table width as follows:
// If the 'table' or 'inline-table' element's 'width' property has a computed value (W) other than 'auto', the used width is the greater of
@@ -164,8 +164,7 @@
}
}
- auto& tableDisplayBox = layoutState().displayBoxForLayoutBox(tableWrapperBox);
- tableDisplayBox.setContentBoxWidth(usedWidth);
+ return usedWidth;
}
void TableFormattingContext::distributeAvailableWidth(LayoutUnit extraHorizontalSpace) const
@@ -179,15 +178,7 @@
column.setLogicalWidth(column.widthConstraints().minimum + columnExtraSpace);
}
-void TableFormattingContext::computeTableHeight() const
-{
}
-
-void TableFormattingContext::distributeAvailableHeight() const
-{
}
-}
-}
-
#endif
Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h (249171 => 249172)
--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h 2019-08-27 21:14:56 UTC (rev 249171)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h 2019-08-27 21:24:40 UTC (rev 249172)
@@ -44,13 +44,11 @@
private:
IntrinsicWidthConstraints computedIntrinsicWidthConstraints() const override;
+ LayoutUnit computedTableWidth() const;
void ensureTableGrid() const;
void computePreferredWidthForColumns() const;
- void computeTableWidth() const;
void distributeAvailableWidth(LayoutUnit extraHorizontalSpace) const;
- void computeTableHeight() const;
- void distributeAvailableHeight() const;
TableFormattingState& formattingState() const { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
};
Modified: trunk/Source/WebCore/layout/tableformatting/TableGrid.h (249171 => 249172)
--- trunk/Source/WebCore/layout/tableformatting/TableGrid.h 2019-08-27 21:14:56 UTC (rev 249171)
+++ trunk/Source/WebCore/layout/tableformatting/TableGrid.h 2019-08-27 21:24:40 UTC (rev 249172)
@@ -101,6 +101,7 @@
ColumnsContext& columnsContext() { return m_columnsContext; }
struct Row {
+ LayoutUnit offset;
LayoutUnit height;
};
using RowList = WTF::Vector<Row>;