From c6dc92e0ec56ccfc898d4d432eb9ec758e50d813 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Thu, 12 Sep 2019 19:34:32 +0300 Subject: [PATCH 1/6] Fixed: Cleanup of table/cell border --HG-- branch : html-improvements --- code/nel/include/nel/gui/group_table.h | 1 + code/nel/src/gui/group_html.cpp | 2 -- code/nel/src/gui/group_table.cpp | 10 ++++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/code/nel/include/nel/gui/group_table.h b/code/nel/include/nel/gui/group_table.h index ccc2ce3cf..52839e14b 100644 --- a/code/nel/include/nel/gui/group_table.h +++ b/code/nel/include/nel/gui/group_table.h @@ -41,6 +41,7 @@ namespace NLGUI DECLARE_UI_CLASS( CGroupCell ) CGroupCell(const TCtorParam ¶m); + ~CGroupCell(); enum TAlign { diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index b6b83fa3c..fcb1f58f0 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -6614,8 +6614,6 @@ namespace NLGUI uint32 borderWidth = 0; CRGBA borderColor = CRGBA::Transparent; - // TODO: _Style->hasBorder() ?? - table->Border = new CSSBorderRenderer(); if (elm.hasAttribute("border")) { std::string s = elm.getAttribute("border"); diff --git a/code/nel/src/gui/group_table.cpp b/code/nel/src/gui/group_table.cpp index 6f61b7571..6f4e93741 100644 --- a/code/nel/src/gui/group_table.cpp +++ b/code/nel/src/gui/group_table.cpp @@ -73,6 +73,16 @@ namespace NLGUI addGroup (Group); } + // ---------------------------------------------------------------------------- + CGroupCell::~CGroupCell() + { + if (Border) + { + delete Border; + Border = NULL; + } + } + // ---------------------------------------------------------------------------- void CGroupCell::setEnclosedGroupDefaultParams() { From 0ef7419fd6f309718e1045584fd5c9984307230d Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 14 Sep 2019 15:26:21 +0300 Subject: [PATCH 2/6] Fixed: Wrong border size when border hidden/none --HG-- branch : html-improvements --- code/nel/src/gui/group_table.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/code/nel/src/gui/group_table.cpp b/code/nel/src/gui/group_table.cpp index 6f4e93741..fa6279ad7 100644 --- a/code/nel/src/gui/group_table.cpp +++ b/code/nel/src/gui/group_table.cpp @@ -1134,7 +1134,9 @@ namespace NLGUI if (cell->NewLine) { column = 0; - currentX = Border->LeftWidth + CellSpacing; + currentX = CellSpacing; + if (Border) + currentX += Border->getLeftWidth(); _Rows.push_back(CRow()); } @@ -1412,7 +1414,9 @@ namespace NLGUI maxWidth += columns[i]; // TODO: CellPadding is probably already in columns width - maxWidth += Border->LeftWidth + Border->RightWidth + ((sint32)columns.size()+1) * CellSpacing + ((sint32)columns.size()*2) * CellPadding; + maxWidth += ((sint32)columns.size()+1) * CellSpacing + ((sint32)columns.size()*2) * CellPadding; + if (Border) + maxWidth += Border->getLeftRightWidth(); return maxWidth; } @@ -1458,7 +1462,9 @@ namespace NLGUI maxWidth += columns[i]; // TODO: CellPadding is probably already in columns width - maxWidth += Border->LeftWidth + Border->RightWidth + ((sint32)columns.size()+1) * CellSpacing + ((sint32)columns.size()*2) * CellPadding; + maxWidth += ((sint32)columns.size()+1) * CellSpacing + ((sint32)columns.size()*2) * CellPadding; + if (Border) + maxWidth += Border->getLeftRightWidth(); return maxWidth; } @@ -1556,12 +1562,16 @@ namespace NLGUI { if( name == "border" ) { - return toString( Border->TopWidth ); + if (Border) + return toString( Border->TopWidth ); + return "0"; } else if( name == "bordercolor" ) { - return toString( Border->TopColor ); + if (Border) + return toString( Border->TopColor ); + return toString(CRGBA::Transparent); } else if( name == "cellpadding" ) @@ -1597,6 +1607,8 @@ namespace NLGUI sint32 i; if( fromString( value, i ) ) { + if (!Border) + Border = new CSSBorderRenderer(); Border->TopWidth = i; Border->RightWidth = i; Border->BottomWidth = i; @@ -1610,6 +1622,8 @@ namespace NLGUI CRGBA c; if( fromString( value, c ) ) { + if (!Border) + Border = new CSSBorderRenderer(); Border->TopColor = c; Border->RightColor = c; Border->BottomColor = c; @@ -1659,8 +1673,11 @@ namespace NLGUI return NULL; xmlSetProp( node, BAD_CAST "type", BAD_CAST "table" ); - xmlSetProp( node, BAD_CAST "border", BAD_CAST toString( Border->TopWidth ).c_str() ); - xmlSetProp( node, BAD_CAST "bordercolor", BAD_CAST toString( Border->TopColor ).c_str() ); + if (Border) + { + xmlSetProp( node, BAD_CAST "border", BAD_CAST toString( Border->TopWidth ).c_str() ); + xmlSetProp( node, BAD_CAST "bordercolor", BAD_CAST toString( Border->TopColor ).c_str() ); + } xmlSetProp( node, BAD_CAST "cellpadding", BAD_CAST toString( CellPadding ).c_str() ); xmlSetProp( node, BAD_CAST "cellspacing", BAD_CAST toString( CellSpacing ).c_str() ); xmlSetProp( node, BAD_CAST "bgcolor", BAD_CAST toString( BgColor ).c_str() ); From 79fd4cf8d7421562daa2631140683c4a3561026a Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 14 Sep 2019 15:27:33 +0300 Subject: [PATCH 3/6] Changed: refactor --HG-- branch : html-improvements --- code/nel/include/nel/gui/css_style.h | 12 +-- code/nel/src/gui/css_style.cpp | 124 +++++++++++++-------------- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/code/nel/include/nel/gui/css_style.h b/code/nel/include/nel/gui/css_style.h index 50dd3180a..b4e751ac8 100644 --- a/code/nel/include/nel/gui/css_style.h +++ b/code/nel/include/nel/gui/css_style.h @@ -162,16 +162,16 @@ namespace NLGUI bool getShorthandIndices(const uint32 size, uint8 &t, uint8 &r, uint8 &b, uint8 &l) const; // break 'border' into 'border-top-color', 'border-top-style', etc rules - bool tryBorderWidthShorthand(const std::string &value, CStyleParams &style, const std::string &prop) const; - bool tryBorderStyleShorthand(const std::string &value, CStyleParams &style, const std::string &prop) const; - bool tryBorderColorShorthand(const std::string &value, CStyleParams &style, const std::string &prop) const; - void parseBorderShorthand(const std::string &value, CStyleParams &style, const std::string &prop) const; + bool tryBorderWidthShorthand(const std::string &prop, const std::string &value, TStyle &style) const; + bool tryBorderStyleShorthand(const std::string &prop, const std::string &value, TStyle &style) const; + bool tryBorderColorShorthand(const std::string &prop, const std::string &value, TStyle &style) const; + void expandBorderShorthand(const std::string &prop, const std::string &value, TStyle &style) const; // parse 'background' into 'background-color', 'background-image', etc - void parseBackgroundShorthand(const std::string &value, CStyleParams &style) const; + void expandBackgroundShorthand(const std::string &value, TStyle &style) const; // parse 'padding' into 'padding-top', 'padding-left', etc - void parsePaddingShorthand(const std::string &value, CStyleParams &style) const; + void expandPaddingShorthand(const std::string &value, TStyle &style) const; // parse string value into corresponding value void applyBorderWidth(const std::string &value, uint32 *dest, const uint32 currentWidth, const uint32 fontSize) const; diff --git a/code/nel/src/gui/css_style.cpp b/code/nel/src/gui/css_style.cpp index 888044e5c..79565acfa 100644 --- a/code/nel/src/gui/css_style.cpp +++ b/code/nel/src/gui/css_style.cpp @@ -434,7 +434,7 @@ namespace NLGUI else if (it->first == "background") { - parseBackgroundShorthand(it->second, style); + expandBackgroundShorthand(it->second, style.StyleRules); } else if (it->first == "background-repeat") @@ -464,25 +464,25 @@ namespace NLGUI || it->first == "border-bottom" || it->first == "border-left") { // TODO: use enum or bitmap constant instead of passing a string name (it->first) - parseBorderShorthand(it->second, style, it->first); + expandBorderShorthand(it->first, it->second, style.StyleRules); keep = false; } else if (it->first == "border-width") { - tryBorderWidthShorthand(it->second, style, it->first); + tryBorderWidthShorthand(it->first, it->second, style.StyleRules); keep = false; } else if (it->first == "border-style") { - tryBorderStyleShorthand(it->second, style, it->first); + tryBorderStyleShorthand(it->first, it->second, style.StyleRules); keep = false; } else if (it->first == "border-color") { - tryBorderColorShorthand(it->second, style, it->first); + tryBorderColorShorthand(it->first, it->second, style.StyleRules); keep = false; } else @@ -496,7 +496,7 @@ namespace NLGUI else if (it->first == "padding") { - parsePaddingShorthand(it->second, style); + expandPaddingShorthand(it->second, style.StyleRules); keep = false; } @@ -983,7 +983,7 @@ namespace NLGUI } // *************************************************************************** - void CCssStyle::parseBackgroundShorthand(const std::string &value, CStyleParams &style) const + void CCssStyle::expandBackgroundShorthand(const std::string &value, TStyle &style) const { // background: url(image.jpg) top center / 200px 200px no-repeat fixed padding-box content-box red; // background-image : url(image.jpg) @@ -1261,16 +1261,16 @@ namespace NLGUI { if (props[i] == "background-position") { - style.StyleRules["background-position-x"] = bgPositionX; - style.StyleRules["background-position-y"] = bgPositionY; + style["background-position-x"] = bgPositionX; + style["background-position-y"] = bgPositionY; } else if (props[i] == "background-clip") { - style.StyleRules["background-clip"] = bgClipValue; + style["background-clip"] = bgClipValue; } else { - style.StyleRules[props[i]] = values[i]; + style[props[i]] = values[i]; } } else @@ -1278,40 +1278,40 @@ namespace NLGUI // fill in default if one is set if (props[i] == "background-image") { - style.StyleRules[props[i]] = "none"; + style[props[i]] = "none"; } else if (props[i] == "background-position") { - style.StyleRules[props[i]] = "0% 0%"; - style.StyleRules["background-position-x"] = "left 0%"; - style.StyleRules["background-position-y"] = "top 0%"; + style[props[i]] = "0% 0%"; + style["background-position-x"] = "left 0%"; + style["background-position-y"] = "top 0%"; } else if (props[i] == "background-size") { - style.StyleRules[props[i]] = "auto auto"; + style[props[i]] = "auto auto"; } else if (props[i] == "background-repeat") { - style.StyleRules[props[i]] = "repeat"; + style[props[i]] = "repeat"; } else if(props[i] == "background-attachment") { - style.StyleRules[props[i]] = "scroll"; + style[props[i]] = "scroll"; } else if(props[i] == "background-origin") { - style.StyleRules[props[i]] = "padding-box"; + style[props[i]] = "padding-box"; } else if (props[i] == "background-clip") { if (bgClipFound) - style.StyleRules[props[i]] = bgClipValue; + style[props[i]] = bgClipValue; else - style.StyleRules[props[i]] = "border-box"; + style[props[i]] = "border-box"; } else if (props[i] == "background-color") { - style.StyleRules[props[i]] = "transparent"; + style[props[i]] = "transparent"; } } } @@ -1349,7 +1349,7 @@ namespace NLGUI } // *************************************************************************** - bool CCssStyle::tryBorderWidthShorthand(const std::string &value, CStyleParams &style, const std::string &prop) const + bool CCssStyle::tryBorderWidthShorthand(const std::string &prop, const std::string &value, TStyle &style) const { std::vector parts; NLMISC::splitString(toLower(value), " ", parts); @@ -1378,15 +1378,15 @@ namespace NLGUI uint8 t, r, b, l; if (!getShorthandIndices(parts.size(), t, r, b, l)) return false; - if (hasTop) style.StyleRules["border-top-width"] = parts[t]; - if (hasRight) style.StyleRules["border-right-width"] = parts[r]; - if (hasBottom) style.StyleRules["border-bottom-width"] = parts[b]; - if (hasLeft) style.StyleRules["border-left-width"] = parts[l]; + if (hasTop) style["border-top-width"] = parts[t]; + if (hasRight) style["border-right-width"] = parts[r]; + if (hasBottom) style["border-bottom-width"] = parts[b]; + if (hasLeft) style["border-left-width"] = parts[l]; return true; } // *************************************************************************** - bool CCssStyle::tryBorderStyleShorthand(const std::string &value, CStyleParams &style, const std::string &prop) const + bool CCssStyle::tryBorderStyleShorthand(const std::string &prop, const std::string &value, TStyle &style) const { std::vector parts; NLMISC::splitString(toLower(value), " ", parts); @@ -1427,15 +1427,15 @@ namespace NLGUI uint8 t, r, b, l; if (!getShorthandIndices(parts.size(), t, r, b, l)) return false; - if (hasTop) style.StyleRules["border-top-style"] = parts[t]; - if (hasRight) style.StyleRules["border-right-style"] = parts[r]; - if (hasBottom) style.StyleRules["border-bottom-style"] = parts[b]; - if (hasLeft) style.StyleRules["border-left-style"] = parts[l]; + if (hasTop) style["border-top-style"] = parts[t]; + if (hasRight) style["border-right-style"] = parts[r]; + if (hasBottom) style["border-bottom-style"] = parts[b]; + if (hasLeft) style["border-left-style"] = parts[l]; return true; } // *************************************************************************** - bool CCssStyle::tryBorderColorShorthand(const std::string &value, CStyleParams &style, const std::string &prop) const + bool CCssStyle::tryBorderColorShorthand(const std::string &prop, const std::string &value, TStyle &style) const { std::vector parts; NLMISC::splitString(toLower(value), " ", parts); @@ -1460,16 +1460,16 @@ namespace NLGUI uint8 t, r, b, l; if (!getShorthandIndices(parts.size(), t, r, b, l)) return false; - if (hasTop) style.StyleRules["border-top-color"] = parts[t]; - if (hasRight) style.StyleRules["border-right-color"] = parts[r]; - if (hasBottom) style.StyleRules["border-bottom-color"] = parts[b]; - if (hasLeft) style.StyleRules["border-left-color"] = parts[l]; + if (hasTop) style["border-top-color"] = parts[t]; + if (hasRight) style["border-right-color"] = parts[r]; + if (hasBottom) style["border-bottom-color"] = parts[b]; + if (hasLeft) style["border-left-color"] = parts[l]; return true; } // *************************************************************************** - void CCssStyle::parseBorderShorthand(const std::string &value, CStyleParams &style, const std::string &prop) const + void CCssStyle::expandBorderShorthand(const std::string &prop, const std::string &value, TStyle &style) const { // border: 1px solid #000; bool hasTop = (prop == "border" || prop == "border-top"); @@ -1481,7 +1481,7 @@ namespace NLGUI bool foundStyle = false; bool foundColor = false; - CStyleParams borderStyle; + TStyle borderStyle; std::vector parts; NLMISC::splitString(toLower(value), " ", parts); @@ -1490,17 +1490,17 @@ namespace NLGUI bool matched = false; if (!foundWidth) { - matched = foundWidth = tryBorderWidthShorthand(parts[index], borderStyle, prop); + matched = foundWidth = tryBorderWidthShorthand(prop, parts[index], borderStyle); } if (!matched && !foundStyle) { - matched = foundStyle = tryBorderStyleShorthand(parts[index], borderStyle, prop); + matched = foundStyle = tryBorderStyleShorthand(prop, parts[index], borderStyle); } if (!matched && !foundColor) { - matched = foundColor = tryBorderColorShorthand(parts[index], borderStyle, prop); + matched = foundColor = tryBorderColorShorthand(prop, parts[index], borderStyle); } // invalid rule if nothing gets matched @@ -1511,41 +1511,41 @@ namespace NLGUI } // apply rules that are present - TStyle::const_iterator it = borderStyle.StyleRules.begin(); - while(it != borderStyle.StyleRules.end()) + TStyle::const_iterator it = borderStyle.begin(); + while(it != borderStyle.end()) { - style.StyleRules[it->first] = it->second; + style[it->first] = it->second; ++it; } // reset those not present if (!foundWidth) { - if (hasTop) style.StyleRules["border-top-width"] = "medium"; - if (hasRight) style.StyleRules["border-right-width"] = "medium"; - if (hasBottom) style.StyleRules["border-bottom-width"] = "medium"; - if (hasLeft) style.StyleRules["border-left-width"] = "medium"; + if (hasTop) style["border-top-width"] = "medium"; + if (hasRight) style["border-right-width"] = "medium"; + if (hasBottom) style["border-bottom-width"] = "medium"; + if (hasLeft) style["border-left-width"] = "medium"; } // if (!foundStyle) { - if (hasTop) style.StyleRules["border-top-style"] = "none"; - if (hasRight) style.StyleRules["border-right-style"] = "none"; - if (hasBottom) style.StyleRules["border-bottom-style"] = "none"; - if (hasLeft) style.StyleRules["border-left-style"] = "none"; + if (hasTop) style["border-top-style"] = "none"; + if (hasRight) style["border-right-style"] = "none"; + if (hasBottom) style["border-bottom-style"] = "none"; + if (hasLeft) style["border-left-style"] = "none"; } // if (!foundColor) { - if (hasTop) style.StyleRules["border-top-color"] = "currentcolor"; - if (hasRight) style.StyleRules["border-right-color"] = "currentcolor"; - if (hasBottom) style.StyleRules["border-bottom-color"] = "currentcolor"; - if (hasLeft) style.StyleRules["border-left-color"] = "currentcolor"; + if (hasTop) style["border-top-color"] = "currentcolor"; + if (hasRight) style["border-right-color"] = "currentcolor"; + if (hasBottom) style["border-bottom-color"] = "currentcolor"; + if (hasLeft) style["border-left-color"] = "currentcolor"; } } // *************************************************************************** - void CCssStyle::parsePaddingShorthand(const std::string &value, CStyleParams &style) const + void CCssStyle::expandPaddingShorthand(const std::string &value, TStyle &style) const { std::vector parts; NLMISC::splitString(toLower(value), " ", parts); @@ -1554,10 +1554,10 @@ namespace NLGUI if (!getShorthandIndices(parts.size(), t, r, b, l)) return; - style.StyleRules["padding-top"] = parts[t]; - style.StyleRules["padding-right"] = parts[r]; - style.StyleRules["padding-bottom"] = parts[b]; - style.StyleRules["padding-left"] = parts[l]; + style["padding-top"] = parts[t]; + style["padding-right"] = parts[r]; + style["padding-bottom"] = parts[b]; + style["padding-left"] = parts[l]; } // *************************************************************************** From 963a9814da53364d30ce07a3d458c97a2ae3f6ea Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 14 Sep 2019 15:27:36 +0300 Subject: [PATCH 4/6] Changed: refactor css shorthand expansion to own method --HG-- branch : html-improvements --- code/nel/include/nel/gui/css_style.h | 4 + code/nel/src/gui/css_style.cpp | 120 +++++++++++++-------------- 2 files changed, 63 insertions(+), 61 deletions(-) diff --git a/code/nel/include/nel/gui/css_style.h b/code/nel/include/nel/gui/css_style.h index b4e751ac8..b553881d1 100644 --- a/code/nel/include/nel/gui/css_style.h +++ b/code/nel/include/nel/gui/css_style.h @@ -173,6 +173,10 @@ namespace NLGUI // parse 'padding' into 'padding-top', 'padding-left', etc 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 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 ¤tColor, const NLMISC::CRGBA &textColor) const; diff --git a/code/nel/src/gui/css_style.cpp b/code/nel/src/gui/css_style.cpp index 79565acfa..3f13dbb10 100644 --- a/code/nel/src/gui/css_style.cpp +++ b/code/nel/src/gui/css_style.cpp @@ -338,13 +338,9 @@ namespace NLGUI // - normalize values void CCssStyle::normalize(const TStyle &styleRules, CStyleParams &style, const CStyleParams ¤t) const { - bool keep = true; TStyle::const_iterator 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 style.StyleRules[it->first] = it->second; @@ -432,11 +428,6 @@ namespace NLGUI } } else - if (it->first == "background") - { - expandBackgroundShorthand(it->second, style.StyleRules); - } - else if (it->first == "background-repeat") { // old ryzom specific value @@ -444,48 +435,6 @@ namespace NLGUI style.StyleRules[it->first] = "repeat"; } 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->second == "inherit") @@ -494,17 +443,8 @@ namespace NLGUI style.DisplayBlock = (it->second == "block" || it->second == "table"); } else - if (it->first == "padding") { - expandPaddingShorthand(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); + expandShorthand(it->first, it->second, style.StyleRules); } } } @@ -1560,6 +1500,64 @@ namespace NLGUI 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 { From d7c754039e3a6377a0e428b22ea8fde3bccc33c5 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 14 Sep 2019 15:27:37 +0300 Subject: [PATCH 5/6] Fixed: shorthand/longhand properties handled in wrong order --HG-- branch : html-improvements --- code/nel/include/nel/gui/css_parser.h | 2 +- code/nel/include/nel/gui/css_style.h | 6 ++++-- code/nel/src/gui/css_parser.cpp | 8 ++++---- code/nel/src/gui/css_style.cpp | 20 +++++++++++--------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/code/nel/include/nel/gui/css_parser.h b/code/nel/include/nel/gui/css_parser.h index cfaf03caa..a6dc92022 100644 --- a/code/nel/include/nel/gui/css_parser.h +++ b/code/nel/include/nel/gui/css_parser.h @@ -31,7 +31,7 @@ namespace NLGUI class CCssParser { public: // parse style declaration, eg "color: red; font-size: 10px;" - static TStyle parseDecls(const std::string &styleString); + static TStyleVec parseDecls(const std::string &styleString); // parse css stylesheet void parseStylesheet(const std::string &cssString, std::vector &rules); diff --git a/code/nel/include/nel/gui/css_style.h b/code/nel/include/nel/gui/css_style.h index b553881d1..4eabe26ba 100644 --- a/code/nel/include/nel/gui/css_style.h +++ b/code/nel/include/nel/gui/css_style.h @@ -27,6 +27,8 @@ namespace NLGUI class CHtmlElement; typedef std::map TStyle; + typedef std::pair TStylePair; + typedef std::vector TStyleVec; /** * \brief CSS style rules @@ -118,7 +120,7 @@ namespace NLGUI struct SStyleRule { std::vector Selector; - TStyle Properties; + TStyleVec Properties; // pseudo element like ':before' std::string PseudoElement; @@ -153,7 +155,7 @@ namespace NLGUI void apply(CStyleParams &style, const CStyleParams ¤t) const; // merge src into dest by overwriting key in dest - void merge(TStyle &dst, const TStyle &src) const; + void merge(TStyle &dst, const TStyleVec &src) const; // match selector to dom path bool match(const std::vector &selector, const CHtmlElement &elm) const; diff --git a/code/nel/src/gui/css_parser.cpp b/code/nel/src/gui/css_parser.cpp index 39a4496bc..e59cf832b 100644 --- a/code/nel/src/gui/css_parser.cpp +++ b/code/nel/src/gui/css_parser.cpp @@ -35,9 +35,9 @@ namespace NLGUI // // key is converted to lowercase // value is left as is - TStyle CCssParser::parseDecls(const std::string &styleString) + TStyleVec CCssParser::parseDecls(const std::string &styleString) { - TStyle styles; + TStyleVec styles; std::vector elements; NLMISC::splitString(styleString, ";", elements); @@ -49,7 +49,7 @@ namespace NLGUI { std::string key = trim(toLower(elements[i].substr(0, pos))); std::string value = trim(elements[i].substr(pos+1)); - styles[key] = value; + styles.push_back(TStylePair(key, value)); } } @@ -94,7 +94,7 @@ namespace NLGUI std::vector selectors; NLMISC::explode(selectorString, ucstring(","), selectors); - TStyle props; + TStyleVec props; props = parseDecls(styleString.toUtf8()); // duplicate props to each selector in selector list, diff --git a/code/nel/src/gui/css_style.cpp b/code/nel/src/gui/css_style.cpp index 3f13dbb10..4555de6c9 100644 --- a/code/nel/src/gui/css_style.cpp +++ b/code/nel/src/gui/css_style.cpp @@ -102,7 +102,9 @@ namespace NLGUI } else { - elm.setPseudo(i->PseudoElement, i->Properties); + TStyle props; + merge(props, i->Properties); + elm.setPseudo(i->PseudoElement, props); } } } @@ -110,17 +112,18 @@ namespace NLGUI // style from "style" attribute overrides