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: Add support for focus-related events #16581

Merged
merged 17 commits into from
Jul 25, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tests: Add avm2/focus_events_key_same_object test
This test verifies the behavior of focus-related events when
changing focus to the same object using keyboard.
  • Loading branch information
kjarosh committed Jul 25, 2024
commit 3fdfa85c26ab4039333b5a079ef3a8146983dfdd
78 changes: 78 additions & 0 deletions tests/tests/swfs/avm2/focus_events_key_same_object/Test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package {

import flash.display.InteractiveObject;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;

[SWF(width="200", height="200")]
public class Test extends MovieClip {
private var spriteA: Sprite;
private var preventDefault: Boolean;

public function Test() {
super();

spriteA = newSprite();
spriteA.name = "spriteA";
spriteA.x = 0;
spriteA.y = 100;

spriteA.tabEnabled = true;
spriteA.tabIndex = 1;

stage.addChild(spriteA);

stage.addEventListener("keyDown", function(evt:KeyboardEvent):void {
if (evt.keyCode == 9) {
trace("Tab pressed");
}
if (evt.keyCode == 27) {
trace("Escape pressed");
preventDefault = true;
stage.focus = null;
}
});

function eventListener(obj: InteractiveObject): Function {
return function(evt: Event): void {
var str;
if (evt is MouseEvent) {
str = evt.formatToString(
"MouseEvent", "type", "cancelable", "eventPhase",
"relatedObject", "ctrlKey", "altKey", "shiftKey");
} else {
str = evt.toString();
}
trace(" " + obj.name + ", " + evt.target.name + ": " + str);
if (preventDefault && obj != stage) {
evt.preventDefault();
}
}
}

for each (var obj: InteractiveObject in [spriteA, stage]) {
obj.addEventListener("focusIn", eventListener(obj));
obj.addEventListener("focusOut", eventListener(obj));
obj.addEventListener("mouseDown", eventListener(obj));
obj.addEventListener("mouseUp", eventListener(obj));
obj.addEventListener("click", eventListener(obj));
obj.addEventListener("mouseFocusChange", eventListener(obj));
obj.addEventListener("keyFocusChange", eventListener(obj));
obj.addEventListener("rollOut", eventListener(obj));
obj.addEventListener("rollOver", eventListener(obj));
obj.addEventListener("mouseOver", eventListener(obj));
}
}

private function newSprite(): Sprite {
var s:Sprite = new Sprite();
s.graphics.beginFill(0x00FFFF);
s.graphics.drawRect(0, 0, 100, 100);
s.graphics.endFill();
return s;
}
}
}
18 changes: 18 additions & 0 deletions tests/tests/swfs/avm2/focus_events_key_same_object/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{ "type": "KeyDown", "key_code": 9 },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 27 },
{ "type": "KeyUp", "key_code": 27 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 27 },
{ "type": "KeyUp", "key_code": 27 }
]
26 changes: 26 additions & 0 deletions tests/tests/swfs/avm2/focus_events_key_same_object/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Tab pressed
null, null: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=2 relatedObject=[object Sprite] shiftKey=false keyCode=9]
spriteA, spriteA: [FocusEvent type="focusIn" bubbles=true cancelable=false eventPhase=2 relatedObject=null shiftKey=false keyCode=0]
null, spriteA: [FocusEvent type="focusIn" bubbles=true cancelable=false eventPhase=3 relatedObject=null shiftKey=false keyCode=0]
Tab pressed
spriteA, spriteA: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=2 relatedObject=[object Sprite] shiftKey=false keyCode=9]
null, spriteA: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=3 relatedObject=[object Sprite] shiftKey=false keyCode=9]
Tab pressed
spriteA, spriteA: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=2 relatedObject=[object Sprite] shiftKey=false keyCode=9]
null, spriteA: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=3 relatedObject=[object Sprite] shiftKey=false keyCode=9]
Escape pressed
spriteA, spriteA: [FocusEvent type="focusOut" bubbles=true cancelable=false eventPhase=2 relatedObject=null shiftKey=false keyCode=0]
null, spriteA: [FocusEvent type="focusOut" bubbles=true cancelable=false eventPhase=3 relatedObject=null shiftKey=false keyCode=0]
Tab pressed
null, null: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=2 relatedObject=[object Sprite] shiftKey=false keyCode=9]
spriteA, spriteA: [FocusEvent type="focusIn" bubbles=true cancelable=false eventPhase=2 relatedObject=null shiftKey=false keyCode=0]
null, spriteA: [FocusEvent type="focusIn" bubbles=true cancelable=false eventPhase=3 relatedObject=null shiftKey=false keyCode=0]
Tab pressed
spriteA, spriteA: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=2 relatedObject=[object Sprite] shiftKey=false keyCode=9]
null, spriteA: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=3 relatedObject=[object Sprite] shiftKey=false keyCode=9]
Tab pressed
spriteA, spriteA: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=2 relatedObject=[object Sprite] shiftKey=false keyCode=9]
null, spriteA: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=3 relatedObject=[object Sprite] shiftKey=false keyCode=9]
Escape pressed
spriteA, spriteA: [FocusEvent type="focusOut" bubbles=true cancelable=false eventPhase=2 relatedObject=null shiftKey=false keyCode=0]
null, spriteA: [FocusEvent type="focusOut" bubbles=true cancelable=false eventPhase=3 relatedObject=null shiftKey=false keyCode=0]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_ticks = 1