diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2016-01-20 18:40:38 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2016-01-20 20:02:56 +0000 |
commit | 948a93041dba3ec95dbb04bee523a9bbd4ca9918 (patch) | |
tree | 78763cd68097cc4fae7e58d9571ea574c455ef30 | |
parent | 38e6fd1b74f2bc6677398d5167aff68bf163a286 (diff) | |
download | netsurf-948a93041dba3ec95dbb04bee523a9bbd4ca9918.tar.gz netsurf-948a93041dba3ec95dbb04bee523a9bbd4ca9918.tar.bz2 |
Sort float_children of containers by their bottom edge.
-rw-r--r-- | render/layout.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/render/layout.c b/render/layout.c index 4381f296c..f1e321e7f 100644 --- a/render/layout.c +++ b/render/layout.c @@ -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 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) { - b->next_float = cont->float_children; - cont->float_children = b; + struct box *box = cont->float_children; + 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; + } + } } |