diff --git a/core/src/avm2/globals/flash/events.rs b/core/src/avm2/globals/flash/events.rs index 3e8f9b744..1f5bdafe0 100644 --- a/core/src/avm2/globals/flash/events.rs +++ b/core/src/avm2/globals/flash/events.rs @@ -5,5 +5,6 @@ pub mod event_dispatcher; pub mod gesture_event; pub mod keyboard_event; pub mod mouse_event; +pub mod press_and_tap_gesture_event; pub mod timer_event; pub mod touch_event; diff --git a/core/src/avm2/globals/flash/events/PressAndTapGestureEvent.as b/core/src/avm2/globals/flash/events/PressAndTapGestureEvent.as new file mode 100644 index 000000000..b986e5a23 --- /dev/null +++ b/core/src/avm2/globals/flash/events/PressAndTapGestureEvent.as @@ -0,0 +1,50 @@ +package flash.events +{ + public class PressAndTapGestureEvent extends GestureEvent + { + public static const GESTURE_PRESS_AND_TAP : String = "gesturePressAndTap"; + + private var _tapLocalX: Number; + private var _tapLocalY: Number; + + + public function PressAndTapGestureEvent(type:String, bubbles:Boolean = true, cancelable:Boolean = false, phase:String = null, + localX:Number = 0, localY:Number = 0, tapLocalX:Number = 0, tapLocalY:Number = 0, + ctrlKey:Boolean = false, altKey:Boolean = false, shiftKey:Boolean = false, + controlKey:Boolean = false) { + super(type, bubbles, cancelable, phase, localX, localY, ctrlKey, altKey, shiftKey, controlKey); + this._tapLocalX = tapLocalX; + this._tapLocalY = tapLocalY; + } + + override public function clone():Event { + return new PressAndTapGestureEvent(this.type, this.bubbles, this.cancelable, this.phase, this.localX, this.localY, + this.tapLocalX, this.tapLocalY, this.ctrlKey, this.altKey, this.shiftKey, this.controlKey); + } + + override public function toString():String + { + // should fail on FP too, see discussion https://github.com/ruffle-rs/ruffle/pull/12330 + return this.formatToString("GestureEvent","type","bubbles","cancelable","args"); + } + + public function get tapLocalX(): Number { + return this._tapLocalX; + } + + public function set tapLocalX(value: Number): void { + this._tapLocalX = value; + } + + public function get tapLocalY(): Number { + return this._tapLocalY; + } + + public function set tapLocalY(value: Number): void { + this._tapLocalY = value; + } + + public native function get tapStageX():Number; + public native function get tapStageY():Number; + } +} diff --git a/core/src/avm2/globals/flash/events/gesture_event.rs b/core/src/avm2/globals/flash/events/gesture_event.rs index 18982fad7..825542cf5 100644 --- a/core/src/avm2/globals/flash/events/gesture_event.rs +++ b/core/src/avm2/globals/flash/events/gesture_event.rs @@ -4,20 +4,18 @@ use crate::avm2::object::Object; use crate::avm2::value::Value; use crate::avm2::Error; -// Borrow mouse_event's `stageX` getter pub fn get_stage_x<'gc>( activation: &mut Activation<'_, 'gc>, this: Object<'gc>, - args: &[Value<'gc>], + _args: &[Value<'gc>], ) -> Result, Error<'gc>> { - mouse_event::get_stage_x(activation, this, args) + mouse_event::local_to_stage_x(activation, this, "localX", "localY") } -// Borrow mouse_event's `stageY` getter pub fn get_stage_y<'gc>( activation: &mut Activation<'_, 'gc>, this: Object<'gc>, - args: &[Value<'gc>], + _args: &[Value<'gc>], ) -> Result, Error<'gc>> { - mouse_event::get_stage_y(activation, this, args) + mouse_event::local_to_stage_y(activation, this, "localX", "localY") } diff --git a/core/src/avm2/globals/flash/events/mouse_event.rs b/core/src/avm2/globals/flash/events/mouse_event.rs index 75862b823..ae5680372 100644 --- a/core/src/avm2/globals/flash/events/mouse_event.rs +++ b/core/src/avm2/globals/flash/events/mouse_event.rs @@ -10,13 +10,40 @@ pub fn get_stage_x<'gc>( activation: &mut Activation<'_, 'gc>, this: Object<'gc>, _args: &[Value<'gc>], +) -> Result, Error<'gc>> { + local_to_stage_x(activation, this, "localX", "localY") +} + +/// Implements `stageY`'s getter. +pub fn get_stage_y<'gc>( + activation: &mut Activation<'_, 'gc>, + this: Object<'gc>, + _args: &[Value<'gc>], +) -> Result, Error<'gc>> { + local_to_stage_y(activation, this, "localX", "localY") +} + +pub fn update_after_event<'gc>( + activation: &mut Activation<'_, 'gc>, + _this: Object<'gc>, + _args: &[Value<'gc>], +) -> Result, Error<'gc>> { + *activation.context.needs_render = true; + Ok(Value::Undefined) +} + +pub(super) fn local_to_stage_x<'gc>( + activation: &mut Activation<'_, 'gc>, + this: Object<'gc>, + label_x: &'static str, + label_y: &'static str, ) -> Result, Error<'gc>> { if let Some(evt) = this.as_event() { let local_x = this - .get_public_property("localX", activation)? + .get_public_property(label_x, activation)? .coerce_to_number(activation)?; let local_y = this - .get_public_property("localY", activation)? + .get_public_property(label_y, activation)? .coerce_to_number(activation)?; if local_x.is_nan() || local_y.is_nan() { @@ -35,18 +62,18 @@ pub fn get_stage_x<'gc>( Ok(Value::Undefined) } -/// Implements `stageY`'s getter. -pub fn get_stage_y<'gc>( +pub(super) fn local_to_stage_y<'gc>( activation: &mut Activation<'_, 'gc>, this: Object<'gc>, - _args: &[Value<'gc>], + label_x: &'static str, + label_y: &'static str, ) -> Result, Error<'gc>> { if let Some(evt) = this.as_event() { let local_x = this - .get_public_property("localX", activation)? + .get_public_property(label_x, activation)? .coerce_to_number(activation)?; let local_y = this - .get_public_property("localY", activation)? + .get_public_property(label_y, activation)? .coerce_to_number(activation)?; if local_x.is_nan() || local_y.is_nan() { @@ -64,12 +91,3 @@ pub fn get_stage_y<'gc>( Ok(Value::Undefined) } - -pub fn update_after_event<'gc>( - activation: &mut Activation<'_, 'gc>, - _this: Object<'gc>, - _args: &[Value<'gc>], -) -> Result, Error<'gc>> { - *activation.context.needs_render = true; - Ok(Value::Undefined) -} diff --git a/core/src/avm2/globals/flash/events/press_and_tap_gesture_event.rs b/core/src/avm2/globals/flash/events/press_and_tap_gesture_event.rs new file mode 100644 index 000000000..2adcb34f8 --- /dev/null +++ b/core/src/avm2/globals/flash/events/press_and_tap_gesture_event.rs @@ -0,0 +1,21 @@ +use crate::avm2::activation::Activation; +use crate::avm2::globals::flash::events::mouse_event; +use crate::avm2::object::Object; +use crate::avm2::value::Value; +use crate::avm2::Error; + +pub fn get_tap_stage_x<'gc>( + activation: &mut Activation<'_, 'gc>, + this: Object<'gc>, + _args: &[Value<'gc>], +) -> Result, Error<'gc>> { + mouse_event::local_to_stage_x(activation, this, "localTapX", "localTapY") +} + +pub fn get_tap_stage_y<'gc>( + activation: &mut Activation<'_, 'gc>, + this: Object<'gc>, + _args: &[Value<'gc>], +) -> Result, Error<'gc>> { + mouse_event::local_to_stage_y(activation, this, "localTapX", "localTapY") +} diff --git a/core/src/avm2/globals/globals.as b/core/src/avm2/globals/globals.as index 905b60562..53769d73a 100644 --- a/core/src/avm2/globals/globals.as +++ b/core/src/avm2/globals/globals.as @@ -160,6 +160,7 @@ include "flash/events/IOErrorEvent.as" include "flash/events/KeyboardEvent.as" include "flash/events/NetDataEvent.as" include "flash/events/NetStatusEvent.as" +include "flash/events/PressAndTapGestureEvent.as" include "flash/events/ProgressEvent.as" include "flash/events/SampleDataEvent.as" include "flash/events/SecurityErrorEvent.as"