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"
42 #warning "locking not implemented for this platform"
47 /*****************************************************************************
48 * VlcPlugin constructor and destructor
49 *****************************************************************************/
50 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
58 libvlc_instance(NULL),
59 libvlc_media_list(NULL),
60 libvlc_media_player(NULL),
68 ,i_width((unsigned)-1)
69 ,i_height((unsigned)-1)
78 ,p_btnFullscreen(NULL)
83 memset(&npwindow, 0, sizeof(NPWindow));
85 memset(&npvideo, 0, sizeof(Window));
86 memset(&npcontrol, 0, sizeof(Window));
90 static bool boolValue(const char *value) {
91 return ( !strcmp(value, "1") ||
92 !strcasecmp(value, "true") ||
93 !strcasecmp(value, "yes") );
99 return pthread_mutex_init(&mutex, NULL) == 0;
101 #warning "locking not implemented for this platform"
105 EventObj::~EventObj()
108 pthread_mutex_destroy(&mutex);
110 #warning "locking not implemented for this platform"
114 void EventObj::deliver(NPP browser)
120 pthread_mutex_lock(&mutex);
122 #warning "locking not implemented for this platform"
124 for( ev_l::iterator i=_elist.begin();i!=_elist.end();++i )
126 libvlc_event_type_t event = *i;
127 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
129 // Invalid events aren't supposed to be queued up.
130 // if( !have_event(event) ) continue;
132 for( lr_l::iterator j=_llist.begin();j!=_llist.end();++j )
136 NPN_InvokeDefault(browser, j->listener(), params, 1, &result);
137 NPN_ReleaseVariantValue(&result);
143 pthread_mutex_unlock(&mutex);
145 #warning "locking not implemented for this platform"
149 void VlcPlugin::eventAsync(void *param)
151 VlcPlugin *plugin = (VlcPlugin*)param;
152 plugin->events.deliver(plugin->getBrowser());
155 void EventObj::callback(const libvlc_event_t* event)
158 pthread_mutex_lock(&mutex);
160 #warning "locking not implemented for this platform"
162 if( have_event(event->type) )
163 _elist.push_back(event->type);
165 pthread_mutex_unlock(&mutex);
167 #warning "locking not implemented for this platform"
171 void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
173 VlcPlugin *plugin = (VlcPlugin*)param;
175 plugin->events.callback(event);
176 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
178 #warning NPN_PluginThreadAsyncCall not implemented yet.
179 printf("%s","No NPN_PluginThreadAsyncCall(), doing nothing.");
183 inline EventObj::event_t EventObj::find_event(const char *s) const
186 for(i=0;i<maxbit();++i)
187 if(!strcmp(s,libvlc_event_type_name(i)))
192 bool EventObj::insert(const NPString &s, NPObject *l, bool b)
194 event_t e = find_event(s.utf8characters);
198 if( !have_event(e) && !ask_for_event(e) )
202 for(i=_llist.begin();i!=_llist.end();++i)
203 if(i->listener()==l && i->bubble()==b)
206 if( i == _llist.end() ) {
207 _llist.push_back(Listener(e,l,b));
217 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
219 event_t e = find_event(s.utf8characters);
220 if( e>=maxbit() || !get(e) )
224 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
226 if(i->listener()!=l || i->bubble()!=b)
246 void EventObj::hook_manager(libvlc_event_manager_t *em,
247 libvlc_callback_t cb, void *udata)
249 _em = em; _cb = cb; _ud = udata;
252 for(size_t i=0;i<maxbit();++i)
254 libvlc_event_attach(_em, i, _cb, _ud);
257 void EventObj::unhook_manager()
261 for(size_t i=0;i<maxbit();++i)
263 libvlc_event_detach(_em, i, _cb, _ud);
267 bool EventObj::ask_for_event(event_t e)
269 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
273 void EventObj::unask_for_event(event_t e)
275 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
279 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
281 /* prepare VLC command line */
282 const char *ppsz_argv[32];
286 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
289 /* locate VLC module path */
291 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
292 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
293 #elif defined(XP_WIN)
295 DWORD i_type, i_data = MAX_PATH + 1;
296 char p_data[MAX_PATH + 1];
297 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
298 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
300 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
301 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
303 if( i_type == REG_SZ )
305 strcat( p_data, "\\plugins" );
306 ppsz_argv[ppsz_argc++] = "--plugin-path";
307 ppsz_argv[ppsz_argc++] = p_data;
310 RegCloseKey( h_key );
312 ppsz_argv[ppsz_argc++] = "--no-one-instance";
314 #endif /* XP_MACOSX */
316 /* common settings */
317 ppsz_argv[ppsz_argc++] = "-vv";
318 ppsz_argv[ppsz_argc++] = "--no-stats";
319 ppsz_argv[ppsz_argc++] = "--no-media-library";
320 ppsz_argv[ppsz_argc++] = "--intf=dummy";
321 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
323 const char *progid = NULL;
325 /* parse plugin arguments */
326 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
328 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
330 if( !strcmp( argn[i], "target" )
331 || !strcmp( argn[i], "mrl")
332 || !strcmp( argn[i], "filename")
333 || !strcmp( argn[i], "src") )
335 psz_target = argv[i];
337 else if( !strcmp( argn[i], "text" ) )
340 psz_text = strdup( argv[i] );
342 else if( !strcmp( argn[i], "autoplay")
343 || !strcmp( argn[i], "autostart") )
345 b_autoplay = boolValue(argv[i]);
347 else if( !strcmp( argn[i], "fullscreen" ) )
349 if( boolValue(argv[i]) )
351 ppsz_argv[ppsz_argc++] = "--fullscreen";
355 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
358 else if( !strcmp( argn[i], "mute" ) )
360 if( boolValue(argv[i]) )
362 ppsz_argv[ppsz_argc++] = "--volume=0";
365 else if( !strcmp( argn[i], "loop")
366 || !strcmp( argn[i], "autoloop") )
368 if( boolValue(argv[i]) )
370 ppsz_argv[ppsz_argc++] = "--loop";
374 ppsz_argv[ppsz_argc++] = "--no-loop";
377 else if( !strcmp( argn[i], "version")
378 || !strcmp( argn[i], "progid") )
382 else if( !strcmp( argn[i], "toolbar" ) )
384 /* FIXME: Remove this when toolbar functionality has been implemented on
385 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
387 b_toolbar = boolValue(argv[i]);
392 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
393 if( !libvlc_instance )
394 return NPERR_GENERIC_ERROR;
395 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
398 ** fetch plugin base URL, which is the URL of the page containing the plugin
399 ** this URL is used for making absolute URL from relative URL that may be
400 ** passed as an MRL argument
402 NPObject *plugin = NULL;
404 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
407 ** is there a better way to get that info ?
409 static const char docLocHref[] = "document.location.href";
413 script.utf8characters = docLocHref;
414 script.utf8length = sizeof(docLocHref)-1;
416 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
418 if( NPVARIANT_IS_STRING(result) )
420 NPString &location = NPVARIANT_TO_STRING(result);
422 psz_baseURL = (char *) malloc(location.utf8length+1);
425 strncpy(psz_baseURL, location.utf8characters, location.utf8length);
426 psz_baseURL[location.utf8length] = '\0';
429 NPN_ReleaseVariantValue(&result);
431 NPN_ReleaseObject(plugin);
436 // get absolute URL from src
437 char *psz_absurl = getAbsoluteURL(psz_target);
438 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
441 /* assign plugin script root class */
443 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
446 return NPERR_GENERIC_ERROR;
448 return NPERR_NO_ERROR;
451 VlcPlugin::~VlcPlugin()
457 if( libvlc_media_player )
459 events.unhook_manager();
460 libvlc_media_player_release( libvlc_media_player );
462 if( libvlc_media_list )
463 libvlc_media_list_release( libvlc_media_list );
464 if( libvlc_instance )
465 libvlc_release(libvlc_instance);
468 /*****************************************************************************
469 * VlcPlugin playlist replacement methods
470 *****************************************************************************/
471 void VlcPlugin::set_player_window()
474 libvlc_media_player_set_xwindow(libvlc_media_player,
475 (uint32_t)getVideoWindow());
478 // XXX FIXME insert appropriate call here
481 libvlc_media_player_set_hwnd(libvlc_media_player,
486 int VlcPlugin::playlist_add( const char *mrl )
489 libvlc_media_t *p_m = libvlc_media_new_location(libvlc_instance,mrl);
492 assert( libvlc_media_list );
493 libvlc_media_list_lock(libvlc_media_list);
494 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
495 item = libvlc_media_list_count(libvlc_media_list)-1;
496 libvlc_media_list_unlock(libvlc_media_list);
498 libvlc_media_release(p_m);
503 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
504 int optc, const char **optv )
509 assert( libvlc_media_list );
511 p_m = libvlc_media_new_location(libvlc_instance, mrl);
515 for( int i = 0; i < optc; ++i )
516 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
518 libvlc_media_list_lock(libvlc_media_list);
519 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
520 item = libvlc_media_list_count(libvlc_media_list)-1;
521 libvlc_media_list_unlock(libvlc_media_list);
522 libvlc_media_release(p_m);
527 bool VlcPlugin::playlist_select( int idx )
529 libvlc_media_t *p_m = NULL;
531 assert( libvlc_media_list );
533 libvlc_media_list_lock(libvlc_media_list);
535 int count = libvlc_media_list_count(libvlc_media_list);
536 if( idx<0||idx>=count )
539 playlist_index = idx;
541 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index);
542 libvlc_media_list_unlock(libvlc_media_list);
547 if( libvlc_media_player )
549 if( playlist_isplaying() )
551 events.unhook_manager();
552 libvlc_media_player_release( libvlc_media_player );
553 libvlc_media_player = NULL;
556 libvlc_media_player = libvlc_media_player_new_from_media(p_m);
557 if( libvlc_media_player )
561 libvlc_media_player_event_manager(libvlc_media_player),
562 event_callback, this);
565 libvlc_media_release( p_m );
569 libvlc_media_list_unlock(libvlc_media_list);
573 int VlcPlugin::playlist_delete_item( int idx )
575 if( !libvlc_media_list )
577 libvlc_media_list_lock(libvlc_media_list);
578 int ret = libvlc_media_list_remove_index(libvlc_media_list,idx);
579 libvlc_media_list_unlock(libvlc_media_list);
583 void VlcPlugin::playlist_clear()
585 if( libvlc_media_list )
586 libvlc_media_list_release(libvlc_media_list);
587 libvlc_media_list = libvlc_media_list_new(getVLC());
590 int VlcPlugin::playlist_count()
593 if( !libvlc_media_list )
595 libvlc_media_list_lock(libvlc_media_list);
596 items_count = libvlc_media_list_count(libvlc_media_list);
597 libvlc_media_list_unlock(libvlc_media_list);
601 void VlcPlugin::toggle_fullscreen()
603 if( playlist_isplaying() )
604 libvlc_toggle_fullscreen(libvlc_media_player);
607 void VlcPlugin::set_fullscreen( int yes )
609 if( playlist_isplaying() )
610 libvlc_set_fullscreen(libvlc_media_player,yes);
613 int VlcPlugin::get_fullscreen()
616 if( playlist_isplaying() )
617 r = libvlc_get_fullscreen(libvlc_media_player);
621 bool VlcPlugin::player_has_vout()
624 if( playlist_isplaying() )
625 r = libvlc_media_player_has_vout(libvlc_media_player);
629 /*****************************************************************************
631 *****************************************************************************/
633 char *VlcPlugin::getAbsoluteURL(const char *url)
637 // check whether URL is already absolute
638 const char *end=strchr(url, ':');
639 if( (NULL != end) && (end != url) )
641 // validate protocol header
642 const char *start = url;
647 while( start != end )
654 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
655 // not valid protocol header, assume relative URL
659 /* we have a protocol header, therefore URL is absolute */
662 // not a valid protocol header, assume relative URL
669 size_t baseLen = strlen(psz_baseURL);
670 char *href = (char *) malloc(baseLen+strlen(url)+1);
673 /* prepend base URL */
674 memcpy(href, psz_baseURL, baseLen+1);
677 ** relative url could be empty,
678 ** in which case return base URL
684 ** locate pathname part of base URL
687 /* skip over protocol part */
688 char *pathstart = strchr(href, ':');
689 char *pathend = href+baseLen;
692 if( '/' == *(++pathstart) )
694 if( '/' == *(++pathstart) )
699 /* skip over host part */
700 pathstart = strchr(pathstart, '/');
703 // no path, add a / past end of url (over '\0')
710 /* baseURL is just a UNIX path */
713 /* baseURL is not an absolute path */
720 /* relative URL made of an absolute path ? */
723 /* replace path completely */
724 strcpy(pathstart, url);
728 /* find last path component and replace it */
729 while( '/' != *pathend)
733 ** if relative url path starts with one or more '../',
734 ** factor them out of href so that we return a
737 while( pathend != pathstart )
745 /* relative url is just '.' */
751 /* relative url starts with './' */
760 /* relative url is '..' */
766 /* relative url starts with '../' */
774 while( '/' != *pathend );
776 /* skip over '/' separator */
778 /* concatenate remaining base URL and relative URL */
779 strcpy(pathend, url);
788 int VlcPlugin::setSize(unsigned width, unsigned height)
790 int diff = (width != i_width) || (height != i_height);
799 #define BTN_SPACE ((unsigned int)4)
800 void VlcPlugin::showToolbar()
802 const NPWindow& window = getWindow();
803 Window control = getControlWindow();
804 Window video = getVideoWindow();
805 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
806 unsigned int i_height = 0, i_width = BTN_SPACE;
810 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
811 &p_btnPlay, NULL, NULL);
814 i_height = __MAX( i_height, p_btnPlay->height );
817 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
818 &p_btnPause, NULL, NULL);
821 i_height = __MAX( i_height, p_btnPause->height );
823 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
826 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
827 &p_btnStop, NULL, NULL );
830 i_height = __MAX( i_height, p_btnStop->height );
831 i_width += BTN_SPACE + p_btnStop->width;
834 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
835 &p_timeline, NULL, NULL);
838 i_height = __MAX( i_height, p_timeline->height );
839 i_width += BTN_SPACE + p_timeline->width;
842 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
843 &p_btnTime, NULL, NULL);
846 i_height = __MAX( i_height, p_btnTime->height );
847 i_width += BTN_SPACE + p_btnTime->width;
849 if( !p_btnFullscreen )
850 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
851 &p_btnFullscreen, NULL, NULL);
852 if( p_btnFullscreen )
854 i_height = __MAX( i_height, p_btnFullscreen->height );
855 i_width += BTN_SPACE + p_btnFullscreen->width;
858 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
859 &p_btnMute, NULL, NULL);
862 i_height = __MAX( i_height, p_btnMute->height );
865 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
866 &p_btnUnmute, NULL, NULL);
869 i_height = __MAX( i_height, p_btnUnmute->height );
871 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
873 setToolbarSize( i_width, i_height );
875 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
876 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
877 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
879 /* reset panels position and size */
880 /* XXX use i_width */
881 XResizeWindow( p_display, video, window.width, window.height - i_height);
882 XMoveWindow( p_display, control, 0, window.height - i_height );
883 XResizeWindow( p_display, control, window.width, i_height -1);
885 b_toolbar = 1; /* says toolbar is now shown */
889 void VlcPlugin::hideToolbar()
891 const NPWindow& window = getWindow();
892 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
893 Window control = getControlWindow();
894 Window video = getVideoWindow();
896 i_tb_width = i_tb_height = 0;
898 if( p_btnPlay ) XDestroyImage( p_btnPlay );
899 if( p_btnPause ) XDestroyImage( p_btnPause );
900 if( p_btnStop ) XDestroyImage( p_btnStop );
901 if( p_timeline ) XDestroyImage( p_timeline );
902 if( p_btnTime ) XDestroyImage( p_btnTime );
903 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
904 if( p_btnMute ) XDestroyImage( p_btnMute );
905 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
912 p_btnFullscreen = NULL;
916 /* reset panels position and size */
917 /* XXX use i_width */
918 XResizeWindow( p_display, video, window.width, window.height );
919 XMoveWindow( p_display, control, 0, window.height-1 );
920 XResizeWindow( p_display, control, window.width, 1 );
922 b_toolbar = 0; /* says toolbar is now hidden */
926 void VlcPlugin::redrawToolbar()
930 unsigned int dst_x, dst_y;
933 unsigned int i_tb_width, i_tb_height;
935 /* This method does nothing if toolbar is hidden. */
936 if( !b_toolbar || !libvlc_media_player )
939 const NPWindow& window = getWindow();
940 Window control = getControlWindow();
941 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
943 getToolbarSize( &i_tb_width, &i_tb_height );
946 b_mute = libvlc_audio_get_mute( libvlc_media_player );
948 gcv.foreground = BlackPixel( p_display, 0 );
949 gc = XCreateGC( p_display, control, GCForeground, &gcv );
951 XFillRectangle( p_display, control, gc,
952 0, 0, window.width, i_tb_height );
953 gcv.foreground = WhitePixel( p_display, 0 );
954 XChangeGC( p_display, gc, GCForeground, &gcv );
958 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
960 if( p_btnPause && (is_playing == 1) )
962 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
963 dst_y - (p_btnPause->height >> 1),
964 p_btnPause->width, p_btnPause->height );
965 dst_x += BTN_SPACE + p_btnPause->width;
969 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
970 dst_y - (p_btnPlay->height >> 1),
971 p_btnPlay->width, p_btnPlay->height );
972 dst_x += BTN_SPACE + p_btnPlay->width;
976 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
977 dst_y - (p_btnStop->height >> 1),
978 p_btnStop->width, p_btnStop->height );
980 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
982 if( p_btnFullscreen )
983 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
984 dst_y - (p_btnFullscreen->height >> 1),
985 p_btnFullscreen->width, p_btnFullscreen->height );
987 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
989 if( p_btnUnmute && b_mute )
991 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
992 dst_y - (p_btnUnmute->height >> 1),
993 p_btnUnmute->width, p_btnUnmute->height );
995 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
999 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
1000 dst_y - (p_btnMute->height >> 1),
1001 p_btnMute->width, p_btnMute->height );
1003 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
1007 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
1008 dst_y - (p_timeline->height >> 1),
1009 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
1011 /* get movie position in % */
1012 if( playlist_isplaying() )
1014 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
1015 libvlc_media_player_get_position(libvlc_media_player));
1019 XPutImage( p_display, control, gc, p_btnTime,
1020 0, 0, (dst_x+i_last_position),
1021 dst_y - (p_btnTime->height >> 1),
1022 p_btnTime->width, p_btnTime->height );
1024 XFreeGC( p_display, gc );
1027 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
1029 unsigned int i_dest = BTN_SPACE;
1031 bool b_mute = false;
1034 fprintf( stderr, "ToolbarButtonClicked:: "
1035 "trying to match (%d,%d) (%d,%d)\n",
1036 i_xpos, i_ypos, i_tb_height, i_tb_width );
1038 if( i_ypos >= i_tb_width )
1039 return clicked_Unknown;
1041 /* Note: the order of testing is dependend on the original
1042 * drawing positions of the icon buttons. Buttons are tested
1047 is_playing = playlist_isplaying();
1050 if( libvlc_media_player )
1051 b_mute = libvlc_audio_get_mute( libvlc_media_player );
1053 /* is Pause of Play button clicked */
1054 if( (is_playing != 1) &&
1055 (i_xpos >= (BTN_SPACE>>1)) &&
1056 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1057 return clicked_Play;
1058 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1059 (i_xpos <= i_dest + p_btnPause->width) )
1060 return clicked_Pause;
1062 /* is Stop button clicked */
1063 if( is_playing != 1 )
1064 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1066 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1068 if( (i_xpos >= i_dest) &&
1069 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1070 return clicked_Stop;
1072 /* is Fullscreen button clicked */
1073 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1074 if( (i_xpos >= i_dest) &&
1075 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1076 return clicked_Fullscreen;
1078 /* is Mute or Unmute button clicked */
1079 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1080 if( !b_mute && (i_xpos >= i_dest) &&
1081 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1082 return clicked_Mute;
1083 else if( (i_xpos >= i_dest) &&
1084 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1085 return clicked_Unmute;
1087 /* is timeline clicked */
1089 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1091 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1092 if( (i_xpos >= i_dest) &&
1093 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1094 return clicked_timeline;
1096 /* is time button clicked */
1097 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1098 if( (i_xpos >= i_dest) &&
1099 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1100 return clicked_Time;
1102 return clicked_Unknown;
1107 // Verifies the version of the NPAPI.
1108 // The eventListeners use a NPAPI function available
1110 bool VlcPlugin::canUseEventListener()
1112 int plugin_major, plugin_minor;
1113 int browser_major, browser_minor;
1115 NPN_Version(&plugin_major, &plugin_minor,
1116 &browser_major, &browser_minor);
1118 if (browser_minor >= 19 || browser_major > 0)