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"
52 /*****************************************************************************
54 *****************************************************************************/
55 static void plugin_lock_init(plugin_lock_t *lock)
60 pthread_mutex_init(&lock->mutex, NULL);
62 InitializeCriticalSection(&lock->cs);
64 #warning "locking not implemented in this platform"
68 static void plugin_lock_destroy(plugin_lock_t *lock)
73 pthread_mutex_destroy(&lock->mutex);
75 DeleteCriticalSection(&lock->cs);
77 #warning "locking not implemented in this platform"
81 static void plugin_lock(plugin_lock_t *lock)
86 pthread_mutex_lock(&lock->mutex);
88 EnterCriticalSection(&lock->cs);
90 #warning "locking not implemented in this platform"
94 static void plugin_unlock(plugin_lock_t *lock)
99 pthread_mutex_unlock(&lock->mutex);
100 #elif defined(XP_WIN)
101 LeaveCriticalSection(&lock->cs);
103 #warning "locking not implemented in this platform"
107 /*****************************************************************************
108 * VlcPlugin constructor and destructor
109 *****************************************************************************/
110 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
111 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
113 VlcPlugin::VlcPlugin( NPP instance, uint16_t mode ) :
122 libvlc_instance(NULL),
123 libvlc_media_list(NULL),
124 libvlc_media_player(NULL),
132 ,i_width((unsigned)-1)
133 ,i_height((unsigned)-1)
142 ,p_btnFullscreen(NULL)
147 memset(&npwindow, 0, sizeof(NPWindow));
149 memset(&npvideo, 0, sizeof(Window));
150 memset(&npcontrol, 0, sizeof(Window));
154 static bool boolValue(const char *value) {
155 return ( !strcmp(value, "1") ||
156 !strcasecmp(value, "true") ||
157 !strcasecmp(value, "yes") );
160 bool EventObj::init()
162 plugin_lock_init(&lock);
166 EventObj::~EventObj()
168 plugin_lock_destroy(&lock);
171 void EventObj::deliver(NPP browser)
178 for( ev_l::iterator i=_elist.begin();i!=_elist.end();++i )
180 libvlc_event_type_t event = *i;
181 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
183 // Invalid events aren't supposed to be queued up.
184 // if( !have_event(event) ) continue;
186 for( lr_l::iterator j=_llist.begin();j!=_llist.end();++j )
190 NPN_InvokeDefault(browser, j->listener(), params, 1, &result);
191 NPN_ReleaseVariantValue(&result);
197 plugin_unlock(&lock);
200 void VlcPlugin::eventAsync(void *param)
202 VlcPlugin *plugin = (VlcPlugin*)param;
203 plugin->events.deliver(plugin->getBrowser());
206 void EventObj::callback(const libvlc_event_t* event)
210 if( have_event(event->type) )
211 _elist.push_back(event->type);
213 plugin_unlock(&lock);
216 void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
218 VlcPlugin *plugin = (VlcPlugin*)param;
220 plugin->events.callback(event);
221 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
223 #warning NPN_PluginThreadAsyncCall not implemented yet.
224 printf("No NPN_PluginThreadAsyncCall(), doing nothing.");
228 inline EventObj::event_t EventObj::find_event(const char *s) const
231 for(i=0;i<maxbit();++i)
232 if(!strcmp(s,libvlc_event_type_name(i)))
237 bool EventObj::insert(const NPString &s, NPObject *l, bool b)
239 event_t e = find_event(s.utf8characters);
243 if( !have_event(e) && !ask_for_event(e) )
247 for(i=_llist.begin();i!=_llist.end();++i)
248 if(i->listener()==l && i->bubble()==b)
251 if( i == _llist.end() ) {
252 _llist.push_back(Listener(e,l,b));
262 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
264 event_t e = find_event(s.utf8characters);
265 if( e>=maxbit() || !get(e) )
269 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
271 if(i->listener()!=l || i->bubble()!=b)
291 void EventObj::hook_manager(libvlc_event_manager_t *em,
292 libvlc_callback_t cb, void *udata)
294 _em = em; _cb = cb; _ud = udata;
297 for(size_t i=0;i<maxbit();++i)
299 libvlc_event_attach(_em, i, _cb, _ud);
302 void EventObj::unhook_manager()
306 for(size_t i=0;i<maxbit();++i)
308 libvlc_event_detach(_em, i, _cb, _ud);
312 bool EventObj::ask_for_event(event_t e)
314 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
318 void EventObj::unask_for_event(event_t e)
320 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
324 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
326 /* prepare VLC command line */
327 const char *ppsz_argv[32];
331 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
334 /* locate VLC module path */
336 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
337 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
338 #elif defined(XP_WIN)
340 DWORD i_type, i_data = MAX_PATH + 1;
341 char p_data[MAX_PATH + 1];
342 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
343 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
345 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
346 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
348 if( i_type == REG_SZ )
350 strcat( p_data, "\\plugins" );
351 ppsz_argv[ppsz_argc++] = "--plugin-path";
352 ppsz_argv[ppsz_argc++] = p_data;
355 RegCloseKey( h_key );
357 ppsz_argv[ppsz_argc++] = "--no-one-instance";
359 #endif /* XP_MACOSX */
361 /* common settings */
362 ppsz_argv[ppsz_argc++] = "-vv";
363 ppsz_argv[ppsz_argc++] = "--no-stats";
364 ppsz_argv[ppsz_argc++] = "--no-media-library";
365 ppsz_argv[ppsz_argc++] = "--intf=dummy";
366 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
368 const char *progid = NULL;
370 /* parse plugin arguments */
371 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
373 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
375 if( !strcmp( argn[i], "target" )
376 || !strcmp( argn[i], "mrl")
377 || !strcmp( argn[i], "filename")
378 || !strcmp( argn[i], "src") )
380 psz_target = argv[i];
382 else if( !strcmp( argn[i], "text" ) )
385 psz_text = strdup( argv[i] );
387 else if( !strcmp( argn[i], "autoplay")
388 || !strcmp( argn[i], "autostart") )
390 b_autoplay = boolValue(argv[i]);
392 else if( !strcmp( argn[i], "fullscreen" ) )
394 if( boolValue(argv[i]) )
396 ppsz_argv[ppsz_argc++] = "--fullscreen";
400 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
403 else if( !strcmp( argn[i], "mute" ) )
405 if( boolValue(argv[i]) )
407 ppsz_argv[ppsz_argc++] = "--volume=0";
410 else if( !strcmp( argn[i], "loop")
411 || !strcmp( argn[i], "autoloop") )
413 if( boolValue(argv[i]) )
415 ppsz_argv[ppsz_argc++] = "--loop";
419 ppsz_argv[ppsz_argc++] = "--no-loop";
422 else if( !strcmp( argn[i], "version")
423 || !strcmp( argn[i], "progid") )
427 else if( !strcmp( argn[i], "toolbar" ) )
429 /* FIXME: Remove this when toolbar functionality has been implemented on
430 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
432 b_toolbar = boolValue(argv[i]);
437 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
438 if( !libvlc_instance )
439 return NPERR_GENERIC_ERROR;
440 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
443 ** fetch plugin base URL, which is the URL of the page containing the plugin
444 ** this URL is used for making absolute URL from relative URL that may be
445 ** passed as an MRL argument
447 NPObject *plugin = NULL;
449 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
452 ** is there a better way to get that info ?
454 static const char docLocHref[] = "document.location.href";
458 script.UTF8Characters = docLocHref;
459 script.UTF8Length = sizeof(docLocHref)-1;
461 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
463 if( NPVARIANT_IS_STRING(result) )
465 NPString &location = NPVARIANT_TO_STRING(result);
467 psz_baseURL = (char *) malloc(location.UTF8Length+1);
470 strncpy(psz_baseURL, location.UTF8Characters, location.UTF8Length);
471 psz_baseURL[location.UTF8Length] = '\0';
474 NPN_ReleaseVariantValue(&result);
476 NPN_ReleaseObject(plugin);
481 // get absolute URL from src
482 char *psz_absurl = getAbsoluteURL(psz_target);
483 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
486 /* assign plugin script root class */
488 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
491 return NPERR_GENERIC_ERROR;
493 return NPERR_NO_ERROR;
496 VlcPlugin::~VlcPlugin()
502 if( libvlc_media_player )
504 if( playlist_isplaying() )
506 events.unhook_manager();
507 libvlc_media_player_release( libvlc_media_player );
509 if( libvlc_media_list )
510 libvlc_media_list_release( libvlc_media_list );
511 if( libvlc_instance )
512 libvlc_release(libvlc_instance);
515 /*****************************************************************************
516 * VlcPlugin playlist replacement methods
517 *****************************************************************************/
518 void VlcPlugin::set_player_window()
521 libvlc_media_player_set_xwindow(libvlc_media_player,
522 (uint32_t)getVideoWindow());
525 // XXX FIXME insert appropriate call here
528 libvlc_media_player_set_hwnd(libvlc_media_player,
533 int VlcPlugin::playlist_add( const char *mrl )
536 libvlc_media_t *p_m = libvlc_media_new_location(libvlc_instance,mrl);
539 assert( libvlc_media_list );
540 libvlc_media_list_lock(libvlc_media_list);
541 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
542 item = libvlc_media_list_count(libvlc_media_list)-1;
543 libvlc_media_list_unlock(libvlc_media_list);
545 libvlc_media_release(p_m);
550 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
551 int optc, const char **optv )
556 assert( libvlc_media_list );
558 p_m = libvlc_media_new_location(libvlc_instance, mrl);
562 for( int i = 0; i < optc; ++i )
563 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
565 libvlc_media_list_lock(libvlc_media_list);
566 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
567 item = libvlc_media_list_count(libvlc_media_list)-1;
568 libvlc_media_list_unlock(libvlc_media_list);
569 libvlc_media_release(p_m);
574 bool VlcPlugin::playlist_select( int idx )
576 libvlc_media_t *p_m = NULL;
578 assert( libvlc_media_list );
580 libvlc_media_list_lock(libvlc_media_list);
582 int count = libvlc_media_list_count(libvlc_media_list);
583 if( idx<0||idx>=count )
586 playlist_index = idx;
588 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index);
589 libvlc_media_list_unlock(libvlc_media_list);
594 if( libvlc_media_player )
596 if( playlist_isplaying() )
598 events.unhook_manager();
599 libvlc_media_player_release( libvlc_media_player );
600 libvlc_media_player = NULL;
603 libvlc_media_player = libvlc_media_player_new_from_media(p_m);
604 if( libvlc_media_player )
608 libvlc_media_player_event_manager(libvlc_media_player),
609 event_callback, this);
612 libvlc_media_release( p_m );
616 libvlc_media_list_unlock(libvlc_media_list);
620 int VlcPlugin::playlist_delete_item( int idx )
622 if( !libvlc_media_list )
624 libvlc_media_list_lock(libvlc_media_list);
625 int ret = libvlc_media_list_remove_index(libvlc_media_list,idx);
626 libvlc_media_list_unlock(libvlc_media_list);
630 void VlcPlugin::playlist_clear()
632 if( libvlc_media_list )
633 libvlc_media_list_release(libvlc_media_list);
634 libvlc_media_list = libvlc_media_list_new(getVLC());
637 int VlcPlugin::playlist_count()
640 if( !libvlc_media_list )
642 libvlc_media_list_lock(libvlc_media_list);
643 items_count = libvlc_media_list_count(libvlc_media_list);
644 libvlc_media_list_unlock(libvlc_media_list);
648 void VlcPlugin::toggle_fullscreen()
650 if( playlist_isplaying() )
651 libvlc_toggle_fullscreen(libvlc_media_player);
654 void VlcPlugin::set_fullscreen( int yes )
656 if( playlist_isplaying() )
657 libvlc_set_fullscreen(libvlc_media_player,yes);
660 int VlcPlugin::get_fullscreen()
663 if( playlist_isplaying() )
664 r = libvlc_get_fullscreen(libvlc_media_player);
668 bool VlcPlugin::player_has_vout()
671 if( playlist_isplaying() )
672 r = libvlc_media_player_has_vout(libvlc_media_player);
676 /*****************************************************************************
678 *****************************************************************************/
680 char *VlcPlugin::getAbsoluteURL(const char *url)
684 // check whether URL is already absolute
685 const char *end=strchr(url, ':');
686 if( (NULL != end) && (end != url) )
688 // validate protocol header
689 const char *start = url;
694 while( start != end )
701 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
702 // not valid protocol header, assume relative URL
706 /* we have a protocol header, therefore URL is absolute */
709 // not a valid protocol header, assume relative URL
716 size_t baseLen = strlen(psz_baseURL);
717 char *href = (char *) malloc(baseLen+strlen(url)+1);
720 /* prepend base URL */
721 memcpy(href, psz_baseURL, baseLen+1);
724 ** relative url could be empty,
725 ** in which case return base URL
731 ** locate pathname part of base URL
734 /* skip over protocol part */
735 char *pathstart = strchr(href, ':');
736 char *pathend = href+baseLen;
739 if( '/' == *(++pathstart) )
741 if( '/' == *(++pathstart) )
746 /* skip over host part */
747 pathstart = strchr(pathstart, '/');
750 // no path, add a / past end of url (over '\0')
757 /* baseURL is just a UNIX path */
760 /* baseURL is not an absolute path */
767 /* relative URL made of an absolute path ? */
770 /* replace path completely */
771 strcpy(pathstart, url);
775 /* find last path component and replace it */
776 while( '/' != *pathend)
780 ** if relative url path starts with one or more '../',
781 ** factor them out of href so that we return a
784 while( pathend != pathstart )
792 /* relative url is just '.' */
798 /* relative url starts with './' */
807 /* relative url is '..' */
813 /* relative url starts with '../' */
821 while( '/' != *pathend );
823 /* skip over '/' separator */
825 /* concatenate remaining base URL and relative URL */
826 strcpy(pathend, url);
835 int VlcPlugin::setSize(unsigned width, unsigned height)
837 int diff = (width != i_width) || (height != i_height);
846 #define BTN_SPACE ((unsigned int)4)
847 void VlcPlugin::showToolbar()
849 const NPWindow& window = getWindow();
850 Window control = getControlWindow();
851 Window video = getVideoWindow();
852 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
853 unsigned int i_height = 0, i_width = BTN_SPACE;
857 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
858 &p_btnPlay, NULL, NULL);
861 i_height = __MAX( i_height, p_btnPlay->height );
864 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
865 &p_btnPause, NULL, NULL);
868 i_height = __MAX( i_height, p_btnPause->height );
870 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
873 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
874 &p_btnStop, NULL, NULL );
877 i_height = __MAX( i_height, p_btnStop->height );
878 i_width += BTN_SPACE + p_btnStop->width;
881 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
882 &p_timeline, NULL, NULL);
885 i_height = __MAX( i_height, p_timeline->height );
886 i_width += BTN_SPACE + p_timeline->width;
889 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
890 &p_btnTime, NULL, NULL);
893 i_height = __MAX( i_height, p_btnTime->height );
894 i_width += BTN_SPACE + p_btnTime->width;
896 if( !p_btnFullscreen )
897 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
898 &p_btnFullscreen, NULL, NULL);
899 if( p_btnFullscreen )
901 i_height = __MAX( i_height, p_btnFullscreen->height );
902 i_width += BTN_SPACE + p_btnFullscreen->width;
905 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
906 &p_btnMute, NULL, NULL);
909 i_height = __MAX( i_height, p_btnMute->height );
912 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
913 &p_btnUnmute, NULL, NULL);
916 i_height = __MAX( i_height, p_btnUnmute->height );
918 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
920 setToolbarSize( i_width, i_height );
922 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
923 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
924 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
926 /* reset panels position and size */
927 /* XXX use i_width */
928 XResizeWindow( p_display, video, window.width, window.height - i_height);
929 XMoveWindow( p_display, control, 0, window.height - i_height );
930 XResizeWindow( p_display, control, window.width, i_height -1);
932 b_toolbar = 1; /* says toolbar is now shown */
936 void VlcPlugin::hideToolbar()
938 const NPWindow& window = getWindow();
939 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
940 Window control = getControlWindow();
941 Window video = getVideoWindow();
943 i_tb_width = i_tb_height = 0;
945 if( p_btnPlay ) XDestroyImage( p_btnPlay );
946 if( p_btnPause ) XDestroyImage( p_btnPause );
947 if( p_btnStop ) XDestroyImage( p_btnStop );
948 if( p_timeline ) XDestroyImage( p_timeline );
949 if( p_btnTime ) XDestroyImage( p_btnTime );
950 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
951 if( p_btnMute ) XDestroyImage( p_btnMute );
952 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
959 p_btnFullscreen = NULL;
963 /* reset panels position and size */
964 /* XXX use i_width */
965 XResizeWindow( p_display, video, window.width, window.height );
966 XMoveWindow( p_display, control, 0, window.height-1 );
967 XResizeWindow( p_display, control, window.width, 1 );
969 b_toolbar = 0; /* says toolbar is now hidden */
973 void VlcPlugin::redrawToolbar()
977 unsigned int dst_x, dst_y;
980 unsigned int i_tb_width, i_tb_height;
982 /* This method does nothing if toolbar is hidden. */
983 if( !b_toolbar || !libvlc_media_player )
986 const NPWindow& window = getWindow();
987 Window control = getControlWindow();
988 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
990 getToolbarSize( &i_tb_width, &i_tb_height );
993 b_mute = libvlc_audio_get_mute( libvlc_media_player );
995 gcv.foreground = BlackPixel( p_display, 0 );
996 gc = XCreateGC( p_display, control, GCForeground, &gcv );
998 XFillRectangle( p_display, control, gc,
999 0, 0, window.width, i_tb_height );
1000 gcv.foreground = WhitePixel( p_display, 0 );
1001 XChangeGC( p_display, gc, GCForeground, &gcv );
1003 /* position icons */
1005 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
1007 if( p_btnPause && (is_playing == 1) )
1009 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
1010 dst_y - (p_btnPause->height >> 1),
1011 p_btnPause->width, p_btnPause->height );
1012 dst_x += BTN_SPACE + p_btnPause->width;
1014 else if( p_btnPlay )
1016 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
1017 dst_y - (p_btnPlay->height >> 1),
1018 p_btnPlay->width, p_btnPlay->height );
1019 dst_x += BTN_SPACE + p_btnPlay->width;
1023 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
1024 dst_y - (p_btnStop->height >> 1),
1025 p_btnStop->width, p_btnStop->height );
1027 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
1029 if( p_btnFullscreen )
1030 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
1031 dst_y - (p_btnFullscreen->height >> 1),
1032 p_btnFullscreen->width, p_btnFullscreen->height );
1034 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
1036 if( p_btnUnmute && b_mute )
1038 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
1039 dst_y - (p_btnUnmute->height >> 1),
1040 p_btnUnmute->width, p_btnUnmute->height );
1042 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
1044 else if( p_btnMute )
1046 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
1047 dst_y - (p_btnMute->height >> 1),
1048 p_btnMute->width, p_btnMute->height );
1050 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
1054 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
1055 dst_y - (p_timeline->height >> 1),
1056 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
1058 /* get movie position in % */
1059 if( playlist_isplaying() )
1061 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
1062 libvlc_media_player_get_position(libvlc_media_player));
1066 XPutImage( p_display, control, gc, p_btnTime,
1067 0, 0, (dst_x+i_last_position),
1068 dst_y - (p_btnTime->height >> 1),
1069 p_btnTime->width, p_btnTime->height );
1071 XFreeGC( p_display, gc );
1074 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
1076 unsigned int i_dest = BTN_SPACE;
1078 bool b_mute = false;
1081 fprintf( stderr, "ToolbarButtonClicked:: "
1082 "trying to match (%d,%d) (%d,%d)\n",
1083 i_xpos, i_ypos, i_tb_height, i_tb_width );
1085 if( i_ypos >= i_tb_width )
1086 return clicked_Unknown;
1088 /* Note: the order of testing is dependend on the original
1089 * drawing positions of the icon buttons. Buttons are tested
1094 is_playing = playlist_isplaying();
1097 if( libvlc_media_player )
1098 b_mute = libvlc_audio_get_mute( libvlc_media_player );
1100 /* is Pause of Play button clicked */
1101 if( (is_playing != 1) &&
1102 (i_xpos >= (BTN_SPACE>>1)) &&
1103 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1104 return clicked_Play;
1105 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1106 (i_xpos <= i_dest + p_btnPause->width) )
1107 return clicked_Pause;
1109 /* is Stop button clicked */
1110 if( is_playing != 1 )
1111 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1113 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1115 if( (i_xpos >= i_dest) &&
1116 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1117 return clicked_Stop;
1119 /* is Fullscreen button clicked */
1120 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1121 if( (i_xpos >= i_dest) &&
1122 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1123 return clicked_Fullscreen;
1125 /* is Mute or Unmute button clicked */
1126 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1127 if( !b_mute && (i_xpos >= i_dest) &&
1128 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1129 return clicked_Mute;
1130 else if( (i_xpos >= i_dest) &&
1131 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1132 return clicked_Unmute;
1134 /* is timeline clicked */
1136 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1138 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1139 if( (i_xpos >= i_dest) &&
1140 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1141 return clicked_timeline;
1143 /* is time button clicked */
1144 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1145 if( (i_xpos >= i_dest) &&
1146 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1147 return clicked_Time;
1149 return clicked_Unknown;
1154 // Verifies the version of the NPAPI.
1155 // The eventListeners use a NPAPI function available
1157 bool VlcPlugin::canUseEventListener()
1159 int plugin_major, plugin_minor;
1160 int browser_major, browser_minor;
1162 NPN_Version(&plugin_major, &plugin_minor,
1163 &browser_major, &browser_minor);
1165 if (browser_minor >= 19 || browser_major > 0)