Search code examples
c++winapipluginsclickfirebreath

Can't detect click in browser window to fire a function


Want to trigger function on mouse click in browser window via C++ plugin, written with FireBreath. But with code below nothing happends on click. Got the following code in TestPluginAPI.h:

BEGIN_PLUGIN_EVENT_MAP() 
EVENTTYPE_CASE(FB::MouseDownEvent, onMouseDown, FB::PluginWindow) 
END_PLUGIN_EVENT_MAP()
virtual bool onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *);

And this code in testPluginAPI.cpp:

bool TestPluginAPI::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *) 
 {

   if(evt->m_Btn == FB::MouseButtonEvent::MouseButton_Left) 
     {  
      fire_showcrd(FB::variant_list_of(evt->m_x)(evt->m_y));
   }
   return 0;
 }

Fire_showcrd(...) was tested separately and it's working. It seems that something wrong with click detecter part, but what?


Solution

  • The PluginWindow events in FireBreath only apply to the region where the plugin lives, not elsewhere on the webpage. You'll only get events when the plugin itself is clicked on using this method, and if any DOM elements are hovering over your plugin (even if your plugin draws in front because it's windowed) you may end up losing the events to that element.

    You can get click events for the whole page by using javascript.