Commit graph

822 commits

Author SHA1 Message Date
Emilio Cobos Álvarez
873867b161 Bug 1793727 - Minor optimization: avoid looping through all items to see if we have any collapsed strut. r=jwatt
Keep track of whether we have any collapsed items, since we're already
looking at it while generating them.

No behavior change intended.

Differential Revision: https://phabricator.services.mozilla.com/D158627
2022-10-06 14:20:38 +00:00
Emilio Cobos Álvarez
d5836162f2 Bug 1793700 - Improve widget-imposed min size handling. r=TYLin,layout-reviewers,dshin
Make it work as a min-size everywhere rather than only handling it in
nsIFrame::ComputeSize.

This is more similar to what XUL code does. In particular, it makes
makes it work for elements that don't have a definite size in
ComputeSize (like flex containers).

For web-exposed widgets this only matters for <input type=color> and
<input type=range>, which are the only exposed widgets that return a
minimum size that return a minimum size. This patch makes the minimum
size honored for `<input type="color" style="height: auto">`. Add a test
for that (though we might want to change it to match other browsers).

Without this fix, min/max/close buttons on Linux are zero-height with
flex emulation, because we fail to account for their minimum
widget-imposed size.

This allows us to remove the special case in nsFlexContainerFrame too,
since that should be handled by ReflowInput correctly now.

Differential Revision: https://phabricator.services.mozilla.com/D158612
2022-10-05 19:34:03 +00:00
Emilio Cobos Álvarez
2414af9244 Bug 1793689 - Make GetMinimumWidgetSize work properly on non-XUL flexbox. r=TYLin,layout-reviewers
The XUL behavior in nsBox.cpp is fairly different to what the non-XUL
layout code paths do. In particular, canOverride=false means that the
min-{width,height} properties cannot go under the min widget size of the
widget, but that doesn't mean that intrinsic sizes don't affect the
final size of the widget.

This is very visible if you turn on flex emulation on Windows or macOS,
where the toolbar has an appearance that returns
width=0,height=N,canOverride=false.

With flex emulation we'd collapse the item to be zero-width, which is
not good at all.

The good thing is that this is no longer exposed to the web
(non-native-theme always returns canOverride=true), and our front-end
code doesn't seem to rely on this, so we can just remove support for
canOverride=false.

Differential Revision: https://phabricator.services.mozilla.com/D158608
2022-10-05 19:09:29 +00:00
Emilio Cobos Álvarez
dd98178218 Bug 1793687 - Simplify collapse code for legacy moz-box. r=dshin
Recently we added different bits for -webkit-/-moz- box emulation, so we
no longer need to go look at the scrolled frame etc.

Differential Revision: https://phabricator.services.mozilla.com/D158603
2022-10-05 14:23:15 +00:00
Emilio Cobos Álvarez
a3231a2981 Bug 1793375 - Rename nsILineIterator::GetDirection to IsLineIteratorFlowRTL. r=dholbert
bool GetDirection() is rather meaningless.

Differential Revision: https://phabricator.services.mozilla.com/D158474
2022-10-03 11:00:39 +00:00
Emilio Cobos Álvarez
12a34801fb Bug 1792333 - Implement nsILineIterator in nsFlex/GridContainerFrame. r=dholbert
Instead of digging into the first line-iterable frame. Digging into the
first line-iterable frame is bogus, because if there are multiple flex
items we might prevent moving through them properly (see test-case).

The flex implementation is nice and fairly complete, IMO. The grid one
is not, but the resulting behavior is nicer than the behavior before
this patch, seems reasonable, and matches Chrome in my testing.

In Searchfox, the behavior is even funnier because user-select: none is
involved, but that predates the regression.

Differential Revision: https://phabricator.services.mozilla.com/D158086
2022-10-02 07:49:46 +00:00
Ting-Yu Lin
dbd25c17f5 Bug 1791458 - Remove auto main-size workaround for replaced elements when computing flex base size. r=emilio
After bug 1340715, we use the same path [1] when computing `auto` and
`max-content` inline-sizes for replaced elements in
`nsContainerFrame::ComputeSizeWithIntrinsicDimensions()`. For block-sizes,
`max-content` and `auto` already have the same behavior.

This patch shouldn't change the behavior.

[1] https://searchfox.org/mozilla-central/rev/6d7704caae2a61b0101bdb67481a80af20376663/layout/generic/nsContainerFrame.cpp#2354-2355

Differential Revision: https://phabricator.services.mozilla.com/D157678
2022-09-19 23:49:06 +00:00
Ting-Yu Lin
f752657659 Bug 1791430 - Remove a "Not Implemented Yet" warning of bug 1480850 in flex container. r=dholbert
Differential Revision: https://phabricator.services.mozilla.com/D157667
2022-09-19 20:55:14 +00:00
Daniel Holbert
8be8e10200 Bug 1786910: Ignore 'align-content' when determining the aligned static position of abspos flex children. r=TYLin
Before this patch, we honored `align-content` (in combination with
`align-self`) for cross-axis alignment for abspos flex children **in cases
where the flex container was multi-line**. This was a bit weird, but was
required by the spec, and made some sense in the spirit of aligning the abspos
box as if it were the sole flex item in a flex container.

Now the CSSWG has resolved in [1] to simplify things by just ignoring
`align-content` for abspos flex children. So, this patch updates us in
accordance with this change. Such items now only have to look at `align-self`
for cross-axis alignment to determine their static position in their flex
container.

Before this commit, we had a bunch of WPT tests to check the impact of every
align-content value, with all of the various flavors of directionality.  Now
that align-content has *no effect* in any of these cases, all of these tests
become pretty trivial and redundant.  Rather than carrying them all forward
with trivial "no impact" expectations for each scenario, I've just updated the
first/simplest such test to expect no-behavioral-impact and I've removed the
rest.

[1] https://github.com/w3c/csswg-drafts/issues/7596#issuecomment-1225952646

Differential Revision: https://phabricator.services.mozilla.com/D157571
2022-09-19 20:36:05 +00:00
Martin Robinson
f943c5f18d Bug 1789255: Anonymous children of elements with content-visibility should not be skipped for layout r=emilio
Some anonymous children are important for properly sizing their parents
even when those parents hide content with `content-visibility`. This is
shown by regressions in the proper layout of some form elements with
`content-visibility`.

This change introduces a more conservative approach for avoiding layout
of hidden content. Instead of leaving all children dirty during reflow,
reflow anonymous frames (and nsComboboxDisplayFrame, a specialized kind
of anonymous frame). This change means that frames may only lay out some
of their children, so it must introduce some more changes to assumptions
during line layout.

In addition, this change renames `content-visibility` related methods in
nsIFrame in order to make it more obvious what they do.

Differential Revision: https://phabricator.services.mozilla.com/D157306
2022-09-15 20:32:27 +00:00
Norisz Fay
fd54c095de Backed out changeset c3780baf6f24 (bug 1789255) for causing build bustages CLOSED TREE 2022-09-15 21:14:04 +03:00
Martin Robinson
631f1807ed Bug 1789255: Anonymous children of elements with content-visibility should not be skipped for layout r=emilio
Some anonymous children are important for properly sizing their parents
even when those parents hide content with `content-visibility`. This is
shown by regressions in the proper layout of some form elements with
`content-visibility`.

This change introduces a more conservative approach for avoiding layout
of hidden content. Instead of leaving all children dirty during reflow,
reflow anonymous frames (and nsComboboxDisplayFrame, a specialized kind
of anonymous frame). This change means that frames may only lay out some
of their children, so it must introduce some more changes to assumptions
during line layout.

In addition, this change renames `content-visibility` related methods in
nsIFrame in order to make it more obvious what they do.

Differential Revision: https://phabricator.services.mozilla.com/D157306
2022-09-15 17:56:42 +00:00
Sandor Molnar
4009825526 Backed out changeset 3a5759eabb42 (bug 1789255) for causing wpt failures in netwerk/protocol/http/Http2Session.cpp CLOSED TREE 2022-09-14 02:01:36 +03:00
Martin Robinson
f48a334b7c Bug 1789255: Anonymous children of elements with content-visibility should not be skipped for layout r=emilio
Some anonymous children are important for properly sizing their parents
even when those parents hide content with `content-visibility`. This is
shown by regressions in the proper layout of some form elements with
`content-visibility`.

This change introduces a more conservative approach for avoiding layout
of hidden content. Instead of leaving all children dirty during reflow,
reflow anonymous frames (and nsComboboxDisplayFrame, a specialized kind
of anonymous frame). This change means that frames may only lay out some
of their children, so it must introduce some more changes to assumptions
during line layout.

In addition, this change renames `content-visibility` related methods in
nsIFrame in order to make it more obvious what they do.

Differential Revision: https://phabricator.services.mozilla.com/D156473
2022-09-13 20:01:35 +00:00
Ting-Yu Lin
4b20ea1119 Bug 1790312 Part 2 - Remove flex item's normal position snapshot in ReflowChildren(). r=dholbert
ReflowChildren() only cares about the flex item's normal position, so we don't
need to output the relative position from `MoveFlexItemToFinalPosition()`.

By making `aFramePos` const for `MoveFlexItemToFinalPosition`, we can delete
`itemNormalBPos` because `framePos` cannot be changed after calling
`MoveFlexItemToFinalPosition`.

This patch shouldn't change the behavior.

Differential Revision: https://phabricator.services.mozilla.com/D157079
2022-09-12 16:34:10 +00:00
Ting-Yu Lin
19e8ae9be4 Bug 1790312 Part 1 - Make aFramePos parameter const for ReflowFlexItem(). r=dholbert
`aFramePos` is never modified in ReflowFlexItem().

Differential Revision: https://phabricator.services.mozilla.com/D157078
2022-09-12 16:34:09 +00:00
Emilio Cobos Álvarez
c5d167dfed Bug 1789123 - Split legacy box bits in MOZ/WEBKIT. r=dholbert
Differential Revision: https://phabricator.services.mozilla.com/D156737
2022-09-08 11:54:45 +00:00
Emilio Cobos Álvarez
b5c2fd645c Bug 1789123 - Make anonymous box wrapping inside XUL boxes be similar to modern flex boxes. r=dholbert
I haven't spotted any UI regression from this, and this should generally
make the XUL -> modern flex transition easier, and simplify some
of the relevant code.

This does fix a few layout issues with emulated flexbox.

For the most part, this shouldn't change behavior without that. This
changes behavior if you have mixed inline/non-inline content in the same
XUL box (before they'd get a single item, now you'd get the flexbox /
grid behavior of one item per inline run), and multiple inline-elements
(which would become their own flex items). But I pushed a patch with
some asserts and they didn't fire on our browser mochitests, so I think
we're good.

The UA rule refactoring (removing the inherit from xul anon blocks)
shouldn't matter in practice, since we only have one item (so
box-ordinal is irrelevant) and they have overflow: visible (so
text-overflow and overflow-clip-box shouldn't have an effect).

Differential Revision: https://phabricator.services.mozilla.com/D156375
2022-09-08 11:51:15 +00:00
Emilio Cobos Álvarez
3c206e563a Bug 1786147 - Make -webkit-line-clamp create a block container in the appropriate situations. r=dholbert
This is a hack, sorta, similar to Chromium's:

  https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/layout/layout_object.cc;l=356;drc=312b74e385e6aba98ab31fd911238c0dc16b396c

except at computed-value rather than used-value time, because it's both
simpler to reason about and prevents lying in the computed style.

This fixes the relevant test-case, and matches closer what Chromium does,
by not creating anonymous flex items for all elements inside the
line-clamp context.

The behavior change is covered by the test changes. I had to also fix a
couple pre-existing bugs that were caught by tests, now that the
line-clamped block is the -webkit-box-styled element rather than an anonymous
flex item (and thus now had padding).

Depends on D155180

Differential Revision: https://phabricator.services.mozilla.com/D155181
2022-09-07 23:57:18 +00:00
Emilio Cobos Álvarez
83c7733c7c Bug 1786147 - Move line-clamp out of mako and do some adjacent clean-up. r=boris
No behavior change, but simplifies the following patch.

Differential Revision: https://phabricator.services.mozilla.com/D155180
2022-08-31 12:39:19 +00:00
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