avm2: Impl `TextField.selectable`

This commit is contained in:
David Wendt 2021-02-26 18:24:56 -05:00 committed by Mike Welsh
parent b6a1bf80c1
commit dee937ac3a
1 changed files with 44 additions and 0 deletions

View File

@ -409,6 +409,42 @@ pub fn set_multiline<'gc>(
Ok(Value::Undefined)
}
pub fn selectable<'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_selectable().into());
}
Ok(Value::Undefined)
}
pub fn set_selectable<'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_selectable = args
.get(0)
.cloned()
.unwrap_or(Value::Undefined)
.coerce_to_boolean();
this.set_selectable(is_selectable, &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(
@ -497,6 +533,14 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
QName::new(Namespace::public(), "multiline"),
Method::from_builtin(set_multiline),
));
write.define_instance_trait(Trait::from_getter(
QName::new(Namespace::public(), "selectable"),
Method::from_builtin(selectable),
));
write.define_instance_trait(Trait::from_setter(
QName::new(Namespace::public(), "selectable"),
Method::from_builtin(set_selectable),
));
class
}