Changed: Parse html style attribute

--HG--
branch : develop
This commit is contained in:
Nimetu 2019-03-12 20:02:43 +02:00
parent 78c39850ae
commit d62c139ee0
4 changed files with 68 additions and 16 deletions

View file

@ -105,6 +105,7 @@ namespace NLGUI
Height=-1; Height=-1;
MaxWidth=-1; MaxWidth=-1;
MaxHeight=-1; MaxHeight=-1;
BackgroundColor=NLMISC::CRGBA::Black;
} }
uint FontSize; uint FontSize;
uint FontWeight; uint FontWeight;
@ -119,6 +120,7 @@ namespace NLGUI
sint32 Height; sint32 Height;
sint32 MaxWidth; sint32 MaxWidth;
sint32 MaxHeight; sint32 MaxHeight;
NLMISC::CRGBA BackgroundColor;
}; };
// ImageDownload system // ImageDownload system
@ -345,6 +347,9 @@ namespace NLGUI
// Get Home URL // Get Home URL
virtual std::string home(); virtual std::string home();
// Clear style stack and restore default style
void resetCssStyle();
// Parse style html tag // Parse style html tag
TStyle parseStyle(const std::string &str_styles); TStyle parseStyle(const std::string &str_styles);

View file

@ -49,6 +49,14 @@ namespace NLGUI
#undef HTML_ATTR #undef HTML_ATTR
#define HTML_ATTR(t,a) MY_HTML_##t##_##a #define HTML_ATTR(t,a) MY_HTML_##t##_##a
enum
{
HTML_ATTR(HTML,DIR) = 0,
HTML_ATTR(HTML,LANG),
HTML_ATTR(HTML,VERSION),
HTML_ATTR(HTML,STYLE),
};
enum enum
{ {
HTML_ATTR(A,ACCESSKEY) = 0, HTML_ATTR(A,ACCESSKEY) = 0,

View file

@ -1489,6 +1489,13 @@ namespace NLGUI
// Paragraph ? // Paragraph ?
switch(element_number) switch(element_number)
{ {
case HTML_HTML:
if (present[MY_HTML_HTML_STYLE] && value[MY_HTML_HTML_STYLE])
getStyleParams(value[MY_HTML_HTML_STYLE], _StyleDefault);
_Style = _StyleDefault;
setBackgroundColor(_Style.BackgroundColor);
break;
case HTML_HEAD: case HTML_HEAD:
_ReadingHeadTag = !_IgnoreHeadTag; _ReadingHeadTag = !_IgnoreHeadTag;
_IgnoreHeadTag = true; _IgnoreHeadTag = true;
@ -1708,17 +1715,21 @@ namespace NLGUI
break; break;
case HTML_BODY: case HTML_BODY:
{ {
if (present[HTML_BODY_BGCOLOR] && value[HTML_BODY_BGCOLOR]) pushStyle();
{
CRGBA bgColor;
if (scanHTMLColor(value[HTML_BODY_BGCOLOR], bgColor))
setBackgroundColor (bgColor);
}
string style; string style;
if (present[HTML_BODY_STYLE] && value[HTML_BODY_STYLE]) if (present[HTML_BODY_STYLE] && value[HTML_BODY_STYLE])
style = value[HTML_BODY_STYLE]; style = value[HTML_BODY_STYLE];
if (!style.empty())
getStyleParams(style, _Style);
CRGBA bgColor = _Style.BackgroundColor;
if (present[HTML_BODY_BGCOLOR] && value[HTML_BODY_BGCOLOR])
scanHTMLColor(value[HTML_BODY_BGCOLOR], bgColor);
if (bgColor != _Style.BackgroundColor)
setBackgroundColor(bgColor);
if (!style.empty()) if (!style.empty())
{ {
@ -1743,10 +1754,6 @@ namespace NLGUI
image = image.substr(4, image.size()-5); image = image.substr(4, image.size()-5);
setBackground (image, scale, repeat); setBackground (image, scale, repeat);
} }
// set default text style from <body>
getStyleParams(style, _StyleDefault);
_Style = _StyleDefault;
} }
} }
break; break;
@ -2737,6 +2744,9 @@ namespace NLGUI
case HTML_HEAD: case HTML_HEAD:
_ReadingHeadTag = false; _ReadingHeadTag = false;
break; break;
case HTML_BODY:
popStyle();
break;
case HTML_FONT: case HTML_FONT:
popStyle(); popStyle();
break; break;
@ -4915,9 +4925,7 @@ namespace NLGUI
_IgnoreBaseUrlTag = false; _IgnoreBaseUrlTag = false;
// reset style // reset style
_StyleDefault = CStyleParams(); resetCssStyle();
_Style = _StyleDefault;
_StyleParams.clear();
// TR // TR
@ -6252,6 +6260,18 @@ namespace NLGUI
return uri.toString(); return uri.toString();
} }
// ***************************************************************************
void CGroupHTML::resetCssStyle()
{
_StyleDefault = CStyleParams();
_StyleDefault.TextColor = TextColor;
_StyleDefault.FontSize = TextFontSize;
_StyleDefault.BackgroundColor = BgColor;
_Style = _StyleDefault;
_StyleParams.clear();
}
// *************************************************************************** // ***************************************************************************
// CGroupHTML::CStyleParams style; // CGroupHTML::CStyleParams style;
// style.FontSize; // font-size: 10px; // style.FontSize; // font-size: 10px;
@ -6485,6 +6505,14 @@ namespace NLGUI
if (fromString(it->second, b)) if (fromString(it->second, b))
style.GlobalColor = b; style.GlobalColor = b;
} }
else
if (it->first == "background-color")
{
if (it->second == "inherit")
style.BackgroundColor = current.backgroundColor;
else
scanHTMLColor(it->second.c_str(), style.BackgroundColor);
}
} }
} }

View file

@ -47,6 +47,15 @@ namespace NLGUI
#undef HTML_ATTR #undef HTML_ATTR
#define HTML_ATTR(a,b) { (char*) #b } #define HTML_ATTR(a,b) { (char*) #b }
HTAttr html_attr[] =
{
HTML_ATTR(HTML,DIR),
HTML_ATTR(HTML,LANG),
HTML_ATTR(HTML,VERSION),
HTML_ATTR(HTML,STYLE),
{ 0 }
};
HTAttr a_attr[] = HTAttr a_attr[] =
{ {
HTML_ATTR(A,ACCESSKEY), HTML_ATTR(A,ACCESSKEY),
@ -469,6 +478,8 @@ namespace NLGUI
// Change the HTML DTD // Change the HTML DTD
SGML_dtd *HTML_DTD = HTML_dtd (); SGML_dtd *HTML_DTD = HTML_dtd ();
HTML_DTD->tags[HTML_HTML].attributes = html_attr;
HTML_DTD->tags[HTML_HTML].number_of_attributes = sizeof(html_attr) / sizeof(HTAttr) - 1;
HTML_DTD->tags[HTML_TABLE].attributes = table_attr; HTML_DTD->tags[HTML_TABLE].attributes = table_attr;
HTML_DTD->tags[HTML_TABLE].number_of_attributes = sizeof(table_attr) / sizeof(HTAttr) - 1; HTML_DTD->tags[HTML_TABLE].number_of_attributes = sizeof(table_attr) / sizeof(HTAttr) - 1;
HTML_DTD->tags[HTML_TR].attributes = tr_attr; HTML_DTD->tags[HTML_TR].attributes = tr_attr;