Changed: refactor css shorthand expansion to own method

--HG--
branch : html-improvements
hg/feature/html-improvements
Nimetu 5 years ago
parent 79fd4cf8d7
commit 963a9814da

@ -173,6 +173,10 @@ namespace NLGUI
// parse 'padding' into 'padding-top', 'padding-left', etc // parse 'padding' into 'padding-top', 'padding-left', etc
void expandPaddingShorthand(const std::string &value, TStyle &style) const; void expandPaddingShorthand(const std::string &value, TStyle &style) const;
// expand shorthand rule, ie "border", into longhand names, ie "border-top-width"
// if shorthand is present in style, then its removed
void expandShorthand(const std::string &prop, const std::string &value, TStyle &style) const;
// parse string value into corresponding value // parse string value into corresponding value
void applyBorderWidth(const std::string &value, uint32 *dest, const uint32 currentWidth, const uint32 fontSize) const; void applyBorderWidth(const std::string &value, uint32 *dest, const uint32 currentWidth, const uint32 fontSize) const;
void applyBorderColor(const std::string &value, NLMISC::CRGBA *dest, const NLMISC::CRGBA &currentColor, const NLMISC::CRGBA &textColor) const; void applyBorderColor(const std::string &value, NLMISC::CRGBA *dest, const NLMISC::CRGBA &currentColor, const NLMISC::CRGBA &textColor) const;

@ -338,13 +338,9 @@ namespace NLGUI
// - normalize values // - normalize values
void CCssStyle::normalize(const TStyle &styleRules, CStyleParams &style, const CStyleParams &current) const void CCssStyle::normalize(const TStyle &styleRules, CStyleParams &style, const CStyleParams &current) const
{ {
bool keep = true;
TStyle::const_iterator it; TStyle::const_iterator it;
for (it=styleRules.begin(); it != styleRules.end(); ++it) for (it=styleRules.begin(); it != styleRules.end(); ++it)
{ {
// shorthands will be replaced with proper statements and shorthand rule is removed
keep = true;
// update local copy of applied style // update local copy of applied style
style.StyleRules[it->first] = it->second; style.StyleRules[it->first] = it->second;
@ -432,11 +428,6 @@ namespace NLGUI
} }
} }
else else
if (it->first == "background")
{
expandBackgroundShorthand(it->second, style.StyleRules);
}
else
if (it->first == "background-repeat") if (it->first == "background-repeat")
{ {
// old ryzom specific value // old ryzom specific value
@ -444,48 +435,6 @@ namespace NLGUI
style.StyleRules[it->first] = "repeat"; style.StyleRules[it->first] = "repeat";
} }
else else
if (it->first == "background-scale")
{
// replace old ryzom specific rule with background-size
if (it->second != "1")
{
style.StyleRules["background-size"] = "auto";
}
else
{
style.StyleRules["background-size"] = "100%";
}
keep = false;
}
else
if (it->first == "border"
|| it->first == "border-top" || it->first == "border-right"
|| it->first == "border-bottom" || it->first == "border-left")
{
// TODO: use enum or bitmap constant instead of passing a string name (it->first)
expandBorderShorthand(it->first, it->second, style.StyleRules);
keep = false;
}
else
if (it->first == "border-width")
{
tryBorderWidthShorthand(it->first, it->second, style.StyleRules);
keep = false;
}
else
if (it->first == "border-style")
{
tryBorderStyleShorthand(it->first, it->second, style.StyleRules);
keep = false;
}
else
if (it->first == "border-color")
{
tryBorderColorShorthand(it->first, it->second, style.StyleRules);
keep = false;
}
else
if (it->first == "display") if (it->first == "display")
{ {
if (it->second == "inherit") if (it->second == "inherit")
@ -494,17 +443,8 @@ namespace NLGUI
style.DisplayBlock = (it->second == "block" || it->second == "table"); style.DisplayBlock = (it->second == "block" || it->second == "table");
} }
else else
if (it->first == "padding")
{ {
expandPaddingShorthand(it->second, style.StyleRules); expandShorthand(it->first, it->second, style.StyleRules);
keep = false;
}
if (!keep)
{
TStyle::iterator pos = style.StyleRules.find(it->first);
if (pos != style.StyleRules.end())
style.StyleRules.erase(pos);
} }
} }
} }
@ -1560,6 +1500,64 @@ namespace NLGUI
style["padding-left"] = parts[l]; style["padding-left"] = parts[l];
} }
// ***************************************************************************
void CCssStyle::expandShorthand(const std::string &prop, const std::string &value, TStyle &style) const
{
// if shorthand matches, then remove it after expansion
bool keep = false;
if (prop == "background")
{
expandBackgroundShorthand(value, style);
}
else if (prop == "background-scale")
{
// replace old ryzom specific rule with background-size
if (value != "1")
{
style["background-size"] = "auto";
}
else
{
style["background-size"] = "100%";
}
}
else if (prop == "border"
|| prop == "border-top" || prop == "border-right"
|| prop == "border-bottom" || prop == "border-left")
{
// TODO: use enum or bitmap constant instead of passing a string name (prop)
expandBorderShorthand(prop, value, style);
}
else if (prop == "border-width")
{
tryBorderWidthShorthand(prop, value, style);
}
else if (prop == "border-style")
{
tryBorderStyleShorthand(prop, value, style);
}
else if (prop == "border-color")
{
tryBorderColorShorthand(prop, value, style);
}
else if (prop == "padding")
{
expandPaddingShorthand(value, style);
}
else
{
keep = true;
}
if (!keep)
{
TStyle::iterator pos = style.find(prop);
if (pos != style.end())
style.erase(pos);
}
}
// *************************************************************************** // ***************************************************************************
void CCssStyle::applyCssMinMax(sint32 &width, sint32 &height, sint32 minw, sint32 minh, sint32 maxw, sint32 maxh) const void CCssStyle::applyCssMinMax(sint32 &width, sint32 &height, sint32 minw, sint32 minh, sint32 maxw, sint32 maxh) const
{ {

Loading…
Cancel
Save