Fixed: CSS inherit rules

--HG--
branch : develop
This commit is contained in:
Nimetu 2019-03-15 15:41:02 +02:00
parent dafd8cf7f7
commit 24767a86df
2 changed files with 37 additions and 38 deletions

View file

@ -796,7 +796,7 @@ namespace NLGUI
static TGroupHtmlByUIDMap _GroupHtmlByUID; static TGroupHtmlByUIDMap _GroupHtmlByUID;
// read style attribute // read style attribute
void getStyleParams(const std::string &styleString, CStyleParams &style, bool inherit = true); void getStyleParams(const std::string &styleString, CStyleParams &style, const CStyleParams &current);
void applyCssMinMax(sint32 &width, sint32 &height, sint32 minw=0, sint32 minh=0, sint32 maxw=0, sint32 maxh=0); void applyCssMinMax(sint32 &width, sint32 &height, sint32 minw=0, sint32 minh=0, sint32 maxw=0, sint32 maxh=0);
// load and render local html file (from bnp for example) // load and render local html file (from bnp for example)

View file

@ -1545,7 +1545,7 @@ namespace NLGUI
{ {
case HTML_HTML: case HTML_HTML:
if (present[MY_HTML_HTML_STYLE] && value[MY_HTML_HTML_STYLE]) if (present[MY_HTML_HTML_STYLE] && value[MY_HTML_HTML_STYLE])
getStyleParams(value[MY_HTML_HTML_STYLE], _StyleDefault); getStyleParams(value[MY_HTML_HTML_STYLE], _StyleDefault, _StyleDefault);
_Style = _StyleDefault; _Style = _StyleDefault;
setBackgroundColor(_Style.BackgroundColor); setBackgroundColor(_Style.BackgroundColor);
@ -1616,7 +1616,7 @@ namespace NLGUI
_Style.Height = -1; _Style.Height = -1;
if (present[HTML_A_STYLE] && value[HTML_A_STYLE]) if (present[HTML_A_STYLE] && value[HTML_A_STYLE])
getStyleParams(value[HTML_A_STYLE], _Style); getStyleParams(value[HTML_A_STYLE], _Style, _StyleParams.back());
_A.push_back(true); _A.push_back(true);
_Link.push_back (""); _Link.push_back ("");
@ -1669,7 +1669,7 @@ namespace NLGUI
style = value[MY_HTML_DIV_STYLE]; style = value[MY_HTML_DIV_STYLE];
if (!style.empty()) if (!style.empty())
getStyleParams(style, _Style); getStyleParams(style, _Style, _StyleParams.back());
// use generic template system // use generic template system
if (_TrustedDomain && !instClass.empty() && instClass == "ryzom-ui-grouptemplate") if (_TrustedDomain && !instClass.empty() && instClass == "ryzom-ui-grouptemplate")
@ -1780,7 +1780,7 @@ namespace NLGUI
style = value[HTML_BODY_STYLE]; style = value[HTML_BODY_STYLE];
if (!style.empty()) if (!style.empty())
getStyleParams(style, _Style); getStyleParams(style, _Style, _StyleParams.back());
CRGBA bgColor = _Style.BackgroundColor; CRGBA bgColor = _Style.BackgroundColor;
if (present[HTML_BODY_BGCOLOR] && value[HTML_BODY_BGCOLOR]) if (present[HTML_BODY_BGCOLOR] && value[HTML_BODY_BGCOLOR])
@ -1841,7 +1841,7 @@ namespace NLGUI
_Style.TextColor = H1Color; _Style.TextColor = H1Color;
_Style.GlobalColor = H1ColorGlobalColor; _Style.GlobalColor = H1ColorGlobalColor;
if (present[MY_HTML_H1_STYLE] && value[MY_HTML_H1_STYLE]) if (present[MY_HTML_H1_STYLE] && value[MY_HTML_H1_STYLE])
getStyleParams(value[MY_HTML_H1_STYLE], _Style); getStyleParams(value[MY_HTML_H1_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_H2: case HTML_H2:
@ -1853,7 +1853,7 @@ namespace NLGUI
_Style.TextColor = H2Color; _Style.TextColor = H2Color;
_Style.GlobalColor = H2ColorGlobalColor; _Style.GlobalColor = H2ColorGlobalColor;
if (present[MY_HTML_H2_STYLE] && value[MY_HTML_H2_STYLE]) if (present[MY_HTML_H2_STYLE] && value[MY_HTML_H2_STYLE])
getStyleParams(value[MY_HTML_H2_STYLE], _Style); getStyleParams(value[MY_HTML_H2_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_H3: case HTML_H3:
@ -1865,7 +1865,7 @@ namespace NLGUI
_Style.TextColor = H3Color; _Style.TextColor = H3Color;
_Style.GlobalColor = H3ColorGlobalColor; _Style.GlobalColor = H3ColorGlobalColor;
if (present[MY_HTML_H3_STYLE] && value[MY_HTML_H3_STYLE]) if (present[MY_HTML_H3_STYLE] && value[MY_HTML_H3_STYLE])
getStyleParams(value[MY_HTML_H3_STYLE], _Style); getStyleParams(value[MY_HTML_H3_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_H4: case HTML_H4:
@ -1877,7 +1877,7 @@ namespace NLGUI
_Style.TextColor = H4Color; _Style.TextColor = H4Color;
_Style.GlobalColor = H4ColorGlobalColor; _Style.GlobalColor = H4ColorGlobalColor;
if (present[MY_HTML_H4_STYLE] && value[MY_HTML_H4_STYLE]) if (present[MY_HTML_H4_STYLE] && value[MY_HTML_H4_STYLE])
getStyleParams(value[MY_HTML_H4_STYLE], _Style); getStyleParams(value[MY_HTML_H4_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_H5: case HTML_H5:
@ -1889,7 +1889,7 @@ namespace NLGUI
_Style.TextColor = H5Color; _Style.TextColor = H5Color;
_Style.GlobalColor = H5ColorGlobalColor; _Style.GlobalColor = H5ColorGlobalColor;
if (present[MY_HTML_H5_STYLE] && value[MY_HTML_H5_STYLE]) if (present[MY_HTML_H5_STYLE] && value[MY_HTML_H5_STYLE])
getStyleParams(value[MY_HTML_H5_STYLE], _Style); getStyleParams(value[MY_HTML_H5_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_H6: case HTML_H6:
@ -1901,7 +1901,7 @@ namespace NLGUI
_Style.TextColor = H6Color; _Style.TextColor = H6Color;
_Style.GlobalColor = H6ColorGlobalColor; _Style.GlobalColor = H6ColorGlobalColor;
if (present[MY_HTML_H6_STYLE] && value[MY_HTML_H6_STYLE]) if (present[MY_HTML_H6_STYLE] && value[MY_HTML_H6_STYLE])
getStyleParams(value[MY_HTML_H6_STYLE], _Style); getStyleParams(value[MY_HTML_H6_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_IMG: case HTML_IMG:
@ -1928,7 +1928,7 @@ namespace NLGUI
// width, height from inline css // width, height from inline css
if (present[MY_HTML_IMG_STYLE] && value[MY_HTML_IMG_STYLE]) if (present[MY_HTML_IMG_STYLE] && value[MY_HTML_IMG_STYLE])
getStyleParams(value[MY_HTML_IMG_STYLE], style); getStyleParams(value[MY_HTML_IMG_STYLE], style, _Style);
// Tooltip // Tooltip
const char *tooltip = NULL; const char *tooltip = NULL;
@ -2032,7 +2032,7 @@ namespace NLGUI
tooltip = value[MY_HTML_INPUT_ALT]; tooltip = value[MY_HTML_INPUT_ALT];
if (present[MY_HTML_INPUT_STYLE] && value[MY_HTML_INPUT_STYLE]) if (present[MY_HTML_INPUT_STYLE] && value[MY_HTML_INPUT_STYLE])
getStyleParams(value[MY_HTML_INPUT_STYLE], _Style); getStyleParams(value[MY_HTML_INPUT_STYLE], _Style, _StyleParams.back());
string type = toLower(value[MY_HTML_INPUT_TYPE]); string type = toLower(value[MY_HTML_INPUT_TYPE]);
if (type == "image") if (type == "image")
@ -2258,7 +2258,6 @@ namespace NLGUI
if (!(_Forms.empty())) if (!(_Forms.empty()))
{ {
CStyleParams style; CStyleParams style;
style.FontSize = _Style.FontSize;
// A select box // A select box
string name; string name;
@ -2272,7 +2271,7 @@ namespace NLGUI
if (present[HTML_SELECT_MULTIPLE] && value[HTML_SELECT_MULTIPLE]) if (present[HTML_SELECT_MULTIPLE] && value[HTML_SELECT_MULTIPLE])
multiple = true; multiple = true;
if (present[HTML_SELECT_STYLE] && value[HTML_SELECT_STYLE]) if (present[HTML_SELECT_STYLE] && value[HTML_SELECT_STYLE])
getStyleParams(value[HTML_SELECT_STYLE], style); getStyleParams(value[HTML_SELECT_STYLE], style, _Style);
CGroupHTML::CForm::CEntry entry; CGroupHTML::CForm::CEntry entry;
entry.Name = name; entry.Name = name;
@ -2356,7 +2355,7 @@ namespace NLGUI
pushStyle(); pushStyle();
if (present[HTML_LI_STYLE] && value[HTML_LI_STYLE]) if (present[HTML_LI_STYLE] && value[HTML_LI_STYLE])
getStyleParams(value[HTML_LI_STYLE], _Style); getStyleParams(value[HTML_LI_STYLE], _Style, _StyleParams.back());
ucstring str; ucstring str;
str.fromUtf8(_UL.back().getListMarkerText()); str.fromUtf8(_UL.back().getListMarkerText());
@ -2379,7 +2378,7 @@ namespace NLGUI
newParagraph(PBeginSpace); newParagraph(PBeginSpace);
pushStyle(); pushStyle();
if (present[MY_HTML_P_STYLE] && value[MY_HTML_P_STYLE]) if (present[MY_HTML_P_STYLE] && value[MY_HTML_P_STYLE])
getStyleParams(value[MY_HTML_P_STYLE], _Style); getStyleParams(value[MY_HTML_P_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_PRE: case HTML_PRE:
@ -2388,7 +2387,7 @@ namespace NLGUI
_Style.FontFamily = "monospace"; _Style.FontFamily = "monospace";
if (present[HTML_PRE_STYLE] && value[HTML_PRE_STYLE]) if (present[HTML_PRE_STYLE] && value[HTML_PRE_STYLE])
getStyleParams(value[HTML_PRE_STYLE], _Style); getStyleParams(value[HTML_PRE_STYLE], _Style, _StyleParams.back());
_PRE.push_back(true); _PRE.push_back(true);
@ -2416,7 +2415,7 @@ namespace NLGUI
if (present[MY_HTML_TABLE_CELLPADDING] && value[MY_HTML_TABLE_CELLPADDING]) if (present[MY_HTML_TABLE_CELLPADDING] && value[MY_HTML_TABLE_CELLPADDING])
fromString(value[MY_HTML_TABLE_CELLPADDING], table->CellPadding); fromString(value[MY_HTML_TABLE_CELLPADDING], table->CellPadding);
if (present[MY_HTML_TABLE_STYLE] && value[MY_HTML_TABLE_STYLE]) if (present[MY_HTML_TABLE_STYLE] && value[MY_HTML_TABLE_STYLE])
getStyleParams(value[MY_HTML_TABLE_STYLE], _Style); getStyleParams(value[MY_HTML_TABLE_STYLE], _Style, _StyleParams.back());
table->setMarginLeft(getIndent()); table->setMarginLeft(getIndent());
addHtmlGroup (table, 0); addHtmlGroup (table, 0);
@ -2446,7 +2445,7 @@ namespace NLGUI
} }
if (present[MY_HTML_TD_STYLE] && value[MY_HTML_TD_STYLE]) if (present[MY_HTML_TD_STYLE] && value[MY_HTML_TD_STYLE])
getStyleParams(value[MY_HTML_TD_STYLE], _Style); getStyleParams(value[MY_HTML_TD_STYLE], _Style, _StyleParams.back());
CGroupTable *table = getTable(); CGroupTable *table = getTable();
if (table) if (table)
@ -2541,7 +2540,7 @@ namespace NLGUI
_Style.BackgroundColor.A = 0; _Style.BackgroundColor.A = 0;
if (present[MY_HTML_TEXTAREA_STYLE] && value[MY_HTML_TEXTAREA_STYLE]) if (present[MY_HTML_TEXTAREA_STYLE] && value[MY_HTML_TEXTAREA_STYLE])
getStyleParams(value[MY_HTML_TEXTAREA_STYLE], _Style); getStyleParams(value[MY_HTML_TEXTAREA_STYLE], _Style, _StyleParams.back());
// Got one form ? // Got one form ?
if (!(_Forms.empty())) if (!(_Forms.empty()))
@ -2597,7 +2596,7 @@ namespace NLGUI
pushStyle(); pushStyle();
if (present[MY_HTML_TR_STYLE] && value[MY_HTML_TR_STYLE]) if (present[MY_HTML_TR_STYLE] && value[MY_HTML_TR_STYLE])
getStyleParams(value[MY_HTML_TR_STYLE], _Style); getStyleParams(value[MY_HTML_TR_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_UL: case HTML_UL:
@ -2614,7 +2613,7 @@ namespace NLGUI
pushStyle(); pushStyle();
if (present[HTML_UL_STYLE] && value[HTML_UL_STYLE]) if (present[HTML_UL_STYLE] && value[HTML_UL_STYLE])
getStyleParams(value[HTML_UL_STYLE], _Style); getStyleParams(value[HTML_UL_STYLE], _Style, _StyleParams.back());
break; break;
case HTML_OBJECT: case HTML_OBJECT:
_ObjectType.clear(); _ObjectType.clear();
@ -2637,7 +2636,7 @@ namespace NLGUI
pushStyle(); pushStyle();
if (present[MY_HTML_SPAN_STYLE] && value[MY_HTML_SPAN_STYLE]) if (present[MY_HTML_SPAN_STYLE] && value[MY_HTML_SPAN_STYLE])
getStyleParams(value[MY_HTML_SPAN_STYLE], _Style); getStyleParams(value[MY_HTML_SPAN_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_DEL: case HTML_DEL:
@ -2681,7 +2680,7 @@ namespace NLGUI
endParagraph(); endParagraph();
pushStyle(); pushStyle();
if (present[HTML_GEN_STYLE] && value[HTML_GEN_STYLE]) if (present[HTML_GEN_STYLE] && value[HTML_GEN_STYLE])
getStyleParams(value[HTML_GEN_STYLE], _Style); getStyleParams(value[HTML_GEN_STYLE], _Style, _StyleParams.back());
} }
break; break;
case HTML_DT: case HTML_DT:
@ -2704,7 +2703,7 @@ namespace NLGUI
pushStyle(); pushStyle();
_Style.FontWeight = FONT_WEIGHT_BOLD; _Style.FontWeight = FONT_WEIGHT_BOLD;
if (present[HTML_GEN_STYLE] && value[HTML_GEN_STYLE]) if (present[HTML_GEN_STYLE] && value[HTML_GEN_STYLE])
getStyleParams(value[HTML_GEN_STYLE], _Style); getStyleParams(value[HTML_GEN_STYLE], _Style, _StyleParams.back());
if (!_LI) if (!_LI)
{ {
@ -2739,7 +2738,7 @@ namespace NLGUI
pushStyle(); pushStyle();
if (present[HTML_GEN_STYLE] && value[HTML_GEN_STYLE]) if (present[HTML_GEN_STYLE] && value[HTML_GEN_STYLE])
getStyleParams(value[HTML_GEN_STYLE], _Style); getStyleParams(value[HTML_GEN_STYLE], _Style, _StyleParams.back());
if (!_LI) if (!_LI)
{ {
@ -2763,7 +2762,7 @@ namespace NLGUI
if (present[HTML_OL_TYPE] && value[HTML_OL_TYPE]) if (present[HTML_OL_TYPE] && value[HTML_OL_TYPE])
type = value[HTML_OL_TYPE]; type = value[HTML_OL_TYPE];
if (present[HTML_OL_STYLE] && value[HTML_OL_STYLE]) if (present[HTML_OL_STYLE] && value[HTML_OL_STYLE])
getStyleParams(value[HTML_OL_STYLE], _Style); getStyleParams(value[HTML_OL_STYLE], _Style, _StyleParams.back());
_UL.push_back(HTMLOListElement(start, type)); _UL.push_back(HTMLOListElement(start, type));
// if LI is already present // if LI is already present
@ -2786,7 +2785,7 @@ namespace NLGUI
style.Width = 0; style.Width = 0;
if (present[HTML_HR_STYLE] && value[HTML_HR_STYLE]) if (present[HTML_HR_STYLE] && value[HTML_HR_STYLE])
getStyleParams(value[HTML_HR_STYLE], style); getStyleParams(value[HTML_HR_STYLE], style, _Style);
CViewBitmap *bitmap = dynamic_cast<CViewBitmap*>(sep->getView("hr")); CViewBitmap *bitmap = dynamic_cast<CViewBitmap*>(sep->getView("hr"));
if (bitmap) if (bitmap)
@ -6364,16 +6363,8 @@ namespace NLGUI
// style.TextColor; // color: #ABCDEF; // style.TextColor; // color: #ABCDEF;
// style.Underlined; // text-decoration: underline; text-decoration-line: underline; // style.Underlined; // text-decoration: underline; text-decoration-line: underline;
// style.StrikeThrough; // text-decoration: line-through; text-decoration-line: line-through; // style.StrikeThrough; // text-decoration: line-through; text-decoration-line: line-through;
void CGroupHTML::getStyleParams(const std::string &styleString, CStyleParams &style, bool inherit) void CGroupHTML::getStyleParams(const std::string &styleString, CStyleParams &style, const CStyleParams &current)
{ {
const CStyleParams current = _Style;
if (inherit)
{
style.Underlined = current.Underlined;
style.StrikeThrough = current.StrikeThrough;
}
float tmpf; float tmpf;
TStyle styles = parseStyle(styleString); TStyle styles = parseStyle(styleString);
TStyle::iterator it; TStyle::iterator it;
@ -6698,6 +6689,14 @@ namespace NLGUI
scanHTMLColor(it->second.c_str(), style.BackgroundColorOver); scanHTMLColor(it->second.c_str(), style.BackgroundColorOver);
} }
} }
// if outer element has underline set, then inner element cannot remove it
if (current.Underlined)
style.Underlined = current.Underlined;
// if outer element has line-through set, then inner element cannot remove it
if (current.StrikeThrough)
style.StrikeThrough = current.StrikeThrough;
} }
// *************************************************************************** // ***************************************************************************