diff --git a/code/nel/include/nel/gui/html_element.h b/code/nel/include/nel/gui/html_element.h index bac681c1c..b7bceb4ab 100644 --- a/code/nel/include/nel/gui/html_element.h +++ b/code/nel/include/nel/gui/html_element.h @@ -47,8 +47,6 @@ namespace NLGUI // defined style and :before/:after pseudo elements TStyle Style; - TStyle StyleBefore; - TStyle StyleAfter; // hierarchy CHtmlElement *parent; @@ -79,6 +77,16 @@ namespace NLGUI // debug std::string toString(bool tree = false, uint depth = 0) const; + + // query, get, set pseudo element style rules + void clearPseudo(); + bool hasPseudo(const std::string &key) const; + TStyle getPseudo(const std::string &key) const; + void setPseudo(const std::string &key, const TStyle &style); + + private: + // pseudo elements like ":before" and ":after" + std::map _Pseudo; }; } diff --git a/code/nel/src/gui/css_style.cpp b/code/nel/src/gui/css_style.cpp index 0147b06f5..95503e77c 100644 --- a/code/nel/src/gui/css_style.cpp +++ b/code/nel/src/gui/css_style.cpp @@ -89,8 +89,7 @@ namespace NLGUI } elm.Style.clear(); - elm.StyleBefore.clear(); - elm.StyleAfter.clear(); + elm.clearPseudo(); if (!mRules.empty()) { @@ -101,13 +100,9 @@ namespace NLGUI { merge(elm.Style, i->Properties); } - else if (i->PseudoElement == ":before") + else { - merge(elm.StyleBefore, i->Properties); - } - else if (i->PseudoElement == ":after") - { - merge(elm.StyleAfter, i->Properties); + elm.setPseudo(i->PseudoElement, i->Properties); } } } diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 7f8d29a79..76a7d3c25 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -1193,26 +1193,20 @@ namespace NLGUI // *************************************************************************** void CGroupHTML::renderPseudoElement(const std::string &pseudo, const CHtmlElement &elm) { - if (pseudo == ":before" && !elm.StyleBefore.empty()) - { - _Style.pushStyle(); - _Style.applyStyle(elm.StyleBefore); - } - else if (pseudo == ":after" && !elm.StyleAfter.empty()) - { - _Style.pushStyle(); - _Style.applyStyle(elm.StyleAfter); - } - else - { - // unknown pseudo element + if (pseudo != ":before" && pseudo != ":after") return; - } + + if (!elm.hasPseudo(pseudo)) + return; + + _Style.pushStyle(); + _Style.applyStyle(elm.getPseudo(pseudo)); // TODO: 'content' should already be tokenized in css parser as it has all the functions for that std::string content = trim(_Style.getStyle("content")); if (toLower(content) == "none" || toLower(content) == "normal") { + _Style.popStyle(); return; } diff --git a/code/nel/src/gui/html_element.cpp b/code/nel/src/gui/html_element.cpp index 215c1c9f5..141fa87af 100644 --- a/code/nel/src/gui/html_element.cpp +++ b/code/nel/src/gui/html_element.cpp @@ -82,6 +82,46 @@ namespace NLGUI } } + // *************************************************************************** + void CHtmlElement::clearPseudo() + { + _Pseudo.clear(); + } + + // *************************************************************************** + bool CHtmlElement::hasPseudo(const std::string &key) const + { + return _Pseudo.find(key) != _Pseudo.end(); + } + + // *************************************************************************** + TStyle CHtmlElement::getPseudo(const std::string &key) const + { + std::map::const_iterator it = _Pseudo.find(key); + if (it != _Pseudo.end()) + return it->second; + + return TStyle(); + } + + // *************************************************************************** + void CHtmlElement::setPseudo(const std::string &key, const TStyle &style) + { + std::map::iterator it = _Pseudo.find(key); + if (it != _Pseudo.end()) + { + // insert into previous, override previous values if they exist + for(TStyle::const_iterator itStyle = style.begin(); itStyle != style.end(); ++itStyle) + { + it->second[itStyle->first] = itStyle->second; + } + } + else + { + _Pseudo[key] = style; + } + } + // *************************************************************************** std::string CHtmlElement::toString(bool tree, uint depth) const {