Merge branch 'develop' into develop-atys

feature/develop-atys
Nimetu 4 years ago
commit b2d6c313db

@ -36,6 +36,7 @@ typedef void CURLM;
namespace NLGUI namespace NLGUI
{ {
class CViewLink;
class CCtrlButton; class CCtrlButton;
class CCtrlTextButton; class CCtrlTextButton;
class CCtrlScroll; class CCtrlScroll;
@ -142,37 +143,15 @@ namespace NLGUI
float getTimeout() const {return (float)_TimeoutValue;} float getTimeout() const {return (float)_TimeoutValue;}
// Some constants // Some constants
NLMISC::CRGBA BgColor;
NLMISC::CRGBA ErrorColor; NLMISC::CRGBA ErrorColor;
NLMISC::CRGBA LinkColor; NLMISC::CRGBA LinkColor;
NLMISC::CRGBA TextColor;
NLMISC::CRGBA H1Color;
NLMISC::CRGBA H2Color;
NLMISC::CRGBA H3Color;
NLMISC::CRGBA H4Color;
NLMISC::CRGBA H5Color;
NLMISC::CRGBA H6Color;
bool ErrorColorGlobalColor; bool ErrorColorGlobalColor;
bool LinkColorGlobalColor; bool LinkColorGlobalColor;
bool TextColorGlobalColor; bool TextColorGlobalColor;
bool H1ColorGlobalColor;
bool H2ColorGlobalColor;
bool H3ColorGlobalColor;
bool H4ColorGlobalColor;
bool H5ColorGlobalColor;
bool H6ColorGlobalColor;
uint TextFontSize;
uint H1FontSize;
uint H2FontSize;
uint H3FontSize;
uint H4FontSize;
uint H5FontSize;
uint H6FontSize;
uint TDBeginSpace; uint TDBeginSpace;
uint PBeginSpace; uint PBeginSpace;
uint LIBeginSpace; uint LIBeginSpace;
uint ULBeginSpace; uint ULBeginSpace;
uint LIIndent;
uint ULIndent; uint ULIndent;
float LineSpaceFontFactor; float LineSpaceFontFactor;
std::string DefaultButtonGroup; std::string DefaultButtonGroup;
@ -187,7 +166,6 @@ namespace NLGUI
std::string DefaultRadioButtonBitmapPushed; std::string DefaultRadioButtonBitmapPushed;
std::string DefaultRadioButtonBitmapOver; std::string DefaultRadioButtonBitmapOver;
std::string DefaultBackgroundBitmapView; std::string DefaultBackgroundBitmapView;
std::string CurrentLinkTitle;
struct TFormField { struct TFormField {
public: public:
@ -327,6 +305,12 @@ namespace NLGUI
// Translate a char // Translate a char
bool translateChar(u32char &output, u32char input, u32char lastChar) const; bool translateChar(u32char &output, u32char input, u32char lastChar) const;
// return true if text has same style
bool isSameStyle(CViewLink *text, const CStyleParams &style) const;
// add text link using template
void newTextButton(const std::string &text, const std::string &tpl);
void newTextLink(const std::string &text);
// Add a string in the current paragraph // Add a string in the current paragraph
void addString(const std::string &str); void addString(const std::string &str);
@ -752,9 +736,7 @@ namespace NLGUI
bool _Localize; bool _Localize;
// Current node is a text area // Current node is a text area
bool _TextArea;
std::string _TextAreaTemplate; std::string _TextAreaTemplate;
std::string _TextAreaContent;
std::string _TextAreaName; std::string _TextAreaName;
uint _TextAreaRow; uint _TextAreaRow;
uint _TextAreaCols; uint _TextAreaCols;
@ -1005,11 +987,9 @@ namespace NLGUI
void htmlTD(const CHtmlElement &elm); void htmlTD(const CHtmlElement &elm);
void htmlTDend(const CHtmlElement &elm); void htmlTDend(const CHtmlElement &elm);
void htmlTEXTAREA(const CHtmlElement &elm); void htmlTEXTAREA(const CHtmlElement &elm);
void htmlTEXTAREAend(const CHtmlElement &elm);
void htmlTH(const CHtmlElement &elm); void htmlTH(const CHtmlElement &elm);
void htmlTHend(const CHtmlElement &elm); void htmlTHend(const CHtmlElement &elm);
void htmlTITLE(const CHtmlElement &elm); void htmlTITLE(const CHtmlElement &elm);
void htmlTITLEend(const CHtmlElement &elm);
void htmlTR(const CHtmlElement &elm); void htmlTR(const CHtmlElement &elm);
void htmlTRend(const CHtmlElement &elm); void htmlTRend(const CHtmlElement &elm);
//void htmlU(const CHtmlElement &elm); //void htmlU(const CHtmlElement &elm);

@ -75,6 +75,18 @@ namespace NLGUI
// update Children index/parent/next/prevSibling pointers // update Children index/parent/next/prevSibling pointers
void reindexChilds(); void reindexChilds();
// escape text tag or attribute value
std::string htmlEscape(std::string val, bool isAttribute = false) const;
// serialize element attributes as string
std::string serializeAttributes() const;
// serialize child elements as html string
std::string serializeChilds() const;
// serialize itself and children as html string
std::string serialize() const;
// debug // debug
std::string toString(bool tree = false, uint depth = 0) const; std::string toString(bool tree = false, uint depth = 0) const;

@ -32,7 +32,7 @@ public:
uint32 Size; uint32 Size;
uint32 LastModified; uint32 LastModified;
void serial(NLMISC::IStream &f) throw(NLMISC::EStream); void serial(NLMISC::IStream &f);
}; };
@ -40,7 +40,7 @@ public:
CStreamedPackage(); CStreamedPackage();
~CStreamedPackage(); ~CStreamedPackage();
void serial(NLMISC::IStream &f) throw(NLMISC::EStream); void serial(NLMISC::IStream &f);
/// result: [out] ex. /00/00/000000000.. /// result: [out] ex. /00/00/000000000..
/// hash: [in] /// hash: [in]

@ -1231,10 +1231,10 @@ namespace NLGUI
case HTML_TABLE: htmlTABLEend(elm); break; case HTML_TABLE: htmlTABLEend(elm); break;
case HTML_TD: htmlTDend(elm); break; case HTML_TD: htmlTDend(elm); break;
case HTML_TBODY: renderPseudoElement(":after", elm); break; case HTML_TBODY: renderPseudoElement(":after", elm); break;
case HTML_TEXTAREA: htmlTEXTAREAend(elm); break; case HTML_TEXTAREA: break;
case HTML_TFOOT: renderPseudoElement(":after", elm); break; case HTML_TFOOT: renderPseudoElement(":after", elm); break;
case HTML_TH: htmlTHend(elm); break; case HTML_TH: htmlTHend(elm); break;
case HTML_TITLE: htmlTITLEend(elm); break; case HTML_TITLE: break;
case HTML_TR: htmlTRend(elm); break; case HTML_TR: htmlTRend(elm); break;
case HTML_U: renderPseudoElement(":after", elm); break; case HTML_U: renderPseudoElement(":after", elm); break;
case HTML_UL: htmlULend(elm); break; case HTML_UL: htmlULend(elm); break;
@ -1396,9 +1396,9 @@ namespace NLGUI
{ {
beginElement(elm); beginElement(elm);
std::list<CHtmlElement>::iterator it = elm.Children.begin();
if (!_IgnoreChildElements) if (!_IgnoreChildElements)
{ {
std::list<CHtmlElement>::iterator it = elm.Children.begin();
while(it != elm.Children.end()) while(it != elm.Children.end())
{ {
renderDOM(*it); renderDOM(*it);
@ -1460,37 +1460,15 @@ namespace NLGUI
CWidgetManager::getInstance()->registerClockMsgTarget(this); CWidgetManager::getInstance()->registerClockMsgTarget(this);
// HTML parameters // HTML parameters
BgColor = CRGBA::Black;
ErrorColor = CRGBA(255, 0, 0); ErrorColor = CRGBA(255, 0, 0);
LinkColor = CRGBA(0, 0, 255); LinkColor = CRGBA(0, 0, 255);
TextColor = CRGBA(255, 255, 255);
H1Color = CRGBA(255, 255, 255);
H2Color = CRGBA(255, 255, 255);
H3Color = CRGBA(255, 255, 255);
H4Color = CRGBA(255, 255, 255);
H5Color = CRGBA(255, 255, 255);
H6Color = CRGBA(255, 255, 255);
ErrorColorGlobalColor = false; ErrorColorGlobalColor = false;
LinkColorGlobalColor = false; LinkColorGlobalColor = false;
TextColorGlobalColor = false; TextColorGlobalColor = false;
H1ColorGlobalColor = false;
H2ColorGlobalColor = false;
H3ColorGlobalColor = false;
H4ColorGlobalColor = false;
H5ColorGlobalColor = false;
H6ColorGlobalColor = false;
TextFontSize = 9;
H1FontSize = 18;
H2FontSize = 15;
H3FontSize = 12;
H4FontSize = 9;
H5FontSize = 9;
H6FontSize = 9;
LIBeginSpace = 4; LIBeginSpace = 4;
ULBeginSpace = 12; ULBeginSpace = 12;
PBeginSpace = 12; PBeginSpace = 12;
TDBeginSpace = 0; TDBeginSpace = 0;
LIIndent = -10;
ULIndent = 30; ULIndent = 30;
LineSpaceFontFactor = 0.5f; LineSpaceFontFactor = 0.5f;
DefaultButtonGroup = "html_text_button"; DefaultButtonGroup = "html_text_button";
@ -1562,11 +1540,6 @@ namespace NLGUI
return _TitlePrefix; return _TitlePrefix;
} }
else else
if( name == "background_color" )
{
return toString( BgColor );
}
else
if( name == "error_color" ) if( name == "error_color" )
{ {
return toString( ErrorColor ); return toString( ErrorColor );
@ -1577,36 +1550,6 @@ namespace NLGUI
return toString( LinkColor ); return toString( LinkColor );
} }
else else
if( name == "h1_color" )
{
return toString( H1Color );
}
else
if( name == "h2_color" )
{
return toString( H2Color );
}
else
if( name == "h3_color" )
{
return toString( H3Color );
}
else
if( name == "h4_color" )
{
return toString( H4Color );
}
else
if( name == "h5_color" )
{
return toString( H5Color );
}
else
if( name == "h6_color" )
{
return toString( H6Color );
}
else
if( name == "error_color_global_color" ) if( name == "error_color_global_color" )
{ {
return toString( ErrorColorGlobalColor ); return toString( ErrorColorGlobalColor );
@ -1622,71 +1565,6 @@ namespace NLGUI
return toString( TextColorGlobalColor ); return toString( TextColorGlobalColor );
} }
else else
if( name == "h1_color_global_color" )
{
return toString( H1ColorGlobalColor );
}
else
if( name == "h2_color_global_color" )
{
return toString( H2ColorGlobalColor );
}
else
if( name == "h3_color_global_color" )
{
return toString( H3ColorGlobalColor );
}
else
if( name == "h4_color_global_color" )
{
return toString( H4ColorGlobalColor );
}
else
if( name == "h5_color_global_color" )
{
return toString( H5ColorGlobalColor );
}
else
if( name == "h6_color_global_color" )
{
return toString( H6ColorGlobalColor );
}
else
if( name == "text_font_size" )
{
return toString( TextFontSize );
}
else
if( name == "h1_font_size" )
{
return toString( H1FontSize );
}
else
if( name == "h2_font_size" )
{
return toString( H2FontSize );
}
else
if( name == "h3_font_size" )
{
return toString( H3FontSize );
}
else
if( name == "h4_font_size" )
{
return toString( H4FontSize );
}
else
if( name == "h5_font_size" )
{
return toString( H5FontSize );
}
else
if( name == "h6_font_size" )
{
return toString( H6FontSize );
}
else
if( name == "td_begin_space" ) if( name == "td_begin_space" )
{ {
return toString( TDBeginSpace ); return toString( TDBeginSpace );
@ -1707,11 +1585,6 @@ namespace NLGUI
return toString( ULBeginSpace ); return toString( ULBeginSpace );
} }
else else
if( name == "li_indent" )
{
return toString( LIIndent );
}
else
if( name == "ul_indent" ) if( name == "ul_indent" )
{ {
return toString( ULIndent ); return toString( ULIndent );
@ -1824,14 +1697,6 @@ namespace NLGUI
return; return;
} }
else else
if( name == "background_color" )
{
CRGBA c;
if( fromString( value, c ) )
BgColor = c;
return;
}
else
if( name == "error_color" ) if( name == "error_color" )
{ {
CRGBA c; CRGBA c;
@ -1848,54 +1713,6 @@ namespace NLGUI
return; return;
} }
else else
if( name == "h1_color" )
{
CRGBA c;
if( fromString( value, c ) )
H1Color = c;
return;
}
else
if( name == "h2_color" )
{
CRGBA c;
if( fromString( value, c ) )
H2Color = c;
return;
}
else
if( name == "h3_color" )
{
CRGBA c;
if( fromString( value, c ) )
H3Color = c;
return;
}
else
if( name == "h4_color" )
{
CRGBA c;
if( fromString( value, c ) )
H4Color = c;
return;
}
else
if( name == "h5_color" )
{
CRGBA c;
if( fromString( value, c ) )
H5Color = c;
return;
}
else
if( name == "h6_color" )
{
CRGBA c;
if( fromString( value, c ) )
H6Color = c;
return;
}
else
if( name == "error_color_global_color" ) if( name == "error_color_global_color" )
{ {
bool b; bool b;
@ -1920,110 +1737,6 @@ namespace NLGUI
return; return;
} }
else else
if( name == "h1_color_global_color" )
{
bool b;
if( fromString( value, b ) )
H1ColorGlobalColor = b;
return;
}
else
if( name == "h2_color_global_color" )
{
bool b;
if( fromString( value, b ) )
H2ColorGlobalColor = b;
return;
}
else
if( name == "h3_color_global_color" )
{
bool b;
if( fromString( value, b ) )
H3ColorGlobalColor = b;
return;
}
else
if( name == "h4_color_global_color" )
{
bool b;
if( fromString( value, b ) )
H4ColorGlobalColor = b;
return;
}
else
if( name == "h5_color_global_color" )
{
bool b;
if( fromString( value, b ) )
H5ColorGlobalColor = b;
return;
}
else
if( name == "h6_color_global_color" )
{
bool b;
if( fromString( value, b ) )
H6ColorGlobalColor = b;
return;
}
else
if( name == "text_font_size" )
{
uint i;
if( fromString( value, i ) )
TextFontSize = i;
return;
}
else
if( name == "h1_font_size" )
{
uint i;
if( fromString( value, i ) )
H1FontSize = i;
return;
}
else
if( name == "h2_font_size" )
{
uint i;
if( fromString( value, i ) )
H2FontSize = i;
return;
}
else
if( name == "h3_font_size" )
{
uint i;
if( fromString( value, i ) )
H3FontSize = i;
return;
}
else
if( name == "h4_font_size" )
{
uint i;
if( fromString( value, i ) )
H4FontSize = i;
return;
}
else
if( name == "h5_font_size" )
{
uint i;
if( fromString( value, i ) )
H5FontSize = i;
return;
}
else
if( name == "h6_font_size" )
{
uint i;
if( fromString( value, i ) )
H6FontSize = i;
return;
}
else
if( name == "td_begin_space" ) if( name == "td_begin_space" )
{ {
uint i; uint i;
@ -2056,14 +1769,6 @@ namespace NLGUI
return; return;
} }
else else
if( name == "li_indent" )
{
uint i;
if( fromString( value, i ) )
LIIndent = i;
return;
}
else
if( name == "ul_indent" ) if( name == "ul_indent" )
{ {
uint i; uint i;
@ -2222,16 +1927,8 @@ namespace NLGUI
xmlSetProp( node, BAD_CAST "type", BAD_CAST "html" ); xmlSetProp( node, BAD_CAST "type", BAD_CAST "html" );
xmlSetProp( node, BAD_CAST "url", BAD_CAST _URL.c_str() ); xmlSetProp( node, BAD_CAST "url", BAD_CAST _URL.c_str() );
xmlSetProp( node, BAD_CAST "title_prefix", BAD_CAST _TitlePrefix.c_str() ); xmlSetProp( node, BAD_CAST "title_prefix", BAD_CAST _TitlePrefix.c_str() );
xmlSetProp( node, BAD_CAST "background_color", BAD_CAST toString( BgColor ).c_str() );
xmlSetProp( node, BAD_CAST "error_color", BAD_CAST toString( ErrorColor ).c_str() ); xmlSetProp( node, BAD_CAST "error_color", BAD_CAST toString( ErrorColor ).c_str() );
xmlSetProp( node, BAD_CAST "link_color", BAD_CAST toString( LinkColor ).c_str() ); xmlSetProp( node, BAD_CAST "link_color", BAD_CAST toString( LinkColor ).c_str() );
xmlSetProp( node, BAD_CAST "background_color", BAD_CAST toString( BgColor ).c_str() );
xmlSetProp( node, BAD_CAST "h1_color", BAD_CAST toString( H1Color ).c_str() );
xmlSetProp( node, BAD_CAST "h2_color", BAD_CAST toString( H2Color ).c_str() );
xmlSetProp( node, BAD_CAST "h3_color", BAD_CAST toString( H3Color ).c_str() );
xmlSetProp( node, BAD_CAST "h4_color", BAD_CAST toString( H4Color ).c_str() );
xmlSetProp( node, BAD_CAST "h5_color", BAD_CAST toString( H5Color ).c_str() );
xmlSetProp( node, BAD_CAST "h6_color", BAD_CAST toString( H6Color ).c_str() );
xmlSetProp( node, BAD_CAST "error_color_global_color", xmlSetProp( node, BAD_CAST "error_color_global_color",
BAD_CAST toString( ErrorColorGlobalColor ).c_str() ); BAD_CAST toString( ErrorColorGlobalColor ).c_str() );
@ -2239,31 +1936,11 @@ namespace NLGUI
BAD_CAST toString( LinkColorGlobalColor ).c_str() ); BAD_CAST toString( LinkColorGlobalColor ).c_str() );
xmlSetProp( node, BAD_CAST "text_color_global_color", xmlSetProp( node, BAD_CAST "text_color_global_color",
BAD_CAST toString( TextColorGlobalColor ).c_str() ); BAD_CAST toString( TextColorGlobalColor ).c_str() );
xmlSetProp( node, BAD_CAST "h1_color_global_color",
BAD_CAST toString( H1ColorGlobalColor ).c_str() );
xmlSetProp( node, BAD_CAST "h2_color_global_color",
BAD_CAST toString( H2ColorGlobalColor ).c_str() );
xmlSetProp( node, BAD_CAST "h3_color_global_color",
BAD_CAST toString( H3ColorGlobalColor ).c_str() );
xmlSetProp( node, BAD_CAST "h4_color_global_color",
BAD_CAST toString( H4ColorGlobalColor ).c_str() );
xmlSetProp( node, BAD_CAST "h5_color_global_color",
BAD_CAST toString( H5ColorGlobalColor ).c_str() );
xmlSetProp( node, BAD_CAST "h6_color_global_color",
BAD_CAST toString( H6ColorGlobalColor ).c_str() );
xmlSetProp( node, BAD_CAST "text_font_size", BAD_CAST toString( TextFontSize ).c_str() );
xmlSetProp( node, BAD_CAST "h1_font_size", BAD_CAST toString( H1FontSize ).c_str() );
xmlSetProp( node, BAD_CAST "h2_font_size", BAD_CAST toString( H2FontSize ).c_str() );
xmlSetProp( node, BAD_CAST "h3_font_size", BAD_CAST toString( H3FontSize ).c_str() );
xmlSetProp( node, BAD_CAST "h4_font_size", BAD_CAST toString( H4FontSize ).c_str() );
xmlSetProp( node, BAD_CAST "h5_font_size", BAD_CAST toString( H5FontSize ).c_str() );
xmlSetProp( node, BAD_CAST "h6_font_size", BAD_CAST toString( H6FontSize ).c_str() );
xmlSetProp( node, BAD_CAST "td_begin_space", BAD_CAST toString( TDBeginSpace ).c_str() ); xmlSetProp( node, BAD_CAST "td_begin_space", BAD_CAST toString( TDBeginSpace ).c_str() );
xmlSetProp( node, BAD_CAST "paragraph_begin_space", BAD_CAST toString( PBeginSpace ).c_str() ); xmlSetProp( node, BAD_CAST "paragraph_begin_space", BAD_CAST toString( PBeginSpace ).c_str() );
xmlSetProp( node, BAD_CAST "li_begin_space", BAD_CAST toString( LIBeginSpace ).c_str() ); xmlSetProp( node, BAD_CAST "li_begin_space", BAD_CAST toString( LIBeginSpace ).c_str() );
xmlSetProp( node, BAD_CAST "ul_begin_space", BAD_CAST toString( ULBeginSpace ).c_str() ); xmlSetProp( node, BAD_CAST "ul_begin_space", BAD_CAST toString( ULBeginSpace ).c_str() );
xmlSetProp( node, BAD_CAST "li_indent", BAD_CAST toString( LIIndent ).c_str() );
xmlSetProp( node, BAD_CAST "ul_indent", BAD_CAST toString( ULIndent ).c_str() ); xmlSetProp( node, BAD_CAST "ul_indent", BAD_CAST toString( ULIndent ).c_str() );
xmlSetProp( node, BAD_CAST "multi_line_space_factor", BAD_CAST toString( LineSpaceFontFactor ).c_str() ); xmlSetProp( node, BAD_CAST "multi_line_space_factor", BAD_CAST toString( LineSpaceFontFactor ).c_str() );
xmlSetProp( node, BAD_CAST "form_text_area_group", BAD_CAST DefaultFormTextGroup.c_str() ); xmlSetProp( node, BAD_CAST "form_text_area_group", BAD_CAST DefaultFormTextGroup.c_str() );
@ -2315,36 +1992,12 @@ namespace NLGUI
_TitlePrefix = CI18N::get((const char*)ptr); _TitlePrefix = CI18N::get((const char*)ptr);
// Parameters // Parameters
ptr = xmlGetProp (cur, (xmlChar*)"background_color");
if (ptr)
BgColor = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"error_color"); ptr = xmlGetProp (cur, (xmlChar*)"error_color");
if (ptr) if (ptr)
ErrorColor = convertColor(ptr); ErrorColor = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"link_color"); ptr = xmlGetProp (cur, (xmlChar*)"link_color");
if (ptr) if (ptr)
LinkColor = convertColor(ptr); LinkColor = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"text_color");
if (ptr)
TextColor = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h1_color");
if (ptr)
H1Color = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h2_color");
if (ptr)
H2Color = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h3_color");
if (ptr)
H3Color = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h4_color");
if (ptr)
H4Color = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h5_color");
if (ptr)
H5Color = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h6_color");
if (ptr)
H6Color = convertColor(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"error_color_global_color"); ptr = xmlGetProp (cur, (xmlChar*)"error_color_global_color");
if (ptr) if (ptr)
ErrorColorGlobalColor = convertBool(ptr); ErrorColorGlobalColor = convertBool(ptr);
@ -2354,45 +2007,6 @@ namespace NLGUI
ptr = xmlGetProp (cur, (xmlChar*)"text_color_global_color"); ptr = xmlGetProp (cur, (xmlChar*)"text_color_global_color");
if (ptr) if (ptr)
TextColorGlobalColor = convertBool(ptr); TextColorGlobalColor = convertBool(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h1_color_global_color");
if (ptr)
H1ColorGlobalColor = convertBool(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h2_color_global_color");
if (ptr)
H2ColorGlobalColor = convertBool(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h3_color_global_color");
if (ptr)
H3ColorGlobalColor = convertBool(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h4_color_global_color");
if (ptr)
H4ColorGlobalColor = convertBool(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h5_color_global_color");
if (ptr)
H5ColorGlobalColor = convertBool(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"h6_color_global_color");
if (ptr)
H6ColorGlobalColor = convertBool(ptr);
ptr = xmlGetProp (cur, (xmlChar*)"text_font_size");
if (ptr)
fromString((const char*)ptr, TextFontSize);
ptr = xmlGetProp (cur, (xmlChar*)"h1_font_size");
if (ptr)
fromString((const char*)ptr, H1FontSize);
ptr = xmlGetProp (cur, (xmlChar*)"h2_font_size");
if (ptr)
fromString((const char*)ptr, H2FontSize);
ptr = xmlGetProp (cur, (xmlChar*)"h3_font_size");
if (ptr)
fromString((const char*)ptr, H3FontSize);
ptr = xmlGetProp (cur, (xmlChar*)"h4_font_size");
if (ptr)
fromString((const char*)ptr, H4FontSize);
ptr = xmlGetProp (cur, (xmlChar*)"h5_font_size");
if (ptr)
fromString((const char*)ptr, H5FontSize);
ptr = xmlGetProp (cur, (xmlChar*)"h6_font_size");
if (ptr)
fromString((const char*)ptr, H6FontSize);
ptr = xmlGetProp (cur, (xmlChar*)"td_begin_space"); ptr = xmlGetProp (cur, (xmlChar*)"td_begin_space");
if (ptr) if (ptr)
fromString((const char*)ptr, TDBeginSpace); fromString((const char*)ptr, TDBeginSpace);
@ -2405,9 +2019,6 @@ namespace NLGUI
ptr = xmlGetProp (cur, (xmlChar*)"ul_begin_space"); ptr = xmlGetProp (cur, (xmlChar*)"ul_begin_space");
if (ptr) if (ptr)
fromString((const char*)ptr, ULBeginSpace); fromString((const char*)ptr, ULBeginSpace);
ptr = xmlGetProp (cur, (xmlChar*)"li_indent");
if (ptr)
fromString((const char*)ptr, LIIndent);
ptr = xmlGetProp (cur, (xmlChar*)"ul_indent"); ptr = xmlGetProp (cur, (xmlChar*)"ul_indent");
if (ptr) if (ptr)
fromString((const char*)ptr, ULIndent); fromString((const char*)ptr, ULIndent);
@ -2770,6 +2381,113 @@ namespace NLGUI
} }
} }
// ***************************************************************************
bool CGroupHTML::isSameStyle(CViewLink *text, const CStyleParams &style) const
{
if (!text) return false;
bool embolden = style.FontWeight >= FONT_WEIGHT_BOLD;
bool sameShadow = style.TextShadow.Enabled && text->getShadow();
if (sameShadow && style.TextShadow.Enabled)
{
sint sx, sy;
text->getShadowOffset(sx, sy);
sameShadow = (style.TextShadow.Color == text->getShadowColor());
sameShadow = sameShadow && (style.TextShadow.Outline == text->getShadowOutline());
sameShadow = sameShadow && (style.TextShadow.X == sx) && (style.TextShadow.Y == sy);
}
// Compatible with current parameters ?
return sameShadow &&
(style.TextColor == text->getColor()) &&
(style.FontFamily == text->getFontName()) &&
(style.FontSize == (uint)text->getFontSize()) &&
(style.Underlined == text->getUnderlined()) &&
(style.StrikeThrough == text->getStrikeThrough()) &&
(embolden == text->getEmbolden()) &&
(style.FontOblique == text->getOblique()) &&
(getLink() == text->Link) &&
(style.GlobalColor == text->getModulateGlobalColor());
}
// ***************************************************************************
void CGroupHTML::newTextButton(const std::string &text, const std::string &tpl)
{
_CurrentViewLink = NULL;
_CurrentViewImage = NULL;
// Action handler parameters : "name=group_html_id|form=id_of_the_form|submit_button=button_name"
string param = "name=" + this->_Id + "|url=" + getLink();
string name;
if (!_AnchorName.empty())
name = _AnchorName.back();
typedef pair<string, string> TTmplParam;
vector<TTmplParam> tmplParams;
tmplParams.push_back(TTmplParam("id", ""));
tmplParams.push_back(TTmplParam("onclick", "browse"));
tmplParams.push_back(TTmplParam("onclick_param", param));
tmplParams.push_back(TTmplParam("active", "true"));
CInterfaceGroup *buttonGroup = CWidgetManager::getInstance()->getParser()->createGroupInstance(tpl, getId()+":"+name, tmplParams);
if (!buttonGroup)
{
nlinfo("Text button template '%s' not found", tpl.c_str());
return;
}
buttonGroup->setId(getId()+":"+name);
// Add the ctrl button
CCtrlTextButton *ctrlButton = dynamic_cast<CCtrlTextButton*>(buttonGroup->getCtrl("button"));
if (!ctrlButton) ctrlButton = dynamic_cast<CCtrlTextButton*>(buttonGroup->getCtrl("b"));
if (!ctrlButton)
{
nlinfo("Text button template '%s' is missing :button or :b text element", tpl.c_str());
return;
}
ctrlButton->setModulateGlobalColorAll(false);
// Translate the tooltip
ctrlButton->setText(text);
ctrlButton->setDefaultContextHelp(std::string(getLinkTitle()));
// empty url / button disabled
ctrlButton->setFrozen(*getLink() == '\0');
setTextButtonStyle(ctrlButton, _Style.Current);
_Paragraph->addChild(buttonGroup);
}
// ***************************************************************************
void CGroupHTML::newTextLink(const std::string &text)
{
CViewLink *newLink = new CViewLink(CViewBase::TCtorParam());
if (getA())
{
newLink->Link = getLink();
newLink->LinkTitle = getLinkTitle();
if (!newLink->Link.empty())
{
newLink->setHTMLView (this);
newLink->setActionOnLeftClick("browse");
newLink->setParamsOnLeftClick("name=" + getId() + "|url=" + newLink->Link);
}
}
newLink->setText(text);
newLink->setMultiLineSpace((uint)((float)(_Style.Current.FontSize)*LineSpaceFontFactor));
newLink->setMultiLine(true);
newLink->setModulateGlobalColor(_Style.Current.GlobalColor);
setTextStyle(newLink, _Style.Current);
registerAnchor(newLink);
if (getA() && !newLink->Link.empty())
getParagraph()->addChildLink(newLink);
else
getParagraph()->addChild(newLink);
_CurrentViewLink = newLink;
_CurrentViewImage = NULL;
}
// *************************************************************************** // ***************************************************************************
void CGroupHTML::addString(const std::string &str) void CGroupHTML::addString(const std::string &str)
@ -2809,15 +2527,7 @@ namespace NLGUI
} }
// In title ? // In title ?
if (_Title) if (_Object)
{
_TitleString += tmpStr;
}
else if (_TextArea)
{
_TextAreaContent += tmpStr;
}
else if (_Object)
{ {
_ObjectScript += tmpStr; _ObjectScript += tmpStr;
} }
@ -2844,32 +2554,11 @@ namespace NLGUI
// Text added ? // Text added ?
bool added = false; bool added = false;
bool embolden = style.FontWeight >= FONT_WEIGHT_BOLD;
// Number of child in this paragraph
if (_CurrentViewLink) if (_CurrentViewLink)
{ {
bool skipLine = !_CurrentViewLink->getText().empty() && *(_CurrentViewLink->getText().rbegin()) == '\n'; bool skipLine = !_CurrentViewLink->getText().empty() && *(_CurrentViewLink->getText().rbegin()) == '\n';
bool sameShadow = style.TextShadow.Enabled && _CurrentViewLink->getShadow(); if (!skipLine && isSameStyle(_CurrentViewLink, style))
if (sameShadow && style.TextShadow.Enabled)
{
sint sx, sy;
_CurrentViewLink->getShadowOffset(sx, sy);
sameShadow = (style.TextShadow.Color == _CurrentViewLink->getShadowColor());
sameShadow = sameShadow && (style.TextShadow.Outline == _CurrentViewLink->getShadowOutline());
sameShadow = sameShadow && (style.TextShadow.X == sx) && (style.TextShadow.Y == sy);
}
// Compatible with current parameters ?
if (!skipLine && sameShadow &&
(style.TextColor == _CurrentViewLink->getColor()) &&
(style.FontFamily == _CurrentViewLink->getFontName()) &&
(style.FontSize == (uint)_CurrentViewLink->getFontSize()) &&
(style.Underlined == _CurrentViewLink->getUnderlined()) &&
(style.StrikeThrough == _CurrentViewLink->getStrikeThrough()) &&
(embolden == _CurrentViewLink->getEmbolden()) &&
(style.FontOblique == _CurrentViewLink->getOblique()) &&
(getLink() == _CurrentViewLink->Link) &&
(style.GlobalColor == _CurrentViewLink->getModulateGlobalColor()))
{ {
// Concat the text // Concat the text
_CurrentViewLink->setText(_CurrentViewLink->getText()+tmpStr); _CurrentViewLink->setText(_CurrentViewLink->getText()+tmpStr);
@ -2882,78 +2571,9 @@ namespace NLGUI
if (!added) if (!added)
{ {
if (getA() && string(getLinkClass()) == "ryzom-ui-button") if (getA() && string(getLinkClass()) == "ryzom-ui-button")
{ newTextButton(tmpStr, DefaultButtonGroup);
string buttonTemplate = DefaultButtonGroup;
// Action handler parameters : "name=group_html_id|form=id_of_the_form|submit_button=button_name"
string param = "name=" + this->_Id + "|url=" + getLink();
string name;
if (!_AnchorName.empty())
name = _AnchorName.back();
typedef pair<string, string> TTmplParam;
vector<TTmplParam> tmplParams;
tmplParams.push_back(TTmplParam("id", ""));
tmplParams.push_back(TTmplParam("onclick", "browse"));
tmplParams.push_back(TTmplParam("onclick_param", param));
tmplParams.push_back(TTmplParam("active", "true"));
CInterfaceGroup *buttonGroup = CWidgetManager::getInstance()->getParser()->createGroupInstance(buttonTemplate, getId()+":"+name, tmplParams);
if (buttonGroup)
{
buttonGroup->setId(getId()+":"+name);
// Add the ctrl button
CCtrlTextButton *ctrlButton = dynamic_cast<CCtrlTextButton*>(buttonGroup->getCtrl("button"));
if (!ctrlButton) ctrlButton = dynamic_cast<CCtrlTextButton*>(buttonGroup->getCtrl("b"));
if (ctrlButton)
{
ctrlButton->setModulateGlobalColorAll (false);
// Translate the tooltip
ctrlButton->setDefaultContextHelp(getLinkTitle());
ctrlButton->setText(tmpStr);
// empty url / button disabled
bool disabled = string(getLink()).empty();
ctrlButton->setFrozen(disabled);
setTextButtonStyle(ctrlButton, style);
}
getParagraph()->addChild (buttonGroup);
paragraphChange ();
}
}
else else
{ newTextLink(tmpStr);
CViewLink *newLink = new CViewLink(CViewBase::TCtorParam());
if (getA())
{
newLink->Link = getLink();
newLink->LinkTitle = getLinkTitle();
if (!newLink->Link.empty())
{
newLink->setHTMLView (this);
newLink->setActionOnLeftClick("browse");
newLink->setParamsOnLeftClick("name=" + getId() + "|url=" + newLink->Link);
}
}
newLink->setText(tmpStr);
newLink->setMultiLineSpace((uint)((float)(style.FontSize)*LineSpaceFontFactor));
newLink->setMultiLine(true);
newLink->setModulateGlobalColor(style.GlobalColor);
setTextStyle(newLink, style);
// newLink->setLineAtBottom (true);
registerAnchor(newLink);
if (getA() && !newLink->Link.empty())
{
getParagraph()->addChildLink(newLink);
}
else
{
getParagraph()->addChild(newLink);
}
paragraphChange ();
}
} }
} }
} }
@ -3302,8 +2922,6 @@ namespace NLGUI
_Anchors.clear(); _Anchors.clear();
_AnchorName.clear(); _AnchorName.clear();
_CellParams.clear(); _CellParams.clear();
_Title = false;
_TextArea = false;
_Object = false; _Object = false;
_Localize = false; _Localize = false;
_ReadingHeadTag = false; _ReadingHeadTag = false;
@ -3439,12 +3057,10 @@ namespace NLGUI
void CGroupHTML::setTitle(const std::string &title) void CGroupHTML::setTitle(const std::string &title)
{ {
_TitleString.clear(); if(_TitlePrefix.empty())
if(!_TitlePrefix.empty()) _TitleString = title;
{ else
_TitleString = _TitlePrefix + " - "; _TitleString = _TitlePrefix + " - " + title;
}
_TitleString += title;
setContainerTitle(_TitleString); setContainerTitle(_TitleString);
} }
@ -4428,7 +4044,7 @@ namespace NLGUI
clearContext(); clearContext();
// Reset default background color // Reset default background color
setBackgroundColor (BgColor); setBackgroundColor (_BrowserStyle.Current.BackgroundColor);
setBackground ("blank.tga", true, false); setBackground ("blank.tga", true, false);
paragraphChange (); paragraphChange ();
@ -6845,12 +6461,11 @@ namespace NLGUI
string image = _Style.getStyle("background-image"); string image = _Style.getStyle("background-image");
addImageDownload(image, table, CStyleParams(), NormalImage, ""); addImageDownload(image, table, CStyleParams(), NormalImage, "");
} }
else
// setting ModulateGlobalColor must be after addImageDownload {
if (_Style.checkStyle("-ryzom-modulate-bgcolor", "true")) // will be set in addImageDownload if background-image exists
table->setModulateGlobalColor(true); table->setModulateGlobalColor(_Style.Current.GlobalColor);
else if (_Style.checkStyle("-ryzom-modulate-bgcolor", "false")) }
table->setModulateGlobalColor(false);
table->setMarginLeft(getIndent()); table->setMarginLeft(getIndent());
addHtmlGroup (table, 0); addHtmlGroup (table, 0);
@ -6935,6 +6550,11 @@ namespace NLGUI
string image = _Style.getStyle("background-image"); string image = _Style.getStyle("background-image");
addImageDownload(image, _Cells.back(), CStyleParams(), NormalImage, ""); addImageDownload(image, _Cells.back(), CStyleParams(), NormalImage, "");
} }
else
{
// will be set in addImageDownload if background-image is set
_Cells.back()->setModulateGlobalColor(_Style.Current.GlobalColor);
}
if (elm.hasNonEmptyAttribute("colspan")) if (elm.hasNonEmptyAttribute("colspan"))
fromString(elm.getAttribute("colspan"), _Cells.back()->ColSpan); fromString(elm.getAttribute("colspan"), _Cells.back()->ColSpan);
@ -6971,10 +6591,6 @@ namespace NLGUI
_Cells.back()->NewLine = getTR(); _Cells.back()->NewLine = getTR();
// setting ModulateGlobalColor must be after addImageDownload
if (_Style.checkStyle("-ryzom-modulate-bgcolor", "true"))
_Cells.back()->setModulateGlobalColor(true);
// border from <table border="1"> // border from <table border="1">
if (table->CellBorder) if (table->CellBorder)
{ {
@ -7039,6 +6655,9 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::htmlTEXTAREA(const CHtmlElement &elm) void CGroupHTML::htmlTEXTAREA(const CHtmlElement &elm)
{ {
_IgnoreChildElements = true;
// TODO: allow textarea without form
if (_Forms.empty()) if (_Forms.empty())
return; return;
@ -7053,7 +6672,6 @@ namespace NLGUI
_TextAreaName.clear(); _TextAreaName.clear();
_TextAreaRow = 1; _TextAreaRow = 1;
_TextAreaCols = 10; _TextAreaCols = 10;
_TextAreaContent.clear();
_TextAreaMaxLength = 1024; _TextAreaMaxLength = 1024;
if (elm.hasNonEmptyAttribute("name")) if (elm.hasNonEmptyAttribute("name"))
_TextAreaName = elm.getAttribute("name"); _TextAreaName = elm.getAttribute("name");
@ -7065,16 +6683,11 @@ namespace NLGUI
fromString(elm.getAttribute("maxlength"), _TextAreaMaxLength); fromString(elm.getAttribute("maxlength"), _TextAreaMaxLength);
_TextAreaTemplate = !templateName.empty() ? templateName : DefaultFormTextAreaGroup; _TextAreaTemplate = !templateName.empty() ? templateName : DefaultFormTextAreaGroup;
_TextArea = true;
_PRE.push_back(true);
}
void CGroupHTML::htmlTEXTAREAend(const CHtmlElement &elm) std::string content = strFindReplaceAll(elm.serializeChilds(), std::string("\t"), std::string(" "));
{ content = strFindReplaceAll(content, std::string("\n"), std::string(" "));
if (_Forms.empty())
return;
CInterfaceGroup *textArea = addTextArea (_TextAreaTemplate, _TextAreaName.c_str (), _TextAreaRow, _TextAreaCols, true, _TextAreaContent, _TextAreaMaxLength); CInterfaceGroup *textArea = addTextArea (_TextAreaTemplate, _TextAreaName.c_str (), _TextAreaRow, _TextAreaCols, true, content, _TextAreaMaxLength);
if (textArea) if (textArea)
{ {
// Add the text area to the form // Add the text area to the form
@ -7083,9 +6696,6 @@ namespace NLGUI
entry.TextArea = textArea; entry.TextArea = textArea;
_Forms.back().Entries.push_back (entry); _Forms.back().Entries.push_back (entry);
} }
_TextArea = false;
popIfNotEmpty (_PRE);
} }
// *************************************************************************** // ***************************************************************************
@ -7102,18 +6712,14 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::htmlTITLE(const CHtmlElement &elm) void CGroupHTML::htmlTITLE(const CHtmlElement &elm)
{ {
_IgnoreChildElements = true;
// TODO: only from <head> // TODO: only from <head>
// if (!_ReadingHeadTag) return; // if (!_ReadingHeadTag) return;
if(!_TitlePrefix.empty())
_TitleString = _TitlePrefix + " - ";
else
_TitleString.clear();
_Title = true;
}
void CGroupHTML::htmlTITLEend(const CHtmlElement &elm) // consume all child elements
{ _TitleString = strFindReplaceAll(elm.serializeChilds(), std::string("\t"), std::string(" "));
_Title = false; _TitleString = strFindReplaceAll(_TitleString, std::string("\n"), std::string(" "));
setTitle(_TitleString); setTitle(_TitleString);
} }

@ -18,6 +18,7 @@
#include "stdpch.h" #include "stdpch.h"
#include "nel/gui/html_element.h" #include "nel/gui/html_element.h"
#include "nel/gui/libwww.h"
using namespace std; using namespace std;
using namespace NLMISC; using namespace NLMISC;
@ -137,6 +138,103 @@ namespace NLGUI
return ""; return "";
} }
// ***************************************************************************
std::string CHtmlElement::htmlEscape(std::string val, bool isAttribute) const
{
static const std::vector<std::string> searchReplace = {
"&", "&amp;",
"<", "&lt;",
">", "&gt;",
"\xA0", "&nbsp;",
};
for(uint i = 0; i < searchReplace.size(); i+=2)
val = strFindReplaceAll(val, searchReplace[i], searchReplace[i+1]);
if (isAttribute)
{
static const std::string q = "\"";
static const std::string quot = "&quot;";
val = strFindReplaceAll(val, q, quot);
}
return val;
}
// ***************************************************************************
std::string CHtmlElement::serializeAttributes() const
{
std::string result;
for(std::map<std::string, std::string>::const_iterator it = Attributes.begin(); it != Attributes.end(); ++it)
{
if (it->first == "class")
{
result += " class=\"";
for(std::set<std::string>::const_iterator it2 = ClassNames.begin(); it2 != ClassNames.end(); ++it2)
{
if (it2 != ClassNames.begin())
{
result += " ";
}
result += htmlEscape(*it2, true);
}
result += "\"";
}
else
{
result += " " + it->first + "=\"" + htmlEscape(it->second, true) + "\"";
}
}
return result;
}
// ***************************************************************************
std::string CHtmlElement::serializeChilds() const
{
std::string result;
for(std::list<CHtmlElement>::const_iterator it = Children.begin(); it != Children.end(); ++it)
result += it->serialize();
return result;
}
// ***************************************************************************
std::string CHtmlElement::serialize() const
{
if (Type == TEXT_NODE)
{
if (parent && (parent->ID == HTML_SCRIPT || parent->ID == HTML_STYLE ||
parent->ID == HTML_IFRAME || parent->ID == HTML_NOEMBED ||
parent->ID == HTML_NOSCRIPT))
{
return Value;
} else {
return htmlEscape(Value);
}
}
std::string result = "<" + Value + serializeAttributes() + ">";
if (ID == HTML_AREA || ID == HTML_BASE || ID == HTML_BR ||
ID == HTML_COL || ID == HTML_EMBED || ID == HTML_HR ||
ID == HTML_IMG || ID == HTML_INPUT || ID == HTML_LINK ||
ID == HTML_META || ID == HTML_PARAM || ID == HTML_WBR)
{
return result;
}
// first linebreak that will be ignored on parse time
if (ID == HTML_PRE || ID == HTML_TEXTAREA)
result += "\n";
if (!Children.empty())
result += serializeChilds();
result += "</" + Value + ">";
return result;
}
// *************************************************************************** // ***************************************************************************
std::string CHtmlElement::toString(bool tree, uint depth) const std::string CHtmlElement::toString(bool tree, uint depth) const
{ {

@ -32,7 +32,7 @@ CStreamedPackage::~CStreamedPackage()
// release // release
} }
void CStreamedPackage::serial(NLMISC::IStream &f) throw(NLMISC::EStream) void CStreamedPackage::serial(NLMISC::IStream &f)
{ {
f.serialCheck(NELID("SNPK")); f.serialCheck(NELID("SNPK"));
@ -42,7 +42,7 @@ void CStreamedPackage::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
f.serialCont(Entries); f.serialCont(Entries);
} }
void CStreamedPackage::CEntry::serial(NLMISC::IStream &f) throw(NLMISC::EStream) void CStreamedPackage::CEntry::serial(NLMISC::IStream &f)
{ {
uint version = 1; uint version = 1;
f.serialVersion(version); f.serialVersion(version);

@ -37,3 +37,8 @@ ENDIF()
IF(WITH_NEL_TESTS) IF(WITH_NEL_TESTS)
ADD_SUBDIRECTORY(nel_unit_test) ADD_SUBDIRECTORY(nel_unit_test)
ENDIF() ENDIF()
IF(WITH_HTMLCSS_TEST)
ADD_SUBDIRECTORY(htmlcss_test)
ENDIF()

@ -0,0 +1,15 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
CMAKE_POLICY(SET CMP0015 NEW)
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${CMAKE_LIBRARY_DIR})
ADD_DEFINITIONS(${LIBXML2_DEFINITIONS})
FILE(GLOB SRC htmlcss_test.cpp)
ADD_EXECUTABLE(htmlcss_test ${SRC})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${LUA_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR} )
TARGET_LINK_LIBRARIES(htmlcss_test nelmisc nelgui ${LUA_LIBRARIES} ${LIBXML2_LIBRARIES})
NL_DEFAULT_PROPS(htmlcss_test "Ryzom, Tests: html/css parser tests")
NL_ADD_RUNTIME_FLAGS(htmlcss_test)
INSTALL(TARGETS htmlcss_test RUNTIME DESTINATION bin COMPONENT tools)
# TODO: test fixtures

@ -0,0 +1,183 @@
/*
* File: main.cpp
* Author: Karu <nimetu@gmail.com>
*
* Created on 2015-04-11
*/
typedef struct _xmlNode xmlNode;
#include <string>
#include <fstream>
#include "nel/misc/types_nl.h"
#include "nel/misc/file.h"
#include "nel/misc/path.h"
#include "nel/gui/html_parser.h"
#include "nel/gui/css_parser.h"
#include "nel/gui/html_element.h"
#include "nel/gui/css_style.h"
#include "nel/gui/libwww.h"
using namespace std;
using namespace NLMISC;
using namespace NLGUI;
sint indent { 0 };
// ***************************************************************************
void checkRuleset(CHtmlElement &elm, CCssStyle &style, TStyleVec testset, bool exists)
{
bool verbose = false;
std::string existsMessage = exists ? "exist" : "unset";
for (auto it : testset)
{
bool failed = (exists != style.hasStyle(it.first));
if (failed)
{
bool failed2 = true;
if (it.first == "font-size")
{
printf("[%s]: font-size: %d; expected '%s'\n", existsMessage.c_str(), style.Current.FontSize, it.second.c_str());
printf(" (%s)\n", elm.toString().c_str());
failed2 = false;
}
else if (it.first == "background-color")
{
printf("[%s]: background-color: '%s'; expected '%s'\n", existsMessage.c_str(), style.Current.BackgroundColor.toString().c_str(), it.second.c_str());
printf(" (%s)\n", elm.toString().c_str());
failed2 = false;
}
if (failed2)
{
printf("[%s] FAIL: '%s': '%s'\n", existsMessage.c_str(), it.first.c_str(), it.second.c_str());
printf(" (%s)\n", elm.toString().c_str());
for (auto it2 : style.Current.StyleRules)
printf("'%s': '%s'\n", it2.first.c_str(), it2.second.c_str());
}
}
else if (exists && !style.checkStyle(it.first, it.second))
{
printf("[%s] FAIL: expecting '%s': '%s', got '%s'\n", existsMessage.c_str(), it.first.c_str(), it.second.c_str(), style.getStyle(it.first).c_str());
printf(" (%s)\n", elm.toString().c_str());
}
else if (!failed)
{
if (verbose)
printf("[%s] PASS: '%s': '%s'\n", existsMessage.c_str(), it.first.c_str(), it.second.c_str());
}
}
}
// ***************************************************************************
void recursiveHtmlRender(CHtmlElement &elm, CCssStyle &style)
{
bool verbose = false;
if (elm.Type == CHtmlElement::TEXT_NODE)
{
std::string val = trim(elm.Value);
if (verbose)
if (!val.empty())
printf("[%d] '%s'\n", indent, val.c_str());
}
else if (elm.Type == CHtmlElement::ELEMENT_NODE)
{
style.pushStyle();
if (verbose)
printf("========= '%s'\n", elm.toString().c_str());
style.getStyleFor(elm);
style.applyStyle(elm.Style);
if (elm.hasAttribute("data-ruleset"))
{
TStyleVec testset = CCssParser::parseDecls(elm.getAttribute("data-ruleset"));
checkRuleset(elm, style, testset, true);
}
if (elm.hasAttribute("data-ruleunset"))
{
TStyleVec testset = CCssParser::parseDecls(elm.getAttribute("data-ruleunset"));
checkRuleset(elm, style, testset, false);
}
if (elm.hasAttribute("data-ruleset-before"))
{
TStyleVec testset = CCssParser::parseDecls(elm.getAttribute("data-ruleset-before"));
}
for (auto it = elm.Children.begin(); it != elm.Children.end(); ++it)
{
recursiveHtmlRender(*it, style);
}
style.popStyle();
}
}
// ***************************************************************************
void runTestOnFile(const std::string &filename)
{
CHtmlElement dom;
CHtmlParser htmlParser;
std::vector<CHtmlParser::StyleLink> links;
std::vector<std::string> styles;
//, elm, styles, links
ifstream f(filename);
if (!f.is_open())
{
printf("!! failed to open file '%s'\n", filename.c_str());
return;
}
printf(": %s\n", filename.c_str());
std::string htmlString;
std::string line;
while (getline(f, line))
htmlString += line;
htmlParser.getDOM(htmlString, dom, styles, links);
CCssStyle style;
for (std::string s : styles)
{
if (!s.empty())
style.parseStylesheet(s);
}
for (auto it = dom.Children.begin(); it != dom.Children.end(); ++it)
recursiveHtmlRender(*it, style);
}
// ***************************************************************************
int main(int argc, const char *argv[])
{
CApplicationContext *appContext = new CApplicationContext;
// htmlcss_test file.html
if (argc == 2)
{
runTestOnFile(argv[1]);
}
else
{
std::vector<std::string> result;
CPath::getPathContent("tests/", true /*recursive*/, false /*wantDir*/, true /*wantFile*/, result, NULL /*callback*/, true /*showEverything*/);
printf(":: got %ld files\n", result.size());
for (const auto &fname : result)
{
if (endsWith(fname, ".html") && fname != "tests/XX-template.html")
runTestOnFile(fname);
}
}
printf(">>> all done\n");
return EXIT_SUCCESS;
}

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<body>
<style>
:lang(en) { --text: '(en)'; }
:lang(de-DE) { --text: '(de-DE)'; }
a { test: " (" var(--lang) ")"}
div {
/* '--a' and '--b' are both 'initial' */
--should-not-exist: var(--a, var(--b, ( "p() " ) ), { "b" [ "r" ] });
/* 'before -var- after' */
--concate-test: 'before' var(--exists) 'after';
--exists: '-var-';
/* fallback should be at least one char */
--invalid-fallback: var(--exists,);
/* using fallback */
--fallback: var(--a, 'ok');
}
</style>
<div data-ruleset="--concate-test: 'before' '-var-' 'after'; --exists: '-var-'; --fallback: 'ok';"
data-ruleunset="--should-not-exists: 1; --invalid-fallback: 1;" />
<a lang="en" data-ruleset="--text: '(en)';">link</a>
<a lang="de" data-ruleunset="--text: 1;">link</a>
</body>
</html>

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<body>
<style>
p {
--mq-sm: initial;
}
.small {
--mq-sm: ;
}
p {
--padding-when-small: var(--mq-sm) 2rem;
--padding-when-large: 4rem;
padding: var(--padding-when-small, var(--padding-when-large));
}
</style>
<p data-ruleset="padding-left: 4rem;" comment="--mq-sm==initial, should use fallback value" />
<div>
<p class="small" data-ruleset="padding-left: 2rem;" comment="--mq-sm==;, should use defined value"/>
</div>
</body>
</html>

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<body>
<style>
:root {
--main-color: #06c;
--accent-color: #006;
}
/* The rest of the CSS file */
#foo h1 {
color: var(--main-color);
}
</style>
<div id="foo">
<h1 data-ruleset="color: #06c;">Header</h1>
</div>
</body>
</html>

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<body>
<style>
:root {
--main-color: #06c;
--accent-color: #006;
--MAIN-COLOR: #f00;
}
/* The rest of the CSS file */
#foo h1 {
color: var(--main-color);
}
h2 {
color: var(--MAIN-COLOR);
}
</style>
<div id="foo">
<h1 data-ruleset="color: #06c;">Header1</h1>
<h2 data-ruleset="color: #f00;">Header2</h1>
</div>
</body>
</html>

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<body>
<style>
:root {
--foo: if(x > 5) this.width = 10;
}
/* The rest of the CSS file */
#foo h1 {
test: var(--foo)
}
</style>
<div id="foo">
<h1 data-ruleset="test: if(x > 5) this.width = 10;">Header</h1>
</div>
</body>
</html>

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<body>
<style>
:root { --color: blue; }
div { --color: green; }
#alert { --color: red; }
* { color: var(--color); }
</style>
<p data-ruleset="color: blue;">I inherited blue from the root element!</p>
<div data-ruleset="color: green;">I got green set directly on me!</div>
<div id='alert' data-ruleset="color: red;">
While I got red set directly on me!
<p data-ruleset="color: red;">Im red too, because of inheritance!</p>
</div>
</body>
</html>

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<body>
<style>
a:lang(en) {--lang: 'en';}
a:lang(de) {--lang: 'de';}
a { test: var(--lang); }
</style>
<a lang="en" data-ruleset="test: 'en';">link</a>
<a lang="de" data-ruleset="test: 'de';">link</a>
</body>
</html>

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<body>
<style>
:root {
--main-color: #c06;
--accent-background: var(--main-color);
}
div {
test: var(--accent-background);
}
</style>
<div data-ruleset="test: #c06;"/>
</body>
</html>

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<body>
<style>
div {
--one: calc(var(--two) + 20px);
--two: calc(var(--one) - 20px);
--ok: 'ok';
}
</style>
<div data-ruleset="--ok: 'ok';"
data-ruleunset="--one: 1; --two: 1;" />
</body>
</html>

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<body>
<style>
one { --foo: 10px; }
two { --bar: calc(var(--foo) + 10px); }
three { --foo: calc(var(--bar) + 10px); }
</style>
<one data-ruleset="--foo: 10px;">
<two data-ruleset="--bar: calc( 10px + 10px);">
<three data-ruleset="--foo: calc( calc( 10px + 10px) + 10px);"/>
</two>
</one>
</body>
</html>

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<body>
<style>
/* In the components style: */
.component .header {
color: var(--header-color, blue);
}
.component .text {
color: var(--text-color, black);
}
/* In the larger applications style: */
.component {
--text-color: #080;
/* header-color isnt set, and so remains blue, the fallback value */
}
</style>
<div class="component">
<h1 class="header" data-ruleset="color: blue;">header</h1>
<p class="text" data-ruleset="color: #080;">text</p>
</div>
</body>
</html>

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<body>
<style>
div {
--side: margin-top;
var(--side): 20px;
}
</style>
<div data-ruleset="--side: margin-top;" data-ruleunset="var(--side): 1;" />
</body>
</html>

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<body>
<style>
div {
--gap: 20;
margin-top: var(--gap)px;
}
</style>
<!-- should have whitespace, ie '20 px' -->
<div data-ruleset="margin-top: 20 px;" />
</body>
</html>

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<body>
<style>
:root { --not-a-color: 20px; }
p { background-color: red; }
p { background-color: var(--not-a-color); }
</style>
<!-- this should have 'red' because var() has invalid value for color -->
<!-- TODO: not really supported by NEL currently -->
<div data-ruleset="background-color: red;" />
</body>
</html>

@ -170,8 +170,8 @@ void CGroupQuickHelp::setGroupTextSize (CInterfaceGroup *group, bool selected)
{ {
bool globalColor = selected ? TextColorGlobalColor : _NonSelectedGlobalColor; bool globalColor = selected ? TextColorGlobalColor : _NonSelectedGlobalColor;
bool linkGlobalColor = selected ? LinkColorGlobalColor : _NonSelectedGlobalColor; bool linkGlobalColor = selected ? LinkColorGlobalColor : _NonSelectedGlobalColor;
uint fontSize = selected ? TextFontSize : _NonSelectedSize; uint fontSize = selected ? _BrowserStyle.Current.FontSize : _NonSelectedSize;
NLMISC::CRGBA color = selected ? TextColor : _NonSelectedColor; NLMISC::CRGBA color = selected ? _BrowserStyle.Current.TextColor : _NonSelectedColor;
NLMISC::CRGBA linkColor = selected ? LinkColor : _NonSelectedLinkColor; NLMISC::CRGBA linkColor = selected ? LinkColor : _NonSelectedLinkColor;
// Look for text in this group // Look for text in this group

Loading…
Cancel
Save