comparison nodejs/coord.cc @ 562:1b6402f07cd4 Android_Skia

Make root coord availabe for Javascript code
author Thinker K.F. Li <thinker@branda.to>
date Mon, 07 Jun 2010 14:45:01 +0800
parents ce7a35abcb0d
children bc207070e3d5
comparison
equal deleted inserted replaced
561:a3c13c2a4792 562:1b6402f07cd4
69 coord_obj_temp->SetIndexedPropertyHandler(xnjsmb_coord_get_index, 69 coord_obj_temp->SetIndexedPropertyHandler(xnjsmb_coord_get_index,
70 xnjsmb_coord_set_index); 70 xnjsmb_coord_set_index);
71 coord_obj_temp->SetInternalFieldCount(1); 71 coord_obj_temp->SetInternalFieldCount(1);
72 } 72 }
73 73
74 static Handle<Object>
75 xnjsmb_coord_new_jsobj(coord_t *coord, Handle<Object> parent_obj,
76 Handle<Object> js_rt) {
77 Handle<Object> coord_obj;
78 static int init_temp = 0;
79
80 if(!init_temp) {
81 xnjsmb_init_temp();
82 init_temp = 1;
83 }
84
85 coord_obj = coord_obj_temp->NewInstance();
86 ASSERT(coord_obj != NULL);
87 WRAP(coord_obj, coord);
88
89 if(!parent_obj.IsEmpty())
90 SET(coord_obj, "parent", parent_obj);
91 SET(coord_obj, "mbrt", js_rt);
92
93 return coord_obj;
94 }
95
74 /*! \brief Create a coord object associated with the rdman of the runtime. 96 /*! \brief Create a coord object associated with the rdman of the runtime.
75 * 97 *
76 * Two internal fields, coord and rdman. 98 * Two internal fields, coord and rdman.
77 */ 99 */
78 Handle<Value> 100 Handle<Value>
82 Handle<Object> coord_obj, parent_obj; 104 Handle<Object> coord_obj, parent_obj;
83 njs_runtime_t *rt; 105 njs_runtime_t *rt;
84 redraw_man_t *rdman; 106 redraw_man_t *rdman;
85 coord_t *coord, *parent = NULL; 107 coord_t *coord, *parent = NULL;
86 int argc; 108 int argc;
87 static int init_temp = 0;
88
89 if(!init_temp) {
90 xnjsmb_init_temp();
91 init_temp = 1;
92 }
93 109
94 argc = args.Length(); 110 argc = args.Length();
95 if(argc > 1) 111 if(argc > 1)
96 THROW("Too many arguments (> 1)"); 112 THROW("Too many arguments (> 1)");
97 113
102 if(argc == 1) { 118 if(argc == 1) {
103 parent_obj = args[0]->ToObject(); 119 parent_obj = args[0]->ToObject();
104 parent = (coord_t *)UNWRAP(parent_obj); 120 parent = (coord_t *)UNWRAP(parent_obj);
105 } 121 }
106 122
107 /*
108 * Set Javascript object
109 */
110 coord = rdman_coord_new(rdman, parent); 123 coord = rdman_coord_new(rdman, parent);
111 ASSERT(coord != NULL); 124 ASSERT(coord != NULL);
125 coord_obj = xnjsmb_coord_new_jsobj(coord, parent_obj, js_rt);
112 126
113 coord_obj = coord_obj_temp->NewInstance();
114 ASSERT(coord_obj != NULL);
115 WRAP(coord_obj, coord);
116
117 if(parent != NULL)
118 SET(coord_obj, "parent", parent_obj);
119 SET(coord_obj, "mbrt", js_rt);
120
121 return coord_obj; 127 return coord_obj;
122 } 128 }
129
130 /*! \brief Initialize Javascript object for root coord of a runtime.
131 *
132 * \param js_rt is the runtime object to create the root object for.
133 *
134 * After the function, js_rt.root is the object for root coord in
135 * Javascript.
136 */
137 void
138 xnjsmb_coord_mkroot(Handle<Object> js_rt) {
139 redraw_man_t *rdman;
140 coord_t *root;
141 Handle<Object> obj;
142
143 rdman = xnjsmb_rt_rdman(js_rt);
144 root = rdman_get_root(rdman);
145 obj = xnjsmb_coord_new_jsobj(root, Handle<Object>(NULL), js_rt);
146
147 SET(js_rt, "root", obj);
148 }