• NPAPI插件编写学习记录01


    Apple官网示例:https://developer.apple.com/library/safari/samplecode/NPAPI_Core_Animation_Movie_Plugin/Introduction/Intro.html

    项目名称:NetscapeCoreAnimationMoviePlugin

     相关中文资料地址:http://www.tanhao.me/pieces/1084.html

    一,main.m:

      //通过此方法将浏览器的对象返回给插件

      NPError NP_Initialize(NPNetscapeFuncs* browserFuncs)
      {
          browser = browserFuncs;
          return NPERR_NO_ERROR;
      }
     
      // 每个实例存储结构
    typedef struct PluginObject
    {

      NPP npp;

        NPWindow window;

        CALayer *rootLayer;

        MovieControllerLayer *controllerLayer;

        QTMovieLayer *movieLayer;

        CALayer *mouseDownLayer;

        NSURL *movieURL;

        QTMovie *movie;

        // The NPObject for this scriptable object.

        NPObject *movieNPObject;

    } PluginObject;
    =============================
    =============================

      NP_GetEntryPoints{

        ...

        pluginFuncs->getvalue = NPP_GetValue;

        ...

        }

        ||

        ||

      NPP_GetValue(NPP instance, NPPVariable variable, void *value)

    {

    ......

      obj->movieNPObject = createMovieNPObject(instance, obj->movie);  <=== 【MovieNPObject.m:

    NPObject *createMovieNPObject(NPP npp, QTMovie *movie) 】

    ......

    }

      ||

      ||

    二,MovieNPObject.m:

      NPObject *createMovieNPObject(NPP npp, QTMovie *movie)

    {

    ......

      (MovieNPObject *)browser->createobject(npp, &movieNPClass);

    ......

    }

      ||

      ||

    static NPClass movieNPClass = {

        NP_CLASS_STRUCT_VERSION,

        movieNPObjectAllocate, // NP_Allocate

        movieNPObjectDeallocate, // NP_Deallocate

        0, // NP_Invalidate

        movieNPObjectHasMethod, // NP_HasMethod

        movieNPObjectInvoke, // NP_Invoke

        0, // NP_InvokeDefault

        0, // NP_HasProperty

        0, // NP_GetProperty

        0, // NP_SetProperty

        0, // NP_RemoveProperty

        0, // NP_Enumerate

        0, // NP_Construct

    };

      ||

      ||

    static bool movieNPObjectHasMethod(NPObject *obj, NPIdentifier name)

    {......}

    static bool movieNPObjectInvoke(NPObject *npObject, NPIdentifier name, const NPVariant* args, uint32_t argCount, NPVariant* result)

    {......}

    ===============

    ===============

    ===============

    关于MovieControllerLayer

    一,main.m:

    typedef struct PluginObject

    {

    ......

    MovieControllerLayer *controllerLayer;

    ......

    }

    对controllerLayer的使用:

    handleMouseDown{} ==> MovieControllerLayer类:MovieControllerLayer.m

    handleMouseUp{}

    handleMouseDragged{}

    handleMouseEntered{}

    handleMouseExited{}

    setupLayerHierarchy{}

     ==============

    ================

    MovieNPObject.m:
      

    static NPClass movieNPClass = {

        NP_CLASS_STRUCT_VERSION,

        movieNPObjectAllocate, // NP_Al

     }

      ||

      

    static NPObject *movieNPObjectAllocate(NPP npp, NPClass* theClass)

    {

        initializeIdentifiers();

        MovieNPObject *movieNPObject = malloc(sizeof(MovieNPObject));

        movieNPObject->movie = 0;

        return (NPObject *)movieNPObject;

    }

      ||

    static void initializeIdentifiers(void)

    {

        static bool identifiersInitialized;

        if (identifiersInitialized)

            return;

        // Take all method identifier names and convert them to NPIdentifiers.

        browser->getstringidentifiers(methodIdentifierNames, NUM_METHOD_IDENTIFIERS, methodIdentifiers);

        identifiersInitialized = true;

    }

        ||

    static NPIdentifier methodIdentifiers[NUM_METHOD_IDENTIFIERS];

    static const NPUTF8 *methodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {

        "play",

        "pause",

    };

      ||

    使用的地方:

    movieNPObjectHasMethod{}

    movieNPObjectInvoke{}

  • 相关阅读:
    Android 布局中 如何使控件居中
    VGA, QVGA, HVGA, WVGA, FWVGA和iPhone显示分辨率
    [转+整理] Android 分辨率,密度,像素单位说明
    多线程的知识点总结
    集合的相关信息
    spring cloud详解
    iostat实时监控磁盘util
    Jenkins安装过程
    hdfs的block为什么设置成128M
    shell变量自增的几种方式
  • 原文地址:https://www.cnblogs.com/Miami/p/3315509.html
Copyright © 2020-2023  润新知