avm2: Implement TextField.restrict
This commit is contained in:
parent
1c15cd55b9
commit
2ef63d3a61
|
@ -1325,18 +1325,35 @@ pub fn set_mouse_wheel_enabled<'gc>(
|
|||
|
||||
pub fn get_restrict<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
_this: Object<'gc>,
|
||||
this: Object<'gc>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
avm2_stub_getter!(activation, "flash.text.TextField", "restrict");
|
||||
Ok(Value::Null)
|
||||
if let Some(this) = this
|
||||
.as_display_object()
|
||||
.and_then(|this| this.as_edit_text())
|
||||
{
|
||||
return match this.restrict() {
|
||||
Some(value) => Ok(AvmString::new(activation.context.gc_context, value).into()),
|
||||
None => Ok(Value::Null),
|
||||
};
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
pub fn set_restrict<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
_this: Object<'gc>,
|
||||
_args: &[Value<'gc>],
|
||||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
avm2_stub_setter!(activation, "flash.text.TextField", "restrict");
|
||||
if let Some(this) = this
|
||||
.as_display_object()
|
||||
.and_then(|this| this.as_edit_text())
|
||||
{
|
||||
this.set_restrict(
|
||||
args.try_get_string(activation, 0)?.as_deref(),
|
||||
&mut activation.context,
|
||||
);
|
||||
}
|
||||
Ok(Value::Undefined)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
// https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#restrict
|
||||
// See the analogous test from avm1 for description.
|
||||
|
||||
package {
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Stage;
|
||||
import flash.events.Event;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.ui.Keyboard;
|
||||
import flash.text.TextField;
|
||||
|
||||
public class Test extends Sprite {
|
||||
private var player:Sprite;
|
||||
private var text:TextField;
|
||||
|
||||
private var currentRestrict:int = -1;
|
||||
private var restricts:Array = [
|
||||
// different empty values
|
||||
undefined,
|
||||
null,
|
||||
"",
|
||||
false,
|
||||
// non-empty non-string values
|
||||
1,
|
||||
true,
|
||||
0.1,
|
||||
NaN,
|
||||
new Object(),
|
||||
// only selected chars
|
||||
"aB*Δ",
|
||||
"aa",
|
||||
// ASCII ranges
|
||||
"a-z",
|
||||
"A-Z",
|
||||
"a-bA",
|
||||
// non-standard ranges
|
||||
"a-",
|
||||
"-b",
|
||||
"b-a",
|
||||
"A-z",
|
||||
"-",
|
||||
"--",
|
||||
"---",
|
||||
"----",
|
||||
"-----",
|
||||
"-----b",
|
||||
"b-----",
|
||||
"a-b-c",
|
||||
"a-b-A",
|
||||
"a-a-b",
|
||||
"\\\\-\\^",
|
||||
"\\^-\\\\",
|
||||
// various behaviors with caret ^
|
||||
"^",
|
||||
"^^",
|
||||
"\\^a",
|
||||
"^\\^",
|
||||
"^aą",
|
||||
"a^b^c",
|
||||
"a^b^c^A^B",
|
||||
"a-zA-Z^bC",
|
||||
"a-zA-Z^",
|
||||
// escapes
|
||||
"\\-",
|
||||
"a\\-z",
|
||||
"\\\\",
|
||||
"\\^",
|
||||
"\\ab",
|
||||
"a\\",
|
||||
"\u0020-\u007E",
|
||||
// unicode range
|
||||
"α-ω"
|
||||
];
|
||||
|
||||
public function Test() {
|
||||
text = new TextField();
|
||||
text.border = true;
|
||||
text.width = 200;
|
||||
text.height = 20;
|
||||
text.type = "input";
|
||||
addChild(text);
|
||||
|
||||
stage.focus = text;
|
||||
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
|
||||
}
|
||||
|
||||
private function keyPressedDown(event:KeyboardEvent):void {
|
||||
if (event.keyCode == 27) {
|
||||
nextRestrict();
|
||||
}
|
||||
}
|
||||
|
||||
private function nextRestrict():void {
|
||||
trace("Text: '" + text.text + "'");
|
||||
trace("====================");
|
||||
text.text = "";
|
||||
currentRestrict += 1;
|
||||
if (restricts.length <= currentRestrict) {
|
||||
trace("No more restricts");
|
||||
return;
|
||||
}
|
||||
text.restrict = restricts[currentRestrict];
|
||||
trace("Restrict set: '" + restricts[currentRestrict] + "'");
|
||||
trace("Restrict get: '" + text.restrict + "'");
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,191 @@
|
|||
Text: 'abcABC012^\-* &ąδłĄΔŁß'
|
||||
====================
|
||||
Restrict set: 'undefined'
|
||||
Restrict get: 'null'
|
||||
Text: 'abcABC012^\-* &ąδłĄΔŁß'
|
||||
====================
|
||||
Restrict set: 'null'
|
||||
Restrict get: 'null'
|
||||
Text: 'abcABC012^\-* &ąδłĄΔŁß'
|
||||
====================
|
||||
Restrict set: ''
|
||||
Restrict get: ''
|
||||
Text: ''
|
||||
====================
|
||||
Restrict set: 'false'
|
||||
Restrict get: 'false'
|
||||
Text: 'aa'
|
||||
====================
|
||||
Restrict set: '1'
|
||||
Restrict get: '1'
|
||||
Text: '1'
|
||||
====================
|
||||
Restrict set: 'true'
|
||||
Restrict get: 'true'
|
||||
Text: ''
|
||||
====================
|
||||
Restrict set: '0.1'
|
||||
Restrict get: '0.1'
|
||||
Text: '01'
|
||||
====================
|
||||
Restrict set: 'NaN'
|
||||
Restrict get: 'NaN'
|
||||
Text: 'aa'
|
||||
====================
|
||||
Restrict set: '[object Object]'
|
||||
Restrict get: '[object Object]'
|
||||
Text: 'bcbc '
|
||||
====================
|
||||
Restrict set: 'aB*Δ'
|
||||
Restrict get: 'aB*Δ'
|
||||
Text: 'aBaB*Δ'
|
||||
====================
|
||||
Restrict set: 'aa'
|
||||
Restrict get: 'aa'
|
||||
Text: 'aa'
|
||||
====================
|
||||
Restrict set: 'a-z'
|
||||
Restrict get: 'a-z'
|
||||
Text: 'abcabc'
|
||||
====================
|
||||
Restrict set: 'A-Z'
|
||||
Restrict get: 'A-Z'
|
||||
Text: 'ABCABC'
|
||||
====================
|
||||
Restrict set: 'a-bA'
|
||||
Restrict get: 'a-bA'
|
||||
Text: 'abAb'
|
||||
====================
|
||||
Restrict set: 'a-'
|
||||
Restrict get: 'a-'
|
||||
Text: 'aa'
|
||||
====================
|
||||
Restrict set: '-b'
|
||||
Restrict get: '-b'
|
||||
Text: 'abCABC012^\-* &'
|
||||
====================
|
||||
Restrict set: 'b-a'
|
||||
Restrict get: 'b-a'
|
||||
Text: 'bb'
|
||||
====================
|
||||
Restrict set: 'A-z'
|
||||
Restrict get: 'A-z'
|
||||
Text: 'abcABC^\'
|
||||
====================
|
||||
Restrict set: '-'
|
||||
Restrict get: '-'
|
||||
Text: ''
|
||||
====================
|
||||
Restrict set: '--'
|
||||
Restrict get: '--'
|
||||
Text: ''
|
||||
====================
|
||||
Restrict set: '---'
|
||||
Restrict get: '---'
|
||||
Text: ''
|
||||
====================
|
||||
Restrict set: '----'
|
||||
Restrict get: '----'
|
||||
Text: ''
|
||||
====================
|
||||
Restrict set: '-----'
|
||||
Restrict get: '-----'
|
||||
Text: ''
|
||||
====================
|
||||
Restrict set: '-----b'
|
||||
Restrict get: '-----b'
|
||||
Text: 'abCABC012^\-* &'
|
||||
====================
|
||||
Restrict set: 'b-----'
|
||||
Restrict get: 'b-----'
|
||||
Text: 'bb'
|
||||
====================
|
||||
Restrict set: 'a-b-c'
|
||||
Restrict get: 'a-b-c'
|
||||
Text: 'abcABC012^\-* &'
|
||||
====================
|
||||
Restrict set: 'a-b-A'
|
||||
Restrict get: 'a-b-A'
|
||||
Text: 'abAb012-* &'
|
||||
====================
|
||||
Restrict set: 'a-a-b'
|
||||
Restrict get: 'a-a-b'
|
||||
Text: 'abCABC012^\-* &'
|
||||
====================
|
||||
Restrict set: '\\-\^'
|
||||
Restrict get: '\\-\^'
|
||||
Text: '^\'
|
||||
====================
|
||||
Restrict set: '\^-\\'
|
||||
Restrict get: '\^-\\'
|
||||
Text: '^'
|
||||
====================
|
||||
Restrict set: '^'
|
||||
Restrict get: '^'
|
||||
Text: 'abcABC012^\-* &ąδłĄΔŁß'
|
||||
====================
|
||||
Restrict set: '^^'
|
||||
Restrict get: '^^'
|
||||
Text: 'abcABC012^\-* &ąδłĄΔŁß'
|
||||
====================
|
||||
Restrict set: '\^a'
|
||||
Restrict get: '\^a'
|
||||
Text: 'aa^'
|
||||
====================
|
||||
Restrict set: '^\^'
|
||||
Restrict get: '^\^'
|
||||
Text: 'abcABC012\-* &ąδłĄΔŁß'
|
||||
====================
|
||||
Restrict set: '^aą'
|
||||
Restrict get: '^aą'
|
||||
Text: 'AbcABC012^\-* &δłĄΔŁß'
|
||||
====================
|
||||
Restrict set: 'a^b^c'
|
||||
Restrict get: 'a^b^c'
|
||||
Text: 'acac'
|
||||
====================
|
||||
Restrict set: 'a^b^c^A^B'
|
||||
Restrict get: 'a^b^c^A^B'
|
||||
Text: 'aBcaBc'
|
||||
====================
|
||||
Restrict set: 'a-zA-Z^bC'
|
||||
Restrict get: 'a-zA-Z^bC'
|
||||
Text: 'aBcABc'
|
||||
====================
|
||||
Restrict set: 'a-zA-Z^'
|
||||
Restrict get: 'a-zA-Z^'
|
||||
Text: 'abcABC'
|
||||
====================
|
||||
Restrict set: '\-'
|
||||
Restrict get: '\-'
|
||||
Text: '-'
|
||||
====================
|
||||
Restrict set: 'a\-z'
|
||||
Restrict get: 'a\-z'
|
||||
Text: 'aa-'
|
||||
====================
|
||||
Restrict set: '\\'
|
||||
Restrict get: '\\'
|
||||
Text: '\'
|
||||
====================
|
||||
Restrict set: '\^'
|
||||
Restrict get: '\^'
|
||||
Text: '^'
|
||||
====================
|
||||
Restrict set: '\ab'
|
||||
Restrict get: '\ab'
|
||||
Text: 'abab'
|
||||
====================
|
||||
Restrict set: 'a\'
|
||||
Restrict get: 'a\'
|
||||
Text: 'aa'
|
||||
====================
|
||||
Restrict set: ' -~'
|
||||
Restrict get: ' -~'
|
||||
Text: 'abcABC012^\-* &'
|
||||
====================
|
||||
Restrict set: 'α-ω'
|
||||
Restrict get: 'α-ω'
|
||||
Text: 'δ'
|
||||
====================
|
||||
No more restricts
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
num_frames = 1
|
Loading…
Reference in New Issue