[project @ 2003-09-19 23:36:17 by bursa]

Start converting forms to use CSS properly.

svn path=/import/netsurf/; revision=305
This commit is contained in:
James Bursa 2003-09-19 23:36:17 +00:00
parent e526454e67
commit 4aadb2d013
5 changed files with 84 additions and 114 deletions

View File

@ -37,3 +37,6 @@ hr { background-color: #000; height: 1px; }
center { text-align: center; }
small { font-size: smaller; }
big { font-size: larger; }
input, select { width: 10em; height: 2em; background-color: #eeeebb; }
textarea { width: 20em; height: 4em; background-color: #eeeebb; }

View File

@ -713,7 +713,7 @@ void browser_window_text_selection(struct browser_window* bw,
start = &(bw->current_content->data.html.text_selection.start);
end = &(bw->current_content->data.html.text_selection.end);
if (click_boxes[i].box->font != 0)
if (click_boxes[i].box->text && click_boxes[i].box->font)
{
font_position_in_string(click_boxes[i].box->text,
click_boxes[i].box->font, click_boxes[i].box->length,

View File

@ -524,6 +524,27 @@ struct css_style * box_get_style(struct content ** stylesheet,
xmlFree(s);
}
if (strcmp((const char *) n->name, "input") == 0) {
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "size"))) {
int size = atoi(s);
if (0 < size) {
char *type = (char *) xmlGetProp(n, (const xmlChar *) "type");
style->width.width = CSS_WIDTH_LENGTH;
if (!type || stricmp(type, "text") == 0 ||
stricmp(type, "password") == 0)
/* in characters for text or password */
style->width.value.length.unit = CSS_UNIT_EX;
else
/* in pixels otherwise */
style->width.value.length.unit = CSS_UNIT_PX;
style->width.value.length.value = size;
if (type)
xmlFree(type);
}
xmlFree(s);
}
}
if (strcmp((const char *) n->name, "body") == 0) {
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "text"))) {
unsigned int r, g, b;
@ -773,6 +794,7 @@ struct result box_input(xmlNode *n, struct status *status,
if (type == 0 || stricmp(type, "text") == 0)
{
box = box_create(style, NULL, 0);
box->font = font_open(status->content->data.html.fonts, style);
box->gadget = gadget = xcalloc(1, sizeof(struct gui_gadget));
gadget->type = GADGET_TEXTBOX;
@ -801,6 +823,7 @@ struct result box_input(xmlNode *n, struct status *status,
else if (stricmp(type, "password") == 0)
{
box = box_create(style, NULL, 0);
box->font = font_open(status->content->data.html.fonts, style);
box->gadget = gadget = xcalloc(1, sizeof(struct gui_gadget));
gadget->type = GADGET_PASSWORD;

View File

@ -95,69 +95,6 @@ void layout_node(struct box * box, unsigned long width, struct box * cont,
}
/* TODO: change this to use style sheets */
int gadget_width(struct gui_gadget* gadget)
{
struct formoption* current;
int max;
/* should use wimp_textop via a gui wrapper for these */
switch (gadget->type)
{
case GADGET_CHECKBOX:
case GADGET_RADIO:
return 22;
case GADGET_TEXTBOX:
return gadget->data.textbox.size * 8;
case GADGET_PASSWORD:
return gadget->data.password.size * 8;
case GADGET_ACTIONBUTTON:
return strlen(gadget->data.actionbutt.label) * 8 + 16;
case GADGET_IMAGE:
return gadget->data.image.width;
case GADGET_SELECT:
current = gadget->data.select.items;
max = 32;
while (current != NULL)
{
if (strlen(current->text) * 8 + 16 > max)
max = strlen(current->text) * 8 + 16;
current = current->next;
}
return max;
case GADGET_TEXTAREA:
return gadget->data.textarea.cols * 8 + 8;
default:
assert(0);
}
return 0;
}
int gadget_height(struct gui_gadget* gadget)
{
switch (gadget->type)
{
case GADGET_CHECKBOX:
case GADGET_RADIO:
return 22;
case GADGET_TEXTBOX:
return 28;
case GADGET_PASSWORD:
return 28;
case GADGET_ACTIONBUTTON:
return 28;
case GADGET_IMAGE:
return gadget->data.image.height;
case GADGET_SELECT:
return 28; // * gadget->data.select.size;
case GADGET_TEXTAREA:
return gadget->data.textarea.rows * 16 + 8;
default:
assert(0);
}
return 0;
}
/**
* layout_block -- position block and recursively layout children
*
@ -354,28 +291,24 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
for (x = 0, b = first; x < x1 - x0 && b != 0; b = b->next) {
assert(b->type == BOX_INLINE || b->type == BOX_FLOAT_LEFT || b->type == BOX_FLOAT_RIGHT);
if (b->type == BOX_INLINE) {
if (b->object && b->style && b->style->height.height == CSS_HEIGHT_LENGTH)
if ((b->object || b->gadget) && b->style && b->style->height.height == CSS_HEIGHT_LENGTH)
h = len(&b->style->height.length, b->style);
else if (b->text)
h = line_height(b->style ? b->style : b->parent->parent->style);
else if (b->gadget != 0)
h = gadget_height(b->gadget);
else
h = 0;
b->height = h;
if (h > height) height = h;
if (b->object && b->style && b->style->width.width == CSS_WIDTH_LENGTH)
if ((b->object || b->gadget) && b->style && b->style->width.width == CSS_WIDTH_LENGTH)
b->width = len(&b->style->width.value.length, b->style);
else if (b->object && b->style && b->style->width.width == CSS_WIDTH_PERCENT)
else if ((b->object || b->gadget) && b->style && b->style->width.width == CSS_WIDTH_PERCENT)
b->width = width * b->style->width.value.percent / 100;
else if (b->text) {
if (b->width == UNKNOWN_WIDTH)
b->width = font_width(b->font, b->text, b->length);
} else if (b->gadget != 0)
b->width = gadget_width(b->gadget);
else
} else
b->width = 0;
if (b->text != 0)
@ -885,7 +818,7 @@ void calculate_inline_container_widths(struct box *box)
for (child = box->children; child != 0; child = child->next) {
switch (child->type) {
case BOX_INLINE:
if (child->object) {
if (child->object || child->gadget) {
if (child->style->width.width == CSS_WIDTH_LENGTH) {
child->width = len(&child->style->width.value.length,
child->style);
@ -910,12 +843,6 @@ void calculate_inline_container_widths(struct box *box)
if (min < width) min = width;
i = j + 1;
} while (j != child->length);
} else if (child->gadget) {
child->width = gadget_width(child->gadget);
max += child->width;
if (min < child->width)
min = child->width;
}
break;

View File

@ -16,12 +16,21 @@
#include "netsurf/riscos/gui.h"
#include "netsurf/utils/log.h"
static long x0, y0, x1, y1;
static void html_redraw_box(struct content *content, struct box * box,
signed long x, signed long y,
unsigned long current_background_color,
signed long gadget_subtract_x, signed long gadget_subtract_y,
bool *select_on,
long clip_x0, long clip_y0, long clip_x1, long clip_y1);
static void html_redraw_clip(struct box * box,
signed long x, signed long y,
long clip_x0, long clip_y0, long clip_x1, long clip_y1);
static void html_redraw_unclip(long clip_x0, long clip_y0,
long clip_x1, long clip_y1);
void html_redraw(struct content *c, long x, long y,
unsigned long width, unsigned long height,
@ -91,35 +100,13 @@ void html_redraw_box(struct content *content, struct box * box,
}
if (box->object) {
long x0 = x + box->x * 2;
long y1 = y - box->y * 2 - 1;
long x1 = x0 + box->width * 2 - 1;
long y0 = y1 - box->height * 2 + 1;
LOG(("%s %li %li %li %li", box->object->url, x0, y0, x1, y1));
if (x0 < clip_x0) x0 = clip_x0;
if (y0 < clip_y0) y0 = clip_y0;
if (clip_x1 < x1) x1 = clip_x1;
if (clip_y1 < y1) y1 = clip_y1;
os_set_graphics_window();
os_writec((char) (x0 & 0xff)); os_writec((char) (x0 >> 8));
os_writec((char) (y0 & 0xff)); os_writec((char) (y0 >> 8));
os_writec((char) (x1 & 0xff)); os_writec((char) (x1 >> 8));
os_writec((char) (y1 & 0xff)); os_writec((char) (y1 >> 8));
html_redraw_clip(box, x, y, clip_x0, clip_y0, clip_x1, clip_y1);
content_redraw(box->object,
(int) x + (int) box->x * 2,
(int) y - (int) box->y * 2,
box->width * 2, box->height * 2,
x0, y0, x1, y1);
os_set_graphics_window();
os_writec((char) (clip_x0 & 0xff)); os_writec((char) (clip_x0 >> 8));
os_writec((char) (clip_y0 & 0xff)); os_writec((char) (clip_y0 >> 8));
os_writec((char) (clip_x1 & 0xff)); os_writec((char) (clip_x1 >> 8));
os_writec((char) (clip_y1 & 0xff)); os_writec((char) (clip_y1 >> 8));
html_redraw_unclip(clip_x0, clip_y0, clip_x1, clip_y1);
} else if (box->gadget) {
wimp_icon icon;
@ -144,18 +131,15 @@ void html_redraw_box(struct content *content, struct box * box,
wimp_plot_icon(&icon);
break;
case GADGET_TEXTBOX:
icon.flags = wimp_ICON_TEXT | wimp_ICON_BORDER |
wimp_ICON_VCENTRED | wimp_ICON_FILLED |
wimp_ICON_INDIRECTED |
(wimp_COLOUR_DARK_GREY << wimp_ICON_FG_COLOUR_SHIFT) |
(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT);
icon.data.indirected_text.text = box->gadget->data.textbox.text;
icon.data.indirected_text.size = box->gadget->data.textbox.maxlength + 1;
icon.data.indirected_text.validation = validation_textbox;
LOG(("writing GADGET TEXTBOX"));
wimp_plot_icon(&icon);
colourtrans_set_font_colours(box->font->handle, current_background_color << 8,
box->style->color << 8, 14, 0, 0, 0);
html_redraw_clip(box, x, y, clip_x0, clip_y0, clip_x1, clip_y1);
font_paint(box->font->handle, box->gadget->data.textbox.text,
font_OS_UNITS | font_GIVEN_FONT | font_KERN,
(int) x + (int) box->x * 2, (int) y - (int) box->y * 2 - (int) (box->height * 1.5),
NULL, NULL, 0);
html_redraw_unclip(clip_x0, clip_y0, clip_x1, clip_y1);
break;
case GADGET_PASSWORD:
@ -367,3 +351,36 @@ void html_redraw_box(struct content *content, struct box * box,
}*/
}
void html_redraw_clip(struct box * box,
signed long x, signed long y,
long clip_x0, long clip_y0, long clip_x1, long clip_y1)
{
x0 = x + box->x * 2;
y1 = y - box->y * 2 - 1;
x1 = x0 + box->width * 2 - 1;
y0 = y1 - box->height * 2 + 1;
if (x0 < clip_x0) x0 = clip_x0;
if (y0 < clip_y0) y0 = clip_y0;
if (clip_x1 < x1) x1 = clip_x1;
if (clip_y1 < y1) y1 = clip_y1;
os_set_graphics_window();
os_writec((char) (x0 & 0xff)); os_writec((char) (x0 >> 8));
os_writec((char) (y0 & 0xff)); os_writec((char) (y0 >> 8));
os_writec((char) (x1 & 0xff)); os_writec((char) (x1 >> 8));
os_writec((char) (y1 & 0xff)); os_writec((char) (y1 >> 8));
}
void html_redraw_unclip(long clip_x0, long clip_y0,
long clip_x1, long clip_y1)
{
os_set_graphics_window();
os_writec((char) (clip_x0 & 0xff)); os_writec((char) (clip_x0 >> 8));
os_writec((char) (clip_y0 & 0xff)); os_writec((char) (clip_y0 >> 8));
os_writec((char) (clip_x1 & 0xff)); os_writec((char) (clip_x1 >> 8));
os_writec((char) (clip_y1 & 0xff)); os_writec((char) (clip_y1 >> 8));
}