]> git.sesse.net Git - vlc/commitdiff
mozilla plugin: Bring marquee interface in line with logo.
authorJP Dinger <jpd@m2x.nl>
Tue, 19 Jan 2010 16:47:31 +0000 (17:47 +0100)
committerJP Dinger <jpd@m2x.nl>
Tue, 19 Jan 2010 16:53:20 +0000 (17:53 +0100)
projects/mozilla/control/npolibvlc.cpp
projects/mozilla/control/position.h [new file with mode: 0644]
projects/mozilla/test.html

index 8b840835fbdadf8b68cc598af7db4e0ab409cbd2..c75694d3d58508fb338a5c517db01f06ed3c224d 100644 (file)
@@ -36,6 +36,8 @@
 #include "vlcplugin.h"
 #include "npolibvlc.h"
 
+#include "position.h"
+
 /*
 ** Local helper macros and function
 */
@@ -1562,29 +1564,90 @@ LibvlcVideoNPObject::invoke(int index, const NPVariant *args,
 
 const NPUTF8 * const LibvlcMarqueeNPObject::propertyNames[] =
 {
+    "color",
+    "opacity",
+    "position",
+    "refresh",
+    "size",
+    "text",
+    "timeout",
+    "x",
+    "y",
 };
 
 enum LibvlcMarqueeNPObjectPropertyIds
 {
+    ID_marquee_color,
+    ID_marquee_opacity,
+    ID_marquee_position,
+    ID_marquee_refresh,
+    ID_marquee_size,
+    ID_marquee_text,
+    ID_marquee_timeout,
+    ID_marquee_x,
+    ID_marquee_y,
 };
+
 COUNTNAMES(LibvlcMarqueeNPObject,propertyCount,propertyNames);
 
+static const unsigned char marquee_idx[] = {
+    libvlc_marquee_Color,
+    libvlc_marquee_Opacity,
+    libvlc_marquee_Position,
+    libvlc_marquee_Refresh,
+    libvlc_marquee_Size,
+    0,
+    libvlc_marquee_Timeout,
+    libvlc_marquee_X,
+    libvlc_marquee_Y,
+};
+
 RuntimeNPObject::InvokeResult
 LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
 {
-    /* is plugin still running */
-    if( isPluginRunning() )
+    char *psz;
+
+    if( !isPluginRunning() )
+        return INVOKERESULT_GENERIC_ERROR;
+
+    VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
+    libvlc_exception_t ex;
+    libvlc_exception_init(&ex);
+
+    libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
+    RETURN_ON_EXCEPTION(this,ex);
+
+    switch( index )
     {
-        VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
-        libvlc_exception_t ex;
-        libvlc_exception_init(&ex);
+    case ID_marquee_color:
+    case ID_marquee_opacity:
+    case ID_marquee_refresh:
+    case ID_marquee_timeout:
+    case ID_marquee_size:
+    case ID_marquee_x:
+    case ID_marquee_y:
+        INT32_TO_NPVARIANT(
+            libvlc_video_get_marquee_int(p_md, marquee_idx[index], &ex),
+            result );
+        RETURN_ON_EXCEPTION(this,ex);
+        return INVOKERESULT_NO_ERROR;
+
+    case ID_marquee_position:
+        STRINGZ_TO_NPVARIANT( position_bynumber(
+            libvlc_video_get_marquee_int(p_md, libvlc_marquee_Position, &ex) ),
+            result );
 
-        libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
         RETURN_ON_EXCEPTION(this,ex);
+        break;
 
-        switch( index )
+    case ID_marquee_text:
+        psz = libvlc_video_get_marquee_string(p_md, libvlc_marquee_Text, &ex);
+        if( psz )
         {
+            STRINGZ_TO_NPVARIANT(psz, result);
+            return INVOKERESULT_NO_ERROR;
         }
+        break;
     }
     return INVOKERESULT_GENERIC_ERROR;
 }
@@ -1592,36 +1655,62 @@ LibvlcMarqueeNPObject::getProperty(int index, NPVariant &result)
 RuntimeNPObject::InvokeResult
 LibvlcMarqueeNPObject::setProperty(int index, const NPVariant &value)
 {
-    /* is plugin still running */
-    if( isPluginRunning() )
+    size_t i;
+
+    if( !isPluginRunning() )
+        return INVOKERESULT_GENERIC_ERROR;
+
+    VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
+    libvlc_exception_t ex;
+    libvlc_exception_init(&ex);
+    libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
+    RETURN_ON_EXCEPTION(this,ex);
+
+    switch( index )
     {
-        VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
-        libvlc_exception_t ex;
-        libvlc_exception_init(&ex);
+    case ID_marquee_color:
+    case ID_marquee_opacity:
+    case ID_marquee_refresh:
+    case ID_marquee_timeout:
+    case ID_marquee_x:
+    case ID_marquee_y:
+        if( NPVARIANT_IS_INT32( value ) )
+        {
+            libvlc_video_set_marquee_int(p_md, marquee_idx[index],
+                                         NPVARIANT_TO_INT32( value ), &ex);
+            RETURN_ON_EXCEPTION(this,ex);
+            return INVOKERESULT_NO_ERROR;
+        }
+        break;
 
-        libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
+    case ID_marquee_position:
+        if( !NPVARIANT_IS_STRING(value) ||
+            !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
+            return INVOKERESULT_INVALID_VALUE;
+
+        libvlc_video_set_marquee_int(p_md, libvlc_marquee_Position, i, &ex);
         RETURN_ON_EXCEPTION(this,ex);
+        return INVOKERESULT_NO_ERROR;
 
-        switch( index )
+    case ID_marquee_text:
+        if( NPVARIANT_IS_STRING( value ) )
         {
+            char *psz_text = stringValue( NPVARIANT_TO_STRING( value ) );
+            libvlc_video_set_marquee_string(p_md, libvlc_marquee_Text,
+                                            psz_text, &ex);
+            free(psz_text);
+            RETURN_ON_EXCEPTION(this,ex);
+            return INVOKERESULT_NO_ERROR;
         }
+        break;
     }
-    return INVOKERESULT_GENERIC_ERROR;
+    return INVOKERESULT_NO_SUCH_METHOD;
 }
 
 const NPUTF8 * const LibvlcMarqueeNPObject::methodNames[] =
 {
     "enable",
     "disable",
-    "color",
-    "opacity",
-    "position",
-    "refresh",
-    "size",
-    "text",
-    "timeout",
-    "x",
-    "y"
 };
 COUNTNAMES(LibvlcMarqueeNPObject,methodCount,methodNames);
 
@@ -1629,195 +1718,33 @@ enum LibvlcMarqueeNPObjectMethodIds
 {
     ID_marquee_enable,
     ID_marquee_disable,
-    ID_marquee_color,
-    ID_marquee_opacity,
-    ID_marquee_position,
-    ID_marquee_refresh,
-    ID_marquee_size,
-    ID_marquee_text,
-    ID_marquee_timeout,
-    ID_marquee_x,
-    ID_marquee_y
 };
 
 RuntimeNPObject::InvokeResult
 LibvlcMarqueeNPObject::invoke(int index, const NPVariant *args,
                             uint32_t argCount, NPVariant &result)
 {
-    /* is plugin still running */
-    if( isPluginRunning() )
-    {
-        VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
-        libvlc_exception_t ex;
-        libvlc_exception_init(&ex);
+    if( !isPluginRunning() )
+        return INVOKERESULT_GENERIC_ERROR;
 
-        libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
-        RETURN_ON_EXCEPTION(this,ex);
+    VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
+    libvlc_exception_t ex;
+    libvlc_exception_init(&ex);
 
-        switch( index )
-        {
-            case ID_marquee_enable:
-            {
-                libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, true, &ex);
-                    RETURN_ON_EXCEPTION(this,ex);
-                return INVOKERESULT_NO_ERROR;
-            }
-            case ID_marquee_disable:
-            {
-                libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Enabled, false, &ex);
-                    RETURN_ON_EXCEPTION(this,ex);
-                return INVOKERESULT_NO_ERROR;
-            }
-            case ID_marquee_color:
-            {
-                if( argCount == 1)
-                {
-                    if( NPVARIANT_IS_INT32( args[0] ) )
-                    {
-                        int i_color = NPVARIANT_TO_INT32( args[0] );
-                        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Color, i_color, &ex);
-                            RETURN_ON_EXCEPTION(this,ex);
-                        return INVOKERESULT_NO_ERROR;
-                    }
-                    else
-                        return INVOKERESULT_GENERIC_ERROR;
-                }
-                return INVOKERESULT_NO_SUCH_METHOD;
-            }
-            case ID_marquee_opacity:
-            {
-                if( argCount == 1)
-                {
-                    if( NPVARIANT_IS_INT32( args[0] ) )
-                    {
-                        int i_opacity = NPVARIANT_TO_INT32( args[0] );
-                        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Opacity, i_opacity, &ex);
-                            RETURN_ON_EXCEPTION(this,ex);
-                        return INVOKERESULT_NO_ERROR;
-                    }
-                    else
-                        return INVOKERESULT_GENERIC_ERROR;
-                }
-                return INVOKERESULT_NO_SUCH_METHOD;
-            }
-            case ID_marquee_position:
-            {
-                if( argCount == 1)
-                {
-                    if( NPVARIANT_IS_INT32( args[0] ) )
-                    {
-                        int i_position = NPVARIANT_TO_INT32( args[0] );
-                        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Position, i_position, &ex);
-                            RETURN_ON_EXCEPTION(this,ex);
-                        return INVOKERESULT_NO_ERROR;
-                    }
-                    else
-                        return INVOKERESULT_GENERIC_ERROR;
-                }
-                return INVOKERESULT_NO_SUCH_METHOD;
-            }
-            case ID_marquee_refresh:
-            {
-                if( argCount == 1)
-                {
-                    if( NPVARIANT_IS_INT32( args[0] ) )
-                    {
-                        int i_refresh = NPVARIANT_TO_INT32( args[0] );
-                        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Refresh, i_refresh, &ex);
-                            RETURN_ON_EXCEPTION(this,ex);
-                        return INVOKERESULT_NO_ERROR;
-                    }
-                    else
-                        return INVOKERESULT_GENERIC_ERROR;
-                }
-                return INVOKERESULT_NO_SUCH_METHOD;
-            }
-            case ID_marquee_size:
-            {
-                if( argCount == 1)
-                {
-                    if( NPVARIANT_IS_INT32( args[0] ) )
-                    {
-                        int i_size = NPVARIANT_TO_INT32( args[0] );
-                        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Size, i_size, &ex);
-                            RETURN_ON_EXCEPTION(this,ex);
-                        return INVOKERESULT_NO_ERROR;
-                    }
-                    else
-                        return INVOKERESULT_GENERIC_ERROR;
-                }
-                return INVOKERESULT_NO_SUCH_METHOD;
-            }
-            case ID_marquee_text:
-            {
-                if( argCount == 1)
-                {
-                    if( NPVARIANT_IS_STRING( args[0] ) )
-                    {
-                        char *psz_text = stringValue( NPVARIANT_TO_STRING( args[0] ) );
-                        libvlc_video_set_marquee_option_as_string(p_md, libvlc_marquee_Text, psz_text, &ex);
-                            RETURN_ON_EXCEPTION(this,ex);
-                        free(psz_text);
-                        return INVOKERESULT_NO_ERROR;
-                    }
-                    else
-                        return INVOKERESULT_GENERIC_ERROR;
-                }
-                return INVOKERESULT_NO_SUCH_METHOD;
-            }
-            case ID_marquee_timeout:
-            {
-                if( argCount == 1)
-                {
-                    if( NPVARIANT_IS_INT32( args[0] ) )
-                    {
-                        int i_timeout = NPVARIANT_TO_INT32( args[0] );
-                        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Timeout, i_timeout, &ex);
-                            RETURN_ON_EXCEPTION(this,ex);
-                        return INVOKERESULT_NO_ERROR;
-                    }
-                    else
-                        return INVOKERESULT_GENERIC_ERROR;
-                }
-                return INVOKERESULT_NO_SUCH_METHOD;
-            }
-            case ID_marquee_x:
-            {
-                if( argCount == 1)
-                {
-                    if( NPVARIANT_IS_INT32( args[0] ) )
-                    {
-                        int i_x = NPVARIANT_TO_INT32( args[0] );
-                        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_X, i_x, &ex);
-                            RETURN_ON_EXCEPTION(this,ex);
-                        return INVOKERESULT_NO_ERROR;
-                    }
-                    else
-                        return INVOKERESULT_GENERIC_ERROR;
-                }
-                return INVOKERESULT_NO_SUCH_METHOD;
-            }
-            case ID_marquee_y:
-            {
-                if( argCount == 1)
-                {
-                    if( NPVARIANT_IS_INT32( args[0] ) )
-                    {
-                        int i_y = NPVARIANT_TO_INT32( args[0] );
-                        libvlc_video_set_marquee_option_as_int(p_md, libvlc_marquee_Y, i_y, &ex);
-                            RETURN_ON_EXCEPTION(this,ex);
-                        return INVOKERESULT_NO_ERROR;
-                    }
-                    else
-                        return INVOKERESULT_GENERIC_ERROR;
-                }
-                return INVOKERESULT_NO_SUCH_METHOD;
-            }
-            default:
-                return INVOKERESULT_NO_SUCH_METHOD;
-        }
+    libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
+    RETURN_ON_EXCEPTION(this,ex);
+
+    switch( index )
+    {
+    case ID_marquee_enable:
+    case ID_marquee_disable:
+        libvlc_video_set_marquee_int(p_md, libvlc_marquee_Enable,
+                                     index!=ID_marquee_disable, &ex);
+        RETURN_ON_EXCEPTION(this,ex);
+        VOID_TO_NPVARIANT(result);
+        return INVOKERESULT_NO_ERROR;
     }
-    return INVOKERESULT_GENERIC_ERROR;
+    return INVOKERESULT_NO_SUCH_METHOD;
 }
 
 const NPUTF8 * const LibvlcLogoNPObject::propertyNames[] = {
@@ -1846,36 +1773,6 @@ static const unsigned char logo_idx[] = {
     libvlc_logo_y,
 };
 
-struct posidx_s { const char *n; size_t i; };
-static const posidx_s posidx[] = {
-    { "center",        0 },
-    { "left",          1 },
-    { "right",         2 },
-    { "top",           4 },
-    { "bottom",        8 },
-    { "top-left",      5 },
-    { "top-right",     6 },
-    { "bottom-left",   9 },
-    { "bottom-right", 10 },
-};
-enum { num_posidx = sizeof(posidx)/sizeof(*posidx) };
-
-static inline const char *logo_numtopos( size_t i )
-{
-    for( const posidx_s *h=posidx; h<posidx+num_posidx; ++h )
-        if( h->i == i )
-            return h->n;
-    return "undefined";
-}
-
-static inline bool logo_postonum( const char *n, size_t &i )
-{
-    for( const posidx_s *h=posidx; h<posidx+num_posidx; ++h )
-        if( !strcasecmp( n, h->n ) )
-            { i=h->i; return true; }
-    return false;
-}
-
 RuntimeNPObject::InvokeResult
 LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
 {
@@ -1903,7 +1800,7 @@ LibvlcLogoNPObject::getProperty(int index, NPVariant &result)
         break;
 
     case ID_logo_position:
-        STRINGZ_TO_NPVARIANT( logo_numtopos(
+        STRINGZ_TO_NPVARIANT( position_bynumber(
             libvlc_video_get_logo_int(p_md, libvlc_logo_position, &ex) ),
             result );
 
@@ -1948,7 +1845,7 @@ LibvlcLogoNPObject::setProperty(int index, const NPVariant &value)
 
     case ID_logo_position:
         if( !NPVARIANT_IS_STRING(value) ||
-            !logo_postonum( NPVARIANT_TO_STRING(value).utf8characters, i ) )
+            !position_byname( NPVARIANT_TO_STRING(value).utf8characters, i ) )
             return INVOKERESULT_INVALID_VALUE;
 
         libvlc_video_set_logo_int(p_md, libvlc_logo_position, i, &ex);
diff --git a/projects/mozilla/control/position.h b/projects/mozilla/control/position.h
new file mode 100644 (file)
index 0000000..ec1c7f8
--- /dev/null
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ * position.h: Support routines for logo and marquee plugin objects
+ *****************************************************************************
+ * Copyright (C) 2010 M2X BV
+ *
+ * Authors: JP Dinger <jpd (at) videolan (dot) org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef POSITION_H
+#define POSITION_H
+
+struct posidx_s { const char *n; size_t i; };
+static const posidx_s posidx[] = {
+    { "center",        0 },
+    { "left",          1 },
+    { "right",         2 },
+    { "top",           4 },
+    { "bottom",        8 },
+    { "top-left",      5 },
+    { "top-right",     6 },
+    { "bottom-left",   9 },
+    { "bottom-right", 10 },
+};
+enum { num_posidx = sizeof(posidx)/sizeof(*posidx) };
+
+static inline const char *position_bynumber( size_t i )
+{
+    for( const posidx_s *h=posidx; h<posidx+num_posidx; ++h )
+        if( h->i == i )
+            return h->n;
+    return "undefined";
+}
+
+static inline bool position_byname( const char *n, size_t &i )
+{
+    for( const posidx_s *h=posidx; h<posidx+num_posidx; ++h )
+        if( !strcasecmp( n, h->n ) )
+            { i=h->i; return true; }
+    return false;
+}
+#endif
index 9c3c3235755adc250523fdf764274b243e98d20d..0d5d19cf89886a0b84c80d773d6bd3fcfe3e9d0a 100644 (file)
@@ -761,23 +761,23 @@ function doMarqueeOption(option, value)
     if( vlc )\r
     {\r
         if (option == 1)\r
-            vlc.video.marquee.color(val);\r
+            vlc.video.marquee.color = val;\r
         if (option == 2)\r
-            vlc.video.marquee.opacity(val);\r
+            vlc.video.marquee.opacity = val;\r
         if (option == 3)\r
-            vlc.video.marquee.position(val);\r
+            vlc.video.marquee.position = value;\r
         if (option == 4)\r
-            vlc.video.marquee.refresh(val);\r
+            vlc.video.marquee.refresh = val;\r
         if (option == 5)\r
-            vlc.video.marquee.size(val);\r
+            vlc.video.marquee.size = val;\r
         if (option == 6)\r
-            vlc.video.marquee.text(value);\r
+            vlc.video.marquee.text = value;\r
         if (option == 7)\r
-            vlc.video.marquee.timeout(val);\r
+            vlc.video.marquee.timeout = val;\r
         if (option == 8)\r
-            vlc.video.marquee.x(val);\r
+            vlc.video.marquee.x = val;\r
         if (option == 9)\r
-            vlc.video.marquee.y(val);\r
+            vlc.video.marquee.y = val;\r
     }\r
 }\r