mirror of
https://github.com/servo/servo
synced 2026-04-25 17:15:48 +02:00
script: make all keyboard events composed (#44094)
Adjust event targeting for keyboard events when a shadow host is involved. This is needed to not interfere with keyboard default action like tabindex focusing. Testing: Updated WPT tests expectations Fixes: #43809 --------- Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
@@ -1380,10 +1380,7 @@ impl DocumentEventHandler {
|
||||
|
||||
let event = keyevent.upcast::<Event>();
|
||||
|
||||
// FIXME: https://github.com/servo/servo/issues/43809
|
||||
if event.type_() != atom!("keydown") {
|
||||
event.set_composed(true);
|
||||
}
|
||||
event.set_composed(true);
|
||||
|
||||
event.fire(target, can_gc);
|
||||
|
||||
|
||||
@@ -327,6 +327,10 @@ impl Event {
|
||||
|
||||
let mut target = DomRoot::from_ref(target);
|
||||
|
||||
// Save the original dispatch target. Keyboard default actions need the
|
||||
// element the event was originally fired on, not the retargeted host.
|
||||
let original_target = target.clone();
|
||||
|
||||
// Step 1. Set event’s dispatch flag.
|
||||
self.set_flags(EventFlags::Dispatch);
|
||||
|
||||
@@ -637,7 +641,16 @@ impl Event {
|
||||
// https://w3c.github.io/uievents/#default-action
|
||||
// https://dom.spec.whatwg.org/#action-versus-occurance
|
||||
if !self.DefaultPrevented() {
|
||||
if let Some(target) = self.GetTarget() {
|
||||
if self.is::<KeyboardEvent>() {
|
||||
// For keyboard events, use the original dispatch target rather than
|
||||
// event.GetTarget(). Composed keyboard events may retarget across
|
||||
// shadow boundaries, but the default action (character input, Tab
|
||||
// navigation) should use the element the event was originally fired on.
|
||||
if let Some(node) = original_target.downcast::<Node>() {
|
||||
let vtable = vtable_for(node);
|
||||
vtable.handle_event(self, can_gc);
|
||||
}
|
||||
} else if let Some(target) = self.GetTarget() {
|
||||
if let Some(node) = target.downcast::<Node>() {
|
||||
let vtable = vtable_for(node);
|
||||
vtable.handle_event(self, can_gc);
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
[event-propagate-disabled-keyboard.tentative.html]
|
||||
[Untrusted key events on <custom-control disabled="">Text</custom-control>, observed from <form>]
|
||||
expected: FAIL
|
||||
|
||||
[Trusted key events on <custom-control disabled="">Text</custom-control>, observed from <form>]
|
||||
expected: FAIL
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
[keyboardevent-composed.html]
|
||||
[keydown event must be composed]
|
||||
expected: FAIL
|
||||
Reference in New Issue
Block a user