Commit 628b7eaa authored by Cheng Sun's avatar Cheng Sun Committed by Jean-Baptiste Kempf

Moved event handling to VlcPlugin::handle_event

Add NPP_HandleEvent support for Win/Linux. Needed for windowless mode.
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent fe3c3cb2
......@@ -680,6 +680,7 @@ NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason);
void Private_URLNotify(NPP instance, const char* url,
NPReason reason, void* notifyData);
void Private_Print(NPP instance, NPPrint* platformPrint);
int16_t Private_HandleEvent(NPP instance, NPEvent *event);
NPError Private_GetValue(NPP instance, NPPVariable variable, void *r_value);
NPError Private_SetValue(NPP instance, NPNVariable variable, void *r_value);
#ifdef OJI
......@@ -775,6 +776,13 @@ Private_Print(NPP instance, NPPrint* platformPrint)
NPP_Print(instance, platformPrint);
}
int16_t
Private_HandleEvent(NPP instance, NPEvent *event)
{
PLUGINDEBUGSTR("HandleEvent");
NPP_HandleEvent(instance, event);
}
NPError
Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
{
......@@ -1004,6 +1012,7 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
pluginFuncs->write = NewNPP_WriteProc(Private_Write);
pluginFuncs->print = NewNPP_PrintProc(Private_Print);
pluginFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent);
pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue);
#else
......@@ -1016,10 +1025,10 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
pluginFuncs->writeready = (NPP_WriteReadyProcPtr)(Private_WriteReady);
pluginFuncs->write = (NPP_WriteProcPtr)(Private_Write);
pluginFuncs->print = (NPP_PrintProcPtr)(Private_Print);
pluginFuncs->event = (NPP_HandleEventProcPtr)(Private_HandleEvent);
pluginFuncs->getvalue = (NPP_GetValueProcPtr)(Private_GetValue);
pluginFuncs->setvalue = (NPP_SetValueProcPtr)(Private_SetValue);
#endif
pluginFuncs->event = NULL;
if( minor >= NPVERS_HAS_NOTIFICATION )
{
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
......
......@@ -115,7 +115,7 @@ NP_GetEntryPoints(NPPluginFuncs* pFuncs)
pFuncs->writeready = NPP_WriteReady;
pFuncs->write = NPP_Write;
pFuncs->print = NPP_Print;
pFuncs->event = 0; /// reserved
pFuncs->event = NPP_HandleEvent;
pFuncs->getvalue = NPP_GetValue;
pFuncs->setvalue = NPP_SetValue;
......
......@@ -578,6 +578,11 @@ void VlcPluginBase::setWindow(const NPWindow &window)
npwindow = window;
}
bool VlcPluginBase::handle_event(void *event)
{
return false;
}
/*****************************************************************************
* VlcPluginBase playlist replacement methods
*****************************************************************************/
......
......@@ -294,6 +294,8 @@ public:
virtual bool resize_windows() = 0;
virtual bool destroy_windows() = 0;
virtual bool handle_event(void *event);
virtual void toggle_fullscreen() = 0;
virtual void set_fullscreen(int) = 0;
virtual int get_fullscreen() = 0;
......
......@@ -100,3 +100,103 @@ bool VlcPluginMac::destroy_windows()
{
npwindow.window = NULL;
}
bool VlcPluginMac::handle_event(void *event)
{
// FIXME: implement Cocoa event model, by porting this legacy code:
/*
static UInt32 lastMouseUp = 0;
EventRecord *myEvent = (EventRecord*)event;
switch( myEvent->what )
{
case nullEvent:
return true;
case mouseDown:
{
if( (myEvent->when - lastMouseUp) < GetDblTime() )
{
// double click
p_plugin->toggle_fullscreen();
}
return true;
}
case mouseUp:
lastMouseUp = myEvent->when;
return true;
case keyUp:
case keyDown:
case autoKey:
return true;
case updateEvt:
{
const NPWindow& npwindow = p_plugin->getWindow();
if( npwindow.window )
{
bool hasVout = false;
if( p_plugin->playlist_isplaying() )
{
hasVout = p_plugin->player_has_vout();
#if 0
if( hasVout )
{
libvlc_rectangle_t area;
area.left = 0;
area.top = 0;
area.right = npwindow.width;
area.bottom = npwindow.height;
libvlc_video_redraw_rectangle(p_plugin->getMD(), &area, NULL);
}
#else
#warning disabled code
#endif
}
if( ! hasVout )
{
// draw the text from get_bg_text()
ForeColor(blackColor);
PenMode( patCopy );
// seems that firefox forgets to set the following
// on occasion (reload)
SetOrigin(((NP_Port *)npwindow.window)->portx,
((NP_Port *)npwindow.window)->porty);
Rect rect;
rect.left = 0;
rect.top = 0;
rect.right = npwindow.width;
rect.bottom = npwindow.height;
PaintRect( &rect );
ForeColor(whiteColor);
MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
if( !p_plugin->get_bg_text().empty() )
DrawText( p_plugin->get_bg_text().c_str(), 0, p_plugin->get_bg_text().length() );
}
}
return true;
}
case activateEvt:
return false;
case NPEventType_GetFocusEvent:
case NPEventType_LoseFocusEvent:
return true;
case NPEventType_AdjustCursorEvent:
return false;
case NPEventType_MenuCommandEvent:
return false;
case NPEventType_ClippingChangedEvent:
return false;
case NPEventType_ScrollingBeginsEvent:
return true;
case NPEventType_ScrollingEndsEvent:
return true;
default:
;
}
*/
return VlcPluginBase::handle_event(event);
}
......@@ -49,6 +49,8 @@ public:
bool get_toolbar_visible() { return false; }
void update_controls() {/* STUB */}
void popup_menu() {/* STUB */}
virtual void handle_event(void *event);
private:
void set_player_window();
......
......@@ -120,122 +120,6 @@ NPError NPP_SetValue( NPP, NPNVariable, void * )
return NPERR_GENERIC_ERROR;
}
/******************************************************************************
* Mac-only API calls
*****************************************************************************/
#ifdef XP_MACOSX
int16_t NPP_HandleEvent( NPP instance, void * event )
{
static UInt32 lastMouseUp = 0;
if( instance == NULL )
{
return false;
}
VlcPluginBase *p_plugin = reinterpret_cast<VlcPluginBase *>(instance->pdata);
if( p_plugin == NULL )
{
return false;
}
// FIXME: implement Cocoa event model, by porting this legacy code:
/*
EventRecord *myEvent = (EventRecord*)event;
switch( myEvent->what )
{
case nullEvent:
return true;
case mouseDown:
{
if( (myEvent->when - lastMouseUp) < GetDblTime() )
{
// double click
p_plugin->toggle_fullscreen();
}
return true;
}
case mouseUp:
lastMouseUp = myEvent->when;
return true;
case keyUp:
case keyDown:
case autoKey:
return true;
case updateEvt:
{
const NPWindow& npwindow = p_plugin->getWindow();
if( npwindow.window )
{
bool hasVout = false;
if( p_plugin->playlist_isplaying() )
{
hasVout = p_plugin->player_has_vout();
#if 0
if( hasVout )
{
libvlc_rectangle_t area;
area.left = 0;
area.top = 0;
area.right = npwindow.width;
area.bottom = npwindow.height;
libvlc_video_redraw_rectangle(p_plugin->getMD(), &area, NULL);
}
#else
#warning disabled code
#endif
}
if( ! hasVout )
{
// draw the text from get_bg_text()
ForeColor(blackColor);
PenMode( patCopy );
// seems that firefox forgets to set the following
// on occasion (reload)
SetOrigin(((NP_Port *)npwindow.window)->portx,
((NP_Port *)npwindow.window)->porty);
Rect rect;
rect.left = 0;
rect.top = 0;
rect.right = npwindow.width;
rect.bottom = npwindow.height;
PaintRect( &rect );
ForeColor(whiteColor);
MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
if( !p_plugin->get_bg_text().empty() )
DrawText( p_plugin->get_bg_text().c_str(), 0, p_plugin->get_bg_text().length() );
}
}
return true;
}
case activateEvt:
return false;
case NPEventType_GetFocusEvent:
case NPEventType_LoseFocusEvent:
return true;
case NPEventType_AdjustCursorEvent:
return false;
case NPEventType_MenuCommandEvent:
return false;
case NPEventType_ClippingChangedEvent:
return false;
case NPEventType_ScrollingBeginsEvent:
return true;
case NPEventType_ScrollingEndsEvent:
return true;
default:
;
}
*/
return false;
}
#endif /* XP_MACOSX */
/******************************************************************************
* General Plug-in Calls
*****************************************************************************/
......@@ -546,3 +430,20 @@ void NPP_Print( NPP instance, NPPrint* printInfo )
}
}
}
int16_t NPP_HandleEvent( NPP instance, void * event )
{
if( instance == NULL )
{
return false;
}
VlcPluginBase *p_plugin = reinterpret_cast<VlcPluginBase *>(instance->pdata);
if( p_plugin == NULL )
{
return false;
}
return p_plugin->handle_event(event);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment