diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-17 16:48:27 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-17 16:48:27 +0100 |
commit | 679090b3c7776ee024edce97800c51bd3e59ead2 (patch) | |
tree | 40167319d7a5bc1e46b321613cf1b0ec56940ec2 /src | |
parent | 650710395c696eb51fc46a6a7cf4c040db77b2ce (diff) |
implement parsing of CSS data from style attribute
E.g.
<body style="background-color: red; font-family: arial; font-size: 30mm">
Hello World
</body>
Diffstat (limited to 'src')
-rw-r--r-- | src/cssparser.cc | 34 | ||||
-rw-r--r-- | src/cssparser.hh | 2 | ||||
-rw-r--r-- | src/styleengine.cc | 19 |
3 files changed, 47 insertions, 8 deletions
diff --git a/src/cssparser.cc b/src/cssparser.cc index 5fc10c3c..f11e0a86 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -836,7 +836,7 @@ static void Css_parse_declaration(CssParser * parser, Css_next_token(parser); if (Css_parse_value(parser, prop, &val)) { weight = Css_parse_weight(parser); - if (weight) + if (weight && importantProps) importantProps->set(prop, val); else props->set(prop, val); @@ -877,7 +877,7 @@ static void Css_parse_declaration(CssParser * parser, Css_shorthand_info[sh_index] .properties[i], &val)) { weight = Css_parse_weight(parser); - if (weight) + if (weight && importantProps) importantProps-> set(Css_shorthand_info[sh_index]. properties[i], val); @@ -908,7 +908,7 @@ static void Css_parse_declaration(CssParser * parser, weight = Css_parse_weight(parser); if (n > 0) { for (i = 0; i < 4; i++) - if (weight) + if (weight && importantProps) importantProps->set(Css_shorthand_info[sh_index] .properties[i], dir_vals[dir_set[n - 1] @@ -938,7 +938,7 @@ static void Css_parse_declaration(CssParser * parser, .properties[i], &val)) { weight = Css_parse_weight(parser); for (j = 0; j < 4; j++) - if (weight) + if (weight && importantProps) importantProps-> set(Css_shorthand_info[sh_index]. properties[j * 3 + i], val); @@ -1165,3 +1165,29 @@ void a_Css_parse(CssContext * context, while (parser.ttype != CSS_TK_END) Css_parse_ruleset(&parser); } + +CssPropertyList *a_Css_parse_declaration(const char *buf, int buflen) +{ + CssPropertyList *props = new CssPropertyList (); + CssParser parser; + + parser.context = NULL; + parser.buf = buf; + parser.buflen = buflen; + parser.bufptr = 0; + parser.order_count = 0; + parser.origin = CSS_ORIGIN_AUTHOR; + parser.within_block = true; + parser.space_separated = false; + + Css_next_token(&parser); + while (parser.ttype != CSS_TK_END) + Css_parse_declaration(&parser, props, NULL); + + if (props->size () == 0) { + delete props; + props = NULL; + } + + return props; +} diff --git a/src/cssparser.hh b/src/cssparser.hh index 6a905625..533ad1c6 100644 --- a/src/cssparser.hh +++ b/src/cssparser.hh @@ -58,6 +58,8 @@ void a_Css_parse (CssContext *context, int order_count, CssOrigin origin); +CssPropertyList *a_Css_parse_declaration(const char *buf, int buflen); + extern const CssPropertyInfo Css_property_info[CssProperty::CSS_PROPERTY_LAST]; #endif // __CSS_H__ diff --git a/src/styleengine.cc b/src/styleengine.cc index 72709b78..fd160f29 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -391,8 +391,9 @@ bool StyleEngine::computeLength (dw::core::style::Length *dest, * This method is private. Call style() to get a current style object. */ Style * StyleEngine::style0 (CssPropertyList *nonCssProperties) { - CssPropertyList props; - CssPropertyList *tagStyleProps = NULL; /** \todo implementation */ + CssPropertyList props, *styleAttributeProps = NULL; + const char *styleAttribute = + stack->getRef (stack->size () - 1)->styleAttribute; // get previous style from the stack StyleAttrs attrs = *stack->getRef (stack->size () - 2)->style; @@ -402,9 +403,19 @@ Style * StyleEngine::style0 (CssPropertyList *nonCssProperties) { if (stack->getRef (stack->size () - 2)->inheritBackgroundColor) attrs.backgroundColor = stack->getRef (stack->size () - 2)->style->backgroundColor; - - cssContext->apply (&props, this, tagStyleProps, nonCssProperties); + // parse style information from style="" attribute, if it exists + if (styleAttribute) + styleAttributeProps = + a_Css_parse_declaration (styleAttribute, strlen (styleAttribute)); + + // merge style information + cssContext->apply (&props, this, styleAttributeProps, nonCssProperties); + + if (styleAttributeProps) + delete styleAttributeProps; + + // apply style apply (&attrs, &props); stack->getRef (stack->size () - 1)->style = Style::create (layout, &attrs); |