Skip to content

Conversation

@syvb
Copy link
Contributor

@syvb syvb commented Feb 2, 2024

The HTMLImageElement.prototype.width/height attributes should provide the rendered width/height of images that are being rendered, and the natural width/height of images that are not being rendered. In Servo, these attributes call bounding_content_box on the node, treating None as an indication that the element is not being rendered (and returning the natural width/height). But Layout 2020 returns a 0x0 bounding box for elements that are not being rendered, instead of None.

As a result:

let image = new Image();
image.src = "...";
image.onload = () => {
    const [width, height] = [image.width, image.height];
    // use width/height
};

always gets 0/0 for the width/height (instead of the natural width/height) in Layout 2020.

This PR makes it so requests to Layout 2020 for the bounding box of a node that isn't being rendered return None instead of a 0x0 bounding box, which matches the Layout 2013 behavior.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • There are tests for these changes (which already exist in WPT)

@mrobinson mrobinson added this pull request to the merge queue Feb 2, 2024
Merged via the queue into servo:main with commit 436e949 Feb 3, 2024
@syvb syvb deleted the fix-nil-bbox branch February 3, 2024 03:17
Taym95 pushed a commit to Taym95/servo that referenced this pull request Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants