summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2008-02-11 17:53:00 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2008-02-11 17:53:00 +0000
commit7d748ae2ffd7569b4502e14c66d6b08a64c1d425 (patch)
tree95831234d75d9719577293b54544b8746e9cc0a3 /render
parent455aefbb91660853e6483271a1b11e1e4619ff75 (diff)
downloadnetsurf-7d748ae2ffd7569b4502e14c66d6b08a64c1d425.tar.gz
netsurf-7d748ae2ffd7569b4502e14c66d6b08a64c1d425.tar.bz2
Select element width is width of longest option text.
svn path=/trunk/netsurf/; revision=3855
Diffstat (limited to 'render')
-rw-r--r--render/layout.c68
1 files changed, 60 insertions, 8 deletions
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);