Skip to content

Commit

Permalink
avm2: Migrate ContextMenu-related classes to AS
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian17 authored and Herschel committed Jul 17, 2022
1 parent cad3cd8 commit 22d2810
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 303 deletions.
26 changes: 0 additions & 26 deletions core/src/avm2/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ pub struct SystemClasses<'gc> {
pub date: ClassObject<'gc>,
pub qname: ClassObject<'gc>,
pub sharedobject: ClassObject<'gc>,
pub nativemenu: ClassObject<'gc>,
pub contextmenu: ClassObject<'gc>,
pub mouseevent: ClassObject<'gc>,
pub textevent: ClassObject<'gc>,
pub errorevent: ClassObject<'gc>,
Expand Down Expand Up @@ -151,8 +149,6 @@ impl<'gc> SystemClasses<'gc> {
date: object,
qname: object,
sharedobject: object,
nativemenu: object,
contextmenu: object,
mouseevent: object,
textevent: object,
errorevent: object,
Expand Down Expand Up @@ -658,17 +654,6 @@ pub fn load_player_globals<'gc>(
flash::display::bitmapdata::create_class(mc),
script
);
avm2_system_class!(
nativemenu,
activation,
flash::display::nativemenu::create_class(mc),
script
);
class(
activation,
flash::display::nativemenuitem::create_class(mc),
script,
)?;

// package `flash.filters`
class(
Expand Down Expand Up @@ -716,17 +701,6 @@ pub fn load_player_globals<'gc>(
);

// package `flash.ui`
avm2_system_class!(
contextmenu,
activation,
flash::ui::contextmenu::create_class(mc),
script
);
class(
activation,
flash::ui::contextmenuitem::create_class(mc),
script,
)?;
class(activation, flash::ui::mouse::create_class(mc), script)?;
class(activation, flash::ui::keyboard::create_class(mc), script)?;

Expand Down
2 changes: 0 additions & 2 deletions core/src/avm2/globals/flash/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ pub mod interactiveobject;
pub mod loader;
pub mod loaderinfo;
pub mod movieclip;
pub mod nativemenu;
pub mod nativemenuitem;
pub mod shape;
pub mod simplebutton;
pub mod sprite;
Expand Down
6 changes: 6 additions & 0 deletions core/src/avm2/globals/flash/display/NativeMenu.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package flash.display {
import flash.events.EventDispatcher;
public class NativeMenu extends EventDispatcher {

}
}
6 changes: 6 additions & 0 deletions core/src/avm2/globals/flash/display/NativeMenuItem.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package flash.display {
import flash.events.EventDispatcher;
public class NativeMenuItem extends EventDispatcher {
public var enabled: Boolean;
}
}
3 changes: 2 additions & 1 deletion core/src/avm2/globals/flash/display/interactiveobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ fn set_context_menu<'gc>(
.and_then(|t| t.as_display_object())
.and_then(|dobj| dobj.as_interactive())
{
let cls = activation.avm2().classes().nativemenu;
let cls_name = QName::new(Namespace::package("flash.display"), "NativeMenu");
let cls = activation.resolve_class(&cls_name.into())?;
let value = args
.get(0)
.cloned()
Expand Down
46 changes: 0 additions & 46 deletions core/src/avm2/globals/flash/display/nativemenu.rs

This file was deleted.

49 changes: 0 additions & 49 deletions core/src/avm2/globals/flash/display/nativemenuitem.rs

This file was deleted.

3 changes: 1 addition & 2 deletions core/src/avm2/globals/flash/ui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! `flash.ui` namespace
pub mod contextmenu;
pub mod contextmenuitem;
pub mod context_menu;
pub mod keyboard;
pub mod mouse;
23 changes: 23 additions & 0 deletions core/src/avm2/globals/flash/ui/ContextMenu.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package flash.ui
{
import flash.display.NativeMenu;

public final class ContextMenu extends NativeMenu
{
public function ContextMenu()
{
super();
this.customItems = new Array();
}

public var customItems: Array;

public native function hideBuiltInItems(): void;

public static function get isSupported() : Boolean
{
// TODO: return true when implementation actually affects the context menu
return false;
}
}
}
29 changes: 29 additions & 0 deletions core/src/avm2/globals/flash/ui/ContextMenuItem.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package flash.ui
{
import flash.display.NativeMenuItem;

public final class ContextMenuItem extends NativeMenuItem
{
public function ContextMenuItem(
caption:String,
separatorBefore:Boolean = false,
enabled:Boolean = true,
visible:Boolean = true
)
{
this.caption = caption;
this.separatorBefore = separatorBefore;
this.enabled = enabled;
this.visible = visible;
}

public function clone(): ContextMenuItem
{
return new ContextMenuItem(this.caption, this.separatorBefore, this.enabled, this.visible);
}

public var caption: String;
public var separatorBefore: Boolean;
public var visible: Boolean;
}
}
19 changes: 19 additions & 0 deletions core/src/avm2/globals/flash/ui/context_menu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::avm2::activation::Activation;
use crate::avm2::object::Object;
use crate::avm2::value::Value;
use crate::avm2::Error;

pub fn hide_built_in_items<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
_this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
// TODO: replace this by a proper implementation.
log::warn!("flash.ui.ContextMenu is a stub");
activation
.context
.stage
.set_show_menu(&mut activation.context, false);

Ok(Value::Undefined)
}
90 changes: 0 additions & 90 deletions core/src/avm2/globals/flash/ui/contextmenu.rs

This file was deleted.

Loading

0 comments on commit 22d2810

Please sign in to comment.