Changed: Keep track of all pseudo elements matching html element

--HG--
branch : develop
feature/clean-deprecated
Nimetu 6 years ago
parent 2f5de64d96
commit 077f57c4b9

@ -47,8 +47,6 @@ namespace NLGUI
// defined style and :before/:after pseudo elements // defined style and :before/:after pseudo elements
TStyle Style; TStyle Style;
TStyle StyleBefore;
TStyle StyleAfter;
// hierarchy // hierarchy
CHtmlElement *parent; CHtmlElement *parent;
@ -79,6 +77,16 @@ namespace NLGUI
// debug // debug
std::string toString(bool tree = false, uint depth = 0) const; 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<std::string, TStyle> _Pseudo;
}; };
} }

@ -89,8 +89,7 @@ namespace NLGUI
} }
elm.Style.clear(); elm.Style.clear();
elm.StyleBefore.clear(); elm.clearPseudo();
elm.StyleAfter.clear();
if (!mRules.empty()) if (!mRules.empty())
{ {
@ -101,13 +100,9 @@ namespace NLGUI
{ {
merge(elm.Style, i->Properties); 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);
} }
} }
} }

@ -1193,26 +1193,20 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::renderPseudoElement(const std::string &pseudo, const CHtmlElement &elm) void CGroupHTML::renderPseudoElement(const std::string &pseudo, const CHtmlElement &elm)
{ {
if (pseudo == ":before" && !elm.StyleBefore.empty()) if (pseudo != ":before" && pseudo != ":after")
{ return;
_Style.pushStyle();
_Style.applyStyle(elm.StyleBefore); if (!elm.hasPseudo(pseudo))
}
else if (pseudo == ":after" && !elm.StyleAfter.empty())
{
_Style.pushStyle();
_Style.applyStyle(elm.StyleAfter);
}
else
{
// unknown pseudo element
return; 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 // TODO: 'content' should already be tokenized in css parser as it has all the functions for that
std::string content = trim(_Style.getStyle("content")); std::string content = trim(_Style.getStyle("content"));
if (toLower(content) == "none" || toLower(content) == "normal") if (toLower(content) == "none" || toLower(content) == "normal")
{ {
_Style.popStyle();
return; return;
} }

@ -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<std::string, TStyle>::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<std::string, TStyle>::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 std::string CHtmlElement::toString(bool tree, uint depth) const
{ {

Loading…
Cancel
Save