Commit 71d32267 authored by Cheng Sun's avatar Cheng Sun Committed by Jean-Baptiste Kempf

Added platform-specific child classes of VlcPluginBase:

VlcPluginWin: Windows support - briefly tested
VlcPluginMac: Mac support - completely untested
VlcPluginGtk: GTK+ Linux support - well tested
VlcPluginXlib: Xlib Linux support for those who don't want to compile
with GTK+ - buggy
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent c2d71323
#include "vlcplugin_gtk.h"
#include <gdk/gdkx.h>
#include <cstring>
static uint32_t getXid(GtkWidget *widget) {
GdkDrawable *video_drawable = gtk_widget_get_window(widget);
return (uint32_t)gdk_x11_drawable_get_xid(video_drawable);
}
VlcPluginGtk::VlcPluginGtk(NPP instance, NPuint16_t mode) :
VlcPluginBase(instance, mode),
parent(NULL),
parent_vbox(NULL),
video(NULL)
{
}
VlcPluginGtk::~VlcPluginGtk()
{
}
void VlcPluginGtk::set_player_window()
{
libvlc_media_player_set_xwindow(libvlc_media_player,
(uint32_t)getXid(video));
}
void VlcPluginGtk::toggle_fullscreen()
{
if (playlist_isplaying())
libvlc_toggle_fullscreen(libvlc_media_player);
}
void VlcPluginGtk::set_fullscreen(int yes)
{
if (playlist_isplaying())
libvlc_set_fullscreen(libvlc_media_player, yes);
}
int VlcPluginGtk::get_fullscreen()
{
int r = 0;
if (playlist_isplaying())
r = libvlc_get_fullscreen(libvlc_media_player);
return r;
}
void VlcPluginGtk::show_toolbar()
{
/* TODO */
}
void VlcPluginGtk::hide_toolbar()
{
/* TODO */
}
void VlcPluginGtk::update_controls()
{
/* TODO */
}
bool VlcPluginGtk::create_windows()
{
Display *p_display = ( (NPSetWindowCallbackStruct *)
npwindow.ws_info )->display;
Window socket = (Window) npwindow.window;
GdkColor color_black;
gdk_color_parse("black", &color_black);
parent = gtk_plug_new(socket);
gtk_widget_modify_bg(parent, GTK_STATE_NORMAL, &color_black);
parent_vbox = gtk_vbox_new(false, 0);
gtk_container_add(GTK_CONTAINER(parent), parent_vbox);
video = gtk_drawing_area_new();
gtk_widget_modify_bg(video, GTK_STATE_NORMAL, &color_black);
gtk_box_pack_start(GTK_BOX(parent_vbox), video, true, true, 0);
gtk_widget_show_all(parent);
return true;
}
bool VlcPluginGtk::resize_windows()
{
GtkRequisition req;
req.width = npwindow.width;
req.height = npwindow.height;
gtk_widget_size_request(parent, &req);
#if 0
Window root_return, parent_return, *children_return;
unsigned int i_nchildren;
XQueryTree( p_display, npvideo,
&root_return, &parent_return, &children_return,
&i_nchildren );
if( i_nchildren > 0 )
{
/* XXX: Make assumptions related to the window parenting structure in
vlc/modules/video_output/x11/xcommon.c */
Window base_window = children_return[i_nchildren - 1];
i_ret = XResizeWindow( p_display, base_window,
npwindow.width, ( npwindow.height - i_tb_height ) );
}
return true;
#endif
}
bool VlcPluginGtk::destroy_windows()
{
/* TODO */
}
/*****************************************************************************
* vlcplugin_gtk.h: a VLC plugin for Mozilla
*****************************************************************************
* Copyright (C) 2011 the VideoLAN team
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Damien Fouilleul <damienf@videolan.org>
* Jean-Paul Saman <jpsaman@videolan.org>
* Cheng Sun <chengsun9@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef __VLCPLUGIN_GTK_H__
#define __VLCPLUGIN_GTK_H__
#include "vlcplugin_base.h"
#include <gtk/gtk.h>
class VlcPluginGtk : public VlcPluginBase
{
public:
VlcPluginGtk(NPP, NPuint16_t);
virtual ~VlcPluginGtk();
int setSize(unsigned width, unsigned height);
void toggle_fullscreen();
void set_fullscreen( int );
int get_fullscreen();
bool create_windows();
bool resize_windows();
bool destroy_windows();
void show_toolbar();
void hide_toolbar();
void update_controls();
static void toolbar_handler(GtkToolButton *, gpointer);
static bool time_slider_handler(GtkRange *, GtkScrollType, gdouble, gpointer);
static bool vol_slider_handler(GtkRange *, GtkScrollType, gdouble, gpointer);
private:
void set_player_window();
unsigned int i_width, i_height;
GtkWidget *parent, *parent_vbox, *video;
};
#endif /* __VLCPLUGIN_GTK_H__ */
#include "vlcplugin_mac.h"
VlcPluginMac::VlcPluginMac(NPP instance, NPuint16_t mode) :
VlcPluginBase(instance, mode)
{
}
VlcPluginMac::~VlcPluginMac()
{
}
void VlcPluginMac::set_player_window()
{
// XXX FIXME insert appropriate call here
}
void VlcPluginMac::toggle_fullscreen()
{
if (playlist_isplaying())
libvlc_toggle_fullscreen(libvlc_media_player);
}
void VlcPluginMac::set_fullscreen(int yes)
{
if (playlist_isplaying())
libvlc_set_fullscreen(libvlc_media_player, yes);
}
int VlcPluginMac::get_fullscreen()
{
int r = 0;
if (playlist_isplaying())
r = libvlc_get_fullscreen(libvlc_media_player);
return r;
}
void VlcPluginMac::show_toolbar()
{
// TODO
}
void VlcPluginMac::hide_toolbar()
{
// TODO
}
void VlcPluginMac::update_controls()
{
// TODO
}
bool VlcPluginMac::create_windows()
{
return true;
}
bool VlcPluginMac::resize_windows()
{
/* as MacOS X video output is windowless, set viewport */
libvlc_rectangle_t view, clip;
/* browser sets port origin to top-left location of plugin
* relative to GrafPort window origin is set relative to document,
* which of little use for drawing
*/
view.top = ((NP_Port*) (npwindow.window))->porty;
view.left = ((NP_Port*) (npwindow.window))->portx;
view.bottom = npwindow.height+view.top;
view.right = npwindow.width+view.left;
/* clipRect coordinates are also relative to GrafPort */
clip.top = npwindow.clipRect.top;
clip.left = npwindow.clipRect.left;
clip.bottom = npwindow.clipRect.bottom;
clip.right = npwindow.clipRect.right;
#ifdef NOT_WORKING
libvlc_video_set_viewport(p_vlc, p_plugin->getMD(), &view, &clip);
#else
#warning disabled code
#endif
}
bool VlcPluginMac::destroy_windows()
{
window.window = NULL;
}
/*****************************************************************************
* vlcplugin_mac.h: a VLC plugin for Mozilla
*****************************************************************************
* Copyright (C) 2011 the VideoLAN team
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Damien Fouilleul <damienf@videolan.org>
* Jean-Paul Saman <jpsaman@videolan.org>
* Cheng Sun <chengsun9@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef __VLCPLUGIN_MAC_H__
#define __VLCPLUGIN_MAC_H__
#include "vlcplugin_base.h"
#include <Quickdraw.h>
class VlcPluginMac : public VlcPluginBase
{
public:
VlcPluginMac(NPP, NPuint16_t);
virtual ~VlcPluginMac();
int setSize(unsigned width, unsigned height);
void toggle_fullscreen();
void set_fullscreen( int );
int get_fullscreen();
bool create_windows();
bool resize_windows();
bool destroy_windows();
void show_toolbar();
void hide_toolbar();
void update_controls();
private:
void set_player_window();
unsigned int i_width, i_height;
int i_last_position;
};
#endif /* __VLCPLUGIN_MAC_H__ */
#include "vlcplugin_win.h"
#include "../common/win32_fullscreen.h"
static HMODULE hDllModule= 0;
HMODULE DllGetModule()
{
return hDllModule;
};
extern "C"
BOOL WINAPI DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved )
{
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
hDllModule = (HMODULE)hModule;
break;
default:
break;
}
return TRUE;
};
static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
{
VlcPluginWin *p_plugin = reinterpret_cast<VlcPluginWin *>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
switch( i_msg )
{
case WM_ERASEBKGND:
return 1L;
case WM_PAINT:
{
PAINTSTRUCT paintstruct;
HDC hdc;
RECT rect;
hdc = BeginPaint( p_hwnd, &paintstruct );
GetClientRect( p_hwnd, &rect );
FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
SetTextColor(hdc, RGB(255, 255, 255));
SetBkColor(hdc, RGB(0, 0, 0));
if( p_plugin->psz_text )
DrawText( hdc, p_plugin->psz_text, strlen(p_plugin->psz_text), &rect,
DT_CENTER|DT_VCENTER|DT_SINGLELINE);
EndPaint( p_hwnd, &paintstruct );
return 0L;
}
case WM_SIZE:{
int new_client_width = LOWORD(lpar);
int new_client_height = HIWORD(lpar);
//first child will be resized to client area
HWND hChildWnd = GetWindow(p_hwnd, GW_CHILD);
if(hChildWnd){
MoveWindow(hChildWnd, 0, 0, new_client_width, new_client_height, FALSE);
}
return 0L;
}
case WM_LBUTTONDBLCLK:{
p_plugin->toggle_fullscreen();
return 0L;
}
default:
/* delegate to default handler */
return CallWindowProc( p_plugin->getWindowProc(), p_hwnd,
i_msg, wpar, lpar );
}
}
VlcPluginWin::VlcPluginWin(NPP instance, NPuint16_t mode) :
VlcPluginBase(instance, mode),
pf_wndproc(NULL),
_WindowsManager(DllGetModule())
{
}
VlcPluginWin::~VlcPluginWin()
{
HWND win = (HWND)getWindow().window;
WNDPROC winproc = getWindowProc();
if( winproc )
{
/* reset WNDPROC */
SetWindowLongPtr( win, GWLP_WNDPROC, (LONG_PTR)winproc );
}
_WindowsManager.DestroyWindows();
}
void VlcPluginWin::set_player_window()
{
_WindowsManager.LibVlcAttach(libvlc_media_player);
}
void VlcPluginWin::toggle_fullscreen()
{
if (playlist_isplaying())
libvlc_toggle_fullscreen(libvlc_media_player);
}
void VlcPluginWin::set_fullscreen(int yes)
{
if (playlist_isplaying())
libvlc_set_fullscreen(libvlc_media_player,yes);
}
int VlcPluginWin::get_fullscreen()
{
int r = 0;
if (playlist_isplaying())
r = libvlc_get_fullscreen(libvlc_media_player);
return r;
}
void VlcPluginWin::show_toolbar()
{
/* TODO */
}
void VlcPluginWin::hide_toolbar()
{
/* TODO */
}
void VlcPluginWin::update_controls()
{
/* TODO */
}
bool VlcPluginWin::create_windows()
{
HWND drawable = (HWND) (getWindow().window);
/* attach our plugin object */
SetWindowLongPtr(drawable, GWLP_USERDATA,
(LONG_PTR)this);
/* install our WNDPROC */
setWindowProc( (WNDPROC)SetWindowLongPtr( drawable,
GWLP_WNDPROC, (LONG_PTR)Manage ) );
/* change window style to our liking */
LONG style = GetWindowLong(drawable, GWL_STYLE);
style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
SetWindowLong(drawable, GWL_STYLE, style);
_WindowsManager.CreateWindows(drawable);
return true;
}
bool VlcPluginWin::resize_windows()
{
/* TODO */
HWND drawable = (HWND) (getWindow().window);
/* Redraw window */
InvalidateRect( drawable, NULL, TRUE );
UpdateWindow( drawable );
}
bool VlcPluginWin::destroy_windows()
{
/* reset WNDPROC */
HWND oldwin = (HWND)npwindow.window;
SetWindowLongPtr( oldwin, GWLP_WNDPROC, (LONG_PTR)(getWindowProc()) );
setWindowProc(NULL);
npwindow.window = NULL;
}
/*****************************************************************************
* vlcplugin_win.h: a VLC plugin for Mozilla
*****************************************************************************
* Copyright (C) 2011 the VideoLAN team
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Damien Fouilleul <damienf@videolan.org>
* Jean-Paul Saman <jpsaman@videolan.org>
* Cheng Sun <chengsun9@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef __VLCPLUGIN_WIN_H__
#define __VLCPLUGIN_WIN_H__
#include "vlcplugin_base.h"
#include <windows.h>
#include <winbase.h>
HMODULE DllGetModule();
#include "../common/win32_fullscreen.h"
class VlcPluginWin : public VlcPluginBase
{
public:
VlcPluginWin(NPP, NPuint16_t);
virtual ~VlcPluginWin();
int setSize(unsigned width, unsigned height);
void toggle_fullscreen();
void set_fullscreen( int );
int get_fullscreen();
bool create_windows();
bool resize_windows();
bool destroy_windows();
void show_toolbar();
void hide_toolbar();
void update_controls();
WNDPROC getWindowProc()
{ return pf_wndproc; };
void setWindowProc(WNDPROC wndproc)
{ pf_wndproc = wndproc; };
private:
void set_player_window();
unsigned int i_width, i_height;
unsigned int i_tb_width, i_tb_height;
WNDPROC pf_wndproc;
VLCWindowsManager _WindowsManager;
int i_last_position;
};
#endif /* __VLCPLUGIN_WIN_H__ */
#include "vlcplugin_xlib.h"
#include <cstring>
VlcPluginXlib::VlcPluginXlib(NPP instance, NPuint16_t mode) :
VlcPluginBase(instance, mode)
{
memset(&npparent, 0, sizeof(Window));
memset(&npvideo, 0, sizeof(Window));
}
VlcPluginXlib::~VlcPluginXlib()
{
}
Display *VlcPluginXlib::getDisplay()
{
return ((NPSetWindowCallbackStruct *) npwindow.ws_info)->display;
}
void VlcPluginXlib::set_player_window()
{
libvlc_media_player_set_xwindow(libvlc_media_player,
(uint32_t)npvideo);
}
void VlcPluginXlib::toggle_fullscreen()
{
if (playlist_isplaying())
libvlc_toggle_fullscreen(libvlc_media_player);
}
void VlcPluginXlib::set_fullscreen(int yes)
{
if (playlist_isplaying())
libvlc_set_fullscreen(libvlc_media_player,yes);
}
int VlcPluginXlib::get_fullscreen()
{
int r = 0;
if (playlist_isplaying())
r = libvlc_get_fullscreen(libvlc_media_player);
return r;
}
void VlcPluginXlib::show_toolbar()
{
/* TODO */
}
void VlcPluginXlib::hide_toolbar()
{
/* TODO */
}
void VlcPluginXlib::update_controls()
{
/* TODO */
}
bool VlcPluginXlib::create_windows()
{
Display *p_display = getDisplay();
Window socket = (Window) npwindow.window;
unsigned long xembed_info_buf[2] =
{ PLUGIN_XEMBED_PROTOCOL_VERSION, XEMBED_MAPPED };
Atom xembed_info_atom = XInternAtom( p_display, "_XEMBED_INFO", 1);
int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
/* create windows */
npparent = XCreateSimpleWindow( p_display, socket, 0, 0,
1, 1,
0, i_blackColor, i_blackColor );
XChangeProperty( p_display, npparent, xembed_info_atom,
xembed_info_atom, 32, PropModeReplace,
(unsigned char *)xembed_info_buf, 2);
npvideo = XCreateSimpleWindow( p_display, npparent, 0, 0,
1, 1,
0, i_blackColor, i_blackColor );
XMapWindow( p_display, npvideo );
return true;
}
bool VlcPluginXlib::resize_windows()
{
Display *p_display = getDisplay();
int i_ret;
i_ret = XMoveResizeWindow( p_display, npparent, 0, 0,
npwindow.width, npwindow.height );
i_ret = XMoveResizeWindow( p_display, npvideo, 0, 0,
npwindow.width, npwindow.height );
Window root_return, parent_return, *children_return;
unsigned int i_nchildren;
XQueryTree( p_display, npvideo,
&root_return, &parent_return, &children_return,
&i_nchildren );
if( i_nchildren > 0 )
{
/* XXX: Make assumptions related to the window parenting structure in
vlc/modules/video_output/x11/xcommon.c */
Window base_window = children_return[i_nchildren - 1];
i_ret = XResizeWindow( p_display, base_window,
npwindow.width, ( npwindow.height ) );
}
return true;
}
bool VlcPluginXlib::destroy_windows()
{
/* TODO */
}
/*****************************************************************************
* vlcplugin_xlib.h: a VLC plugin for Mozilla
*****************************************************************************
* Copyright (C) 2011 the VideoLAN team
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Damien Fouilleul <damienf@videolan.org>
* Jean-Paul Saman <jpsaman@videolan.org>
* Cheng Sun <chengsun9@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef __VLCPLUGIN_XLIB_H__
#define __VLCPLUGIN_XLIB_H__
#include "vlcplugin_base.h"
#include <X11/Xlib.h>
#include "xembed.h"
class VlcPluginXlib : public VlcPluginBase
{
public:
VlcPluginXlib(NPP, NPuint16_t);
virtual ~VlcPluginXlib();
int setSize(unsigned width, unsigned height);
void toggle_fullscreen();
void set_fullscreen( int );
int get_fullscreen();
bool create_windows();