Skip to content

Commit

Permalink
[RemoveLegacy] Remove NGConstraintSpace::CreateFromLayoutObject
Browse files Browse the repository at this point in the history
As above - there should be no behaviour change.

Bug: 1229581
Change-Id: I311565fb48ab12d248c23191aba4b22bb241f66d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4590235
Reviewed-by: Morten Stenshorne <mstensho@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1153818}
  • Loading branch information
bfgeek authored and Chromium LUCI CQ committed Jun 6, 2023
1 parent c7b513c commit ff45d0b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 233 deletions.
38 changes: 0 additions & 38 deletions third_party/blink/renderer/core/layout/layout_box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3320,44 +3320,6 @@ bool LayoutBox::IsStretchingColumnFlexItem() const {
return false;
}

bool LayoutBox::SizesLogicalWidthToFitContent(
const Length& logical_width) const {
NOT_DESTROYED();
if (IsFloating() || IsInlineBlockOrInlineTable() ||
StyleRef().HasOutOfFlowPosition())
return true;

// Flexible box items should shrink wrap, so we lay them out at their
// intrinsic widths. In the case of columns that have a stretch alignment, we
// go ahead and layout at the stretched size to avoid an extra layout when
// applying alignment.
if (Parent()->IsFlexibleBoxIncludingNG()) {
// For multiline columns, we need to apply align-content first, so we can't
// stretch now.
if (!Parent()->StyleRef().ResolvedIsColumnFlexDirection() ||
Parent()->StyleRef().FlexWrap() != EFlexWrap::kNowrap)
return true;
if (!ColumnFlexItemHasStretchAlignment())
return true;
}

// Button, input, select, textarea, and legend treat width value of 'auto' as
// 'intrinsic' unless it's in a stretching column flexbox.
// FIXME: Think about writing-mode here.
// https://bugs.webkit.org/show_bug.cgi?id=46473
if (logical_width.IsAuto() && !IsStretchingColumnFlexItem() &&
AutoWidthShouldFitContent())
return true;

if (IsHorizontalWritingMode() != ContainingBlock()->IsHorizontalWritingMode())
return true;

if (IsCustomItem())
return IsCustomItemShrinkToFit();

return false;
}

bool LayoutBox::AutoWidthShouldFitContent() const {
NOT_DESTROYED();
return GetNode() &&
Expand Down
5 changes: 0 additions & 5 deletions third_party/blink/renderer/core/layout/layout_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -1146,11 +1146,6 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject {
: IntrinsicSize().Width();
}

// Whether or not the element shrinks to its intrinsic width (rather than
// filling the width of a containing block). HTML4 buttons, <select>s,
// <input>s, legends, and floating/compact elements do this.
bool SizesLogicalWidthToFitContent(const Length& logical_width) const;

bool AutoWidthShouldFitContent() const;

LayoutUnit ComputeLogicalHeightUsing(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,9 @@ TEST_F(NGInlineLayoutAlgorithmTest, ContainerBorderPadding) {
</style>
<div id=container>test</div>
)HTML");
auto* block_flow =
To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"));
NGBlockNode block_node(block_flow);
NGConstraintSpace space =
NGConstraintSpace::CreateFromLayoutObject(*block_flow);
const NGLayoutResult* layout_result = block_node.Layout(space);

const auto* layout_result =
GetLayoutBoxByElementId("container")->GetSingleCachedLayoutResult();

EXPECT_TRUE(layout_result->BfcBlockOffset().has_value());
EXPECT_EQ(0, *layout_result->BfcBlockOffset());
Expand Down Expand Up @@ -440,11 +437,16 @@ TEST_F(NGInlineLayoutAlgorithmTest, TextFloatsAroundFloatsBefore) {
<span id="text">The quick brown fox jumps over the lazy dog</span>
</div>
)HTML");
// ** Run LayoutNG algorithm **
auto [html_fragment, space] = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));

const auto& html_fragment = To<LayoutBox>(GetDocument()
.getElementsByTagName("html")
->item(0)
->GetLayoutObject())
->GetSingleCachedLayoutResult()
->PhysicalFragment();

auto* body_fragment =
To<NGPhysicalBoxFragment>(html_fragment->Children()[0].get());
To<NGPhysicalBoxFragment>(html_fragment.Children()[0].get());
auto* container_fragment =
To<NGPhysicalBoxFragment>(body_fragment->Children()[0].get());
Vector<PhysicalOffset> line_offsets;
Expand Down
27 changes: 0 additions & 27 deletions third_party/blink/renderer/core/layout/ng/layout_box_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,6 @@

namespace blink {

LayoutUnit LayoutBoxUtils::AvailableLogicalWidth(const LayoutBox& box,
const LayoutBlock* cb) {
// SVG <text> and <foreignObject> should not refer to its containing block.
DCHECK(!box.IsSVGChild());
auto writing_mode = box.StyleRef().GetWritingMode();
bool parallel_containing_block = IsParallelWritingMode(
cb ? cb->StyleRef().GetWritingMode() : writing_mode, writing_mode);

// Grid layout sets OverrideContainingBlockContentLogicalWidth|Height
if (parallel_containing_block &&
box.HasOverrideContainingBlockContentLogicalWidth()) {
return box.OverrideContainingBlockContentLogicalWidth()
.ClampNegativeToZero();
}

if (!parallel_containing_block &&
box.HasOverrideContainingBlockContentLogicalHeight()) {
return box.OverrideContainingBlockContentLogicalHeight()
.ClampNegativeToZero();
}

if (parallel_containing_block)
return box.ContainingBlockLogicalWidthForContent().ClampNegativeToZero();

return box.PerpendicularContainingBlockLogicalHeight().ClampNegativeToZero();
}

LayoutUnit LayoutBoxUtils::AvailableLogicalHeight(const LayoutBox& box,
const LayoutBlock* cb) {
// SVG <text> and <foreignObject> should not refer to its containing block.
Expand Down
2 changes: 0 additions & 2 deletions third_party/blink/renderer/core/layout/ng/layout_box_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class LayoutBoxUtils {
// Returns the available logical width/height for |box| accounting for:
// - Orthogonal writing modes.
// - Any containing block override sizes set.
static LayoutUnit AvailableLogicalWidth(const LayoutBox& box,
const LayoutBlock* cb);
static LayoutUnit AvailableLogicalHeight(const LayoutBox& box,
const LayoutBlock* cb);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ const NGPhysicalBoxFragment* NGBaseLayoutAlgorithmTest::RunBlockLayoutAlgorithm(
return To<NGPhysicalBoxFragment>(&result->PhysicalFragment());
}

std::pair<const NGPhysicalBoxFragment*, NGConstraintSpace>
NGBaseLayoutAlgorithmTest::RunBlockLayoutAlgorithmForElement(Element* element) {
auto* block_flow = To<LayoutBlockFlow>(element->GetLayoutObject());
NGBlockNode node(block_flow);
NGConstraintSpace space =
NGConstraintSpace::CreateFromLayoutObject(*block_flow);
NGFragmentGeometry fragment_geometry =
CalculateInitialFragmentGeometry(space, node, /* break_token */ nullptr);

const NGLayoutResult* result =
NGBlockLayoutAlgorithm({node, fragment_geometry, space}).Layout();
return std::make_pair(To<NGPhysicalBoxFragment>(&result->PhysicalFragment()),
std::move(space));
}

const NGPhysicalBoxFragment*
NGBaseLayoutAlgorithmTest::RunFieldsetLayoutAlgorithm(
NGBlockNode node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace blink {

class Element;
class LayoutNGBlockFlow;
class NGBlockNode;
class NGBreakToken;
Expand All @@ -29,18 +28,13 @@ class NGBaseLayoutAlgorithmTest
protected:
void SetUp() override;

// Should be called before calling Layout(), if you're not using
// RunBlockLayoutAlgorithmForElement.
void AdvanceToLayoutPhase();

const NGPhysicalBoxFragment* RunBlockLayoutAlgorithm(
NGBlockNode node,
const NGConstraintSpace& space,
const NGBreakToken* break_token = nullptr);

std::pair<const NGPhysicalBoxFragment*, NGConstraintSpace>
RunBlockLayoutAlgorithmForElement(Element* element);

const NGPhysicalBoxFragment* RunFieldsetLayoutAlgorithm(
NGBlockNode node,
const NGConstraintSpace& space,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class NGBlockLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {
NGBaseLayoutAlgorithmTest::SetUp();
}

const NGPhysicalBoxFragment* GetHtmlPhysicalFragment() const {
const auto* layout_box = To<LayoutBox>(
GetDocument().getElementsByTagName("html")->item(0)->GetLayoutObject());
return To<NGPhysicalBoxFragment>(
&layout_box->GetSingleCachedLayoutResult()->PhysicalFragment());
}

MinMaxSizes RunComputeMinMaxSizes(NGBlockNode node) {
// The constraint space is not used for min/max computation, but we need
// it to create the algorithm.
Expand Down Expand Up @@ -73,6 +80,7 @@ class NGBlockLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {
layout_object->SetStyle(builder.TakeStyle(),
LayoutObject::ApplyStyleChanges::kNo);
layout_object->SetNeedsLayout("");
UpdateAllLifecyclePhasesForTest();
}
};

Expand Down Expand Up @@ -423,10 +431,9 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase1WithFloats) {
</div>
)HTML");

// ** Run LayoutNG algorithm **
auto [fragment, space] = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
const auto* fragment = GetHtmlPhysicalFragment();
ASSERT_EQ(fragment->Children().size(), 1UL);

PhysicalOffset body_offset = fragment->Children()[0].Offset();
auto* body_fragment =
To<NGPhysicalBoxFragment>(fragment->Children()[0].get());
Expand Down Expand Up @@ -503,10 +510,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase2WithFloats) {
<div id='empty5'></div>
)HTML");

// ** Run LayoutNG algorithm **
auto [fragment, space] = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));

const auto* fragment = GetHtmlPhysicalFragment();
auto* body_fragment =
To<NGPhysicalBoxFragment>(fragment->Children()[0].get());
PhysicalOffset body_offset = fragment->Children()[0].Offset();
Expand Down Expand Up @@ -567,8 +571,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase3) {
[&](ComputedStyleBuilder& builder) {
builder.SetHeight(container_height);
});
std::tie(fragment, std::ignore) = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
fragment = GetHtmlPhysicalFragment();
ASSERT_EQ(1UL, fragment->Children().size());
body_fragment = To<NGPhysicalBoxFragment>(fragment->Children()[0].get());
container_fragment =
Expand Down Expand Up @@ -620,8 +623,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase4) {
[&](ComputedStyleBuilder& builder) {
builder.SetPaddingTop(container_padding_top);
});
std::tie(fragment, std::ignore) = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
fragment = GetHtmlPhysicalFragment();
ASSERT_EQ(1UL, fragment->Children().size());
const auto* body_fragment =
To<NGPhysicalBoxFragment>(fragment->Children()[0].get());
Expand Down Expand Up @@ -682,9 +684,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase5) {
<div id='horizontal'></div>
</div>
)HTML");
const NGPhysicalBoxFragment* fragment = nullptr;
std::tie(fragment, std::ignore) = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
const auto* fragment = GetHtmlPhysicalFragment();

// body
auto* body_fragment =
Expand Down Expand Up @@ -736,9 +736,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsWithText) {
</style>
<p>Some text</p>
)HTML");
const NGPhysicalBoxFragment* html_fragment = nullptr;
std::tie(html_fragment, std::ignore) = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
const auto* html_fragment = GetHtmlPhysicalFragment();

const NGPhysicalBoxFragment* body_fragment =
To<NGPhysicalBoxFragment>(html_fragment->Children()[0].get());
Expand Down Expand Up @@ -827,10 +825,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase7) {
<div id="inflow"></div>
)HTML");

const NGPhysicalBoxFragment* fragment = nullptr;
std::tie(fragment, std::ignore) = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));

const auto* fragment = GetHtmlPhysicalFragment();
FragmentChildIterator iterator(fragment);

// body
Expand Down Expand Up @@ -1028,9 +1023,10 @@ TEST_F(NGBlockLayoutAlgorithmTest, NewFormattingContextAutoMargins) {
</div>
)HTML");

const NGPhysicalBoxFragment* fragment = nullptr;
std::tie(fragment, std::ignore) =
RunBlockLayoutAlgorithmForElement(GetElementById("container"));
const auto* fragment =
&To<NGPhysicalBoxFragment>(GetLayoutBoxByElementId("container")
->GetSingleCachedLayoutResult()
->PhysicalFragment());

String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:200x60
Expand Down Expand Up @@ -1204,10 +1200,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionFloatInsideEmptyBlocks) {
</div>
)HTML");

// ** Run LayoutNG algorithm **
auto [fragment, space] = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));

const auto* fragment = GetHtmlPhysicalFragment();
const auto* body_fragment =
To<NGPhysicalBoxFragment>(fragment->Children()[0].get());
PhysicalOffset body_offset = fragment->Children()[0].Offset();
Expand Down Expand Up @@ -1307,9 +1300,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionFloatFragments) {
</div>
)HTML");

// ** Run LayoutNG algorithm **
auto [fragment, space] = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
const auto* fragment = GetHtmlPhysicalFragment();

// ** Verify LayoutNG fragments and the list of positioned floats **
ASSERT_EQ(1UL, fragment->Children().size());
Expand Down Expand Up @@ -1431,13 +1422,11 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionFragmentsWithClear) {
PhysicalOffset container_offset;
PhysicalOffset block_offset;
PhysicalOffset adjoining_clearance_offset;
const NGPhysicalBoxFragment* fragment = nullptr;
auto run_with_clearance = [&](EClear clear_value) {
UpdateStyleForElement(
GetDocument().getElementById("clearance"),
[&](ComputedStyleBuilder& builder) { builder.SetClear(clear_value); });
std::tie(fragment, std::ignore) = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
const auto* fragment = GetHtmlPhysicalFragment();
ASSERT_EQ(1UL, fragment->Children().size());
const NGPhysicalBoxFragment* body_fragment =
To<NGPhysicalBoxFragment>(fragment->Children()[0].get());
Expand Down Expand Up @@ -1677,9 +1666,7 @@ TEST_F(NGBlockLayoutAlgorithmTest, PositionEmptyBlocksInNewBfc) {
</div>
)HTML");

const NGPhysicalBoxFragment* html_fragment = nullptr;
std::tie(html_fragment, std::ignore) = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
const auto* html_fragment = GetHtmlPhysicalFragment();
auto* body_fragment =
To<NGPhysicalBoxFragment>(html_fragment->Children()[0].get());
auto* container_fragment =
Expand Down Expand Up @@ -1744,10 +1731,7 @@ TEST_F(NGBlockLayoutAlgorithmTest,
</div>
)HTML");

// Run LayoutNG algorithm.
const NGPhysicalBoxFragment* html_fragment = nullptr;
std::tie(html_fragment, std::ignore) = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
const auto* html_fragment = GetHtmlPhysicalFragment();
auto* body_fragment =
To<NGPhysicalBoxFragment>(html_fragment->Children()[0].get());
ASSERT_EQ(4UL, body_fragment->Children().size());
Expand Down Expand Up @@ -2252,13 +2236,11 @@ TEST_F(NGBlockLayoutAlgorithmTest,
PhysicalOffset body_offset;
PhysicalOffset new_fc_offset;

const NGPhysicalBoxFragment* fragment = nullptr;
auto run_test = [&](const Length& block_width) {
UpdateStyleForElement(
GetDocument().getElementById("new-fc"),
[&](ComputedStyleBuilder& builder) { builder.SetWidth(block_width); });
std::tie(fragment, std::ignore) = RunBlockLayoutAlgorithmForElement(
GetDocument().getElementsByTagName("html")->item(0));
const auto* fragment = GetHtmlPhysicalFragment();
ASSERT_EQ(1UL, fragment->Children().size());
const auto* body_fragment =
To<NGPhysicalBoxFragment>(fragment->Children()[0].get());
Expand Down

0 comments on commit ff45d0b

Please sign in to comment.