script: Add FocusOptions argument to Element.focus and implement FocusOptions.preventScroll (#38495)

This is an implementation of the `prevent_scroll` feature in the focus
transaction system. It allows to control whether focusing an element
should prevent scrolling or not.

Spec:
https://html.spec.whatwg.org/multipage/interaction.html#dom-focusoptions-preventscroll
Testing: Existing WPT tests

Signed-off-by: abdelrahman1234567 <abdelrahman.hossameldin.awadalla@huawei.com>
This commit is contained in:
Abdelrahman Hossam 2025-08-22 22:05:32 +08:00 committed by GitHub
parent 2ac8665e03
commit 176e42d36d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 95 additions and 60 deletions

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
use crate::dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods;
use crate::dom::bindings::codegen::Bindings::HTMLOrSVGElementBinding::FocusOptions;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
@ -75,7 +76,9 @@ pub(crate) trait Validatable {
validation_message_for_flags(&self.validity_state(), flags)
);
if let Some(html_elem) = self.as_element().downcast::<HTMLElement>() {
html_elem.Focus(can_gc);
// TODO: "Focusing steps" has a different meaning from the focus() method.
// The actual focusing steps should be implemented
html_elem.Focus(&FocusOptions::default(), can_gc);
}
}