[vlc-devel] [PATCH 1/2] Moved event handling to VlcPlugin::handle_event
Cheng Sun
chengsun9 at gmail.com
Mon Nov 19 22:11:45 CET 2012
Add NPP_HandleEvent support for Win/Linux. Needed for windowless mode.
---
npapi/support/npunix.cpp | 11 +++-
npapi/support/npwin.cpp | 2 +-
npapi/vlcplugin_base.cpp | 5 ++
npapi/vlcplugin_base.h | 2 +
npapi/vlcplugin_mac.cpp | 100 +++++++++++++++++++++++++++++++++++
npapi/vlcplugin_mac.h | 2 +
npapi/vlcshell.cpp | 133 ++++++-----------------------------------------
7 files changed, 137 insertions(+), 118 deletions(-)
diff --git a/npapi/support/npunix.cpp b/npapi/support/npunix.cpp
index 2c5aacc..cb4f9a7 100644
--- a/npapi/support/npunix.cpp
+++ b/npapi/support/npunix.cpp
@@ -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)
diff --git a/npapi/support/npwin.cpp b/npapi/support/npwin.cpp
index 84e3194..8c46d73 100644
--- a/npapi/support/npwin.cpp
+++ b/npapi/support/npwin.cpp
@@ -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;
diff --git a/npapi/vlcplugin_base.cpp b/npapi/vlcplugin_base.cpp
index 9b9252b..15280ec 100644
--- a/npapi/vlcplugin_base.cpp
+++ b/npapi/vlcplugin_base.cpp
@@ -578,6 +578,11 @@ void VlcPluginBase::setWindow(const NPWindow &window)
npwindow = window;
}
+bool VlcPluginBase::handle_event(void *event)
+{
+ return false;
+}
+
/*****************************************************************************
* VlcPluginBase playlist replacement methods
*****************************************************************************/
diff --git a/npapi/vlcplugin_base.h b/npapi/vlcplugin_base.h
index 4bb4f8d..e112eeb 100644
--- a/npapi/vlcplugin_base.h
+++ b/npapi/vlcplugin_base.h
@@ -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;
diff --git a/npapi/vlcplugin_mac.cpp b/npapi/vlcplugin_mac.cpp
index 4054215..019a8a2 100644
--- a/npapi/vlcplugin_mac.cpp
+++ b/npapi/vlcplugin_mac.cpp
@@ -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);
+}
diff --git a/npapi/vlcplugin_mac.h b/npapi/vlcplugin_mac.h
index f976e8c..99a7ed5 100644
--- a/npapi/vlcplugin_mac.h
+++ b/npapi/vlcplugin_mac.h
@@ -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();
diff --git a/npapi/vlcshell.cpp b/npapi/vlcshell.cpp
index cde708c..883eb33 100644
--- a/npapi/vlcshell.cpp
+++ b/npapi/vlcshell.cpp
@@ -121,122 +121,6 @@ NPError NPP_SetValue( NPP, NPNVariable, void * )
}
/******************************************************************************
- * 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
*****************************************************************************/
NPError NPP_Initialize( void )
@@ -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);
+
+}
--
1.8.0
More information about the vlc-devel
mailing list