Mercurial > dillo_port1.3
changeset 1711:b27cf7eb15b6
fix last commit
dw::core::style::Style must always hold the computed values of CSS
properties, as those are inherited.
The computed value of border-width is 0 if border-style is 'none', so
avoid the combination of border-width != 0 and border-style 'none'.
Refactor StyleEngine a bit.
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> |
---|---|
date | Fri, 01 Oct 2010 23:28:13 +0200 |
parents | 18f974a1380c |
children | 9a71c8d886ef |
files | dw/style.cc src/styleengine.cc src/styleengine.hh |
diffstat | 3 files changed, 43 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/dw/style.cc Fri Oct 01 16:12:16 2010 +0200 +++ b/dw/style.cc Fri Oct 01 23:28:13 2010 +0200 @@ -47,7 +47,7 @@ backgroundColor = NULL; width = height = lineHeight = LENGTH_AUTO; margin.setVal (0); - borderWidth.setVal (2); + borderWidth.setVal (0); padding.setVal (0); setBorderColor (NULL); setBorderStyle (BORDER_NONE); @@ -75,7 +75,7 @@ height = LENGTH_AUTO; margin.setVal (0); - borderWidth.setVal (2); + borderWidth.setVal (0); padding.setVal (0); setBorderColor (NULL); setBorderStyle (BORDER_NONE);
--- a/src/styleengine.cc Fri Oct 01 16:12:16 2010 +0200 +++ b/src/styleengine.cc Fri Oct 01 23:28:13 2010 +0200 @@ -182,6 +182,42 @@ stack->setSize (stack->size () - 1); } +void StyleEngine::preprocessAttrs (dw::core::style::StyleAttrs *attrs) { + /* workaround for styling of inline elements */ + if (stack->getRef (stack->size () - 2)->inheritBackgroundColor) { + attrs->backgroundColor = + stack->getRef (stack->size () - 2)->style->backgroundColor; + + attrs->valign = stack->getRef (stack->size () - 2)->style->valign; + } + /* initial value of border-width is 'medium' */ + attrs->borderWidth.top = 2; + attrs->borderWidth.bottom = 2; + attrs->borderWidth.left = 2; + attrs->borderWidth.right = 2; +} + +void StyleEngine::postprocessAttrs (dw::core::style::StyleAttrs *attrs) { + /* if border-color is not specified use color as computed value */ + if (attrs->borderColor.top == NULL) + attrs->borderColor.top = attrs->color; + if (attrs->borderColor.bottom == NULL) + attrs->borderColor.bottom = attrs->color; + if (attrs->borderColor.left == NULL) + attrs->borderColor.left = attrs->color; + if (attrs->borderColor.right == NULL) + attrs->borderColor.right = attrs->color; + /* computed value of border-width is 0 if border-style is 'none' */ + if (attrs->borderStyle.top == BORDER_NONE) + attrs->borderWidth.top = 0; + if (attrs->borderStyle.bottom == BORDER_NONE) + attrs->borderWidth.bottom = 0; + if (attrs->borderStyle.left == BORDER_NONE) + attrs->borderWidth.left = 0; + if (attrs->borderStyle.right == BORDER_NONE) + attrs->borderWidth.right = 0; +} + /** * \brief Make changes to StyleAttrs attrs according to CssPropertyList props. */ @@ -498,24 +534,6 @@ } } - /* make sure border colors are set */ - if (attrs->borderColor.top == NULL) - attrs->borderColor.top = attrs->color; - if (attrs->borderColor.bottom == NULL) - attrs->borderColor.bottom = attrs->color; - if (attrs->borderColor.left == NULL) - attrs->borderColor.left = attrs->color; - if (attrs->borderColor.right == NULL) - attrs->borderColor.right = attrs->color; - - if (attrs->borderStyle.top == BORDER_NONE) - attrs->borderWidth.top = 0; - if (attrs->borderStyle.bottom == BORDER_NONE) - attrs->borderWidth.bottom = 0; - if (attrs->borderStyle.left == BORDER_NONE) - attrs->borderWidth.left = 0; - if (attrs->borderStyle.right == BORDER_NONE) - attrs->borderWidth.right = 0; } /** @@ -632,13 +650,7 @@ // reset values that are not inherited according to CSS attrs.resetValues (); - - if (stack->getRef (stack->size () - 2)->inheritBackgroundColor) { - attrs.backgroundColor = - stack->getRef (stack->size () - 2)->style->backgroundColor; - - attrs.valign = stack->getRef (stack->size () - 2)->style->valign; - } + preprocessAttrs (&attrs); // parse style information from style="" attribute, if it exists if (styleAttribute && prefs.parse_embedded_css) @@ -652,6 +664,8 @@ // apply style apply (&attrs, &props); + postprocessAttrs (&attrs); + stack->getRef (stack->size () - 1)->style = Style::create (layout, &attrs); if (styleAttributeProps)
--- a/src/styleengine.hh Fri Oct 01 16:12:16 2010 +0200 +++ b/src/styleengine.hh Fri Oct 01 23:28:13 2010 +0200 @@ -35,6 +35,8 @@ dw::core::style::Style *style0 (CssPropertyList *nonCssHints = NULL); dw::core::style::Style *wordStyle0 (CssPropertyList *nonCssHints = NULL); + void preprocessAttrs (dw::core::style::StyleAttrs *attrs); + void postprocessAttrs (dw::core::style::StyleAttrs *attrs); void apply (dw::core::style::StyleAttrs *attrs, CssPropertyList *props); bool computeValue (int *dest, CssLength value, dw::core::style::Font *font);