avm2: Impl `TextField.multiline`

This commit is contained in:
David Wendt 2021-02-25 21:33:47 -05:00 committed by Mike Welsh
parent 053b6bd4cc
commit b6a1bf80c1
1 changed files with 44 additions and 0 deletions

View File

@ -373,6 +373,42 @@ pub fn length<'gc>(
Ok(Value::Undefined)
}
pub fn multiline<'gc>(
_activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(this) = this
.and_then(|this| this.as_display_object())
.and_then(|this| this.as_edit_text())
{
return Ok(this.is_multiline().into());
}
Ok(Value::Undefined)
}
pub fn set_multiline<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(this) = this
.and_then(|this| this.as_display_object())
.and_then(|this| this.as_edit_text())
{
let is_multiline = args
.get(0)
.cloned()
.unwrap_or(Value::Undefined)
.coerce_to_boolean();
this.set_multiline(is_multiline, &mut activation.context);
}
Ok(Value::Undefined)
}
/// Construct `TextField`'s class.
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
let class = Class::new(
@ -453,6 +489,14 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
QName::new(Namespace::public(), "length"),
Method::from_builtin(length),
));
write.define_instance_trait(Trait::from_getter(
QName::new(Namespace::public(), "multiline"),
Method::from_builtin(multiline),
));
write.define_instance_trait(Trait::from_setter(
QName::new(Namespace::public(), "multiline"),
Method::from_builtin(set_multiline),
));
class
}