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"
41 /*****************************************************************************
42 * VlcPlugin constructor and destructor
43 *****************************************************************************/
44 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
52 libvlc_instance(NULL),
53 libvlc_media_list(NULL),
54 libvlc_media_player(NULL),
62 ,i_width((unsigned)-1)
63 ,i_height((unsigned)-1)
72 ,p_btnFullscreen(NULL)
77 memset(&npwindow, 0, sizeof(NPWindow));
79 memset(&npvideo, 0, sizeof(Window));
80 memset(&npcontrol, 0, sizeof(Window));
84 static bool boolValue(const char *value) {
85 return ( !strcmp(value, "1") ||
86 !strcasecmp(value, "true") ||
87 !strcasecmp(value, "yes") );
90 void eventAsync(void *param)
92 VlcPlugin *plugin = (VlcPlugin*)param;
96 pthread_mutex_lock(&plugin->mutex);
98 for (int i = 0; i < plugin->eventList.size(); i++)
100 for (int j = 0; j < plugin->eventListeners.size(); j++)
102 libvlc_event_type_t event = plugin->eventList[i];
104 if (plugin->eventListeners[j]->eventMap.have_event(event))
106 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
107 params[1] = plugin->eventListeners[j]->id;
108 NPN_InvokeDefault(plugin->getBrowser(), plugin->eventListeners[j]->listener, params, 2, &result);
109 NPN_ReleaseVariantValue(&result);
113 plugin->eventList.clear();
115 pthread_mutex_unlock(&plugin->mutex);
118 void event_callback(const libvlc_event_t* event, void *param)
120 VlcPlugin *plugin = (VlcPlugin*)param;
122 pthread_mutex_lock(&plugin->mutex);
124 if (plugin->eventToCatch.have_event(event->type))
125 plugin->eventList.push_back(event->type);
127 pthread_mutex_unlock(&plugin->mutex);
129 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
132 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
134 /* prepare VLC command line */
135 const char *ppsz_argv[32];
139 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
142 /* locate VLC module path */
144 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
145 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
146 #elif defined(XP_WIN)
148 DWORD i_type, i_data = MAX_PATH + 1;
149 char p_data[MAX_PATH + 1];
150 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
151 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
153 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
154 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
156 if( i_type == REG_SZ )
158 strcat( p_data, "\\plugins" );
159 ppsz_argv[ppsz_argc++] = "--plugin-path";
160 ppsz_argv[ppsz_argc++] = p_data;
163 RegCloseKey( h_key );
165 ppsz_argv[ppsz_argc++] = "--no-one-instance";
167 #endif /* XP_MACOSX */
169 /* common settings */
170 ppsz_argv[ppsz_argc++] = "-vv";
171 ppsz_argv[ppsz_argc++] = "--no-stats";
172 ppsz_argv[ppsz_argc++] = "--no-media-library";
173 ppsz_argv[ppsz_argc++] = "--intf=dummy";
174 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
176 const char *progid = NULL;
178 /* parse plugin arguments */
179 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
181 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
183 if( !strcmp( argn[i], "target" )
184 || !strcmp( argn[i], "mrl")
185 || !strcmp( argn[i], "filename")
186 || !strcmp( argn[i], "src") )
188 psz_target = argv[i];
190 else if( !strcmp( argn[i], "text" ) )
193 psz_text = strdup( argv[i] );
195 else if( !strcmp( argn[i], "autoplay")
196 || !strcmp( argn[i], "autostart") )
198 b_autoplay = boolValue(argv[i]);
200 else if( !strcmp( argn[i], "fullscreen" ) )
202 if( boolValue(argv[i]) )
204 ppsz_argv[ppsz_argc++] = "--fullscreen";
208 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
211 else if( !strcmp( argn[i], "mute" ) )
213 if( boolValue(argv[i]) )
215 ppsz_argv[ppsz_argc++] = "--volume=0";
218 else if( !strcmp( argn[i], "loop")
219 || !strcmp( argn[i], "autoloop") )
221 if( boolValue(argv[i]) )
223 ppsz_argv[ppsz_argc++] = "--loop";
227 ppsz_argv[ppsz_argc++] = "--no-loop";
230 else if( !strcmp( argn[i], "version")
231 || !strcmp( argn[i], "progid") )
235 else if( !strcmp( argn[i], "toolbar" ) )
237 /* FIXME: Remove this when toolbar functionality has been implemented on
238 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
240 b_toolbar = boolValue(argv[i]);
245 libvlc_exception_t ex;
246 libvlc_exception_init(&ex);
248 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, &ex);
249 if( libvlc_exception_raised(&ex) )
251 libvlc_exception_clear(&ex);
252 return NPERR_GENERIC_ERROR;
255 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
258 ** fetch plugin base URL, which is the URL of the page containing the plugin
259 ** this URL is used for making absolute URL from relative URL that may be
260 ** passed as an MRL argument
262 NPObject *plugin = NULL;
264 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
267 ** is there a better way to get that info ?
269 static const char docLocHref[] = "document.location.href";
273 script.utf8characters = docLocHref;
274 script.utf8length = sizeof(docLocHref)-1;
276 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
278 if( NPVARIANT_IS_STRING(result) )
280 NPString &location = NPVARIANT_TO_STRING(result);
282 psz_baseURL = (char *) malloc(location.utf8length+1);
285 strncpy(psz_baseURL, location.utf8characters, location.utf8length);
286 psz_baseURL[location.utf8length] = '\0';
289 NPN_ReleaseVariantValue(&result);
291 NPN_ReleaseObject(plugin);
296 // get absolute URL from src
297 char *psz_absurl = getAbsoluteURL(psz_target);
298 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
301 /* assign plugin script root class */
303 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
305 if (pthread_mutex_init(&mutex, NULL) != 0)
306 return NPERR_GENERIC_ERROR;
308 return NPERR_NO_ERROR;
311 VlcPlugin::~VlcPlugin()
317 if( libvlc_media_player )
318 libvlc_media_player_release( libvlc_media_player );
319 if( libvlc_media_list )
320 libvlc_media_list_release( libvlc_media_list );
321 if( libvlc_instance )
322 libvlc_release(libvlc_instance);
324 for (int i = 0; i < eventListeners.size(); i++)
326 NPN_ReleaseObject(eventListeners[i]->listener);
327 NPN_ReleaseVariantValue(&(eventListeners[i]->id));
328 delete eventListeners[i];
331 pthread_mutex_destroy(&mutex);
334 /*****************************************************************************
335 * VlcPlugin playlist replacement methods
336 *****************************************************************************/
337 void VlcPlugin::set_player_window()
340 libvlc_media_player_set_xwindow(libvlc_media_player,
341 (libvlc_drawable_t)getVideoWindow());
344 // XXX FIXME insert appropriate call here
347 libvlc_media_player_set_hwnd(libvlc_media_player,
352 int VlcPlugin::playlist_add( const char *mrl, libvlc_exception_t *ex )
355 libvlc_media_t *p_m = libvlc_media_new(libvlc_instance,mrl,ex);
356 if( libvlc_exception_raised(ex) )
359 libvlc_media_list_lock(libvlc_media_list);
360 libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
361 if( !libvlc_exception_raised(ex) )
362 item = libvlc_media_list_count(libvlc_media_list)-1;
363 libvlc_media_list_unlock(libvlc_media_list);
365 libvlc_media_release(p_m);
370 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
371 int optc, const char **optv, libvlc_exception_t *ex )
373 libvlc_media_t *p_m = libvlc_media_new(libvlc_instance, mrl,ex);
375 if( libvlc_exception_raised(ex) )
378 for( int i = 0; i < optc; ++i )
379 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
381 libvlc_media_list_lock(libvlc_media_list);
382 libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
383 if( !libvlc_exception_raised(ex) )
384 item = libvlc_media_list_count(libvlc_media_list)-1;
385 libvlc_media_list_unlock(libvlc_media_list);
386 libvlc_media_release(p_m);
391 bool VlcPlugin::playlist_select( int idx, libvlc_exception_t *ex )
393 libvlc_media_t *p_m = NULL;
394 libvlc_event_manager_t *eventManager = NULL;
396 libvlc_media_list_lock(libvlc_media_list);
398 int count = libvlc_media_list_count(libvlc_media_list);
400 if( idx<0||idx>=count )
403 playlist_index = idx;
405 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index,ex);
406 libvlc_media_list_unlock(libvlc_media_list);
408 if( libvlc_exception_raised(ex) )
411 if( libvlc_media_player )
413 libvlc_media_player_release( libvlc_media_player );
414 libvlc_media_player = NULL;
417 libvlc_media_player = libvlc_media_player_new_from_media(p_m,ex);
418 if( libvlc_media_player )
422 // Registers the events we're interested in.
423 eventManager = libvlc_media_player_event_manager(libvlc_media_player, ex);
425 libvlc_event_attach(eventManager, libvlc_MediaPlayerOpening, event_callback, this, ex);
426 libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering, event_callback, this, ex);
427 libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying, event_callback, this, ex);
428 libvlc_event_attach(eventManager, libvlc_MediaPlayerStopped, event_callback, this, ex);
429 libvlc_event_attach(eventManager, libvlc_MediaPlayerPaused, event_callback, this, ex);
430 libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, event_callback, this, ex);
431 libvlc_event_attach(eventManager, libvlc_MediaPlayerForward, event_callback, this, ex);
432 libvlc_event_attach(eventManager, libvlc_MediaPlayerBackward, event_callback, this, ex);
433 libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, event_callback, this, ex);
434 libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, event_callback, this, ex);
435 libvlc_event_attach(eventManager, libvlc_MediaPlayerTimeChanged, event_callback, this, ex);
436 libvlc_event_attach(eventManager, libvlc_MediaPlayerPositionChanged, event_callback, this, ex);
437 libvlc_event_attach(eventManager, libvlc_MediaPlayerTitleChanged, event_callback, this, ex);
438 libvlc_event_attach(eventManager, libvlc_MediaPlayerSnapshotTaken, event_callback, this, ex);
442 libvlc_media_release( p_m );
443 return !libvlc_exception_raised(ex);
446 libvlc_media_list_unlock(libvlc_media_list);
450 void VlcPlugin::playlist_delete_item( int idx, libvlc_exception_t *ex )
452 libvlc_media_list_lock(libvlc_media_list);
453 libvlc_media_list_remove_index(libvlc_media_list,idx,ex);
454 libvlc_media_list_unlock(libvlc_media_list);
457 void VlcPlugin::playlist_clear( libvlc_exception_t *ex )
459 if( libvlc_media_list )
460 libvlc_media_list_release(libvlc_media_list);
461 libvlc_media_list = libvlc_media_list_new(getVLC());
464 int VlcPlugin::playlist_count()
467 libvlc_media_list_lock(libvlc_media_list);
468 items_count = libvlc_media_list_count(libvlc_media_list);
469 libvlc_media_list_unlock(libvlc_media_list);
473 void VlcPlugin::toggle_fullscreen( libvlc_exception_t *ex )
475 if( playlist_isplaying() )
476 libvlc_toggle_fullscreen(libvlc_media_player,ex);
478 void VlcPlugin::set_fullscreen( int yes, libvlc_exception_t *ex )
480 if( playlist_isplaying() )
481 libvlc_set_fullscreen(libvlc_media_player,yes,ex);
483 int VlcPlugin::get_fullscreen( libvlc_exception_t *ex )
486 if( playlist_isplaying() )
487 r = libvlc_get_fullscreen(libvlc_media_player,ex);
491 bool VlcPlugin::player_has_vout( libvlc_exception_t *ex )
494 if( playlist_isplaying() )
495 r = libvlc_media_player_has_vout(libvlc_media_player, ex);
499 /*****************************************************************************
501 *****************************************************************************/
503 char *VlcPlugin::getAbsoluteURL(const char *url)
507 // check whether URL is already absolute
508 const char *end=strchr(url, ':');
509 if( (NULL != end) && (end != url) )
511 // validate protocol header
512 const char *start = url;
517 while( start != end )
524 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
525 // not valid protocol header, assume relative URL
529 /* we have a protocol header, therefore URL is absolute */
532 // not a valid protocol header, assume relative URL
539 size_t baseLen = strlen(psz_baseURL);
540 char *href = (char *) malloc(baseLen+strlen(url)+1);
543 /* prepend base URL */
544 memcpy(href, psz_baseURL, baseLen+1);
547 ** relative url could be empty,
548 ** in which case return base URL
554 ** locate pathname part of base URL
557 /* skip over protocol part */
558 char *pathstart = strchr(href, ':');
559 char *pathend = href+baseLen;
562 if( '/' == *(++pathstart) )
564 if( '/' == *(++pathstart) )
569 /* skip over host part */
570 pathstart = strchr(pathstart, '/');
573 // no path, add a / past end of url (over '\0')
580 /* baseURL is just a UNIX path */
583 /* baseURL is not an absolute path */
590 /* relative URL made of an absolute path ? */
593 /* replace path completely */
594 strcpy(pathstart, url);
598 /* find last path component and replace it */
599 while( '/' != *pathend)
603 ** if relative url path starts with one or more '../',
604 ** factor them out of href so that we return a
607 while( pathend != pathstart )
615 /* relative url is just '.' */
621 /* relative url starts with './' */
630 /* relative url is '..' */
636 /* relative url starts with '../' */
644 while( '/' != *pathend );
646 /* skip over '/' separator */
648 /* concatenate remaining base URL and relative URL */
649 strcpy(pathend, url);
658 int VlcPlugin::setSize(unsigned width, unsigned height)
660 int diff = (width != i_width) || (height != i_height);
669 #define BTN_SPACE ((unsigned int)4)
670 void VlcPlugin::showToolbar()
672 const NPWindow& window = getWindow();
673 Window control = getControlWindow();
674 Window video = getVideoWindow();
675 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
676 unsigned int i_height = 0, i_width = BTN_SPACE;
680 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
681 &p_btnPlay, NULL, NULL);
684 i_height = __MAX( i_height, p_btnPlay->height );
687 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
688 &p_btnPause, NULL, NULL);
691 i_height = __MAX( i_height, p_btnPause->height );
693 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
696 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
697 &p_btnStop, NULL, NULL );
700 i_height = __MAX( i_height, p_btnStop->height );
701 i_width += BTN_SPACE + p_btnStop->width;
704 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
705 &p_timeline, NULL, NULL);
708 i_height = __MAX( i_height, p_timeline->height );
709 i_width += BTN_SPACE + p_timeline->width;
712 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
713 &p_btnTime, NULL, NULL);
716 i_height = __MAX( i_height, p_btnTime->height );
717 i_width += BTN_SPACE + p_btnTime->width;
719 if( !p_btnFullscreen )
720 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
721 &p_btnFullscreen, NULL, NULL);
722 if( p_btnFullscreen )
724 i_height = __MAX( i_height, p_btnFullscreen->height );
725 i_width += BTN_SPACE + p_btnFullscreen->width;
728 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
729 &p_btnMute, NULL, NULL);
732 i_height = __MAX( i_height, p_btnMute->height );
735 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
736 &p_btnUnmute, NULL, NULL);
739 i_height = __MAX( i_height, p_btnUnmute->height );
741 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
743 setToolbarSize( i_width, i_height );
745 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
746 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
747 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
749 /* reset panels position and size */
750 /* XXX use i_width */
751 XResizeWindow( p_display, video, window.width, window.height - i_height);
752 XMoveWindow( p_display, control, 0, window.height - i_height );
753 XResizeWindow( p_display, control, window.width, i_height -1);
755 b_toolbar = 1; /* says toolbar is now shown */
759 void VlcPlugin::hideToolbar()
761 const NPWindow& window = getWindow();
762 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
763 Window control = getControlWindow();
764 Window video = getVideoWindow();
766 i_tb_width = i_tb_height = 0;
768 if( p_btnPlay ) XDestroyImage( p_btnPlay );
769 if( p_btnPause ) XDestroyImage( p_btnPause );
770 if( p_btnStop ) XDestroyImage( p_btnStop );
771 if( p_timeline ) XDestroyImage( p_timeline );
772 if( p_btnTime ) XDestroyImage( p_btnTime );
773 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
774 if( p_btnMute ) XDestroyImage( p_btnMute );
775 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
782 p_btnFullscreen = NULL;
786 /* reset panels position and size */
787 /* XXX use i_width */
788 XResizeWindow( p_display, video, window.width, window.height );
789 XMoveWindow( p_display, control, 0, window.height-1 );
790 XResizeWindow( p_display, control, window.width, 1 );
792 b_toolbar = 0; /* says toolbar is now hidden */
796 void VlcPlugin::redrawToolbar()
800 unsigned int dst_x, dst_y;
803 unsigned int i_tb_width, i_tb_height;
805 /* This method does nothing if toolbar is hidden. */
809 const NPWindow& window = getWindow();
810 Window control = getControlWindow();
811 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
813 getToolbarSize( &i_tb_width, &i_tb_height );
817 b_mute = libvlc_audio_get_mute( getVLC() );
819 gcv.foreground = BlackPixel( p_display, 0 );
820 gc = XCreateGC( p_display, control, GCForeground, &gcv );
822 XFillRectangle( p_display, control, gc,
823 0, 0, window.width, i_tb_height );
824 gcv.foreground = WhitePixel( p_display, 0 );
825 XChangeGC( p_display, gc, GCForeground, &gcv );
829 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
831 if( p_btnPause && (is_playing == 1) )
833 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
834 dst_y - (p_btnPause->height >> 1),
835 p_btnPause->width, p_btnPause->height );
836 dst_x += BTN_SPACE + p_btnPause->width;
840 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
841 dst_y - (p_btnPlay->height >> 1),
842 p_btnPlay->width, p_btnPlay->height );
843 dst_x += BTN_SPACE + p_btnPlay->width;
847 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
848 dst_y - (p_btnStop->height >> 1),
849 p_btnStop->width, p_btnStop->height );
851 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
853 if( p_btnFullscreen )
854 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
855 dst_y - (p_btnFullscreen->height >> 1),
856 p_btnFullscreen->width, p_btnFullscreen->height );
858 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
860 if( p_btnUnmute && b_mute )
862 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
863 dst_y - (p_btnUnmute->height >> 1),
864 p_btnUnmute->width, p_btnUnmute->height );
866 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
870 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
871 dst_y - (p_btnMute->height >> 1),
872 p_btnMute->width, p_btnMute->height );
874 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
878 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
879 dst_y - (p_timeline->height >> 1),
880 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
882 /* get movie position in % */
883 if( playlist_isplaying() )
885 libvlc_exception_t ex;
886 libvlc_exception_init( &ex );
887 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
888 libvlc_media_player_get_position(libvlc_media_player,&ex));
889 libvlc_exception_clear( &ex );
893 XPutImage( p_display, control, gc, p_btnTime,
894 0, 0, (dst_x+i_last_position),
895 dst_y - (p_btnTime->height >> 1),
896 p_btnTime->width, p_btnTime->height );
898 XFreeGC( p_display, gc );
901 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
903 unsigned int i_dest = BTN_SPACE;
908 fprintf( stderr, "ToolbarButtonClicked:: "
909 "trying to match (%d,%d) (%d,%d)\n",
910 i_xpos, i_ypos, i_tb_height, i_tb_width );
912 if( i_ypos >= i_tb_width )
913 return clicked_Unknown;
915 /* Note: the order of testing is dependend on the original
916 * drawing positions of the icon buttons. Buttons are tested
921 is_playing = playlist_isplaying();
924 b_mute = libvlc_audio_get_mute( getVLC() );
926 /* is Pause of Play button clicked */
927 if( (is_playing != 1) &&
928 (i_xpos >= (BTN_SPACE>>1)) &&
929 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
931 else if( (i_xpos >= (BTN_SPACE>>1)) &&
932 (i_xpos <= i_dest + p_btnPause->width) )
933 return clicked_Pause;
935 /* is Stop button clicked */
936 if( is_playing != 1 )
937 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
939 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
941 if( (i_xpos >= i_dest) &&
942 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
945 /* is Fullscreen button clicked */
946 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
947 if( (i_xpos >= i_dest) &&
948 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
949 return clicked_Fullscreen;
951 /* is Mute or Unmute button clicked */
952 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
953 if( !b_mute && (i_xpos >= i_dest) &&
954 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
956 else if( (i_xpos >= i_dest) &&
957 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
958 return clicked_Unmute;
960 /* is timeline clicked */
962 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
964 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
965 if( (i_xpos >= i_dest) &&
966 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
967 return clicked_timeline;
969 /* is time button clicked */
970 i_dest += (p_timeline->width + (BTN_SPACE>>1));
971 if( (i_xpos >= i_dest) &&
972 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
975 return clicked_Unknown;
980 // Verifies the version of the NPAPI.
981 // The eventListeners use a NPAPI function available
983 bool VlcPlugin::canUseEventListener()
985 int plugin_major, plugin_minor;
986 int browser_major, browser_minor;
988 NPN_Version(&plugin_major, &plugin_minor,
989 &browser_major, &browser_minor);
991 if (browser_minor >= 19 || browser_major > 0)