• R/O
  • HTTP
  • SSH
  • HTTPS

bchanf: Commit

各種ライブラリ


Commit MetaInfo

Revision156ab6407b815c33d8fa192e6676c0a050012239 (tree)
Time2014-11-22 02:38:05
Authorornse01 <ornse01@user...>
Commiterornse01

Log Message

add functions for tree oparations.

git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchanf/trunk@644 20a0b8eb-f62a-4a12-8fe1-b598822500fb

Change Summary

Incremental Difference

--- a/src/css/cssrendering_box.c
+++ b/src/css/cssrendering_box.c
@@ -53,6 +53,39 @@ LOCAL VOID cssrendering_basebox_appendchild(cssrendering_basebox_t *box, cssrend
5353 treebase_node_appendchild(&box->base, &child->base);
5454 }
5555
56+LOCAL W cssrendering_basebox_insertbefore(cssrendering_basebox_t *box, cssrendering_basebox_t *child, cssrendering_basebox_t *ref)
57+{
58+ return treebase_node_insertbefore(&box->base, &child->base, (ref != NULL) ? &ref->base : NULL);
59+}
60+
61+LOCAL cssrendering_basebox_t* cssrendering_basebox_getparent(cssrendering_basebox_t *box)
62+{
63+ return (cssrendering_basebox_t*)treebase_node_getparent(&box->base);
64+}
65+
66+LOCAL W cssrendering_basebox_removechild(cssrendering_basebox_t *box, cssrendering_basebox_t *child)
67+{
68+ cssrendering_basebox_t *parent;
69+
70+ parent = cssrendering_basebox_getparent(child);
71+ if (parent != box) {
72+ return -1; /* TODO */
73+ }
74+ treebase_node_remove(&child->base);
75+
76+ return 0;
77+}
78+
79+LOCAL cssrendering_basebox_t* cssrendering_basebox_getfirstchild(cssrendering_basebox_t *box)
80+{
81+ return (cssrendering_basebox_t*)treebase_node_getfirstchild(&box->base);
82+}
83+
84+LOCAL cssrendering_basebox_t* cssrendering_basebox_getnextsibling(cssrendering_basebox_t *box)
85+{
86+ return (cssrendering_basebox_t*)treebase_node_getnextsibling(&box->base);
87+}
88+
5689 LOCAL VOID cssrendering_basebox_setuserdata(cssrendering_basebox_t *box, VP data)
5790 {
5891 box->userdata = data;
@@ -76,6 +109,11 @@ LOCAL VOID cssrendering_basebox_finalize(cssrendering_basebox_t *box)
76109
77110 /* cssrendering_linebox */
78111
112+EXPORT cssrendering_linebox_t* cssrendering_linebox_getnextsibling(cssrendering_linebox_t *box)
113+{
114+ return (cssrendering_linebox_t*)cssrendering_basebox_getnextsibling(&box->base);
115+}
116+
79117 EXPORT VOID cssrendering_linebox_setuserdata(cssrendering_linebox_t *box, VP data)
80118 {
81119 cssrendering_basebox_setuserdata(&box->base, data);
@@ -98,6 +136,21 @@ EXPORT VOID cssrendering_anonymousbox_appendchild(cssrendering_anonymousbox_t *b
98136 cssrendering_basebox_appendchild(&box->base, &child->base);
99137 }
100138
139+EXPORT W cssrendering_anonymousbox_insertbefore(cssrendering_anonymousbox_t *box, cssrendering_linebox_t *child, cssrendering_linebox_t *ref)
140+{
141+ return cssrendering_basebox_insertbefore(&box->base, &child->base, (ref != NULL) ? &ref->base : NULL);
142+}
143+
144+EXPORT W cssrendering_anonymousbox_removechild(cssrendering_anonymousbox_t *box, cssrendering_linebox_t *child)
145+{
146+ return cssrendering_basebox_removechild(&box->base, &child->base);
147+}
148+
149+EXPORT cssrendering_linebox_t* cssrendering_anonymousbox_getfirstchild(cssrendering_anonymousbox_t *box)
150+{
151+ return (cssrendering_linebox_t*)cssrendering_basebox_getfirstchild(&box->base);
152+}
153+
101154 EXPORT VOID cssrendering_anonymousbox_setuserdata(cssrendering_anonymousbox_t *box, VP data)
102155 {
103156 cssrendering_basebox_setuserdata(&box->base, data);
--- a/src/css/cssrendering_box.h
+++ b/src/css/cssrendering_box.h
@@ -143,11 +143,15 @@ typedef struct cssrendering_hittraversal_result_ cssrendering_hittraversal_resul
143143
144144 IMPORT VOID cssrendering_linebox_initialize(cssrendering_linebox_t *box);
145145 IMPORT VOID cssrendering_linebox_finalize(cssrendering_linebox_t *box);
146+IMPORT cssrendering_linebox_t* cssrendering_linebox_getnextsibling(cssrendering_linebox_t *box);
146147 IMPORT VOID cssrendering_linebox_setuserdata(cssrendering_linebox_t *box, VP data);
147148
148149 IMPORT VOID cssrendering_anonymousbox_initialize(cssrendering_anonymousbox_t *box);
149150 IMPORT VOID cssrendering_anonymousbox_finalize(cssrendering_anonymousbox_t *box);
150151 IMPORT VOID cssrendering_anonymousbox_appendchild(cssrendering_anonymousbox_t *box, cssrendering_linebox_t *child);
152+IMPORT W cssrendering_anonymousbox_insertbefore(cssrendering_anonymousbox_t *box, cssrendering_linebox_t *child, cssrendering_linebox_t *ref);
153+IMPORT W cssrendering_anonymousbox_removechild(cssrendering_anonymousbox_t *box, cssrendering_linebox_t *child);
154+IMPORT cssrendering_linebox_t* cssrendering_anonymousbox_getfirstchild(cssrendering_anonymousbox_t *box);
151155 IMPORT VOID cssrendering_anonymousbox_setuserdata(cssrendering_anonymousbox_t *box, VP data);
152156
153157 IMPORT VOID cssrendering_blockbox_initialize(cssrendering_blockbox_t *box);
--- a/src/css/test_cssrendering_box.c
+++ b/src/css/test_cssrendering_box.c
@@ -1,7 +1,7 @@
11 /*
22 * test_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
@@ -469,6 +469,131 @@ LOCAL UNITTEST_RESULT test_cssrendering_anonymousbox_appendchild1()
469469 return result;
470470 }
471471
472+LOCAL UNITTEST_RESULT test_cssrendering_anonymousbox_appendchild2()
473+{
474+ cssrendering_anonymousbox_t anon;
475+ cssrendering_linebox_t *line, line0, line1, line2;
476+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
477+
478+ cssrendering_anonymousbox_initialize(&anon);
479+ cssrendering_linebox_initialize(&line0);
480+ cssrendering_linebox_initialize(&line1);
481+ cssrendering_linebox_initialize(&line2);
482+
483+ anon.base.content_edge = (cssmetric_rectangle_t){{0, 0, 100, 100}};
484+ cssrendering_anonymousbox_appendchild(&anon, &line0);
485+ cssrendering_anonymousbox_appendchild(&anon, &line1);
486+ cssrendering_anonymousbox_appendchild(&anon, &line2);
487+
488+ line = cssrendering_anonymousbox_getfirstchild(&anon);
489+ if (line != &line0) {
490+ result = UNITTEST_RESULT_FAIL;
491+ }
492+ line = cssrendering_linebox_getnextsibling(&line0);
493+ if (line != &line1) {
494+ result = UNITTEST_RESULT_FAIL;
495+ }
496+ line = cssrendering_linebox_getnextsibling(&line1);
497+ if (line != &line2) {
498+ result = UNITTEST_RESULT_FAIL;
499+ }
500+ line = cssrendering_linebox_getnextsibling(&line2);
501+ if (line != NULL) {
502+ result = UNITTEST_RESULT_FAIL;
503+ }
504+
505+ cssrendering_linebox_finalize(&line2);
506+ cssrendering_linebox_finalize(&line1);
507+ cssrendering_linebox_finalize(&line0);
508+ cssrendering_anonymousbox_finalize(&anon);
509+
510+ return result;
511+}
512+
513+LOCAL UNITTEST_RESULT test_cssrendering_anonymousbox_insertbefore1()
514+{
515+ cssrendering_anonymousbox_t anon;
516+ cssrendering_linebox_t *line, line0, line1, line2;
517+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
518+
519+ cssrendering_anonymousbox_initialize(&anon);
520+ cssrendering_linebox_initialize(&line0);
521+ cssrendering_linebox_initialize(&line1);
522+ cssrendering_linebox_initialize(&line2);
523+
524+ anon.base.content_edge = (cssmetric_rectangle_t){{0, 0, 100, 100}};
525+ cssrendering_anonymousbox_insertbefore(&anon, &line0, NULL);
526+ cssrendering_anonymousbox_insertbefore(&anon, &line1, &line0);
527+ cssrendering_anonymousbox_insertbefore(&anon, &line2, NULL);
528+
529+ line = cssrendering_anonymousbox_getfirstchild(&anon);
530+ if (line != &line1) {
531+ result = UNITTEST_RESULT_FAIL;
532+ }
533+ line = cssrendering_linebox_getnextsibling(&line1);
534+ if (line != &line0) {
535+ result = UNITTEST_RESULT_FAIL;
536+ }
537+ line = cssrendering_linebox_getnextsibling(&line0);
538+ if (line != &line2) {
539+ result = UNITTEST_RESULT_FAIL;
540+ }
541+ line = cssrendering_linebox_getnextsibling(&line2);
542+ if (line != NULL) {
543+ result = UNITTEST_RESULT_FAIL;
544+ }
545+
546+ cssrendering_linebox_finalize(&line2);
547+ cssrendering_linebox_finalize(&line1);
548+ cssrendering_linebox_finalize(&line0);
549+ cssrendering_anonymousbox_finalize(&anon);
550+
551+ return result;
552+}
553+
554+LOCAL UNITTEST_RESULT test_cssrendering_anonymousbox_removechild1()
555+{
556+ cssrendering_anonymousbox_t anon;
557+ cssrendering_linebox_t *line, line0, line1, line2;
558+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
559+
560+ cssrendering_anonymousbox_initialize(&anon);
561+ cssrendering_linebox_initialize(&line0);
562+ cssrendering_linebox_initialize(&line1);
563+ cssrendering_linebox_initialize(&line2);
564+
565+ anon.base.content_edge = (cssmetric_rectangle_t){{0, 0, 100, 100}};
566+ cssrendering_anonymousbox_appendchild(&anon, &line0);
567+ cssrendering_anonymousbox_appendchild(&anon, &line1);
568+ cssrendering_anonymousbox_appendchild(&anon, &line2);
569+ cssrendering_anonymousbox_removechild(&anon, &line1);
570+
571+ line = cssrendering_anonymousbox_getfirstchild(&anon);
572+ if (line != &line0) {
573+ result = UNITTEST_RESULT_FAIL;
574+ }
575+ line = cssrendering_linebox_getnextsibling(&line0);
576+ if (line != &line2) {
577+ result = UNITTEST_RESULT_FAIL;
578+ }
579+ line = cssrendering_linebox_getnextsibling(&line2);
580+ if (line != NULL) {
581+ result = UNITTEST_RESULT_FAIL;
582+ }
583+
584+ line = cssrendering_linebox_getnextsibling(&line1);
585+ if (line != NULL) {
586+ result = UNITTEST_RESULT_FAIL;
587+ }
588+
589+ cssrendering_linebox_finalize(&line2);
590+ cssrendering_linebox_finalize(&line1);
591+ cssrendering_linebox_finalize(&line0);
592+ cssrendering_anonymousbox_finalize(&anon);
593+
594+ return result;
595+}
596+
472597 EXPORT VOID test_cssrendering_box_main(unittest_driver_t *driver)
473598 {
474599 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_drawtraversal_1);
@@ -478,4 +603,7 @@ EXPORT VOID test_cssrendering_box_main(unittest_driver_t *driver)
478603 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_blockbox_appendchild1);
479604 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_blockbox_appendchild2);
480605 UNITTEST_DRIVER_REGIST(driver, test_cssrendering_anonymousbox_appendchild1);
606+ UNITTEST_DRIVER_REGIST(driver, test_cssrendering_anonymousbox_appendchild2);
607+ UNITTEST_DRIVER_REGIST(driver, test_cssrendering_anonymousbox_insertbefore1);
608+ UNITTEST_DRIVER_REGIST(driver, test_cssrendering_anonymousbox_removechild1);
481609 }
Show on old repository browser