Skip to content

Implement the aspect-ratio property for replaced elements - #32800

Merged
mrobinson merged 2 commits into
servo:mainfrom
valadaptive:aspect-ratio
Jul 24, 2024
Merged

mrobinson merged 2 commits into
servo:mainfrom
valadaptive:aspect-ratio

Conversation

@valadaptive

@valadaptive valadaptive commented Jul 17, 2024 •

Copy link
Copy Markdown
Contributor

First step towards fully implementing aspect-ratio. This is probably the easy part since replaced elements are already known to have an intrinsic aspect ratio and treated as such.

This PR touches the same code as #32777 and therefore depends on it.

This will require the aspect-ratio property to be enabled for layout 2020 in Stylo--I currently have it pointed to my fork which does so.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #___ (GitHub issue number if applicable)
  • There are tests for these changes OR
  • These changes do not require tests because ___

@jdm jdm added the T-linux-wpt Do a try run of the WPT label Jul 17, 2024
@github-actions github-actions Bot removed the T-linux-wpt Do a try run of the WPT label Jul 17, 2024
@github-actions

Copy link
Copy Markdown

🔨 Triggering try run (#9982811571) for Linux WPT

@github-actions

Copy link
Copy Markdown

Test results for linux-wpt-layout-2020 from try job (#9982811571):

Flaky unexpected result (24)
  • TIMEOUT [expected OK] /_webgl/conformance/glsl/misc/shader-uniform-packing-restrictions.html (#28103)
  • TIMEOUT [expected OK] /_webgl/conformance/uniforms/out-of-bounds-uniform-array-access.html (#26225)
    • NOTRUN [expected PASS] subtest: Overall test
  • OK /css/css-fonts/variations/at-font-face-font-matching.html (#20684)
    • FAIL [expected PASS] subtest: Matching font-weight: '400' should prefer '350 399' over '351 398'

      assert_equals: Unexpected font on test element expected 487 but got 532
      

    • FAIL [expected PASS] subtest: Matching font-weight: '430' should prefer '501 550' over '502 560'

      assert_equals: Unexpected font on test element expected 487 but got 532
      

  • FAIL [expected PASS] /css/css-sizing/dynamic-available-size-iframe.html (#31559)
  • OK /css/css-values/viewport-units-after-font-load.html (#27645)
    • FAIL [expected PASS] subtest: Viewport units are correctly updated after resize even if a font load has happened before

      assert_equals: Height shouldn't have changed expected "0px" but got "300px"
      

  • OK [expected TIMEOUT] /css/cssom-view/MediaQueryList-extends-EventTarget-interop.html (#25285)
    • PASS [expected TIMEOUT] subtest: listener added with addListener and addEventListener (capture) is called twice
    • PASS [expected NOTRUN] subtest: removeEventListener removes listener added with addListener
    • FAIL [expected NOTRUN] subtest: removeEventListener (capture) doesn't remove listener added with addListener

      assert_equals: triggerMQLEvent expected 1 but got 0
      

    • PASS [expected NOTRUN] subtest: removeListener removes listener added with addEventListener
    • FAIL [expected NOTRUN] subtest: removeListener doesn't remove listener added with addEventListener (capture)

      assert_equals: triggerMQLEvent expected 1 but got 0
      

    • FAIL [expected NOTRUN] subtest: capturing event listener fires before non-capturing listener at target

      assert_array_equals: triggerMQLEvent lengths differ, expected array ["addEventListener", "addListener"] length 2, got [] length 0
      

  • OK [expected TIMEOUT] /css/cssom-view/MediaQueryList-extends-EventTarget.html (#25269)
    • FAIL [expected TIMEOUT] subtest: listeners for "change" type are called

      assert_equals: expected 1 but got 0
      

    • PASS [expected NOTRUN] subtest: listeners with different type are not called
    • FAIL [expected NOTRUN] subtest: addEventListener "once" option is respected

      assert_equals: expected 1 but got 0
      

    • PASS [expected NOTRUN] subtest: removeEventListener removes listener
  • OK /custom-elements/form-associated/ElementInternals-setFormValue.html (#29174)
    • PASS [expected FAIL] subtest: Single value - Non-empty name exists
    • PASS [expected FAIL] subtest: Null value should submit nothing
  • OK /fetch/metadata/generated/css-font-face.https.sub.tentative.html (#32732)
    • PASS [expected FAIL] subtest: sec-fetch-user
  • OK /html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-src-aboutblank-navigate-immediately.html (#29048)
    • PASS [expected FAIL] subtest: Navigating to a different document with link click
    • PASS [expected FAIL] subtest: Navigating to a different document with form submission
  • OK /html/browsers/browsing-the-web/navigating-across-documents/navigation-unload-cross-origin.sub.window.html (#29056)
    • FAIL [expected PASS] subtest: Cross-origin navigation started from unload handler must be ignored

      promise_test: Unhandled rejection with value: object "SecurityError: The operation is insecure."
      

  • CRASH [expected OK] /html/browsers/windows/embedded-opener-remove-frame.html (#23867)
  • TIMEOUT [expected CRASH] /html/canvas/element/canvas-host/2d.canvas.host.size.large.html
  • TIMEOUT [expected OK] /html/interaction/focus/the-autofocus-attribute/autofocus-dialog.html (#29087)
    • TIMEOUT [expected FAIL] subtest: <dialog>-contained autofocus element gets focused when the dialog is shown

      Test timed out
      

  • OK /html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-nav-window-open.html (#32596)
    • FAIL [expected PASS] subtest: Navigating iframe loading='lazy' before it is loaded: location.replace

      uncaught exception: Error: assert_equals: expected "http://web-platform.test:8000/html/semantics/embedded-content/the-iframe-element/support/blank.htm?nav" but got "http://web-platform.test:8000/html/semantics/embedded-content/the-iframe-element/support/blank.htm?src"
      

  • TIMEOUT [expected OK] /html/semantics/embedded-content/the-iframe-element/sandbox-top-navigation-cross-site.tentative.sub.window.html (#31754)
    • TIMEOUT [expected FAIL] subtest: A cross-site unsandboxed iframe navigation consumes user activation and disallows top-level navigation.

      Test timed out
      

  • CRASH [expected PASS] /html/semantics/embedded-content/the-img-element/image-loading-lazy-subframe-detached-crash.html (#31572)
  • OK /html/semantics/forms/form-submission-0/multipart-formdata.window.html (#28725)
    • PASS [expected FAIL] subtest: multipart/form-data: 0x00 in name (normal form)
    • PASS [expected FAIL] subtest: multipart/form-data: 0x00 in value (formdata event)
  • TIMEOUT [expected OK] /html/semantics/forms/form-submission-0/reparent-form-during-planned-navigation-task.html (#29724)
    • TIMEOUT [expected PASS] subtest: reparent-form-during-planned-navigation-task

      Test timed out
      

  • CRASH [expected OK] /html/semantics/forms/the-fieldset-element/disabled-003.html (#31730)
  • OK /html/syntax/parsing/DOMContentLoaded-defer.html (#21550)
    • PASS [expected FAIL] subtest: The end: DOMContentLoaded and defer scripts
  • TIMEOUT /resource-timing/test_resource_timing.html (#25720)
    • FAIL [expected PASS] subtest: PerformanceEntry has correct name, initiatorType, startTime, and duration (img)

      assert_equals: expected 4902400 but got 4902656
      

  • TIMEOUT /resource-timing/test_resource_timing.https.html (#25216)
    • FAIL [expected PASS] subtest: PerformanceEntry has correct name, initiatorType, startTime, and duration (img)

      assert_equals: expected 6836224 but got 6835968
      

  • OK [expected ERROR] /workers/constructors/Worker/Worker-constructor.html (#22991)
Stable unexpected results that are known to be intermittent (12)
  • FAIL [expected PASS] /_mozilla/css/dirty_viewport.html (#13731)
  • TIMEOUT /css/cssom-view/MediaQueryList-addListener-removeListener.html (#24569)
    • TIMEOUT [expected PASS] subtest: listeners are called in order they were added

      Test timed out
      

  • TIMEOUT /fetch/metadata/generated/element-img-environment-change.sub.html (#30111)
    • PASS [expected FAIL] subtest: sec-fetch-site - Not sent to non-trustworthy same-origin destination, no attributes
  • OK /html/browsers/browsing-the-web/navigating-across-documents/empty-iframe-load-event.html (#29066)
    • FAIL [expected PASS] subtest: Check execution order from nested timeout

      assert_equals: Expected nested setTimeout to run second expected true but got false
      

    • FAIL [expected PASS] subtest: Check execution order on load handler

      assert_equals: Expected onload to run first expected false but got true
      

  • OK /html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/a-click.html (#28697)
    • PASS [expected FAIL] subtest: aElement.click() before the load event must NOT replace
  • OK /html/browsers/history/the-history-interface/traverse_the_history_3.html (#21383)
    • FAIL [expected PASS] subtest: Multiple history traversals, last would be aborted

      assert_array_equals: Pages opened during history navigation expected property 1 to be 3 but got 1 (expected array [6, 3] got [6, 1])
      

  • TIMEOUT [expected ERROR] /html/canvas/element/manual/imagebitmap/createImageBitmap-drawImage.html (#32745)
  • ERROR [expected TIMEOUT] /html/canvas/element/manual/imagebitmap/createImageBitmap-flipY.html (#32745)
  • CRASH [expected OK] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-1.html (#24066)
  • CRASH [expected TIMEOUT] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-2.html (#22154)
  • CRASH [expected OK] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-3.html (#24066)
  • TIMEOUT [expected OK] /webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.tentative.html (#29053)
    • TIMEOUT [expected PASS] subtest: StorageKey: test 3P about:blank window opened from a 3P iframe

      Test timed out
      

@github-actions

Copy link
Copy Markdown

✨ Try run (#9982811571) succeeded.

@valadaptive

Copy link
Copy Markdown
Contributor Author

This still needs a bit more work--I need to enable the aspect-ratio WPT tests and fix a bug relating to max-width and border-box

@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

🤖 Opened new upstream WPT pull request (web-platform-tests/wpt#47187) with upstreamable changes.

@valadaptive

Copy link
Copy Markdown
Contributor Author

Turns out the "bug" was me forgetting to rebuild.

On the plus side, I did create some web platform tests (WPT tests? Has that "ATM machine" ring to it) for testing the behavior of aspect-ratio in combination with box-sizing: border-box, which seems to have been missing from the existing test suite.

Most of the existing aspect-ratio tests seem to be single-file ones, but there are a lot of different test cases and I don't want to create 24 individual .html files, so I used the layout test harness.

Not sure why the WPT Export step is failing--doesn't seem to be anything related to the contents of the tests themselves.

@mrobinson

Copy link
Copy Markdown
Member

Not sure why the WPT Export step is failing--doesn't seem to be anything related to the contents of the tests themselves.

This might be related to the commit from #32803 somehow. Hopefully once you rebase it will improve, but I'll watch it.

@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

📝 Transplanted new upstreamable changes to existing upstream WPT pull request (web-platform-tests/wpt#47187).

@valadaptive

Copy link
Copy Markdown
Contributor Author

Seems to have been caused by force-pushing while the initial WPT sync action was running; I believe it tried to create the PR twice?

@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

📝 Transplanted new upstreamable changes to existing upstream WPT pull request (web-platform-tests/wpt#47187).

@valadaptive

Copy link
Copy Markdown
Contributor Author

About the regressions: replaced-element-024 and replaced-element-026 regress because we don't implement object-fit, and replaced-element-028 regresses because we don't treat non-available <img>s with alt attributes properly.

@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

📝 Transplanted new upstreamable changes to existing upstream WPT pull request (web-platform-tests/wpt#47187).

@mrobinson mrobinson 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 work. I have a few nits, but I'll apply them myself and try to land this.

Comment thread components/layout_2020/style_ext.rs Outdated
Comment on lines +596 to +599
if let PreferredRatio::Ratio(ratio) = preferred_ratio {
if ratio.is_degenerate() {
preferred_ratio = PreferredRatio::None;
}
}

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.

Suggested change
if let PreferredRatio::Ratio(ratio) = preferred_ratio {
if ratio.is_degenerate() {
preferred_ratio = PreferredRatio::None;
}
}
if matches!(preferred_ratio, PreferredRatio::Ratio(ratio) if ratio.is_degenerate()) {
preferred_ratio = PreferredRatio::None;
}

Comment thread components/layout_2020/style_ext.rs Outdated

/// Resolve the preferred aspect ratio according to the given natural aspect
/// ratio and the `aspect-ratio` property.
/// https://drafts.csswg.org/css-sizing-4/#aspect-ratio

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.

Raw URLS in rustdoc comments lead to rustdoc warnings:

Suggested change
/// https://drafts.csswg.org/css-sizing-4/#aspect-ratio
/// <https://drafts.csswg.org/css-sizing-4/#aspect-ratio>

Comment thread components/layout_2020/style_ext.rs Outdated
/// border-box, and the aspect-ratio property does not contain "auto", then
/// the aspect ratio is in respect to the border box. This will then contain
/// the summed sizes of the padding and border. Otherwise, it's 0.
pb_adjust: LogicalVec2<Au>,

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.

Let's just calling this box_sizing_adjustment.

There are two regressions because we don't implement `object-fit`, and
one because we don't properly represent non-available <img>s with `alt`
attributes.

Signed-off-by: valadaptive <[email protected]>
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

📝 Transplanted new upstreamable changes to existing upstream WPT pull request (web-platform-tests/wpt#47187).

@mrobinson
mrobinson added this pull request to the merge queue Jul 24, 2024
Merged via the queue into servo:main with commit 60e65c1 Jul 24, 2024
Gae24 pushed a commit to Gae24/servo that referenced this pull request Jul 26, 2024
)

* Add WPT tests for box-sizing with aspect-ratio

Signed-off-by: valadaptive <[email protected]>

* Implement `aspect-ratio` for replaced elements

There are two regressions because we don't implement `object-fit`, and
one because we don't properly represent non-available <img>s with `alt`
attributes.

Signed-off-by: valadaptive <[email protected]>

---------

Signed-off-by: valadaptive <[email protected]>
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.

4 participants