Firefox可可插件 [英] Firefox Cocoa Plugin

查看:104
本文介绍了Firefox可可插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的hello world-like插件,该插件绘制了红色框。

I`ve created simple hello world-like plugin which draws red box.

将fter嵌入到xulrunner应用程序中后,该插件几乎可以正常工作。 Xulrunner应用程序成功重绘了应用程序窗口大小的框。

Аfter embedding into xulrunner application the plugin works almost fine. Xulrunner application successfully redraws the box on resizing the application window.

但是在发生任何鼠标事件后,例如-左键单击,我的应用程序因堆栈溢出而崩溃。调试器说,原因是连续两次调用forwardMethod,然后再调用JSD_GetValueForObject

But after any mouse event, for instance - left click, my application crashes with "Stack overflow". Debugger says the reason is endless cycle of 2 calls of forwardMethod followed by one call of 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

  • forwardMeth od

  • forwardMethod

  • JSD_GetValueForObject

  • forwardMethod

  • forwardMethod

  • ..... etc

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


推荐答案

我不认为可可

可可事件模型现在可以在最新版的mozilla中使用。

A cocoa event model is now avalaible in the last build of mozilla.

使用 Mercurial 并尝试:

hg clone http:// hg.mozilla.org/mozilla-central/ src

Xcode项目的路径为:

src / modules / plugin / sdk / samples / basic / mac /

,必须将插件复制到:

/ Library / Internet Plug-Ins /

Check-out the tree for comm-central with Mercurial and try it:
hg clone http://hg.mozilla.org/mozilla-central/ src
The path to the Xcode project is:
src/modules/plugin/sdk/samples/basic/mac/
and the plugin must be copied to:
/Library/Internet Plug-Ins/

我自己使用基本的firefox插件尝试了一下,可可事件系统也起作用了。

我只是不知道如何获取当前指针NSView。

I tried it myself with the basic firefox plugin and the cocoa event system works.
I just do not know how to get a pointer to the current NSView.

我认为必须在Mac上的64位版本的Firefox中完成此操作。它在Firefox 3.6中不可用,但在Firefox 3.7中可能可用,并且带有Cocoa事件模型的NPAPI SDK的版本是0.23。

I think it had to be done for the 64 bits version of Firefox on mac. It is not available in Firefox 3.6, but might be in Firefox 3.7, and the version of the NPAPI SDK with the Cocoa event model is the version 0.23.

编辑:< br>
要直接尝试而不用花钱,请以Misha的身份下载最新的mozilla版本:

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

具有Cocoa事件模型的Xcode项目位于:

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

Webkit来源中的NetscapeCocoaPlugin示例也使用了可可事件模型。

The NetscapeCocoaPlugin sample in the Webkit sources use the cocoa event model too.

这篇关于Firefox可可插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆