Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: KeyPress events have precedence over tabbing #16415

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,19 @@ impl Player {
}
}

// KeyPress events also take precedence over tabbing.
if !key_press_handled {
if let PlayerEvent::KeyDown {
key_code: KeyCode::Tab,
..
} = event
{
let reversed = context.input.is_key_down(KeyCode::Shift);
let tracker = context.focus_tracker;
tracker.cycle(context, reversed);
}
}

// KeyPress events also take precedence over keyboard navigation.
// Note that keyboard navigation works only when the highlight is visible.
if !key_press_handled && context.focus_tracker.highlight().is_visible() {
Expand Down Expand Up @@ -1200,18 +1213,6 @@ impl Player {
}
}

if let PlayerEvent::KeyDown {
key_code: KeyCode::Tab,
..
} = event
{
self.mutate_with_update_context(|context| {
let reversed = context.input.is_key_down(KeyCode::Shift);
let tracker = context.focus_tracker;
tracker.cycle(context, reversed);
});
}

if self.should_reset_highlight(event) {
self.mutate_with_update_context(|context| {
context.focus_tracker.reset_highlight();
Expand Down
16 changes: 16 additions & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_tab/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{ "type": "KeyDown", "key_code": 9 },
{ "type": "TextInput", "codepoint": "\t" },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "TextInput", "codepoint": "\t" },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 27 },
{ "type": "KeyUp", "key_code": 27 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "TextInput", "codepoint": "\t" },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "TextInput", "codepoint": "\t" },
{ "type": "KeyUp", "key_code": 9 }
]
20 changes: 20 additions & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_tab/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Focus changed: null -> _level0.button1
button.onKeyDown: 9
Tab pressed
Focus changed: _level0.button1 -> _level0.button2
button.onKeyUp: 9
button.onKeyDown: 9
Tab pressed
Focus changed: _level0.button2 -> _level0.button1
button.onKeyUp: 9
button.onKeyDown: 27
===== Escape pressed
button.onKeyUp: 27
button.onKeyDown: 9
Tab pressed
keyPress 3 tab
button.onKeyUp: 9
button.onKeyDown: 9
Tab pressed
keyPress 3 tab
button.onKeyUp: 9
35 changes: 35 additions & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_tab/test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var listener = new Object();
listener.onKeyDown = function() {
if (Key.getCode() == 9) {
trace("Tab pressed");
}
if (Key.getCode() == 27) {
trace("===== Escape pressed");

button2._visible = false;
button3._visible = true;
Selection.setFocus(button1);
}
};
listener.onSetFocus = function(oldFocus, newFocus) {
if (newFocus) {
trace("Focus changed: " + oldFocus + " -> " + newFocus);
}
};
Key.addListener(listener);
Selection.addListener(listener);

button1.tabIndex = 1;
button2.tabIndex = 2;
button3.tabIndex = 3;

var buttons = [button1, button2, button3];
for (var i in buttons) {
buttons[i].onKeyDown = function () { trace("button.onKeyDown: " + Key.getCode()); }
buttons[i].onKeyUp = function () { trace("button.onKeyUp: " + Key.getCode()); }
buttons[i].onPress = function () { trace("button.onPress: " + Key.getCode()); }
buttons[i].onRelease = function () { trace("button.onRelease: " + Key.getCode()); }
}

button3._visible = false;
Selection.setFocus(button1);
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_tab/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_ticks = 1