Skip to content

script: Make visible selection updates flat tree aware - #47931

Merged
mrobinson merged 5 commits into
servo:mainfrom
mrobinson:selection-visible-selection-in-shadow-tree
Sep 11, 2026
Merged

mrobinson merged 5 commits into
servo:mainfrom
mrobinson:selection-visible-selection-in-shadow-tree

Conversation

@mrobinson

Copy link
Copy Markdown
Member

This change reworks the visible selection flag update traversal to be
flat tree aware. In particular:

  • Selection boundaries that are not in the flat tree make the selection
    unrenderable.
  • Selection boundaries now may be inverted if their flat tree positions
    have a different order than their composed tree positions.
  • A new visible range is preserved before layout. This is consulted by
    layout to ensure that start and end boundaries are consistent with
    flat tree reality.
  • The traversal is refactored to be a bit more maintainable.

Testing: This causes a WPT test to start passing.
Fixes: #47120.
Fixes: #47121.

@mrobinson
mrobinson requested a review from gterzian as a code owner September 9, 2026 11:04
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Sep 9, 2026
@mrobinson mrobinson added the T-linux-wpt Do a try run of the WPT label Sep 9, 2026
@github-actions github-actions Bot removed the T-linux-wpt Do a try run of the WPT label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

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

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

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

Flaky unexpected result (31)
  • TIMEOUT [expected OK] /_webgl/conformance/reading/read-pixels-test.html
  • CRASH [expected OK] /_webgl/conformance/uniforms/no-over-optimization-on-uniform-array-06.html
  • TIMEOUT [expected OK] /_webgl/conformance/uniforms/no-over-optimization-on-uniform-array-07.html
  • CRASH [expected OK] /_webgl/conformance/uniforms/no-over-optimization-on-uniform-array-16.html
  • OK /beacon/beacon-basic.https.window.html (#41723)
    • FAIL [expected PASS] subtest: Payload size restriction should be accumulated: type = string

      assert_false: expected false got true
      

    • 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
      

  • TIMEOUT [expected OK] /content-security-policy/navigation/to-javascript-parent-initiated-parent-csp.html (#46400)
    • TIMEOUT [expected PASS] subtest: Should not have executed the javascript url for area[target=iframe].href

      Test timed out
      

    • NOTRUN [expected PASS] subtest: Should not have executed the javascript url for area[target=otherTab].href
    • NOTRUN [expected PASS] subtest: Should not have executed the javascript url for a[target=otherTab].href
    • NOTRUN [expected PASS] subtest: Should not have executed the javascript url for a[target=iframe].href
  • FAIL [expected PASS] /css/css-backgrounds/background-size-041.html
  • OK /css/css-flexbox/text-as-flexitem-size-001.html (#47104)
    • FAIL [expected PASS] subtest: .flexbox > div 1

      assert_equals: 
      <div data-expected-width="70" data-expected-height="35">
              <p>xx xxx</p>
              <p>xx</p>
            </div>
      width expected 70 but got 46
      

    • FAIL [expected PASS] subtest: .flexbox > div 2

      assert_equals: 
      <div data-expected-width="50" data-expected-height="45">
              <p>xx xxx</p>
              <p>xx</p>
            </div>
      width expected 50 but got 46
      

    • FAIL [expected PASS] subtest: .flexbox > div 5

      assert_equals: 
      <div style="height: 30px" data-expected-width="70" data-expected-height="30">
              <p>xx xxx</p>
              <p>xx</p>
            </div>
      width expected 70 but got 46
      

    • FAIL [expected PASS] subtest: .flexbox > div 8

      assert_equals: 
      <div style="min-height: 40px" data-expected-width="70" data-expected-height="40">
              <p>xx xxx</p>
              <p>xx</p>
            </div>
      width expected 70 but got 46
      

    • FAIL [expected PASS] subtest: .flexbox > div 11

      assert_equals: 
      <div style="max-height: 20px" data-expected-width="70" data-expected-height="20">
              <p>xx xxx</p>
              <p>xx</p>
            </div>
      width expected 70 but got 46
      

  • OK /css/css-fonts/variations/at-font-face-font-matching.html (#20684)
    • FAIL [expected PASS] subtest: Matching font-style: 'oblique 20deg' should prefer 'oblique 0deg' over 'oblique -50deg -20deg'

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

    • FAIL [expected PASS] subtest: Matching font-style: 'oblique 10deg' should prefer 'oblique 40deg 50deg' over 'oblique 0deg'

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

  • FAIL [expected PASS] /css/css-ui/appearance-button-001.html
  • TIMEOUT [expected OK] /fetch/content-encoding/zstd/big-zstd-body.https.any.worker.html
    • TIMEOUT [expected PASS] subtest: large zstd data should be decompressed successfully

      Test timed out
      

    • NOTRUN [expected FAIL] subtest: large zstd data should be decompressed successfully with byte stream
  • TIMEOUT /fetch/metadata/generated/css-images.sub.tentative.html (#29047)
    • TIMEOUT [expected PASS] subtest: background-image sec-fetch-site - Not sent to non-trustworthy same-origin destination

      Test timed out
      

    • PASS [expected TIMEOUT] subtest: background-image sec-fetch-mode - Not sent to non-trustworthy cross-site destination
    • FAIL [expected PASS] subtest: content sec-fetch-storage-access - Not sent to non-trustworthy same-site destination

      assert_unreached: Reached unreachable code
      

    • TIMEOUT [expected PASS] subtest: background-image sec-fetch-storage-access - Not sent to non-trustworthy cross-site destination

      Test timed out
      

  • OK /html/browsers/browsing-the-web/navigating-across-documents/navigation-unload-same-origin-fragment.html (#20768)
    • PASS [expected FAIL] subtest: Tests that a fragment navigation in the unload handler will not block the initial navigation
  • 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)&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 /html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/window-open-popup.html (#47829, #47850)
    • FAIL [expected PASS] subtest: No replace before load, triggered by window.open() on a non-_self window

      promise_test: Unhandled rejection with value: object "SecurityError: Location's relevant Document is not same origin-domain with the entry settings object's origin"
      

  • TIMEOUT /html/browsers/history/the-history-interface/001.html (#12580)
    • PASS [expected FAIL] subtest: traversing history must also traverse hash changes
  • TIMEOUT [expected ERROR] /html/browsers/history/the-location-interface/location_replace_session_history.html (#41896)
  • CRASH [expected OK] /html/browsers/history/the-location-interface/security_location_0.htm
  • OK /html/semantics/embedded-content/media-elements/media_fragment_seek.html (#24114)
    • FAIL [expected PASS] subtest: Video should seek to time specified in media fragment syntax

      assert_equals: expected 4 but got 0
      

  • CRASH [expected OK] /html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-nav-location-replace-set-src.html (#32697)
  • CRASH [expected FAIL] /html/semantics/interestfor/interestfor-plain-inline-element.tentative.html
  • OK /paint-timing/fcp-only/fcp-svg.html (#45878)
    • PASS [expected FAIL] subtest: First contentful paint fires when SVG becomes contentful.
  • TIMEOUT [expected OK] /pointerevents/compat/pointerevent_touch-action_two-finger_interaction.html (#44693)
    • 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'
  • OK /preload/prefetch-document.html (#37210)
    • FAIL [expected PASS] subtest: different-site document prefetch with 'as=document' should not be consumed

      assert_equals: expected 2 but got 1
      

  • OK /sanitizer-api/sanitizer-inert-document.html (#45260)
    • PASS [expected FAIL] subtest: Test whether setHTML loads the image.
    • FAIL [expected PASS] subtest: Test whether setHTMLUnsafe loads the image.

      promise_test: Unhandled rejection with value: "The server observed a request. It shouldn't have."
      

  • OK [expected TIMEOUT] /trusted-types/trusted-types-navigation.html?11-15 (#44834)
    • PASS [expected TIMEOUT] subtest: Navigate a window via area with javascript:-urls in report-only mode.
  • TIMEOUT [expected OK] /trusted-types/trusted-types-navigation.html?16-20 (#44835)
    • TIMEOUT [expected PASS] subtest: Navigate a frame via area with javascript:-urls in report-only mode.

      Test timed out
      

    • NOTRUN [expected PASS] subtest: Navigate a frame via area with javascript:-urls w/ default policy in report-only mode.
  • OK [expected TIMEOUT] /trusted-types/trusted-types-navigation.html?31-35 (#38034)
    • PASS [expected TIMEOUT] subtest: Navigate a frame via form-submission with javascript:-urls in report-only mode.
    • PASS [expected NOTRUN] subtest: Navigate a frame via form-submission with javascript:-urls w/ default policy in report-only mode.
    • FAIL [expected NOTRUN] subtest: Navigate a window via form-submission with javascript:-urls w/ a default policy throwing an exception in enforcing mode.

      promise_test: Unhandled rejection with value: "Unexpected message received: \"No securitypolicyviolation reported!\""
      

    • FAIL [expected NOTRUN] subtest: Navigate a window via form-submission with javascript:-urls w/ a default policy throwing an exception in report-only mode.

      promise_test: Unhandled rejection with value: "Unexpected message received: \"No securitypolicyviolation reported!\""
      

    • FAIL [expected NOTRUN] subtest: Navigate a window via form-submission with javascript:-urls w/ a default policy making the URL invalid in enforcing mode.

      promise_test: Unhandled rejection with value: "Unexpected message received: \"No securitypolicyviolation reported!\""
      

  • CRASH [expected OK] /upgrade-insecure-requests/gen/iframe-blank-inherit.meta/unset/sharedworker-module.https.html
  • OK /webdriver/tests/classic/element_click/navigate.py (#47582)
    • FAIL [expected PASS] subtest: test_link_from_toplevel_context_with_target[_blank]

      webdriver.error.NoSuchWindowException: no such window (404)
      

  • OK /webxr/xrSession_features_deviceSupport.https.html (#24357)
    • FAIL [expected PASS] subtest: Immersive XRSession requests with no supported device should reject

      assert_unreached: Should have rejected: undefined Reached unreachable code
      

Stable unexpected results that are known to be intermittent (12)
  • TIMEOUT [expected OK] /_mozilla/mozilla/window-resize-event.html (#36741)
    • TIMEOUT [expected PASS] subtest: Popup onresize event fires after resizeTo

      Test timed out
      

  • OK /_webgl/conformance/textures/misc/texture-upload-size.html (#21770)
    • PASS [expected FAIL] subtest: WebGL test #77
    • PASS [expected FAIL] subtest: WebGL test #79
    • PASS [expected FAIL] subtest: WebGL test #81
    • PASS [expected FAIL] subtest: WebGL test #83
  • PASS [expected FAIL] /css/css-text-decor/text-underline-position-from-font-variable.html (#45615)
  • OK /dom/nodes/moveBefore/iframe-document-preserve.window.html (#43152)
    • FAIL [expected PASS] subtest: moveBefore(): cross-origin iframe is preserved: remove self

      assert_equals: iframe does not fire a second load event expected 1 but got 0
      

    • FAIL [expected PASS] subtest: moveBefore(): cross-origin iframe is preserved: remove self via innerHTML

      assert_equals: iframe does not fire a second load event expected 1 but got 0
      

  • OK [expected TIMEOUT] /fetch/api/redirect/redirect-keepalive.https.any.html (#32153)
    • PASS [expected TIMEOUT] subtest: [keepalive][iframe][load] mixed content redirect; setting up
  • TIMEOUT /fetch/metadata/generated/css-images.https.sub.tentative.html (#42229)
    • FAIL [expected PASS] subtest: content sec-fetch-site - Cross-Site -> Same-Site

      assert_unreached: Reached unreachable code
      

    • FAIL [expected PASS] subtest: content sec-fetch-site - Cross-Site -> Cross-Site

      assert_unreached: Reached unreachable code
      

  • OK /html/browsers/browsing-the-web/navigating-across-documents/refresh/same-document-refresh.html (#34597)
    • PASS [expected FAIL] subtest: Same-Document Referrer from Refresh
  • OK /html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-reload-location-reload.html (#32595)
    • FAIL [expected PASS] subtest: Reloading iframe loading='lazy' before it is loaded: location.reload

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

  • OK /infrastructure/testdriver/click_window.html (#47303)
    • PASS [expected FAIL] subtest: TestDriver click method in window
  • OK [expected TIMEOUT] /trusted-types/trusted-types-navigation.html?01-05 (#38975)
    • PASS [expected TIMEOUT] subtest: Navigate a window via anchor with javascript:-urls in report-only mode.
    • PASS [expected NOTRUN] subtest: Navigate a window via anchor with javascript:-urls w/ default policy in report-only mode.
    • PASS [expected NOTRUN] subtest: Navigate a frame via anchor with javascript:-urls in enforcing mode.
  • TIMEOUT [expected OK] /trusted-types/trusted-types-navigation.html?26-30 (#38807)
    • TIMEOUT [expected PASS] subtest: Navigate a window via form-submission with javascript:-urls in report-only mode.

      Test timed out
      

    • NOTRUN [expected PASS] subtest: Navigate a window via form-submission with javascript:-urls w/ default policy in report-only mode.
    • NOTRUN [expected PASS] subtest: Navigate a frame via form-submission with javascript:-urls in enforcing mode.
    • NOTRUN [expected PASS] subtest: Navigate a frame via form-submission with javascript:-urls w/ default policy in enforcing mode.
  • OK [expected TIMEOUT] /webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.html (#29053)
    • FAIL [expected TIMEOUT] subtest: StorageKey: test 3P about:blank window opened from a 3P iframe

      assert_true: about:blank window opened by 3P iframe does not inherit 3P iframe's StorageKey expected true got false
      

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

✨ Try run (#34343635414) succeeded.

@mrobinson
mrobinson force-pushed the selection-visible-selection-in-shadow-tree branch from 86e9147 to ebc529e Compare September 9, 2026 12:07
@mrobinson
mrobinson marked this pull request as draft September 9, 2026 16:16
@mrobinson
mrobinson force-pushed the selection-visible-selection-in-shadow-tree branch from ebc529e to 0d9a6cb Compare September 9, 2026 18:56
@mrobinson
mrobinson marked this pull request as ready for review September 9, 2026 18:56
Comment thread components/script/dom/node/node.rs Resolved
Comment thread components/script/dom/node/node.rs Resolved
Comment thread components/script/dom/selection.rs Outdated
Comment on lines +61 to +62
/// This is like [`Range`], but in the flat tree, which means that it is `None`
/// if the selection is unrenderable and boundaries are in flat tree order.

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.

At first I read this as "it is None if ([…] and boundaries are in flat tree order)" but a second reading I think it should be:

Suggested change
/// This is like [`Range`], but in the flat tree, which means that it is `None`
/// if the selection is unrenderable and boundaries are in flat tree order.
/// This is like [`Range`], but in the flat tree, which means that:
///
/// * It is `None` if the selection is unrenderable.
/// * Boundaries are in flat tree order.

Comment thread components/script/dom/selection.rs Resolved
@servo-highfive servo-highfive added S-needs-rebase There are merge conflict errors. and removed S-needs-rebase There are merge conflict errors. labels Sep 10, 2026
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Sep 10, 2026
mrobinson and others added 5 commits September 11, 2026 06:19
This change reworks the visible selection flag update traversal to be
flat tree aware. In particular:

 - Selection boundaries that are not in the flat tree make the selection
   unrenderable.
 - Selection boundaries now may be inverted if their flat tree positions
   have a different order than their composed tree positions.
 - A new visible range is preserved before layout. This is consulted by
   layout to ensure that start and end boundaries are consistent with
   flat tree reality.
 - The traversal is refactored to be a bit more maintainable.

Signed-off-by: Martin Robinson <[email protected]>
And move loop consuming it closer to its definition

Signed-off-by: Simon Sapin <[email protected]>
Signed-off-by: Simon Sapin <[email protected]>
Signed-off-by: Martin Robinson <[email protected]>
@mrobinson
mrobinson force-pushed the selection-visible-selection-in-shadow-tree branch from 9db3272 to 774fca2 Compare September 11, 2026 04:46
@servo-highfive servo-highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-rebase There are merge conflict errors. labels Sep 11, 2026
@mrobinson
mrobinson enabled auto-merge September 11, 2026 04:46
@mrobinson
mrobinson added this pull request to the merge queue Sep 11, 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 Sep 11, 2026
Merged via the queue into servo:main with commit c4fbc94 Sep 11, 2026
36 checks passed
@mrobinson
mrobinson deleted the selection-visible-selection-in-shadow-tree branch September 11, 2026 05:48
@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 Sep 11, 2026
RichardTjokroutomo pushed a commit to RichardTjokroutomo/servo that referenced this pull request Oct 6, 2026
This change reworks the visible selection flag update traversal to be
flat tree aware. In particular:

 - Selection boundaries that are not in the flat tree make the selection
   unrenderable.
 - Selection boundaries now may be inverted if their flat tree positions
   have a different order than their composed tree positions.
 - A new visible range is preserved before layout. This is consulted by
   layout to ensure that start and end boundaries are consistent with
   flat tree reality.
 - The traversal is refactored to be a bit more maintainable.


Testing: This causes a WPT test to start passing.
Fixes: servo#47120.
Fixes: servo#47121.

---------

Signed-off-by: Martin Robinson <[email protected]>
Signed-off-by: Simon Sapin <[email protected]>
Signed-off-by: Martin Robinson <[email protected]>
Co-authored-by: Simon Sapin <[email protected]>
hhhwsqhhh pushed a commit to hhhwsqhhh/servo that referenced this pull request Oct 12, 2026
This change reworks the visible selection flag update traversal to be
flat tree aware. In particular:

 - Selection boundaries that are not in the flat tree make the selection
   unrenderable.
 - Selection boundaries now may be inverted if their flat tree positions
   have a different order than their composed tree positions.
 - A new visible range is preserved before layout. This is consulted by
   layout to ensure that start and end boundaries are consistent with
   flat tree reality.
 - The traversal is refactored to be a bit more maintainable.


Testing: This causes a WPT test to start passing.
Fixes: servo#47120.
Fixes: servo#47121.

---------

Signed-off-by: Martin Robinson <[email protected]>
Signed-off-by: Simon Sapin <[email protected]>
Signed-off-by: Martin Robinson <[email protected]>
Co-authored-by: Simon Sapin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

3 participants