Commit 3b914013 authored by Aleks Totic's avatar Aleks Totic Committed by Commit Bot

[TablesNG] TablePart style adjustments

Legacy tables code does two style adjustments that need to be
modified for TablesNG.

1) Legacy cannot handle position:relative/fixed on Section/Rows, but
TablesNG can.
In Legacy, style used to be modified in
 style_adjuster.cc:AdjustStyleForDisplay
AdjustStyleForDisplay does not know if style is layout object is
legacy, or ng. Therefore, style adjustment cannot be done here.
The adjustment code was moved to LayoutObjectFactory, which knows
type of object being created.

2) Legacy cells cannot handle orthogonal writing modes. Cell
writing mode is reset to parent's writing  mode.

This one was tricky, because neither AdjustStyleForDisplay,
nor LayoutObject factory have data needed to modify the style.

AdjustStyleForDisplay does not know if layout object is
legacy or ng.

LayoutObjectFactory does not have parent's writing mode.

One option is to plumb parent's style to LayoutObjectFactory.
There is a lot of layers here, and feels like an unnecessary
complexity just to support temporary table weirdness.

My solution was to modify cell's style in
LayoutTableRow::AddChild. It is hacky, but I believe it is
safe.

Bug: 958381
Change-Id: I77dd9c7a253282d0f8647c9add0b5c1fc908d8eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2356849
Commit-Queue: Aleks Totic <atotic@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800505}
parent 178df420
...@@ -462,18 +462,6 @@ static void AdjustStyleForDisplay(ComputedStyle& style, ...@@ -462,18 +462,6 @@ static void AdjustStyleForDisplay(ComputedStyle& style,
style.GetWritingMode() != layout_parent_style.GetWritingMode()) style.GetWritingMode() != layout_parent_style.GetWritingMode())
style.SetDisplay(EDisplay::kInlineBlock); style.SetDisplay(EDisplay::kInlineBlock);
// We do not honor position: relative or sticky for table rows, headers, and
// footers. This is correct for position: relative in CSS2.1 (and caused a
// crash in containingBlock() on some sites) and position: sticky is defined
// as following position: relative behavior for table elements. It is
// incorrect for CSS3.
if ((style.Display() == EDisplay::kTableHeaderGroup ||
style.Display() == EDisplay::kTableRowGroup ||
style.Display() == EDisplay::kTableFooterGroup ||
style.Display() == EDisplay::kTableRow) &&
style.HasInFlowPosition())
style.SetPosition(EPosition::kStatic);
// Cannot support position: sticky for table columns and column groups because // Cannot support position: sticky for table columns and column groups because
// current code is only doing background painting through columns / column // current code is only doing background painting through columns / column
// groups. // groups.
...@@ -484,15 +472,12 @@ static void AdjustStyleForDisplay(ComputedStyle& style, ...@@ -484,15 +472,12 @@ static void AdjustStyleForDisplay(ComputedStyle& style,
// writing-mode does not apply to table row groups, table column groups, table // writing-mode does not apply to table row groups, table column groups, table
// rows, and table columns. // rows, and table columns.
// FIXME: Table cells should be allowed to be perpendicular or flipped with
// respect to the table, though.
if (style.Display() == EDisplay::kTableColumn || if (style.Display() == EDisplay::kTableColumn ||
style.Display() == EDisplay::kTableColumnGroup || style.Display() == EDisplay::kTableColumnGroup ||
style.Display() == EDisplay::kTableFooterGroup || style.Display() == EDisplay::kTableFooterGroup ||
style.Display() == EDisplay::kTableHeaderGroup || style.Display() == EDisplay::kTableHeaderGroup ||
style.Display() == EDisplay::kTableRow || style.Display() == EDisplay::kTableRow ||
style.Display() == EDisplay::kTableRowGroup || style.Display() == EDisplay::kTableRowGroup) {
style.Display() == EDisplay::kTableCell) {
style.SetWritingMode(layout_parent_style.GetWritingMode()); style.SetWritingMode(layout_parent_style.GetWritingMode());
style.UpdateFontOrientation(); style.UpdateFontOrientation();
} }
......
...@@ -102,6 +102,8 @@ void LayoutTreeBuilderForElement::CreateLayoutObject() { ...@@ -102,6 +102,8 @@ void LayoutTreeBuilderForElement::CreateLayoutObject() {
LayoutObject* next_layout_object = NextLayoutObject(); LayoutObject* next_layout_object = NextLayoutObject();
// SetStyle() can depend on LayoutObject() already being set. // SetStyle() can depend on LayoutObject() already being set.
node_->SetLayoutObject(new_layout_object); node_->SetLayoutObject(new_layout_object);
DCHECK(!new_layout_object->Style());
new_layout_object->SetStyle(style_); new_layout_object->SetStyle(style_);
// Note: Adding new_layout_object instead of LayoutObject(). LayoutObject() // Note: Adding new_layout_object instead of LayoutObject(). LayoutObject()
...@@ -164,7 +166,9 @@ void LayoutTreeBuilderForText::CreateLayoutObject() { ...@@ -164,7 +166,9 @@ void LayoutTreeBuilderForText::CreateLayoutObject() {
context_.parent->IsInsideFlowThread()); context_.parent->IsInsideFlowThread());
node_->SetLayoutObject(new_layout_object); node_->SetLayoutObject(new_layout_object);
DCHECK(!new_layout_object->Style());
new_layout_object->SetStyle(&style); new_layout_object->SetStyle(&style);
layout_object_parent->AddChild(new_layout_object, next_layout_object); layout_object_parent->AddChild(new_layout_object, next_layout_object);
} }
......
...@@ -89,7 +89,7 @@ class LayoutTreeBuilder { ...@@ -89,7 +89,7 @@ class LayoutTreeBuilder {
NodeType* node_; NodeType* node_;
Node::AttachContext& context_; Node::AttachContext& context_;
const ComputedStyle* style_; scoped_refptr<const ComputedStyle> style_;
}; };
class LayoutTreeBuilderForElement : public LayoutTreeBuilder<Element> { class LayoutTreeBuilderForElement : public LayoutTreeBuilder<Element> {
......
...@@ -436,10 +436,27 @@ LayoutUnit LayoutTableCell::CellBaselinePosition() const { ...@@ -436,10 +436,27 @@ LayoutUnit LayoutTableCell::CellBaselinePosition() const {
return BorderBefore() + PaddingBefore() + ContentLogicalHeight(); return BorderBefore() + PaddingBefore() + ContentLogicalHeight();
} }
// Legacy code does not support orthogonal table cells, and must match
// row's writing mode.
void LayoutTableCell::UpdateStyleWritingModeFromRow(const LayoutObject* row) {
DCHECK_NE(StyleRef().GetWritingMode(), row->StyleRef().GetWritingMode());
scoped_refptr<ComputedStyle> new_style = ComputedStyle::Clone(StyleRef());
new_style->SetWritingMode(row->StyleRef().GetWritingMode());
new_style->UpdateFontOrientation();
SetModifiedStyleOutsideStyleRecalc(new_style,
LayoutObject::ApplyStyleChanges::kNo);
SetHorizontalWritingMode(StyleRef().IsHorizontalWritingMode());
}
void LayoutTableCell::StyleDidChange(StyleDifference diff, void LayoutTableCell::StyleDidChange(StyleDifference diff,
const ComputedStyle* old_style) { const ComputedStyle* old_style) {
DCHECK_EQ(StyleRef().Display(), EDisplay::kTableCell); DCHECK_EQ(StyleRef().Display(), EDisplay::kTableCell);
if (Parent() &&
StyleRef().GetWritingMode() != Parent()->StyleRef().GetWritingMode()) {
UpdateStyleWritingModeFromRow(Parent());
}
LayoutBlockFlow::StyleDidChange(diff, old_style); LayoutBlockFlow::StyleDidChange(diff, old_style);
SetHasBoxDecorationBackground(true); SetHasBoxDecorationBackground(true);
......
...@@ -363,6 +363,8 @@ class CORE_EXPORT LayoutTableCell : public LayoutBlockFlow, ...@@ -363,6 +363,8 @@ class CORE_EXPORT LayoutTableCell : public LayoutBlockFlow,
MinMaxSizes PreferredLogicalWidths() const override; MinMaxSizes PreferredLogicalWidths() const override;
void UpdateStyleWritingModeFromRow(const LayoutObject* row);
protected: protected:
void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override; void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override;
......
...@@ -64,6 +64,14 @@ void LayoutTableRow::StyleDidChange(StyleDifference diff, ...@@ -64,6 +64,14 @@ void LayoutTableRow::StyleDidChange(StyleDifference diff,
const ComputedStyle* old_style) { const ComputedStyle* old_style) {
DCHECK_EQ(StyleRef().Display(), EDisplay::kTableRow); DCHECK_EQ(StyleRef().Display(), EDisplay::kTableRow);
// Legacy tables cannont handle relative/fixed rows.
if (StyleRef().HasInFlowPosition()) {
scoped_refptr<ComputedStyle> new_style = ComputedStyle::Clone(StyleRef());
new_style->SetPosition(EPosition::kStatic);
SetModifiedStyleOutsideStyleRecalc(new_style,
LayoutObject::ApplyStyleChanges::kNo);
}
LayoutTableBoxComponent::StyleDidChange(diff, old_style); LayoutTableBoxComponent::StyleDidChange(diff, old_style);
PropagateStyleToAnonymousChildren(); PropagateStyleToAnonymousChildren();
...@@ -180,6 +188,12 @@ void LayoutTableRow::AddChild(LayoutObject* child, LayoutObject* before_child) { ...@@ -180,6 +188,12 @@ void LayoutTableRow::AddChild(LayoutObject* child, LayoutObject* before_child) {
LayoutTableCell* cell = To<LayoutTableCell>(child); LayoutTableCell* cell = To<LayoutTableCell>(child);
// In Legacy tables, cell writing mode must match row writing mode.
// This adjustment is performed here because is LayoutObject type is
// unknown in style_adjuster.cc::AdjustStyleForDisplay
if (cell->StyleRef().GetWritingMode() != StyleRef().GetWritingMode()) {
cell->UpdateStyleWritingModeFromRow(this);
}
DCHECK(!before_child || before_child->IsTableCell()); DCHECK(!before_child || before_child->IsTableCell());
LayoutTableBoxComponent::AddChild(cell, before_child); LayoutTableBoxComponent::AddChild(cell, before_child);
......
...@@ -111,6 +111,14 @@ void LayoutTableSection::StyleDidChange(StyleDifference diff, ...@@ -111,6 +111,14 @@ void LayoutTableSection::StyleDidChange(StyleDifference diff,
StyleRef().Display() == EDisplay::kTableRowGroup || StyleRef().Display() == EDisplay::kTableRowGroup ||
StyleRef().Display() == EDisplay::kTableHeaderGroup); StyleRef().Display() == EDisplay::kTableHeaderGroup);
// Legacy tables cannot handle relative/sticky sections.
if (StyleRef().HasInFlowPosition()) {
scoped_refptr<ComputedStyle> new_style = ComputedStyle::Clone(StyleRef());
new_style->SetPosition(EPosition::kStatic);
SetModifiedStyleOutsideStyleRecalc(new_style,
LayoutObject::ApplyStyleChanges::kNo);
}
LayoutTableBoxComponent::StyleDidChange(diff, old_style); LayoutTableBoxComponent::StyleDidChange(diff, old_style);
PropagateStyleToAnonymousChildren(); PropagateStyleToAnonymousChildren();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment