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

avm1: Drop focus on EditText when something else is clicked #16587

Merged
merged 2 commits into from
Jun 4, 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
20 changes: 20 additions & 0 deletions core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,9 @@ impl Player {
for (object, event) in events {
let display_object = object.as_displayobject();
if !display_object.avm1_removed() {
if event == ClipEvent::Press {
Self::update_focus_on_mouse_press(context, display_object);
}
object.handle_clip_event(context, event);
if display_object.movie().is_action_script_3() {
object.event_dispatch_to_avm2(context, event);
Expand Down Expand Up @@ -1575,6 +1578,23 @@ impl Player {
needs_render
}

fn update_focus_on_mouse_press(context: &mut UpdateContext, pressed_object: DisplayObject) {
let is_avm2 = context.swf.is_action_script_3();

// Update AVM1 focus
if !is_avm2 {
let tracker = context.focus_tracker;
// In AVM1 text fields are somewhat special when handling focus.
// When a text field is clicked, it gains focus,
// when something else is clicked, it loses the focus.
// However, this logic only applies to text fields, other objects
// (buttons, movie clips) neither gain focus nor lose it upon press.
if tracker.get_as_edit_text().is_some() && pressed_object.as_edit_text().is_none() {
tracker.set(None, context);
}
}
}

//Checks if two displayObjects have the same depth and id and accur in the same movie.s
fn check_display_object_equality(object1: DisplayObject, object2: DisplayObject) -> bool {
object1.depth() == object2.depth()
Expand Down
34 changes: 34 additions & 0 deletions tests/tests/swfs/avm1/focus_mouse/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "MouseDown", "pos": [5, 5], "btn": "Left" }, { "type": "MouseUp", "pos": [5, 5], "btn": "Left" },

{ "type": "MouseMove", "pos": [70, 175] },
{ "type": "MouseDown", "pos": [70, 175], "btn": "Left" }, { "type": "MouseUp", "pos": [70, 175], "btn": "Left" },
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "MouseDown", "pos": [5, 5], "btn": "Left" }, { "type": "MouseUp", "pos": [5, 5], "btn": "Left" },

{ "type": "MouseMove", "pos": [230, 175] },
{ "type": "MouseDown", "pos": [230, 175], "btn": "Left" }, { "type": "MouseUp", "pos": [230, 175], "btn": "Left" },
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "MouseDown", "pos": [5, 5], "btn": "Left" }, { "type": "MouseUp", "pos": [5, 5], "btn": "Left" },

{ "type": "MouseMove", "pos": [360, 190] },
{ "type": "MouseDown", "pos": [360, 190], "btn": "Left" }, { "type": "MouseUp", "pos": [360, 190], "btn": "Left" },
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "MouseDown", "pos": [5, 5], "btn": "Left" }, { "type": "MouseUp", "pos": [5, 5], "btn": "Left" },

{ "type": "MouseMove", "pos": [360, 190] },
{ "type": "MouseDown", "pos": [360, 190], "btn": "Left" }, { "type": "MouseUp", "pos": [360, 190], "btn": "Left" },
{ "type": "MouseMove", "pos": [230, 175] },
{ "type": "MouseDown", "pos": [230, 175], "btn": "Left" }, { "type": "MouseUp", "pos": [230, 175], "btn": "Left" },

{ "type": "MouseMove", "pos": [360, 190] },
{ "type": "MouseDown", "pos": [360, 190], "btn": "Left" }, { "type": "MouseUp", "pos": [360, 190], "btn": "Left" },
{ "type": "MouseMove", "pos": [70, 175] },
{ "type": "MouseDown", "pos": [70, 175], "btn": "Left" }, { "type": "MouseUp", "pos": [70, 175], "btn": "Left" },

{ "type": "MouseMove", "pos": [360, 190] },
{ "type": "MouseDown", "pos": [360, 190], "btn": "Left" }, { "type": "MouseUp", "pos": [360, 190], "btn": "Left" },
{ "type": "MouseMove", "pos": [360, 190] },
{ "type": "MouseDown", "pos": [360, 190], "btn": "Left" }, { "type": "MouseUp", "pos": [360, 190], "btn": "Left" }
]
45 changes: 45 additions & 0 deletions tests/tests/swfs/avm1/focus_mouse/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
_level0.clip.onMouseDown
_level0.clip.onMouseUp
_level0.clip.onMouseDown
_level0.clip.onPress
_level0.clip.onMouseUp
_level0.clip.onRelease
_level0.clip.onMouseDown
_level0.clip.onMouseUp
_level0.clip.onMouseDown
press
_level0.button.onPress
_level0.clip.onMouseUp
release
_level0.button.onRelease
_level0.clip.onMouseDown
_level0.clip.onMouseUp
_level0.clip.onMouseDown
Focus at: _level0.text
_level0.clip.onMouseUp
_level0.clip.onMouseDown
Focus at: null
_level0.clip.onMouseUp
_level0.clip.onMouseDown
Focus at: _level0.text
_level0.clip.onMouseUp
_level0.clip.onMouseDown
Focus at: null
press
_level0.button.onPress
_level0.clip.onMouseUp
release
_level0.button.onRelease
_level0.clip.onMouseDown
Focus at: _level0.text
_level0.clip.onMouseUp
_level0.clip.onMouseDown
Focus at: null
_level0.clip.onPress
_level0.clip.onMouseUp
_level0.clip.onRelease
_level0.clip.onMouseDown
Focus at: _level0.text
_level0.clip.onMouseUp
_level0.clip.onMouseDown
_level0.clip.onMouseUp
20 changes: 20 additions & 0 deletions tests/tests/swfs/avm1/focus_mouse/test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var listener = new Object();
listener.onSetFocus = function(oldFocus, newFocus) {
trace("Focus at: " + newFocus);
};
Selection.addListener(listener);

function setHandlers(obj) {
obj.onRelease = function () { trace(obj + ".onRelease"); }
obj.onKeyDown = function () { trace(obj + ".onKeyDown"); }
obj.onKeyUp = function () { trace(obj + ".onKeyUp"); }
obj.onPress = function () { trace(obj + ".onPress"); }
obj.onReleaseOutside = function () { trace(obj + ".onReleaseOutside"); }
obj.onMouseDown = function () { trace(obj + ".onMouseDown") }
obj.onMouseUp = function () { trace(obj + ".onMouseUp") }
}

clip.focusEnabled = true;
setHandlers(clip);
setHandlers(button);
setHandlers(text);
Binary file added tests/tests/swfs/avm1/focus_mouse/test.swf
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/focus_mouse/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_ticks = 1