Changed: Merge UL and OL code

This commit is contained in:
Nimetu 2016-01-05 20:21:40 +02:00
parent eedcd2f265
commit 0fb9e8323a
2 changed files with 32 additions and 54 deletions

View file

@ -438,15 +438,6 @@ namespace NLGUI
return _PRE.back(); return _PRE.back();
} }
// UL mode
std::vector<bool> _UL;
inline bool getUL() const
{
if (_UL.empty())
return false;
return _UL.back();
}
// DL list // DL list
std::vector<bool> _DL; std::vector<bool> _DL;
inline bool getDL() const inline bool getDL() const
@ -456,7 +447,7 @@ namespace NLGUI
return _DL.back(); return _DL.back();
} }
// OL // OL and UL
class HTMLOListElement { class HTMLOListElement {
public: public:
HTMLOListElement(int start, std::string type) HTMLOListElement(int start, std::string type)
@ -469,7 +460,7 @@ namespace NLGUI
std::string Type; std::string Type;
bool First; bool First;
}; };
std::vector<HTMLOListElement> _OL; std::vector<HTMLOListElement> _UL;
// A mode // A mode
std::vector<bool> _A; std::vector<bool> _A;

View file

@ -1709,9 +1709,9 @@ namespace NLGUI
_SelectOption = true; _SelectOption = true;
break; break;
case HTML_LI: case HTML_LI:
if (getUL()) if (!_UL.empty())
{ {
// First LI ? // UL, OL top margin if this is the first LI
if (!_LI) if (!_LI)
{ {
_LI = true; _LI = true;
@ -1721,35 +1721,18 @@ namespace NLGUI
{ {
newParagraph(LIBeginSpace); newParagraph(LIBeginSpace);
} }
ucstring str;
str += (ucchar)0x2219;
str += (ucchar)' ';
addString (str);
flushString ();
getParagraph()->setFirstViewIndent(LIIndent);
}
else if (!_OL.empty())
{
if (_OL.back().First)
{
_OL.back().First = false;
newParagraph(ULBeginSpace);
}
else
{
newParagraph(LIBeginSpace);
}
// OL list index can be overridden by <li value="1"> attribute // OL list index can be overridden by <li value="1"> attribute
if (present[HTML_LI_VALUE] && value[HTML_LI_VALUE]) if (present[HTML_LI_VALUE] && value[HTML_LI_VALUE])
fromString(value[HTML_LI_VALUE], _OL.back().Value); fromString(value[HTML_LI_VALUE], _UL.back().Value);
ucstring str; ucstring str;
str.fromUtf8(_OL.back().getListMarkerText() + ". "); str.fromUtf8(_UL.back().getListMarkerText());
addString (str); addString (str);
flushString (); flushString ();
getParagraph()->setFirstViewIndent(LIIndent); getParagraph()->setFirstViewIndent(LIIndent);
_OL.back().Value++;
_UL.back().Value++;
} }
break; break;
case HTML_P: case HTML_P:
@ -1934,10 +1917,11 @@ namespace NLGUI
} }
break; break;
case HTML_UL: case HTML_UL:
_UL.push_back(HTMLOListElement(1, "disc"));
// if LI is already present
_LI = _UL.size() > 1;
_Indent += ULIndent; _Indent += ULIndent;
_LI = false;
endParagraph(); endParagraph();
_UL.push_back(true);
break; break;
case HTML_OBJECT: case HTML_OBJECT:
_ObjectType = ""; _ObjectType = "";
@ -2044,7 +2028,9 @@ 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];
_OL.push_back(HTMLOListElement(start, type)); _UL.push_back(HTMLOListElement(start, type));
// if LI is already present
_LI = _UL.size() > 1;
_Indent += ULIndent; _Indent += ULIndent;
endParagraph(); endParagraph();
} }
@ -2218,19 +2204,14 @@ namespace NLGUI
} }
break; break;
case HTML_OL: case HTML_OL:
if (!_OL.empty())
{
_Indent -= ULIndent;
_Indent = std::max(_Indent, (uint)0);
endParagraph();
popIfNotEmpty(_OL);
}
break;
case HTML_UL: case HTML_UL:
if (getUL()) if (!_UL.empty())
{ {
_Indent -= ULIndent; if (_Indent > ULIndent)
_Indent = std::max(_Indent, (uint)0); _Indent = _Indent - ULIndent;
else
_Indent = 0;
endParagraph(); endParagraph();
popIfNotEmpty(_UL); popIfNotEmpty(_UL);
} }
@ -4050,7 +4031,6 @@ namespace NLGUI
_DT = false; _DT = false;
_UL.clear(); _UL.clear();
_DL.clear(); _DL.clear();
_OL.clear();
_A.clear(); _A.clear();
_Link.clear(); _Link.clear();
_LinkTitle.clear(); _LinkTitle.clear();
@ -5527,7 +5507,12 @@ namespace NLGUI
sint32 number = Value; sint32 number = Value;
bool upper = false; bool upper = false;
if (Type == "a" || Type == "A") if (Type == "disc")
{
// (ucchar)0x2219;
ret = "\xe2\x88\x99 ";
}
else if (Type == "a" || Type == "A")
{ {
// @see toAlphabeticOrNumeric in WebKit // @see toAlphabeticOrNumeric in WebKit
static const char lower[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', static const char lower[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
@ -5549,6 +5534,7 @@ namespace NLGUI
number /= size; number /= size;
} }
} }
ret += ". ";
} }
else if (Type == "i" || Type == "I") else if (Type == "i" || Type == "I")
{ {
@ -5592,10 +5578,11 @@ namespace NLGUI
ret = toUpper(ret); ret = toUpper(ret);
} }
} }
ret += ". ";
} }
else else
{ {
ret = toString(Value); ret = toString(Value) + ". ";
} }
return ret; return ret;