Re: Converting a webkit plugin to NPAPI?

Stuart Morgan <[email protected]>
Newsgroups gmane.comp.mozilla.devel.plugins
Organization http://groups.google.com
Message-ID <e15f9397-f2ad-447b-aef0-d0ff38700d0b@w18g2000yqc.googlegroups.com>
On Mon, Aug 22, 2011 at 10:26 PM, snappa <[email protected]>
wrote:
> The NPAPI documentation as I read it states that the "window" attribute of
> the NPWindow structure will point to an NP_Port structure for OS X.
> I am seeing the window attribute as NULL.

It sounds like you are using the Cocoa event model; see the
documentation here for changes on top of the CoreGraphics drawing
model changes if you are using the Cocoa event model:
https://wiki.mozilla.org/NPAPI:CocoaEventModel

> I'm trying to understand where the correct x/y attributes are found
> for passing into an NSRect create method.  The documents are slightly
> confusing here.

It depends a lot on what you are planning on using the NSRect for.

> If I use the X/Y coordinates that are in the NPWindow structure this
> works fine for the div at 0,0 but a div that would be placed directly
> below the top most div doesn't draw where I expect it to.

In general it shouldn't matter to you what the coordinates in the
NPWindow structure are. Depending on the browser and the models, you
may or may not get real values. I'm not familiar with the details of
Firefox's implementation, but for example in Chrome you would always
get 0,0 no matter where the plugin is. If for some reason you actually
do need to know where the plugin is in page coordinates you'd need to
pass that information in via JS.

> The coordinates given to me are, for example,
> 0, 400.  Now this to me implies that drawing is relative to the entire
> page and not a 400x400 div area. [...] If I change the value to always
> be 0 based then the image is drawn in the correct location
> within the div (rectangle).

At the point where you get a paint event, the context should have been
transformed by the browser such that (0,0) is the corner of your
plugin, so you are seeing the expected behavior.

> Am I supposed to be able to get / use the NP_Port structure for laying
> things out on OS X?

No, not unless you are using the deprecated QD+Carbon model (which you
don't want to do, since it won't work in most 64-bit browsers, and
eventually won't work anywhere).

>  I need to be able to have this plugin draw videos into a grid of rectangles.

Unless the plugins are making decisions about what to draw based on
their coordinates, this won't matter at the plugin layer. Just lay out
the grid in HTML, and pass the appropriate parameters to each plugin
instance to have it draw the content you want.

> Also, the NP_Port structure is "ifdef'd" out by default.

No it isn't (at least, not if you are using the canonical headers at
<http://code.google.com/p/npapi-sdk>). It's only ifdef'd out if
NP_NO_QUICKDRAW is set, which is only set for 64-bit builds.

Either way though, it's irrelevant if you are using the Cocoa event
model (which you should if you want compatibility with 64-bit
Firefox).

> I noticed that XP_MACOSX needs to be defined in order for the NP_Port
> structure to be visible.  This did nothing for me other than to get rid of
> compile errors.

XP_MACOSX needs to be defined if you are building for Mac in general.
Not having compiler errors due to missing symbols is the point of a
header, so I'm not sure what else you expected having the right flags
set there to do.

-Stuart
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.