Commit Graph

9 Commits

Author SHA1 Message Date
Martin Robinson
1528f31269 script: Add an initial implementation of the "focus update steps" (#44360)
This moves Servo closer to the focus parts of the HTML specification.
The behavior should be the same as before, but now the code in `script`
matches the structure of the specification.

The main goal is to set us up for:
 - Firing focus events in the right order on nested documents
 - A proper implementation of the unfocusing steps.

Testing: This should not change behavior so is covered by existing
tests.

Signed-off-by: Martin Robinson <mrobinson@fastmail.fm>
Co-authored-by: Martin Robinson <mrobinson@fastmail.fm>
2026-04-22 15:55:36 +00:00
Tim van der Lippe
ec513ff851 script: Split up contenteditable.rs into multiple files (#44110)
This file was getting way too big and too cluttered. Instead, split it
up into multiple files in a dedicated folder.

Part of #25005
Part of #43709

Testing: It compiles

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-04-11 15:18:36 +00:00
Martin Robinson
1444aa942b script: Make DocumentFocusHandler hold a FocusableArea (#44029)
Make Servo match the focus bits of the HTML specification a bit more by
storing a `FocusableArea` as the currently focused thing in a
`Document` instead of an optional `Element`. There is always a focused
area of a `Document`, defaulting to the viewport. This is important to
support the case of focused navigables and image maps parts in the
future.

Some focus chain debugging code has been removed as the focus chain
concept needs to be reworked to match the specification more closely.

Testing: This should not change behavior so existing tests should
suffice.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-04-10 21:37:42 +00:00
Martin Robinson
718c8913af script/constellation: Rename and consolidate cross-Document focus messaging (#44020)
There are two times that Servo needs to ask other `Document`s to either
focus or blur.

- During processing of the "focusing steps". When a new element gains
  focus this may cause focus to be lost or gained in parent `<iframe>`s.
- When calling `focus()` on a DOM Window from another origin.

In both of these cases we need to request that a `Document` gain or lose
focus via the Constellation, but in the second case we may have a
`BrowsingContextId` of the `<iframe>` gaining focus and a
`FocusSequence`. This change splits those cases into two kinds of
messages.

Finally, run the entire focusing steps when calling `window.focus()`
instead of going to the constellation immediately. This will be
important in a followup changes where messaging order is made more
consistent.

Testing: This should not change behavior so is covered by existing
tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-04-09 08:59:47 +00:00
Martin Robinson
953206e7c4 script: Add an initial implementation of relatedTarget forfocus/blur events (#43926)
This is an initial implementation for `relatedTarget` of `focus` and
`blur` events. As the code doesn't yet follow the specification this is
a bit tricky to associate with specification text, but this should be
correct. A later change will adapt the code to the "focusing steps" part
of the specification.

In addition, a duplicated call to `Element::set_focus_state` is removed.

Testing: This gets one more WPT test passing.

Signed-off-by: Martin Robinson <mrobinson@fastmail.fm>
Co-authored-by: Martin Robinson <mrobinson@fastmail.fm>
2026-04-04 10:32:22 +00:00
Martin Robinson
87627c4c74 script: Also set the focus state on focused area's shadow hosts (#43873)
The specification says that `:focus` should be active on all shadow
hosts of ancestors of focused areas. This change does that by exposing a
new `DocumentFocusHandler::set_focused_element` method and also using it
during the "removing steps." This is important because unlike the
"focusing steps" `set_focused_element` does not cause focus and blur
events.

Testing: This leads to a progression in results on 8 WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-04-02 17:21:16 +00:00
Martin Robinson
ed8576b163 script: Move all focus-related code to components/script/document/focus.rs and create DocumentFocusHandler (#43868)
This continues the work to split up the large DOM structs. In this case
we create a helper struct to store focus-related state much like
`DocumentEventHandler`.

Testing: This is mostly code motion, so should be covered by existing
tests.
Fixes: #43720

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-04-02 14:11:32 +00:00
Martin Robinson
a486ed525e script: Move "scroll into view" call out of "focusing steps" (#43842)
`HTMLOrSVGElement#focus` specifies the "scroll into view" steps should
be run after focusing. This was happening implicitly as part of the
`Document`'s implementation of the "focusing steps." That behavior is
not in the specification, so this change moves the scrolling call to
where it is specified. Along with making the code match the
specification, this change simplifies it as well.

Testing: This should not modify behavior, so existing tests should
suffice.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-04-01 21:40:13 +00:00
Martin Robinson
ceac966c34 script: Remove focus transaction concept (#43834)
For years Servo has had the concept of a focus transaction which was
used only to allow falling back to focusing the viewport when focusing a
clicked element failed. As this concept isn't part of the specification,
this change removes it.

Instead, a `FocusableArea` (a specification concept) is passed to
the `Document` focusing code. A `FocusableArea` might also be the
`Document`'s viewport.

As part of this change, some focus-related methods are moved to `Node`
from `Element` as the `Document` is not an `Element`.  This brings the
code closer to implementing the "focusing steps" from the specification.

Testing: This should not change behavior and is thus covered by existing
tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-04-01 15:12:21 +00:00