Closed Bug 1658140 Opened 4 years ago Closed 4 years ago

Percentage canvas background-size resolved incorrectly for fixed-pos root element

Categories

(Core :: Web Painting, defect)

79 Branch
defect

Tracking

()

RESOLVED FIXED
81 Branch
Tracking Status
firefox81 --- fixed

People

(Reporter: gzbkfr, Assigned: emilio)

Details

Attachments

(3 files, 1 obsolete file)

Attached file Sample HTML file showing the issue (obsolete) —

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0

Steps to reproduce:

Open the following sample (same issue when setting the "position" property on the <HTML> tag):

<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body style="background-image: url('hand.jpg'); background-size: 100%;position: fixed;">
</body>
</html>

Actual results:

When opening this page using Firefox, no background image is shown (blank page).

Removing either the "position" or the "background-size" CSS property make the background image appear.

Issue reproduced on several Firefox versions (Linux, Windows, Android). Other tested browsers do not show this behavior: when using other browsers the image is always displayed.

Expected results:

Despite the "position" property being set either on the <BODY> or the <HTML> tags, the "background-image" property should not be ignored, it should remain unaffected by this property and the image should appear the same way as if there was no "position" property set.

Component: Untriaged → CSS Parsing and Computation
Product: Firefox → Core

Sorry, unlike what is stated in the initial report, the position property MUST be set on the <HTML> element to trigger the issue :

Content of issue.html:

<!DOCTYPE html>
<html style="position: fixed;">
	<head><title>Issue</title></head>
	<body style="background-image: url('hand.jpg'); background-size: 100%; background-color: blue;">
		<p style="font-size: 400%">This is a test.</p>
	</body>
</html>

Settings anything background-related on the <HTML> tag seems to workaround the issue :

Content of workaround.html:

<!DOCTYPE html>
<html style="position: fixed; background-color: white;">
	<head><title>Workaround</title></head>
	<body style="background-image: url('hand.jpg'); background-size: 100%; background-color: blue;">
		<p style="font-size: 400%">This is a test.</p>
	</body>
</html>

So, my understanding of the issue is as follow:

  • When no background is configured on the <HTML> tag, Firefox should use the background settings applied on the <BODY> tag.

  • However, if a position style property is set on the <HTML> tag, and both a background-image and background-width are set on the <BODY> tag, then the background-image will be ignored. Note that the background-color will still be taken into account: when opening issue.html the background appears blue instead of showing the background image as with other browsers. Normally, as long as the the background image file exists, the blue background should never be visible.

  • On the other side, if a background is configured on the <HTML> tag, then Firefox does not need to internally "move" the background defined on the <BODY> to the upper <HTML> tag, so the background-image does not get lost in the process, thus producing the expected result, as shown in workaround.html.

Attachment #9168994 - Attachment is obsolete: true
Attachment #9169031 - Attachment mime type: text/plain → text/html

This is not a CSS bug per se. The percentage background-size is getting resolved against the wrong size looks like.

Status: UNCONFIRMED → NEW
Component: CSS Parsing and Computation → Web Painting
Ever confirmed: true
Summary: CSS properties "position" and "background-size" make the "background-image' to be ignored → Percentage canvas background-size resolved incorrectly for fixed-pos root element

I think this is the line that goes wrong, but would need to double-check: https://searchfox.org/mozilla-central/rev/491612fa0be0f809069ea62c6316bf452cacc816/layout/painting/nsCSSRendering.cpp#2748-2754

The issue is that since the root element is out-of-flow, the frame we find is the placeholder, which is zero-sized.

Assignee: nobody → emilio
Status: NEW → ASSIGNED
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/58bc7d3949c0 Fix percentage background-size on the root when out-of-flow. r=mattwoodrow
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/24932 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 81 Branch
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: