Skip to content

script: Determine dimensions for <img> and <input> - #49085

Merged
jdm merged 1 commit into
servo:mainfrom
TimvdLippe:img-input-determine-dimensions
Oct 20, 2026
Merged

jdm merged 1 commit into
servo:mainfrom
TimvdLippe:img-input-determine-dimensions

Conversation

@TimvdLippe

Copy link
Copy Markdown
Contributor

The img and input elements have specific handling for how they determine their dimensions. They should inspect the relevant image and also take into account the existing width/height attributes (if any) if they aren't rendering.

Implement the relevant algorithms for these and let input defer to img for it, since it uses that element in its shadow tree. Note that we also weren't firing the load/error event for input since these weren't escaping the shadow tree. By firing these events on the host of the img element we start running the appropriate tests.

Part of #48603

Testing: new WPT tests passing

@TimvdLippe
TimvdLippe requested a review from gterzian as a code owner October 20, 2026 09:32
@TimvdLippe TimvdLippe added the T-linux-wpt Do a try run of the WPT label Oct 20, 2026
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 20, 2026
@github-actions github-actions Bot removed the T-linux-wpt Do a try run of the WPT label Oct 20, 2026
@github-actions

Copy link
Copy Markdown

🔨 Triggering try run (#39401434794) for Linux (WPT)

@@ -1,88 +1,27 @@
[image-width-height.html]
expected: TIMEOUT
[no width/height attributes]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we fail some of the most basic tests. That's because node.context_box() for an <img> that loads an image of 100 by 100 pixels reports 100 by 103 pixels. E.g. the height is 3 pixels too large. I have no clue why that is happening. Initially I thought it would have been our CSS, but we don't set any padding explicitly for an <input type="image">:

input:not([type="image"]) {
padding: 1px 2px;
}

Then I thought maybe the image does itself, but that's also not the case. Basically, I have no clue why this is happening 😭 Still, these tests run now rather than timeout, so that's progress.

@github-actions

Copy link
Copy Markdown

Test results for linux-wpt from try job (#39401434794):

Flaky unexpected result (17)
  • CRASH [expected OK] /IndexedDB/idbindex-request-source.any.worker.html
  • OK /IndexedDB/idbtransaction-oncomplete.any.html (#42845)
    • FAIL [expected PASS] subtest: IDBTransaction - complete event

      assert_array_equals: lengths differ, expected array ["upgradeneeded", "complete", "success", "opencursor"] length 4, got ["upgradeneeded", "complete", "success"] length 3
      

  • CRASH [expected OK] /_webgl/conformance2/wasm/readpixels-2gb-in-4gb-wasm-memory.html
  • OK /beacon/beacon-basic.https.window.html (#41723)
    • FAIL [expected PASS] subtest: Payload size restriction should be accumulated: type = arraybuffer

      assert_false: expected false got true
      

    • FAIL [expected PASS] subtest: Payload size restriction should be accumulated: type = blob

      assert_false: expected false got true
      

  • OK /fetch/content-length/api-and-duplicate-headers.any.html (#35873)
    • FAIL [expected PASS] subtest: fetch() and duplicate Content-Length/Content-Type headers

      promise_test: Unhandled rejection with value: object "TypeError: Network error: HTTP failure: client error (SendRequest)"
      

  • OK [expected ERROR] /focus/focus-event-after-switching-iframes.sub.html (#40368)
  • OK /html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-src-204.html (#48879)
    • FAIL [expected PASS] subtest: Navigating to a different document with form submission

      The operation is insecure.
      

  • OK /html/browsers/browsing-the-web/navigating-across-documents/navigation-unload-same-origin.window.html (#29049)
    • PASS [expected FAIL] subtest: Same-origin navigation started from unload handler must be ignored
  • OK [expected TIMEOUT] /html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/form-submit-button-click.html (#44099)
    • FAIL [expected TIMEOUT] subtest: Replace before load, triggered by submitButton.click()

      assert_equals: expected "http://web-platform.test:8000/common/blank.html?thereplacement=" but got "http://web-platform.test:8000/html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/resources/code-injector.html?pipe=sub(none)&amp;code=%0A%20%20%20%20const%20form%20%3D%20document.createElement(%22form%22)%3B%0A%20%20%20%20form.action%20%3D%20%22%2Fcommon%2Fblank.html%22%3B%0A%0A%20%20%20%20const%20input%20%3D%20document.createElement(%22input%22)%3B%0A%20%20%20%20input.type%20%3D%20%22hidden%22%3B%0A%20%20%20%20input.name%20%3D%20%22thereplacement%22%3B%0A%20%20%20%20form.append(input)%3B%0A%0A%20%20%20%20const%20button%20%3D%20document.createElement(%22button%22)%3B%0A%20%20%20%20button.type%20%3D%20%22submit%22%3B%0A%20%20%20%20form.append(button)%3B%0A%0A%20%20%20%20document.currentScript.before(form)%3B%0A%20%20%20%20button.click()%3B%0A%20%20"
      

  • CRASH [expected OK] /html/browsers/history/the-location-interface/security_location_0.htm (#48200)
  • CRASH [expected OK] /html/browsers/sandboxing/sandbox-initial-empty-document-toward-same-origin.html (#35948)
  • TIMEOUT [expected OK] /html/semantics/embedded-content/media-elements/autoplay-allowed-by-permissions-policy.https.sub.html (#46803)
    • TIMEOUT [expected PASS] subtest: Permissions-Policy header: autoplay * allows same-origin iframes.

      Test timed out
      

  • TIMEOUT [expected OK] /html/semantics/embedded-content/media-elements/src_object_blob.html (#40340)
    • TIMEOUT [expected PASS] subtest: HTMLMediaElement.srcObject blob

      Test timed out
      

  • CRASH [expected ERROR] /html/semantics/forms/the-select-element/customizable-select/select-appearance-button-after-span.html
  • OK /infrastructure/testdriver/click_window.html (#47303)
    • FAIL [expected PASS] subtest: TestDriver click method in window

      Unhandled rejection: assert_unreached: click failed Reached unreachable code
      

  • TIMEOUT [expected OK] /pointerevents/compat/pointerevent_touch-action_two-finger_interaction.html
    • NOTRUN [expected PASS] subtest: touch two-finger pan on 'touch-action: pan-x pan-y'
    • NOTRUN [expected FAIL] subtest: touch two-finger pan on 'touch-action: pinch-zoom'
  • TIMEOUT [expected PASS] /streams/readable-streams/crashtests/from-cross-realm.https.html
Stable unexpected results that are known to be intermittent (10)
  • OK /css/CSS2/linebox/inline-negative-margin-001.html (#43763)
    • FAIL [expected PASS] subtest: [data-expected-height] 3

      assert_equals: 
      &lt;div class="w4" data-expected-height="10"&gt;123 &lt;span style="margin-left: -4ch"&gt;1234 &lt;/span&gt;&lt;/div&gt;
      height expected 10 but got 20
      

    • FAIL [expected PASS] subtest: [data-expected-height] 4

      assert_equals: 
      &lt;div class="w4" data-expected-height="10"&gt;123 &lt;span style="margin-left: -4ch"&gt;123 &lt;/span&gt;&lt;/div&gt;
      height expected 10 but got 20
      

    • FAIL [expected PASS] subtest: [data-expected-height] 5

      assert_equals: 
      &lt;div class="w4" data-expected-height="10"&gt;&lt;img class="w4"&gt;&lt;span style="margin-left: -4ch"&gt;123&lt;/span&gt;&lt;/div&gt;
      height expected 10 but got 20
      

    • FAIL [expected PASS] subtest: [data-expected-height] 6

      assert_equals: 
      &lt;div class="w4" data-expected-height="10"&gt;&lt;img class="w5"&gt;&lt;span style="margin-left: -5ch"&gt;123&lt;/span&gt;&lt;/div&gt;
      height expected 10 but got 20
      

  • OK /html/browsers/browsing-the-web/navigating-across-documents/navigation-unload-same-origin-fragment.html (#20768)
    • FAIL [expected PASS] subtest: Tests that a fragment navigation in the unload handler will not block the initial navigation

      assert_equals: expected "" but got "#fragment"
      

  • OK [expected TIMEOUT] /html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/form-requestsubmit.html (#44098)
    • FAIL [expected TIMEOUT] subtest: Replace before load, triggered by formElement.requestSubmit()

      assert_equals: expected "http://web-platform.test:8000/common/blank.html?thereplacement=" but got "http://web-platform.test:8000/html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/resources/code-injector.html?pipe=sub(none)&amp;code=%0A%20%20%20%20const%20form%20%3D%20document.createElement(%22form%22)%3B%0A%20%20%20%20form.action%20%3D%20%22%2Fcommon%2Fblank.html%22%3B%0A%0A%20%20%20%20const%20input%20%3D%20document.createElement(%22input%22)%3B%0A%20%20%20%20input.type%20%3D%20%22hidden%22%3B%0A%20%20%20%20input.name%20%3D%20%22thereplacement%22%3B%0A%20%20%20%20form.append(input)%3B%0A%0A%20%20%20%20document.currentScript.before(form)%3B%0A%20%20%20%20form.requestSubmit()%3B%0A%20%20"
      

  • OK [expected TIMEOUT] /html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/form-submit.html (#44028)
  • TIMEOUT /html/browsers/history/the-history-interface/001.html (#12580)
    • PASS [expected FAIL] subtest: traversing history must also traverse hash changes
  • CRASH [expected OK] /html/browsers/history/the-location-interface/assign-replace-from-iframe.html (#47679)
  • TIMEOUT /html/browsers/sandboxing/sandbox-window-open-srcdoc.html (#48863)
    • TIMEOUT [expected PASS] subtest: window.open('about:srcdoc') from sandboxed srcdoc doesn't crash.

      Test timed out
      

    • NOTRUN [expected PASS] subtest: popup is isolated from an isolated iframe
  • OK /html/semantics/embedded-content/media-elements/media_fragment_seek.html (#24114)
    • PASS [expected FAIL] subtest: Video should seek to time specified in media fragment syntax
  • CRASH [expected OK] /html/semantics/forms/form-submission-0/form-submit-iframe-then-location-navigate.html (#29634)
  • OK /user-timing/measure_associated_with_navigation_timing.html (#47273)
    • PASS [expected FAIL] subtest: loadTime plus loadEventEnd to a mark "a" should equal to navigationStart to "a".
Stable unexpected results (3)
  • OK [expected TIMEOUT] /fetch/metadata/generated/element-input-image.https.sub.html
    • PASS [expected TIMEOUT] subtest: sec-fetch-site - Same origin, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Cross-site, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Same site, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Same-Origin -&gt; Cross-Site -&gt; Same-Origin redirect, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Same-Origin -&gt; Same-Site -&gt; Same-Origin redirect, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Cross-Site -&gt; Same Origin, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Cross-Site -&gt; Same-Site, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Cross-Site -&gt; Cross-Site, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Same-Origin -&gt; Same Origin, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Same-Origin -&gt; Same-Site, no attributes
    • And 10 more unexpected results...
  • OK [expected TIMEOUT] /fetch/metadata/generated/element-input-image.sub.html
    • PASS [expected TIMEOUT] subtest: sec-fetch-site - Not sent to non-trustworthy same-origin destination, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Not sent to non-trustworthy same-site destination, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-site - Not sent to non-trustworthy cross-site destination, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-mode - Not sent to non-trustworthy same-origin destination, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-mode - Not sent to non-trustworthy same-site destination, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-mode - Not sent to non-trustworthy cross-site destination, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-dest - Not sent to non-trustworthy same-origin destination, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-dest - Not sent to non-trustworthy same-site destination, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-dest - Not sent to non-trustworthy cross-site destination, no attributes
    • PASS [expected NOTRUN] subtest: sec-fetch-user - Not sent to non-trustworthy same-origin destination, no attributes
    • And 8 more unexpected results...
  • OK [expected TIMEOUT] /resource-timing/input-sequence-of-events.html
    • PASS [expected TIMEOUT] subtest: An image input element should receive its load event after the ResourceTiming entry is available

@github-actions

Copy link
Copy Markdown

⚠️ Try run (#39401434794) failed!

The img and input elements have specific handling for how they determine
their dimensions. They should inspect the relevant image and also take
into account the existing width/height attributes (if any) if they
aren't rendering.

Implement the relevant algorithms for these and let input defer to img
for it, since it uses that element in its shadow tree. Note that we also
weren't firing the `load`/`error` event for input since these weren't
escaping the shadow tree. By firing these events on the host of the img
element we start running the appropriate tests.

Part of servo#48603

Testing: new WPT tests passing

Signed-off-by: Tim van der Lippe <[email protected]>
@TimvdLippe
TimvdLippe force-pushed the img-input-determine-dimensions branch from 84a1e0c to 72e9a4b Compare October 20, 2026 13:10

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Oct 20, 2026
@jdm
jdm enabled auto-merge October 20, 2026 13:30
@jdm
jdm added this pull request to the merge queue Oct 20, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 20, 2026
Merged via the queue into servo:main with commit afe1e0c Oct 20, 2026
35 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 20, 2026
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.

3 participants