From 4fc467bb9112d4e49cc9ecbde03aa72bd805fc6d Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 17 Sep 2010 21:42:31 +0200 Subject: directly set background color As defined in http://www.w3.org/TR/CSS2/colors.html, the background color of the canvas can either be defined by the or the tag. To be able to deal with this in src/html.cc we now explicitely set the canvas color instead of infering it from the root widget. --- src/html.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/html.cc') diff --git a/src/html.cc b/src/html.cc index d728713e..3f39095a 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1761,6 +1761,7 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) html->styleEngine->setNonCssHints (&props); html->dw->setStyle (html->styleEngine->style ()); + HT2LT(html)->setBgColor(html->styleEngine->style ()->backgroundColor); /* Determine a color for visited links. * This color is computed once per page and used for immediate feedback @@ -1788,6 +1789,7 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) html->styleEngine->backgroundStyle()->backgroundColor->getColor()); } + S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_BODY; } -- cgit v1.2.3 From 3d530af5285a6b6238a683a87d637d22ec0855f3 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 17 Sep 2010 22:05:15 +0200 Subject: draw topLevel background if it differs from canvas background --- dw/layout.hh | 2 ++ dw/widget.cc | 4 +++- src/html.cc | 12 +++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src/html.cc') diff --git a/dw/layout.hh b/dw/layout.hh index a02cd101..dc9bf227 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -363,6 +363,8 @@ public: inline void resetSearch () { findtextState.resetSearch (); } void setBgColor (style::Color *color); + + inline style::Color* getBgColor () { return bgColor; } }; } // namespace dw diff --git a/dw/widget.cc b/dw/widget.cc index 7476e246..ded963fc 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -397,7 +397,9 @@ void Widget::drawWidgetBox (View *view, Rectangle *area, bool inverse) * widget->style->background_color is NULL (shining through). */ /** \todo Background images? */ - if (parent && style->backgroundColor) + + if (style->backgroundColor && + (parent || layout->getBgColor () != style->backgroundColor)) style::drawBackground (view, &viewArea, allocation.x, allocation.y, allocation.width, getHeight (), style, inverse); } diff --git a/src/html.cc b/src/html.cc index 3f39095a..9649b42e 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1569,10 +1569,16 @@ static void Html_parse_doctype(DilloHtml *html, const char *tag, int tagsize) */ static void Html_tag_open_html(DilloHtml *html, const char *tag, int tagsize) { + Style *style; + if (!(html->InFlags & IN_HTML)) html->InFlags |= IN_HTML; ++html->Num_HTML; + style = html->styleEngine->style (); + if (style->backgroundColor) + HT2LT(html)->setBgColor(style->backgroundColor); + if (html->Num_HTML > 1) { BUG_MSG("HTML element was already open\n"); } @@ -1761,7 +1767,11 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) html->styleEngine->setNonCssHints (&props); html->dw->setStyle (html->styleEngine->style ()); - HT2LT(html)->setBgColor(html->styleEngine->style ()->backgroundColor); + + /* Set canvas color if not already set from Html_open_html(). + */ + if (! HT2LT(html)->getBgColor()) + HT2LT(html)->setBgColor(html->styleEngine->style ()->backgroundColor); /* Determine a color for visited links. * This color is computed once per page and used for immediate feedback -- cgit v1.2.3 From 301d6d61c841a7456f0b5f0fd1f6142b0ed933df Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 17 Sep 2010 23:16:43 +0200 Subject: recompute style for in Html_open_body() The CSS style information is only available after has been parsed completely. So we redo the style for the tag in Html_open_body(). Also set the canvas color either as background color of the or the tag (see http://www.w3.org/TR/CSS2/colors.html). --- src/html.cc | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/html.cc') diff --git a/src/html.cc b/src/html.cc index 9649b42e..c46ec4af 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1569,16 +1569,10 @@ static void Html_parse_doctype(DilloHtml *html, const char *tag, int tagsize) */ static void Html_tag_open_html(DilloHtml *html, const char *tag, int tagsize) { - Style *style; - if (!(html->InFlags & IN_HTML)) html->InFlags |= IN_HTML; ++html->Num_HTML; - style = html->styleEngine->style (); - if (style->backgroundColor) - HT2LT(html)->setBgColor(style->backgroundColor); - if (html->Num_HTML > 1) { BUG_MSG("HTML element was already open\n"); } @@ -1731,6 +1725,9 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) CssPropertyList props; int32_t color; int tag_index_a = a_Html_tag_index ("a"); + int tag_index_body = a_Html_tag_index ("body"); + int tag_index_html = a_Html_tag_index ("html"); + style::Color *bgColor; if (!(html->InFlags & IN_BODY)) html->InFlags |= IN_BODY; @@ -1745,6 +1742,22 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) BUG_MSG("unclosed HEAD element\n"); } + html->styleEngine->endElement(tag_index_body); + html->styleEngine->endElement(tag_index_html); + html->styleEngine->startElement(tag_index_html); + bgColor = html->styleEngine->style ()->backgroundColor; + html->styleEngine->startElement(tag_index_body); + + if ((attrbuf = Html_get_attr2(html, tag, tagsize, "id", + HTML_LeftTrim | HTML_RightTrim))) + html->styleEngine->setId(attrbuf); + if ((attrbuf = Html_get_attr2(html, tag, tagsize, "class", + HTML_LeftTrim | HTML_RightTrim))) + html->styleEngine->setClass(attrbuf); + if ((attrbuf = Html_get_attr2(html, tag, tagsize, "style", + HTML_LeftTrim | HTML_RightTrim))) + html->styleEngine->setStyle(attrbuf); + textblock = HT2TB(html); if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) { @@ -1770,8 +1783,10 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) /* Set canvas color if not already set from Html_open_html(). */ - if (! HT2LT(html)->getBgColor()) - HT2LT(html)->setBgColor(html->styleEngine->style ()->backgroundColor); + if (!bgColor) + bgColor = html->styleEngine->style ()->backgroundColor; + + HT2LT(html)->setBgColor(bgColor); /* Determine a color for visited links. * This color is computed once per page and used for immediate feedback -- cgit v1.2.3 From b66ff3ea295863bebe2d062df0c235891f9a597b Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 24 Sep 2010 23:08:24 +0200 Subject: bring back bg_color dillorc option --- dillorc | 5 +++++ dw/widget.cc | 4 +--- src/html.cc | 2 ++ src/plain.cc | 4 ++++ src/prefs.c | 1 + src/prefs.h | 1 + src/prefsparser.cc | 7 +++++++ 7 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src/html.cc') diff --git a/dillorc b/dillorc index ba132ba0..713a290a 100644 --- a/dillorc +++ b/dillorc @@ -46,6 +46,11 @@ # RENDERING SECTION #------------------------------------------------------------------------- +# Set the background color +# bg_color=gray +# bg_color=0xd6d6c0 +#bg_color=0xdcd1ba + # Default fonts: # # If FLTK2 has been configured with Xft enabled (the default), you can diff --git a/dw/widget.cc b/dw/widget.cc index ded963fc..ee8cb17c 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -337,9 +337,7 @@ style::Color *Widget::getBgColor () widget = widget->parent; } - MSG_WARN("No background color found!\n"); - return NULL; - + return layout->getBgColor (); } diff --git a/src/html.cc b/src/html.cc index c46ec4af..91b8ac99 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1785,6 +1785,8 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) */ if (!bgColor) bgColor = html->styleEngine->style ()->backgroundColor; + if (!bgColor) + bgColor = style::Color::create (HT2LT(html), prefs.bg_color); HT2LT(html)->setBgColor(bgColor); diff --git a/src/plain.cc b/src/plain.cc index 4da618e4..b5b2dc0a 100644 --- a/src/plain.cc +++ b/src/plain.cc @@ -85,6 +85,8 @@ void a_Plain_free(void *data); */ DilloPlain::DilloPlain(BrowserWindow *p_bw) { + style::Color *bgColor; + /* Init event receiver */ plainReceiver.plain = this; @@ -95,6 +97,8 @@ DilloPlain::DilloPlain(BrowserWindow *p_bw) state = ST_SeekingEol; Layout *layout = (Layout*) bw->render_layout; + bgColor = style::Color::create (layout, prefs.bg_color); + layout->setBgColor(bgColor); StyleEngine styleEngine (layout); styleEngine.startElement ("body"); diff --git a/src/prefs.c b/src/prefs.c index 5514c01a..f968710a 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -36,6 +36,7 @@ DilloPrefs prefs; void a_Prefs_init(void) { prefs.allow_white_bg = TRUE; + prefs.bg_color = 0xdcd1ba; prefs.buffered_drawing = 1; prefs.contrast_visited_color = TRUE; prefs.enterpress_forces_submit = FALSE; diff --git a/src/prefs.h b/src/prefs.h index 684262ed..4009925c 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -46,6 +46,7 @@ struct _DilloPrefs { DilloUrl *start_page; DilloUrl *home; bool_t allow_white_bg; + int32_t bg_color; bool_t contrast_visited_color; bool_t show_tooltip; int panel_size; diff --git a/src/prefsparser.cc b/src/prefsparser.cc index 78cade0b..95f98c16 100644 --- a/src/prefsparser.cc +++ b/src/prefsparser.cc @@ -16,11 +16,13 @@ #include "prefs.h" #include "misc.h" #include "msg.h" +#include "colors.h" #include "prefsparser.hh" typedef enum { PREFS_BOOL, + PREFS_COLOR, PREFS_STRING, PREFS_URL, PREFS_INT32, @@ -43,10 +45,12 @@ int PrefsParser::parseOption(char *name, char *value) { const SymNode_t *node; uint_t i; + int st; /* 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, @@ -122,6 +126,9 @@ int PrefsParser::parseOption(char *name, char *value) *(bool_t *)node->pref = (!dStrcasecmp(value, "yes") || !dStrcasecmp(value, "true")); break; + case PREFS_COLOR: + *(int32_t *)node->pref = a_Color_parse(value, *(int32_t*)node->pref,&st); + break; case PREFS_STRING: dFree(*(char **)node->pref); *(char **)node->pref = dStrdup(value); -- cgit v1.2.3 From a6cf69ecca7f17838f551a2983e2277440ec3f0d Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 24 Sep 2010 23:44:47 +0200 Subject: call layout->setBgColor() from web.cc --- dw/layout.cc | 3 ++- src/css.cc | 1 - src/html.cc | 5 ++--- src/plain.cc | 4 ---- src/uicmd.cc | 4 ++++ src/web.cc | 5 ++++- 6 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/html.cc') diff --git a/dw/layout.cc b/dw/layout.cc index f3ff896e..aa9f05ed 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -611,7 +611,8 @@ void Layout::updateCursor () void Layout::setBgColor (style::Color *color) { bgColor = color; - view->setBgColor (bgColor); + if (view) + view->setBgColor (bgColor); } void Layout::resizeIdle () diff --git a/src/css.cc b/src/css.cc index 2e3b4858..25ddc9ae 100644 --- a/src/css.cc +++ b/src/css.cc @@ -566,7 +566,6 @@ void CssContext::buildUserAgentStyle () { ":link {color: blue; text-decoration: underline; cursor: pointer}" ":visited {color: #800080; text-decoration: underline; cursor: pointer}" "h1, h2, h3, h4, h5, h6, b, strong {font-weight: bolder}" - "html {font-family: sans-serif; color: black}" "i, em, cite, address, var {font-style: italic}" ":link img, :visited img {border: 1px solid}" "frameset, ul, ol, dir {margin-left: 40px}" diff --git a/src/html.cc b/src/html.cc index 91b8ac99..1a353224 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1785,10 +1785,9 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) */ if (!bgColor) bgColor = html->styleEngine->style ()->backgroundColor; - if (!bgColor) - bgColor = style::Color::create (HT2LT(html), prefs.bg_color); - HT2LT(html)->setBgColor(bgColor); + if (bgColor) + HT2LT(html)->setBgColor(bgColor); /* Determine a color for visited links. * This color is computed once per page and used for immediate feedback diff --git a/src/plain.cc b/src/plain.cc index b5b2dc0a..4da618e4 100644 --- a/src/plain.cc +++ b/src/plain.cc @@ -85,8 +85,6 @@ void a_Plain_free(void *data); */ DilloPlain::DilloPlain(BrowserWindow *p_bw) { - style::Color *bgColor; - /* Init event receiver */ plainReceiver.plain = this; @@ -97,8 +95,6 @@ DilloPlain::DilloPlain(BrowserWindow *p_bw) state = ST_SeekingEol; Layout *layout = (Layout*) bw->render_layout; - bgColor = style::Color::create (layout, prefs.bg_color); - layout->setBgColor(bgColor); StyleEngine styleEngine (layout); styleEngine.startElement ("body"); diff --git a/src/uicmd.cc b/src/uicmd.cc index 93836735..001165d6 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -449,6 +449,8 @@ BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, // Now create the Dw render layout and viewport FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); + style::Color *bgColor = style::Color::create (layout, prefs.bg_color); + layout->setBgColor (bgColor); FltkViewport *viewport = new FltkViewport (0, 0, 1, 1); if (prefs.buffered_drawing == 1) @@ -507,6 +509,8 @@ static BrowserWindow *UIcmd_tab_new(const void *vbw) // Now create the Dw render layout and viewport FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); + style::Color *bgColor = style::Color::create (layout, prefs.bg_color); + layout->setBgColor (bgColor); FltkViewport *viewport = new FltkViewport (0, 0, 1, 1); diff --git a/src/web.cc b/src/web.cc index 17302b1c..1b5741ae 100644 --- a/src/web.cc +++ b/src/web.cc @@ -61,10 +61,13 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, if (Web->flags & WEB_RootUrl) { /* We have RootUrl! */ + style::Color *bgColor = style::Color::create (layout, prefs.bg_color); + Web->bgColor = bgColor->getColor (); + layout->setBgColor (bgColor); + /* 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) -- cgit v1.2.3