Author: rolf
Date: 2007-08-29 11:08:03 -0400 (Wed, 29 Aug 2007)
New Revision: 85000
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/plugin-class.cpp
trunk/moon/plugin/plugin-class.h
trunk/moon/plugin/plugin.cpp
trunk/moon/src/ChangeLog
trunk/moon/src/clock.h
trunk/moon/src/dependencyobject.cpp
trunk/moon/src/dependencyobject.h
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
trunk/moon/src/type.cpp
trunk/moon/src/type.cpp.in
trunk/moon/src/type.h
trunk/moon/src/type.h.in
Log:
* src/clock.h: Implement TimeManager::GetObjectType.
* src/dependencyobject.h, src/dependencyobject.cpp: Move all type
management down to Base (GetObjectType, Is, GetType, GetTypeName),
and implement GetObjectType in the classes that don't do it
already. Remove BASE_FLOATS, simplifying ref counting.
* src/type.cpp.in, src/type.h, src/type.cpp, src/type.h.in: Added Base
and inherited classes that don't already inherit from
DependencyObject.
* src/runtime.h, src/runtime.cpp: Add the Fullscreen API (not
implemented yet, only raises events), and implement GetObjectType.
* plugin/plugin.cpp: Don't delete the surface, unref it.
* plugin/plugin-class.cpp, plugin/plugin-class.h: Create a
MoonlightEventObject* and make MoonlightDependencyObject* inherit
from it. Change all event usage to the new class, enables events
for objects that aren't DependencyObjects (but are EventObjects,
such as Surface). Implement FullScreen support in the plugin.
Remove the dob field from MoonlightDependencyObject, the
MoonlightEventObject has an eo field that fits the purpose, and
implement a MoonlightDependencyObject.GetDependencyObject () that
does what dob did earlier (and change all usages).
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/plugin/ChangeLog 2007-08-29 15:08:03 UTC (rev 85000)
@@ -1,3 +1,15 @@
+2007-08-29 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
+
+ * plugin.cpp: Don't delete the surface, unref it.
+ * plugin-class.cpp, plugin-class.h: Create a MoonlightEventObject* and
make
+ MoonlightDependencyObject* inherit from it. Change all event usage to
+ the new class, enables events for objects that aren't
DependencyObjects
+ (but are EventObjects, such as Surface). Implement FullScreen support
in
+ the plugin. Remove the dob field from MoonlightDependencyObject, the
+ MoonlightEventObject has an eo field that fits the purpose, and
+ implement a MoonlightDependencyObject.GetDependencyObject () that does
+ what dob did earlier (and change all usages).
+
2007-08-24 Jackson Harper <[EMAIL PROTECTED]>
* plugin-class.cpp|h: Add a new EventListenerObject that we can
Modified: trunk/moon/plugin/plugin-class.cpp
===================================================================
--- trunk/moon/plugin/plugin-class.cpp 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/plugin/plugin-class.cpp 2007-08-29 15:08:03 UTC (rev 85000)
@@ -141,8 +141,8 @@
/* more builtins.. */
default:
if (v->GetKind () >= Type::DEPENDENCY_OBJECT) {
- MoonlightDependencyObjectObject *depobj =
- DependencyObjectCreateWrapper
(((MoonlightObject*)npobj)->instance, v->AsDependencyObject ());
+ MoonlightEventObjectObject *depobj =
+ EventObjectCreateWrapper
(((MoonlightObject*)npobj)->instance, v->AsDependencyObject ());
OBJECT_TO_NPVARIANT (depobj, *result);
}
break;
@@ -180,6 +180,12 @@
}
}
+NPObject*
+EventListenerProxy::GetCallbackAsNPObject ()
+{
+ g_assert (is_func);
+ return (NPObject*) callback;
+}
EventListenerProxy::EventListenerProxy (NPP instance, const char *event_name,
const char *cb_name)
{
@@ -282,8 +288,8 @@
NPVariant args[2];
NPVariant result;
- MoonlightDependencyObjectObject *depobj = DependencyObjectCreateWrapper
(proxy->instance,
-
/* XXX ew */ (DependencyObject*)sender);
+ MoonlightEventObjectObject *depobj = EventObjectCreateWrapper
(proxy->instance,
+
(EventObject*)sender);
NPN_RetainObject (depobj); // XXX leak?
@@ -291,10 +297,8 @@
EventArgsWrapper event_args_wrapper = get_wrapper_for_event_name
(proxy->event_name);
- // printf ("proxying event %s to javascript\n", proxy->event_name);
+ // printf ("proxying event %s to javascript, sender = %p (%s)\n",
proxy->event_name, sender, ((EventObject*)sender)->GetTypeName());
- // printf ("sender == %p (%s)\n", sender,
((DependencyObject*)sender)->GetTypeName());
-
event_args_wrapper (proxy->instance, calldata, &args[1]);
if (proxy->is_func) {
@@ -802,7 +806,7 @@
double y = ea->y;
if (NPVARIANT_IS_OBJECT (args [0])) {
- DependencyObject *dob =
((MoonlightDependencyObjectObject*) NPVARIANT_TO_OBJECT (args [0]))->dob;
+ DependencyObject *dob =
((MoonlightDependencyObjectObject*) NPVARIANT_TO_OBJECT (args
[0]))->GetDependencyObject ();
if (dob->Is (Type::UIELEMENT))
uielement_transform_point ((UIElement*) dob,
&x, &y);
}
@@ -1128,7 +1132,7 @@
Downloader *dl = new Downloader ();
- obj = DependencyObjectCreateWrapper
(((MoonlightObject*)npobj)->instance, dl);
+ obj = EventObjectCreateWrapper
(((MoonlightObject*)npobj)->instance, dl);
OBJECT_TO_NPVARIANT (obj, *result);
return true;
@@ -1332,6 +1336,9 @@
if (content->resizeProxy)
delete content->resizeProxy;
content->resizeProxy = NULL;
+ if (content->fullScreenChangeProxy)
+ delete content->fullScreenChangeProxy;
+ content->fullScreenChangeProxy = NULL;
}
static const char *const
@@ -1378,33 +1385,36 @@
PluginInstance *plugin = (PluginInstance*)
((MoonlightObject*)npobj)->instance->pdata;
if (name_matches (name, "actualHeight")) {
- // not implemented correctly yet - these only have values in
fullscreen mode
INT32_TO_NPVARIANT (plugin->getActualHeight (), *result);
return true;
}
else if (name_matches (name, "actualWidth")) {
- // not implemented correctly yet - these only have values in
fullscreen mode
INT32_TO_NPVARIANT (plugin->getActualWidth (), *result);
return true;
}
else if (name_matches (name, "fullScreen")) {
- // not implemented yet.
- BOOLEAN_TO_NPVARIANT (false, *result);
+ BOOLEAN_TO_NPVARIANT (plugin->surface->GetFullScreen (),
*result);
return true;
}
else if (name_matches (name, "onResize")) {
- // not implemented yet.
- NULL_TO_NPVARIANT (*result);
+ MoonlightContentObject* obj = (MoonlightContentObject*) npobj;
+ if (obj->resizeProxy == NULL)
+ NULL_TO_NPVARIANT (*result);
+ else
+ OBJECT_TO_NPVARIANT
(obj->resizeProxy->GetCallbackAsNPObject (), *result);
return true;
}
else if (name_matches (name, "onFullScreenChange")) {
- // not implemented yet.
- NULL_TO_NPVARIANT (*result);
+ MoonlightContentObject* obj = (MoonlightContentObject*) npobj;
+ if (obj->fullScreenChangeProxy == NULL)
+ NULL_TO_NPVARIANT (*result);
+ else
+ OBJECT_TO_NPVARIANT
(obj->fullScreenChangeProxy->GetCallbackAsNPObject (), *result);
return true;
}
else if (name_matches (name, "root")) {
DependencyObject *top = plugin->surface->GetToplevel ();
- MoonlightDependencyObjectObject *topobj =
DependencyObjectCreateWrapper (((MoonlightObject *) npobj)->instance, top);
+ MoonlightEventObjectObject *topobj = EventObjectCreateWrapper
(((MoonlightObject *) npobj)->instance, top);
OBJECT_TO_NPVARIANT (topobj, *result);
return true;
@@ -1425,24 +1435,45 @@
static bool
moonlight_content_set_property (NPObject *npobj, NPIdentifier name, const
NPVariant *value)
{
+ PluginInstance *plugin = (PluginInstance*)
((MoonlightObject*)npobj)->instance->pdata;
if (name_matches (name, "fullScreen")) {
- // not implemented yet.
+ plugin->surface->SetFullScreen (NPVARIANT_TO_BOOLEAN (*value));
return true;
}
else if (name_matches (name, "onResize")) {
MoonlightContentObject *obj = (MoonlightContentObject *) npobj;
- PluginInstance *plugin = (PluginInstance*)
((MoonlightObject*)npobj)->instance->pdata;
- EventListenerProxy *proxy = new EventListenerProxy
(((MoonlightObject*)npobj)->instance,
- "Resize",
- value);
-
- proxy->AddHandler (plugin->surface);
- obj->resizeProxy = proxy;
+ // If we have a handler, remove it.
+ if (obj->resizeProxy != NULL) {
+ obj->resizeProxy->RemoveHandler (plugin->surface);
+ delete obj->resizeProxy;
+ obj->resizeProxy = NULL;
+ }
+
+ if (!NPVARIANT_IS_NULL (*value)) {
+ obj->resizeProxy = new EventListenerProxy
(((MoonlightObject*)npobj)->instance,
+ "Resize",
value);
+ obj->resizeProxy->AddHandler (plugin->surface);
+ }
+
return true;
}
else if (name_matches (name, "onFullScreenChange")) {
- DEBUG_WARN_NOTIMPLEMENTED ("content onFullScreenChange");
+ MoonlightContentObject *obj = (MoonlightContentObject *) npobj;
+
+ // If we have a handler, remove it.
+ if (obj->fullScreenChangeProxy != NULL) {
+ obj->fullScreenChangeProxy->RemoveHandler
(plugin->surface);
+ delete obj->fullScreenChangeProxy;
+ obj->fullScreenChangeProxy = NULL;
+ }
+
+ if (!NPVARIANT_IS_NULL (*value)) {
+ obj->fullScreenChangeProxy = new EventListenerProxy
(obj->instance,
+
"FullScreenChange", value);
+ obj->fullScreenChangeProxy->AddHandler
(plugin->surface);
+ }
+
return true;
}
return false;
@@ -1464,7 +1495,7 @@
if (!element)
return true;
- MoonlightDependencyObjectObject *depobj =
DependencyObjectCreateWrapper (((MoonlightObject*)npobj)->instance, element);
+ MoonlightEventObjectObject *depobj = EventObjectCreateWrapper
(((MoonlightObject*)npobj)->instance, element);
OBJECT_TO_NPVARIANT (depobj, *result);
return true;
@@ -1483,8 +1514,8 @@
Type::Kind element_type;
DependencyObject *dep = xaml_create_from_str (xaml, false,
&element_type);
- MoonlightDependencyObjectObject *depobj =
- DependencyObjectCreateWrapper
(((MoonlightObject*)npobj)->instance, dep);
+ MoonlightEventObjectObject *depobj =
+ EventObjectCreateWrapper
(((MoonlightObject*)npobj)->instance, dep);
OBJECT_TO_NPVARIANT (depobj, *result);
@@ -1548,11 +1579,7 @@
static void
moonlight_dependency_object_invalidate (NPObject *npobj)
{
- MoonlightDependencyObjectObject *depobj =
(MoonlightDependencyObjectObject*)npobj;
-
- if (depobj->dob)
- depobj->dob->unref ();
- depobj->dob = NULL;
+ moonlight_event_object_invalidate (npobj);
}
static DependencyProperty*
@@ -1591,7 +1618,7 @@
if (obj->moonlight_type >= Type::DEPENDENCY_OBJECT ||
obj->moonlight_type == Type::INVALID) {
MoonlightDependencyObjectObject *depobj =
(MoonlightDependencyObjectObject*) NPVARIANT_TO_OBJECT (*value);
- dob->SetValue (p, Value(depobj->dob));
+ dob->SetValue (p, Value(depobj->GetDependencyObject
()));
return true;
}
@@ -1655,7 +1682,7 @@
static bool
moonlight_dependency_object_has_property (NPObject *npobj, NPIdentifier name)
{
- DependencyObject *dob = ((MoonlightDependencyObjectObject*)npobj)->dob;
+ DependencyObject *dob =
((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
strname[0] = toupper(strname[0]);
@@ -1668,7 +1695,7 @@
static bool
moonlight_dependency_object_get_property (NPObject *npobj, NPIdentifier name,
NPVariant *result)
{
- DependencyObject *dob = ((MoonlightDependencyObjectObject*)npobj)->dob;
+ DependencyObject *dob =
((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
strname[0] = toupper(strname[0]);
@@ -1696,7 +1723,7 @@
static bool
moonlight_dependency_object_set_property (NPObject *npobj, NPIdentifier name,
const NPVariant *value)
{
- DependencyObject *dob = ((MoonlightDependencyObjectObject*)npobj)->dob;
+ DependencyObject *dob =
((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
strname[0] = toupper(strname[0]);
@@ -1720,7 +1747,7 @@
const NPVariant *args, uint32_t argCount,
NPVariant *result)
{
- DependencyObject *dob = ((MoonlightDependencyObjectObject*)npobj)->dob;
+ DependencyObject *dob =
((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
if (name_matches (name, "setValue")) {
/* obj.setValue (prop, val) is another way of writing obj[prop]
= val (or obj.prop = val) */
@@ -1758,7 +1785,7 @@
if (!element)
return true;
- MoonlightDependencyObjectObject *depobj =
DependencyObjectCreateWrapper (((MoonlightObject*)npobj)->instance, element);
+ MoonlightEventObjectObject *depobj = EventObjectCreateWrapper
(((MoonlightObject*)npobj)->instance, element);
OBJECT_TO_NPVARIANT (depobj, *result);
return true;
@@ -1777,7 +1804,7 @@
else if (name_matches (name, "getParent")) {
DependencyObject *parent = dob->GetParent();
if (parent) {
- MoonlightDependencyObjectObject *depobj =
DependencyObjectCreateWrapper (((MoonlightObject*)npobj)->instance,
+ MoonlightEventObjectObject *depobj =
EventObjectCreateWrapper (((MoonlightObject*)npobj)->instance,
dob->GetParent());
OBJECT_TO_NPVARIANT (depobj, *result);
@@ -1864,12 +1891,83 @@
MoonlightDependencyObjectType* MoonlightDependencyObjectClass;
-MoonlightDependencyObjectObject*
-DependencyObjectCreateWrapper (NPP instance, DependencyObject *obj)
+/*** MoonlightEventObjectClass
***************************************************/
+
+static NPObject*
+moonlight_event_object_allocate (NPP instance, NPClass*)
{
+ return new MoonlightEventObjectObject (instance);
+}
+
+static void
+moonlight_event_object_deallocate (NPObject *npobj)
+{
+ delete (MoonlightEventObjectObject*)npobj;
+}
+
+static void
+moonlight_event_object_invalidate (NPObject *npobj)
+{
+ MoonlightEventObjectObject *eo = (MoonlightEventObjectObject*)npobj;
+
+ if (eo->eo)
+ eo->eo->unref ();
+ eo->eo = NULL;
+}
+
+static bool
+moonlight_event_object_has_property (NPObject *npobj, NPIdentifier name)
+{
+ return false;
+}
+
+static bool
+moonlight_event_object_has_method (NPObject *npobj, NPIdentifier name)
+{
+ return false;
+}
+
+static bool
+moonlight_event_object_get_property (NPObject *npobj, NPIdentifier name,
NPVariant *result)
+{
+ return false;
+}
+
+static bool
+moonlight_event_object_set_property (NPObject *npobj, NPIdentifier name, const
NPVariant *value)
+{
+ return false;
+}
+
+static bool
+moonlight_event_object_invoke (NPObject *npobj, NPIdentifier name,
+ const NPVariant *args, uint32_t argCount, NPVariant
*result)
+{
+ return false;
+}
+
+MoonlightEventObjectType::MoonlightEventObjectType ()
+{
+ allocate = moonlight_event_object_allocate;
+ deallocate = moonlight_event_object_deallocate;
+ invalidate = moonlight_event_object_invalidate;
+
+ hasProperty = moonlight_event_object_has_property;
+ setProperty = moonlight_event_object_set_property;
+ getProperty = moonlight_event_object_get_property;
+
+ hasMethod = moonlight_event_object_has_method;
+ invoke = moonlight_event_object_invoke;
+}
+
+MoonlightEventObjectType* MoonlightEventObjectClass;
+
+MoonlightEventObjectObject*
+EventObjectCreateWrapper (NPP instance, EventObject *obj)
+{
NPClass *np_class;
- /* for DependencyObject subclasses which have special plugin classes,
check here */
+ /* for EventObject subclasses which have special plugin classes, check
here */
if (Type::Find (obj->GetObjectType ())->IsSubclassOf (Type::COLLECTION))
np_class = MoonlightCollectionClass;
else {
@@ -1895,21 +1993,25 @@
case Type::TEXTBLOCK:
np_class = MoonlightTextBlockClass;
break;
+ case Type::EVENTOBJECT:
+ case Type::SURFACE:
+ np_class = MoonlightEventObjectClass;
+ break;
default:
np_class = MoonlightDependencyObjectClass;
}
}
- MoonlightDependencyObjectObject *depobj
- = (MoonlightDependencyObjectObject*)NPN_CreateObject (instance,
+ MoonlightEventObjectObject *depobj
+ = (MoonlightEventObjectObject*)NPN_CreateObject (instance,
np_class);
- depobj->SetDependencyObject (obj);
+ depobj->SetEventObject (obj);
/* do any post creation initialization here */
switch (obj->GetObjectType()) {
case Type::CONTROL:
- ((MoonlightControlObject *)depobj)->real_object =
DependencyObjectCreateWrapper (instance,
+ ((MoonlightControlObject *)depobj)->real_object =
EventObjectCreateWrapper (instance,
((Control*)obj)->real_object);
break;
default:
@@ -1951,7 +2053,7 @@
static bool
moonlight_collection_get_property (NPObject *npobj, NPIdentifier name,
NPVariant *result)
{
- Collection *col =
(Collection*)((MoonlightDependencyObjectObject*)npobj)->dob;
+ Collection *col =
(Collection*)((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
if (name_matches (name, "count")) {
INT32_TO_NPVARIANT (col->list->Length(), *result);
@@ -1977,14 +2079,14 @@
const NPVariant *args, uint32_t argCount,
NPVariant *result)
{
- Collection *col =
(Collection*)((MoonlightDependencyObjectObject*)npobj)->dob;
+ Collection *col =
(Collection*)((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
if (name_matches (name, "add")) {
if (argCount < 1)
return true;
MoonlightDependencyObjectObject *el =
(MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT (args[0]);
- col->Add (el->dob);
+ col->Add (el->GetDependencyObject ());
VOID_TO_NPVARIANT (*result);
@@ -1995,7 +2097,7 @@
return true;
MoonlightDependencyObjectObject *el =
(MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT (args[0]);
- col->Remove (el->dob);
+ col->Remove (el->GetDependencyObject ());
VOID_TO_NPVARIANT (*result);
@@ -2019,7 +2121,7 @@
int index = NPVARIANT_TO_INT32 (args[0]);
MoonlightDependencyObjectObject *el =
(MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT (args[1]);
- col->Insert (index, el->dob);
+ col->Insert (index, el->GetDependencyObject ());
VOID_TO_NPVARIANT (*result);
@@ -2046,7 +2148,7 @@
Collection::Node *n = (Collection::Node*)col->list->Index
(index);
- MoonlightDependencyObjectObject *depobj =
DependencyObjectCreateWrapper (((MoonlightObject*)npobj)->instance,
+ MoonlightEventObjectObject *depobj = EventObjectCreateWrapper
(((MoonlightObject*)npobj)->instance,
n->obj);
OBJECT_TO_NPVARIANT ((NPObject*)depobj, *result);
@@ -2097,7 +2199,7 @@
const NPVariant *args, uint32_t argCount,
NPVariant *result)
{
- Storyboard *sb =
(Storyboard*)((MoonlightDependencyObjectObject*)npobj)->dob;
+ Storyboard *sb =
(Storyboard*)((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
if (name_matches (name, "begin")) {
if (argCount != 0)
@@ -2190,7 +2292,7 @@
const NPVariant *args, uint32_t argCount,
NPVariant *result)
{
- MediaElement *media =
(MediaElement*)((MoonlightDependencyObjectObject*)npobj)->dob;
+ MediaElement *media =
(MediaElement*)((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject
();
if (name_matches (name, "play")) {
if (argCount != 0)
@@ -2228,7 +2330,7 @@
|| !NPVARIANT_IS_STRING (args[1]))
return true;
- DependencyObject *downloader =
((MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT(args[0]))->dob;
+ DependencyObject *downloader =
((MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT(args[0]))->GetDependencyObject
();
const char *part = NPVARIANT_TO_STRING (args[0]).utf8characters;
media->SetSource (downloader, part);
@@ -2273,7 +2375,7 @@
const NPVariant *args, uint32_t argCount,
NPVariant *result)
{
- Image *img = (Image*)((MoonlightDependencyObjectObject*)npobj)->dob;
+ Image *img =
(Image*)((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
if (name_matches (name, "setSource")) {
if (argCount != 2
@@ -2281,7 +2383,7 @@
|| !NPVARIANT_IS_STRING (args[1]))
return true;
- DependencyObject *downloader =
((MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT(args[0]))->dob;
+ DependencyObject *downloader =
((MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT(args[0]))->GetDependencyObject
();
const char *part = NPVARIANT_TO_STRING (args[1]).utf8characters;
img->SetSource (downloader, part);
@@ -2326,7 +2428,7 @@
const NPVariant *args, uint32_t argCount,
NPVariant *result)
{
- ImageBrush *img =
(ImageBrush*)((MoonlightDependencyObjectObject*)npobj)->dob;
+ ImageBrush *img =
(ImageBrush*)((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
if (name_matches (name, "setSource")) {
if (argCount != 2
@@ -2334,7 +2436,7 @@
|| !NPVARIANT_IS_STRING (args[1]))
return true;
- DependencyObject *downloader =
((MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT(args[0]))->dob;
+ DependencyObject *downloader =
((MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT(args[0]))->GetDependencyObject
();
const char *part = NPVARIANT_TO_STRING (args[1]).utf8characters;
img->SetSource (downloader, part);
@@ -2380,14 +2482,14 @@
const NPVariant *args, uint32_t argCount,
NPVariant *result)
{
- TextBlock *tb =
(TextBlock*)((MoonlightDependencyObjectObject*)npobj)->dob;
+ TextBlock *tb =
(TextBlock*)((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
if (name_matches (name, "setFontSource")) {
if (argCount != 1
|| !NPVARIANT_IS_OBJECT (args[0]))
return true;
- DependencyObject *downloader =
((MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT(args[0]))->dob;
+ DependencyObject *downloader =
((MoonlightDependencyObjectObject*)NPVARIANT_TO_OBJECT(args[0]))->GetDependencyObject
();
tb->SetFontSource (downloader);
@@ -2436,7 +2538,7 @@
static bool
moonlight_downloader_get_property (NPObject *npobj, NPIdentifier name,
NPVariant *result)
{
- Downloader *dl =
(Downloader*)((MoonlightDependencyObjectObject*)npobj)->dob;
+ Downloader *dl =
(Downloader*)((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
if (name_matches (name, "responseText")) {
uint64_t size;
@@ -2471,7 +2573,7 @@
const NPVariant *args, uint32_t argCount,
NPVariant *result)
{
- Downloader *dl =
(Downloader*)((MoonlightDependencyObjectObject*)npobj)->dob;
+ Downloader *dl =
(Downloader*)((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
if (name_matches (name, "abort")) {
if (argCount != 0)
@@ -2571,8 +2673,8 @@
moonlight_control_get_property (NPObject *npobj, NPIdentifier name, NPVariant
*result)
{
MoonlightControlObject *control = (MoonlightControlObject*)npobj;
- DependencyObject *dob =
((MoonlightDependencyObjectObject*)control)->dob;
- DependencyObject *real_object =
((MoonlightDependencyObjectObject*)control->real_object)->dob;
+ DependencyObject *dob =
((MoonlightDependencyObjectObject*)control)->GetDependencyObject ();
+ DependencyObject *real_object =
((MoonlightDependencyObjectObject*)control->real_object)->GetDependencyObject
();
DependencyProperty *p;
NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
@@ -2600,8 +2702,8 @@
moonlight_control_set_property (NPObject *npobj, NPIdentifier name, const
NPVariant *value)
{
MoonlightControlObject *control = (MoonlightControlObject*)npobj;
- DependencyObject *dob =
((MoonlightDependencyObjectObject*)control)->dob;
- DependencyObject *real_object =
((MoonlightDependencyObjectObject*)control->real_object)->dob;
+ DependencyObject *dob =
((MoonlightDependencyObjectObject*)control)->GetDependencyObject ();
+ DependencyObject *real_object =
((MoonlightDependencyObjectObject*)control->real_object)->GetDependencyObject
();
DependencyProperty *p;
NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
@@ -3243,6 +3345,7 @@
MoonlightCollectionClass = new MoonlightCollectionType ();
MoonlightContentClass = new MoonlightContentType ();
MoonlightControlClass = new MoonlightControlType ();
+ MoonlightEventObjectClass = new MoonlightEventObjectType ();
MoonlightDependencyObjectClass = new MoonlightDependencyObjectType ();
MoonlightDownloaderClass = new MoonlightDownloaderType ();
MoonlightErrorEventArgsClass = new MoonlightErrorEventArgsType ();
Modified: trunk/moon/plugin/plugin-class.h
===================================================================
--- trunk/moon/plugin/plugin-class.h 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/plugin/plugin-class.h 2007-08-29 15:08:03 UTC (rev 85000)
@@ -30,7 +30,7 @@
~EventListenerProxy ();
void AddHandler (EventObject *obj);
void RemoveHandler (EventObject *obj);
-
+ NPObject* GetCallbackAsNPObject ();
private:
NPP instance;
@@ -217,7 +217,8 @@
struct MoonlightContentObject : MoonlightObject {
MoonlightContentObject (NPP instance)
: MoonlightObject (instance),
- resizeProxy (NULL)
+ resizeProxy (NULL),
+ fullScreenChangeProxy (NULL)
{
registered_scriptable_objects = g_hash_table_new
(g_direct_hash, g_direct_equal);
}
@@ -225,6 +226,7 @@
GHashTable *registered_scriptable_objects;
EventListenerProxy *resizeProxy;
+ EventListenerProxy *fullScreenChangeProxy;
};
extern MoonlightContentType* MoonlightContentClass;
@@ -247,29 +249,55 @@
NPObject *settings;
};
+/*** MoonlightEventObjectClass
***************************************************/
+struct MoonlightEventObjectType : MoonlightObjectType {
+ MoonlightEventObjectType ();
+};
+extern MoonlightEventObjectType *MoonlightEventObjectClass;
+
+struct MoonlightEventObjectObject : public MoonlightObject
+{
+ MoonlightEventObjectObject (NPP instance) : MoonlightObject (instance)
+ {
+ eo = NULL;
+ moonlight_type = Type::EVENTOBJECT;
+ }
+
+ void SetEventObject (EventObject *eo)
+ {
+ this->eo = eo;
+ if (eo)
+ eo->ref ();
+ }
+
+ EventObject *eo;
+};
+static void moonlight_event_object_invalidate (NPObject *npobj);
+extern MoonlightEventObjectObject* EventObjectCreateWrapper (NPP instance,
EventObject *obj);
+
/*** MoonlightDependencyObjectClass
***************************************************/
-
-struct MoonlightDependencyObjectType : MoonlightObjectType {
+struct MoonlightDependencyObjectType : MoonlightEventObjectType {
MoonlightDependencyObjectType ();
};
extern MoonlightDependencyObjectType *MoonlightDependencyObjectClass;
-struct MoonlightDependencyObjectObject : public MoonlightObject
+struct MoonlightDependencyObjectObject : public MoonlightEventObjectObject
{
- MoonlightDependencyObjectObject (NPP instance) : MoonlightObject
(instance)
+ MoonlightDependencyObjectObject (NPP instance) :
MoonlightEventObjectObject (instance)
{
- dob = NULL;
moonlight_type = Type::DEPENDENCY_OBJECT;
}
void SetDependencyObject (DependencyObject *dob)
{
- this->dob = dob;
- if (dob)
- dob->ref ();
+ SetEventObject (dob);
}
-
- DependencyObject *dob;
+
+ DependencyObject* GetDependencyObject ()
+ {
+ g_assert (eo->GetObjectType () >= Type::DEPENDENCY_OBJECT);
+ return (DependencyObject*) eo;
+ }
};
extern MoonlightDependencyObjectObject* DependencyObjectCreateWrapper (NPP
instance, DependencyObject *obj);
Modified: trunk/moon/plugin/plugin.cpp
===================================================================
--- trunk/moon/plugin/plugin.cpp 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/plugin/plugin.cpp 2007-08-29 15:08:03 UTC (rev 85000)
@@ -152,7 +152,7 @@
fprintf (stderr, "Destroying the plugin: %p\n", surface);
if (surface != NULL){
//gdk_error_trap_push ();
- delete surface;
+ surface->unref ();
//gdk_display_sync (this->display);
//gdk_error_trap_pop ();
}
@@ -358,7 +358,7 @@
DependencyObject *toplevel = surface->GetToplevel ();
DEBUGMSG ("In JsRunOnload, toplevel = %p", toplevel);
- MoonlightDependencyObjectObject *depobj = DependencyObjectCreateWrapper
(instance, toplevel);
+ MoonlightEventObjectObject *depobj = EventObjectCreateWrapper
(instance, toplevel);
OBJECT_TO_NPVARIANT ((NPObject*)depobj, args[0]);
if (NPN_Invoke (instance, object, NPID (expression),
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/ChangeLog 2007-08-29 15:08:03 UTC (rev 85000)
@@ -1,3 +1,15 @@
+2007-08-29 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
+
+ * clock.h: Implement TimeManager::GetObjectType.
+ * dependencyobject.h, dependencyobject.cpp: Move all type management
down to
+ Base (GetObjectType, Is, GetType, GetTypeName), and implement
+ GetObjectType in the classes that don't do it already. Remove
+ BASE_FLOATS, simplifying ref counting.
+ * type.cpp.in, type.h, type.cpp, type.h.in: Added Base and inherited
classes
+ that don't already inherit from DependencyObject.
+ * runtime.h, runtime.cpp: Add the Fullscreen API (not implemented yet,
only
+ raises events), and implement GetObjectType.
+
2007-08-28 Sebastien Pouliot <[EMAIL PROTECTED]>
* shape.cpp: Fix StretchUniformToFill
Modified: trunk/moon/src/clock.h
===================================================================
--- trunk/moon/src/clock.h 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/clock.h 2007-08-29 15:08:03 UTC (rev 85000)
@@ -194,6 +194,8 @@
int UpdateInputEvent;
int RenderEvent;
+ virtual Type::Kind GetObjectType () { return Type::TIMEMANAGER; };
+
private:
TimeManager ();
Modified: trunk/moon/src/dependencyobject.cpp
===================================================================
--- trunk/moon/src/dependencyobject.cpp 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/dependencyobject.cpp 2007-08-29 15:08:03 UTC (rev 85000)
@@ -22,33 +22,27 @@
void
Base::ref ()
{
- if (refcount & BASE_FLOATS)
- refcount = 1;
- else
- refcount++;
+ refcount++;
#if DEBUG_REFCNT
- printf ("refcount++ %p (%s), refcnt = %d\n", this,
- Type::Find (((DependencyObject *) this)->GetObjectType
())->name, refcount);
+ printf ("refcount++ %p (%s), refcnt = %d\n", this, GetTypeName (),
refcount);
#endif
}
void
Base::unref ()
{
- if (refcount == BASE_FLOATS || refcount == 1) {
+ refcount--;
+
#if DEBUG_REFCNT
- printf ("destroying object %p (%s)\n", this,
- Type::Find (((DependencyObject *) this)->GetObjectType
())->name);
+ printf ("refcount-- %p (%s), refcnt = %d\n", this, GetTypeName
(), refcount);
#endif
- delete this;
- } else {
- refcount--;
+
+ if (refcount == 0) {
#if DEBUG_REFCNT
- printf ("refcount-- %p (%s), refcnt = %d\n", this,
- Type::Find (((DependencyObject *) this)->GetObjectType
())->name,
- refcount);
+ printf ("destroying object %p (%s)\n", this, GetTypeName ());
#endif
+ delete this;
}
}
Modified: trunk/moon/src/dependencyobject.h
===================================================================
--- trunk/moon/src/dependencyobject.h 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/dependencyobject.h 2007-08-29 15:08:03 UTC (rev 85000)
@@ -19,17 +19,42 @@
//
// This guy provide reference counting
-//
-#define BASE_FLOATS 0x80000000
+// and type management.
+//
+// An object starts out with a reference
+// count of 1 (no need to ref it after
+// creation), and will be deleted once
+// the count reaches 0.
class Base {
public:
guint32 refcount;
- Base () : refcount(BASE_FLOATS) { }
+ Base () : refcount(1) { }
virtual ~Base () { }
void ref ();
void unref ();
+
+ virtual Type::Kind GetObjectType () = 0;
+
+ //
+ // Is:
+ // Similar to C#'s is: it checks if this object is of this kind or
+ // a derived class.
+
+ bool Is(Type::Kind k) {
+ return GetType ()->IsSubclassOf (k);
+ };
+
+ Type *GetType ()
+ {
+ return Type::Find (GetObjectType ());
+ }
+
+ char *GetTypeName ()
+ {
+ return Type::Find (GetObjectType ())->name;
+ }
};
class EventObject : public Base {
@@ -43,6 +68,8 @@
void AddHandler (int event_id, EventHandler handler, gpointer data);
void RemoveHandler (int event_id, EventHandler handler, gpointer data);
+ virtual Type::Kind GetObjectType () { return Type::EVENTOBJECT; }
+
protected:
int RegisterEvent (const char *event_name);
void Emit (char *event_name, gpointer calldata = NULL);
@@ -104,15 +131,6 @@
virtual void OnCollectionChanged (Collection *col, CollectionChangeType
type, DependencyObject *obj, DependencyProperty *prop) { }
virtual Type::Kind GetObjectType ();
- Type *GetType ()
- {
- return Type::Find (GetObjectType ());
- }
-
- char *GetTypeName ()
- {
- return Type::Find (GetObjectType ())->name;
- }
const char *GetName ()
{
@@ -123,15 +141,6 @@
void SetParent (DependencyObject *parent);
DependencyObject* GetParent ();
- //
- // Is:
- // Similar to C#'s is: it checks if this object is of this kind or
- // a derived class.
-
- bool Is(Type::Kind k) {
- return GetType ()->IsSubclassOf (k);
- };
-
static void Shutdown ();
void Attach (DependencyProperty *property, DependencyObject *container);
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/runtime.cpp 2007-08-29 15:08:03 UTC (rev 85000)
@@ -113,6 +113,7 @@
capture_element = NULL;
ResizeEvent = RegisterEvent ("Resize");
+ FullScreenChangeEvent = RegisterEvent ("FullScreenChange");
Realloc ();
}
@@ -377,6 +378,33 @@
}
void
+Surface::SetFullScreen (bool value)
+{
+ if (value && !can_full_screen) {
+ g_warning ("You're not allowed to switch to fullscreen from
where you're doing it.");
+ return;
+ }
+
+ UpdateFullScreen (value);
+
+}
+
+void
+Surface::UpdateFullScreen (bool value)
+{
+ if (value == full_screen)
+ return;
+
+ if (value) {
+ g_warning ("Fullscreen mode not implemented yet.");
+ } else {
+ g_warning ("Fullscreen mode not implemented yet.");
+ }
+ full_screen = value;
+ Emit (FullScreenChangeEvent);
+}
+
+void
Surface::render_cb (EventObject *sender, gpointer calldata, gpointer closure)
{
Surface *s = (Surface*)closure;
@@ -669,17 +697,38 @@
}
}
+bool
+Surface::FullScreenKeyHandled (GdkEventKey *key)
+{
+ if (!GetFullScreen ())
+ return false;
+
+ // If we're in fullscreen mode no key events are passed through.
+ // We only handle Esc, to exit fullscreen mode.
+ if (key->keyval == GDK_Escape) {
+ SetFullScreen (false);
+ }
+ return true;
+}
+
gboolean
Surface::key_press_callback (GtkWidget *widget, GdkEventKey *key, gpointer
data)
{
Surface *s = (Surface *) data;
+ if (s->FullScreenKeyHandled (key))
+ return TRUE;
+
+ s->SetCanFullScreen (true);
//
// I could not write a test that would send the output elsewhere, for
now
// just send to the toplevel
//
s->toplevel->HandleKeyDown (s->cairo,
key->state, gdk_keyval_to_key
(key->keyval), key->hardware_keycode);
+
+ s->SetCanFullScreen (false);
+
return TRUE;
}
@@ -688,12 +737,20 @@
{
Surface *s = (Surface *) data;
+ if (s->FullScreenKeyHandled (key))
+ return TRUE;
+
+ s->SetCanFullScreen (true);
+
//
// I could not write a test that would send the output elsewhere, for
now
// just send to the toplevel
//
s->toplevel->HandleKeyUp (s->cairo,
key->state, gdk_keyval_to_key
(key->keyval), key->hardware_keycode);
+
+ s->SetCanFullScreen (false);
+
return TRUE;
}
@@ -705,6 +762,8 @@
if (button->button != 1)
return FALSE;
+ s->SetCanFullScreen (true);
+
double x = button->x;
double y = button->y;
if (GTK_WIDGET_NO_WINDOW (widget)){
@@ -714,6 +773,8 @@
UIElement *input_element = s->capture_element ? s->capture_element :
s->toplevel;
input_element->HandleButtonRelease (s->cairo, button->state, x, y);
+ s->SetCanFullScreen (false);
+
return TRUE;
}
@@ -727,6 +788,8 @@
if (button->button != 1)
return FALSE;
+ s->SetCanFullScreen (true);
+
double x = button->x;
double y = button->y;
if (GTK_WIDGET_NO_WINDOW (widget)){
@@ -736,6 +799,8 @@
UIElement *input_element = s->capture_element ? s->capture_element :
s->toplevel;
input_element->HandleButtonPress (s->cairo, button->state, x, y);
+ s->SetCanFullScreen (false);
+
return FALSE;
}
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/runtime.h 2007-08-29 15:08:03 UTC (rev 85000)
@@ -71,7 +71,14 @@
UIElement* GetCapturedElement () { return capture_element; }
int ResizeEvent;
-
+ int FullScreenChangeEvent;
+
+ bool GetFullScreen () { return full_screen; }
+ void SetFullScreen (bool value);
+ void SetCanFullScreen (bool value) { can_full_screen = value; }
+ bool FullScreenKeyHandled (GdkEventKey *key);
+
+ virtual Type::Kind GetObjectType () { return Type::SURFACE; };
private:
int width, height;
@@ -114,6 +121,13 @@
// the currently shown cursor
MouseCursor cursor;
+ // Fullscreen support
+ bool full_screen;
+ // Should be set to true only while executing MouseLeftButtonDown,
+ // MouseLeftButtonUp, KeyDown, and KeyUp event handlers
+ bool can_full_screen;
+ void UpdateFullScreen (bool value);
+
int frames;
int last_event_state;
Modified: trunk/moon/src/type.cpp
===================================================================
--- trunk/moon/src/type.cpp 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/type.cpp 2007-08-29 15:08:03 UTC (rev 85000)
@@ -163,6 +163,10 @@
Type::RegisterType ("Point*", Type::POINT_ARRAY, false);
Type::RegisterType ("Matrix", Type::MATRIX, true);
Type::RegisterType ("NPObj", Type::NPOBJ, false);
+ Type::RegisterType ("Base", Type::BASE, false);
+ Type::RegisterType ("EventObject", Type::EVENTOBJECT, Type::BASE);
+ Type::RegisterType ("TimeManager", Type::TIMEMANAGER,
Type::EVENTOBJECT);
+ Type::RegisterType ("Surface", Type::SURFACE, Type::EVENTOBJECT);
#if DEBUG
for (int i = 1; i < Type::LASTTYPE; i++) {
if (Type::types [i] != NULL)
Modified: trunk/moon/src/type.cpp.in
===================================================================
--- trunk/moon/src/type.cpp.in 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/type.cpp.in 2007-08-29 15:08:03 UTC (rev 85000)
@@ -158,6 +158,10 @@
Type::RegisterType ("Point*", Type::POINT_ARRAY, false);
Type::RegisterType ("Matrix", Type::MATRIX, true);
Type::RegisterType ("NPObj", Type::NPOBJ, false);
+ Type::RegisterType ("Base", Type::BASE, false);
+ Type::RegisterType ("EventObject", Type::EVENTOBJECT, Type::BASE);
+ Type::RegisterType ("TimeManager", Type::TIMEMANAGER,
Type::EVENTOBJECT);
+ Type::RegisterType ("Surface", Type::SURFACE, Type::EVENTOBJECT);
#if DEBUG
for (int i = 1; i < Type::LASTTYPE; i++) {
if (Type::types [i] != NULL)
Modified: trunk/moon/src/type.h
===================================================================
--- trunk/moon/src/type.h 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/type.h 2007-08-29 15:08:03 UTC (rev 85000)
@@ -44,6 +44,10 @@
KEYTIME,
MATRIX,
NPOBJ,
+ BASE,
+ EVENTOBJECT,
+ SURFACE,
+ TIMEMANAGER,
DEPENDENCY_OBJECT,
ANIMATION,
Modified: trunk/moon/src/type.h.in
===================================================================
--- trunk/moon/src/type.h.in 2007-08-29 14:44:07 UTC (rev 84999)
+++ trunk/moon/src/type.h.in 2007-08-29 15:08:03 UTC (rev 85000)
@@ -40,6 +40,10 @@
KEYTIME,
MATRIX,
NPOBJ,
+ BASE,
+ EVENTOBJECT,
+ SURFACE,
+ TIMEMANAGER,
/*DO_KINDS*/
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches