mirror of
https://github.com/servo/servo.git
synced 2025-09-30 08:39:16 +01:00
script: Do not call "scroll into view" when handling element clicks (#39326)
Previously, when we click any element, it would trigger "scroll into view". What's worse, for an anchor `<a>`, clicking it would "scroll into view" instead of navigating to the url until you retry the click. The reason is that we built `scrollIntoView` into the focus transaction system with default option. However, the default `preventScroll` for `FocusOption` is false according to spec, which triggers "scroll into view" by default with focus triggered by interaction. This PR 1. Adds spec document for those which really expects "scroll into view", i.e. `<form>` when validating data. 2. Make sure when we begin focus transaction, we prevent "scroll into view". 3. `Focus` method of element/document stays unchanged, which by default scroll into view if no parameter provided according to spec. Testing: Manually tested on `servo.org` and other websites, and examples with `<form>` still correctly scroll into view when validation fails. Fixes: #38616 --------- Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
parent
d96b147bab
commit
8c50c44942
3 changed files with 27 additions and 10 deletions
|
@ -61,14 +61,15 @@ pub(crate) trait Validatable {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Step 1.1: Let report be the result of firing an event named invalid at element,
|
||||
// Step 1.1: Let `report` be the result of firing an event named invalid at element,
|
||||
// with the cancelable attribute initialized to true.
|
||||
let report = self
|
||||
.as_element()
|
||||
.upcast::<EventTarget>()
|
||||
.fire_cancelable_event(atom!("invalid"), can_gc);
|
||||
|
||||
// Step 1.2.
|
||||
// Step 1.2. If `report` is true, for the element,
|
||||
// report the problem, run focusing steps, scroll into view.
|
||||
if report {
|
||||
let flags = self.validity_state().invalid_flags();
|
||||
println!(
|
||||
|
@ -76,8 +77,7 @@ pub(crate) trait Validatable {
|
|||
validation_message_for_flags(&self.validity_state(), flags)
|
||||
);
|
||||
if let Some(html_elem) = self.as_element().downcast::<HTMLElement>() {
|
||||
// TODO: "Focusing steps" has a different meaning from the focus() method.
|
||||
// The actual focusing steps should be implemented
|
||||
// Run focusing steps and scroll into view.
|
||||
html_elem.Focus(&FocusOptions::default(), can_gc);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue