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));
182 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
184 event_t e = find_event(s.utf8characters);
185 if( e>=maxbit() || !get(e) )
189 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
191 if(i->listener()!=l || i->bubble()!=b)
209 void EventObj::hook_manager(libvlc_event_manager_t *em,
210 libvlc_callback_t cb, void *udata)
212 _em = em; _cb = cb; _ud = udata;
215 for(size_t i=0;i<maxbit();++i)
217 libvlc_event_attach(_em, i, _cb, _ud);
220 void EventObj::unhook_manager()
224 for(size_t i=0;i<maxbit();++i)
226 libvlc_event_detach(_em, i, _cb, _ud);
230 bool EventObj::ask_for_event(event_t e)
232 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
236 void EventObj::unask_for_event(event_t e)
238 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
242 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
244 /* prepare VLC command line */
245 const char *ppsz_argv[32];
249 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
252 /* locate VLC module path */
254 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
255 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
256 #elif defined(XP_WIN)
258 DWORD i_type, i_data = MAX_PATH + 1;
259 char p_data[MAX_PATH + 1];
260 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
261 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
263 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
264 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
266 if( i_type == REG_SZ )
268 strcat( p_data, "\\plugins" );
269 ppsz_argv[ppsz_argc++] = "--plugin-path";
270 ppsz_argv[ppsz_argc++] = p_data;
273 RegCloseKey( h_key );
275 ppsz_argv[ppsz_argc++] = "--no-one-instance";
277 #endif /* XP_MACOSX */
279 /* common settings */
280 ppsz_argv[ppsz_argc++] = "-vv";
281 ppsz_argv[ppsz_argc++] = "--no-stats";
282 ppsz_argv[ppsz_argc++] = "--no-media-library";
283 ppsz_argv[ppsz_argc++] = "--intf=dummy";
284 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
286 const char *progid = NULL;
288 /* parse plugin arguments */
289 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
291 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
293 if( !strcmp( argn[i], "target" )
294 || !strcmp( argn[i], "mrl")
295 || !strcmp( argn[i], "filename")
296 || !strcmp( argn[i], "src") )
298 psz_target = argv[i];
300 else if( !strcmp( argn[i], "text" ) )
303 psz_text = strdup( argv[i] );
305 else if( !strcmp( argn[i], "autoplay")
306 || !strcmp( argn[i], "autostart") )
308 b_autoplay = boolValue(argv[i]);
310 else if( !strcmp( argn[i], "fullscreen" ) )
312 if( boolValue(argv[i]) )
314 ppsz_argv[ppsz_argc++] = "--fullscreen";
318 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
321 else if( !strcmp( argn[i], "mute" ) )
323 if( boolValue(argv[i]) )
325 ppsz_argv[ppsz_argc++] = "--volume=0";
328 else if( !strcmp( argn[i], "loop")
329 || !strcmp( argn[i], "autoloop") )
331 if( boolValue(argv[i]) )
333 ppsz_argv[ppsz_argc++] = "--loop";
337 ppsz_argv[ppsz_argc++] = "--no-loop";
340 else if( !strcmp( argn[i], "version")
341 || !strcmp( argn[i], "progid") )
345 else if( !strcmp( argn[i], "toolbar" ) )
347 /* FIXME: Remove this when toolbar functionality has been implemented on
348 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
350 b_toolbar = boolValue(argv[i]);
355 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
356 if( !libvlc_instance )
357 return NPERR_GENERIC_ERROR;
358 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
361 ** fetch plugin base URL, which is the URL of the page containing the plugin
362 ** this URL is used for making absolute URL from relative URL that may be
363 ** passed as an MRL argument
365 NPObject *plugin = NULL;
367 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
370 ** is there a better way to get that info ?
372 static const char docLocHref[] = "document.location.href";
376 script.utf8characters = docLocHref;
377 script.utf8length = sizeof(docLocHref)-1;
379 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
381 if( NPVARIANT_IS_STRING(result) )
383 NPString &location = NPVARIANT_TO_STRING(result);
385 psz_baseURL = (char *) malloc(location.utf8length+1);
388 strncpy(psz_baseURL, location.utf8characters, location.utf8length);
389 psz_baseURL[location.utf8length] = '\0';
392 NPN_ReleaseVariantValue(&result);
394 NPN_ReleaseObject(plugin);
399 // get absolute URL from src
400 char *psz_absurl = getAbsoluteURL(psz_target);
401 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
404 /* assign plugin script root class */
406 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
409 return NPERR_GENERIC_ERROR;
411 return NPERR_NO_ERROR;
414 VlcPlugin::~VlcPlugin()
420 if( libvlc_media_player )
422 events.unhook_manager();
423 libvlc_media_player_release( libvlc_media_player );
425 if( libvlc_media_list )
426 libvlc_media_list_release( libvlc_media_list );
427 if( libvlc_instance )
428 libvlc_release(libvlc_instance);
431 /*****************************************************************************
432 * VlcPlugin playlist replacement methods
433 *****************************************************************************/
434 void VlcPlugin::set_player_window()
437 libvlc_media_player_set_xwindow(libvlc_media_player,
438 (libvlc_drawable_t)getVideoWindow());
441 // XXX FIXME insert appropriate call here
444 libvlc_media_player_set_hwnd(libvlc_media_player,
449 int VlcPlugin::playlist_add( const char *mrl, libvlc_exception_t *ex )
452 libvlc_media_t *p_m = libvlc_media_new(libvlc_instance,mrl,ex);
453 if( libvlc_exception_raised(ex) )
456 libvlc_media_list_lock(libvlc_media_list);
457 libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
458 if( !libvlc_exception_raised(ex) )
459 item = libvlc_media_list_count(libvlc_media_list)-1;
460 libvlc_media_list_unlock(libvlc_media_list);
462 libvlc_media_release(p_m);
467 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
468 int optc, const char **optv, libvlc_exception_t *ex )
470 libvlc_media_t *p_m = libvlc_media_new(libvlc_instance, mrl,ex);
472 if( libvlc_exception_raised(ex) )
475 for( int i = 0; i < optc; ++i )
476 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
478 libvlc_media_list_lock(libvlc_media_list);
479 libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
480 if( !libvlc_exception_raised(ex) )
481 item = libvlc_media_list_count(libvlc_media_list)-1;
482 libvlc_media_list_unlock(libvlc_media_list);
483 libvlc_media_release(p_m);
488 bool VlcPlugin::playlist_select( int idx, libvlc_exception_t *ex )
490 libvlc_media_t *p_m = NULL;
492 libvlc_media_list_lock(libvlc_media_list);
494 int count = libvlc_media_list_count(libvlc_media_list);
496 if( idx<0||idx>=count )
499 playlist_index = idx;
501 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index,ex);
502 libvlc_media_list_unlock(libvlc_media_list);
504 if( libvlc_exception_raised(ex) )
507 if( libvlc_media_player )
509 events.unhook_manager();
510 libvlc_media_player_release( libvlc_media_player );
511 libvlc_media_player = NULL;
514 libvlc_media_player = libvlc_media_player_new_from_media(p_m);
515 if( libvlc_media_player )
519 libvlc_media_player_event_manager(libvlc_media_player),
520 event_callback, this);
523 libvlc_media_release( p_m );
527 libvlc_media_list_unlock(libvlc_media_list);
531 void VlcPlugin::playlist_delete_item( int idx, libvlc_exception_t *ex )
533 libvlc_media_list_lock(libvlc_media_list);
534 libvlc_media_list_remove_index(libvlc_media_list,idx,ex);
535 libvlc_media_list_unlock(libvlc_media_list);
538 void VlcPlugin::playlist_clear( libvlc_exception_t *ex )
540 if( libvlc_media_list )
541 libvlc_media_list_release(libvlc_media_list);
542 libvlc_media_list = libvlc_media_list_new(getVLC());
545 int VlcPlugin::playlist_count()
548 libvlc_media_list_lock(libvlc_media_list);
549 items_count = libvlc_media_list_count(libvlc_media_list);
550 libvlc_media_list_unlock(libvlc_media_list);
554 void VlcPlugin::toggle_fullscreen( libvlc_exception_t *ex )
556 if( playlist_isplaying() )
557 libvlc_toggle_fullscreen(libvlc_media_player,ex);
559 void VlcPlugin::set_fullscreen( int yes, libvlc_exception_t *ex )
561 if( playlist_isplaying() )
562 libvlc_set_fullscreen(libvlc_media_player,yes,ex);
564 int VlcPlugin::get_fullscreen( libvlc_exception_t *ex )
567 if( playlist_isplaying() )
568 r = libvlc_get_fullscreen(libvlc_media_player,ex);
572 bool VlcPlugin::player_has_vout( libvlc_exception_t *ex )
575 if( playlist_isplaying() )
576 r = libvlc_media_player_has_vout(libvlc_media_player);
580 /*****************************************************************************
582 *****************************************************************************/
584 char *VlcPlugin::getAbsoluteURL(const char *url)
588 // check whether URL is already absolute
589 const char *end=strchr(url, ':');
590 if( (NULL != end) && (end != url) )
592 // validate protocol header
593 const char *start = url;
598 while( start != end )
605 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
606 // not valid protocol header, assume relative URL
610 /* we have a protocol header, therefore URL is absolute */
613 // not a valid protocol header, assume relative URL
620 size_t baseLen = strlen(psz_baseURL);
621 char *href = (char *) malloc(baseLen+strlen(url)+1);
624 /* prepend base URL */
625 memcpy(href, psz_baseURL, baseLen+1);
628 ** relative url could be empty,
629 ** in which case return base URL
635 ** locate pathname part of base URL
638 /* skip over protocol part */
639 char *pathstart = strchr(href, ':');
640 char *pathend = href+baseLen;
643 if( '/' == *(++pathstart) )
645 if( '/' == *(++pathstart) )
650 /* skip over host part */
651 pathstart = strchr(pathstart, '/');
654 // no path, add a / past end of url (over '\0')
661 /* baseURL is just a UNIX path */
664 /* baseURL is not an absolute path */
671 /* relative URL made of an absolute path ? */
674 /* replace path completely */
675 strcpy(pathstart, url);
679 /* find last path component and replace it */
680 while( '/' != *pathend)
684 ** if relative url path starts with one or more '../',
685 ** factor them out of href so that we return a
688 while( pathend != pathstart )
696 /* relative url is just '.' */
702 /* relative url starts with './' */
711 /* relative url is '..' */
717 /* relative url starts with '../' */
725 while( '/' != *pathend );
727 /* skip over '/' separator */
729 /* concatenate remaining base URL and relative URL */
730 strcpy(pathend, url);
739 int VlcPlugin::setSize(unsigned width, unsigned height)
741 int diff = (width != i_width) || (height != i_height);
750 #define BTN_SPACE ((unsigned int)4)
751 void VlcPlugin::showToolbar()
753 const NPWindow& window = getWindow();
754 Window control = getControlWindow();
755 Window video = getVideoWindow();
756 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
757 unsigned int i_height = 0, i_width = BTN_SPACE;
761 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
762 &p_btnPlay, NULL, NULL);
765 i_height = __MAX( i_height, p_btnPlay->height );
768 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
769 &p_btnPause, NULL, NULL);
772 i_height = __MAX( i_height, p_btnPause->height );
774 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
777 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
778 &p_btnStop, NULL, NULL );
781 i_height = __MAX( i_height, p_btnStop->height );
782 i_width += BTN_SPACE + p_btnStop->width;
785 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
786 &p_timeline, NULL, NULL);
789 i_height = __MAX( i_height, p_timeline->height );
790 i_width += BTN_SPACE + p_timeline->width;
793 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
794 &p_btnTime, NULL, NULL);
797 i_height = __MAX( i_height, p_btnTime->height );
798 i_width += BTN_SPACE + p_btnTime->width;
800 if( !p_btnFullscreen )
801 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
802 &p_btnFullscreen, NULL, NULL);
803 if( p_btnFullscreen )
805 i_height = __MAX( i_height, p_btnFullscreen->height );
806 i_width += BTN_SPACE + p_btnFullscreen->width;
809 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
810 &p_btnMute, NULL, NULL);
813 i_height = __MAX( i_height, p_btnMute->height );
816 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
817 &p_btnUnmute, NULL, NULL);
820 i_height = __MAX( i_height, p_btnUnmute->height );
822 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
824 setToolbarSize( i_width, i_height );
826 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
827 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
828 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
830 /* reset panels position and size */
831 /* XXX use i_width */
832 XResizeWindow( p_display, video, window.width, window.height - i_height);
833 XMoveWindow( p_display, control, 0, window.height - i_height );
834 XResizeWindow( p_display, control, window.width, i_height -1);
836 b_toolbar = 1; /* says toolbar is now shown */
840 void VlcPlugin::hideToolbar()
842 const NPWindow& window = getWindow();
843 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
844 Window control = getControlWindow();
845 Window video = getVideoWindow();
847 i_tb_width = i_tb_height = 0;
849 if( p_btnPlay ) XDestroyImage( p_btnPlay );
850 if( p_btnPause ) XDestroyImage( p_btnPause );
851 if( p_btnStop ) XDestroyImage( p_btnStop );
852 if( p_timeline ) XDestroyImage( p_timeline );
853 if( p_btnTime ) XDestroyImage( p_btnTime );
854 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
855 if( p_btnMute ) XDestroyImage( p_btnMute );
856 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
863 p_btnFullscreen = NULL;
867 /* reset panels position and size */
868 /* XXX use i_width */
869 XResizeWindow( p_display, video, window.width, window.height );
870 XMoveWindow( p_display, control, 0, window.height-1 );
871 XResizeWindow( p_display, control, window.width, 1 );
873 b_toolbar = 0; /* says toolbar is now hidden */
877 void VlcPlugin::redrawToolbar()
881 unsigned int dst_x, dst_y;
884 unsigned int i_tb_width, i_tb_height;
886 /* This method does nothing if toolbar is hidden. */
890 const NPWindow& window = getWindow();
891 Window control = getControlWindow();
892 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
894 getToolbarSize( &i_tb_width, &i_tb_height );
898 b_mute = libvlc_audio_get_mute( libvlc_media_player );
900 gcv.foreground = BlackPixel( p_display, 0 );
901 gc = XCreateGC( p_display, control, GCForeground, &gcv );
903 XFillRectangle( p_display, control, gc,
904 0, 0, window.width, i_tb_height );
905 gcv.foreground = WhitePixel( p_display, 0 );
906 XChangeGC( p_display, gc, GCForeground, &gcv );
910 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
912 if( p_btnPause && (is_playing == 1) )
914 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
915 dst_y - (p_btnPause->height >> 1),
916 p_btnPause->width, p_btnPause->height );
917 dst_x += BTN_SPACE + p_btnPause->width;
921 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
922 dst_y - (p_btnPlay->height >> 1),
923 p_btnPlay->width, p_btnPlay->height );
924 dst_x += BTN_SPACE + p_btnPlay->width;
928 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
929 dst_y - (p_btnStop->height >> 1),
930 p_btnStop->width, p_btnStop->height );
932 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
934 if( p_btnFullscreen )
935 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
936 dst_y - (p_btnFullscreen->height >> 1),
937 p_btnFullscreen->width, p_btnFullscreen->height );
939 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
941 if( p_btnUnmute && b_mute )
943 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
944 dst_y - (p_btnUnmute->height >> 1),
945 p_btnUnmute->width, p_btnUnmute->height );
947 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
951 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
952 dst_y - (p_btnMute->height >> 1),
953 p_btnMute->width, p_btnMute->height );
955 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
959 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
960 dst_y - (p_timeline->height >> 1),
961 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
963 /* get movie position in % */
964 if( playlist_isplaying() )
966 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
967 libvlc_media_player_get_position(libvlc_media_player));
971 XPutImage( p_display, control, gc, p_btnTime,
972 0, 0, (dst_x+i_last_position),
973 dst_y - (p_btnTime->height >> 1),
974 p_btnTime->width, p_btnTime->height );
976 XFreeGC( p_display, gc );
979 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
981 unsigned int i_dest = BTN_SPACE;
986 fprintf( stderr, "ToolbarButtonClicked:: "
987 "trying to match (%d,%d) (%d,%d)\n",
988 i_xpos, i_ypos, i_tb_height, i_tb_width );
990 if( i_ypos >= i_tb_width )
991 return clicked_Unknown;
993 /* Note: the order of testing is dependend on the original
994 * drawing positions of the icon buttons. Buttons are tested
999 is_playing = playlist_isplaying();
1002 b_mute = libvlc_audio_get_mute( libvlc_media_player );
1004 /* is Pause of Play button clicked */
1005 if( (is_playing != 1) &&
1006 (i_xpos >= (BTN_SPACE>>1)) &&
1007 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1008 return clicked_Play;
1009 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1010 (i_xpos <= i_dest + p_btnPause->width) )
1011 return clicked_Pause;
1013 /* is Stop button clicked */
1014 if( is_playing != 1 )
1015 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1017 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1019 if( (i_xpos >= i_dest) &&
1020 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1021 return clicked_Stop;
1023 /* is Fullscreen button clicked */
1024 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1025 if( (i_xpos >= i_dest) &&
1026 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1027 return clicked_Fullscreen;
1029 /* is Mute or Unmute button clicked */
1030 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1031 if( !b_mute && (i_xpos >= i_dest) &&
1032 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1033 return clicked_Mute;
1034 else if( (i_xpos >= i_dest) &&
1035 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1036 return clicked_Unmute;
1038 /* is timeline clicked */
1040 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1042 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1043 if( (i_xpos >= i_dest) &&
1044 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1045 return clicked_timeline;
1047 /* is time button clicked */
1048 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1049 if( (i_xpos >= i_dest) &&
1050 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1051 return clicked_Time;
1053 return clicked_Unknown;
1058 // Verifies the version of the NPAPI.
1059 // The eventListeners use a NPAPI function available
1061 bool VlcPlugin::canUseEventListener()
1063 int plugin_major, plugin_minor;
1064 int browser_major, browser_minor;
1066 NPN_Version(&plugin_major, &plugin_minor,
1067 &browser_major, &browser_minor);
1069 if (browser_minor >= 19 || browser_major > 0)