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

avm2: Do not highlight Stage on focus #16214

Merged
merged 3 commits into from
May 5, 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
5 changes: 2 additions & 3 deletions core/src/display_object/avm1_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,11 @@ impl<'gc> TInteractiveObject<'gc> for Avm1Button<'gc> {

fn on_focus_changed(
&self,
context: &mut UpdateContext<'_, 'gc>,
_context: &mut UpdateContext<'_, 'gc>,
focused: bool,
other: Option<InteractiveObject<'gc>>,
_other: Option<InteractiveObject<'gc>>,
) {
self.0.has_focus.set(focused);
self.call_focus_handler(context, focused, other);
}

fn tab_enabled_avm1(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
Expand Down
5 changes: 2 additions & 3 deletions core/src/display_object/avm2_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,12 +826,11 @@ impl<'gc> TInteractiveObject<'gc> for Avm2Button<'gc> {

fn on_focus_changed(
&self,
context: &mut UpdateContext<'_, 'gc>,
_context: &mut UpdateContext<'_, 'gc>,
focused: bool,
other: Option<InteractiveObject<'gc>>,
_other: Option<InteractiveObject<'gc>>,
) {
self.0.has_focus.set(focused);
self.call_focus_handler(context, focused, other);
}

fn tab_enabled_avm2_default(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
Expand Down
5 changes: 1 addition & 4 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2457,17 +2457,14 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
&self,
context: &mut UpdateContext<'_, 'gc>,
focused: bool,
other: Option<InteractiveObject<'gc>>,
_other: Option<InteractiveObject<'gc>>,
) {
let is_action_script_3 = self.movie().is_action_script_3();
let mut text = self.0.write(context.gc_context);
text.flags.set(EditTextFlag::HAS_FOCUS, focused);
if !focused && !is_action_script_3 {
text.selection = None;
}
drop(text);

self.call_focus_handler(context, focused, other);
}

fn is_highlightable(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
Expand Down
3 changes: 1 addition & 2 deletions core/src/display_object/movie_clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3390,10 +3390,9 @@ impl<'gc> TInteractiveObject<'gc> for MovieClip<'gc> {
&self,
context: &mut UpdateContext<'_, 'gc>,
focused: bool,
other: Option<InteractiveObject<'gc>>,
_other: Option<InteractiveObject<'gc>>,
) {
self.0.write(context.gc_context).has_focus = focused;
self.call_focus_handler(context, focused, other);
}

fn tab_enabled_avm1(&self, context: &mut UpdateContext<'_, 'gc>) -> bool {
Expand Down
5 changes: 5 additions & 0 deletions core/src/display_object/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,11 @@ impl<'gc> TInteractiveObject<'gc> for Stage<'gc> {
fn mouse_cursor(self, _context: &mut UpdateContext<'_, 'gc>) -> MouseCursor {
MouseCursor::Arrow
}

fn is_highlight_enabled(&self, _context: &mut UpdateContext<'_, 'gc>) -> bool {
// Highlight is always disabled for stage.
false
}
}

pub struct ParseEnumError;
Expand Down
2 changes: 2 additions & 0 deletions core/src/focus_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ impl<'gc> FocusTracker<'gc> {

if let Some(old) = old {
old.on_focus_changed(context, false, new);
old.call_focus_handler(context, false, new);
}
if let Some(new) = new {
new.on_focus_changed(context, true, old);
new.call_focus_handler(context, true, old);
}

tracing::info!("Focus is now on {:?}", new);
Expand Down
26 changes: 26 additions & 0 deletions tests/tests/swfs/avm2/focus_stage/Test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package {

import flash.display.Sprite;
import flash.text.TextField;
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.MovieClip;
import flash.events.FocusEvent;

[SWF(width="50", height="50", backgroundColor="#000000")]
public class Test extends MovieClip {
public function Test() {
super();

var shape = new Shape();
shape.graphics.beginFill(0xFFFF0000);
shape.graphics.drawRect(10, 10, 30, 30);
shape.graphics.endFill();
this.stage.addChild(shape);
this.stage.addEventListener("focusIn", function (evt:FocusEvent):void {
trace("Focus changed to stage");
});
this.stage.focus = this.stage;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm2/focus_stage/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Focus changed to stage
Binary file added tests/tests/swfs/avm2/focus_stage/test.swf
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/tests/swfs/avm2/focus_stage/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
num_ticks = 1

image_comparisons."output".trigger = 1

[player_options]
with_renderer = { optional = false, sample_count = 1 }