Commit 5374a96a authored by Aleks Totic's avatar Aleks Totic Committed by Commit Bot

[TablesNG] NGTableNode implementation

Move table-specific node to NGTableNode. This is good for code
health:
* ng_block_node header no longer includes table-specific
headers, and compiles faster.
* it is easier for developers to find out where
table-specific methods are.

Bug: 958381
Change-Id: I975e59aabbbbcd06892a746a918825da4336a6c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522113
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825050}
parent 925a93d2
......@@ -570,6 +570,8 @@ blink_core_sources_layout = [
"ng/table/ng_table_layout_algorithm_types.h",
"ng/table/ng_table_layout_algorithm_utils.cc",
"ng/table/ng_table_layout_algorithm_utils.h",
"ng/table/ng_table_node.cc",
"ng/table/ng_table_node.h",
"ng/table/ng_table_row_layout_algorithm.cc",
"ng/table/ng_table_row_layout_algorithm.h",
"ng/table/ng_table_section_layout_algorithm.cc",
......
......@@ -57,11 +57,8 @@
#include "third_party/blink/renderer/core/layout/ng/ng_page_layout_algorithm.h"
#include "third_party/blink/renderer/core/layout/ng/ng_simplified_layout_algorithm.h"
#include "third_party/blink/renderer/core/layout/ng/ng_space_utils.h"
#include "third_party/blink/renderer/core/layout/ng/table/layout_ng_table.h"
#include "third_party/blink/renderer/core/layout/ng/table/layout_ng_table_cell.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_borders.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_layout_algorithm.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_layout_algorithm_utils.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_row_layout_algorithm.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_section_layout_algorithm.h"
#include "third_party/blink/renderer/core/layout/shapes/shape_outside_info.h"
......@@ -997,46 +994,6 @@ NGBlockNode NGBlockNode::GetFieldsetContent() const {
return NGBlockNode(ToLayoutBox(child));
}
const NGBoxStrut& NGBlockNode::GetTableBordersStrut() const {
return GetTableBorders()->TableBorder();
}
scoped_refptr<const NGTableBorders> NGBlockNode::GetTableBorders() const {
DCHECK(IsTable());
DCHECK(box_->IsLayoutNGMixin());
LayoutNGTable* layout_table = To<LayoutNGTable>(box_);
scoped_refptr<const NGTableBorders> table_borders =
layout_table->GetCachedTableBorders();
if (!table_borders) {
table_borders = NGTableBorders::ComputeTableBorders(*this);
layout_table->SetCachedTableBorders(table_borders.get());
}
return table_borders;
}
scoped_refptr<const NGTableTypes::Columns> NGBlockNode::GetColumnConstraints(
const NGTableGroupedChildren& grouped_children,
const NGBoxStrut& border_padding) const {
DCHECK(IsTable());
LayoutNGTable* layout_table = To<LayoutNGTable>(box_);
scoped_refptr<const NGTableTypes::Columns> column_constraints =
layout_table->GetCachedTableColumnConstraints();
if (!column_constraints) {
column_constraints = NGTableAlgorithmUtils::ComputeColumnConstraints(
*this, grouped_children, *GetTableBorders().get(), border_padding);
layout_table->SetCachedTableColumnConstraints(column_constraints.get());
}
return column_constraints;
}
LayoutUnit NGBlockNode::ComputeTableInlineSize(
const NGConstraintSpace& space,
const NGBoxStrut& border_padding) const {
DCHECK(IsNGTable());
return NGTableLayoutAlgorithm::ComputeTableInlineSize(*this, space,
border_padding);
}
bool NGBlockNode::CanUseNewLayout(const LayoutBox& box) {
DCHECK(RuntimeEnabledFeatures::LayoutNGEnabled());
if (box.ForceLegacyLayout())
......
......@@ -8,8 +8,6 @@
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_offset.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_input_node.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_borders.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_layout_algorithm_types.h"
#include "third_party/blink/renderer/platform/fonts/font_baseline.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
......@@ -30,7 +28,7 @@ struct NGLayoutAlgorithmParams;
enum class MathScriptType;
// Represents a node to be laid out.
class CORE_EXPORT NGBlockNode final : public NGLayoutInputNode {
class CORE_EXPORT NGBlockNode : public NGLayoutInputNode {
friend NGLayoutInputNode;
public:
explicit NGBlockNode(LayoutBox* box) : NGLayoutInputNode(box, kBlock) {}
......@@ -97,21 +95,10 @@ class CORE_EXPORT NGBlockNode final : public NGLayoutInputNode {
NGBlockNode GetRenderedLegend() const;
NGBlockNode GetFieldsetContent() const;
bool IsNGTable() const { return IsTable() && box_->IsLayoutNGMixin(); }
bool IsNGTableCell() const {
return box_->IsTableCell() && !box_->IsTableCellLegacy();
}
// TODO(atotic) Move table-specific calls to NGTableNode
const NGBoxStrut& GetTableBordersStrut() const;
scoped_refptr<const NGTableBorders> GetTableBorders() const;
scoped_refptr<const NGTableTypes::Columns> GetColumnConstraints(
const NGTableGroupedChildren&,
const NGBoxStrut& border_padding) const;
LayoutUnit ComputeTableInlineSize(const NGConstraintSpace&,
const NGBoxStrut& border_padding) const;
// Return true if this block node establishes an inline formatting context.
// This will only be the case if there is actual inline content. Empty nodes
// or nodes consisting purely of block-level, floats, and/or out-of-flow
......
......@@ -82,7 +82,7 @@ class CORE_EXPORT NGLayoutAlgorithm : public NGLayoutAlgorithmOperations {
// Constructor for algorithms that use NGBoxFragmentBuilder and
// NGBlockBreakToken.
explicit NGLayoutAlgorithm(const NGLayoutAlgorithmParams& params)
: node_(params.node),
: node_(To<NGInputNodeType>(params.node)),
break_token_(params.break_token),
container_builder_(
params.node,
......
......@@ -140,6 +140,7 @@ class CORE_EXPORT NGLayoutInputNode {
// Return true if this node is for a slider thumb in <input type=range>.
bool IsSliderThumb() const;
bool IsTable() const { return IsBlock() && box_->IsTable(); }
bool IsNGTable() const { return IsTable() && box_->IsLayoutNGMixin(); }
bool IsTableCaption() const { return IsBlock() && box_->IsTableCaption(); }
......
......@@ -12,6 +12,7 @@
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space.h"
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space_builder.h"
#include "third_party/blink/renderer/core/layout/ng/ng_space_utils.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_node.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/platform/geometry/layout_unit.h"
#include "third_party/blink/renderer/platform/geometry/length.h"
......@@ -270,6 +271,7 @@ MinMaxSizesResult ComputeMinAndMaxContentContributionInternal(
ComputeBorders(space, child) + ComputePadding(space, style);
MinMaxSizesResult result;
const Length& inline_size = parent_writing_mode == WritingMode::kHorizontalTb
? style.Width()
: style.Height();
......@@ -433,11 +435,8 @@ LayoutUnit ComputeInlineSizeForFragment(
const MinMaxSizes* override_min_max_sizes_for_test) {
if (space.IsFixedInlineSize() || space.IsAnonymous())
return space.AvailableSize().inline_size;
if (node.IsBlock()) {
NGBlockNode block = To<NGBlockNode>(node);
if (block.IsNGTable())
return block.ComputeTableInlineSize(space, border_padding);
}
if (node.IsNGTable())
return To<NGTableNode>(node).ComputeTableInlineSize(space, border_padding);
const ComputedStyle& style = node.Style();
Length logical_width = style.LogicalWidth();
......@@ -956,7 +955,7 @@ NGBoxStrut ComputeBorders(const NGConstraintSpace& constraint_space,
return constraint_space.TableCellBorders();
if (node.IsNGTable())
return node.GetTableBorders()->TableBorder();
return To<NGTableNode>(node).GetTableBorders()->TableBorder();
return ComputeBordersInternal(node.Style());
}
......
......@@ -24,6 +24,7 @@
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_fragment_data.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_layout_algorithm_helpers.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_layout_algorithm_utils.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_node.h"
#include "third_party/blink/renderer/core/layout/text_autosizer.h"
namespace blink {
......@@ -136,9 +137,9 @@ LayoutUnit ComputeEmptyTableInlineSize(
table_border_padding.InlineSum());
}
// Table is defined by its border/padding.
if (has_collapsed_borders) {
if (has_collapsed_borders)
return LayoutUnit();
}
return assignable_table_inline_size + table_border_padding.InlineSum();
}
......@@ -406,7 +407,7 @@ LayoutUnit ComputeTableSizeFromColumns(
} // namespace
LayoutUnit NGTableLayoutAlgorithm::ComputeTableInlineSize(
const NGBlockNode& table,
const NGTableNode& table,
const NGConstraintSpace& space,
const NGBoxStrut& table_border_padding) {
const bool is_fixed_layout = table.Style().IsFixedTableLayout();
......
......@@ -9,15 +9,15 @@
#include "third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_layout_algorithm_types.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_node.h"
namespace blink {
class NGBlockNode;
class NGBlockBreakToken;
class NGTableBorders;
class CORE_EXPORT NGTableLayoutAlgorithm
: public NGLayoutAlgorithm<NGBlockNode,
: public NGLayoutAlgorithm<NGTableNode,
NGBoxFragmentBuilder,
NGBlockBreakToken> {
public:
......@@ -27,7 +27,7 @@ class CORE_EXPORT NGTableLayoutAlgorithm
MinMaxSizesResult ComputeMinMaxSizes(const MinMaxSizesInput&) const override;
static LayoutUnit ComputeTableInlineSize(const NGBlockNode& node,
static LayoutUnit ComputeTableInlineSize(const NGTableNode& node,
const NGConstraintSpace& space,
const NGBoxStrut& border_padding);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_node.h"
#include "third_party/blink/renderer/core/layout/ng/table/layout_ng_table.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_layout_algorithm.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_layout_algorithm_utils.h"
namespace blink {
scoped_refptr<const NGTableBorders> NGTableNode::GetTableBorders() const {
LayoutNGTable* layout_table = To<LayoutNGTable>(box_);
scoped_refptr<const NGTableBorders> table_borders =
layout_table->GetCachedTableBorders();
if (!table_borders) {
table_borders = NGTableBorders::ComputeTableBorders(*this);
layout_table->SetCachedTableBorders(table_borders.get());
}
return table_borders;
}
const NGBoxStrut& NGTableNode::GetTableBordersStrut() const {
return GetTableBorders()->TableBorder();
}
scoped_refptr<const NGTableTypes::Columns> NGTableNode::GetColumnConstraints(
const NGTableGroupedChildren& grouped_children,
const NGBoxStrut& border_padding) const {
LayoutNGTable* layout_table = To<LayoutNGTable>(box_);
scoped_refptr<const NGTableTypes::Columns> column_constraints =
layout_table->GetCachedTableColumnConstraints();
if (!column_constraints) {
column_constraints = NGTableAlgorithmUtils::ComputeColumnConstraints(
*this, grouped_children, *GetTableBorders().get(), border_padding);
layout_table->SetCachedTableColumnConstraints(column_constraints.get());
}
return column_constraints;
}
LayoutUnit NGTableNode::ComputeTableInlineSize(
const NGConstraintSpace& space,
const NGBoxStrut& border_padding) const {
return NGTableLayoutAlgorithm::ComputeTableInlineSize(*this, space,
border_padding);
}
} // namespace blink
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_TABLE_NG_TABLE_NODE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_TABLE_NG_TABLE_NODE_H_
#include "third_party/blink/renderer/core/layout/ng/ng_block_node.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_borders.h"
#include "third_party/blink/renderer/core/layout/ng/table/ng_table_layout_algorithm_types.h"
namespace blink {
// Table specific extensions to NGBlockNode.
class CORE_EXPORT NGTableNode final : public NGBlockNode {
public:
explicit NGTableNode(LayoutBox* box) : NGBlockNode(box) {}
const NGBoxStrut& GetTableBordersStrut() const;
scoped_refptr<const NGTableBorders> GetTableBorders() const;
scoped_refptr<const NGTableTypes::Columns> GetColumnConstraints(
const NGTableGroupedChildren&,
const NGBoxStrut& border_padding) const;
LayoutUnit ComputeTableInlineSize(const NGConstraintSpace&,
const NGBoxStrut& border_padding) const;
};
template <>
struct DowncastTraits<NGTableNode> {
static bool AllowFrom(const NGLayoutInputNode& node) {
return node.IsNGTable();
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_TABLE_NG_TABLE_NODE_H_
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