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 50dd3180a..bbeac8d9a 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; @@ -142,6 +144,9 @@ namespace NLGUI // test if str is one of "thin/medium/thick" and return its pixel value bool scanCssLength(const std::string& str, uint32 &px) const; + // split css properties string, ie '1px solid rgb(100, 100, 100)' split by ' ' returns 3 parts. + void splitParams(const std::string &str, char sep, std::vector &result) const; + // read style attribute void getStyleParams(const std::string &styleString, CStyleParams &style, const CStyleParams ¤t) const; void getStyleParams(const TStyle &styleRules, CStyleParams &style, const CStyleParams ¤t) const; @@ -153,7 +158,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; @@ -162,16 +167,20 @@ 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; + + // 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; 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/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 888044e5c..fe2dab4fd 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