]> git.sesse.net Git - vlc/blobdiff - mozilla/vlcshell.cpp
Removes trailing spaces. Removes tabs.
[vlc] / mozilla / vlcshell.cpp
index 039a40d79a6da971b79b24c92a0161000634087e..94df4df8d7cdc7cfd84269a11dca8a52893b447b 100644 (file)
@@ -99,7 +99,7 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
 
         default:
             /* move on to instance variables ... */
-            break;
+            ;
     }
 
     if( instance == NULL )
@@ -119,18 +119,32 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
     switch( variable )
     {
         case NPPVpluginScriptableNPObject:
-            /* create an instance and return it */
-            *(NPObject**)value = NPN_CreateObject(instance, p_plugin->getScriptClass());
-            if( NULL == *(NPObject**)value )
+        {
+            /* retrieve plugin root class */
+            NPClass *scriptClass = p_plugin->getScriptClass();
+            if( scriptClass )
             {
-                return NPERR_OUT_OF_MEMORY_ERROR;
+                /* create an instance and return it */
+                *(NPObject**)value = NPN_CreateObject(instance, scriptClass);
+                return NPERR_NO_ERROR;
             }
             break;
+        }
 
         default:
-            return NPERR_GENERIC_ERROR;
+            ;
     }
-    return NPERR_NO_ERROR;
+    return NPERR_GENERIC_ERROR;
+}
+
+/*
+ * there is some confusion in gecko headers regarding definition of this API
+ * NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
+ */
+
+NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
+{
+    return NPERR_GENERIC_ERROR;
 }
 
 /******************************************************************************
@@ -139,20 +153,50 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
 #ifdef XP_MACOSX
 int16 NPP_HandleEvent( NPP instance, void * event )
 {
+    static UInt32 lastMouseUp = 0;
+
     if( instance == NULL )
     {
         return false;
     }
 
     VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
+
+    if( p_plugin == NULL )
+    {
+        return false;
+    }
+
     EventRecord *myEvent = (EventRecord*)event;
 
     switch( myEvent->what )
     {
         case nullEvent:
-            break;
+            return true;
         case mouseDown:
+        {
+            if( (myEvent->when - lastMouseUp) < GetDblTime() )
+            {
+                /* double click */
+                libvlc_instance_t *p_vlc = p_plugin->getVLC();
+
+                if( p_vlc )
+                {
+                    if( libvlc_playlist_isplaying(p_vlc, NULL) )
+                    {
+                        libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_vlc, NULL);
+                        if( p_md )
+                        {
+                            libvlc_toggle_fullscreen(p_md, NULL);
+                            libvlc_media_instance_release(p_md);
+                        }
+                    }
+                }
+            }
+            return true;
+        }
         case mouseUp:
+            lastMouseUp = myEvent->when;
             return true;
         case keyUp:
         case keyDown:
@@ -160,44 +204,55 @@ int16 NPP_HandleEvent( NPP instance, void * event )
             return true;
         case updateEvt:
         {
-            int needsDisplay = TRUE;
-            libvlc_instance_t *p_vlc = p_plugin->getVLC();
-
-            if( p_vlc )
+            const NPWindow& npwindow = p_plugin->getWindow();
+            if( npwindow.window )
             {
-                if( libvlc_playlist_isplaying(p_vlc, NULL) )
+                int hasVout = FALSE;
+                libvlc_instance_t *p_vlc = p_plugin->getVLC();
+
+                if( p_vlc )
                 {
-                    libvlc_input_t *p_input = libvlc_playlist_get_input(p_vlc, NULL);
-                    if( p_input )
+                    if( libvlc_playlist_isplaying(p_vlc, NULL) )
                     {
-                        needsDisplay = ! libvlc_input_has_vout(p_input, NULL);
-                        libvlc_input_free(p_input);
+                        libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_vlc, NULL);
+                        if( p_md )
+                        {
+                            hasVout = libvlc_media_instance_has_vout(p_md, NULL);
+                            if( hasVout )
+                            {
+                                libvlc_rectangle_t area;
+                                area.left = 0;
+                                area.top = 0;
+                                area.right = npwindow.width;
+                                area.bottom = npwindow.height;
+                                libvlc_video_redraw_rectangle(p_md, &area, NULL);
+                            }
+                            libvlc_media_instance_release(p_md);
+                        }
                     }
                 }
-            }
 
-            const NPWindow *npwindow = p_plugin->getWindow();
-                
-            if( needsDisplay && npwindow->window )
-            {
-                /* draw the beautiful "No Picture" */
+                if( ! hasVout )
+                {
+                    /* draw the beautiful "No Picture" */
 
-                ForeColor(blackColor);
-                PenMode( patCopy );
+                    ForeColor(blackColor);
+                    PenMode( patCopy );
 
-                /* seems that firefox forgets to set the following on occasion (reload) */
-                SetOrigin(((NP_Port *)npwindow->window)->portx, ((NP_Port *)npwindow->window)->porty);
+                    /* seems that firefox forgets to set the following on occasion (reload) */
+                    SetOrigin(((NP_Port *)npwindow.window)->portx, ((NP_Port *)npwindow.window)->porty);
 
-                Rect rect;
-                rect.left = 0;
-                rect.top = 0;
-                rect.right = npwindow->width;
-                rect.bottom = npwindow->height;
-                PaintRect( &rect );
+                    Rect rect;
+                    rect.left = 0;
+                    rect.top = 0;
+                    rect.right = npwindow.width;
+                    rect.bottom = npwindow.height;
+                    PaintRect( &rect );
 
-                ForeColor(whiteColor);
-                MoveTo( (npwindow->width-80)/ 2  , npwindow->height / 2 );
-                DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
+                    ForeColor(whiteColor);
+                    MoveTo( (npwindow.width-80)/ 2  , npwindow.height / 2 );
+                    DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
+                }
             }
             return true;
         }
@@ -213,6 +268,7 @@ int16 NPP_HandleEvent( NPP instance, void * event )
         case NPEventType_ClippingChangedEvent:
             return false;
         case NPEventType_ScrollingBeginsEvent:
+            return true;
         case NPEventType_ScrollingEndsEvent:
             return true;
         default:
@@ -257,10 +313,16 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
     }
 
     status = p_plugin->init(argc, argn, argv);
-    if( NPERR_NO_ERROR == status ) {
+    if( NPERR_NO_ERROR == status )
+    {
         instance->pdata = reinterpret_cast<void*>(p_plugin);
+#if 0
+        NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
+        NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
+#endif
     }
-    else {
+    else
+    {
         delete p_plugin;
     }
     return status;
@@ -268,15 +330,17 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
 
 NPError NPP_Destroy( NPP instance, NPSavedData** save )
 {
-    if( instance == NULL )
-    {
+    if( NULL == instance )
         return NPERR_INVALID_INSTANCE_ERROR;
-    }
 
     VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
+    if( NULL == p_plugin )
+        return NPERR_NO_ERROR;
+
+    instance->pdata = NULL;
 
 #if XP_WIN
-    HWND win = (HWND)p_plugin->getWindow()->window;
+    HWND win = (HWND)p_plugin->getWindow().window;
     WNDPROC winproc = p_plugin->getWindowProc();
     if( winproc )
     {
@@ -285,10 +349,7 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
     }
 #endif
 
-    if( p_plugin )
-        delete p_plugin;
-
-    instance->pdata = NULL;
+    delete p_plugin;
 
     return NPERR_NO_ERROR;
 }
@@ -318,14 +379,15 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
      *  size changes, etc.
      */
 
-    const NPWindow *curwin = p_plugin->getWindow();
+    /* retrieve current window */
+    NPWindow& curwin = p_plugin->getWindow();
 
 #ifdef XP_MACOSX
     if( window && window->window )
     {
         /* check if plugin has a new parent window */
         CGrafPtr drawable = (((NP_Port*) (window->window))->port);
-        if( !curwin->window || drawable != (((NP_Port*) (curwin->window))->port) )
+        if( !curwin.window || drawable != (((NP_Port*) (curwin.window))->port) )
         {
             /* set/change parent window */
             libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
@@ -350,8 +412,13 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
 
         libvlc_video_set_viewport(p_vlc, &view, &clip, NULL);
 
-        /* remember window details */
-        p_plugin->setWindow(window);
+        /* remember new window */
+        p_plugin->setWindow(*window);
+    }
+    else if( curwin.window ) {
+        /* change/set parent */
+        libvlc_video_set_parent(p_vlc, 0, NULL);
+        curwin.window = NULL;
     }
 #endif /* XP_MACOSX */
 
@@ -360,10 +427,10 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
     {
         /* check if plugin has a new parent window */
         HWND drawable = (HWND) (window->window);
-        if( !curwin->window || drawable != curwin->window )
+        if( !curwin.window || drawable != curwin.window )
         {
             /* reset previous window settings */
-            HWND oldwin = (HWND)p_plugin->getWindow()->window;
+            HWND oldwin = (HWND)p_plugin->getWindow().window;
             WNDPROC oldproc = p_plugin->getWindowProc();
             if( oldproc )
             {
@@ -384,23 +451,24 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
 
             /* change/set parent */
             libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
-        }
 
-        /* remember window details */
-        p_plugin->setWindow(window);
+            /* remember new window */
+            p_plugin->setWindow(*window);
 
-        /* Redraw window */
-        InvalidateRect( (HWND)drawable, NULL, TRUE );
-        UpdateWindow( (HWND)drawable );
+            /* Redraw window */
+            InvalidateRect( (HWND)drawable, NULL, TRUE );
+            UpdateWindow( (HWND)drawable );
+        }
     }
-    else
+    else if ( curwin.window )
     {
         /* reset WNDPROC */
-        HWND oldwin = (HWND)curwin->window;
+        HWND oldwin = (HWND)curwin.window;
         SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) );
         p_plugin->setWindowProc(NULL);
         /* change/set parent */
         libvlc_video_set_parent(p_vlc, 0, NULL);
+        curwin.window = NULL;
     }
 #endif /* XP_WIN */
 
@@ -408,7 +476,7 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
     if( window && window->window )
     {
         Window  drawable   = (Window) window->window;
-        if( !curwin->window || drawable != (Window)curwin->window )
+        if( !curwin.window || drawable != (Window)curwin.window )
         {
             Display *p_display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
 
@@ -422,25 +490,31 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
             libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
 
             /* remember window */
-            p_plugin->setWindow(window);
+            p_plugin->setWindow(*window);
 
             Redraw( w, (XtPointer)p_plugin, NULL );
         }
     }
+    else if ( curwin.window )
+    {
+        /* change/set parent */
+        libvlc_video_set_parent(p_vlc, 0, NULL);
+        curwin.window = NULL;
+    }
 #endif /* XP_UNIX */
 
     if( !p_plugin->b_stream )
     {
         if( p_plugin->psz_target )
         {
-            if( VLC_SUCCESS == libvlc_playlist_add( p_vlc, p_plugin->psz_target, NULL, NULL ) )
+            if( libvlc_playlist_add( p_vlc, p_plugin->psz_target, NULL, NULL ) != -1 )
             {
                 if( p_plugin->b_autoplay )
                 {
                     libvlc_playlist_play(p_vlc, 0, 0, NULL, NULL);
                 }
-                p_plugin->b_stream = VLC_TRUE;
             }
+            p_plugin->b_stream = VLC_TRUE;
         }
     }
     return NPERR_NO_ERROR;
@@ -455,6 +529,10 @@ NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
     }
 
     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
+    if( NULL == p_plugin )
+    {
+        return NPERR_INVALID_INSTANCE_ERROR;
+    }
 
    /*
    ** Firefox/Mozilla may decide to open a stream from the URL specified
@@ -505,8 +583,12 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
     }
 
     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
+    if( NULL == p_plugin )
+    {
+        return;
+    }
 
-    if( VLC_SUCCESS == libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) )
+    if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) != -1 )
     {
         if( p_plugin->b_autoplay )
         {
@@ -620,14 +702,14 @@ static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpa
             FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
             SetTextColor(hdc, RGB(255, 255, 255));
             SetBkColor(hdc, RGB(0, 0, 0));
-            DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); 
+            DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
 
             EndPaint( p_hwnd, &paintstruct );
             return 0L;
         }
         default:
             /* delegate to default handler */
-            return p_plugin->getWindowProc()( p_hwnd, i_msg, wpar, lpar );
+            return CallWindowProc(p_plugin->getWindowProc(), p_hwnd, i_msg, wpar, lpar );
     }
 }
 #endif /* XP_WIN */
@@ -639,24 +721,24 @@ static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpa
 static void Redraw( Widget w, XtPointer closure, XEvent *event )
 {
     VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
-    const NPWindow *window = p_plugin->getWindow();
+    const NPWindowwindow = p_plugin->getWindow();
     GC gc;
     XGCValues gcv;
 
-    Window  drawable   = (Window) window->window;
-    Display *p_display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
+    Window  drawable   = (Window) window.window;
+    Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
 
     gcv.foreground = BlackPixel( p_display, 0 );
     gc = XCreateGC( p_display, drawable, GCForeground, &gcv );
 
     XFillRectangle( p_display, drawable, gc,
-                    0, 0, window->width, window->height );
+                    0, 0, window.width, window.height );
 
     gcv.foreground = WhitePixel( p_display, 0 );
     XChangeGC( p_display, gc, GCForeground, &gcv );
 
     XDrawString( p_display, drawable, gc,
-                 window->width / 2 - 40, window->height / 2,
+                 window.width / 2 - 40, window.height / 2,
                  WINDOW_TEXT, strlen(WINDOW_TEXT) );
 
     XFreeGC( p_display, gc );
@@ -665,9 +747,9 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
 static void Resize ( Widget w, XtPointer closure, XEvent *event )
 {
     VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
-    const NPWindow *window = p_plugin->getWindow();
-    Window  drawable   = (Window) window->window;
-    Display *p_display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
+    const NPWindowwindow = p_plugin->getWindow();
+    Window  drawable   = (Window) window.window;
+    Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
 
     int i_ret;
     Window root_return, parent_return, * children_return;
@@ -686,14 +768,14 @@ static void Resize ( Widget w, XtPointer closure, XEvent *event )
     }
 #endif /* X11_RESIZE_DEBUG */
 
-    if( ! p_plugin->setSize(window->width, window->height) )
+    if( ! p_plugin->setSize(window.width, window.height) )
     {
         /* size already set */
         return;
     }
 
 
-    i_ret = XResizeWindow( p_display, drawable, window->width, window->height );
+    i_ret = XResizeWindow( p_display, drawable, window.width, window.height );
 
 #ifdef X11_RESIZE_DEBUG
     fprintf( stderr,
@@ -725,7 +807,7 @@ static void Resize ( Widget w, XtPointer closure, XEvent *event )
 #endif /* X11_RESIZE_DEBUG */
 
         i_ret = XResizeWindow( p_display, base_window,
-                window->width, window->height );
+                window.width, window.height );
 
 #ifdef X11_RESIZE_DEBUG
         fprintf( stderr,