diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2009-01-17 15:31:10 -0300 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2009-01-17 15:31:10 -0300 |
commit | f536df6a1ede16e1dfa906932d1481713ce62649 (patch) | |
tree | 52d1388e3069d8e7c7a46cc688af98b708458008 | |
parent | a0aac54a99d22b5f8131c8243442c81823dc6b3b (diff) | |
parent | 5e0163f8012a66ac34313478d9c095e9b3e08144 (diff) |
merge
-rw-r--r-- | dillorc | 3 | ||||
-rw-r--r-- | src/cssparser.cc | 34 | ||||
-rw-r--r-- | src/cssparser.hh | 2 | ||||
-rw-r--r-- | src/html.cc | 5 | ||||
-rw-r--r-- | src/prefs.c | 6 | ||||
-rw-r--r-- | src/prefs.h | 1 | ||||
-rw-r--r-- | src/styleengine.cc | 19 |
7 files changed, 60 insertions, 10 deletions
@@ -21,6 +21,9 @@ # Change this if you want to disable loading of CSS stylesheets. #load_stylesheets=YES +# Change this if you want to disable parsing of embedded CSS. +#parse_embedded_css=YES + # Change the buffering scheme for drawing # 0 no double buffering - useful for debugging # 1 light buffering using a single back buffer for all windows 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/html.cc b/src/html.cc index ff687c05..d57d7300 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1654,8 +1654,9 @@ static void Html_tag_open_style(DilloHtml *html, const char *tag, int tagsize) */ static void Html_tag_close_style(DilloHtml *html, int TagIdx) { - html->styleEngine->parse(html->Stash->str, html->Stash->len, - 0, CSS_ORIGIN_AUTHOR); + if (prefs.parse_embedded_css) + html->styleEngine->parse(html->Stash->str, html->Stash->len, + 0, CSS_ORIGIN_AUTHOR); } /* diff --git a/src/prefs.c b/src/prefs.c index 34d13db8..f7c286f8 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -79,6 +79,7 @@ typedef enum { DRC_TOKEN_MIDDLE_CLICK_OPENS_NEW_TAB, DRC_TOKEN_NOPROXY, DRC_TOKEN_PANEL_SIZE, + DRC_TOKEN_PARSE_EMBEDDED_CSS, DRC_TOKEN_PROXY, DRC_TOKEN_PROXYUSER, DRC_TOKEN_REFERER, @@ -146,6 +147,7 @@ static const SymNode_t symbols[] = { { "middle_click_opens_new_tab", DRC_TOKEN_MIDDLE_CLICK_OPENS_NEW_TAB }, { "no_proxy", DRC_TOKEN_NOPROXY }, { "panel_size", DRC_TOKEN_PANEL_SIZE }, + { "parse_embedded_css", DRC_TOKEN_PARSE_EMBEDDED_CSS }, { "save_dir", DRC_TOKEN_SAVE_DIR }, { "search_url", DRC_TOKEN_SEARCH_URL }, { "show_back", DRC_TOKEN_SHOW_BACK }, @@ -264,6 +266,9 @@ static int Prefs_parse_pair(char *name, char *value) else /* default to "medium" */ prefs.panel_size = P_medium; break; + case DRC_TOKEN_PARSE_EMBEDDED_CSS: + prefs.parse_embedded_css = (strcmp(value, "YES") == 0); + break; case DRC_TOKEN_SMALL_ICONS: prefs.small_icons = (strcmp(value, "YES") == 0); break; @@ -463,6 +468,7 @@ void a_Prefs_init(void) prefs.fullwindow_start=FALSE; prefs.load_images=TRUE; prefs.load_stylesheets=TRUE; + prefs.parse_embedded_css=TRUE; prefs.buffered_drawing=1; prefs.vw_fontname = dStrdup(D_VW_FONTNAME); prefs.fw_fontname = dStrdup(D_FW_FONTNAME); diff --git a/src/prefs.h b/src/prefs.h index 9156c815..767530d2 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -59,6 +59,7 @@ struct _DilloPrefs { bool_t fullwindow_start; bool_t load_images; bool_t load_stylesheets; + bool_t parse_embedded_css; int32_t buffered_drawing; char *vw_fontname; char *fw_fontname; diff --git a/src/styleengine.cc b/src/styleengine.cc index 72709b78..4e234a3c 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 && prefs.parse_embedded_css) + 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); |