changeset 785:8260f0ff5631

merge
author Jorge Arellano Cid <jcid@dillo.org>
date Sat, 17 Jan 2009 15:31:10 -0300
parents 2ab78f21b9f6 (current diff) b43df60cbb52 (diff)
children 17d77a1950d8
files src/html.cc
diffstat 7 files changed, 60 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/dillorc	Sat Jan 17 15:29:34 2009 -0300
+++ b/dillorc	Sat Jan 17 15:31:10 2009 -0300
@@ -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
--- a/src/cssparser.cc	Sat Jan 17 15:29:34 2009 -0300
+++ b/src/cssparser.cc	Sat Jan 17 15:31:10 2009 -0300
@@ -836,7 +836,7 @@
             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 @@
                                                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 @@
                   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 @@
                                                .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 @@
    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;
+}
--- a/src/cssparser.hh	Sat Jan 17 15:29:34 2009 -0300
+++ b/src/cssparser.hh	Sat Jan 17 15:31:10 2009 -0300
@@ -58,6 +58,8 @@
                                                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__
--- a/src/html.cc	Sat Jan 17 15:29:34 2009 -0300
+++ b/src/html.cc	Sat Jan 17 15:31:10 2009 -0300
@@ -1654,8 +1654,9 @@
  */
 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);
 }
 
 /*
--- a/src/prefs.c	Sat Jan 17 15:29:34 2009 -0300
+++ b/src/prefs.c	Sat Jan 17 15:31:10 2009 -0300
@@ -79,6 +79,7 @@
    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 @@
    { "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 @@
       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 @@
    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);
--- a/src/prefs.h	Sat Jan 17 15:29:34 2009 -0300
+++ b/src/prefs.h	Sat Jan 17 15:31:10 2009 -0300
@@ -59,6 +59,7 @@
    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;
--- a/src/styleengine.cc	Sat Jan 17 15:29:34 2009 -0300
+++ b/src/styleengine.cc	Sat Jan 17 15:31:10 2009 -0300
@@ -391,8 +391,9 @@
  *    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 @@
    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);