From b6a1bf80c15bfec62a669329eca070a5906f018d Mon Sep 17 00:00:00 2001 From: David Wendt Date: Thu, 25 Feb 2021 21:33:47 -0500 Subject: [PATCH] avm2: Impl `TextField.multiline` --- core/src/avm2/globals/flash/text/textfield.rs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/core/src/avm2/globals/flash/text/textfield.rs b/core/src/avm2/globals/flash/text/textfield.rs index 31376dff4..31a32a696 100644 --- a/core/src/avm2/globals/flash/text/textfield.rs +++ b/core/src/avm2/globals/flash/text/textfield.rs @@ -373,6 +373,42 @@ pub fn length<'gc>( Ok(Value::Undefined) } +pub fn multiline<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, 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>, + args: &[Value<'gc>], +) -> Result, 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 }