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"
51 /*****************************************************************************
53 *****************************************************************************/
54 static void plugin_lock_init(plugin_lock_t *lock)
59 pthread_mutex_init(&lock->mutex, NULL);
61 InitializeCriticalSection(&lock->cs);
63 #warning "locking not implemented in this platform"
67 static void plugin_lock_destroy(plugin_lock_t *lock)
72 pthread_mutex_destroy(&lock->mutex);
74 DeleteCriticalSection(&lock->cs);
76 #warning "locking not implemented in this platform"
80 static void plugin_lock(plugin_lock_t *lock)
85 pthread_mutex_lock(&lock->mutex);
87 EnterCriticalSection(&lock->cs);
89 #warning "locking not implemented in this platform"
93 static void plugin_unlock(plugin_lock_t *lock)
98 pthread_mutex_unlock(&lock->mutex);
100 LeaveCriticalSection(&lock->cs);
102 #warning "locking not implemented in this platform"
106 /*****************************************************************************
107 * VlcPlugin constructor and destructor
108 *****************************************************************************/
109 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
110 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
112 VlcPlugin::VlcPlugin( NPP instance, uint16_t mode ) :
121 libvlc_instance(NULL),
122 libvlc_media_list(NULL),
123 libvlc_media_player(NULL),
131 ,i_width((unsigned)-1)
132 ,i_height((unsigned)-1)
141 ,p_btnFullscreen(NULL)
146 memset(&npwindow, 0, sizeof(NPWindow));
148 memset(&npvideo, 0, sizeof(Window));
149 memset(&npcontrol, 0, sizeof(Window));
153 static bool boolValue(const char *value) {
154 return ( !strcmp(value, "1") ||
155 !strcasecmp(value, "true") ||
156 !strcasecmp(value, "yes") );
159 bool EventObj::init()
161 plugin_lock_init(&lock);
165 EventObj::~EventObj()
167 plugin_lock_destroy(&lock);
170 void EventObj::deliver(NPP browser)
177 for( ev_l::iterator i=_elist.begin();i!=_elist.end();++i )
179 libvlc_event_type_t event = *i;
180 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
182 // Invalid events aren't supposed to be queued up.
183 // if( !have_event(event) ) continue;
185 for( lr_l::iterator j=_llist.begin();j!=_llist.end();++j )
189 NPN_InvokeDefault(browser, j->listener(), params, 1, &result);
190 NPN_ReleaseVariantValue(&result);
196 plugin_unlock(&lock);
199 void VlcPlugin::eventAsync(void *param)
201 VlcPlugin *plugin = (VlcPlugin*)param;
202 plugin->events.deliver(plugin->getBrowser());
205 void EventObj::callback(const libvlc_event_t* event)
209 if( have_event(event->type) )
210 _elist.push_back(event->type);
212 plugin_unlock(&lock);
215 void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
217 VlcPlugin *plugin = (VlcPlugin*)param;
219 plugin->events.callback(event);
220 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
222 #warning NPN_PluginThreadAsyncCall not implemented yet.
223 printf("No NPN_PluginThreadAsyncCall(), doing nothing.");
227 inline EventObj::event_t EventObj::find_event(const char *s) const
230 for(i=0;i<maxbit();++i)
231 if(!strcmp(s,libvlc_event_type_name(i)))
236 bool EventObj::insert(const NPString &s, NPObject *l, bool b)
238 event_t e = find_event(s.utf8characters);
242 if( !have_event(e) && !ask_for_event(e) )
246 for(i=_llist.begin();i!=_llist.end();++i)
247 if(i->listener()==l && i->bubble()==b)
250 if( i == _llist.end() ) {
251 _llist.push_back(Listener(e,l,b));
261 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
263 event_t e = find_event(s.utf8characters);
264 if( e>=maxbit() || !get(e) )
268 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
270 if(i->listener()!=l || i->bubble()!=b)
290 void EventObj::hook_manager(libvlc_event_manager_t *em,
291 libvlc_callback_t cb, void *udata)
293 _em = em; _cb = cb; _ud = udata;
296 for(size_t i=0;i<maxbit();++i)
298 libvlc_event_attach(_em, i, _cb, _ud);
301 void EventObj::unhook_manager()
305 for(size_t i=0;i<maxbit();++i)
307 libvlc_event_detach(_em, i, _cb, _ud);
311 bool EventObj::ask_for_event(event_t e)
313 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
317 void EventObj::unask_for_event(event_t e)
319 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
323 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
325 /* prepare VLC command line */
326 const char *ppsz_argv[32];
330 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
333 /* locate VLC module path */
335 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
336 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
337 #elif defined(XP_WIN)
339 DWORD i_type, i_data = MAX_PATH + 1;
340 char p_data[MAX_PATH + 1];
341 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
342 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
344 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
345 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
347 if( i_type == REG_SZ )
349 strcat( p_data, "\\plugins" );
350 ppsz_argv[ppsz_argc++] = "--plugin-path";
351 ppsz_argv[ppsz_argc++] = p_data;
354 RegCloseKey( h_key );
356 ppsz_argv[ppsz_argc++] = "--no-one-instance";
358 #endif /* XP_MACOSX */
360 /* common settings */
361 ppsz_argv[ppsz_argc++] = "-vv";
362 ppsz_argv[ppsz_argc++] = "--no-stats";
363 ppsz_argv[ppsz_argc++] = "--no-media-library";
364 ppsz_argv[ppsz_argc++] = "--intf=dummy";
365 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
367 const char *progid = NULL;
369 /* parse plugin arguments */
370 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
372 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
374 if( !strcmp( argn[i], "target" )
375 || !strcmp( argn[i], "mrl")
376 || !strcmp( argn[i], "filename")
377 || !strcmp( argn[i], "src") )
379 psz_target = argv[i];
381 else if( !strcmp( argn[i], "text" ) )
384 psz_text = strdup( argv[i] );
386 else if( !strcmp( argn[i], "autoplay")
387 || !strcmp( argn[i], "autostart") )
389 b_autoplay = boolValue(argv[i]);
391 else if( !strcmp( argn[i], "fullscreen" ) )
393 if( boolValue(argv[i]) )
395 ppsz_argv[ppsz_argc++] = "--fullscreen";
399 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
402 else if( !strcmp( argn[i], "mute" ) )
404 if( boolValue(argv[i]) )
406 ppsz_argv[ppsz_argc++] = "--volume=0";
409 else if( !strcmp( argn[i], "loop")
410 || !strcmp( argn[i], "autoloop") )
412 if( boolValue(argv[i]) )
414 ppsz_argv[ppsz_argc++] = "--loop";
418 ppsz_argv[ppsz_argc++] = "--no-loop";
421 else if( !strcmp( argn[i], "version")
422 || !strcmp( argn[i], "progid") )
426 else if( !strcmp( argn[i], "toolbar" ) )
428 /* FIXME: Remove this when toolbar functionality has been implemented on
429 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
431 b_toolbar = boolValue(argv[i]);
436 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
437 if( !libvlc_instance )
438 return NPERR_GENERIC_ERROR;
439 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
442 ** fetch plugin base URL, which is the URL of the page containing the plugin
443 ** this URL is used for making absolute URL from relative URL that may be
444 ** passed as an MRL argument
446 NPObject *plugin = NULL;
448 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
451 ** is there a better way to get that info ?
453 static const char docLocHref[] = "document.location.href";
457 script.UTF8Characters = docLocHref;
458 script.UTF8Length = sizeof(docLocHref)-1;
460 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
462 if( NPVARIANT_IS_STRING(result) )
464 NPString &location = NPVARIANT_TO_STRING(result);
466 psz_baseURL = (char *) malloc(location.UTF8Length+1);
469 strncpy(psz_baseURL, location.UTF8Characters, location.UTF8Length);
470 psz_baseURL[location.UTF8Length] = '\0';
473 NPN_ReleaseVariantValue(&result);
475 NPN_ReleaseObject(plugin);
480 // get absolute URL from src
481 char *psz_absurl = getAbsoluteURL(psz_target);
482 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
485 /* assign plugin script root class */
487 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
490 return NPERR_GENERIC_ERROR;
492 return NPERR_NO_ERROR;
495 VlcPlugin::~VlcPlugin()
501 if( libvlc_media_player )
503 if( playlist_isplaying() )
505 events.unhook_manager();
506 libvlc_media_player_release( libvlc_media_player );
508 if( libvlc_media_list )
509 libvlc_media_list_release( libvlc_media_list );
510 if( libvlc_instance )
511 libvlc_release(libvlc_instance);
514 /*****************************************************************************
515 * VlcPlugin playlist replacement methods
516 *****************************************************************************/
517 void VlcPlugin::set_player_window()
520 libvlc_media_player_set_xwindow(libvlc_media_player,
521 (uint32_t)getVideoWindow());
524 // XXX FIXME insert appropriate call here
527 libvlc_media_player_set_hwnd(libvlc_media_player,
532 int VlcPlugin::playlist_add( const char *mrl )
535 libvlc_media_t *p_m = libvlc_media_new_location(libvlc_instance,mrl);
538 assert( libvlc_media_list );
539 libvlc_media_list_lock(libvlc_media_list);
540 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
541 item = libvlc_media_list_count(libvlc_media_list)-1;
542 libvlc_media_list_unlock(libvlc_media_list);
544 libvlc_media_release(p_m);
549 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
550 int optc, const char **optv )
555 assert( libvlc_media_list );
557 p_m = libvlc_media_new_location(libvlc_instance, mrl);
561 for( int i = 0; i < optc; ++i )
562 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
564 libvlc_media_list_lock(libvlc_media_list);
565 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
566 item = libvlc_media_list_count(libvlc_media_list)-1;
567 libvlc_media_list_unlock(libvlc_media_list);
568 libvlc_media_release(p_m);
573 bool VlcPlugin::playlist_select( int idx )
575 libvlc_media_t *p_m = NULL;
577 assert( libvlc_media_list );
579 libvlc_media_list_lock(libvlc_media_list);
581 int count = libvlc_media_list_count(libvlc_media_list);
582 if( idx<0||idx>=count )
585 playlist_index = idx;
587 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index);
588 libvlc_media_list_unlock(libvlc_media_list);
593 if( libvlc_media_player )
595 if( playlist_isplaying() )
597 events.unhook_manager();
598 libvlc_media_player_release( libvlc_media_player );
599 libvlc_media_player = NULL;
602 libvlc_media_player = libvlc_media_player_new_from_media(p_m);
603 if( libvlc_media_player )
607 libvlc_media_player_event_manager(libvlc_media_player),
608 event_callback, this);
611 libvlc_media_release( p_m );
615 libvlc_media_list_unlock(libvlc_media_list);
619 int VlcPlugin::playlist_delete_item( int idx )
621 if( !libvlc_media_list )
623 libvlc_media_list_lock(libvlc_media_list);
624 int ret = libvlc_media_list_remove_index(libvlc_media_list,idx);
625 libvlc_media_list_unlock(libvlc_media_list);
629 void VlcPlugin::playlist_clear()
631 if( libvlc_media_list )
632 libvlc_media_list_release(libvlc_media_list);
633 libvlc_media_list = libvlc_media_list_new(getVLC());
636 int VlcPlugin::playlist_count()
639 if( !libvlc_media_list )
641 libvlc_media_list_lock(libvlc_media_list);
642 items_count = libvlc_media_list_count(libvlc_media_list);
643 libvlc_media_list_unlock(libvlc_media_list);
647 void VlcPlugin::toggle_fullscreen()
649 if( playlist_isplaying() )
650 libvlc_toggle_fullscreen(libvlc_media_player);
653 void VlcPlugin::set_fullscreen( int yes )
655 if( playlist_isplaying() )
656 libvlc_set_fullscreen(libvlc_media_player,yes);
659 int VlcPlugin::get_fullscreen()
662 if( playlist_isplaying() )
663 r = libvlc_get_fullscreen(libvlc_media_player);
667 bool VlcPlugin::player_has_vout()
670 if( playlist_isplaying() )
671 r = libvlc_media_player_has_vout(libvlc_media_player);
675 /*****************************************************************************
677 *****************************************************************************/
679 char *VlcPlugin::getAbsoluteURL(const char *url)
683 // check whether URL is already absolute
684 const char *end=strchr(url, ':');
685 if( (NULL != end) && (end != url) )
687 // validate protocol header
688 const char *start = url;
693 while( start != end )
700 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
701 // not valid protocol header, assume relative URL
705 /* we have a protocol header, therefore URL is absolute */
708 // not a valid protocol header, assume relative URL
715 size_t baseLen = strlen(psz_baseURL);
716 char *href = (char *) malloc(baseLen+strlen(url)+1);
719 /* prepend base URL */
720 memcpy(href, psz_baseURL, baseLen+1);
723 ** relative url could be empty,
724 ** in which case return base URL
730 ** locate pathname part of base URL
733 /* skip over protocol part */
734 char *pathstart = strchr(href, ':');
735 char *pathend = href+baseLen;
738 if( '/' == *(++pathstart) )
740 if( '/' == *(++pathstart) )
745 /* skip over host part */
746 pathstart = strchr(pathstart, '/');
749 // no path, add a / past end of url (over '\0')
756 /* baseURL is just a UNIX path */
759 /* baseURL is not an absolute path */
766 /* relative URL made of an absolute path ? */
769 /* replace path completely */
770 strcpy(pathstart, url);
774 /* find last path component and replace it */
775 while( '/' != *pathend)
779 ** if relative url path starts with one or more '../',
780 ** factor them out of href so that we return a
783 while( pathend != pathstart )
791 /* relative url is just '.' */
797 /* relative url starts with './' */
806 /* relative url is '..' */
812 /* relative url starts with '../' */
820 while( '/' != *pathend );
822 /* skip over '/' separator */
824 /* concatenate remaining base URL and relative URL */
825 strcpy(pathend, url);
834 int VlcPlugin::setSize(unsigned width, unsigned height)
836 int diff = (width != i_width) || (height != i_height);
845 #define BTN_SPACE ((unsigned int)4)
846 void VlcPlugin::showToolbar()
848 const NPWindow& window = getWindow();
849 Window control = getControlWindow();
850 Window video = getVideoWindow();
851 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
852 unsigned int i_height = 0, i_width = BTN_SPACE;
856 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
857 &p_btnPlay, NULL, NULL);
860 i_height = __MAX( i_height, p_btnPlay->height );
863 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
864 &p_btnPause, NULL, NULL);
867 i_height = __MAX( i_height, p_btnPause->height );
869 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
872 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
873 &p_btnStop, NULL, NULL );
876 i_height = __MAX( i_height, p_btnStop->height );
877 i_width += BTN_SPACE + p_btnStop->width;
880 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
881 &p_timeline, NULL, NULL);
884 i_height = __MAX( i_height, p_timeline->height );
885 i_width += BTN_SPACE + p_timeline->width;
888 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
889 &p_btnTime, NULL, NULL);
892 i_height = __MAX( i_height, p_btnTime->height );
893 i_width += BTN_SPACE + p_btnTime->width;
895 if( !p_btnFullscreen )
896 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
897 &p_btnFullscreen, NULL, NULL);
898 if( p_btnFullscreen )
900 i_height = __MAX( i_height, p_btnFullscreen->height );
901 i_width += BTN_SPACE + p_btnFullscreen->width;
904 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
905 &p_btnMute, NULL, NULL);
908 i_height = __MAX( i_height, p_btnMute->height );
911 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
912 &p_btnUnmute, NULL, NULL);
915 i_height = __MAX( i_height, p_btnUnmute->height );
917 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
919 setToolbarSize( i_width, i_height );
921 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
922 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
923 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
925 /* reset panels position and size */
926 /* XXX use i_width */
927 XResizeWindow( p_display, video, window.width, window.height - i_height);
928 XMoveWindow( p_display, control, 0, window.height - i_height );
929 XResizeWindow( p_display, control, window.width, i_height -1);
931 b_toolbar = 1; /* says toolbar is now shown */
935 void VlcPlugin::hideToolbar()
937 const NPWindow& window = getWindow();
938 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
939 Window control = getControlWindow();
940 Window video = getVideoWindow();
942 i_tb_width = i_tb_height = 0;
944 if( p_btnPlay ) XDestroyImage( p_btnPlay );
945 if( p_btnPause ) XDestroyImage( p_btnPause );
946 if( p_btnStop ) XDestroyImage( p_btnStop );
947 if( p_timeline ) XDestroyImage( p_timeline );
948 if( p_btnTime ) XDestroyImage( p_btnTime );
949 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
950 if( p_btnMute ) XDestroyImage( p_btnMute );
951 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
958 p_btnFullscreen = NULL;
962 /* reset panels position and size */
963 /* XXX use i_width */
964 XResizeWindow( p_display, video, window.width, window.height );
965 XMoveWindow( p_display, control, 0, window.height-1 );
966 XResizeWindow( p_display, control, window.width, 1 );
968 b_toolbar = 0; /* says toolbar is now hidden */
972 void VlcPlugin::redrawToolbar()
976 unsigned int dst_x, dst_y;
979 unsigned int i_tb_width, i_tb_height;
981 /* This method does nothing if toolbar is hidden. */
982 if( !b_toolbar || !libvlc_media_player )
985 const NPWindow& window = getWindow();
986 Window control = getControlWindow();
987 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
989 getToolbarSize( &i_tb_width, &i_tb_height );
992 b_mute = libvlc_audio_get_mute( libvlc_media_player );
994 gcv.foreground = BlackPixel( p_display, 0 );
995 gc = XCreateGC( p_display, control, GCForeground, &gcv );
997 XFillRectangle( p_display, control, gc,
998 0, 0, window.width, i_tb_height );
999 gcv.foreground = WhitePixel( p_display, 0 );
1000 XChangeGC( p_display, gc, GCForeground, &gcv );
1002 /* position icons */
1004 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
1006 if( p_btnPause && (is_playing == 1) )
1008 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
1009 dst_y - (p_btnPause->height >> 1),
1010 p_btnPause->width, p_btnPause->height );
1011 dst_x += BTN_SPACE + p_btnPause->width;
1013 else if( p_btnPlay )
1015 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
1016 dst_y - (p_btnPlay->height >> 1),
1017 p_btnPlay->width, p_btnPlay->height );
1018 dst_x += BTN_SPACE + p_btnPlay->width;
1022 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
1023 dst_y - (p_btnStop->height >> 1),
1024 p_btnStop->width, p_btnStop->height );
1026 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
1028 if( p_btnFullscreen )
1029 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
1030 dst_y - (p_btnFullscreen->height >> 1),
1031 p_btnFullscreen->width, p_btnFullscreen->height );
1033 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
1035 if( p_btnUnmute && b_mute )
1037 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
1038 dst_y - (p_btnUnmute->height >> 1),
1039 p_btnUnmute->width, p_btnUnmute->height );
1041 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
1043 else if( p_btnMute )
1045 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
1046 dst_y - (p_btnMute->height >> 1),
1047 p_btnMute->width, p_btnMute->height );
1049 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
1053 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
1054 dst_y - (p_timeline->height >> 1),
1055 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
1057 /* get movie position in % */
1058 if( playlist_isplaying() )
1060 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
1061 libvlc_media_player_get_position(libvlc_media_player));
1065 XPutImage( p_display, control, gc, p_btnTime,
1066 0, 0, (dst_x+i_last_position),
1067 dst_y - (p_btnTime->height >> 1),
1068 p_btnTime->width, p_btnTime->height );
1070 XFreeGC( p_display, gc );
1073 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
1075 unsigned int i_dest = BTN_SPACE;
1077 bool b_mute = false;
1080 fprintf( stderr, "ToolbarButtonClicked:: "
1081 "trying to match (%d,%d) (%d,%d)\n",
1082 i_xpos, i_ypos, i_tb_height, i_tb_width );
1084 if( i_ypos >= i_tb_width )
1085 return clicked_Unknown;
1087 /* Note: the order of testing is dependend on the original
1088 * drawing positions of the icon buttons. Buttons are tested
1093 is_playing = playlist_isplaying();
1096 if( libvlc_media_player )
1097 b_mute = libvlc_audio_get_mute( libvlc_media_player );
1099 /* is Pause of Play button clicked */
1100 if( (is_playing != 1) &&
1101 (i_xpos >= (BTN_SPACE>>1)) &&
1102 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1103 return clicked_Play;
1104 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1105 (i_xpos <= i_dest + p_btnPause->width) )
1106 return clicked_Pause;
1108 /* is Stop button clicked */
1109 if( is_playing != 1 )
1110 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1112 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1114 if( (i_xpos >= i_dest) &&
1115 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1116 return clicked_Stop;
1118 /* is Fullscreen button clicked */
1119 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1120 if( (i_xpos >= i_dest) &&
1121 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1122 return clicked_Fullscreen;
1124 /* is Mute or Unmute button clicked */
1125 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1126 if( !b_mute && (i_xpos >= i_dest) &&
1127 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1128 return clicked_Mute;
1129 else if( (i_xpos >= i_dest) &&
1130 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1131 return clicked_Unmute;
1133 /* is timeline clicked */
1135 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1137 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1138 if( (i_xpos >= i_dest) &&
1139 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1140 return clicked_timeline;
1142 /* is time button clicked */
1143 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1144 if( (i_xpos >= i_dest) &&
1145 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1146 return clicked_Time;
1148 return clicked_Unknown;
1153 // Verifies the version of the NPAPI.
1154 // The eventListeners use a NPAPI function available
1156 bool VlcPlugin::canUseEventListener()
1158 int plugin_major, plugin_minor;
1159 int browser_major, browser_minor;
1161 NPN_Version(&plugin_major, &plugin_minor,
1162 &browser_major, &browser_minor);
1164 if (browser_minor >= 19 || browser_major > 0)