aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2010-10-01 23:28:13 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2010-10-01 23:28:13 +0200
commit53997164c2e61962543a84eb14968b980e8d27a6 (patch)
tree3bd319ed04636a4bdb581deb58bca93562424e0d
parent47a9e5206c2f6d7775198533a70cb40013b467f2 (diff)
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.
-rw-r--r--dw/style.cc4
-rw-r--r--src/styleengine.cc64
-rw-r--r--src/styleengine.hh2
3 files changed, 43 insertions, 27 deletions
diff --git a/dw/style.cc b/dw/style.cc
index f71543f7..cc58ce28 100644
--- a/dw/style.cc
+++ b/dw/style.cc
@@ -47,7 +47,7 @@ void StyleAttrs::initValues ()
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 @@ void StyleAttrs::resetValues ()
height = LENGTH_AUTO;
margin.setVal (0);
- borderWidth.setVal (2);
+ borderWidth.setVal (0);
padding.setVal (0);
setBorderColor (NULL);
setBorderStyle (BORDER_NONE);
diff --git a/src/styleengine.cc b/src/styleengine.cc
index f8b63652..3233b69c 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -182,6 +182,42 @@ void StyleEngine::endElement (int element) {
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 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
}
}
- /* 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 @@ Style * StyleEngine::style0 (CssPropertyList *nonCssProperties) {
// 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 @@ Style * StyleEngine::style0 (CssPropertyList *nonCssProperties) {
// apply style
apply (&attrs, &props);
+ postprocessAttrs (&attrs);
+
stack->getRef (stack->size () - 1)->style = Style::create (layout, &attrs);
if (styleAttributeProps)
diff --git a/src/styleengine.hh b/src/styleengine.hh
index 66f28cee..5eafc7a6 100644
--- a/src/styleengine.hh
+++ b/src/styleengine.hh
@@ -35,6 +35,8 @@ class StyleEngine {
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);