diff options
-rw-r--r-- | !NetSurf/Resources/CSS,f79 | 2 | ||||
-rw-r--r-- | render/layout.c | 68 |
2 files changed, 61 insertions, 9 deletions
diff --git a/!NetSurf/Resources/CSS,f79 b/!NetSurf/Resources/CSS,f79 index 8f053bf2b..301aefb5c 100644 --- a/!NetSurf/Resources/CSS,f79 +++ b/!NetSurf/Resources/CSS,f79 @@ -170,7 +170,7 @@ input[align=left] { float: left; } input[align=right] { float: right; } select { background-color: #d9d9d9; color: #000; text-align: left; - font-family: sans-serif; width: 10em; height: auto; overflow: hidden; + font-family: sans-serif; width: auto; height: auto; overflow: hidden; margin: 1px; border: medium inset #d9d9d9; padding: 1px 2px; } select:after { content: "\25bc"; border-left: 4px ridge #d9d9d9; } diff --git a/render/layout.c b/render/layout.c index 328932ccd..8b65a5853 100644 --- a/render/layout.c +++ b/render/layout.c @@ -46,6 +46,7 @@ #include "desktop/options.h" #include "render/box.h" #include "render/font.h" +#include "render/form.h" #include "render/layout.h" #define NDEBUG #include "utils/log.h" @@ -1140,10 +1141,36 @@ bool layout_line(struct box *first, int *width, int *y, continue; } - if (b->width == UNKNOWN_WIDTH) - /** \todo handle errors */ - nsfont_width(b->style, b->text, b->length, - &b->width); + if (b->width == UNKNOWN_WIDTH) { + /** \todo handle errors */ + + /* If it's a select element, we must use the + * width of the widest option text */ + if (b->parent->parent->gadget && + b->parent->parent->gadget->type + == GADGET_SELECT) { + int opt_maxwidth = 0; + struct form_option *o; + + for (o = b->parent->parent->gadget-> + data.select.items; o; + o = o->next) { + int opt_width; + nsfont_width(b->style, o->text, + strlen(o->text), + &opt_width); + + if (opt_maxwidth < opt_width) + opt_maxwidth =opt_width; + } + + b->width = opt_maxwidth; + } else { + nsfont_width(b->style, b->text, + b->length, &b->width); + } + } + x += b->width; if (b->space) /** \todo optimize out */ @@ -1628,10 +1655,35 @@ struct box *layout_minmax_line(struct box *first, if (!b->text) continue; - if (b->width == UNKNOWN_WIDTH) - /** \todo handle errors */ - nsfont_width(b->style, b->text, b->length, - &b->width); + if (b->width == UNKNOWN_WIDTH) { + /** \todo handle errors */ + + /* If it's a select element, we must use the + * width of the widest option text */ + if (b->parent->parent->gadget && + b->parent->parent->gadget->type + == GADGET_SELECT) { + int opt_maxwidth = 0; + struct form_option *o; + + for (o = b->parent->parent->gadget-> + data.select.items; o; + o = o->next) { + int opt_width; + nsfont_width(b->style, o->text, + strlen(o->text), + &opt_width); + + if (opt_maxwidth < opt_width) + opt_maxwidth =opt_width; + } + + b->width = opt_maxwidth; + } else { + nsfont_width(b->style, b->text, + b->length, &b->width); + } + } max += b->width; if (b->next && b->space) { nsfont_width(b->style, " ", 1, &width); |