1 /*****************************************************************************
2 * vlcplugin.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2010 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Damien Fouilleul <damienf.fouilleul@laposte.net>
9 * Jean-Paul Saman <jpsaman@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
31 #ifdef HAVE_MOZILLA_CONFIG_H
32 # include <mozilla-config.h>
35 #include "vlcplugin.h"
36 #include "control/npolibvlc.h"
45 #warning "locking not implemented for this platform"
50 /*****************************************************************************
52 *****************************************************************************/
53 static void plugin_lock_init(plugin_lock_t *lock)
58 pthread_mutex_init(&lock->mutex, NULL);
60 InitializeCriticalSection(&lock->cs);
62 #warning "locking not implemented in this platform"
66 static void plugin_lock_destroy(plugin_lock_t *lock)
71 pthread_mutex_destroy(&lock->mutex);
73 DeleteCriticalSection(&lock->cs);
75 #warning "locking not implemented in this platform"
79 static void plugin_lock(plugin_lock_t *lock)
84 pthread_mutex_lock(&lock->mutex);
86 EnterCriticalSection(&lock->cs);
88 #warning "locking not implemented in this platform"
92 static void plugin_unlock(plugin_lock_t *lock)
97 pthread_mutex_unlock(&lock->mutex);
99 LeaveCriticalSection(&lock->cs);
101 #warning "locking not implemented in this platform"
105 /*****************************************************************************
106 * VlcPlugin constructor and destructor
107 *****************************************************************************/
108 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
116 libvlc_instance(NULL),
117 libvlc_media_list(NULL),
118 libvlc_media_player(NULL),
126 ,i_width((unsigned)-1)
127 ,i_height((unsigned)-1)
136 ,p_btnFullscreen(NULL)
141 memset(&npwindow, 0, sizeof(NPWindow));
143 memset(&npvideo, 0, sizeof(Window));
144 memset(&npcontrol, 0, sizeof(Window));
148 static bool boolValue(const char *value) {
149 return ( !strcmp(value, "1") ||
150 !strcasecmp(value, "true") ||
151 !strcasecmp(value, "yes") );
154 bool EventObj::init()
156 plugin_lock_init(&lock);
160 EventObj::~EventObj()
162 plugin_lock_destroy(&lock);
165 void EventObj::deliver(NPP browser)
172 for( ev_l::iterator i=_elist.begin();i!=_elist.end();++i )
174 libvlc_event_type_t event = *i;
175 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
177 // Invalid events aren't supposed to be queued up.
178 // if( !have_event(event) ) continue;
180 for( lr_l::iterator j=_llist.begin();j!=_llist.end();++j )
184 NPN_InvokeDefault(browser, j->listener(), params, 1, &result);
185 NPN_ReleaseVariantValue(&result);
191 plugin_unlock(&lock);
194 void VlcPlugin::eventAsync(void *param)
196 VlcPlugin *plugin = (VlcPlugin*)param;
197 plugin->events.deliver(plugin->getBrowser());
200 void EventObj::callback(const libvlc_event_t* event)
204 if( have_event(event->type) )
205 _elist.push_back(event->type);
207 plugin_unlock(&lock);
210 void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
212 VlcPlugin *plugin = (VlcPlugin*)param;
214 plugin->events.callback(event);
215 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
217 #warning NPN_PluginThreadAsyncCall not implemented yet.
218 printf("No NPN_PluginThreadAsyncCall(), doing nothing.");
222 inline EventObj::event_t EventObj::find_event(const char *s) const
225 for(i=0;i<maxbit();++i)
226 if(!strcmp(s,libvlc_event_type_name(i)))
231 bool EventObj::insert(const NPString &s, NPObject *l, bool b)
233 event_t e = find_event(s.utf8characters);
237 if( !have_event(e) && !ask_for_event(e) )
241 for(i=_llist.begin();i!=_llist.end();++i)
242 if(i->listener()==l && i->bubble()==b)
245 if( i == _llist.end() ) {
246 _llist.push_back(Listener(e,l,b));
256 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
258 event_t e = find_event(s.utf8characters);
259 if( e>=maxbit() || !get(e) )
263 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
265 if(i->listener()!=l || i->bubble()!=b)
285 void EventObj::hook_manager(libvlc_event_manager_t *em,
286 libvlc_callback_t cb, void *udata)
288 _em = em; _cb = cb; _ud = udata;
291 for(size_t i=0;i<maxbit();++i)
293 libvlc_event_attach(_em, i, _cb, _ud);
296 void EventObj::unhook_manager()
300 for(size_t i=0;i<maxbit();++i)
302 libvlc_event_detach(_em, i, _cb, _ud);
306 bool EventObj::ask_for_event(event_t e)
308 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
312 void EventObj::unask_for_event(event_t e)
314 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
318 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
320 /* prepare VLC command line */
321 const char *ppsz_argv[32];
325 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
328 /* locate VLC module path */
330 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
331 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
332 #elif defined(XP_WIN)
334 DWORD i_type, i_data = MAX_PATH + 1;
335 char p_data[MAX_PATH + 1];
336 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
337 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
339 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
340 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
342 if( i_type == REG_SZ )
344 strcat( p_data, "\\plugins" );
345 ppsz_argv[ppsz_argc++] = "--plugin-path";
346 ppsz_argv[ppsz_argc++] = p_data;
349 RegCloseKey( h_key );
351 ppsz_argv[ppsz_argc++] = "--no-one-instance";
353 #endif /* XP_MACOSX */
355 /* common settings */
356 ppsz_argv[ppsz_argc++] = "-vv";
357 ppsz_argv[ppsz_argc++] = "--no-stats";
358 ppsz_argv[ppsz_argc++] = "--no-media-library";
359 ppsz_argv[ppsz_argc++] = "--intf=dummy";
360 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
362 const char *progid = NULL;
364 /* parse plugin arguments */
365 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
367 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
369 if( !strcmp( argn[i], "target" )
370 || !strcmp( argn[i], "mrl")
371 || !strcmp( argn[i], "filename")
372 || !strcmp( argn[i], "src") )
374 psz_target = argv[i];
376 else if( !strcmp( argn[i], "text" ) )
379 psz_text = strdup( argv[i] );
381 else if( !strcmp( argn[i], "autoplay")
382 || !strcmp( argn[i], "autostart") )
384 b_autoplay = boolValue(argv[i]);
386 else if( !strcmp( argn[i], "fullscreen" ) )
388 if( boolValue(argv[i]) )
390 ppsz_argv[ppsz_argc++] = "--fullscreen";
394 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
397 else if( !strcmp( argn[i], "mute" ) )
399 if( boolValue(argv[i]) )
401 ppsz_argv[ppsz_argc++] = "--volume=0";
404 else if( !strcmp( argn[i], "loop")
405 || !strcmp( argn[i], "autoloop") )
407 if( boolValue(argv[i]) )
409 ppsz_argv[ppsz_argc++] = "--loop";
413 ppsz_argv[ppsz_argc++] = "--no-loop";
416 else if( !strcmp( argn[i], "version")
417 || !strcmp( argn[i], "progid") )
421 else if( !strcmp( argn[i], "toolbar" ) )
423 /* FIXME: Remove this when toolbar functionality has been implemented on
424 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
426 b_toolbar = boolValue(argv[i]);
431 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
432 if( !libvlc_instance )
433 return NPERR_GENERIC_ERROR;
434 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
437 ** fetch plugin base URL, which is the URL of the page containing the plugin
438 ** this URL is used for making absolute URL from relative URL that may be
439 ** passed as an MRL argument
441 NPObject *plugin = NULL;
443 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
446 ** is there a better way to get that info ?
448 static const char docLocHref[] = "document.location.href";
452 script.utf8characters = docLocHref;
453 script.utf8length = sizeof(docLocHref)-1;
455 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
457 if( NPVARIANT_IS_STRING(result) )
459 NPString &location = NPVARIANT_TO_STRING(result);
461 psz_baseURL = (char *) malloc(location.utf8length+1);
464 strncpy(psz_baseURL, location.utf8characters, location.utf8length);
465 psz_baseURL[location.utf8length] = '\0';
468 NPN_ReleaseVariantValue(&result);
470 NPN_ReleaseObject(plugin);
475 // get absolute URL from src
476 char *psz_absurl = getAbsoluteURL(psz_target);
477 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
480 /* assign plugin script root class */
482 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
485 return NPERR_GENERIC_ERROR;
487 return NPERR_NO_ERROR;
490 VlcPlugin::~VlcPlugin()
496 if( libvlc_media_player )
498 if( playlist_isplaying() )
500 events.unhook_manager();
501 libvlc_media_player_release( libvlc_media_player );
503 if( libvlc_media_list )
504 libvlc_media_list_release( libvlc_media_list );
505 if( libvlc_instance )
506 libvlc_release(libvlc_instance);
509 /*****************************************************************************
510 * VlcPlugin playlist replacement methods
511 *****************************************************************************/
512 void VlcPlugin::set_player_window()
515 libvlc_media_player_set_xwindow(libvlc_media_player,
516 (uint32_t)getVideoWindow());
519 // XXX FIXME insert appropriate call here
522 libvlc_media_player_set_hwnd(libvlc_media_player,
527 int VlcPlugin::playlist_add( const char *mrl )
530 libvlc_media_t *p_m = libvlc_media_new_location(libvlc_instance,mrl);
533 assert( libvlc_media_list );
534 libvlc_media_list_lock(libvlc_media_list);
535 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
536 item = libvlc_media_list_count(libvlc_media_list)-1;
537 libvlc_media_list_unlock(libvlc_media_list);
539 libvlc_media_release(p_m);
544 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
545 int optc, const char **optv )
550 assert( libvlc_media_list );
552 p_m = libvlc_media_new_location(libvlc_instance, mrl);
556 for( int i = 0; i < optc; ++i )
557 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
559 libvlc_media_list_lock(libvlc_media_list);
560 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
561 item = libvlc_media_list_count(libvlc_media_list)-1;
562 libvlc_media_list_unlock(libvlc_media_list);
563 libvlc_media_release(p_m);
568 bool VlcPlugin::playlist_select( int idx )
570 libvlc_media_t *p_m = NULL;
572 assert( libvlc_media_list );
574 libvlc_media_list_lock(libvlc_media_list);
576 int count = libvlc_media_list_count(libvlc_media_list);
577 if( idx<0||idx>=count )
580 playlist_index = idx;
582 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index);
583 libvlc_media_list_unlock(libvlc_media_list);
588 if( libvlc_media_player )
590 if( playlist_isplaying() )
592 events.unhook_manager();
593 libvlc_media_player_release( libvlc_media_player );
594 libvlc_media_player = NULL;
597 libvlc_media_player = libvlc_media_player_new_from_media(p_m);
598 if( libvlc_media_player )
602 libvlc_media_player_event_manager(libvlc_media_player),
603 event_callback, this);
606 libvlc_media_release( p_m );
610 libvlc_media_list_unlock(libvlc_media_list);
614 int VlcPlugin::playlist_delete_item( int idx )
616 if( !libvlc_media_list )
618 libvlc_media_list_lock(libvlc_media_list);
619 int ret = libvlc_media_list_remove_index(libvlc_media_list,idx);
620 libvlc_media_list_unlock(libvlc_media_list);
624 void VlcPlugin::playlist_clear()
626 if( libvlc_media_list )
627 libvlc_media_list_release(libvlc_media_list);
628 libvlc_media_list = libvlc_media_list_new(getVLC());
631 int VlcPlugin::playlist_count()
634 if( !libvlc_media_list )
636 libvlc_media_list_lock(libvlc_media_list);
637 items_count = libvlc_media_list_count(libvlc_media_list);
638 libvlc_media_list_unlock(libvlc_media_list);
642 void VlcPlugin::toggle_fullscreen()
644 if( playlist_isplaying() )
645 libvlc_toggle_fullscreen(libvlc_media_player);
648 void VlcPlugin::set_fullscreen( int yes )
650 if( playlist_isplaying() )
651 libvlc_set_fullscreen(libvlc_media_player,yes);
654 int VlcPlugin::get_fullscreen()
657 if( playlist_isplaying() )
658 r = libvlc_get_fullscreen(libvlc_media_player);
662 bool VlcPlugin::player_has_vout()
665 if( playlist_isplaying() )
666 r = libvlc_media_player_has_vout(libvlc_media_player);
670 /*****************************************************************************
672 *****************************************************************************/
674 char *VlcPlugin::getAbsoluteURL(const char *url)
678 // check whether URL is already absolute
679 const char *end=strchr(url, ':');
680 if( (NULL != end) && (end != url) )
682 // validate protocol header
683 const char *start = url;
688 while( start != end )
695 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
696 // not valid protocol header, assume relative URL
700 /* we have a protocol header, therefore URL is absolute */
703 // not a valid protocol header, assume relative URL
710 size_t baseLen = strlen(psz_baseURL);
711 char *href = (char *) malloc(baseLen+strlen(url)+1);
714 /* prepend base URL */
715 memcpy(href, psz_baseURL, baseLen+1);
718 ** relative url could be empty,
719 ** in which case return base URL
725 ** locate pathname part of base URL
728 /* skip over protocol part */
729 char *pathstart = strchr(href, ':');
730 char *pathend = href+baseLen;
733 if( '/' == *(++pathstart) )
735 if( '/' == *(++pathstart) )
740 /* skip over host part */
741 pathstart = strchr(pathstart, '/');
744 // no path, add a / past end of url (over '\0')
751 /* baseURL is just a UNIX path */
754 /* baseURL is not an absolute path */
761 /* relative URL made of an absolute path ? */
764 /* replace path completely */
765 strcpy(pathstart, url);
769 /* find last path component and replace it */
770 while( '/' != *pathend)
774 ** if relative url path starts with one or more '../',
775 ** factor them out of href so that we return a
778 while( pathend != pathstart )
786 /* relative url is just '.' */
792 /* relative url starts with './' */
801 /* relative url is '..' */
807 /* relative url starts with '../' */
815 while( '/' != *pathend );
817 /* skip over '/' separator */
819 /* concatenate remaining base URL and relative URL */
820 strcpy(pathend, url);
829 int VlcPlugin::setSize(unsigned width, unsigned height)
831 int diff = (width != i_width) || (height != i_height);
840 #define BTN_SPACE ((unsigned int)4)
841 void VlcPlugin::showToolbar()
843 const NPWindow& window = getWindow();
844 Window control = getControlWindow();
845 Window video = getVideoWindow();
846 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
847 unsigned int i_height = 0, i_width = BTN_SPACE;
851 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
852 &p_btnPlay, NULL, NULL);
855 i_height = __MAX( i_height, p_btnPlay->height );
858 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
859 &p_btnPause, NULL, NULL);
862 i_height = __MAX( i_height, p_btnPause->height );
864 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
867 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
868 &p_btnStop, NULL, NULL );
871 i_height = __MAX( i_height, p_btnStop->height );
872 i_width += BTN_SPACE + p_btnStop->width;
875 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
876 &p_timeline, NULL, NULL);
879 i_height = __MAX( i_height, p_timeline->height );
880 i_width += BTN_SPACE + p_timeline->width;
883 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
884 &p_btnTime, NULL, NULL);
887 i_height = __MAX( i_height, p_btnTime->height );
888 i_width += BTN_SPACE + p_btnTime->width;
890 if( !p_btnFullscreen )
891 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
892 &p_btnFullscreen, NULL, NULL);
893 if( p_btnFullscreen )
895 i_height = __MAX( i_height, p_btnFullscreen->height );
896 i_width += BTN_SPACE + p_btnFullscreen->width;
899 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
900 &p_btnMute, NULL, NULL);
903 i_height = __MAX( i_height, p_btnMute->height );
906 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
907 &p_btnUnmute, NULL, NULL);
910 i_height = __MAX( i_height, p_btnUnmute->height );
912 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
914 setToolbarSize( i_width, i_height );
916 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
917 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
918 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
920 /* reset panels position and size */
921 /* XXX use i_width */
922 XResizeWindow( p_display, video, window.width, window.height - i_height);
923 XMoveWindow( p_display, control, 0, window.height - i_height );
924 XResizeWindow( p_display, control, window.width, i_height -1);
926 b_toolbar = 1; /* says toolbar is now shown */
930 void VlcPlugin::hideToolbar()
932 const NPWindow& window = getWindow();
933 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
934 Window control = getControlWindow();
935 Window video = getVideoWindow();
937 i_tb_width = i_tb_height = 0;
939 if( p_btnPlay ) XDestroyImage( p_btnPlay );
940 if( p_btnPause ) XDestroyImage( p_btnPause );
941 if( p_btnStop ) XDestroyImage( p_btnStop );
942 if( p_timeline ) XDestroyImage( p_timeline );
943 if( p_btnTime ) XDestroyImage( p_btnTime );
944 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
945 if( p_btnMute ) XDestroyImage( p_btnMute );
946 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
953 p_btnFullscreen = NULL;
957 /* reset panels position and size */
958 /* XXX use i_width */
959 XResizeWindow( p_display, video, window.width, window.height );
960 XMoveWindow( p_display, control, 0, window.height-1 );
961 XResizeWindow( p_display, control, window.width, 1 );
963 b_toolbar = 0; /* says toolbar is now hidden */
967 void VlcPlugin::redrawToolbar()
971 unsigned int dst_x, dst_y;
974 unsigned int i_tb_width, i_tb_height;
976 /* This method does nothing if toolbar is hidden. */
977 if( !b_toolbar || !libvlc_media_player )
980 const NPWindow& window = getWindow();
981 Window control = getControlWindow();
982 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
984 getToolbarSize( &i_tb_width, &i_tb_height );
987 b_mute = libvlc_audio_get_mute( libvlc_media_player );
989 gcv.foreground = BlackPixel( p_display, 0 );
990 gc = XCreateGC( p_display, control, GCForeground, &gcv );
992 XFillRectangle( p_display, control, gc,
993 0, 0, window.width, i_tb_height );
994 gcv.foreground = WhitePixel( p_display, 0 );
995 XChangeGC( p_display, gc, GCForeground, &gcv );
999 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
1001 if( p_btnPause && (is_playing == 1) )
1003 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
1004 dst_y - (p_btnPause->height >> 1),
1005 p_btnPause->width, p_btnPause->height );
1006 dst_x += BTN_SPACE + p_btnPause->width;
1008 else if( p_btnPlay )
1010 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
1011 dst_y - (p_btnPlay->height >> 1),
1012 p_btnPlay->width, p_btnPlay->height );
1013 dst_x += BTN_SPACE + p_btnPlay->width;
1017 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
1018 dst_y - (p_btnStop->height >> 1),
1019 p_btnStop->width, p_btnStop->height );
1021 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
1023 if( p_btnFullscreen )
1024 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
1025 dst_y - (p_btnFullscreen->height >> 1),
1026 p_btnFullscreen->width, p_btnFullscreen->height );
1028 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
1030 if( p_btnUnmute && b_mute )
1032 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
1033 dst_y - (p_btnUnmute->height >> 1),
1034 p_btnUnmute->width, p_btnUnmute->height );
1036 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
1038 else if( p_btnMute )
1040 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
1041 dst_y - (p_btnMute->height >> 1),
1042 p_btnMute->width, p_btnMute->height );
1044 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
1048 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
1049 dst_y - (p_timeline->height >> 1),
1050 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
1052 /* get movie position in % */
1053 if( playlist_isplaying() )
1055 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
1056 libvlc_media_player_get_position(libvlc_media_player));
1060 XPutImage( p_display, control, gc, p_btnTime,
1061 0, 0, (dst_x+i_last_position),
1062 dst_y - (p_btnTime->height >> 1),
1063 p_btnTime->width, p_btnTime->height );
1065 XFreeGC( p_display, gc );
1068 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
1070 unsigned int i_dest = BTN_SPACE;
1072 bool b_mute = false;
1075 fprintf( stderr, "ToolbarButtonClicked:: "
1076 "trying to match (%d,%d) (%d,%d)\n",
1077 i_xpos, i_ypos, i_tb_height, i_tb_width );
1079 if( i_ypos >= i_tb_width )
1080 return clicked_Unknown;
1082 /* Note: the order of testing is dependend on the original
1083 * drawing positions of the icon buttons. Buttons are tested
1088 is_playing = playlist_isplaying();
1091 if( libvlc_media_player )
1092 b_mute = libvlc_audio_get_mute( libvlc_media_player );
1094 /* is Pause of Play button clicked */
1095 if( (is_playing != 1) &&
1096 (i_xpos >= (BTN_SPACE>>1)) &&
1097 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1098 return clicked_Play;
1099 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1100 (i_xpos <= i_dest + p_btnPause->width) )
1101 return clicked_Pause;
1103 /* is Stop button clicked */
1104 if( is_playing != 1 )
1105 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1107 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1109 if( (i_xpos >= i_dest) &&
1110 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1111 return clicked_Stop;
1113 /* is Fullscreen button clicked */
1114 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1115 if( (i_xpos >= i_dest) &&
1116 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1117 return clicked_Fullscreen;
1119 /* is Mute or Unmute button clicked */
1120 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1121 if( !b_mute && (i_xpos >= i_dest) &&
1122 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1123 return clicked_Mute;
1124 else if( (i_xpos >= i_dest) &&
1125 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1126 return clicked_Unmute;
1128 /* is timeline clicked */
1130 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1132 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1133 if( (i_xpos >= i_dest) &&
1134 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1135 return clicked_timeline;
1137 /* is time button clicked */
1138 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1139 if( (i_xpos >= i_dest) &&
1140 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1141 return clicked_Time;
1143 return clicked_Unknown;
1148 // Verifies the version of the NPAPI.
1149 // The eventListeners use a NPAPI function available
1151 bool VlcPlugin::canUseEventListener()
1153 int plugin_major, plugin_minor;
1154 int browser_major, browser_minor;
1156 NPN_Version(&plugin_major, &plugin_minor,
1157 &browser_major, &browser_minor);
1159 if (browser_minor >= 19 || browser_major > 0)