• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂586 (tree)
時間2013-11-21 01:12:10
作者ornse01

Log Message

implement rendering tree traversal structure for event element position.

Change Summary

差異

--- bchanf/trunk/src/css/cssrendering_box.c (revision 585)
+++ bchanf/trunk/src/css/cssrendering_box.c (revision 586)
@@ -204,3 +204,67 @@
204204 {
205205 treebase_preordertraversal_finalize(&traversal->base);
206206 }
207+
208+/* cssrendering_hittraversal */
209+
210+EXPORT Bool cssrendering_hittraversal_next(cssrendering_hittraversal_t *traversal, cssrendering_hittraversal_result *result)
211+{
212+ Bool cont, ok;
213+ TREEBASE_TRAVERSAL_DIRECTION dir;
214+ union {
215+ cssrendering_basebox_t base;
216+ cssrendering_linebox_t l;
217+ cssrendering_anonymousbox_t a;
218+ cssrendering_blockbox_t b;
219+ } *box;
220+ cssmetric_rectangle_t r;
221+
222+ for (;;) {
223+ cont = treebase_postordertraversal_next(&traversal->base, (treebase_node_t**)&box, &dir);
224+ if (cont == False) {
225+ break;
226+ }
227+ if (dir == TREEBASE_TRAVERSAL_DIRECTION_DOWN) {
228+ if ((box->base.type == CSSRENDEREING_BOX_TYPE_BLOCK)||(box->base.type == CSSRENDEREING_BOX_TYPE_ANONYMOUS)) {
229+ traversal->origin.x += box->base.content_edge.c.left;
230+ traversal->origin.y += box->base.content_edge.c.top;
231+ } else if (box->base.type == CSSRENDEREING_BOX_TYPE_LINE) {
232+ r = box->base.content_edge;
233+ r.c.left += traversal->origin.x;
234+ r.c.top += traversal->origin.y;
235+ r.c.right += traversal->origin.x;
236+ r.c.bottom += traversal->origin.y;
237+ ok = cssmetric_rectangle_andrect(r, traversal->draw);
238+ if (ok == False) {
239+ continue;
240+ }
241+
242+ result->type = CSSRENDERING_HITTRAVERSAL_RESULTTYPE_LINE;
243+ result->data.line.content_edge = r;
244+ result->data.line.nodedata = box->base.userdata;
245+ break;
246+ }
247+ } else {
248+ if ((box->base.type == CSSRENDEREING_BOX_TYPE_BLOCK)||(box->base.type == CSSRENDEREING_BOX_TYPE_ANONYMOUS)) {
249+ traversal->origin.x -= box->base.content_edge.c.left;
250+ traversal->origin.y -= box->base.content_edge.c.top;
251+ } else {
252+ }
253+ }
254+ }
255+
256+ return cont;
257+}
258+
259+EXPORT VOID cssrendering_hittraversal_initialize(cssrendering_hittraversal_t *traversal, cssrendering_blockbox_t *root, cssmetric_rectangle_t draw)
260+{
261+ treebase_postordertraversal_initialize(&traversal->base, &root->base.base);
262+ traversal->origin.x = 0;
263+ traversal->origin.y = 0;
264+ traversal->draw = draw;
265+}
266+
267+EXPORT VOID cssrendering_hittraversal_finalize(cssrendering_hittraversal_t *traversal)
268+{
269+ treebase_postordertraversal_finalize(&traversal->base);
270+}
--- bchanf/trunk/src/css/cssrendering_box.h (revision 585)
+++ bchanf/trunk/src/css/cssrendering_box.h (revision 586)
@@ -110,6 +110,32 @@
110110 };
111111 typedef struct cssrendering_drawtraversal_result_ cssrendering_drawtraversal_result;
112112
113+/* Functionality name: cssrendering */
114+/* Detail name: hittraversal */
115+struct cssrendering_hittraversal_t_ {
116+ treebase_postordertraversal_t base;
117+ cssmetric_point_t origin;
118+ cssmetric_rectangle_t draw;
119+};
120+typedef struct cssrendering_hittraversal_t_ cssrendering_hittraversal_t;
121+
122+/* Functionality name: cssrendering */
123+/* Detail name: hittraversal */
124+/* Data structure identifier: result */
125+struct cssrendering_hittraversal_result_ {
126+ enum {
127+ CSSRENDERING_HITTRAVERSAL_RESULTTYPE_BLOCK,
128+ CSSRENDERING_HITTRAVERSAL_RESULTTYPE_LINE,
129+ } type;
130+ union {
131+ struct {
132+ cssmetric_rectangle_t content_edge;
133+ VP nodedata;
134+ } line;
135+ } data;
136+};
137+typedef struct cssrendering_hittraversal_result_ cssrendering_hittraversal_result;
138+
113139 IMPORT VOID cssrendering_linebox_initialize(cssrendering_linebox_t *box);
114140 IMPORT VOID cssrendering_linebox_finalize(cssrendering_linebox_t *box);
115141 IMPORT VOID cssrendering_linebox_setuserdata(cssrendering_linebox_t *box, VP data);
@@ -128,4 +154,8 @@
128154 IMPORT VOID cssrendering_drawtraversal_finalize(cssrendering_drawtraversal_t *traversal);
129155 IMPORT Bool cssrendering_drawtraversal_next(cssrendering_drawtraversal_t *traversal, cssrendering_drawtraversal_result *result);
130156
157+IMPORT VOID cssrendering_hittraversal_initialize(cssrendering_hittraversal_t *traversal, cssrendering_blockbox_t *root, cssmetric_rectangle_t draw);
158+IMPORT VOID cssrendering_hittraversal_finalize(cssrendering_hittraversal_t *traversal);
159+IMPORT Bool cssrendering_hittraversal_next(cssrendering_hittraversal_t *traversal, cssrendering_hittraversal_result *result);
160+
131161 #endif
--- bchanf/trunk/src/css/test_cssrendering_box.c (revision 585)
+++ bchanf/trunk/src/css/test_cssrendering_box.c (revision 586)
@@ -115,7 +115,86 @@
115115 return ret;
116116 }
117117
118+LOCAL UNITTEST_RESULT test_cssrendering_hittraversal_1()
119+{
120+ cssrendering_blockbox_t root;
121+ cssrendering_anonymousbox_t anon;
122+ cssrendering_linebox_t line[5];
123+ cssrendering_hittraversal_t traversal;
124+ cssrendering_hittraversal_result result;
125+ cssmetric_rectangle_t draw;
126+ Bool cont, line_called[5] = {False, False, False, False, False};
127+ UNITTEST_RESULT ret = UNITTEST_RESULT_PASS;
128+
129+ cssrendering_blockbox_initialize(&root);
130+ cssrendering_anonymousbox_initialize(&anon);
131+ cssrendering_linebox_initialize(line+0);
132+ cssrendering_linebox_initialize(line+1);
133+ cssrendering_linebox_initialize(line+2);
134+ cssrendering_linebox_initialize(line+3);
135+ cssrendering_linebox_initialize(line+4);
136+
137+ cssrendering_blockbox_appendanonymouschild(&root, &anon);
138+ cssrendering_anonymousbox_appendchild(&anon, line+0);
139+ cssrendering_anonymousbox_appendchild(&anon, line+1);
140+ cssrendering_anonymousbox_appendchild(&anon, line+2);
141+ cssrendering_anonymousbox_appendchild(&anon, line+3);
142+ cssrendering_anonymousbox_appendchild(&anon, line+4);
143+
144+ line[0].base.content_edge = (cssmetric_rectangle_t){{0, 0, 100, 100}};
145+ cssrendering_linebox_setuserdata(line+0, line+0);
146+ line[1].base.content_edge = (cssmetric_rectangle_t){{0, 100, 100, 200}};
147+ cssrendering_linebox_setuserdata(line+1, line+1);
148+ line[2].base.content_edge = (cssmetric_rectangle_t){{0, 200, 100, 300}};
149+ cssrendering_linebox_setuserdata(line+2, line+2);
150+ line[3].base.content_edge = (cssmetric_rectangle_t){{0, 300, 100, 400}};
151+ cssrendering_linebox_setuserdata(line+3, line+3);
152+ line[4].base.content_edge = (cssmetric_rectangle_t){{0, 400, 100, 500}};
153+ cssrendering_linebox_setuserdata(line+4, line+4);
154+
155+ draw = (cssmetric_rectangle_t){{25, 150, 75, 350}};
156+ cssrendering_hittraversal_initialize(&traversal, &root, draw);
157+ for (;;) {
158+ cont = cssrendering_hittraversal_next(&traversal, &result);
159+ if (cont == False) {
160+ break;
161+ }
162+ if (result.type != CSSRENDERING_HITTRAVERSAL_RESULTTYPE_LINE) {
163+ continue;
164+ }
165+ if (result.data.line.nodedata == (line+0)) {
166+ line_called[0] = True;
167+ } else if (result.data.line.nodedata == (line+1)) {
168+ line_called[1] = True;
169+ } else if (result.data.line.nodedata == (line+2)) {
170+ line_called[2] = True;
171+ } else if (result.data.line.nodedata == (line+3)) {
172+ line_called[3] = True;
173+ } else if (result.data.line.nodedata == (line+4)) {
174+ line_called[4] = True;
175+ }
176+ }
177+ cssrendering_hittraversal_finalize(&traversal);
178+
179+ if ((line_called[0] == False)&&(line_called[1] != False)&&(line_called[2] != False)&&(line_called[3] != False)&&(line_called[4] == False)) {
180+ ret = UNITTEST_RESULT_PASS;
181+ } else {
182+ ret = UNITTEST_RESULT_FAIL;
183+ }
184+
185+ cssrendering_linebox_finalize(line+4);
186+ cssrendering_linebox_finalize(line+3);
187+ cssrendering_linebox_finalize(line+2);
188+ cssrendering_linebox_finalize(line+1);
189+ cssrendering_linebox_finalize(line+0);
190+ cssrendering_anonymousbox_finalize(&anon);
191+ cssrendering_blockbox_finalize(&root);
192+
193+ return ret;
194+}
195+
118196 EXPORT VOID test_cssrendering_box_main(unittest_driver_t *driver)
119197 {
120198 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_drawtraversal_1);
199+ UNITTEST_DRIVER_REGIST(driver, test_cssrendering_hittraversal_1);
121200 }
Show on old repository browser