Skip to content

The hit_test_result data differs between touch and mouse events in the same event. #40233

Closed as not planned

Description

@ranyuding

Describe the bug:
A touch triggers both touch and mouse events. Normally, after a component touchs down, the mouse event is skipped. However, in this case, the component responds to both touch and mouse signals. Currently, I found that when get the hit_test_result, the DOM tree has changed, and the node responding to the mouse event has also changed.

To Reproduce:

The current phenomenon : Touch event redirects to a new pop-up window, and then the mouse event close the pop-up.
LOG:
touch
10-27 21:43:28.868 54199 54960 E A00000/micservice.5765880207855116497/script::dom::document_event_h..: dingran1 TOUCH Up: at (359.3077, 567.4231) cursor Text
10-27 21:43:28.868 54199 54960 E A00000/micservice.5765880207855116497/script::dom::node: dingran1 Touch or Mouse ==node.dump==: "Element(HTMLElement(HTMLElement))"
10-27 21:43:28.868 54199 54960 E A00000/micservice.5765880207855116497/script::dom::node: dingran1 Touch or Mouse ==node.dump==: " CharacterData(Text(Text))"
10-27 21:43:28.871 54199 54960 E A00000/micservice.5765880207855116497/layout::display_list::hit_test: dingran1 HITTest hit_test result [ElementsFromPointResult { node: OpaqueNode(400575822312), point_in_target: (8.391052, 9.519714), cursor: Text }] point (359.3077, 567.4231)

Mouse
10-27 21:43:28.895 54199 54960 E A00000/micservice.5765880207855116497/script::dom::document_event_h..: dingran1 :: ==MouseButton DOWN== InputEvent
10-27 21:43:28.895 54199 54960 E A00000/micservice.5765880207855116497/layout::display_list::hit_test: dingran1 HITTest hit_test result [ElementsFromPointResult { node: OpaqueNode(400575880816), point_in_target: (359.3077, 567.4231), cursor: Default }] point (359.3077, 567.4231)
10-27 21:43:28.895 54199 54960 E A00000/micservice.5765880207855116497/script::dom::node: dingran1 Touch or Mouse ==node.dump==: "Element(HTMLElement(HTMLElement))"

Platform:
Ohos/Android.
Not sure if can be reproduced with touch simulation.

Activity

  1. added
    C-untriaged
    on Oct 28, 2025
  2. added and removed
    C-untriaged
    on Oct 28, 2025
  3. yezhizhen commented on Oct 28, 2025

    @yezhizhen
    Member

    So the problem is,

    1. script would handle the touch input event, and sending DOM touch event.
    2. script notifies libservo that touch event is processed
    3. Compositor now synthesizes mouse click. However, the layout has already changed.
  4. yezhizhen commented on Oct 28, 2025

    @yezhizhen
    Member

    I just checked the example provided by @kongbai1996. It seems firefox/Chromium also has the same behaviour: synthesized click has different target than the touch when layout changes.

    code sample
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Scroll</title>
        <style>
            div {
                border: 1px black solid;
                width: 200px;
                height: 50px;
            }
        </style>
    </head>
    <body>
    <div id="out" style="width: 220px; height: 600px; border: 2px red solid; overflow: auto"></div>
    <div id="result" style="width: auto"></div>
    </body>
    <script>
        function fib(num) {
            if (num === 0) {
                return 0;
            }
            if (num === 1) {
                return 1;
            }
            return fib(num - 2) + fib(num - 1);
        }
        let out = document.getElementById("out");
        // let out = document.getElementById("result");
        let time = 0;
        for (let i = 0; i < 100; i++) {
            let div = document.createElement("div");
            div.innerHTML = `scroll div ${i}`;
            out.appendChild(div);
            div.addEventListener("mouseup", function (e) {
                result.innerHTML+= `<p>mouseup fire currentTarget:${e.currentTarget.innerHTML} target:${e.target.innerHTML}</p>`
                console.error(`mouseup fire currentTarget:${e.currentTarget.innerHTML} target:${e.target.innerHTML}`)
            })
            div.addEventListener("gesturetap", function (e) {
                result.innerHTML+= `<p>mouseup fire currentTarget:${e.currentTarget.innerHTML} target:${e.target.innerHTML}</p>`
                console.error(`gesturetap fire currentTarget:${e.currentTarget.innerHTML} target:${e.target.innerHTML}`)
            })
            if (i === 1) {
                div.addEventListener("touchmove", function (e) {
                    result.innerHTML+= `<p>div1 touch move handler time:${time} now:${Date.now()}, cancelable: ${e.cancelable}</p>`
                    console.error(`new touch move handler time:${time} now:${Date.now()}, ${e.cancelable}`);
                    time++;
                    let start = Date.now();
                    let fibnum = 42-(time>3?3:time)
                    fibnum = 40;
                    fib(fibnum);
                    e.preventDefault();
                    e.stopPropagation();
                    e.stopImmediatePropagation();
                    console.error(`fib(${fibnum}) cost:${Date.now()-start} now:${Date.now()}  cancelable:${e.cancelable}`)
                }, {passive:true})
                out.addEventListener("scroll", function (e) {
                    result.innerHTML+= `<p>out scroll fire time:${time} now:${Date.now()}, cancelable: ${e.cancelable}</p>`
                })
            }
            if (i === 3) {
                div.addEventListener("touchmove", function (e) {
                    result.innerHTML += `<p>div1 touch move handler time:${time} now:${Date.now()}, cancelable: ${e.cancelable}</p>`
                })
            }
            if (i === 7) {
                div.addEventListener("touchend", function (e) {
                    e.preventDefault();
                })
            }
    
            if (i === 8) {
                function test(){
                    console.error("Test in");
                }
                div.addEventListener("touchend", function (e) {
                    result.innerHTML+= `<p>touchend fire currentTarget:${e.currentTarget.innerHTML} target:${e.target.innerHTML}</p>`
                    console.error(`touchend fire currentTarget:${e.currentTarget.innerHTML} target:${e.target.innerHTML}`)
                    // setTimeout(function () {
                    //     console.error("setTimeout in")
                    out.scrollTo(0,300);
                    // },0)
                })
            }
    
            if (i === 9) {
                div.addEventListener("touchmove", function (e) {
                    console.error(`div9 touchmove fire. cancelable:${e.cancelable}`)
                    e.preventDefault();
                })
            }
            if (i === 11) {
                div.addEventListener("touchmove", function (e) {
                    fib(40);
                    console.error(`div9 touchmove fire. cancelable:${e.cancelable}`)
                })
            }
        }
        document.body.addEventListener("touchmove", function(e) {
            e.preventDefault();
            console.error(`body touchmove fire on bubble now:${Date.now()}`);
        })
       
        out.addEventListener("touchmove", function(e) {
            fib(40);
            result.innerHTML += `<p>out touch move handler time:${time} now:${Date.now()}, cancelable: ${e.cancelable}</p>`
            console.error(`out touchmove fire on capture now:${Date.now()}`);
        }, {passive:false, capture:false})
    </script>
    </html>

    I suspect there is nothing wrong with servo after reading spec. It is website's responsibility, to either

    a. call preventDefault to prevent corresponding mouse events.
    or b. Use pointerEvent to unify all input devices

    cc @xiaochengh @mrobinson It seems the mouse synthesis is a legacy feature, and website developer should do one of above things.

  5. mrobinson commented on Nov 5, 2025

    @mrobinson
    Member

    @yezhizhen Yep, seems pretty reasonable! Considering that the behavior here is the same as other browsers. Can we close this one?

  6. self-assigned this
    on Oct 4, 2026
  7. added a commit that references this issue on Oct 6, 2026
    53f2a80
  8. added a commit that references this issue on Oct 12, 2026
    8876467
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions