Changed: use css display: block instead hardcoded endParagraph()

--HG--
branch : develop
This commit is contained in:
Nimetu 2019-05-10 23:50:14 +03:00
parent 0676cd0d2b
commit d0616ac579
4 changed files with 25 additions and 39 deletions

View file

@ -57,6 +57,7 @@ namespace NLGUI
Underlined=false; Underlined=false;
StrikeThrough=false; StrikeThrough=false;
GlobalColor=false; GlobalColor=false;
DisplayBlock=false;
Width=-1; Width=-1;
Height=-1; Height=-1;
MaxWidth=-1; MaxWidth=-1;
@ -87,6 +88,7 @@ namespace NLGUI
bool GlobalColor; bool GlobalColor;
bool Underlined; bool Underlined;
bool StrikeThrough; bool StrikeThrough;
bool DisplayBlock;
sint32 Width; sint32 Width;
sint32 Height; sint32 Height;
sint32 MaxWidth; sint32 MaxWidth;
@ -172,6 +174,7 @@ namespace NLGUI
styleStackIndex++; styleStackIndex++;
_StyleStack.push_back(Current); _StyleStack.push_back(Current);
Current.DisplayBlock = false;
Current.Width=-1; Current.Width=-1;
Current.Height=-1; Current.Height=-1;
Current.MaxWidth=-1; Current.MaxWidth=-1;

View file

@ -569,14 +569,6 @@ namespace NLGUI
return _LinkClass.back().c_str(); return _LinkClass.back().c_str();
} }
std::vector<bool> _BlockLevelElement;
inline bool isBlockLevelElement() const
{
if (_BlockLevelElement.empty())
return false;
return _BlockLevelElement.back();
}
// Divs (i.e. interface group) // Divs (i.e. interface group)
std::vector<class CInterfaceGroup*> _Divs; std::vector<class CInterfaceGroup*> _Divs;
inline CInterfaceGroup *getDiv() const inline CInterfaceGroup *getDiv() const

View file

@ -456,6 +456,14 @@ namespace NLGUI
if (pos != style.StyleRules.end()) if (pos != style.StyleRules.end())
style.StyleRules.erase(pos); style.StyleRules.erase(pos);
} }
else
if (it->first == "display")
{
if (it->second == "inherit")
style.DisplayBlock = current.DisplayBlock;
else
style.DisplayBlock = (it->second == "block" || it->second == "table");
}
} }
} }

View file

@ -1072,6 +1072,11 @@ namespace NLGUI
_AnchorName.push_back(elm.getAttribute("id")); _AnchorName.push_back(elm.getAttribute("id"));
} }
if (_Style.Current.DisplayBlock)
{
endParagraph();
}
switch(elm.ID) switch(elm.ID)
{ {
case HTML_A: htmlA(elm); break; case HTML_A: htmlA(elm); break;
@ -1189,6 +1194,10 @@ namespace NLGUI
break; break;
} }
if (_Style.Current.DisplayBlock)
{
endParagraph();
}
_Style.popStyle(); _Style.popStyle();
} }
@ -4881,6 +4890,11 @@ namespace NLGUI
css += "small { font-size: smaller;}"; css += "small { font-size: smaller;}";
css += "dt { font-weight: bold; }"; css += "dt { font-weight: bold; }";
css += "hr { color: rgb(120, 120, 120);}"; css += "hr { color: rgb(120, 120, 120);}";
// block level elements
css += "address, article, aside, blockquote, details, dialog, dd, div, dl, dt, fieldset, figcaption, figure,";
css += "footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, li, main, nav, ol, p, pre, section, table,";
css += "ul { display: block; }";
css += "table { display: table; }";
// td { padding: 1px;} - overwrites cellpadding attribute // td { padding: 1px;} - overwrites cellpadding attribute
// table { border-spacing: 2px;} - overwrites cellspacing attribute // table { border-spacing: 2px;} - overwrites cellspacing attribute
css += "table { border-collapse: separate;}"; css += "table { border-collapse: separate;}";
@ -5515,8 +5529,6 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::htmlDIV(const CHtmlElement &elm) void CGroupHTML::htmlDIV(const CHtmlElement &elm)
{ {
_BlockLevelElement.push_back(true);
_DivName = elm.getAttribute("name"); _DivName = elm.getAttribute("name");
string instClass = elm.getAttribute("class"); string instClass = elm.getAttribute("class");
@ -5539,8 +5551,6 @@ namespace NLGUI
{ {
if ((*it).first == "template") if ((*it).first == "template")
templateName = (*it).second; templateName = (*it).second;
else if ((*it).first == "display" && (*it).second == "inline-block")
_BlockLevelElement.back() = false;
else else
tmplParams.push_back(TTmplParam((*it).first, (*it).second)); tmplParams.push_back(TTmplParam((*it).first, (*it).second));
} }
@ -5573,8 +5583,6 @@ namespace NLGUI
inst->setPosRef(Hotspot_TL); inst->setPosRef(Hotspot_TL);
inst->setParentPosRef(Hotspot_TL); inst->setParentPosRef(Hotspot_TL);
getDiv()->addGroup(inst); getDiv()->addGroup(inst);
_BlockLevelElement.back() = false;
} }
else else
{ {
@ -5586,25 +5594,14 @@ namespace NLGUI
} }
} }
if (isBlockLevelElement())
{
newParagraph(0);
}
renderPseudoElement(":before", elm); renderPseudoElement(":before", elm);
} }
void CGroupHTML::htmlDIVend(const CHtmlElement &elm) void CGroupHTML::htmlDIVend(const CHtmlElement &elm)
{ {
renderPseudoElement(":after", elm); renderPseudoElement(":after", elm);
if (isBlockLevelElement())
{
endParagraph();
}
_DivName.clear(); _DivName.clear();
popIfNotEmpty(_Divs); popIfNotEmpty(_Divs);
popIfNotEmpty(_BlockLevelElement);
} }
// *************************************************************************** // ***************************************************************************
@ -5612,7 +5609,6 @@ namespace NLGUI
{ {
_DL.push_back(HTMLDListElement()); _DL.push_back(HTMLDListElement());
_LI = _DL.size() > 1 || !_UL.empty(); _LI = _DL.size() > 1 || !_UL.empty();
endParagraph();
renderPseudoElement(":before", elm); renderPseudoElement(":before", elm);
} }
@ -5624,8 +5620,6 @@ namespace NLGUI
renderPseudoElement(":after", elm); renderPseudoElement(":after", elm);
endParagraph();
// unclosed DT // unclosed DT
if (_DL.back().DT) if (_DL.back().DT)
{ {
@ -5746,7 +5740,6 @@ namespace NLGUI
void CGroupHTML::htmlHend(const CHtmlElement &elm) void CGroupHTML::htmlHend(const CHtmlElement &elm)
{ {
renderPseudoElement(":after", elm); renderPseudoElement(":after", elm);
endParagraph();
} }
// *************************************************************************** // ***************************************************************************
@ -5764,8 +5757,6 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::htmlHR(const CHtmlElement &elm) void CGroupHTML::htmlHR(const CHtmlElement &elm)
{ {
endParagraph();
CInterfaceGroup *sep = CWidgetManager::getInstance()->getParser()->createGroupInstance("html_hr", "", NULL, 0); CInterfaceGroup *sep = CWidgetManager::getInstance()->getParser()->createGroupInstance("html_hr", "", NULL, 0);
if (sep) if (sep)
{ {
@ -5789,8 +5780,6 @@ namespace NLGUI
renderPseudoElement(":before", elm); renderPseudoElement(":before", elm);
addHtmlGroup(sep, 0); addHtmlGroup(sep, 0);
renderPseudoElement(":after", elm); renderPseudoElement(":after", elm);
endParagraph();
} }
} }
@ -6238,7 +6227,6 @@ namespace NLGUI
// if LI is already present // if LI is already present
_LI = _UL.size() > 1 || _DL.size() > 1; _LI = _UL.size() > 1 || _DL.size() > 1;
_Indent.push_back(getIndent() + ULIndent); _Indent.push_back(getIndent() + ULIndent);
endParagraph();
renderPseudoElement(":before", elm); renderPseudoElement(":before", elm);
} }
@ -6348,7 +6336,6 @@ namespace NLGUI
void CGroupHTML::htmlPend(const CHtmlElement &elm) void CGroupHTML::htmlPend(const CHtmlElement &elm)
{ {
renderPseudoElement(":after", elm); renderPseudoElement(":after", elm);
endParagraph();
} }
// *************************************************************************** // ***************************************************************************
@ -6364,7 +6351,6 @@ namespace NLGUI
{ {
renderPseudoElement(":after", elm); renderPseudoElement(":after", elm);
endParagraph();
popIfNotEmpty(_PRE); popIfNotEmpty(_PRE);
} }
@ -6581,7 +6567,6 @@ namespace NLGUI
popIfNotEmpty(_Indent); popIfNotEmpty(_Indent);
renderPseudoElement(":after", elm); renderPseudoElement(":after", elm);
endParagraph();
} }
// *************************************************************************** // ***************************************************************************
@ -6799,7 +6784,6 @@ namespace NLGUI
// if LI is already present // if LI is already present
_LI = _UL.size() > 1 || _DL.size() > 1; _LI = _UL.size() > 1 || _DL.size() > 1;
_Indent.push_back(getIndent() + ULIndent); _Indent.push_back(getIndent() + ULIndent);
endParagraph();
renderPseudoElement(":before", elm); renderPseudoElement(":before", elm);
} }
@ -6811,7 +6795,6 @@ namespace NLGUI
renderPseudoElement(":after", elm); renderPseudoElement(":after", elm);
endParagraph();
popIfNotEmpty(_UL); popIfNotEmpty(_UL);
popIfNotEmpty(_Indent); popIfNotEmpty(_Indent);
} }