我已经创建了简单的 hello world-like 插件,它绘制了红色框。
嵌入到 xulrunner 应用程序后,插件几乎可以正常工作。Xulrunner 应用程序在调整应用程序窗口大小时成功重绘了框。
但是在任何鼠标事件之后,例如左键单击,我的应用程序会因“堆栈溢出”而崩溃。调试器说原因是 2 次 forwardMethod 调用和 1 次 JSD_GetValueForObject 调用的无限循环
崩溃后的堆栈内容是下一个:
-[NSApplication _indexOfWindow:]
-[NSEvent window]
JSD_GetValueForObject
JSD_GetValueForObject
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
JSD_GetValueForObject
forwardMethod
forwardMethod
- .....ETC
我的代码是:
int16_t NPP_HandleEvent(NPP instance, void* event)
{
EventRecord* carbonEvent = (EventRecord*)event;
if (carbonEvent && (carbonEvent->what == updateEvt))
{
PluginInstance* currentInstance = (PluginInstance*)(instance->pdata);
CGContextRef cgContext = ((NP_CGContext*)(currentInstance->window.window))->context;
float windowWidth = currentInstance->window.width;
float windowHeight = currentInstance->window.height;
static int x = 0;
if (x++)
return;
NPRect clipRect = currentInstance->window.clipRect;
NP_CGContext* npContext = currentInstance->window.window;
NSWindow* browserWindow = [[[NSWindow alloc] initWithWindowRef:npContext->window] autorelease];
int y = [browserWindow frame].size.height - (clipRect.bottom - clipRect.top) - currentInstance->window.y;
//[plugin attachToWindow:browserWindow at:NSMakePoint(window->x, y)];
NSPoint point = NSMakePoint(currentInstance->window.x, y);
// find the NSView at the point
NSView* hitView = [[browserWindow contentView] hitTest:NSMakePoint(point.x+1, point.y+1)];
if (hitView == nil || ![[hitView className] isEqualToString:@"ChildView"])
{
x = 0;
return;
}
NSView* parentView = hitView;
NSBox *box = [[NSBox alloc] initWithFrame:NSMakeRect(0.0, 0.0, 100, 100)];
[box setBoxType:NSBoxCustom];
[box setBorderType:NSLineBorder];
[box setTitlePosition:NSNoTitle];
[box setFillColor:[NSColor redColor]];
[parentView addSubview:box];
//DrawPlugin(cgContext, windowWidth, windowHeight);
}
return 0;
}