Author: toshok
Date: 2007-07-19 21:11:27 -0400 (Thu, 19 Jul 2007)
New Revision: 82333
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/plugin-class.cpp
trunk/moon/plugin/plugin-class.h
Log:
* plugin-class.h, plugin-class.cpp: factor out the
EventListenerProxy stuff into a separate class.
2007-07-19 Chris Toshok <[EMAIL PROTECTED]>
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2007-07-20 01:10:43 UTC (rev 82332)
+++ trunk/moon/plugin/ChangeLog 2007-07-20 01:11:27 UTC (rev 82333)
@@ -1,5 +1,10 @@
2007-07-19 Chris Toshok <[EMAIL PROTECTED]>
+ * plugin-class.h, plugin-class.cpp: factor out the
+ EventListenerProxy stuff into a separate class.
+
+2007-07-19 Chris Toshok <[EMAIL PROTECTED]>
+
* plugin-class.cpp (moonlight_control_get_property): Retain the
settings/content objects before returning them. fixes crash in
silverlight chess.
Modified: trunk/moon/plugin/plugin-class.cpp
===================================================================
--- trunk/moon/plugin/plugin-class.cpp 2007-07-20 01:10:43 UTC (rev 82332)
+++ trunk/moon/plugin/plugin-class.cpp 2007-07-20 01:11:27 UTC (rev 82333)
@@ -72,29 +72,68 @@
}
-typedef void (*EventArgsWrapper)(NPP instance, gpointer calldata, NPVariant
*value);
+EventListenerProxy::EventListenerProxy (NPP instance, const char *event_name,
const NPVariant *cb)
+{
+ this->instance = instance;
+ this->event_name = g_strdup (event_name);
-struct EventListenerProxy {
- NPP instance;
+ if (NPVARIANT_IS_OBJECT (*cb)) {
+ this->is_func = true;
+ this->callback = NPVARIANT_TO_OBJECT (*cb);
+ NPN_RetainObject ((NPObject*)this->callback);
+ }
+ else {
+ this->is_func = false;
+ this->callback = g_strdup (NPVARIANT_TO_STRING
(*cb).utf8characters);
+ }
+}
- bool is_func;
+EventListenerProxy::~EventListenerProxy ()
+{
+ if (is_func)
+ NPN_ReleaseObject ((NPObject*)this->callback);
+ else
+ g_free ((char*)this->callback);
- /* if @is_func == true, callback is an NPObject (the function object)
- if @is_func == false, callback is a char* (the function name)
- */
- gpointer callback;
+ g_free (event_name);
+}
- EventArgsWrapper event_args_wrapper;
-};
+void
+EventListenerProxy::AddHandler (EventObject *obj)
+{
+ obj->AddHandler (event_name, proxy_listener_to_javascript, this);
+}
-static void
-default_wrapper (NPP instance, gpointer calldata, NPVariant *value)
+void
+EventListenerProxy::RemoveHandler (EventObject *obj)
{
+ obj->RemoveHandler (event_name, proxy_listener_to_javascript, this);
+}
+
+EventArgsWrapper
+EventListenerProxy::get_wrapper_for_event_name (const char *event_name)
+{
+ if (!g_strcasecmp ("mousemove", event_name) ||
+ !g_strcasecmp ("mouseleftbuttonup", event_name) ||
+ !g_strcasecmp ("mouseleftbuttondown", event_name) ||
+ !g_strcasecmp ("mouseenter", event_name)) {
+
+ return mouse_event_wrapper;
+ }
+ // XXX need to handle key events
+ else {
+ return default_wrapper;
+ }
+}
+
+void
+EventListenerProxy::default_wrapper (NPP instance, gpointer calldata,
NPVariant *value)
+{
NULL_TO_NPVARIANT (*value);
}
-static void
-mouse_event_wrapper (NPP instance, gpointer calldata, NPVariant *value)
+void
+EventListenerProxy::mouse_event_wrapper (NPP instance, gpointer calldata,
NPVariant *value)
{
MouseEventArgs *ea = (MouseEventArgs*)calldata;
MoonlightMouseEventArgsObject *jsea =
(MoonlightMouseEventArgsObject*)NPN_CreateObject (instance,
MoonlightMouseEventArgsClass);
@@ -103,8 +142,8 @@
OBJECT_TO_NPVARIANT (jsea, *value);
}
-static void
-proxy_listener_to_javascript (EventObject *sender, gpointer calldata, gpointer
closure)
+void
+EventListenerProxy::proxy_listener_to_javascript (EventObject *sender,
gpointer calldata, gpointer closure)
{
EventListenerProxy *proxy = (EventListenerProxy*)closure;
@@ -117,8 +156,11 @@
NPN_RetainObject (depobj); // XXX leak?
OBJECT_TO_NPVARIANT (depobj, args[0]);
- proxy->event_args_wrapper (proxy->instance, calldata, &args[1]);
+ EventArgsWrapper event_args_wrapper = get_wrapper_for_event_name
(proxy->event_name);
+
+ event_args_wrapper (proxy->instance, calldata, &args[1]);
+
if (proxy->is_func) {
/* the event listener was added with a JS function object */
if (NPN_InvokeDefault (proxy->instance,
(NPObject*)proxy->callback, args, 2, &result))
@@ -139,22 +181,7 @@
}
}
-static EventArgsWrapper
-get_wrapper_for_event_name (const char *event_name)
-{
- if (!g_strcasecmp ("mousemove", event_name) ||
- !g_strcasecmp ("mouseleftbuttonup", event_name) ||
- !g_strcasecmp ("mouseleftbuttondown", event_name) ||
- !g_strcasecmp ("mouseenter", event_name)) {
- return mouse_event_wrapper;
- }
- // XXX need to handle key events
- else {
- return default_wrapper;
- }
-}
-
static void
value_to_variant (NPObject *npobj, Value *v, NPVariant *result)
{
@@ -843,14 +870,11 @@
MoonlightContentObject *content = (MoonlightContentObject*)npobj;
/* XXX free the registered_scriptable_objects hash */
+ DEBUG_WARN_NOTIMPLEMENTED ();
- /* XXX free resizeMethodName */
-
-
-// XXX apparently we don't need to do this?
-// if (content->resizeScript)
-// NPN_ReleaseObject (content->resizeScript);
- content->resizeScript = NULL;
+ if (content->resizeProxy)
+ delete content->resizeProxy;
+ content->resizeProxy = NULL;
}
static const char *const
@@ -937,26 +961,19 @@
return true;
}
else if (name_matches (name, "onResize")) {
-#if notyet
+#if notyet /* XXX Surface needs to inherit from DependencyObject */
PluginInstance *plugin = (PluginInstance*)
((MoonlightObject*)npobj)->instance->pdata;
+ EventListenerProxy *proxy = new EventListenerProxy
(((MoonlightObject*)npobj)->instance,
+ "Resize",
+ value);
- if (!NPVARIANT_IS_OBJECT (*value)) {
- DEBUG_WARN_NOTIMPLEMENTED ();
- return true;
- }
+ proxy->AddHandler (plugin->surface);
- EventListenerProxy *proxy = new EventListenerProxy ();
- proxy->instance = ((MoonlightObject*)npobj)->instance;
- proxy->callback = NPVARIANT_TO_OBJECT (*value);
- proxy->event_args_wrapper = get_wrapper_for_event_name
("Resize");
-
- NPN_RetainObject (proxy->callback);
-
- plugin->surface->AddHandler ("Resize",
proxy_listener_to_javascript, proxy);
-#endif
+ // XXX store the proxy someplace in this object
+#endif
+ DEBUG_WARN_NOTIMPLEMENTED ();
return true;
}
-
return false;
}
@@ -1217,22 +1234,12 @@
name[0] = toupper(name[0]);
- EventListenerProxy *proxy = new EventListenerProxy ();
- proxy->instance = ((MoonlightObject*)npobj)->instance;
- proxy->event_args_wrapper = get_wrapper_for_event_name (name);
+ EventListenerProxy *proxy = new EventListenerProxy
(((MoonlightObject*)npobj)->instance,
+ name,
+ &args[1]);
- if (NPVARIANT_IS_OBJECT (args[1])) {
- proxy->is_func = true;
- proxy->callback = NPVARIANT_TO_OBJECT (args[1]);
- NPN_RetainObject ((NPObject*)proxy->callback);
- }
- else {
- proxy->is_func = false;
- proxy->callback = g_strdup (NPVARIANT_TO_STRING
(args[1]).utf8characters);
- }
+ proxy->AddHandler (dob);
- dob->AddHandler (name, proxy_listener_to_javascript, proxy);
-
g_free (name);
return true;
Modified: trunk/moon/plugin/plugin-class.h
===================================================================
--- trunk/moon/plugin/plugin-class.h 2007-07-20 01:10:43 UTC (rev 82332)
+++ trunk/moon/plugin/plugin-class.h 2007-07-20 01:11:27 UTC (rev 82333)
@@ -18,6 +18,34 @@
void plugin_init_classes (void);
+/*** EventListenerProxy */
+typedef void (*EventArgsWrapper)(NPP instance, gpointer calldata, NPVariant
*value);
+
+class EventListenerProxy {
+ public:
+ EventListenerProxy (NPP instance, const char *event_name, const
NPVariant *cb);
+ ~EventListenerProxy ();
+ void AddHandler (EventObject *obj);
+ void RemoveHandler (EventObject *obj);
+
+ private:
+ NPP instance;
+
+ bool is_func;
+
+ /* if @is_func == true, callback is an NPObject (the function object)
+ if @is_func == false, callback is a char* (the function name)
+ */
+ gpointer callback;
+
+ char *event_name;
+
+ static EventArgsWrapper get_wrapper_for_event_name (const char
*event_name);
+ static void default_wrapper (NPP instance, gpointer calldata, NPVariant
*value);
+ static void mouse_event_wrapper (NPP instance, gpointer calldata,
NPVariant *value);
+ static void proxy_listener_to_javascript (EventObject *sender, gpointer
calldata, gpointer closure);
+};
+
/*** MoonlightObjectClass
**************************************************************/
struct MoonlightObjectType : NPClass {
@@ -97,18 +125,14 @@
struct MoonlightContentObject : MoonlightObject {
MoonlightContentObject (NPP instance)
: MoonlightObject (instance),
- resizeScript (NULL), resizeMethodName (NULL),
- resizeIsScript (false), resizeSet (false)
+ resizeProxy (NULL)
{
registered_scriptable_objects = g_hash_table_new
(g_direct_hash, g_direct_equal);
}
GHashTable *registered_scriptable_objects;
- NPObject *resizeScript;
- char *resizeMethodName;
- bool resizeIsScript;
- bool resizeSet;
+ EventListenerProxy *resizeProxy;
};
extern MoonlightContentType* MoonlightContentClass;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches