зеркало из https://github.com/mozilla/pjs.git
Bug 469830 - Windows drawing code for test plugin. r=ted,joshmoz
This commit is contained in:
Родитель
21009584b6
Коммит
b1eb90c3f5
|
@ -1,3 +1,3 @@
|
|||
# basic sanity checking
|
||||
random-if(!haveTestPlugin||MOZ_WIDGET_TOOLKIT!="cocoa") != plugin-sanity.html about:blank
|
||||
fails-if(!haveTestPlugin||MOZ_WIDGET_TOOLKIT!="cocoa") == plugin-sanity.html div-sanity.html
|
||||
random-if(!haveTestPlugin||MOZ_WIDGET_TOOLKIT!="cocoa"||MOZ_WIDGET_TOOLKIT!="windows") != plugin-sanity.html about:blank
|
||||
fails-if(!haveTestPlugin||MOZ_WIDGET_TOOLKIT!="cocoa"||MOZ_WIDGET_TOOLKIT!="windows") == plugin-sanity.html div-sanity.html
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
|
||||
NPError pluginInstanceInit(InstanceData* instanceData);
|
||||
int16_t pluginHandleEvent(InstanceData* instanceData, void* event);
|
||||
// draws a gray box with a black border containing the browser UA string
|
||||
void pluginDraw(InstanceData* instanceData);
|
||||
|
||||
#endif // nptest_platform_h_
|
||||
|
|
|
@ -28,11 +28,19 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Josh Aas <josh@mozilla.com>
|
||||
* Jim Mathies <jmathies@mozilla.com>
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nptest_platform.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <unknwn.h>
|
||||
#include <gdiplus.h>
|
||||
using namespace Gdiplus;
|
||||
|
||||
#pragma comment(lib, "gdiplus.lib")
|
||||
|
||||
NPError
|
||||
pluginInstanceInit(InstanceData* instanceData)
|
||||
{
|
||||
|
@ -42,10 +50,116 @@ pluginInstanceInit(InstanceData* instanceData)
|
|||
int16_t
|
||||
pluginHandleEvent(InstanceData* instanceData, void* event)
|
||||
{
|
||||
NPEvent * pe = (NPEvent*) event;
|
||||
|
||||
if (pe == NULL || instanceData == NULL ||
|
||||
instanceData->window.type != NPWindowTypeDrawable)
|
||||
return 0;
|
||||
|
||||
switch((UINT)pe->event) {
|
||||
case WM_PAINT:
|
||||
pluginDraw(instanceData);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Color
|
||||
GetColorsFromRGBA(PRUint32 rgba)
|
||||
{
|
||||
BYTE r, g, b, a;
|
||||
b = (rgba & 0xFF);
|
||||
g = ((rgba & 0xFF00) >> 8);
|
||||
r = ((rgba & 0xFF0000) >> 16);
|
||||
a = ((rgba & 0xFF000000) >> 24);
|
||||
return Color(a, r, g, b);
|
||||
}
|
||||
|
||||
void
|
||||
pluginDraw(InstanceData* instanceData)
|
||||
{
|
||||
NPP npp = instanceData->npp;
|
||||
if (!npp)
|
||||
return;
|
||||
|
||||
const char* uaString = NPN_UserAgent(npp);
|
||||
if (!uaString)
|
||||
return;
|
||||
|
||||
HDC hdc = (HDC)instanceData->window.window;
|
||||
|
||||
if (hdc == NULL)
|
||||
return;
|
||||
|
||||
// Push the browser's hdc on the resource stack. This test plugin is windowless,
|
||||
// so we share the drawing surface with the rest of the browser.
|
||||
int savedDCID = SaveDC(hdc);
|
||||
|
||||
// Reset the clipping region
|
||||
SelectClipRgn(hdc, NULL);
|
||||
|
||||
// Initialize GDI+.
|
||||
GdiplusStartupInput gdiplusStartupInput;
|
||||
ULONG_PTR gdiplusToken;
|
||||
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
|
||||
|
||||
// Calculate the rectangle coordinates from the instanceData information
|
||||
Rect rect(instanceData->window.x, instanceData->window.y,
|
||||
instanceData->window.width, instanceData->window.height);
|
||||
|
||||
// Create a layout rect for the text
|
||||
RectF boundRect((float)instanceData->window.x, (float)instanceData->window.y,
|
||||
(float)instanceData->window.width, (float)instanceData->window.height);
|
||||
boundRect.Inflate(-10.0, -10.0);
|
||||
|
||||
switch(instanceData->scriptableObject->drawMode) {
|
||||
case DM_DEFAULT:
|
||||
{
|
||||
Graphics graphics(hdc);
|
||||
|
||||
// Fill in the background and border
|
||||
Pen blackPen(Color(255, 0, 0, 0), 5);
|
||||
SolidBrush grayBrush(Color(255, 192, 192, 192));
|
||||
|
||||
graphics.FillRectangle(&grayBrush, rect);
|
||||
graphics.DrawRectangle(&blackPen, rect);
|
||||
|
||||
// Load a nice font
|
||||
FontFamily fontFamily(L"Helvetica");
|
||||
Font font(&fontFamily, 20, FontStyleBold, UnitPoint);
|
||||
StringFormat stringFormat;
|
||||
SolidBrush solidBrush(Color(255, 0, 0, 0));
|
||||
|
||||
// Center the text string
|
||||
stringFormat.SetAlignment(StringAlignmentCenter);
|
||||
stringFormat.SetLineAlignment(StringAlignmentCenter);
|
||||
|
||||
// Request anti-aliased text
|
||||
graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
|
||||
|
||||
WCHAR wBuf[1024];
|
||||
memset(&wBuf, 0, sizeof(wBuf));
|
||||
MultiByteToWideChar(CP_ACP, 0, uaString, -1, wBuf, 1024);
|
||||
|
||||
// Draw the string
|
||||
graphics.DrawString(wBuf, -1, &font, boundRect, &stringFormat, &solidBrush);
|
||||
}
|
||||
break;
|
||||
|
||||
case DM_SOLID_COLOR:
|
||||
{
|
||||
// Fill the plugin window with a solid color specified by the params
|
||||
Graphics graphics(hdc);
|
||||
SolidBrush brush(GetColorsFromRGBA(instanceData->scriptableObject->drawColor));
|
||||
graphics.FillRectangle(&brush, rect.X, rect.Y, rect.Width, rect.Height);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Shutdown GDI+
|
||||
GdiplusShutdown(gdiplusToken);
|
||||
|
||||
// Pop our hdc changes off the resource stack
|
||||
RestoreDC(hdc, savedDCID);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче