Skip to content

Commit

Permalink
LayoutNG: Rename NGMarginStrut to MarginStrut
Browse files Browse the repository at this point in the history
This CL has no behavior changes.

Bug: 1492009
Change-Id: I33127bc7290c492c2fd8bb2fa57c3aceeee175ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4935793
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210020}
  • Loading branch information
tkent-google authored and Chromium LUCI CQ committed Oct 16, 2023
1 parent 6581b54 commit d466641
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 77 deletions.
5 changes: 3 additions & 2 deletions third_party/blink/renderer/core/layout/layout_box_hot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const NGLayoutResult* LayoutBox::CachedLayoutResult(
absl::optional<LayoutUnit> bfc_block_offset =
cached_layout_result->BfcBlockOffset();
LayoutUnit block_offset_delta;
NGMarginStrut end_margin_strut = cached_layout_result->EndMarginStrut();
MarginStrut end_margin_strut = cached_layout_result->EndMarginStrut();

bool are_bfc_offsets_equal;
bool is_margin_strut_equal;
Expand All @@ -222,7 +222,8 @@ const NGLayoutResult* LayoutBox::CachedLayoutResult(
old_space.ExpectedBfcBlockOffset() &&
new_space.ForcedBfcBlockOffset() == old_space.ForcedBfcBlockOffset();

is_margin_strut_equal = new_space.MarginStrut() == old_space.MarginStrut();
is_margin_strut_equal =
new_space.GetMarginStrut() == old_space.GetMarginStrut();
is_exclusion_space_equal =
new_space.ExclusionSpace() == old_space.ExclusionSpace();
bool is_clearance_offset_equal =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace blink {

void NGMarginStrut::Append(const LayoutUnit& value, bool is_quirky) {
void MarginStrut::Append(const LayoutUnit& value, bool is_quirky) {
if (is_quirky_container_start && is_quirky)
return;

Expand All @@ -25,14 +25,14 @@ void NGMarginStrut::Append(const LayoutUnit& value, bool is_quirky) {
}
}

bool NGMarginStrut::IsEmpty() const {
bool MarginStrut::IsEmpty() const {
if (discard_margins)
return true;
return positive_margin == LayoutUnit() && negative_margin == LayoutUnit() &&
quirky_positive_margin == LayoutUnit();
}

bool NGMarginStrut::operator==(const NGMarginStrut& other) const {
bool MarginStrut::operator==(const MarginStrut& other) const {
return positive_margin == other.positive_margin &&
negative_margin == other.negative_margin &&
quirky_positive_margin == other.quirky_positive_margin &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace blink {

// This struct is used for the margin collapsing calculation.
struct CORE_EXPORT NGMarginStrut {
struct CORE_EXPORT MarginStrut {
LayoutUnit positive_margin;
LayoutUnit negative_margin;

Expand Down Expand Up @@ -50,10 +50,8 @@ struct CORE_EXPORT NGMarginStrut {
// Whether there have been no margins appended to this margin strut.
bool IsEmpty() const;

bool operator==(const NGMarginStrut& other) const;
bool operator!=(const NGMarginStrut& other) const {
return !(*this == other);
}
bool operator==(const MarginStrut& other) const;
bool operator!=(const MarginStrut& other) const { return !(*this == other); }
};

} // namespace blink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ const NGLayoutResult* NGInlineLayoutAlgorithm::Layout() {
// having resolved the BFC offset).
context_->ClearParallelFlowBreakTokens();

end_margin_strut_ = ConstraintSpace().MarginStrut();
end_margin_strut_ = ConstraintSpace().GetMarginStrut();
container_builder_.SetAdjoiningObjectTypes(
ConstraintSpace().AdjoiningObjectTypes());
lines_until_clamp_ = ConstraintSpace().LinesUntilClamp();
Expand All @@ -1377,7 +1377,7 @@ const NGLayoutResult* NGInlineLayoutAlgorithm::Layout() {
LayoutUnit bfc_block_offset =
ConstraintSpace().ForcedBfcBlockOffset().value_or(
ConstraintSpace().GetBfcOffset().block_offset +
ConstraintSpace().MarginStrut().Sum());
ConstraintSpace().GetMarginStrut().Sum());

// Also apply clearance if necessary.
if (ConstraintSpace().HasClearanceOffset() &&
Expand Down Expand Up @@ -1691,7 +1691,7 @@ const NGLayoutResult* NGInlineLayoutAlgorithm::Layout() {
// Margins should only collapse across "certain zero-height line boxes".
// https://drafts.csswg.org/css2/box.html#collapsing-margins
if (!line_info.IsBlockInInline()) {
end_margin_strut_ = NGMarginStrut();
end_margin_strut_ = MarginStrut();
if (lines_until_clamp_)
*lines_until_clamp_ = *lines_until_clamp_ - 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class CORE_EXPORT NGInlineLayoutAlgorithm final

const NGColumnSpannerPath* column_spanner_path_;

NGMarginStrut end_margin_strut_;
MarginStrut end_margin_strut_;
absl::optional<int> lines_until_clamp_;

FontBaseline baseline_type_ = FontBaseline::kAlphabeticBaseline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ inline const NGLayoutResult* NGBlockLayoutAlgorithm::Layout(
LayoutUnit content_edge = BorderScrollbarPadding().block_start;

NGPreviousInflowPosition previous_inflow_position = {
LayoutUnit(), ConstraintSpace().MarginStrut(),
LayoutUnit(), ConstraintSpace().GetMarginStrut(),
is_resuming_ ? LayoutUnit() : container_builder_.Padding().block_start,
/* self_collapsing_child_had_clearance */ false};

Expand Down Expand Up @@ -676,7 +676,7 @@ inline const NGLayoutResult* NGBlockLayoutAlgorithm::Layout(
// If this is a new formatting context, or if we're resuming from a break
// token, no margin strut must be lingering around at this point.
if (ConstraintSpace().IsNewFormattingContext() || is_resuming_)
DCHECK(ConstraintSpace().MarginStrut().IsEmpty());
DCHECK(ConstraintSpace().GetMarginStrut().IsEmpty());

if (!container_builder_.BfcBlockOffset()) {
// New formatting-contexts, and when we have a self-collapsing child
Expand Down Expand Up @@ -911,7 +911,7 @@ const NGLayoutResult* NGBlockLayoutAlgorithm::FinishLayout(
NGPreviousInflowPosition* previous_inflow_position,
NGInlineChildLayoutContext* inline_child_layout_context) {
LogicalSize border_box_size = container_builder_.InitialBorderBoxSize();
NGMarginStrut end_margin_strut = previous_inflow_position->margin_strut;
MarginStrut end_margin_strut = previous_inflow_position->margin_strut;

// Add line height for empty content editable or button with empty label, e.g.
// <div contenteditable></div>, <input type="button" value="">
Expand Down Expand Up @@ -962,7 +962,7 @@ const NGLayoutResult* NGBlockLayoutAlgorithm::FinishLayout(
DCHECK(container_builder_.BfcBlockOffset());
intrinsic_block_size_ =
*intrinsic_block_size_when_clamped_ + block_end_border_padding;
end_margin_strut = NGMarginStrut();
end_margin_strut = MarginStrut();
} else if (block_end_border_padding ||
previous_inflow_position->self_collapsing_child_had_clearance ||
ConstraintSpace().IsNewFormattingContext()) {
Expand Down Expand Up @@ -1025,7 +1025,7 @@ const NGLayoutResult* NGBlockLayoutAlgorithm::FinishLayout(
block_end_border_padding = LayoutUnit();
}
intrinsic_block_size_ += block_end_border_padding;
end_margin_strut = NGMarginStrut();
end_margin_strut = MarginStrut();
} else {
// Update our intrinsic block size to be just past the block-end border edge
// of the last in-flow child. The pending margin is to be propagated to our
Expand Down Expand Up @@ -1084,7 +1084,7 @@ const NGLayoutResult* NGBlockLayoutAlgorithm::FinishLayout(
// - The parent has computed block-size != auto.
if (border_box_size.block_size != intrinsic_block_size_ ||
!BlockLengthUnresolvable(ConstraintSpace(), Style().LogicalHeight())) {
end_margin_strut = NGMarginStrut();
end_margin_strut = MarginStrut();
}
}

Expand Down Expand Up @@ -1434,7 +1434,7 @@ NGLayoutResult::EStatus NGBlockLayoutAlgorithm::HandleNewFormattingContext(
// realize that the child isn't going to fit beside the floats at the current
// position, and therefore re-resolve the BFC block offset with the child's
// margin non-adjoining. This is akin to clearance.
NGMarginStrut adjoining_margin_strut(previous_inflow_position->margin_strut);
MarginStrut adjoining_margin_strut(previous_inflow_position->margin_strut);
adjoining_margin_strut.Append(child_data.margins.block_start,
child_style.HasMarginBeforeQuirk());
LayoutUnit adjoining_bfc_offset_estimate =
Expand Down Expand Up @@ -2068,7 +2068,7 @@ NGLayoutResult::EStatus NGBlockLayoutAlgorithm::FinishInflow(
// The resulting margin strut in the above example will be {40, -30}. See
// |ComputeInflowPosition| for how this end margin strut is used.
if (self_collapsing_child_had_clearance) {
NGMarginStrut margin_strut;
MarginStrut margin_strut;
margin_strut.Append(child_data->margins.block_start,
child.Style().HasMarginBeforeQuirk());

Expand Down Expand Up @@ -2289,7 +2289,7 @@ NGInflowChildData NGBlockLayoutAlgorithm::ComputeChildData(
// Append the current margin strut with child's block start margin.
// Non empty border/padding, and new formatting-context use cases are handled
// inside of the child's layout
NGMarginStrut margin_strut = previous_inflow_position.margin_strut;
MarginStrut margin_strut = previous_inflow_position.margin_strut;

LayoutUnit logical_block_offset =
previous_inflow_position.logical_block_offset;
Expand All @@ -2302,7 +2302,7 @@ NGInflowChildData NGBlockLayoutAlgorithm::ComputeChildData(
// After a forced fragmentainer break we need to reset the margin strut,
// in case it was set to discard all margins (which is the default at
// breaks). Margins after a forced break should be retained.
margin_strut = NGMarginStrut();
margin_strut = MarginStrut();
}

if (child_block_break_token->MonolithicOverflow() &&
Expand Down Expand Up @@ -2414,7 +2414,7 @@ NGPreviousInflowPosition NGBlockLayoutAlgorithm::ComputeInflowPosition(
layout_result.ClearanceAfterLine());
}

NGMarginStrut margin_strut = layout_result.EndMarginStrut();
MarginStrut margin_strut = layout_result.EndMarginStrut();

// Self collapsing child's end margin can "inherit" quirkiness from its start
// margin. E.g.
Expand All @@ -2440,7 +2440,7 @@ NGPreviousInflowPosition NGBlockLayoutAlgorithm::ComputeInflowPosition(
// (if any). It should only be applied after the fragment where we
// reached the block-end of the node.
if (!token->IsAtBlockEnd())
margin_strut = NGMarginStrut();
margin_strut = MarginStrut();
}
}
}
Expand Down Expand Up @@ -3077,7 +3077,7 @@ bool NGBlockLayoutAlgorithm::ResolveBfcBlockOffset(
// is empty (note that a strut that's set up to eat all margins will also be
// considered to be empty).
if (!is_resuming_)
previous_inflow_position->margin_strut = NGMarginStrut();
previous_inflow_position->margin_strut = MarginStrut();
else
DCHECK(previous_inflow_position->margin_strut.IsEmpty());

Expand All @@ -3096,7 +3096,7 @@ bool NGBlockLayoutAlgorithm::NeedsAbortOnBfcBlockOffsetChange() const {

absl::optional<LayoutUnit>
NGBlockLayoutAlgorithm::CalculateQuirkyBodyMarginBlockSum(
const NGMarginStrut& end_margin_strut) {
const MarginStrut& end_margin_strut) {
if (!Node().IsQuirkyAndFillsViewport())
return absl::nullopt;

Expand All @@ -3115,7 +3115,7 @@ NGBlockLayoutAlgorithm::CalculateQuirkyBodyMarginBlockSum(
if (!container_builder_.BfcBlockOffset())
return end_margin_strut.Sum() + block_end_margin;

NGMarginStrut body_strut = end_margin_strut;
MarginStrut body_strut = end_margin_strut;
body_strut.Append(block_end_margin, Style().HasMarginAfterQuirk());
return *container_builder_.BfcBlockOffset() -
ConstraintSpace().GetBfcOffset().block_offset + body_strut.Sum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NGFragment;
// inflow child. This will be used to calculate the position of the next child.
struct NGPreviousInflowPosition {
LayoutUnit logical_block_offset;
NGMarginStrut margin_strut;
MarginStrut margin_strut;
// > 0: Block-end annotation space of the previous line
// < 0: Block-end annotation overflow of the previous line
LayoutUnit block_end_annotation_space;
Expand All @@ -41,7 +41,7 @@ struct NGPreviousInflowPosition {
// useful outside of handling this single inflow child.
struct NGInflowChildData {
NGInflowChildData(BfcOffset bfc_offset_estimate,
const NGMarginStrut& margin_strut,
const MarginStrut& margin_strut,
const BoxStrut& margins,
bool is_pushed_by_floats = false)
: bfc_offset_estimate(bfc_offset_estimate),
Expand All @@ -52,7 +52,7 @@ struct NGInflowChildData {
NGInflowChildData(const NGInflowChildData&) = default;

BfcOffset bfc_offset_estimate;
NGMarginStrut margin_strut;
MarginStrut margin_strut;
BoxStrut margins;
bool is_pushed_by_floats = false;
};
Expand Down Expand Up @@ -343,7 +343,7 @@ class CORE_EXPORT NGBlockLayoutAlgorithm
// element, and is computed upfront for the |ClampIntrinsicBlockSize|
// function.
absl::optional<LayoutUnit> CalculateQuirkyBodyMarginBlockSum(
const NGMarginStrut& end_margin_strut);
const MarginStrut& end_margin_strut);

// Return true if this is a list-item that may have to place a marker.
bool ShouldPlaceUnpositionedListMarker() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void NGBoxFragmentBuilder::AddResult(
}
}

const NGMarginStrut end_margin_strut = child_layout_result.EndMarginStrut();
const MarginStrut end_margin_strut = child_layout_result.EndMarginStrut();
// No margins should pierce outside formatting-context roots.
DCHECK(!fragment.IsFormattingContextRoot() || end_margin_strut.IsEmpty());

Expand Down Expand Up @@ -171,7 +171,7 @@ void NGBoxFragmentBuilder::AddResult(const NGLayoutResult& child_layout_result,
void NGBoxFragmentBuilder::AddChild(
const NGPhysicalFragment& child,
const LogicalOffset& child_offset,
const NGMarginStrut* margin_strut,
const MarginStrut* margin_strut,
bool is_self_collapsing,
absl::optional<LogicalOffset> relative_offset,
const NGInlineContainer<LogicalOffset>* inline_container) {
Expand Down Expand Up @@ -231,7 +231,7 @@ void NGBoxFragmentBuilder::AddChild(
// If we are in block-flow layout we use the end *margin-strut* as the
// block-end "margin" (instead of just the block-end margin).
if (margin_strut) {
NGMarginStrut end_margin_strut = *margin_strut;
MarginStrut end_margin_strut = *margin_strut;
end_margin_strut.Append(margins.block_end, /* is_quirky */ false);

// Self-collapsing blocks are special, their end margin-strut is part
Expand Down Expand Up @@ -517,7 +517,7 @@ const NGLayoutResult* NGBoxFragmentBuilder::ToBoxFragment(
// we don't prevent such propagation, the trailing margin may push down
// subsequent nodes that are being resumed after a break, rather than
// resuming at the block-start of the fragmentainer.
end_margin_strut_ = NGMarginStrut();
end_margin_strut_ = MarginStrut();
}

if (!break_token_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class CORE_EXPORT NGBoxFragmentBuilder final : public NGFragmentBuilder {
void AddChild(
const NGPhysicalFragment&,
const LogicalOffset&,
const NGMarginStrut* margin_strut = nullptr,
const MarginStrut* margin_strut = nullptr,
bool is_self_collapsing = false,
absl::optional<LogicalOffset> relative_offset = absl::nullopt,
const NGInlineContainer<LogicalOffset>* inline_container = nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ MinMaxSizesResult NGColumnLayoutAlgorithm::ComputeSpannersMinMaxSizes(
}

NGBreakStatus NGColumnLayoutAlgorithm::LayoutChildren() {
NGMarginStrut margin_strut;
MarginStrut margin_strut;
MulticolPartWalker walker(Node(), BreakToken());
while (!walker.IsFinished()) {
auto entry = walker.Current();
Expand Down Expand Up @@ -576,7 +576,7 @@ struct ResultWithOffset {
const NGLayoutResult* NGColumnLayoutAlgorithm::LayoutRow(
const NGBlockBreakToken* next_column_token,
LayoutUnit minimum_column_block_size,
NGMarginStrut* margin_strut) {
MarginStrut* margin_strut) {
LogicalSize column_size(column_inline_size_, column_block_size_);

// Calculate the block-offset by including any trailing margin from a previous
Expand Down Expand Up @@ -1025,7 +1025,7 @@ const NGLayoutResult* NGColumnLayoutAlgorithm::LayoutRow(
// reset the margin strut (it has already been incorporated into the
// offset).
intrinsic_block_size_ = row_offset + intrinsic_block_size_contribution;
*margin_strut = NGMarginStrut();
*margin_strut = MarginStrut();
}

// Commit all column fragments to the fragment builder.
Expand All @@ -1044,7 +1044,7 @@ const NGLayoutResult* NGColumnLayoutAlgorithm::LayoutRow(
NGBreakStatus NGColumnLayoutAlgorithm::LayoutSpanner(
NGBlockNode spanner_node,
const NGBlockBreakToken* break_token,
NGMarginStrut* margin_strut) {
MarginStrut* margin_strut) {
spanner_path_ = nullptr;
const ComputedStyle& spanner_style = spanner_node.Style();
BoxStrut margins =
Expand Down Expand Up @@ -1105,7 +1105,7 @@ NGBreakStatus NGColumnLayoutAlgorithm::LayoutSpanner(

AttemptToPositionListMarker(spanner_fragment, block_offset);

*margin_strut = NGMarginStrut();
*margin_strut = MarginStrut();
margin_strut->Append(margins.block_end, /* is_quirky */ false);

intrinsic_block_size_ = offset.block_offset + logical_fragment.BlockSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class NGBlockBreakToken;
class NGColumnSpannerPath;
class NGConstraintSpace;
struct LogicalSize;
struct NGMarginStrut;
struct MarginStrut;

class CORE_EXPORT NGColumnLayoutAlgorithm
: public NGLayoutAlgorithm<NGBlockNode,
Expand Down Expand Up @@ -47,15 +47,15 @@ class CORE_EXPORT NGColumnLayoutAlgorithm
// row, nullptr is returned.
const NGLayoutResult* LayoutRow(const NGBlockBreakToken* next_column_token,
LayoutUnit miminum_column_block_size,
NGMarginStrut*);
MarginStrut*);

// Lay out a column spanner. The return value will tell whether to break
// before the spanner or not. If |NGBreakStatus::kContinue| is returned, and
// no break token was set, it means that we can proceed to the next row of
// columns.
NGBreakStatus LayoutSpanner(NGBlockNode spanner_node,
const NGBlockBreakToken* break_token,
NGMarginStrut*);
MarginStrut*);

// Attempt to position the list-item marker (if any) beside the child
// fragment. This requires the fragment to have a baseline. If it doesn't,
Expand Down

0 comments on commit d466641

Please sign in to comment.