#include #include #include "stylesheet.h" #include "frame.h" StyleSheetList default_stylesheet = NULL; StyleSheetList user_stylesheet = NULL; void frame_init_default_stylesheet(FILE *fp) { if (default_stylesheet == NULL) { if (style_readstyle(fp, &default_stylesheet)) fprintf(stderr, "warn: can't read style-file corecctry\n"); /* stylesheetlist_show(default_stylesheet);*/ } } void frame_init_user_stylesheet(FILE *fp) { if (user_stylesheet == NULL) { if (style_readstyle(fp, &user_stylesheet)) fprintf(stderr, "warn: can't read style-file corecctry\n"); /* stylesheetlist_show(default_stylesheet);*/ } } void frame_init_dtd(FILE *fp) { dtd_readdtd(fp); } StyleSheetSet * stylesheetset_new(void) { StyleSheetSet *p; if ((p = malloc(sizeof(*p))) == NULL) { perror("stylesheetset_new"); exit(1); } p->next = NULL; p->origin = 0; p->style = NULL; return p; } void stylesheetset_delete(StyleSheetSet *p) { if (p) free(p); } void stylesheetsetlist_delete(StyleSheetSetList l) { StyleSheetSet *p = l, *q; while (p != NULL) { q = p; p = p->next; stylesheetset_delete(q); } } void stylesheetsetlist_show(StyleSheetSetList l) { StyleSheetSet *p = l; while (p != NULL) { stylesheet_show(p->style); p = p->next; } } static int simpleselector_match(SSSimpleSelector *s, ParseInfo *pi) { if ((pi->sel && s->ident && (pi->sel != s->ident))|| (pi->id && s->id && (pi->id != s->id ))|| (pi->class && s->class && (pi->class != s->class))|| (pi->pseudoclass && s->pseudoclass && (pi->pseudoclass != s->pseudoclass))) return 0; return 1; } static StyleSheetSetList stylesheetset_add(Frame *frame, ParseInfo *pinfo, StyleSheetSetList ret, StyleSheetList sl, int origin) { StyleSheet *p = sl; while (p != NULL) { SSSimpleSelector *ss = p->sel->selectors; if (simpleselector_match(ss, pinfo)){ ParseInfo *pi = frame->pinfo; int mached = 1; ss = ss->next; while (ss != NULL) { while (pi != NULL) { /* search */ if (simpleselector_match(ss, pi)) break; pi = pi->next; } if (pi == NULL) { mached = 0; break; } ss = ss->next; } if (mached) { StyleSheetSet *sss = stylesheetset_new(); sss->origin = origin; sss->style = p; sss->next = ret; ret = sss; } } p = p->next; } return ret; } extern StyleSheetList user_stylesheet; extern StyleSheetList default_stylesheet; StyleSheetSetList frame_get_stylesheetsetlist(Frame *frame, ParseInfo *pi) { StyleSheetSetList ssl = NULL; ssl = stylesheetset_add(frame, pi, ssl, default_stylesheet, 0); ssl = stylesheetset_add(frame, pi, ssl, user_stylesheet, 2); ssl = stylesheetset_add(frame, pi, ssl, frame->stylesheet, 4); return ssl; } static SSTerm * style_find_decl(StyleSheetSetList sssl, int pe, char *name) { SSID id = StringToSSID(name); SSTerm *ret = NULL; int origin = -1, origin2; int spec = 0; StyleSheetSet *sss = sssl; while (sss != NULL) { if (sss->style->sel->pseudoelement == pe && sss->style->sel->specificity > spec) { SSDeclarationSet *d = sss->style->decls; while (d != NULL) { if (d->decl->ident == id && (origin2 = d->decl->priority*3 + sss->origin) > origin){ origin = origin2; spec = sss->style->sel->specificity; ret = d->decl->term; break; } d = d->next; } } sss = sss->next; } return ret; } static BlockStyleInfo default_style = { 0, 0, 0, 0, /* margin */ 0, 0, 0, 0, /* border_width */ 0, 0, 0, 0, /* padding */ 0, 0, 0, 0, ALIGN_NONE, /* text_align */ { SSTERM_NUMBER, 1.2, 0, NULL } /* line-height */ }; #define SETLEN_PX(name, str, def) bs->name = term_pixel(f,style_find_decl(sssl, 0, str),def) BlockStyleInfo * frame_blockstyleinfo_new(Frame *f, StyleSheetSetList sssl) { int t, r, l, b; BlockStyleInfo *bsi = frame_get_blockstyleinfo(f); BlockStyleInfo *bs = blockstyleinfo_new(); if (!bsi) bsi = &default_style; t = bsi->margin_top; r = bsi->margin_right; l = bsi->margin_left; b = bsi->margin_bottom; SETLEN_PX(margin_top, "margin-top", t); SETLEN_PX(margin_right, "margin-right", r); SETLEN_PX(margin_left, "margin-left", l); SETLEN_PX(margin_bottom, "margin-bottom", b); t = bsi->padding_top; r = bsi->padding_right; l = bsi->padding_left; b = bsi->padding_bottom; SETLEN_PX(padding_top, "padding-top", t); SETLEN_PX(padding_right, "padding-right", r); SETLEN_PX(padding_left, "padding-left", l); SETLEN_PX(padding_bottom, "padding-bottom", b); t = bsi->border_top_width; r = bsi->border_right_width; l = bsi->border_left_width; b = bsi->border_bottom_width; SETLEN_PX(border_top_width, "border-top-width", t); SETLEN_PX(border_right_width, "border-right-width", r); SETLEN_PX(border_left_width, "border-left-width", l); SETLEN_PX(border_bottom_width, "border-bottom-width", b); bs->text_align = term_text_align (style_find_decl(sssl,0,"text-align"), bsi->text_align); bs->line_height = term_line_height (f,style_find_decl(sssl,0,"line-height"), bsi->line_height); return bs; }