changeset 982:d04d960da3f4

remove bg_color dillorc option To set a custom background color add a line like: body {background-color: white} to your ~/.dillo/style.css file. This also works for plain text display and image viewing.
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Fri, 06 Mar 2009 10:09:38 +0100
parents 99e2a3ee8cd9
children 783043a9ead8
files dillorc src/dicache.c src/html.cc src/plain.cc src/prefs.c src/prefs.h src/styleengine.cc src/styleengine.hh src/table.cc src/web.cc src/web.hh
diffstat 11 files changed, 34 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/dillorc	Fri Mar 06 09:31:29 2009 +0100
+++ b/dillorc	Fri Mar 06 10:09:38 2009 +0100
@@ -144,11 +144,6 @@
 
 # Here we can use the HTML color names or C syntax.
 
-# Set the background color
-# bg_color=gray
-# bg_color=0xd6d6c0
-#bg_color=0xdcd1ba
-
 # Set the text color
 #text_color=black
 
--- a/src/dicache.c	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/dicache.c	Fri Mar 06 10:09:38 2009 +0100
@@ -399,7 +399,7 @@
    dReturn_val_if_fail(MimeType && Ptr, NULL);
 
    if (!web->Image)
-      web->Image = a_Image_new(0, 0, NULL, prefs.bg_color);
+      web->Image = a_Image_new(0, 0, NULL, web->bgColor);
 
    /* Add an extra reference to the Image (for dicache usage) */
    a_Image_ref(web->Image);
--- a/src/html.cc	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/html.cc	Fri Mar 06 10:09:38 2009 +0100
@@ -425,6 +425,8 @@
    DocType = DT_NONE;    /* assume Tag Soup 0.0!   :-) */
    DocTypeVersion = 0.0f;
 
+   styleEngine = new StyleEngine (HT2LT (this));
+
    cssUrls = new misc::SimpleVector <DilloUrl*> (1);
 
    stack = new misc::SimpleVector <DilloHtmlState> (16);
@@ -439,11 +441,10 @@
    stack->getRef(0)->textblock = NULL;
    stack->getRef(0)->table = NULL;
    stack->getRef(0)->ref_list_item = NULL;
-   stack->getRef(0)->current_bg_color = prefs.bg_color;
+   stack->getRef(0)->current_bg_color =
+      styleEngine->style()->backgroundColor->getColor();
    stack->getRef(0)->hand_over_break = false;
 
-   styleEngine = new StyleEngine (HT2LT (this));
-
    InFlags = IN_NONE;
 
    Stash = dStr_new("");
@@ -1694,11 +1695,9 @@
    textblock = DW2TB(html->dw);
 
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
-      color = a_Html_color_parse(html, attrbuf, prefs.bg_color);
-      if (color == 0xffffff && !prefs.allow_white_bg)
-         color = prefs.bg_color;
-      S_TOP(html)->current_bg_color = color;
-      props.set (CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR, color);
+      color = a_Html_color_parse(html, attrbuf, -1);
+      if (color != -1)
+         props.set (CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR, color);
    }
 
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "text"))) {
--- a/src/plain.cc	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/plain.cc	Fri Mar 06 10:09:38 2009 +0100
@@ -22,6 +22,7 @@
 #include "bw.h"
 #include "web.hh"
 #include "misc.h"
+#include "styleengine.hh"
 
 #include "uicmd.hh"
 
@@ -85,9 +86,6 @@
  */
 DilloPlain::DilloPlain(BrowserWindow *p_bw, const DilloUrl *p_url)
 {
-   style::StyleAttrs styleAttrs;
-   style::FontAttrs fontAttrs;
-
    /* Init event receiver */
    plainReceiver.plain = this;
 
@@ -98,20 +96,12 @@
    Start_Ofs = 0;
    state = ST_SeekingEol;
 
-   /* Create the font and attribute for the page. */
-   fontAttrs.name = prefs.font_monospace;
-   fontAttrs.size = (int) rint(14.0 * prefs.font_factor);
-   fontAttrs.weight = 400;
-   fontAttrs.style = style::FONT_STYLE_NORMAL;
+   StyleEngine styleEngine ((Layout*)bw->render_layout);
 
-   Layout *layout = (Layout*)bw->render_layout;
-   styleAttrs.initValues ();
-   styleAttrs.margin.setVal (5);
-   styleAttrs.font = style::Font::create (layout, &fontAttrs);
-   styleAttrs.color = style::Color::create (layout, prefs.text_color);
-   styleAttrs.backgroundColor =
-      style::Color::create (layout, prefs.bg_color);
-   widgetStyle = style::Style::create (layout, &styleAttrs);
+   styleEngine.startElement ("body");
+   styleEngine.startElement ("pre");
+   widgetStyle = styleEngine.wordStyle ();
+   widgetStyle->ref ();
 
    /* The context menu */
    DW2TB(dw)->connectEvent (&plainReceiver);
--- a/src/prefs.c	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/prefs.c	Fri Mar 06 10:09:38 2009 +0100
@@ -43,7 +43,6 @@
 #define D_SEARCH_URL "http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%s"
 #define D_SAVE_DIR "/tmp/"
 
-#define DW_COLOR_DEFAULT_BGND   0xdcd1ba
 #define DW_COLOR_DEFAULT_TEXT   0x000000
 #define DW_COLOR_DEFAULT_LINK   0x0000ff
 #define DW_COLOR_DEFAULT_VLINK  0x800080
@@ -154,7 +153,6 @@
    /* Symbol array, sorted alphabetically */
    const SymNode_t symbols[] = {
    { "allow_white_bg", &prefs.allow_white_bg, PREFS_BOOL },
-   { "bg_color", &prefs.bg_color, PREFS_COLOR },
    { "buffered_drawing", &prefs.buffered_drawing, PREFS_INT32 },
    { "contrast_visited_color", &prefs.contrast_visited_color, PREFS_BOOL },
    { "enterpress_forces_submit", &prefs.enterpress_forces_submit, PREFS_BOOL },
@@ -260,7 +258,6 @@
    char *old_locale;
 
    prefs.allow_white_bg = TRUE;
-   prefs.bg_color = DW_COLOR_DEFAULT_BGND;
    prefs.buffered_drawing=1;
    prefs.contrast_visited_color = TRUE;
    prefs.enterpress_forces_submit = FALSE;
--- a/src/prefs.h	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/prefs.h	Fri Mar 06 10:09:38 2009 +0100
@@ -31,7 +31,6 @@
    DilloUrl *home;
    int32_t link_color;
    int32_t visited_color;
-   int32_t bg_color;
    int32_t text_color;
    bool_t allow_white_bg;
    bool_t force_my_colors;
--- a/src/styleengine.cc	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/styleengine.cc	Fri Mar 06 10:09:38 2009 +0100
@@ -13,6 +13,7 @@
 #include <math.h>
 #include "../dlib/dlib.h"
 #include "prefs.h"
+#include "html_common.hh"
 #include "styleengine.hh"
 
 using namespace dw::core::style;
@@ -85,6 +86,10 @@
    n->inheritBackgroundColor = false;
 }
 
+void StyleEngine::startElement (const char *tagname) {
+   startElement (a_Html_tag_index (tagname));
+}
+
 void StyleEngine::setId (const char *id) {
    Node *n =  stack->getRef (stack->size () - 1);
    assert (n->id == NULL);
--- a/src/styleengine.hh	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/styleengine.hh	Fri Mar 06 10:09:38 2009 +0100
@@ -47,6 +47,7 @@
 
       void parse (const char *buf, int buflen, CssOrigin origin);
       void startElement (int tag);
+      void startElement (const char *tagname);
       void setId (const char *id);
       const char * getId () { return top ()->id; };
       void setClass (const char *klass);
--- a/src/table.cc	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/table.cc	Fri Mar 06 10:09:38 2009 +0100
@@ -90,12 +90,8 @@
 
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
       bgcolor = a_Html_color_parse(html, attrbuf, -1);
-      if (bgcolor != -1) {
-         if (bgcolor == 0xffffff && !prefs.allow_white_bg)
-            bgcolor = prefs.bg_color;
-         S_TOP(html)->current_bg_color = bgcolor;
+      if (bgcolor != -1)
          props.set (CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR, bgcolor);
-      }
    }
 
    html->styleEngine->setNonCssHints (&props);
@@ -165,12 +161,8 @@
 
       if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
          bgcolor = a_Html_color_parse(html, attrbuf, -1);
-         if (bgcolor != -1) {
-            if (bgcolor == 0xffffff && !prefs.allow_white_bg)
-               bgcolor = prefs.bg_color;
+         if (bgcolor != -1)
             props.set (CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR, bgcolor);
-            S_TOP(html)->current_bg_color = bgcolor;
-         }
       }
 
       if (a_Html_get_attr (html, tag, tagsize, "align")) {
@@ -294,13 +286,8 @@
 
       if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) {
          bgcolor = a_Html_color_parse(html, attrbuf, -1);
-         if (bgcolor != -1) {
-            if (bgcolor == 0xffffff && !prefs.allow_white_bg)
-               bgcolor = prefs.bg_color;
-
+         if (bgcolor != -1)
             props->set (CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR, bgcolor);
-            S_TOP(html)->current_bg_color = bgcolor;
-         }
       }
 
       html->styleEngine->setNonCssHints (props);
--- a/src/web.cc	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/web.cc	Fri Mar 06 10:09:38 2009 +0100
@@ -23,6 +23,7 @@
 
 #include "dw/core.hh"
 #include "prefs.h"
+#include "styleengine.hh"
 #include "web.hh"
 
 // Platform independent part
@@ -54,9 +55,6 @@
                             CA_Callback_t *Call, void **Data)
 {
    Widget *dw = NULL;
-   style::StyleAttrs styleAttrs;
-   style::Style *widgetStyle;
-   style::FontAttrs fontAttrs;
 
    _MSG("a_Web_dispatch_by_type\n");
 
@@ -67,25 +65,17 @@
 
    if (Web->flags & WEB_RootUrl) {
       /* We have RootUrl! */
+
+      /* Set a style for the widget */
+      StyleEngine styleEngine (layout);
+      styleEngine.startElement ("body");
+      Web->bgColor = styleEngine.backgroundStyle ()->backgroundColor->getColor ();
+
       dw = (Widget*) a_Mime_set_viewer(Type, Web, Call, Data);
       if (dw == NULL)
          return -1;
 
-      /* Set a style for the widget */
-      fontAttrs.name = prefs.font_sans_serif;
-      fontAttrs.size = (int) rint(14.0 * prefs.font_factor);
-      fontAttrs.weight = 400;
-      fontAttrs.style = style::FONT_STYLE_NORMAL;
-
-      styleAttrs.initValues ();
-      styleAttrs.margin.setVal (5);
-      styleAttrs.font = style::Font::create (layout, &fontAttrs);
-      styleAttrs.color = style::Color::create (layout, 0xff0000);
-      styleAttrs.backgroundColor =
-         style::Color::create (layout, prefs.bg_color);
-      widgetStyle = style::Style::create (layout, &styleAttrs);
-      dw->setStyle (widgetStyle);
-      widgetStyle->unref ();
+      dw->setStyle (styleEngine.style ());
 
       /* This method frees the old dw if any */
       layout->setWidget(dw);
@@ -130,7 +120,8 @@
    web->filename = NULL;
    web->stream  = NULL;
    web->SavedBytes = 0;
-
+   web->bgColor = 0x000000; /* Dummy value will be overwritten
+                             * in a_Web_dispatch_by_type. */
    dList_append(ValidWebs, (void *)web);
    return web;
 }
--- a/src/web.hh	Fri Mar 06 09:31:29 2009 +0100
+++ b/src/web.hh	Fri Mar 06 10:09:38 2009 +0100
@@ -27,6 +27,7 @@
 
   DilloImage *Image;          /* For image urls [reference] */
 
+  int32_t bgColor;            /* for image backgrounds */
   char *filename;             /* Variables for Local saving */
   FILE *stream;
   int SavedBytes;