Plugins:IndependentEventModel

From MozillaWiki
Jump to: navigation, search

Problem Summary

For some platform (X11), we have only one event model type, which is providing only platform native event type (XEvent). And there are no official way to make eventModel negotiation and pass some different event structure in HandleEvent API

Proposal

Provide event model negotiation for all platforms (not only Mac OS X).

Event model negotiation

For documentation on negotiating event models, see NPAPI:Models. The event model variables for all platforms are:

* NPEventModelIndependent - (platform independent events, specified in NPAPI)
* NPNVsupportsIndependentBool (NPNVariable = 3001)

If event model negotiation fail, then will be used default event model ( HandleEvent event argument equals XEvent/NPEvent )

NPEventModelIndependent

typedef struct _NPIndependentEvent
{
  void*         event;       /* event structure pointer */
  NPEventType   type;        /* type of event, defined in NPEventType */
} NPIndependentEvent;
typedef enum {
  NPEventType_NPEvent = 0x0001,   /* default platform NPEvent structure specific to platform (NPEvent, XEvent, EventRecord)
  NPEventType_DrawImage = 0x0002, /* Draw Image even type, event structure == NPImageData.
  NPEventType_GetFocusEvent = ....
  ............
} NPEventType;

NPEventType negotiation

Event types should be negotiated by using NPN value:

NPNVsupportsEventTypes = 4000

Example:

NPEventType aTypes;
browser->getvalue(instance, NPNVsupportsEventTypes, &aTypes);

Then plugin should get decide which events are available in aTypes, and filter out types which are not supported by plugin:

if (aTypes & NPEventType_DrawImage) {
  // if plugin does not support DrawImage event
  // then plugin can remove
  aTypes &= ~NPEventType_DrawImage;
}

browser->setvalue(instance, NPNVsupportsEventTypes, aTypes);