[layout] Remove use InlineLengthUnresolvable within CalculateInitialFragmentGeometry.
Instead of passing a std::optional<LayoutUnit> inline-size, just
pass a LayoutUnit, and compare against kIndefiniteSize.
Bug: 328572265
Change-Id: Ib5f2089231661e961f75199737e1df763627ac60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5357454
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: David Baron <dbaron@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1271211}
diff --git a/third_party/blink/renderer/core/layout/flex/flex_layout_algorithm.cc b/third_party/blink/renderer/core/layout/flex/flex_layout_algorithm.cc
index 680e69b3..aa43286 100644
--- a/third_party/blink/renderer/core/layout/flex/flex_layout_algorithm.cc
+++ b/third_party/blink/renderer/core/layout/flex/flex_layout_algorithm.cc
@@ -171,14 +171,11 @@
// the term "content".
const LayoutUnit border_scrollbar_padding =
BorderScrollbarPadding().BlockSum();
- std::optional<LayoutUnit> inline_size;
- if (container_builder_.InlineSize() != kIndefiniteSize)
- inline_size = container_builder_.InlineSize();
return ComputeBlockSizeForFragment(
GetConstraintSpace(), Style(), BorderPadding(),
sum_hypothetical_main_size.ClampNegativeToZero() +
border_scrollbar_padding,
- inline_size) -
+ container_builder_.InlineSize()) -
border_scrollbar_padding;
}
return ChildAvailableSize().inline_size;
diff --git a/third_party/blink/renderer/core/layout/grid/grid_layout_algorithm.cc b/third_party/blink/renderer/core/layout/grid/grid_layout_algorithm.cc
index fe23c5a..8eb6bb6 100644
--- a/third_party/blink/renderer/core/layout/grid/grid_layout_algorithm.cc
+++ b/third_party/blink/renderer/core/layout/grid/grid_layout_algorithm.cc
@@ -1070,14 +1070,10 @@
const auto& node = To<GridNode>(subgrid_data.node);
const auto& style = node.Style();
- const auto available_inline_size =
- std::make_optional(space.AvailableSize().inline_size);
-
return ComputeBlockSizeForFragment(
space, style, ComputeBorders(space, node) + ComputePadding(space, style),
node.ComputeSubgridIntrinsicBlockSize(sizing_subtree, space),
- (*available_inline_size == kIndefiniteSize) ? std::nullopt
- : available_inline_size);
+ space.AvailableSize().inline_size);
}
} // namespace
diff --git a/third_party/blink/renderer/core/layout/length_utils.cc b/third_party/blink/renderer/core/layout/length_utils.cc
index 2894d2a..8bb5c5bc 100644
--- a/third_party/blink/renderer/core/layout/length_utils.cc
+++ b/third_party/blink/renderer/core/layout/length_utils.cc
@@ -470,7 +470,7 @@
const auto block_size = ComputeBlockSizeForFragment(
space, style, border_padding, /* intrinsic_size */ kIndefiniteSize,
- /* inline_size */ std::nullopt);
+ /* inline_size */ kIndefiniteSize);
if (block_size == kIndefiniteSize)
return kIndefiniteSize;
@@ -686,7 +686,7 @@
const ComputedStyle& style,
const BoxStrut& border_padding,
LayoutUnit intrinsic_size,
- std::optional<LayoutUnit> inline_size,
+ LayoutUnit inline_size,
LayoutUnit override_available_size = kIndefiniteSize) {
MinMaxSizes min_max = ComputeMinMaxBlockSizes(space, style, border_padding,
override_available_size);
@@ -706,8 +706,8 @@
Length logical_height = style.LogicalHeight();
LayoutUnit extent = kIndefiniteSize;
- if (has_aspect_ratio && inline_size) {
- DCHECK_GE(*inline_size, LayoutUnit());
+ if (has_aspect_ratio && inline_size != kIndefiniteSize) {
+ DCHECK_GE(inline_size, LayoutUnit());
const bool has_explicit_stretch =
logical_height.IsAuto() &&
space.BlockAutoBehavior() == AutoSizeBehavior::kStretchExplicit &&
@@ -716,7 +716,7 @@
!has_explicit_stretch) {
extent = BlockSizeFromAspectRatio(
border_padding, style.LogicalAspectRatio(),
- style.BoxSizingForAspectRatio(), *inline_size);
+ style.BoxSizingForAspectRatio(), inline_size);
DCHECK_NE(extent, kIndefiniteSize);
// Apply the automatic minimum size for aspect ratio:
@@ -761,7 +761,7 @@
const ComputedStyle& style,
const BoxStrut& border_padding,
LayoutUnit intrinsic_size,
- std::optional<LayoutUnit> inline_size,
+ LayoutUnit inline_size,
LayoutUnit override_available_size) {
// The |override_available_size| should only be used for <table>s.
DCHECK(override_available_size == kIndefiniteSize ||
@@ -792,7 +792,7 @@
const ComputedStyle& style,
const BoxStrut& border_padding,
LayoutUnit intrinsic_size,
- std::optional<LayoutUnit> inline_size,
+ LayoutUnit inline_size,
LayoutUnit override_available_size) {
if (space.IsInitialBlockSizeIndefinite())
return intrinsic_size;
@@ -1473,43 +1473,38 @@
return {border_box_size, border, scrollbar, padding};
}
- std::optional<LayoutUnit> inline_size;
- const auto default_block_size = CalculateDefaultBlockSize(
- space, node, break_token, border_scrollbar_padding);
+ const LayoutUnit inline_size =
+ is_intrinsic ? kIndefiniteSize
+ : ComputeInlineSizeForFragment(space, node, border_padding,
+ min_max_sizes_func);
- if (!is_intrinsic &&
- (space.IsFixedInlineSize() ||
- !InlineLengthUnresolvable(space, style.LogicalWidth()))) {
- inline_size = ComputeInlineSizeForFragment(space, node, border_padding,
- min_max_sizes_func);
-
- if (UNLIKELY(*inline_size < border_scrollbar_padding.InlineSum() &&
- scrollbar.InlineSum() && !space.IsAnonymous())) {
- // Clamp the inline size of the scrollbar, unless it's larger than the
- // inline size of the content box, in which case we'll return that
- // instead. Scrollbar handling is quite bad in such situations, and this
- // method here is just to make sure that left-hand scrollbars don't mess
- // up scrollWidth. For the full story, visit http://crbug.com/724255.
- const auto content_box_inline_size =
- *inline_size - border_padding.InlineSum();
-
- if (scrollbar.InlineSum() > content_box_inline_size) {
- if (scrollbar.inline_end) {
- DCHECK(!scrollbar.inline_start);
- scrollbar.inline_end = content_box_inline_size;
- } else {
- DCHECK(scrollbar.inline_start);
- scrollbar.inline_start = content_box_inline_size;
- }
+ if (UNLIKELY(inline_size != kIndefiniteSize &&
+ inline_size < border_scrollbar_padding.InlineSum() &&
+ scrollbar.InlineSum() && !space.IsAnonymous())) {
+ // Clamp the inline size of the scrollbar, unless it's larger than the
+ // inline size of the content box, in which case we'll return that instead.
+ // Scrollbar handling is quite bad in such situations, and this method here
+ // is just to make sure that left-hand scrollbars don't mess up scrollWidth.
+ // For the full story, visit http://crbug.com/724255.
+ const auto content_box_inline_size =
+ inline_size - border_padding.InlineSum();
+ if (scrollbar.InlineSum() > content_box_inline_size) {
+ if (scrollbar.inline_end) {
+ DCHECK(!scrollbar.inline_start);
+ scrollbar.inline_end = content_box_inline_size;
+ } else {
+ DCHECK(scrollbar.inline_start);
+ scrollbar.inline_start = content_box_inline_size;
}
}
}
+ const auto default_block_size = CalculateDefaultBlockSize(
+ space, node, break_token, border_scrollbar_padding);
const auto block_size = ComputeInitialBlockSizeForFragment(
space, style, border_padding, default_block_size, inline_size);
- return {LogicalSize(inline_size.value_or(kIndefiniteSize), block_size),
- border, scrollbar, padding};
+ return {LogicalSize(inline_size, block_size), border, scrollbar, padding};
}
FragmentGeometry CalculateInitialFragmentGeometry(
@@ -1620,7 +1615,7 @@
if (space.IsTableCell() && style.LogicalHeight().IsFixed()) {
LayoutUnit block_size = ComputeBlockSizeForFragmentInternal(
space, style, border_padding, kIndefiniteSize /* intrinsic_size */,
- std::nullopt /* inline_size */);
+ kIndefiniteSize /* inline_size */);
DCHECK_NE(block_size, kIndefiniteSize);
return {child_available_size.inline_size,
(block_size - border_scrollbar_padding.BlockSum())
diff --git a/third_party/blink/renderer/core/layout/length_utils.h b/third_party/blink/renderer/core/layout/length_utils.h
index ac2dc0e5..d2ce0d2 100644
--- a/third_party/blink/renderer/core/layout/length_utils.h
+++ b/third_party/blink/renderer/core/layout/length_utils.h
@@ -267,7 +267,7 @@
const ComputedStyle&,
const BoxStrut& border_padding,
LayoutUnit intrinsic_size,
- std::optional<LayoutUnit> inline_size,
+ LayoutUnit inline_size,
LayoutUnit override_available_size = kIndefiniteSize);
CORE_EXPORT LayoutUnit
@@ -324,7 +324,7 @@
const ComputedStyle&,
const BoxStrut& border_padding,
LayoutUnit intrinsic_size,
- std::optional<LayoutUnit> inline_size,
+ LayoutUnit inline_size,
LayoutUnit override_available_size = kIndefiniteSize);
// Calculates default content size for html and body elements in quirks mode.
diff --git a/third_party/blink/renderer/core/layout/length_utils_test.cc b/third_party/blink/renderer/core/layout/length_utils_test.cc
index 1d0b9a4..dec3bef 100644
--- a/third_party/blink/renderer/core/layout/length_utils_test.cc
+++ b/third_party/blink/renderer/core/layout/length_utils_test.cc
@@ -108,7 +108,7 @@
const BlockNode& node,
ConstraintSpace constraint_space = ConstructConstraintSpace(200, 300),
LayoutUnit content_size = LayoutUnit(),
- std::optional<LayoutUnit> inline_size = std::nullopt) {
+ LayoutUnit inline_size = kIndefiniteSize) {
const auto& style = node.Style();
BoxStrut border_padding = ComputeBorders(constraint_space, node) +
ComputePadding(constraint_space, style);
diff --git a/third_party/blink/renderer/core/layout/page_layout_algorithm.cc b/third_party/blink/renderer/core/layout/page_layout_algorithm.cc
index 19c15c2..44dda26 100644
--- a/third_party/blink/renderer/core/layout/page_layout_algorithm.cc
+++ b/third_party/blink/renderer/core/layout/page_layout_algorithm.cc
@@ -69,7 +69,7 @@
// Compute the block-axis size now that we know our content size.
LayoutUnit block_size = ComputeBlockSizeForFragment(
GetConstraintSpace(), Style(), /* border_padding */ BoxStrut(),
- intrinsic_block_size, std::nullopt);
+ intrinsic_block_size, kIndefiniteSize);
container_builder_.SetFragmentsTotalBlockSize(block_size);
OutOfFlowLayoutPart(Node(), GetConstraintSpace(), &container_builder_).Run();