Skip to content

Move click event trigger from embedding layer to ScriptThread - #36413

Merged
jdm merged 3 commits into
servo:mainfrom
yezhizhen:webdriver-click-event
Apr 18, 2025
Merged

jdm merged 3 commits into
servo:mainfrom
yezhizhen:webdriver-click-event

Conversation

@yezhizhen

@yezhizhen yezhizhen commented Apr 9, 2025 •

Copy link
Copy Markdown
Member
  1. Move click event trigger from embedding layer to ScriptThread
  2. Previously, the logic is to trigger click event at same position as MouseButtonAction::Up if MouseButtonAction::Up is within 10px of MouseButtonAction::Down, in embedding layer. This PR removes the condition moves the check to ScriptThread.

Testing: tested for webdriver with self written test case. Perform actions of pointermove, pointerdown, pointerup in sequence. Click event can now be triggered.
Fixes: #35395

cc @xiaochengh @jdm

For MAYBE? TODO: part I added, should we do it? I read the spec, it doesn't specify we have to implement MDN's way.

If we should work in the MDN's way, it also should be fixed in another PR, as this PR doesn't regress anything. Also I am not sure what is the best way to do it.
Should I handle it in

#[allow(unsafe_code)]
pub(crate) fn handle_mouse_button_event(
?

@yezhizhen
yezhizhen force-pushed the webdriver-click-event branch 3 times, most recently from aee567b to ce38d66 Compare April 9, 2025 10:25
Comment thread components/script/script_thread.rs Resolved
@yezhizhen

Copy link
Copy Markdown
Member Author

@mrobinson @jdm I also have some follow up commits to fix #35666. Do you think it should be added to this PR tho?

@jdm

jdm commented Apr 10, 2025

Copy link
Copy Markdown
Member

@mrobinson @jdm I also have some follow up commits to fix #35666. Do you think it should be added to this PR tho?

I would prefer to keep that change in a separate PR.

@yezhizhen
yezhizhen force-pushed the webdriver-click-event branch from ce38d66 to db856ea Compare April 10, 2025 05:46
@yezhizhen
yezhizhen requested a review from jdm April 10, 2025 07:12
@xiaochengh

Copy link
Copy Markdown
Contributor

Do we have a principle which UI events are triggered at which layers?

@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.

Is it possible to remove MouseButtonAction::Click as well with this change?

@jdm

jdm commented Apr 10, 2025

Copy link
Copy Markdown
Member

Is it possible to remove MouseButtonAction::Click as well with this change?

Not without further changes to the egl port, which synthesizes click events from touch events I believe.

@yezhizhen

yezhizhen commented Apr 11, 2025 •

Copy link
Copy Markdown
Member Author

Do we have a principle which UI events are triggered at which layers?

From my observation, most UI events are eventually fired from script/dom/document.rs, tho target can be Element/Window/Document and handle event respectively.

@xiaochengh

Copy link
Copy Markdown
Contributor

I don't get it. Shouldn't most of the UI events triggered from the compositor?

@mrobinson

Copy link
Copy Markdown
Member

I don't get it. Shouldn't most of the UI events triggered from the compositor?

I think that click is a special case. Most UI events map one-to-one to device events, and thus it is easy for an embedder to simply send the events to Servo. click is only supposed to be fired after receiving another event (mouseup) and only when certain conditions are met in a Document. I think that is why, in this case, it is unreasonable for the embedder to trigger this event. I believe that the philosophy we should follow with the Servo API is "Send Servo your raw events, and it will interpret them for the web."

@xiaochengh

Copy link
Copy Markdown
Contributor

I don't get it. Shouldn't most of the UI events triggered from the compositor?

I think that click is a special case. Most UI events map one-to-one to device events, and thus it is easy for an embedder to simply send the events to Servo. click is only supposed to be fired after receiving another event (mouseup) and only when certain conditions are met in a Document. I think that is why, in this case, it is unreasonable for the embedder to trigger this event. I believe that the philosophy we should follow with the Servo API is "Send Servo your raw events, and it will interpret them for the web."

Is it correct to draw the line between device (or raw, low level) events and synthesized (or semantical, higher level) events?

In this way, click, auxclick, dblclick and contextmenu should all be triggered on the script thread. Are we already doing that other than for click?

@mrobinson

Copy link
Copy Markdown
Member

In this way, click, auxclick, dblclick and contextmenu should all be triggered on the script thread. Are we already doing that other than for click?

Yes, I think we are, though it seems like dblclick depends on getting Click events from the embedder (which we would elminate here) and we do not have support for auxclick.

Signed-off-by: Euclid Ye <[email protected]>

Add back `webview_relative_mouse_down_point`

Signed-off-by: Euclid Ye <[email protected]>
@yezhizhen
yezhizhen force-pushed the webdriver-click-event branch from db856ea to 7ce5c08 Compare April 16, 2025 04:28
@yezhizhen
yezhizhen requested a review from xiaochengh April 16, 2025 04:28
Comment thread components/script/script_thread.rs Resolved
@yezhizhen
yezhizhen requested a review from mrobinson April 16, 2025 05:04
Signed-off-by: Euclid Ye <[email protected]>

@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.

This looks good! Thanks for fixing this.

@jdm
jdm added this pull request to the merge queue Apr 18, 2025
Merged via the queue into servo:main with commit 46247a7 Apr 18, 2025
@yezhizhen
yezhizhen deleted the webdriver-click-event branch April 19, 2025 00:49
@yezhizhen

yezhizhen commented Apr 19, 2025 •

Copy link
Copy Markdown
Member Author

I know this is merged. But after pondering, should relative_mouse_down_point be tied with Document instead of ScriptThread?

Otherwise, we might

  1. Trigger mouse down in one tab/iframe
  2. Move to another. But that context is still around.

@jdm

jdm commented Apr 19, 2025 •

Copy link
Copy Markdown
Member

I thought about that when reading the code. I'm not sure it matters, because the user would still need to perform a second mouse down action before another mouse up, which would reset the state.

@yezhizhen

Copy link
Copy Markdown
Member Author

What if I mouse down in one iframe, and then drag by 8px to another pipeline, and then release?
Or with WebDriver: pointerdown, switch to another tab/window, pointerup within 10px of relative_mouse_down_point? (A bit contrived example)

github-merge-queue Bot pushed a commit that referenced this pull request Apr 21, 2025
…ce (#36619)

Rework `ScriptThread::handle_input_event` for correct behaviour and
better performance
1. Only trigger click event with primary button, according to spec
2. Avoid unnecessary clone of `ConstellationInputEvent`

This is a follow up of #36413 

Testing: Manually tested. Right mouse won't trigger click event now.
Fixes: #35666 
cc @jdm @xiaochengh

Signed-off-by: Euclid Ye <[email protected]>
@xiaochengh

Copy link
Copy Markdown
Contributor

@yezhizhen I feel like this can be left as an open issue to discuss.

With mouse, we probably want to avoid such behaviors. But with touch, we probably need such behaviors since touch coordinates are not accurate.

github-merge-queue Bot pushed a commit that referenced this pull request May 13, 2025
After `InputEvent::Touch` processed by Script, it sends
`TouchEventProcessed` back to Constellation, which goes through hit-test
etc. and loops back to Script again. However,
`WebViewRenderer::simulate_mouse_click` should not send
`MouseButtonAction::Click` due to #36413

Testing: Manually tested by converting mouse to touch

cc @jdm @xiaochengh

Signed-off-by: Euclid Ye <[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.

Webdriver mouse down/up pairs should generate a click event

4 participants