Sort float_children of containers by their bottom edge.

This commit is contained in:
Michael Drake 2016-01-20 18:40:38 +00:00
parent 38e6fd1b74
commit 948a93041d

View File

@ -2092,11 +2092,36 @@ void find_sides(struct box *fl, int y0, int y1,
* *
* \param cont block formatting context block, used to contain float * \param cont block formatting context block, used to contain float
* \param b box to add to float * \param b box to add to float
*
* This sorts floats in order of descending bottom edges.
*/ */
static void add_float_to_container(struct box *cont, struct box *b) static void add_float_to_container(struct box *cont, struct box *b)
{ {
b->next_float = cont->float_children; struct box *box = cont->float_children;
cont->float_children = b; int b_bottom = b->y + b->height;
assert(b->type == BOX_FLOAT_LEFT || b->type == BOX_FLOAT_RIGHT);
if (box == NULL) {
/* No other float children */
b->next_float = NULL;
cont->float_children = b;
return;
} else if (b_bottom >= box->y + box->height) {
/* Goes at start of list */
b->next_float = cont->float_children;
cont->float_children = b;
} else {
struct box *prev = NULL;
while (box != NULL && b_bottom < box->y + box->height) {
prev = box;
box = box->next_float;
}
if (prev != NULL) {
b->next_float = prev->next_float;
prev->next_float = b;
}
}
} }