From 298a659c6f28cf2ba6784baf02b6fa1866b1f756 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 5 Jan 2016 20:21:40 +0200 Subject: [PATCH 1/6] Changed: Merge UL and OL code --HG-- branch : develop --- code/nel/include/nel/gui/group_html.h | 13 +---- code/nel/src/gui/group_html.cpp | 73 +++++++++++---------------- 2 files changed, 32 insertions(+), 54 deletions(-) diff --git a/code/nel/include/nel/gui/group_html.h b/code/nel/include/nel/gui/group_html.h index 314e07548..e7e6b8dcd 100644 --- a/code/nel/include/nel/gui/group_html.h +++ b/code/nel/include/nel/gui/group_html.h @@ -438,15 +438,6 @@ namespace NLGUI return _PRE.back(); } - // UL mode - std::vector _UL; - inline bool getUL() const - { - if (_UL.empty()) - return false; - return _UL.back(); - } - // DL list std::vector _DL; inline bool getDL() const @@ -456,7 +447,7 @@ namespace NLGUI return _DL.back(); } - // OL + // OL and UL class HTMLOListElement { public: HTMLOListElement(int start, std::string type) @@ -469,7 +460,7 @@ namespace NLGUI std::string Type; bool First; }; - std::vector _OL; + std::vector _UL; // A mode std::vector _A; diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 1693cb08a..da5e89bc7 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -1709,9 +1709,9 @@ namespace NLGUI _SelectOption = true; break; case HTML_LI: - if (getUL()) + if (!_UL.empty()) { - // First LI ? + // UL, OL top margin if this is the first LI if (!_LI) { _LI = true; @@ -1721,35 +1721,18 @@ namespace NLGUI { 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
  • attribute 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; - str.fromUtf8(_OL.back().getListMarkerText() + ". "); - addString(str); - flushString(); + str.fromUtf8(_UL.back().getListMarkerText()); + addString (str); + flushString (); getParagraph()->setFirstViewIndent(LIIndent); - _OL.back().Value++; + + _UL.back().Value++; } break; case HTML_P: @@ -1934,10 +1917,11 @@ namespace NLGUI } break; case HTML_UL: + _UL.push_back(HTMLOListElement(1, "disc")); + // if LI is already present + _LI = _UL.size() > 1; _Indent += ULIndent; - _LI = false; endParagraph(); - _UL.push_back(true); break; case HTML_OBJECT: _ObjectType = ""; @@ -2044,7 +2028,9 @@ namespace NLGUI if (present[HTML_OL_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; endParagraph(); } @@ -2218,21 +2204,16 @@ namespace NLGUI } break; case HTML_OL: - if (!_OL.empty()) - { - _Indent -= ULIndent; - _Indent = std::max(_Indent, (uint)0); - endParagraph(); - popIfNotEmpty(_OL); - } - break; case HTML_UL: - if (getUL()) + if (!_UL.empty()) { - _Indent -= ULIndent; - _Indent = std::max(_Indent, (uint)0); + if (_Indent > ULIndent) + _Indent = _Indent - ULIndent; + else + _Indent = 0; + endParagraph(); - popIfNotEmpty (_UL); + popIfNotEmpty(_UL); } break; case HTML_DL: @@ -4050,7 +4031,6 @@ namespace NLGUI _DT = false; _UL.clear(); _DL.clear(); - _OL.clear(); _A.clear(); _Link.clear(); _LinkTitle.clear(); @@ -5527,7 +5507,12 @@ namespace NLGUI sint32 number = Value; 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 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; } } + ret += ". "; } else if (Type == "i" || Type == "I") { @@ -5592,10 +5578,11 @@ namespace NLGUI ret = toUpper(ret); } } + ret += ". "; } else { - ret = toString(Value); + ret = toString(Value) + ". "; } return ret; From bbe9ca2b676a6d519d5c85541dae944be0ca1cd8 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 5 Jan 2016 20:23:11 +0200 Subject: [PATCH 2/6] Changed: UL list style type depending on nested depth --HG-- branch : develop --- code/nel/src/gui/group_html.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index da5e89bc7..d80a59266 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -1917,7 +1917,12 @@ namespace NLGUI } break; case HTML_UL: - _UL.push_back(HTMLOListElement(1, "disc")); + if (_UL.empty()) + _UL.push_back(HTMLOListElement(1, "disc")); + else if (_UL.size() == 1) + _UL.push_back(HTMLOListElement(1, "circle")); + else + _UL.push_back(HTMLOListElement(1, "square")); // if LI is already present _LI = _UL.size() > 1; _Indent += ULIndent; @@ -5512,6 +5517,16 @@ namespace NLGUI // (ucchar)0x2219; ret = "\xe2\x88\x99 "; } + else if (Type == "circle") + { + // (uchar)0x26AA; + ret = "\xe2\x9a\xaa "; + } + else if (Type == "square") + { + // (ucchar)0x25AA; + ret = "\xe2\x96\xaa "; + } else if (Type == "a" || Type == "A") { // @see toAlphabeticOrNumeric in WebKit From f95d4458399aba2b422cb63f7b2678a6befac951 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 5 Jan 2016 23:02:21 +0200 Subject: [PATCH 3/6] Fixed: DL list DD element indent --HG-- branch : develop --- code/nel/src/gui/group_html.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index d80a59266..1e802d9f2 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -1999,19 +1999,11 @@ namespace NLGUI _DT = true; _FontWeight.push_back(FONT_WEIGHT_BOLD); } - - if (_DL.size() > 1) - { - uint indent = (_DL.size()-1) * ULIndent; - getParagraph()->setFirstViewIndent(indent); - } } break; case HTML_DD: if (getDL()) { - newParagraph(0); - // if there was no closing tag for
    , then remove
    style if (_DT) { @@ -2019,8 +2011,8 @@ namespace NLGUI popIfNotEmpty (_FontWeight); } - uint indent = _DL.size()*ULIndent; - getParagraph()->setFirstViewIndent(indent); + _Indent += ULIndent; + newParagraph(0); } break; case HTML_OL: @@ -2225,6 +2217,13 @@ namespace NLGUI if (getDL()) { endParagraph(); + if (getDL()) + { + if (_Indent > ULIndent) + _Indent = _Indent - ULIndent; + else + _Indent = 0; + } popIfNotEmpty (_DL); if (_DT) { _DT = false; @@ -2244,6 +2243,13 @@ namespace NLGUI break; case HTML_DD: // style not changed + if (getDL()) + { + if (_Indent > ULIndent) + _Indent = _Indent - ULIndent; + else + _Indent = 0; + } break; case HTML_SPAN: popIfNotEmpty (_FontSize); From 6bcb153930a2dfb7b7bb66b4e094ad2ad6a871c6 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 5 Jan 2016 23:23:19 +0200 Subject: [PATCH 4/6] Fixed: DL list top margin --HG-- branch : develop --- code/nel/src/gui/group_html.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 1e802d9f2..807558f43 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -1924,7 +1924,7 @@ namespace NLGUI else _UL.push_back(HTMLOListElement(1, "square")); // if LI is already present - _LI = _UL.size() > 1; + _LI = _UL.size() > 1 || getDL(); _Indent += ULIndent; endParagraph(); break; @@ -1986,19 +1986,28 @@ namespace NLGUI break; case HTML_DL: _DL.push_back(true); + _LI = _DL.size() > 1 || !_UL.empty(); endParagraph(); break; case HTML_DT: if (getDL()) { - newParagraph(0); - // see if this is the first
    , closing tag not required if (!_DT) { _DT = true; _FontWeight.push_back(FONT_WEIGHT_BOLD); } + + if (!_LI) + { + _LI = true; + newParagraph(ULBeginSpace); + } + else + { + newParagraph(LIBeginSpace); + } } break; case HTML_DD: @@ -2012,7 +2021,15 @@ namespace NLGUI } _Indent += ULIndent; - newParagraph(0); + if (!_LI) + { + _LI = true; + newParagraph(ULBeginSpace); + } + else + { + newParagraph(LIBeginSpace); + } } break; case HTML_OL: @@ -2027,7 +2044,7 @@ namespace NLGUI _UL.push_back(HTMLOListElement(start, type)); // if LI is already present - _LI = _UL.size() > 1; + _LI = _UL.size() > 1 || getDL(); _Indent += ULIndent; endParagraph(); } From 639ce91e61f18fb1db6323c5f590cde97c2423d9 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Wed, 6 Jan 2016 00:08:41 +0200 Subject: [PATCH 5/6] Fixed: Align UL, LI list style type marker outside content --HG-- branch : develop --- code/nel/src/gui/group_html.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 807558f43..86987cb9a 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -1729,8 +1729,14 @@ namespace NLGUI ucstring str; str.fromUtf8(_UL.back().getListMarkerText()); addString (str); + + sint32 indent = LIIndent; + // list-style-type: outside + if (_CurrentViewLink) + indent -= _CurrentViewLink->getMaxUsedW(); + getParagraph()->setFirstViewIndent(indent); + flushString (); - getParagraph()->setFirstViewIndent(LIIndent); _UL.back().Value++; } From 8475f25e75709da965805e9e983dbcf4b2f4ab7c Mon Sep 17 00:00:00 2001 From: Nimetu Date: Wed, 6 Jan 2016 00:11:17 +0200 Subject: [PATCH 6/6] Changed: Refactor DL --HG-- branch : develop --- code/nel/include/nel/gui/group_html.h | 19 +++++---- code/nel/src/gui/group_html.cpp | 58 +++++++++++++++------------ 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/code/nel/include/nel/gui/group_html.h b/code/nel/include/nel/gui/group_html.h index e7e6b8dcd..66f896970 100644 --- a/code/nel/include/nel/gui/group_html.h +++ b/code/nel/include/nel/gui/group_html.h @@ -439,13 +439,17 @@ namespace NLGUI } // DL list - std::vector _DL; - inline bool getDL() const - { - if (_DL.empty()) - return false; - return _DL.back(); - } + class HTMLDListElement { + public: + HTMLDListElement() + : DT(false), DD(false) + { } + + public: + bool DT; + bool DD; + }; + std::vector _DL; // OL and UL class HTMLOListElement { @@ -473,7 +477,6 @@ namespace NLGUI // IL mode bool _LI; - bool _DT; // Current text color std::vector _TextColor; diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 86987cb9a..b4cadc3f4 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -1930,7 +1930,7 @@ namespace NLGUI else _UL.push_back(HTMLOListElement(1, "square")); // if LI is already present - _LI = _UL.size() > 1 || getDL(); + _LI = _UL.size() > 1 || _DL.size() > 1; _Indent += ULIndent; endParagraph(); break; @@ -1991,17 +1991,17 @@ namespace NLGUI _IgnoreText = true; break; case HTML_DL: - _DL.push_back(true); + _DL.push_back(HTMLDListElement()); _LI = _DL.size() > 1 || !_UL.empty(); endParagraph(); break; case HTML_DT: - if (getDL()) + if (!_DL.empty()) { // see if this is the first
    , closing tag not required - if (!_DT) + if (!_DL.back().DT) { - _DT = true; + _DL.back().DT = true; _FontWeight.push_back(FONT_WEIGHT_BOLD); } @@ -2017,16 +2017,21 @@ namespace NLGUI } break; case HTML_DD: - if (getDL()) + if (!_DL.empty()) { // if there was no closing tag for
    , then remove
    style - if (_DT) + if (_DL.back().DT) { - _DT = false; + _DL.back().DT = false; popIfNotEmpty (_FontWeight); } - _Indent += ULIndent; + if (!_DL.back().DD) + { + _Indent += ULIndent; + _DL.back().DD = true; + } + if (!_LI) { _LI = true; @@ -2050,7 +2055,7 @@ namespace NLGUI _UL.push_back(HTMLOListElement(start, type)); // if LI is already present - _LI = _UL.size() > 1 || getDL(); + _LI = _UL.size() > 1 || _DL.size() > 1; _Indent += ULIndent; endParagraph(); } @@ -2237,41 +2242,44 @@ namespace NLGUI } break; case HTML_DL: - if (getDL()) + if (!_DL.empty()) { endParagraph(); - if (getDL()) + + // unclosed DT + if (_DL.back().DT) + { + popIfNotEmpty (_FontWeight); + } + + // unclosed DD + if (_DL.back().DD) { if (_Indent > ULIndent) _Indent = _Indent - ULIndent; else _Indent = 0; } + popIfNotEmpty (_DL); - if (_DT) { - _DT = false; - popIfNotEmpty (_FontWeight); - } } break; case HTML_DT: - if (getDL()) + if (!_DL.empty()) { - if (_DT) - { - _DT = false; - popIfNotEmpty (_FontWeight); - } + _DL.back().DT = false; + popIfNotEmpty (_FontWeight); } break; case HTML_DD: - // style not changed - if (getDL()) + if (!_DL.empty()) { if (_Indent > ULIndent) _Indent = _Indent - ULIndent; else _Indent = 0; + + _DL.back().DD = false; } break; case HTML_SPAN: @@ -2383,7 +2391,6 @@ namespace NLGUI _CurrentViewImage = NULL; _Indent = 0; _LI = false; - _DT = false; _SelectOption = false; _GroupListAdaptor = NULL; _UrlFragment.clear(); @@ -4062,7 +4069,6 @@ namespace NLGUI _FontStrikeThrough.clear(); _Indent = 0; _LI = false; - _DT = false; _UL.clear(); _DL.clear(); _A.clear();