Commit e24eb74c authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[LayoutNG] Remove shrink-to-fit optimization.

For NG types this isn't needed anymore. The NG types now use:
CalculateSizeBasedLayoutCacheStatusWithGeometry

Which determines the size of a fragment ahead of time, and applies the
same optimization.

The only thing that we now miss, is things which are sized shrink-to-fit
which use legacy layout.

We couldn't apply this optimization to shrink-to-fit tables, as they
may have %-based inline-sized children which affect their (final) inline
size.

Bug: 984642
Change-Id: I0d0b584f31947bb674f4e7e5d88d7af6cf5d9d98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1662535
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680095}
parent f3820911
......@@ -21,60 +21,6 @@ namespace {
// kMainSize - width / height
enum class LengthResolveType { kMinSize, kMaxSize, kMainSize };
bool ContentShrinkToFitMayChange(const ComputedStyle& style,
const NGConstraintSpace& new_space,
const NGConstraintSpace& old_space,
const NGLayoutResult& layout_result) {
if (old_space.AvailableSize().inline_size ==
new_space.AvailableSize().inline_size)
return false;
NGBoxStrut margins = ComputeMarginsForSelf(new_space, style);
#if DCHECK_IS_ON()
// The margins must be the same, as this function won't be called if we have
// percentage inline margins, and the percentage resolution size changes.
NGBoxStrut old_margins = ComputeMarginsForSelf(old_space, style);
DCHECK_EQ(margins.inline_start, old_margins.inline_start);
DCHECK_EQ(margins.inline_end, old_margins.inline_end);
#endif
LayoutUnit old_available_inline_size =
std::max(LayoutUnit(),
old_space.AvailableSize().inline_size - margins.InlineSum());
LayoutUnit new_available_inline_size =
std::max(LayoutUnit(),
new_space.AvailableSize().inline_size - margins.InlineSum());
LayoutUnit inline_size =
NGFragment(style.GetWritingMode(), layout_result.PhysicalFragment())
.InlineSize();
// If the previous fragment was at its min-content size (indicated by the old
// available size being smaller than the fragment), we may be able to skip
// layout if the new available size is also smaller.
bool unaffected_as_min_content_size =
old_available_inline_size < inline_size &&
new_available_inline_size <= inline_size;
// If the previous fragment was at its max-content size (indicated by the old
// available size being larger than the fragment), we may be able to skip
// layout if the new available size is also larger.
bool unaffected_as_max_content_size =
old_available_inline_size > inline_size &&
new_available_inline_size >= inline_size;
// TODO(crbug.com/935634): There is an additional optimization where if we
// detect (by setting a flag in the layout result) that the
// min-content == max-content we can simply just skip layout, as the
// available size won't have any effect.
if (unaffected_as_min_content_size || unaffected_as_max_content_size)
return false;
return true;
}
inline bool InlineLengthMayChange(const ComputedStyle& style,
const Length& length,
LengthResolveType type,
......@@ -100,20 +46,6 @@ inline bool InlineLengthMayChange(const ComputedStyle& style,
old_space.PercentageResolutionInlineSize()))
return true;
// For elements which shrink to fit, we can perform a specific optimization
// where we can skip relayout if the element was sized to its min-content or
// max-content size.
bool is_content_shrink_to_fit =
type == LengthResolveType::kMainSize &&
(new_space.IsShrinkToFit() || length.IsFitContent());
// TODO(ikilpatrick): Test if we can remove this optimization now that we
// compute the initial size of the fragment.
if (is_content_shrink_to_fit) {
return ContentShrinkToFitMayChange(style, new_space, old_space,
layout_result);
}
if (is_unspecified) {
if (new_space.AvailableSize().inline_size !=
old_space.AvailableSize().inline_size)
......
<!DOCTYPE html>
<link rel="help" href="https://crbug.com/984642" />
<link rel="match" href="../reference/ref-filled-green-100px-square-only.html">
<style>
html { overflow: hidden; }
</style>
<p>Test passes if there is a filled green square.</p>
<div id="target">
<div style="width: 10%;">
<div style="display: inline-table;">
<div style="display: table-cell; width: 100%;">
<span style="display: inline-block; width: 100%; height: 100px; background: green;"></span>
</div>
<div style="display: table-cell;">
<span style="display: inline-block; width: 10px; height: 100px; background: green;"></span>
</div>
</div>
</div>
</div>
<script>
document.body.offsetTop;
document.getElementById('target').style.width = '1000px';
</script>
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