gpt4 book ai didi

cocoa - 火狐 cocoa 插件

转载 作者:行者123 更新时间:2023-12-03 16:56:12 26 4
gpt4 key购买 nike

我创建了简单的类似 hello world 的插件,它绘制了红色框。

嵌入 xulrunner 应用程序后,该插件几乎可以正常工作。 Xulrunner 应用程序在调整应用程序窗口大小时成功重绘了框。

但是在发生任何鼠标事件(例如左键单击)之后,我的应用程序会因“堆栈溢出”而崩溃。调试器表示原因是 2 次调用forwardMethod 后跟一次调用 JSD_GetValueForObject 的无限循环

崩溃后堆栈内容是下一个:

  • -[NSApplication _indexOfWindow:]
  • -[NSEvent 窗口]
  • 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
  • ......等等

我的代码是:

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;
}

最佳答案

非常感谢你,Winz!

我刚刚从

下载了最新的 mozilla 版本和 SDK

http://ftp.mozilla.org/pub/mozilla.org/xulrunner/nightly/latest-trunk/

以及来自

的 BasicPlugin.xcodeproj

http://mxr.mozilla.org/mozilla-central/source/modules/plugin/sdk/samples/basic/mac/

现在可以访问 Cocoa 事件模型。

关于cocoa - 火狐 cocoa 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1770415/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com