Chapter 3:Plug-in API
5: typedef struct _NPWindow
6: NPError NPP_SetWindow(NPP instance, NPWindow *window);
The NPWindow Structure
When a plug-in is loaded, it is drawn into a target area. This target is either the windowed plug-in's native window, or the drawable of a windowless plug-in. The NPWindow structure represents either the native window or a drawable. This structure contains information about coordinate position, size, the state of the plug-in (windowed or windowless), and some platform-specific information.
NOTE: When a plug-in is drawn to a window, the plug-in is responsible for preserving state information and ensuring that the original state is restored.
For windowless plug-ins, the browser calls the NPP_SetWindow method with an NPWindow structure that represents a drawable. For windowed plug-ins, the browser calls the NPP_SetWindow
method with an NPWindow
structure that represents a window.
//The NPWindow Structure
typedef enum {
NPWindowTypeWindow = 1,
NPWindowTypeDrawable
} NPWindowType;
typedef struct _NPWindow
{
void* window; /* Platform-specific handle */
uint32 x; /* Position of top-left corner */
uint32 y; /* relative to a Netscape page */
uint32 width; /* Maximum window size */
uint32 height;
NPRect clipRect; /* Clipping rectangle in port coordinates */
#ifdef XP_UNIX
void * ws_info; /* Platform-dependent additional data */
#endif /* XP_UNIX */
NPWindowType type; /* Whether this is a window or a drawable */
} NPWindow;
The type field indicates the NPWindow
type of the target area:
- NPWindowType Window: Windowed plug-in. The window field holds a platform-specific handle to a window.
- NPWindowType Drawable: Windowless plug-in. The window field holds a platform-specific handle to a drawable
由type来决定这个Plugin是一个windowed还是一个windowless
Drawing Plug-ins
This section describes the methods and processes you use in drawing both windowed and windowless plug-ins. Processes that apply to only one of these plug-in types are described in the following sections.
The plug-in uses these methods to draw plug-ins and to handle events:
Plug-in methods, called by the browser:
- NPP_HandleEvent : Deliver a platform-specific event to the instance.
- NPP_Print : Request a platform-specific print operation for the instance.
- NPP_SetWindow : Set the window in which a plug-in draws.
Browser-side methods, called by the plug-in:
- NPN_ForceRedraw : Force a paint message to a windowless plug-in.
- NPN_InvalidateRect : Invalidate an area in a windowless plug-in before repainting or refreshing.
- NPN_InvalidateRegion : Invalidate a region in a windowless plug-in before repainting or refreshing.
Printing the Plug-in
The browser calls the NPP_Print
method to ask the plug-in instance to print itself.
void NPP_Print(NPP instance, NPPrint *printInfo);
The PrintInfo
parameter determines the print mode. It is set to either NP_FULL
to indicate full-page plug-in printing, or NP_EMBED
if this is an embedded plug-in printed as part of the window in which it is embedded.
- An embedded plug-in shares printing with the browser. The plug-in prints the part of the page it occupies, and the browser handles the rest of the printing process, including displaying print dialog boxes, getting the printer device context, and, of course, printing the rest of the page.
An embedded plug-in can set the pluginPrinted
field in its PrintInfo
parameter to false (the default). This is a field of the _NPFullPrint
substructure of the NPPrint
structure. The browser displays the necessary print dialog boxes and calls NPP_Print
again. This time, PrintInfo->mode
should be set to NP_EMBED
.
- A full-page plug-in handles the print dialog boxes and printing process as it sees fit. In this case, before the browser displays any print dialog boxes,
NPP_Print
is called withPrintInfo->mode
equal toNP_FULL
. On Mac OS, full-page printing requires that the field PrintInfo contain a standard Mac OS THPrint (seePrinting.h
).
Of course, NPP_Print
is also called with PrintInfo->mode
equal to NP_EMBED
when the instance is embedded. In this case, platformPrint->embedPrint.window
contains the window in which the plug-in should print.
NPP_Print这个函数内部看情形应该对传入的printInfo进行详细的分析然后做出不同的事情来才行。
For windowed plug-ins on MS Windows and Unix, thewindow->window
field is a handle to a subwindow of the Netscape window hierarchy.
之前说送入window,再回过头来看,这个Window还得是浏览器所属的才行?是这个意思吧