avm2: Automatically select a given event's class based on it's data.
This commit is contained in:
parent
ada093938e
commit
c53130e940
|
@ -159,25 +159,12 @@ impl<'gc> Avm2<'gc> {
|
|||
context: &mut UpdateContext<'_, 'gc, '_>,
|
||||
event: Event<'gc>,
|
||||
target: Object<'gc>,
|
||||
) -> Result<bool, Error> {
|
||||
let event_constr = context.avm2.classes().event;
|
||||
Self::dispatch_event_with_class(context, event, event_constr, target)
|
||||
}
|
||||
|
||||
/// Dispatch an event on an object with a specific Event type.
|
||||
///
|
||||
/// The `bool` parameter reads true if the event was cancelled.
|
||||
pub fn dispatch_event_with_class(
|
||||
context: &mut UpdateContext<'_, 'gc, '_>,
|
||||
event: Event<'gc>,
|
||||
event_class: ClassObject<'gc>,
|
||||
target: Object<'gc>,
|
||||
) -> Result<bool, Error> {
|
||||
use crate::avm2::events::dispatch_event;
|
||||
|
||||
let mut activation = Activation::from_nothing(context.reborrow());
|
||||
|
||||
let event_object = EventObject::from_event(&mut activation, event_class, event)?;
|
||||
let event_object = EventObject::from_event(&mut activation, event)?;
|
||||
|
||||
dispatch_event(&mut activation, target, event_object)
|
||||
}
|
||||
|
|
|
@ -142,9 +142,7 @@ pub fn clone<'gc>(
|
|||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
if let Some(evt) = this.unwrap().as_event() {
|
||||
let evt_class = activation.avm2().classes().event;
|
||||
|
||||
return Ok(EventObject::from_event(activation, evt_class, evt.clone())?.into());
|
||||
return Ok(EventObject::from_event(activation, evt.clone())?.into());
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
|
|
|
@ -49,9 +49,14 @@ impl<'gc> EventObject<'gc> {
|
|||
/// we will pull the `prototype` off the `class` given to us.
|
||||
pub fn from_event(
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
class: ClassObject<'gc>,
|
||||
event: Event<'gc>,
|
||||
) -> Result<Object<'gc>, Error> {
|
||||
let class = match event.event_data() {
|
||||
EventData::Event => activation.avm2().classes().event,
|
||||
EventData::FullScreenEvent { .. } => activation.avm2().classes().fullscreenevent,
|
||||
EventData::MouseEvent { .. } => activation.avm2().classes().mouseevent,
|
||||
};
|
||||
|
||||
let proto = class.prototype();
|
||||
let base = ScriptObjectData::base_new(Some(proto), Some(class));
|
||||
|
||||
|
|
|
@ -592,12 +592,7 @@ impl<'gc> Stage<'gc> {
|
|||
full_screen_event.set_bubbles(false);
|
||||
full_screen_event.set_cancelable(false);
|
||||
|
||||
if let Err(e) = crate::avm2::Avm2::dispatch_event_with_class(
|
||||
context,
|
||||
full_screen_event,
|
||||
context.avm2.classes().fullscreenevent,
|
||||
stage,
|
||||
) {
|
||||
if let Err(e) = crate::avm2::Avm2::dispatch_event(context, full_screen_event, stage) {
|
||||
log::error!("Encountered AVM2 error when dispatching event: {}", e);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue