Closed Bug 1522898 Opened 5 years ago Closed 5 years ago

Chrome stretches flexbox to child img's height, Firefox scales the image down w/o aspect ratio

Categories

(Core :: Layout: Flexbox, defect, P3)

defect

Tracking

()

VERIFIED FIXED
mozilla67
Tracking Status
firefox-esr60 --- wontfix
firefox64 --- wontfix
firefox65 --- wontfix
firefox66 --- verified
firefox67 --- verified

People

(Reporter: twisniewski, Assigned: dholbert)

References

Details

(Keywords: regression, testcase, Whiteboard: [webcompat])

Attachments

(2 files)

Attached file test.html

In the attached test-case, Firefox is sizing the img tag down to its flexbox parent's intrinsic height, while Chrome is stretching the flexbox to match the img's height of 32px.

This is causing a similar cosmetic issue on Dropbox's web UI, as per https://webcompat.com/issues/24856

Flags: webcompat?

Thanks for the report & the reduced testcase! I'll take a look. This definitely looks weird (seems like we're subtracting the padding from the intrinsic width, when computing the final height via the aspect ratio,, or something...)

Flags: needinfo?(dholbert)
Priority: -- → P3

mozregression gave me...
https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=8c3fd523d75bd30f691ca2d6cfdad18d576392a1&tochange=2b7c421063ad7e30b6491d62ed8480ca333b628a
...which suggests this is a regression from bug 1030952, BTW (which makes sense).

(That was back in the Firefox 48 timeframe, so all supported Firefox versions are affected.)

Blocks: 1030952
Flags: needinfo?(dholbert)
Keywords: regression, testcase

This is an issue with the "imposed main size" codepaths, e.g. here:
https://searchfox.org/mozilla-central/rev/465dbfe030dfec7756b9b523029e90d48dd5ecce/layout/generic/nsFrame.cpp#5658

We use that codepath to tell flex items what their resolved main size is, so that e.g. an item whose width has been flexed can use the post-flexing value to compute its correct desired height.

The problem here is that we're using it to store the "imposed" content-box size, but then the code further down treats it as if it were the actual "width" value (and subtracts out borderpadding to account for 'box-sizing:border-box').

So, we need to be careful to account for that, somehow (either setting a larger value as the "imposed" main size, or opting out of the border-box calculations in this using-an-imposed-main-size scenario).

For elements that have box-sizing:border-box specified, the aspect ratio
calculation code subtracts out border & padding from any specified property
values.

So, when we create a fake "override" specified property value for a flex item
whose main size has been resolved, we need to add in the border and padding to
account for the fact that they're going to be subtracted out later.

Patch posted, which fixes the issue locally. (I still need to add an automated test, but I verified that it makes us match other browsers on the attached testcase and on another local variant using <canvas>.)

Try run:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=bf9669675c17bbb22cf189a33d9b8045cbae4187

Assignee: nobody → dholbert
Status: NEW → ASSIGNED

[gentle ping, in case the phabricator review-request mail got lost or this slipped past your radar. Patch is hopefully pretty straightforward; let me know if it's not clear, and/or if you don't have cycles and would prefer that I find another reviewer.]

Flags: needinfo?(mats)

Sorry for the late review. Yeah, I tend to miss some phabricator requests since they don't show up in the bugzilla dashboard.

Flags: needinfo?(mats)
Pushed by dholbert@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/1c3a7347d224
Account for box-sizing (add border & padding) when setting a main-size property value override on a flex item (which it uses for aspect ratio calculations). r=mats
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67

Is this something which requires backport consideration or can it ride the trains?

Flags: needinfo?(dholbert)

Sure. It's not a recent regression (we've been shipping with it for a while before noticing it), but it's a pretty small/safe change and a nice correctness/webcompat win.

/me fills out the uplift request forms.

Flags: needinfo?(dholbert)

Comment on attachment 9039279 [details]
Bug 1522898: Account for box-sizing (add border & padding) when setting a main-size property value override on a flex item (which it uses for aspect ratio calculations).

Beta/Release Uplift Approval Request

Feature/Bug causing the regression

Bug 1030952

User impact if declined

Potentially broken layout in some cases (e.g. images squished in a way that doesn't preserve their aspect ratio) -- see screenshot on https://webcompat.com/issues/24856

Is this code covered by automated tests?

Yes

Has the fix been verified in Nightly?

Yes

Needs manual test from QE?

No

If yes, steps to reproduce

List of other uplifts needed

None

Risk to taking this patch

Low

Why is the change risky/not risky? (and alternatives if risky)

It's a very targeted fix that's a pretty clear step in the direction of correctness & compatibility.

String changes made/needed

None

Attachment #9039279 - Flags: approval-mozilla-beta?

To be clear, it'd also be fine if this were to just ride the trains.

The motivation for the uplift request is just that it'd be an "easy" small-risk-small-reward webcompat win.

Comment on attachment 9039279 [details]
Bug 1522898: Account for box-sizing (add border & padding) when setting a main-size property value override on a flex item (which it uses for aspect ratio calculations).

Webcompat fix, adds tests. What's not to love!
OK for beta 8.

Attachment #9039279 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Flags: qe-verify+
QA Contact: comorasu.cristian
Whiteboard: [webcompat] → [webcompat][qa-triaged]

I reproduced this issue using Fx 66.0a1 (2019-01-25), on Windows 10 x64.
I can confirm this issue is fixed, I verified using Fx 67.0a1 (2019-02-15) and Fx 66.0b8, on Windows 10 x64, macOS 10.13 and Ubuntu 16.06 LTS.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
QA Whiteboard: [qa-triaged]
Whiteboard: [webcompat][qa-triaged] → [webcompat]
Regressions: 1540227
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: