diff --git a/third_party/blink/renderer/core/layout/layout_box.h b/third_party/blink/renderer/core/layout/layout_box.h index c8b4c784d1da65..c50ad907cb8fbb 100644 --- a/third_party/blink/renderer/core/layout/layout_box.h +++ b/third_party/blink/renderer/core/layout/layout_box.h @@ -1179,11 +1179,28 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject { : PhysicalRect(PhysicalOffset(), PreviousSize()); } - // Returns cached intrinsic logical widths for this layout box. - MinMaxSizes CachedIntrinsicLogicalWidths() const { + // Returns the cached intrinsic logical widths when no children depend on the + // block constraints. + MinMaxSizesResult CachedIndefiniteIntrinsicLogicalWidths() const { NOT_DESTROYED(); DCHECK(!IntrinsicLogicalWidthsDirty()); - return intrinsic_logical_widths_; + DCHECK(!IntrinsicLogicalWidthsChildDependsOnBlockConstraints()); + return {intrinsic_logical_widths_, + IntrinsicLogicalWidthsDependsOnBlockConstraints()}; + } + + // Returns the cached intrinsic logical widths if the initial block-size + // matches. + absl::optional CachedIntrinsicLogicalWidths( + LayoutUnit initial_block_size) const { + NOT_DESTROYED(); + DCHECK(!IntrinsicLogicalWidthsDirty()); + if (initial_block_size == intrinsic_logical_widths_initial_block_size_) { + return MinMaxSizesResult{ + intrinsic_logical_widths_, + IntrinsicLogicalWidthsDependsOnBlockConstraints()}; + } + return absl::nullopt; } // LayoutNG can use this function to update our cache of intrinsic logical @@ -1191,33 +1208,20 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject { // regular code. // // Also clears the "dirty" flag for the intrinsic logical widths. - void SetIntrinsicLogicalWidthsFromNG( - LayoutUnit intrinsic_logical_widths_initial_block_size, - bool depends_on_block_constraints, - bool child_depends_on_block_constraints, - const MinMaxSizes& sizes) { - NOT_DESTROYED(); - intrinsic_logical_widths_initial_block_size_ = - intrinsic_logical_widths_initial_block_size; + void SetIntrinsicLogicalWidths(LayoutUnit initial_block_size, + bool depends_on_block_constraints, + bool child_depends_on_block_constraints, + const MinMaxSizes& sizes) { + NOT_DESTROYED(); + intrinsic_logical_widths_ = sizes; + intrinsic_logical_widths_initial_block_size_ = initial_block_size; SetIntrinsicLogicalWidthsDependsOnBlockConstraints( depends_on_block_constraints); SetIntrinsicLogicalWidthsChildDependsOnBlockConstraints( child_depends_on_block_constraints); - intrinsic_logical_widths_ = sizes; ClearIntrinsicLogicalWidthsDirty(); } - // Returns what initial block-size was used in the intrinsic logical widths - // phase. This is used for caching purposes when %-block-size children with - // aspect-ratios are present. - // - // For non-LayoutNG code this is always LayoutUnit::Min(), and should not be - // used for caching purposes. - LayoutUnit IntrinsicLogicalWidthsInitialBlockSize() const { - NOT_DESTROYED(); - return intrinsic_logical_widths_initial_block_size_; - } - // Make it public. using LayoutObject::BackgroundIsKnownToBeObscured; diff --git a/third_party/blink/renderer/core/layout/min_max_sizes.h b/third_party/blink/renderer/core/layout/min_max_sizes.h index 92dcac1c3cd849..fa95408653cfab 100644 --- a/third_party/blink/renderer/core/layout/min_max_sizes.h +++ b/third_party/blink/renderer/core/layout/min_max_sizes.h @@ -83,6 +83,19 @@ struct CORE_EXPORT MinMaxSizes { CORE_EXPORT std::ostream& operator<<(std::ostream&, const MinMaxSizes&); +// The output of the min/max inline size calculation algorithm. Contains the +// min/max sizes, and if this calculation will change if the block constraints +// change. +struct MinMaxSizesResult { + MinMaxSizesResult() = default; + MinMaxSizesResult(MinMaxSizes sizes, bool depends_on_block_constraints) + : sizes(sizes), + depends_on_block_constraints(depends_on_block_constraints) {} + + MinMaxSizes sizes; + bool depends_on_block_constraints = false; +}; + } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_MIN_MAX_SIZES_H_ diff --git a/third_party/blink/renderer/core/layout/ng/ng_block_node.cc b/third_party/blink/renderer/core/layout/ng/ng_block_node.cc index 0aab7ee6d01628..0a3b3b0c6b3eb8 100644 --- a/third_party/blink/renderer/core/layout/ng/ng_block_node.cc +++ b/third_party/blink/renderer/core/layout/ng/ng_block_node.cc @@ -974,21 +974,18 @@ MinMaxSizesResult BlockNode::ComputeMinMaxSizes( bool can_use_cached_intrinsic_inline_sizes = CanUseCachedIntrinsicInlineSizes(constraint_space, float_input, *this); + // Ensure the cache is invalid if we know we can't use our cached sizes. + if (!can_use_cached_intrinsic_inline_sizes) { + box_->SetIntrinsicLogicalWidthsDirty(kMarkOnlyThis); + } + // Use our cached sizes if we don't have a descendant which depends on our // block constraints. if (can_use_cached_intrinsic_inline_sizes && !box_->IntrinsicLogicalWidthsChildDependsOnBlockConstraints()) { - MinMaxSizes sizes = box_->CachedIntrinsicLogicalWidths(); - bool depends_on_block_constraints = - box_->IntrinsicLogicalWidthsDependsOnBlockConstraints(); - return MinMaxSizesResult(sizes, depends_on_block_constraints); + return box_->CachedIndefiniteIntrinsicLogicalWidths(); } - // Determine if we are dependent on the block-constraints. - bool self_depends_on_block_constraints = - DependsOnBlockConstraints() || - UseParentPercentageResolutionBlockSizeForChildren(); - const FragmentGeometry fragment_geometry = CalculateInitialFragmentGeometry( constraint_space, *this, /* break_token */ nullptr, /* is_intrinsic */ true); @@ -998,15 +995,12 @@ MinMaxSizesResult BlockNode::ComputeMinMaxSizes( // We might still be able to use the cached values if our children don't // depend on the *input* %-block-size. if (can_use_cached_intrinsic_inline_sizes && - initial_block_size == box_->IntrinsicLogicalWidthsInitialBlockSize() && !UseParentPercentageResolutionBlockSizeForChildren()) { - DCHECK(box_->IntrinsicLogicalWidthsChildDependsOnBlockConstraints()); - MinMaxSizes sizes = box_->CachedIntrinsicLogicalWidths(); - return MinMaxSizesResult(sizes, self_depends_on_block_constraints); + if (auto result = box_->CachedIntrinsicLogicalWidths(initial_block_size)) { + return *result; + } } - box_->SetIntrinsicLogicalWidthsDirty(kMarkOnlyThis); - const BoxStrut border_padding = fragment_geometry.border + fragment_geometry.padding; @@ -1017,8 +1011,11 @@ MinMaxSizesResult BlockNode::ComputeMinMaxSizes( if (auto min_size = ContentMinimumInlineSize(*this, border_padding)) result.sizes.min_size = *min_size; + // Determine if we are dependent on the block-constraints. bool depends_on_block_constraints = - self_depends_on_block_constraints && result.depends_on_block_constraints; + (DependsOnBlockConstraints() || + UseParentPercentageResolutionBlockSizeForChildren()) && + result.depends_on_block_constraints; if (!Style().AspectRatio().IsAuto() && BlockLengthUnresolvable(constraint_space, Style().LogicalHeight())) { @@ -1035,7 +1032,7 @@ MinMaxSizesResult BlockNode::ComputeMinMaxSizes( Style().LogicalMaxHeight().IsPercentOrCalcOrStretch(); } - box_->SetIntrinsicLogicalWidthsFromNG( + box_->SetIntrinsicLogicalWidths( initial_block_size, depends_on_block_constraints, /* child_depends_on_block_constraints */ result.depends_on_block_constraints, result.sizes); diff --git a/third_party/blink/renderer/core/layout/ng/ng_layout_input_node.h b/third_party/blink/renderer/core/layout/ng/ng_layout_input_node.h index 4c37059d51d35d..25edcca559398f 100644 --- a/third_party/blink/renderer/core/layout/ng/ng_layout_input_node.h +++ b/third_party/blink/renderer/core/layout/ng/ng_layout_input_node.h @@ -24,7 +24,6 @@ class ComputedStyle; class Document; class LayoutObject; class LayoutBox; -struct MinMaxSizes; struct PhysicalSize; // The input to the min/max inline size calculation algorithm for child nodes. @@ -36,19 +35,6 @@ struct MinMaxSizesFloatInput { LayoutUnit float_right_inline_size; }; -// The output of the min/max inline size calculation algorithm. Contains the -// min/max sizes, and if this calculation will change if the block constraints -// change. -struct MinMaxSizesResult { - MinMaxSizesResult() = default; - MinMaxSizesResult(MinMaxSizes sizes, bool depends_on_block_constraints) - : sizes(sizes), - depends_on_block_constraints(depends_on_block_constraints) {} - - MinMaxSizes sizes; - bool depends_on_block_constraints = false; -}; - // Represents the input to a layout algorithm for a given node. The layout // engine should use the style, node type to determine which type of layout // algorithm to use to produce fragments for this node.