File: ewk_js.h

package info (click to toggle)
qtwebkit-opensource-src 5.7.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 291,692 kB
  • ctags: 268,122
  • sloc: cpp: 1,360,420; python: 70,286; ansic: 42,986; perl: 35,476; ruby: 12,236; objc: 9,465; xml: 8,396; asm: 3,873; yacc: 2,397; sh: 1,647; makefile: 650; lex: 644; java: 110
file content (209 lines) | stat: -rw-r--r-- 5,920 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
    Copyright (C) 2011 ProFUSION embedded systems

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

/**
 * @file    ewk_js.h
 * @brief   Allows to export objects to JavaScript API.
 */

#ifndef ewk_js_h
#define ewk_js_h

#include <Eina.h>
#include <Evas.h>

#ifdef __cplusplus
extern "C" {
#endif

#define EWK_JS_CLASS_META_VERSION 0

typedef struct _Ewk_JS_Object Ewk_JS_Object;
typedef struct _Ewk_JS_Class_Meta Ewk_JS_Class_Meta;
typedef struct _Ewk_JS_Variant Ewk_JS_Variant;
typedef struct _Ewk_JS_Method Ewk_JS_Method;
typedef struct _Ewk_JS_Property Ewk_JS_Property;
typedef struct _Ewk_JS_Default Ewk_JS_Default;
typedef Eina_Bool (*Ewk_JS_Set_Cb)(Ewk_JS_Object *obj, const char *name, const Ewk_JS_Variant *value);
typedef Eina_Bool (*Ewk_JS_Get_Cb)(Ewk_JS_Object *obj, const char *name, Ewk_JS_Variant *value);
typedef Eina_Bool (*Ewk_JS_Del_Cb)(Ewk_JS_Object *obj, const char *name);
typedef Ewk_JS_Variant* (*Ewk_JS_Invoke_Cb)(Ewk_JS_Object *obj, Ewk_JS_Variant *args, int argCount);

typedef enum {
    EWK_JS_VARIANT_VOID,
    EWK_JS_VARIANT_NULL,
    EWK_JS_VARIANT_BOOL,
    EWK_JS_VARIANT_INT32,
    EWK_JS_VARIANT_DOUBLE,
    EWK_JS_VARIANT_STRING,
    EWK_JS_VARIANT_OBJECT
} Ewk_JS_Variant_Type;

typedef enum {
    EWK_JS_OBJECT_OBJECT,
    EWK_JS_OBJECT_ARRAY,
    EWK_JS_OBJECT_FUNCTION,
    EWK_JS_OBJECT_INVALID
} Ewk_JS_Object_Type;

struct _Ewk_JS_Variant {
    Ewk_JS_Variant_Type type;
    union {
        Eina_Bool b;
        int i;
        double d;
        const char *s;
        Ewk_JS_Object *o;
    } value;
};

struct _Ewk_JS_Method {
    const char *name;
    Ewk_JS_Invoke_Cb invoke;
};

struct _Ewk_JS_Property {
    const char *name;
    Ewk_JS_Set_Cb set;
    Ewk_JS_Get_Cb get;
    Ewk_JS_Del_Cb del;
    Ewk_JS_Variant value;
};

struct _Ewk_JS_Default {
    Ewk_JS_Set_Cb set;
    Ewk_JS_Get_Cb get;
    Ewk_JS_Del_Cb del;
};

struct _Ewk_JS_Class_Meta {
    unsigned int version; // define
    const Ewk_JS_Method *methods; // null terminated array
    const Ewk_JS_Property *properties; // null terminated array
    Ewk_JS_Default default_prop;
};

/**
 * Gets Eina_Hash with object's properties.
 *
 * @param obj Object whose properties are wanted.
 *
 * @return object's properties.
 */
EAPI Eina_Hash *ewk_js_object_properties_get(const Ewk_JS_Object *obj);

/**
 * Gets name of the object.
 *
 * @param obj Object whose name is wanted.
 *
 * @return name of object.
 */

EAPI const char *ewk_js_object_name_get(const Ewk_JS_Object *obj);

/**
 * Returns the view associated with an Ewk_JS_Object.
 *
 * The returned view is the one passed to ewk_view_js_object_add. Right now,
 * the object is always added to the view's main frame.
 *
 * @param obj The object to be queried.
 *
 * @return The view whose main frame the object has been inserted into, or
 *         @c NULL if the object has not been added to a view yet.
 *
 * @sa ewk_view_js_object_add, ewk_view_frame_main_get
 */
EAPI Evas_Object *ewk_js_object_view_get(const Ewk_JS_Object *obj);

/**
 * Release resources allocated by @a var.
 *
 * @param var @a Ewk_JS_Variant to be release
 */
EAPI void ewk_js_variant_free(Ewk_JS_Variant *var);

/**
 * Release resources allocated by @a var.
 *
 * @param var @a Ewk_JS_Variant to be release
 * @param count @a size of array
 */
EAPI void ewk_js_variant_array_free(Ewk_JS_Variant *var, int count);

/**
 * Create a Ewk_JS_Object to be used in @a ewk_view_js_object_add. The Meta class's
 * methods and properties are not modified but references to it are kept as long
 * as the object created from it lives. All properties created here
 * will be added to the object hash of properties. Properties using default_prop's
 * get/set/del methods should also be added to the objects hash(see:
 * @a ewk_js_object_properties_get). Methods must free the arguments they receive(see:
 * @a ewk_js_variang_array_free).
 *
 *
 * @param cls @a Ewk_JS_Class that describes the object to be created.
 *
 * @return The Ewk_JS_Object created.
 */
EAPI Ewk_JS_Object *ewk_js_object_new(const Ewk_JS_Class_Meta *meta_cls);

/**
 * Release resources allocated by @a obj.
 *
 * @param obj @a Ewk_JS_Object to be released.
 */
EAPI void ewk_js_object_free(Ewk_JS_Object *obj);

/**
 * Calls the function this object represents.
 *
 * @param obj Object that represents function.
 * @param args Arguments to be passed to function.
 * @param arg_count Number of arguments.
 * @param result Return value of the invoked function.
 *
 * @return @c EINA_TRUE if function was executed, @c EINA_FALSE if function was not executed.
 */
EAPI Eina_Bool ewk_js_object_invoke(Ewk_JS_Object *obj, Ewk_JS_Variant *args, int arg_count, Ewk_JS_Variant *result);

/**
 * Returns the type this object represents.
 *
 * @param obj Object
 *
 * @return @c EWK_JS_OBJECT if it is an object, @c EWK_JS_ARRAY if it is an array and
 * @c EWK_JS_FUNCTION if it is a function.
 */
EAPI Ewk_JS_Object_Type ewk_js_object_type_get(Ewk_JS_Object *obj);

/**
 * Sets the type this object represents.
 *
 * @param obj Object
 * @param type Type
 *
 */
EAPI void ewk_js_object_type_set(Ewk_JS_Object *obj, Ewk_JS_Object_Type type);

#ifdef __cplusplus
}
#endif

#endif // ewk_js_h