1 /*****************************************************************************
2 * vlcplugin.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2009 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 /*****************************************************************************
43 * VlcPlugin constructor and destructor
44 *****************************************************************************/
45 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
53 libvlc_instance(NULL),
54 libvlc_media_list(NULL),
55 libvlc_media_player(NULL),
63 ,i_width((unsigned)-1)
64 ,i_height((unsigned)-1)
73 ,p_btnFullscreen(NULL)
78 memset(&npwindow, 0, sizeof(NPWindow));
80 memset(&npvideo, 0, sizeof(Window));
81 memset(&npcontrol, 0, sizeof(Window));
85 static bool boolValue(const char *value) {
86 return ( !strcmp(value, "1") ||
87 !strcasecmp(value, "true") ||
88 !strcasecmp(value, "yes") );
92 void EventObj::deliver(NPP browser)
97 pthread_mutex_lock(&mutex);
99 for( ev_l::iterator i=_elist.begin();i!=_elist.end();++i )
101 libvlc_event_type_t event = *i;
102 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
104 // Invalid events aren't supposed to be queued up.
105 // if( !have_event(event) ) continue;
107 for( lr_l::iterator j=_llist.begin();j!=_llist.end();++j )
111 NPN_InvokeDefault(browser, j->listener(), params, 1, &result);
112 NPN_ReleaseVariantValue(&result);
118 pthread_mutex_unlock(&mutex);
121 void VlcPlugin::eventAsync(void *param)
123 VlcPlugin *plugin = (VlcPlugin*)param;
124 plugin->events.deliver(plugin->getBrowser());
127 void EventObj::callback(const libvlc_event_t* event)
129 pthread_mutex_lock(&mutex);
131 if( have_event(event->type) )
132 _elist.push_back(event->type);
134 pthread_mutex_unlock(&mutex);
137 void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
139 VlcPlugin *plugin = (VlcPlugin*)param;
141 plugin->events.callback(event);
142 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
144 #warning NPN_PluginThreadAsyncCall not implemented yet.
145 printf("%s","No NPN_PluginThreadAsyncCall(), doing nothing.");
149 inline EventObj::event_t EventObj::find_event(const char *s) const
152 for(i=0;i<maxbit();++i)
153 if(!strcmp(s,libvlc_event_type_name(i)))
158 bool EventObj::insert(const NPString &s, NPObject *l, bool b)
160 event_t e = find_event(s.utf8characters);
164 if( !have_event(e) && !ask_for_event(e) )
168 for(i=_llist.begin();i!=_llist.end();++i)
169 if(i->listener()==l && i->bubble()==b)
172 if( i == _llist.end() ) {
173 _llist.push_back(Listener(e,l,b));
183 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
185 event_t e = find_event(s.utf8characters);
186 if( e>=maxbit() || !get(e) )
190 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
192 if(i->listener()!=l || i->bubble()!=b)
212 void EventObj::hook_manager(libvlc_event_manager_t *em,
213 libvlc_callback_t cb, void *udata)
215 _em = em; _cb = cb; _ud = udata;
218 for(size_t i=0;i<maxbit();++i)
220 libvlc_event_attach(_em, i, _cb, _ud);
223 void EventObj::unhook_manager()
227 for(size_t i=0;i<maxbit();++i)
229 libvlc_event_detach(_em, i, _cb, _ud);
233 bool EventObj::ask_for_event(event_t e)
235 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
239 void EventObj::unask_for_event(event_t e)
241 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
245 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
247 /* prepare VLC command line */
248 const char *ppsz_argv[32];
252 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
255 /* locate VLC module path */
257 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
258 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
259 #elif defined(XP_WIN)
261 DWORD i_type, i_data = MAX_PATH + 1;
262 char p_data[MAX_PATH + 1];
263 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
264 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
266 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
267 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
269 if( i_type == REG_SZ )
271 strcat( p_data, "\\plugins" );
272 ppsz_argv[ppsz_argc++] = "--plugin-path";
273 ppsz_argv[ppsz_argc++] = p_data;
276 RegCloseKey( h_key );
278 ppsz_argv[ppsz_argc++] = "--no-one-instance";
280 #endif /* XP_MACOSX */
282 /* common settings */
283 ppsz_argv[ppsz_argc++] = "-vv";
284 ppsz_argv[ppsz_argc++] = "--no-stats";
285 ppsz_argv[ppsz_argc++] = "--no-media-library";
286 ppsz_argv[ppsz_argc++] = "--intf=dummy";
287 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
289 const char *progid = NULL;
291 /* parse plugin arguments */
292 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
294 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
296 if( !strcmp( argn[i], "target" )
297 || !strcmp( argn[i], "mrl")
298 || !strcmp( argn[i], "filename")
299 || !strcmp( argn[i], "src") )
301 psz_target = argv[i];
303 else if( !strcmp( argn[i], "text" ) )
306 psz_text = strdup( argv[i] );
308 else if( !strcmp( argn[i], "autoplay")
309 || !strcmp( argn[i], "autostart") )
311 b_autoplay = boolValue(argv[i]);
313 else if( !strcmp( argn[i], "fullscreen" ) )
315 if( boolValue(argv[i]) )
317 ppsz_argv[ppsz_argc++] = "--fullscreen";
321 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
324 else if( !strcmp( argn[i], "mute" ) )
326 if( boolValue(argv[i]) )
328 ppsz_argv[ppsz_argc++] = "--volume=0";
331 else if( !strcmp( argn[i], "loop")
332 || !strcmp( argn[i], "autoloop") )
334 if( boolValue(argv[i]) )
336 ppsz_argv[ppsz_argc++] = "--loop";
340 ppsz_argv[ppsz_argc++] = "--no-loop";
343 else if( !strcmp( argn[i], "version")
344 || !strcmp( argn[i], "progid") )
348 else if( !strcmp( argn[i], "toolbar" ) )
350 /* FIXME: Remove this when toolbar functionality has been implemented on
351 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
353 b_toolbar = boolValue(argv[i]);
358 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
359 if( !libvlc_instance )
360 return NPERR_GENERIC_ERROR;
361 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
364 ** fetch plugin base URL, which is the URL of the page containing the plugin
365 ** this URL is used for making absolute URL from relative URL that may be
366 ** passed as an MRL argument
368 NPObject *plugin = NULL;
370 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
373 ** is there a better way to get that info ?
375 static const char docLocHref[] = "document.location.href";
379 script.utf8characters = docLocHref;
380 script.utf8length = sizeof(docLocHref)-1;
382 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
384 if( NPVARIANT_IS_STRING(result) )
386 NPString &location = NPVARIANT_TO_STRING(result);
388 psz_baseURL = (char *) malloc(location.utf8length+1);
391 strncpy(psz_baseURL, location.utf8characters, location.utf8length);
392 psz_baseURL[location.utf8length] = '\0';
395 NPN_ReleaseVariantValue(&result);
397 NPN_ReleaseObject(plugin);
402 // get absolute URL from src
403 char *psz_absurl = getAbsoluteURL(psz_target);
404 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
407 /* assign plugin script root class */
409 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
412 return NPERR_GENERIC_ERROR;
414 return NPERR_NO_ERROR;
417 VlcPlugin::~VlcPlugin()
423 if( libvlc_media_player )
425 events.unhook_manager();
426 libvlc_media_player_release( libvlc_media_player );
428 if( libvlc_media_list )
429 libvlc_media_list_release( libvlc_media_list );
430 if( libvlc_instance )
431 libvlc_release(libvlc_instance);
434 /*****************************************************************************
435 * VlcPlugin playlist replacement methods
436 *****************************************************************************/
437 void VlcPlugin::set_player_window()
440 libvlc_media_player_set_xwindow(libvlc_media_player,
441 (libvlc_drawable_t)getVideoWindow());
444 // XXX FIXME insert appropriate call here
447 libvlc_media_player_set_hwnd(libvlc_media_player,
452 int VlcPlugin::playlist_add( const char *mrl, libvlc_exception_t *ex )
455 libvlc_media_t *p_m = libvlc_media_new(libvlc_instance,mrl);
459 libvlc_media_list_lock(libvlc_media_list);
460 libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
461 if( !libvlc_exception_raised(ex) )
462 item = libvlc_media_list_count(libvlc_media_list)-1;
463 libvlc_media_list_unlock(libvlc_media_list);
465 libvlc_media_release(p_m);
470 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
471 int optc, const char **optv, libvlc_exception_t *ex )
473 libvlc_media_t *p_m = libvlc_media_new(libvlc_instance, mrl);
478 for( int i = 0; i < optc; ++i )
479 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
481 libvlc_media_list_lock(libvlc_media_list);
482 libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
483 if( !libvlc_exception_raised(ex) )
484 item = libvlc_media_list_count(libvlc_media_list)-1;
485 libvlc_media_list_unlock(libvlc_media_list);
486 libvlc_media_release(p_m);
491 bool VlcPlugin::playlist_select( int idx, libvlc_exception_t *ex )
493 libvlc_media_t *p_m = NULL;
495 libvlc_media_list_lock(libvlc_media_list);
497 int count = libvlc_media_list_count(libvlc_media_list);
499 if( idx<0||idx>=count )
502 playlist_index = idx;
504 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index,ex);
505 libvlc_media_list_unlock(libvlc_media_list);
507 if( libvlc_exception_raised(ex) )
510 if( libvlc_media_player )
512 events.unhook_manager();
513 libvlc_media_player_release( libvlc_media_player );
514 libvlc_media_player = NULL;
517 libvlc_media_player = libvlc_media_player_new_from_media(p_m);
518 if( libvlc_media_player )
522 libvlc_media_player_event_manager(libvlc_media_player),
523 event_callback, this);
526 libvlc_media_release( p_m );
530 libvlc_media_list_unlock(libvlc_media_list);
534 void VlcPlugin::playlist_delete_item( int idx, libvlc_exception_t *ex )
536 libvlc_media_list_lock(libvlc_media_list);
537 libvlc_media_list_remove_index(libvlc_media_list,idx,ex);
538 libvlc_media_list_unlock(libvlc_media_list);
541 void VlcPlugin::playlist_clear()
543 if( libvlc_media_list )
544 libvlc_media_list_release(libvlc_media_list);
545 libvlc_media_list = libvlc_media_list_new(getVLC());
548 int VlcPlugin::playlist_count()
551 libvlc_media_list_lock(libvlc_media_list);
552 items_count = libvlc_media_list_count(libvlc_media_list);
553 libvlc_media_list_unlock(libvlc_media_list);
557 void VlcPlugin::toggle_fullscreen()
559 if( playlist_isplaying() )
560 libvlc_toggle_fullscreen(libvlc_media_player);
562 void VlcPlugin::set_fullscreen( int yes)
564 if( playlist_isplaying() )
565 libvlc_set_fullscreen(libvlc_media_player,yes);
567 int VlcPlugin::get_fullscreen()
570 if( playlist_isplaying() )
571 r = libvlc_get_fullscreen(libvlc_media_player);
575 bool VlcPlugin::player_has_vout()
578 if( playlist_isplaying() )
579 r = libvlc_media_player_has_vout(libvlc_media_player);
583 /*****************************************************************************
585 *****************************************************************************/
587 char *VlcPlugin::getAbsoluteURL(const char *url)
591 // check whether URL is already absolute
592 const char *end=strchr(url, ':');
593 if( (NULL != end) && (end != url) )
595 // validate protocol header
596 const char *start = url;
601 while( start != end )
608 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
609 // not valid protocol header, assume relative URL
613 /* we have a protocol header, therefore URL is absolute */
616 // not a valid protocol header, assume relative URL
623 size_t baseLen = strlen(psz_baseURL);
624 char *href = (char *) malloc(baseLen+strlen(url)+1);
627 /* prepend base URL */
628 memcpy(href, psz_baseURL, baseLen+1);
631 ** relative url could be empty,
632 ** in which case return base URL
638 ** locate pathname part of base URL
641 /* skip over protocol part */
642 char *pathstart = strchr(href, ':');
643 char *pathend = href+baseLen;
646 if( '/' == *(++pathstart) )
648 if( '/' == *(++pathstart) )
653 /* skip over host part */
654 pathstart = strchr(pathstart, '/');
657 // no path, add a / past end of url (over '\0')
664 /* baseURL is just a UNIX path */
667 /* baseURL is not an absolute path */
674 /* relative URL made of an absolute path ? */
677 /* replace path completely */
678 strcpy(pathstart, url);
682 /* find last path component and replace it */
683 while( '/' != *pathend)
687 ** if relative url path starts with one or more '../',
688 ** factor them out of href so that we return a
691 while( pathend != pathstart )
699 /* relative url is just '.' */
705 /* relative url starts with './' */
714 /* relative url is '..' */
720 /* relative url starts with '../' */
728 while( '/' != *pathend );
730 /* skip over '/' separator */
732 /* concatenate remaining base URL and relative URL */
733 strcpy(pathend, url);
742 int VlcPlugin::setSize(unsigned width, unsigned height)
744 int diff = (width != i_width) || (height != i_height);
753 #define BTN_SPACE ((unsigned int)4)
754 void VlcPlugin::showToolbar()
756 const NPWindow& window = getWindow();
757 Window control = getControlWindow();
758 Window video = getVideoWindow();
759 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
760 unsigned int i_height = 0, i_width = BTN_SPACE;
764 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
765 &p_btnPlay, NULL, NULL);
768 i_height = __MAX( i_height, p_btnPlay->height );
771 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
772 &p_btnPause, NULL, NULL);
775 i_height = __MAX( i_height, p_btnPause->height );
777 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
780 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
781 &p_btnStop, NULL, NULL );
784 i_height = __MAX( i_height, p_btnStop->height );
785 i_width += BTN_SPACE + p_btnStop->width;
788 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
789 &p_timeline, NULL, NULL);
792 i_height = __MAX( i_height, p_timeline->height );
793 i_width += BTN_SPACE + p_timeline->width;
796 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
797 &p_btnTime, NULL, NULL);
800 i_height = __MAX( i_height, p_btnTime->height );
801 i_width += BTN_SPACE + p_btnTime->width;
803 if( !p_btnFullscreen )
804 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
805 &p_btnFullscreen, NULL, NULL);
806 if( p_btnFullscreen )
808 i_height = __MAX( i_height, p_btnFullscreen->height );
809 i_width += BTN_SPACE + p_btnFullscreen->width;
812 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
813 &p_btnMute, NULL, NULL);
816 i_height = __MAX( i_height, p_btnMute->height );
819 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
820 &p_btnUnmute, NULL, NULL);
823 i_height = __MAX( i_height, p_btnUnmute->height );
825 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
827 setToolbarSize( i_width, i_height );
829 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
830 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
831 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
833 /* reset panels position and size */
834 /* XXX use i_width */
835 XResizeWindow( p_display, video, window.width, window.height - i_height);
836 XMoveWindow( p_display, control, 0, window.height - i_height );
837 XResizeWindow( p_display, control, window.width, i_height -1);
839 b_toolbar = 1; /* says toolbar is now shown */
843 void VlcPlugin::hideToolbar()
845 const NPWindow& window = getWindow();
846 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
847 Window control = getControlWindow();
848 Window video = getVideoWindow();
850 i_tb_width = i_tb_height = 0;
852 if( p_btnPlay ) XDestroyImage( p_btnPlay );
853 if( p_btnPause ) XDestroyImage( p_btnPause );
854 if( p_btnStop ) XDestroyImage( p_btnStop );
855 if( p_timeline ) XDestroyImage( p_timeline );
856 if( p_btnTime ) XDestroyImage( p_btnTime );
857 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
858 if( p_btnMute ) XDestroyImage( p_btnMute );
859 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
866 p_btnFullscreen = NULL;
870 /* reset panels position and size */
871 /* XXX use i_width */
872 XResizeWindow( p_display, video, window.width, window.height );
873 XMoveWindow( p_display, control, 0, window.height-1 );
874 XResizeWindow( p_display, control, window.width, 1 );
876 b_toolbar = 0; /* says toolbar is now hidden */
880 void VlcPlugin::redrawToolbar()
884 unsigned int dst_x, dst_y;
887 unsigned int i_tb_width, i_tb_height;
889 /* This method does nothing if toolbar is hidden. */
893 const NPWindow& window = getWindow();
894 Window control = getControlWindow();
895 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
897 getToolbarSize( &i_tb_width, &i_tb_height );
901 b_mute = libvlc_audio_get_mute( libvlc_media_player );
903 gcv.foreground = BlackPixel( p_display, 0 );
904 gc = XCreateGC( p_display, control, GCForeground, &gcv );
906 XFillRectangle( p_display, control, gc,
907 0, 0, window.width, i_tb_height );
908 gcv.foreground = WhitePixel( p_display, 0 );
909 XChangeGC( p_display, gc, GCForeground, &gcv );
913 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
915 if( p_btnPause && (is_playing == 1) )
917 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
918 dst_y - (p_btnPause->height >> 1),
919 p_btnPause->width, p_btnPause->height );
920 dst_x += BTN_SPACE + p_btnPause->width;
924 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
925 dst_y - (p_btnPlay->height >> 1),
926 p_btnPlay->width, p_btnPlay->height );
927 dst_x += BTN_SPACE + p_btnPlay->width;
931 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
932 dst_y - (p_btnStop->height >> 1),
933 p_btnStop->width, p_btnStop->height );
935 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
937 if( p_btnFullscreen )
938 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
939 dst_y - (p_btnFullscreen->height >> 1),
940 p_btnFullscreen->width, p_btnFullscreen->height );
942 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
944 if( p_btnUnmute && b_mute )
946 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
947 dst_y - (p_btnUnmute->height >> 1),
948 p_btnUnmute->width, p_btnUnmute->height );
950 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
954 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
955 dst_y - (p_btnMute->height >> 1),
956 p_btnMute->width, p_btnMute->height );
958 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
962 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
963 dst_y - (p_timeline->height >> 1),
964 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
966 /* get movie position in % */
967 if( playlist_isplaying() )
969 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
970 libvlc_media_player_get_position(libvlc_media_player));
974 XPutImage( p_display, control, gc, p_btnTime,
975 0, 0, (dst_x+i_last_position),
976 dst_y - (p_btnTime->height >> 1),
977 p_btnTime->width, p_btnTime->height );
979 XFreeGC( p_display, gc );
982 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
984 unsigned int i_dest = BTN_SPACE;
989 fprintf( stderr, "ToolbarButtonClicked:: "
990 "trying to match (%d,%d) (%d,%d)\n",
991 i_xpos, i_ypos, i_tb_height, i_tb_width );
993 if( i_ypos >= i_tb_width )
994 return clicked_Unknown;
996 /* Note: the order of testing is dependend on the original
997 * drawing positions of the icon buttons. Buttons are tested
1002 is_playing = playlist_isplaying();
1005 b_mute = libvlc_audio_get_mute( libvlc_media_player );
1007 /* is Pause of Play button clicked */
1008 if( (is_playing != 1) &&
1009 (i_xpos >= (BTN_SPACE>>1)) &&
1010 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1011 return clicked_Play;
1012 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1013 (i_xpos <= i_dest + p_btnPause->width) )
1014 return clicked_Pause;
1016 /* is Stop button clicked */
1017 if( is_playing != 1 )
1018 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1020 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1022 if( (i_xpos >= i_dest) &&
1023 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1024 return clicked_Stop;
1026 /* is Fullscreen button clicked */
1027 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1028 if( (i_xpos >= i_dest) &&
1029 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1030 return clicked_Fullscreen;
1032 /* is Mute or Unmute button clicked */
1033 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1034 if( !b_mute && (i_xpos >= i_dest) &&
1035 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1036 return clicked_Mute;
1037 else if( (i_xpos >= i_dest) &&
1038 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1039 return clicked_Unmute;
1041 /* is timeline clicked */
1043 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1045 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1046 if( (i_xpos >= i_dest) &&
1047 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1048 return clicked_timeline;
1050 /* is time button clicked */
1051 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1052 if( (i_xpos >= i_dest) &&
1053 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1054 return clicked_Time;
1056 return clicked_Unknown;
1061 // Verifies the version of the NPAPI.
1062 // The eventListeners use a NPAPI function available
1064 bool VlcPlugin::canUseEventListener()
1066 int plugin_major, plugin_minor;
1067 int browser_major, browser_minor;
1069 NPN_Version(&plugin_major, &plugin_minor,
1070 &browser_major, &browser_minor);
1072 if (browser_minor >= 19 || browser_major > 0)