Commit c08a7cce authored by Javier Fernandez's avatar Javier Fernandez Committed by Commit Bot

[css-grid] Only clear the override size for relative margin/padding

The patch landed in r699290 tried to avoid errors when computing the
the used value of relative margins or padding due old/outdated item's
override size. The solution was to clear the both the inline and block
override size whenever an item had an intrinsic or auto size, or a
relative margin or padding.

However, the change mentioned above caused a performance regression, as
described in the bug. The root cause is an excessive number of relayouts
of the items that had to clear their override-size.

This CL tries to solve the performance issue by reducing the cases where
the override-size has to be cleared. It's not necessary to reset the
inline override-size unless the item has relative margin or padding.

Bug: 1046310
Change-Id: I988ab05e0552af75bf57f5d82dc73714f377ca0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033507Reviewed-by: default avatarManuel Rego <rego@igalia.com>
Commit-Queue: Javier Fernandez <jfernandez@igalia.com>
Cr-Commit-Position: refs/heads/master@{#737766}
parent 4a7574e1
...@@ -148,29 +148,47 @@ class DefiniteSizeStrategy final : public GridTrackSizingAlgorithmStrategy { ...@@ -148,29 +148,47 @@ class DefiniteSizeStrategy final : public GridTrackSizingAlgorithmStrategy {
GridTrackSizingAlgorithmStrategy::~GridTrackSizingAlgorithmStrategy() = default; GridTrackSizingAlgorithmStrategy::~GridTrackSizingAlgorithmStrategy() = default;
bool GridTrackSizingAlgorithmStrategy:: bool GridTrackSizingAlgorithmStrategy::HasRelativeMarginOrPaddingForChild(
ShouldClearOverrideContainingBlockContentSizeForChild( const LayoutGrid& grid,
const LayoutGrid& grid, const LayoutBox& child,
const LayoutBox& child, GridTrackSizingDirection direction) {
GridTrackSizingDirection direction) {
GridTrackSizingDirection child_inline_direction = GridTrackSizingDirection child_inline_direction =
GridLayoutUtils::FlowAwareDirectionForChild(grid, child, kForColumns); GridLayoutUtils::FlowAwareDirectionForChild(grid, child, kForColumns);
if (direction == child_inline_direction) { if (direction == child_inline_direction) {
return child.HasRelativeLogicalWidth() || return child.StyleRef().MarginStart().IsPercentOrCalc() ||
child.StyleRef().LogicalWidth().IsIntrinsicOrAuto() ||
child.StyleRef().MarginStart().IsPercentOrCalc() ||
child.StyleRef().MarginEnd().IsPercentOrCalc() || child.StyleRef().MarginEnd().IsPercentOrCalc() ||
child.StyleRef().PaddingStart().IsPercentOrCalc() || child.StyleRef().PaddingStart().IsPercentOrCalc() ||
child.StyleRef().PaddingEnd().IsPercentOrCalc(); child.StyleRef().PaddingEnd().IsPercentOrCalc();
} }
return child.HasRelativeLogicalHeight() || return child.StyleRef().MarginBefore().IsPercentOrCalc() ||
child.StyleRef().LogicalHeight().IsIntrinsicOrAuto() ||
child.StyleRef().MarginBefore().IsPercentOrCalc() ||
child.StyleRef().MarginAfter().IsPercentOrCalc() || child.StyleRef().MarginAfter().IsPercentOrCalc() ||
child.StyleRef().PaddingBefore().IsPercentOrCalc() || child.StyleRef().PaddingBefore().IsPercentOrCalc() ||
child.StyleRef().PaddingAfter().IsPercentOrCalc(); child.StyleRef().PaddingAfter().IsPercentOrCalc();
} }
bool GridTrackSizingAlgorithmStrategy::HasRelativeOrIntrinsicSizeForChild(
const LayoutGrid& grid,
const LayoutBox& child,
GridTrackSizingDirection direction) {
GridTrackSizingDirection child_inline_direction =
GridLayoutUtils::FlowAwareDirectionForChild(grid, child, kForColumns);
if (direction == child_inline_direction) {
return child.HasRelativeLogicalWidth() ||
child.StyleRef().LogicalWidth().IsIntrinsicOrAuto();
}
return child.HasRelativeLogicalHeight() ||
child.StyleRef().LogicalHeight().IsIntrinsicOrAuto();
}
bool GridTrackSizingAlgorithmStrategy::
ShouldClearOverrideContainingBlockContentSizeForChild(
const LayoutGrid& grid,
const LayoutBox& child,
GridTrackSizingDirection direction) {
return HasRelativeOrIntrinsicSizeForChild(grid, child, direction) ||
HasRelativeMarginOrPaddingForChild(grid, child, direction);
}
void GridTrackSizingAlgorithmStrategy:: void GridTrackSizingAlgorithmStrategy::
SetOverrideContainingBlockContentSizeForChild( SetOverrideContainingBlockContentSizeForChild(
LayoutBox& child, LayoutBox& child,
...@@ -571,8 +589,11 @@ LayoutUnit DefiniteSizeStrategy::MinLogicalSizeForChild( ...@@ -571,8 +589,11 @@ LayoutUnit DefiniteSizeStrategy::MinLogicalSizeForChild(
kForColumns); kForColumns);
LayoutUnit indefinite_size = LayoutUnit indefinite_size =
Direction() == child_inline_direction ? LayoutUnit() : LayoutUnit(-1); Direction() == child_inline_direction ? LayoutUnit() : LayoutUnit(-1);
if (ShouldClearOverrideContainingBlockContentSizeForChild( if (HasRelativeMarginOrPaddingForChild(*GetLayoutGrid(), child,
*GetLayoutGrid(), child, Direction())) { Direction()) ||
(Direction() != child_inline_direction &&
HasRelativeOrIntrinsicSizeForChild(*GetLayoutGrid(), child,
Direction()))) {
SetOverrideContainingBlockContentSizeForChild(child, Direction(), SetOverrideContainingBlockContentSizeForChild(child, Direction(),
indefinite_size); indefinite_size);
} }
......
...@@ -341,6 +341,12 @@ class GridTrackSizingAlgorithmStrategy { ...@@ -341,6 +341,12 @@ class GridTrackSizingAlgorithmStrategy {
} }
// Helper functions // Helper functions
static bool HasRelativeMarginOrPaddingForChild(const LayoutGrid&,
const LayoutBox& child,
GridTrackSizingDirection);
static bool HasRelativeOrIntrinsicSizeForChild(const LayoutGrid&,
const LayoutBox& child,
GridTrackSizingDirection);
static bool ShouldClearOverrideContainingBlockContentSizeForChild( static bool ShouldClearOverrideContainingBlockContentSizeForChild(
const LayoutGrid&, const LayoutGrid&,
const LayoutBox& child, const LayoutBox& child,
......
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