• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂599 (tree)
時間2014-02-15 23:12:24
作者ornse01

Log Message

add block box handling to rendering traversal.

Change Summary

差異

--- bchanf/trunk/src/css/cssrendering_box.c (revision 598)
+++ bchanf/trunk/src/css/cssrendering_box.c (revision 599)
@@ -1,7 +1,7 @@
11 /*
22 * cssrendering_box.c
33 *
4- * Copyright (c) 2013 project bchan
4+ * Copyright (c) 2013-2014 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -160,9 +160,28 @@
160160 break;
161161 }
162162 if (dir == TREEBASE_TRAVERSAL_DIRECTION_DOWN) {
163- if ((box->base.type == CSSRENDEREING_BOX_TYPE_BLOCK)||(box->base.type == CSSRENDEREING_BOX_TYPE_ANONYMOUS)) {
163+ if (box->base.type == CSSRENDEREING_BOX_TYPE_ANONYMOUS) {
164164 traversal->origin.x += box->base.content_edge.c.left;
165165 traversal->origin.y += box->base.content_edge.c.top;
166+ } else if (box->base.type == CSSRENDEREING_BOX_TYPE_BLOCK) {
167+ r = box->base.content_edge;
168+ r.c.left += traversal->origin.x;
169+ r.c.top += traversal->origin.y;
170+ r.c.right += traversal->origin.x;
171+ r.c.bottom += traversal->origin.y;
172+
173+ traversal->origin.x += box->base.content_edge.c.left;
174+ traversal->origin.y += box->base.content_edge.c.top;
175+
176+ ok = cssmetric_rectangle_andrect(r, traversal->draw);
177+ if (ok == False) {
178+ continue;
179+ }
180+
181+ result->type = CSSRENDERING_DRAWTRAVERSAL_RESULTTYPE_BLOCK;
182+ result->data.block.content_edge = r;
183+ result->data.block.nodedata = box->base.userdata;
184+ break;
166185 } else if (box->base.type == CSSRENDEREING_BOX_TYPE_LINE) {
167186 r = box->base.content_edge;
168187 r.c.left += traversal->origin.x;
--- bchanf/trunk/src/css/cssrendering_box.h (revision 598)
+++ bchanf/trunk/src/css/cssrendering_box.h (revision 599)
@@ -99,6 +99,7 @@
9999 struct cssrendering_drawtraversal_result_ {
100100 enum {
101101 CSSRENDERING_DRAWTRAVERSAL_RESULTTYPE_TEXT,
102+ CSSRENDERING_DRAWTRAVERSAL_RESULTTYPE_BLOCK,
102103 } type;
103104 union {
104105 struct {
@@ -106,6 +107,10 @@
106107 cssrendering_textfragment_t *fragment;
107108 VP nodedata;
108109 } text;
110+ struct {
111+ cssmetric_rectangle_t content_edge;
112+ VP nodedata;
113+ } block;
109114 } data;
110115 };
111116 typedef struct cssrendering_drawtraversal_result_ cssrendering_drawtraversal_result;
--- bchanf/trunk/src/css/test_cssrendering_box.c (revision 598)
+++ bchanf/trunk/src/css/test_cssrendering_box.c (revision 599)
@@ -114,6 +114,7 @@
114114
115115 return ret;
116116 }
117+
117118 LOCAL UNITTEST_RESULT test_cssrendering_drawtraversal_2()
118119 {
119120 cssrendering_blockbox_t root, block[5];
@@ -224,6 +225,79 @@
224225 return ret;
225226 }
226227
228+LOCAL UNITTEST_RESULT test_cssrendering_drawtraversal_3()
229+{
230+ cssrendering_blockbox_t root, block[5];
231+ cssrendering_drawtraversal_t traversal;
232+ cssrendering_drawtraversal_result result;
233+ cssmetric_rectangle_t draw;
234+ Bool cont, block_called[5] = {False, False, False, False, False};
235+ UNITTEST_RESULT ret = UNITTEST_RESULT_PASS;
236+
237+ cssrendering_blockbox_initialize(&root);
238+ cssrendering_blockbox_initialize(block+0);
239+ cssrendering_blockbox_initialize(block+1);
240+ cssrendering_blockbox_initialize(block+2);
241+ cssrendering_blockbox_initialize(block+3);
242+ cssrendering_blockbox_initialize(block+4);
243+
244+ cssrendering_blockbox_appendblockchild(&root, block+0);
245+ cssrendering_blockbox_appendblockchild(&root, block+1);
246+ cssrendering_blockbox_appendblockchild(&root, block+2);
247+ cssrendering_blockbox_appendblockchild(&root, block+3);
248+ cssrendering_blockbox_appendblockchild(&root, block+4);
249+
250+ block[0].base.content_edge = (cssmetric_rectangle_t){{0, 0, 100, 100}};
251+ cssrendering_blockbox_setuserdata(block+0, block+0);
252+ block[1].base.content_edge = (cssmetric_rectangle_t){{0, 100, 100, 200}};
253+ cssrendering_blockbox_setuserdata(block+1, block+1);
254+ block[2].base.content_edge = (cssmetric_rectangle_t){{0, 200, 100, 300}};
255+ cssrendering_blockbox_setuserdata(block+2, block+2);
256+ block[3].base.content_edge = (cssmetric_rectangle_t){{0, 300, 100, 400}};
257+ cssrendering_blockbox_setuserdata(block+3, block+3);
258+ block[4].base.content_edge = (cssmetric_rectangle_t){{0, 400, 100, 500}};
259+ cssrendering_blockbox_setuserdata(block+4, block+4);
260+
261+ draw = (cssmetric_rectangle_t){{25, 150, 75, 350}};
262+ cssrendering_drawtraversal_initialize(&traversal, &root, draw);
263+ for (;;) {
264+ cont = cssrendering_drawtraversal_next(&traversal, &result);
265+ if (cont == False) {
266+ break;
267+ }
268+ if (result.type != CSSRENDERING_DRAWTRAVERSAL_RESULTTYPE_BLOCK) {
269+ continue;
270+ }
271+ if (result.data.block.nodedata == (block+0)) {
272+ block_called[0] = True;
273+ } else if (result.data.block.nodedata == (block+1)) {
274+ block_called[1] = True;
275+ } else if (result.data.block.nodedata == (block+2)) {
276+ block_called[2] = True;
277+ } else if (result.data.block.nodedata == (block+3)) {
278+ block_called[3] = True;
279+ } else if (result.data.block.nodedata == (block+4)) {
280+ block_called[4] = True;
281+ }
282+ }
283+ cssrendering_drawtraversal_finalize(&traversal);
284+
285+ if ((block_called[0] == False)&&(block_called[1] != False)&&(block_called[2] != False)&&(block_called[3] != False)&&(block_called[4] == False)) {
286+ ret = UNITTEST_RESULT_PASS;
287+ } else {
288+ ret = UNITTEST_RESULT_FAIL;
289+ }
290+
291+ cssrendering_blockbox_finalize(block+4);
292+ cssrendering_blockbox_finalize(block+3);
293+ cssrendering_blockbox_finalize(block+2);
294+ cssrendering_blockbox_finalize(block+1);
295+ cssrendering_blockbox_finalize(block+0);
296+ cssrendering_blockbox_finalize(&root);
297+
298+ return ret;
299+}
300+
227301 LOCAL UNITTEST_RESULT test_cssrendering_hittraversal_1()
228302 {
229303 cssrendering_blockbox_t root;
@@ -399,6 +473,7 @@
399473 {
400474 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_drawtraversal_1);
401475 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_drawtraversal_2);
476+ UNITTEST_DRIVER_REGIST(driver, test_cssrendering_drawtraversal_3);
402477 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_hittraversal_1);
403478 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_blockbox_appendchild1);
404479 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_blockbox_appendchild2);
Show on old repository browser