[LFC][TFC] Add <col> element's width attribute value to Layout::Box rare data
https://bugs.webkit.org/show_bug.cgi?id=202988
<rdar://problem/56291048>

Reviewed by Antti Koivisto.

Sadly RenderStyle does not have this value.

* layout/layouttree/LayoutBox.cpp:
(WebCore::Layout::Box::setColumnWidth):
(WebCore::Layout::Box::columnWidth const):
* layout/layouttree/LayoutBox.h:
* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::TreeBuilder::createLayoutBox):
(WebCore::Layout::outputLayoutBox):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251136 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index e440763..9040d80 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,5 +1,23 @@
 2019-10-15  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][TFC] Add <col> element's width attribute value to Layout::Box rare data
+        https://bugs.webkit.org/show_bug.cgi?id=202988
+        <rdar://problem/56291048>
+
+        Reviewed by Antti Koivisto.
+
+        Sadly RenderStyle does not have this value.
+
+        * layout/layouttree/LayoutBox.cpp:
+        (WebCore::Layout::Box::setColumnWidth):
+        (WebCore::Layout::Box::columnWidth const):
+        * layout/layouttree/LayoutBox.h:
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::TreeBuilder::createLayoutBox):
+        (WebCore::Layout::outputLayoutBox):
+
+2019-10-15  Zalan Bujtas  <zalan@apple.com>
+
         [LFC] Adjust computed height value when box sizing is border-box
         https://bugs.webkit.org/show_bug.cgi?id=202965
         <rdar://problem/56276771>
diff --git a/Source/WebCore/layout/layouttree/LayoutBox.cpp b/Source/WebCore/layout/layouttree/LayoutBox.cpp
index 4d2bc97..4a28b18 100644
--- a/Source/WebCore/layout/layouttree/LayoutBox.cpp
+++ b/Source/WebCore/layout/layouttree/LayoutBox.cpp
@@ -439,6 +439,18 @@
     return rareData().columnSpan;
 }
 
+void Box::setColumnWidth(LayoutUnit columnWidth)
+{
+    ensureRareData().columnWidth = columnWidth;
+}
+
+Optional<LayoutUnit> Box::columnWidth() const
+{
+    if (!hasRareData())
+        return { };
+    return rareData().columnWidth;
+}
+
 Box::RareDataMap& Box::rareDataMap()
 {
     static NeverDestroyed<RareDataMap> map;
diff --git a/Source/WebCore/layout/layouttree/LayoutBox.h b/Source/WebCore/layout/layouttree/LayoutBox.h
index 6ea2502..793785c 100644
--- a/Source/WebCore/layout/layouttree/LayoutBox.h
+++ b/Source/WebCore/layout/layouttree/LayoutBox.h
@@ -146,10 +146,14 @@
 
     // FIXME: Find a better place for random DOM things.
     void setRowSpan(unsigned);
-    void setColumnSpan(unsigned);
     unsigned rowSpan() const;
+
+    void setColumnSpan(unsigned);
     unsigned columnSpan() const;
 
+    void setColumnWidth(LayoutUnit);
+    Optional<LayoutUnit> columnWidth() const;
+
     void setParent(Container& parent) { m_parent = &parent; }
     void setNextSibling(Box& nextSibling) { m_nextSibling = &nextSibling; }
     void setPreviousSibling(Box& previousSibling) { m_previousSibling = &previousSibling; }
@@ -171,6 +175,7 @@
         std::unique_ptr<Replaced> replaced;
         unsigned rowSpan { 1 };
         unsigned columnSpan { 1 };
+        Optional<LayoutUnit> columnWidth;
     };
 
     bool hasRareData() const { return m_hasRareData; }
diff --git a/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp b/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
index 49e6f78..dd91cad 100644
--- a/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
+++ b/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
@@ -31,6 +31,7 @@
 #include "DisplayBox.h"
 #include "DisplayRun.h"
 #include "HTMLTableCellElement.h"
+#include "HTMLTableColElement.h"
 #include "InlineFormattingState.h"
 #include "LayoutBox.h"
 #include "LayoutChildIterator.h"
@@ -182,8 +183,13 @@
         else if (displayType == DisplayType::TableCaption || displayType == DisplayType::TableCell) {
             childLayoutBox = makeUnique<Container>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
         } else if (displayType == DisplayType::TableRowGroup || displayType == DisplayType::TableHeaderGroup || displayType == DisplayType::TableFooterGroup
-            || displayType == DisplayType::TableRow || displayType == DisplayType::TableColumnGroup || displayType == DisplayType::TableColumn) {
+            || displayType == DisplayType::TableRow || displayType == DisplayType::TableColumnGroup) {
             childLayoutBox = makeUnique<Container>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+        } else if (displayType == DisplayType::TableColumn) {
+            childLayoutBox = makeUnique<Container>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+            auto columnWidth = static_cast<HTMLTableColElement&>(*renderer.element()).width();
+            if (!columnWidth.isEmpty())
+                childLayoutBox->setColumnWidth(columnWidth.toInt());
         } else {
             ASSERT_NOT_IMPLEMENTED_YET();
             return { };
@@ -311,6 +317,10 @@
         stream << "TBODY";
     else if (layoutBox.isTableFooter())
         stream << "TFOOT";
+    else if (layoutBox.isTableColumnGroup())
+        stream << "COL GROUP";
+    else if (layoutBox.isTableColumn())
+        stream << "COL";
     else if (layoutBox.isTableCell())
         stream << "TD";
     else if (layoutBox.isTableRow())