diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2011-06-07 12:06:52 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2011-06-07 12:06:52 +0200 |
commit | d9d884f2437dcfaf9bb576194767247616e5efdb (patch) | |
tree | e181c6d58b6c925f96862e02d5bce8ca97be52ec /src | |
parent | 605ef351d2f344aebb48631db74e330f45158c61 (diff) |
support !important in style attributes
Diffstat (limited to 'src')
-rw-r--r-- | src/css.cc | 6 | ||||
-rw-r--r-- | src/css.hh | 3 | ||||
-rw-r--r-- | src/cssparser.cc | 14 | ||||
-rw-r--r-- | src/cssparser.hh | 5 | ||||
-rw-r--r-- | src/styleengine.cc | 23 | ||||
-rw-r--r-- | src/styleengine.hh | 1 |
6 files changed, 32 insertions, 20 deletions
@@ -535,7 +535,8 @@ CssContext::~CssContext () { */ void CssContext::apply (CssPropertyList *props, Doctree *docTree, DoctreeNode *node, - CssPropertyList *tagStyle, CssPropertyList *nonCssHints) { + CssPropertyList *tagStyle, CssPropertyList *tagStyleImportant, + CssPropertyList *nonCssHints) { if (sheet[CSS_PRIMARY_USER_AGENT]) sheet[CSS_PRIMARY_USER_AGENT]->apply (props, docTree, node); @@ -554,6 +555,9 @@ void CssContext::apply (CssPropertyList *props, Doctree *docTree, if (sheet[CSS_PRIMARY_AUTHOR_IMPORTANT]) sheet[CSS_PRIMARY_AUTHOR_IMPORTANT]->apply (props, docTree, node); + if (tagStyleImportant) + tagStyleImportant->apply (props); + if (sheet[CSS_PRIMARY_USER_IMPORTANT]) sheet[CSS_PRIMARY_USER_IMPORTANT]->apply (props, docTree, node); } @@ -475,7 +475,8 @@ class CssContext { CssPrimaryOrder order); void apply (CssPropertyList *props, Doctree *docTree, DoctreeNode *node, - CssPropertyList *tagStyle, CssPropertyList *nonCssHints); + CssPropertyList *tagStyle, CssPropertyList *tagStyleImportant, + CssPropertyList *nonCssHints); }; #endif diff --git a/src/cssparser.cc b/src/cssparser.cc index aa4cea56..4838f607 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -1590,22 +1590,16 @@ void CssParser::parse(DilloHtml *html, DilloUrl *url, CssContext * context, } } -CssPropertyList *CssParser::parseDeclarationBlock(const char *buf, int buflen) +void CssParser::parseDeclarationBlock(const char *buf, int buflen, + CssPropertyList *props, + CssPropertyList *propsImortant) { - CssPropertyList *props = new CssPropertyList (true); CssParser parser (NULL, CSS_ORIGIN_AUTHOR, buf, buflen); parser.withinBlock = true; do - parser.parseDeclaration(props, NULL); + parser.parseDeclaration(props, propsImortant); while (!(parser.ttype == CSS_TK_END || (parser.ttype == CSS_TK_CHAR && parser.tval[0] == '}'))); - - if (props->size () == 0) { - delete props; - props = NULL; - } - - return props; } diff --git a/src/cssparser.hh b/src/cssparser.hh index 1542405d..8609877b 100644 --- a/src/cssparser.hh +++ b/src/cssparser.hh @@ -47,8 +47,9 @@ class CssParser { void ignoreStatement(); public: - static CssPropertyList *parseDeclarationBlock(const char *buf, - int buflen); + static void parseDeclarationBlock(const char *buf, int buflen, + CssPropertyList *props, + CssPropertyList *propsImortant); static void parse(DilloHtml *html, DilloUrl *url, CssContext *context, const char *buf, int buflen, CssOrigin origin); static const char *propertyNameString(CssPropertyName name); diff --git a/src/styleengine.cc b/src/styleengine.cc index d763146e..9a8a1738 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -52,6 +52,7 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) { n->wordStyle = NULL; n->backgroundStyle = NULL; n->styleAttrProperties = NULL; + n->styleAttrPropertiesImportant = NULL; n->nonCssProperties = NULL; n->inheritBackgroundColor = false; } @@ -82,6 +83,7 @@ void StyleEngine::startElement (int element) { stack->increase (); Node *n = stack->getRef (stack->size () - 1); n->styleAttrProperties = NULL; + n->styleAttrPropertiesImportant = NULL; n->nonCssProperties = NULL; n->style = NULL; n->wordStyle = NULL; @@ -138,10 +140,14 @@ void StyleEngine::setStyle (const char *styleAttr) { Node *n = stack->getRef (stack->size () - 1); assert (n->styleAttrProperties == NULL); // parse style information from style="" attribute, if it exists - if (styleAttr && prefs.parse_embedded_css) - n->styleAttrProperties = - CssParser::parseDeclarationBlock (styleAttr, - strlen (styleAttr)); + if (styleAttr && prefs.parse_embedded_css) { + n->styleAttrProperties = new CssPropertyList (true); + n->styleAttrPropertiesImportant = new CssPropertyList (true); + + CssParser::parseDeclarationBlock (styleAttr, strlen (styleAttr), + n->styleAttrProperties, + n->styleAttrPropertiesImportant); + } }; /** @@ -213,6 +219,8 @@ void StyleEngine::endElement (int element) { if (n->styleAttrProperties) delete n->styleAttrProperties; + if (n->styleAttrPropertiesImportant) + delete n->styleAttrPropertiesImportant; if (n->nonCssProperties) delete n->nonCssProperties; if (n->style) @@ -706,7 +714,8 @@ Style * StyleEngine::backgroundStyle () { * This method is private. Call style() to get a current style object. */ Style * StyleEngine::style0 (int i) { - CssPropertyList props, *styleAttrProperties, *nonCssProperties; + CssPropertyList props, *styleAttrProperties, *styleAttrPropertiesImportant; + CssPropertyList *nonCssProperties; // get previous style from the stack StyleAttrs attrs = *stack->getRef (i - 1)->style; @@ -723,11 +732,13 @@ Style * StyleEngine::style0 (int i) { preprocessAttrs (&attrs); styleAttrProperties = stack->getRef (i)->styleAttrProperties; + styleAttrPropertiesImportant = stack->getRef(i)->styleAttrPropertiesImportant; nonCssProperties = stack->getRef (i)->nonCssProperties; // merge style information cssContext->apply (&props, doctree, stack->getRef(i)->doctreeNode, - styleAttrProperties, nonCssProperties); + styleAttrProperties, styleAttrPropertiesImportant, + nonCssProperties); // apply style apply (i, &attrs, &props); diff --git a/src/styleengine.hh b/src/styleengine.hh index e37aeed1..b73a8b5f 100644 --- a/src/styleengine.hh +++ b/src/styleengine.hh @@ -21,6 +21,7 @@ class StyleEngine { private: struct Node { CssPropertyList *styleAttrProperties; + CssPropertyList *styleAttrPropertiesImportant; CssPropertyList *nonCssProperties; dw::core::style::Style *style; dw::core::style::Style *wordStyle; |