Commit graph

802 commits

Author SHA1 Message Date
Martin Robinson
ff6e1e7e64 Bug 1767262 - Lazily layout content that is hidden via content-visibility: hidden r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D145949
2022-08-29 14:41:36 +00:00
Ting-Yu Lin
f030093058 Bug 1786610 - Use auto main-size workaround for replaced elements without aspect-ratio when computing flex base size. r=dholbert
This bug is regressed by Bug 1686603 Part 4 [1]. When the used flex-basis is
'content', the old code computes flex base size by using 'auto' as the main size
in `nsContainerFrame::ComputeSizeWithIntrinsicDimensions()`. The method is for
replaced elements to compute sizes, even if the element has no preferred
aspect-ratio such as an `<svg>` without viewBox nor aspect-ratio property.

However, Bug 1686603 Part 4 made replaced elements without preferred
aspect-ratio uses 'max-content' when computing flex base size. Unfortunately, we
only trigger the replaced elements intrinsic sizing via 'auto' but not via
'max-content', so this patch restores the behavior via emplacing 'auto' in
`styleFlexBaseSize`.

[1] https://phabricator.services.mozilla.com/D101795

Differential Revision: https://phabricator.services.mozilla.com/D155628
2022-08-26 07:20:04 +00:00
Sandor Molnar
a4f3a0f44b Backed out changeset f67c8298a104 (bug 1767262) for causing wpt assertion failures in layout/base/PresShell.cpp CLOSED TREE 2022-08-24 20:39:45 +03:00
Martin Robinson
9d8878f0d0 Bug 1767262 - Lazily layout content that is hidden via content-visibility: hidden r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D145949
2022-08-24 13:30:55 +00:00
Butkovits Atila
5c5ef28ffa Backed out changeset 5a4a5749f8dc (bug 1767262) for causing wpt failures. 2022-08-23 18:33:04 +03:00
Martin Robinson
4d8325d138 Bug 1767262 - Lazily layout content that is hidden via content-visibility: hidden r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D145949
2022-08-23 14:16:10 +00:00
Emilio Cobos Álvarez
534f39ed75 Bug 1785310 - Remove mozilla/StaticPrefs_layout.h includes from other headers. r=dholbert
Adding layout prefs cause massive rebuilds because of this.

Differential Revision: https://phabricator.services.mozilla.com/D154928
2022-08-17 21:26:36 +00:00
Butkovits Atila
ae6a677e52 Backed out changeset 7538d23ee88e (bug 1767262) for causing failures at content-visibility-081.html. CLOSED TREE 2022-08-15 20:37:49 +03:00
Martin Robinson
1cf715eb0d Bug 1767262 - Lazily layout content that is hidden via content-visibility: hidden r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D145949
2022-08-15 16:18:43 +00:00
Oriol Brufau
9ebd6bd8e5 Bug 1781995 - Obey contain-intrinsic-size in flex containers. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D152984
2022-07-28 09:42:55 +00:00
Ting-Yu Lin
f101e2077d Bug 1464761 Part 4 - Remove nsReflowStatus::mTruncated bit. r=dholbert
In the description of the mTruncated bit, its purpose is the same as calling
SetInlineLineBreakBeforeAndReset(). We've removed all its usages in previous
patches, so the bit is no longer needed.

Differential Revision: https://phabricator.services.mozilla.com/D151461
2022-07-27 21:55:18 +00:00
Ting-Yu Lin
cbdc83f787 Bug 1776079 - Delete SharedFlexData() only if there's no flex container's next-in-flow. r=dholbert
nsGridContainerFrame has the same logic.
https://searchfox.org/mozilla-central/rev/6d0ba065e3d41822337c708c8c0aca334ddd9218/layout/generic/nsGridContainerFrame.cpp#9116

Differential Revision: https://phabricator.services.mozilla.com/D150157
2022-06-24 05:00:07 +00:00
Ting-Yu Lin
4b73cd1e20 Bug 1739561 - Honor break-inside:avoid on flex containers. r=dholbert
Note this patch only prevents "break-inside:avoid" flex containers from being
broken when they are not at the top of their current page/column. When they are
at the top of their current page/column, this patch fails to help since
`nsContainerFrame::ShouldAvoidBreakInside()` returns `false` via the
`mIsTopOfPage` check. This is essentially bug 793686.

Differential Revision: https://phabricator.services.mozilla.com/D149318
2022-06-15 00:55:54 +00:00
Boris Chiou
035220bf4c Bug 1760658 - Part 1: Apply automatic content-based minimum on flex container. r=emilio
Basides, factor out the utility function to AspectRatio so everyone can
use it.

Differential Revision: https://phabricator.services.mozilla.com/D144891
2022-05-02 20:06:32 +00:00
David Shin
ec93876623 Bug 1755565 - Implement contain: inline-size. r=emilio,dholbert
Differential Revision: https://phabricator.services.mozilla.com/D143501
2022-04-19 17:44:16 +00:00
Ting-Yu Lin
04af168c74 Bug 1758020 - Revise MoveFlexItemToFinalPosition(). r=dholbert
This patch shouldn't change the behavior.

* It's OK to get the item's offset only when its relatively positioned, because
  `ApplyRelativePositioning` doesn't use the offset parameter if the frame is
  sticky positioned. Document `ApplyRelativePositioning`'s parameters to clarify
  this. Also, we don't need to call apply relative positioning to a
  non-relatively-and-non-sticky-positioned item.

* Print `FLEX_LOG` after applying relative-positioning because `aFramePos` will
  be adjusted in `ApplyRelativePositioning`, and we really want to see the
  item's "final position".

* `aReflowInput` parameter is removed because it's only used to get flex
  container's WritingMode. We can get it from FlexItem.

Differential Revision: https://phabricator.services.mozilla.com/D140703
2022-03-10 19:17:44 +00:00
Ting-Yu Lin
b48196dcda Bug 1758018 Part 2 - Add helpers testing only "position:relative", and adapt them at some callsites. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D140274
2022-03-04 03:02:01 +00:00
Ting-Yu Lin
7e0c39f9b1 Bug 1758018 Part 1 - Rename the helpers testing "position:relative" or "position:sticky". r=emilio
`nsIFrame::IsRelativelyPositioned()` tests "position:relative" or
"position:sticky", but its naming is misleading until you've dug into the
underlying helper `nsStyleDisplay::IsRelativelyPositionedStyle()`.

Differential Revision: https://phabricator.services.mozilla.com/D140273
2022-03-04 03:02:00 +00:00
Ting-Yu Lin
ae6fa4834c Bug 1752658 Part 7 - Generalize GenerateFlexLines to populate FlexLayoutResult. r=dholbert
Differential Revision: https://phabricator.services.mozilla.com/D138101
2022-02-08 22:47:20 +00:00
Ting-Yu Lin
141dbba00c Bug 1752658 Part 6 - Pass FlexLayoutResult into ReflowChildren(). r=dholbert
Currently, we pass all the five fields in FlexLayoutResult separately into
ReflowChildren(), but we really should just pass FlexLayoutResult instead.

Differential Revision: https://phabricator.services.mozilla.com/D138100
2022-02-08 22:47:20 +00:00
Ting-Yu Lin
6191c0136b Bug 1752658 Part 5 - Pass flex container's tentative cross size into DoFlexLayout and others. r=dholbert
We've got the tentative cross size before calling DoFlexLayout() in Reflow(), so
we can just use that value in DoFlexLayout and a few other methods.

Also, add "ContentBox" to naming of the main size argument ComputeMainSize().

Differential Revision: https://phabricator.services.mozilla.com/D137365
2022-02-08 22:47:20 +00:00
Ting-Yu Lin
0db4093210 Bug 1752658 Part 4 - Aggregate DoFlexLayout's output data in a struct instead of output arguments. r=dholbert
I found in/out parameters confusing when reasoning the data flow. Aggregating
DoFlexLayout's output data in a struct also reduces DoFlexLayout's number of
arguments.

Differential Revision: https://phabricator.services.mozilla.com/D137364
2022-02-08 22:47:19 +00:00
Ting-Yu Lin
f0a1413baf Bug 1752658 Part 3 - Reduce scope of the struts array in Reflow(). r=dholbert
The `struts` array is used only within DoFlexLayout, so we should move it into
`if (!GetPrevInFlow()) { ... }` branch.

Also, move `nsTArray<StrutInfo>&` argument on DoFlexLayout() to the second to
last place so that the output arguments are grouped together after applying Part
4.

Differential Revision: https://phabricator.services.mozilla.com/D137363
2022-02-08 22:47:19 +00:00
Ting-Yu Lin
2b61aa41a4 Bug 1752658 Part 2 - Remove aConsumedBSize from DoFlexLayout() and ComputeCrossSize(). r=dholbert
DoFlexLayout() and ComputeCrossSize() are only called in first-in-flow, so
aConsumedBSize are always 0.

Differential Revision: https://phabricator.services.mozilla.com/D137362
2022-02-08 22:47:19 +00:00
Ting-Yu Lin
6e68c19465 Bug 1752658 Part 1 - Compute gap sizes only in flex container's first-in-flow. r=dholbert
Move the assertion for unconstrained isize to the beginning of Reflow() because
we check it in all cases -- in GetMainSizeFromReflowInput when a flex container
is row-oriented, or in the old code computing gap size and ComputeCrossSize()
when a flex container is column-oriented.

Differential Revision: https://phabricator.services.mozilla.com/D137361
2022-02-08 22:47:18 +00:00
Ting-Yu Lin
9a07ff37d5 Bug 1751471 - Add a diagnostic preference to always run flex item's final reflow. r=dholbert
Differential Revision: https://phabricator.services.mozilla.com/D136764
2022-01-25 06:21:08 +00:00
Ting-Yu Lin
32b84f3235 Bug 1747515 - Remove an obsolete comment in nsFlexContainerFrame.cpp. r=dholbert
We introduced this comment at the very beginning of the flexbox implementation.
Since then, WritingModes.h has obtained the utilities dealing with logical axis,
and CSSAlignUtils.h has supported CSS alignment for both flexbox and grid. All
the helper functions remaining in nsFlexContainerFrame.cpp are related to
flexbox, so I feel it's time we retire this comment.

NPOTB DONTBUILD because this patch changes only comments.

Differential Revision: https://phabricator.services.mozilla.com/D134652
2021-12-25 16:11:29 +00:00
Ting-Yu Lin
0ddbd1d7f7 Bug 1543267 Part 2 - Make 'space-between' fallback to 'flex-start' for flexbox's abspos children. r=dholbert
Per Alignment spec [1], the default fallback alignment for 'space-between' is
'flex-start'.

[1] https://drafts.csswg.org/css-align/#valdef-align-content-space-between

Differential Revision: https://phabricator.services.mozilla.com/D134544
2021-12-23 02:08:04 +00:00
Ting-Yu Lin
2d47a61355 Bug 1543267 Part 1 - Make 'stretch' fallback to 'flex-start' for flexbox's abspos children. r=dholbert
In Flexbox spec 4.1, Example 3 [1]:
   ... since the absolutely-positioned box is considered to be
   "fixed-size", a value of stretch is treated the same as flex-start.

Also, per Alignment 3 spec [2]:
  The default fallback alignment for 'stretch' is 'flex-start'.

Thus, when computing the alignment for flexbox's abspos children in
CSSAlignmentForAbsPosChild(), we convert 'stretch' to 'flex-start', and let the
subsequent logic convert 'flex-start' to either 'start' or 'end', because
nsAbsoluteContainingBlock don't know how to deal with the flex-relative axis.

This patch makes us behave the same as Google Chrome on the modified testcases.

[1] https://drafts.csswg.org/css-flexbox/#abspos-items
[2] https://drafts.csswg.org/css-align/#valdef-align-content-stretch

Differential Revision: https://phabricator.services.mozilla.com/D134543
2021-12-23 02:08:03 +00:00
Ting-Yu Lin
5909d5b7f3 Bug 1744895 Part 3 - Fix justify-*:{left|right} mapping for abspos children of flex containers. r=dholbert
Differential Revision: https://phabricator.services.mozilla.com/D133169
2021-12-10 17:42:23 +00:00
Ting-Yu Lin
fd68e79da7 Bug 1744895 Part 2 - Fix justify-*:{left|right} mapping for vertical row-oriented flex containers. r=dholbert
Currently, we use IsPhysicalLTR() to query which is the start side of the
physical left <-> right axis. However, for vertical row-oriented flex
containers, physical left <-> right axis is its cross axis. We really should
query IsBidiLTR() instead because its main axis is parallel to line-left <->
line-right axis (i.e. inline axis).

flexbox-justify-content-wmvert-003.html is adapted from
flexbox-justify-content-wmvert-002.html.

Differential Revision: https://phabricator.services.mozilla.com/D133168
2021-12-10 17:42:22 +00:00
Ting-Yu Lin
06346bb565 Bug 1744895 Part 1 - Extract a helper mapping justify-*:{left|right} to {start|end}. r=dholbert
Differential Revision: https://phabricator.services.mozilla.com/D133167
2021-12-10 17:42:22 +00:00
Ting-Yu Lin
248b711736 Bug 1730570 - Clamp flex item's resolved min auto size if it's bogus. r=dholbert
This patch clamps the `resolvedMinSize` before the size is passed into
`UpdateMainMinSize`, which is where the assertion is triggered.

Also, tweak the MOZ_ASSERT a bit because it's best to test an nscoord is
not NS_UNCONSTRAINEDSIZE before invoking comparison operator.

Differential Revision: https://phabricator.services.mozilla.com/D129230
2021-10-26 00:01:58 +00:00
Ting-Yu Lin
ca7c388f7e Bug 1735251 - Use AxisTracker::MainComponent() to retrieve main max size. r=emilio
After Bug 1681849 Part 4 [1], accessing ComputedMaxSize() is trivial.
Note: MainComponent() expects its aSize argument in flex container's
writing mode, which matches aReflowInput's writing mode, so we don't
need any conversion.

[1] https://hg.mozilla.org/mozilla-central/rev/80ed365889fc

Differential Revision: https://phabricator.services.mozilla.com/D128151
2021-10-12 17:51:12 +00:00
Ting-Yu Lin
5a1edcbcec Bug 1145323 - Audit callers of ReflowOutput constructor in nsFlexContainerFrame. r=dholbert
ReflowOutput can accept any writing mode or ReflowInput passed to its
constructor, so a caller can pass a writing mode that is more convenient
to retrieve the size.

After reflowing flex items, we want to cache its metrics in flex item's
writing mode, so we pass item's ReflowInput into ReflowOutput. However,
for out-of-flow children, we can change ReflowOutput to use flex
container's writing mode by convention.

Differential Revision: https://phabricator.services.mozilla.com/D127913
2021-10-08 17:50:35 +00:00
Ting-Yu Lin
143fe07a33 Bug 1700580 Part 4 - Cache flex item's border and padding used in the final reflow. r=dholbert
Currently, we assume any flex item with percentage padding will be
marked as dirty if the percentage basis is changed. However, it is not
true.

To fix it, we cache the flex item's border and padding used in its most
recent final reflow to detect their changes.

dynamic-isize-change-004.html is designed to catch the concern in bug
1700580 comment 12.

Differential Revision: https://phabricator.services.mozilla.com/D125620
2021-09-17 05:54:09 +00:00
Ting-Yu Lin
192d010f2b Bug 1700580 Part 2 - Add a helper class to cache flex item's metrics in its most recent reflow. r=dholbert
This patch introduces a class that caches metrics in flex item's final
reflow. With it, we have a better symmetry for caches, one for measuring
reflow and the other for final reflow. Also, we don't have to explain
that mLastReflowTreatedBSizeAsIndefinite is only meaningful if
mFinalReflowSize is set.

Differential Revision: https://phabricator.services.mozilla.com/D124967
2021-09-17 05:54:08 +00:00
Ting-Yu Lin
16a0744567 Bug 1700580 Part 1 - Unify CachedFlexItemData's APIs that update the existing cache. r=dholbert
Add `CachedFlexItemData::Update()` with the same arguments as the
constructor to update the existing cache for both the measuring & final
reflow.

`mFinalReflowSize` is going to be renamed in a later patch, so I also
change `UpdateFinalReflowSize()` to `Update()` for consistency with the
new API.

Differential Revision: https://phabricator.services.mozilla.com/D124966
2021-09-17 05:54:08 +00:00
Ting-Yu Lin
fe3e424e83 Bug 1730506 - Tweak the assertion again to recognize integer overflow due to huge main gap size. r=dholbert
Similar to bug 1728319, a huge main gap size can also make SumOfGaps()
negative due to integer overflow. This patch is to recognize that
scenario.

We still need to annotate the crashtest because it still triggers the
following assertion in nsIFrame.

```
ASSERTION: inline-size less than zero: 'result >= 0'
```

Differential Revision: https://phabricator.services.mozilla.com/D125778
2021-09-16 23:06:37 +00:00
Ting-Yu Lin
30a1f1e161 Bug 1728319 - Tweak an assertion to recognize integer overflow due to huge margin/border/padding. r=dholbert
We could fix the testcase in this patch by promoting
`FlexLine::mTotalItemMBP` to `AuCoord64`, but then
`layout/generic/crashtests/1488762-1.html` will start crashing. It is
because `FlexItem::OuterMainSize()` can return negative size due to
integer overflow, and the negative sizes will accumulate in
`mTotalOuterHypotheticalMainSize`.

Instead of promoting more variables to `AuCoord64` to workaround huge
margin/border/padding that we cannot handle gracefully, this patch
tweaks the assertion to check only if `mTotalOuterHypotheticalMainSize`
and `mTotalItemMBP` have valid values.

Differential Revision: https://phabricator.services.mozilla.com/D124409
2021-09-03 21:23:52 +00:00
Ting-Yu Lin
85766432de Bug 1725973 Part 1 - Add a FLEX_LOG in MoveFlexItemToFinalPosition(). r=dholbert
Make it easier to spot a flex item is being moved to the final position
rather than going through the final reflow.

Differential Revision: https://phabricator.services.mozilla.com/D123702
2021-08-26 22:43:09 +00:00
Ting-Yu Lin
eb00182e36 Bug 1469649 Part 3 - Upgrade the assertion to MOZ_ASSERT, and update its comments. r=dholbert
The assertion is testing the sign of `availableFreeSpace` and `isUsingFlexGrow`.
After we use 64-bit arithmetic, it's likely that the stronger assertion holds.

Differential Revision: https://phabricator.services.mozilla.com/D123519
2021-08-25 06:43:34 +00:00
Ting-Yu Lin
1162baafb1 Bug 1469649 Part 2 - Use 64-bit coord type when resolving the main size for flex items. r=dholbert
The idea of this patch is to use 64-bit coord type when resolving the
main size for flex items to avoid integer overflow when individual flex
items have huge hypothetical main sizes, which can happen with
percent-width table-layout:fixed descendants. We have to avoid integer
overflow to shrink flex items properly in that scenario.

Delete the "Note:" in `AddLastItemToMainSizeTotals()` since we remove
`AddChecked()` in favor of regular 64-bit addition for
`mTotalOuterHypotheticalMainSize`.

The wpt testcase is adapted from bug 1469649 comment 12.

Differential Revision: https://phabricator.services.mozilla.com/D123268
2021-08-25 06:43:34 +00:00
Ting-Yu Lin
1902424bff Bug 1469649 Part 1 - Promote floating point precision when computing the weight of flex items. r=dholbert
The precision of `double` is needed when we are distributing large
`sizeDelta` via `availableFreeSpace * myShareOfRemainingSpace`.

Without this patch, the wpt test added in Part 2 will fail.

Differential Revision: https://phabricator.services.mozilla.com/D123267
2021-08-25 06:43:33 +00:00
Ting-Yu Lin
2fe6eb093f Bug 1611303 - Always assume a flex item needs a block-axis resize in final reflow. r=dholbert
In an incremental reflow, if a flex item has a valid bsize cache , we
skip its measuring reflow. However, we may still need to set relevant
bsize flags if the flex container is changing its definiteness in the
block-axis. See bug 1611303 comment 2 for an analysis.

This patch is playing safe by always calling SetHasBSizeChange() if we
override bsize for the item. Of course this can be solved in a more
sophisticated way by checking whether the item really has a block-axis
resize, but that means we'll need to duplicate a lot of logic in
FlexItem::NeedsFinalReflow().

Differential Revision: https://phabricator.services.mozilla.com/D122041
2021-08-10 21:43:14 +00:00
Ting-Yu Lin
cd5b6baa4e Bug 1686961 - Don't cache ascent in CachedBAxisMeasurement. r=dholbert
CachedBAxisMeasurement::mAscent caches the ascent of a flex item after
the measuring reflow, but the ascent may change after the final reflow
if the item is stretched and does some vertical alignment internally.
However, we don't cache the new ascent. Therefore, when we reflow the
item incrementally, if the CachedBAxisMeasurement::Key is valid, we just
skip the measuring reflow, and retrieve the wrong ascent from the cache.

Instead of fixing this bug by updating the cached ascent or rejecting
the ascent cache for a stretching flex item in block axis, this patch
removes the cache and sets ReflowOutput's BlockStartAscent() to the flex
item after the item's measuring reflow. (We've done the same after the
item's final reflow.) If the ascent is ReflowOutput::ASK_FOR_BASELINE,
we resolve in FlexItem::ResolvedAscent() anyway.

Differential Revision: https://phabricator.services.mozilla.com/D121404
2021-08-09 20:55:11 +00:00
Daniel Holbert
570c828b36 Bug 1672640 part 2: Fall back to GetNaturalBaselineBOffset to ask flex items what their baseline is. r=TYLin
Our earlier call to nsLayoutUtils::GetFirstLineBaseline/GetLastLineBaseline
works in most cases, but those APIs don't handle every frame type and fails for
text control frames (for example).  This new call should handle those cases
by directly asking the frame for its baseline.

Differential Revision: https://phabricator.services.mozilla.com/D121922
2021-08-06 18:46:21 +00:00
Daniel Holbert
607fd2307c Bug 1672640 part 1: Flatten logic and update comments in FlexItem::ResolvedAscent(). r=TYLin
This patch doesn't affect behavior; it just refactors some logic to have an
early-return and reduce indentation, to make the next patch in this series
easier/simpler.

While we're at it, this patch also updates & extends some neighboring
code-comments to be more specific & more correct about how this code behaves
and its limitations.

Differential Revision: https://phabricator.services.mozilla.com/D121921
2021-08-06 18:46:21 +00:00
Ting-Yu Lin
fed4cc4fdd Bug 1702401 - Reject existing CachedBAxisMeasurement if the item's subtree is dirty. r=dholbert
When a flex item's subtree is dirty, we should reject the cached
measurement and perform a measuring reflow for the item to get the
correct ascent. Without this patch, we are going to call
FlexItem::ResolvedAscent() in the flex algorithm based on a dirty flex
item subtree, and get a wrong ascent. (Although we'll still perform the
final reflow for the item, it's too late to get the correct ascent to
compute flex container's ascent.)

With the above modification, it exposes an existing issue that
layout/generic/crashtests/1666592.html can now trigger
`MOZ_ASSERT(!mFinalReflowSize)` in UpdateFinalReflowSize() in
fragmentation scenario. The problem is: when we clone a FlexItem for a
child frame in a flex container's continuation via FlexItem::CloneFor(),
we didn't reset the mHadMeasuringReflow flag, so we wrongly assume it
had a measuring reflow and may update its final reflow size based on the
cached metrics. However, we never run measuring reflow for flex items in
flex container's continuation, so we should reset the flag to prevent it
from falling into wrong path in FlexItem::NeedsFinalReflow().

Differential Revision: https://phabricator.services.mozilla.com/D121405
2021-08-05 05:39:32 +00:00
Sandor Molnar
f10c7e437d Backed out 2 changesets (bug 1686961, bug 1702401) for causing reftest failures in flexbox-align-self-baseline-horiz. CLOSED TREE
Backed out changeset ebbc084701a4 (bug 1702401)
Backed out changeset 20e053eb704a (bug 1686961)
2021-08-04 23:50:16 +03:00