From cafdefbf4a1cacd303290eb5720ddb9dd0c3f7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 10 May 2026 01:55:19 -0300 Subject: [PATCH] Fix auto-size for HTML images. Added visibility property support. Fix display: none. Added figure and figcaption HTML tags. --- include/eepp/ui/css/propertydefinition.hpp | 1 + src/eepp/ui/css/propertyspecification.cpp | 10 +++++----- src/eepp/ui/css/stylesheetparser.cpp | 3 ++- src/eepp/ui/css/stylesheetproperty.cpp | 9 ++++++--- src/eepp/ui/css/stylesheetspecification.cpp | 1 + src/eepp/ui/uihtmlwidget.cpp | 8 ++++++-- src/eepp/ui/uiimage.cpp | 4 +++- src/eepp/ui/uiwidget.cpp | 3 +++ src/eepp/ui/uiwidgetcreator.cpp | 2 ++ 9 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/eepp/ui/css/propertydefinition.hpp b/include/eepp/ui/css/propertydefinition.hpp index 33e0a468c..168d03e47 100644 --- a/include/eepp/ui/css/propertydefinition.hpp +++ b/include/eepp/ui/css/propertydefinition.hpp @@ -35,6 +35,7 @@ enum class PropertyId : Uint32 { ForegroundBottomLeftRadius = String::hash( "foreground-bottom-left-radius" ), ForegroundBottomRightRadius = String::hash( "foreground-bottom-right-radius" ), Visible = String::hash( "visible" ), + Visibility = String::hash( "visibility" ), Enabled = String::hash( "enabled" ), Theme = String::hash( "theme" ), Skin = String::hash( "skin" ), diff --git a/src/eepp/ui/css/propertyspecification.cpp b/src/eepp/ui/css/propertyspecification.cpp index 4ccc485df..727d58a6e 100644 --- a/src/eepp/ui/css/propertyspecification.cpp +++ b/src/eepp/ui/css/propertyspecification.cpp @@ -8,17 +8,17 @@ SINGLETON_DECLARE_IMPLEMENTATION( PropertySpecification ) PropertySpecification::~PropertySpecification() {} -PropertyDefinition& PropertySpecification::registerProperty( const std::string& propertyVame, +PropertyDefinition& PropertySpecification::registerProperty( const std::string& propertyName, const std::string& defaultValue, bool inherited ) { - PropertyDefinition* property = const_cast( getProperty( propertyVame ) ); + PropertyDefinition* property = const_cast( getProperty( propertyName ) ); - if ( nullptr != property ) { - Log::warning( "Property \"%s\" already registered.", propertyVame.c_str() ); + if ( nullptr != property && !String::startsWith( propertyName, "-" ) ) { + Log::warning( "Property \"%s\" already registered.", propertyName.c_str() ); return *property; } - PropertyDefinition* propDef = new PropertyDefinition( propertyVame, defaultValue, inherited ); + PropertyDefinition* propDef = new PropertyDefinition( propertyName, defaultValue, inherited ); mProperties[propDef->getId()] = std::shared_ptr( propDef ); diff --git a/src/eepp/ui/css/stylesheetparser.cpp b/src/eepp/ui/css/stylesheetparser.cpp index c8fc2cd8f..30ca21400 100644 --- a/src/eepp/ui/css/stylesheetparser.cpp +++ b/src/eepp/ui/css/stylesheetparser.cpp @@ -123,7 +123,8 @@ bool StyleSheetParser::parse( std::string& css, std::vector& import mediaParse( css, rs, pos, buffer, importedList ); } else if ( String::startsWith( buffer, "@import" ) ) { importParse( css, pos, buffer, importedList ); - } else if ( String::startsWith( buffer, "@keyframes" ) ) { + } else if ( String::startsWith( buffer, "@keyframes" ) || + String::startsWith( buffer, "@-webkit-keyframes" ) ) { keyframesParse( css, rs, pos, buffer ); } } diff --git a/src/eepp/ui/css/stylesheetproperty.cpp b/src/eepp/ui/css/stylesheetproperty.cpp index 632f5a0be..fe558eacf 100644 --- a/src/eepp/ui/css/stylesheetproperty.cpp +++ b/src/eepp/ui/css/stylesheetproperty.cpp @@ -37,7 +37,8 @@ StyleSheetProperty::StyleSheetProperty( const PropertyDefinition* definition, createIndexed(); checkVars(); - if ( NULL == mShorthandDefinition && NULL == mPropertyDefinition ) { + if ( NULL == mShorthandDefinition && NULL == mPropertyDefinition && + !String::startsWith( mName, "-" ) ) { Log::warning( "Property \"%s\" is not defined!", mName ); } } @@ -60,7 +61,8 @@ StyleSheetProperty::StyleSheetProperty( bool isVolatile, const PropertyDefinitio checkImportant(); checkVars(); - if ( NULL == mShorthandDefinition && NULL == mPropertyDefinition ) { + if ( NULL == mShorthandDefinition && NULL == mPropertyDefinition && + !String::startsWith( mName, "-" ) ) { Log::warning( "Property \"%s\" is not defined!", mName ); } } @@ -86,7 +88,8 @@ StyleSheetProperty::StyleSheetProperty( const std::string& name, const std::stri createIndexed(); checkVars(); - if ( NULL == mShorthandDefinition && NULL == mPropertyDefinition ) { + if ( NULL == mShorthandDefinition && NULL == mPropertyDefinition && + !String::startsWith( mName, "-" ) ) { Log::warning( "Property \"%s\" is not defined!", mName ); } } diff --git a/src/eepp/ui/css/stylesheetspecification.cpp b/src/eepp/ui/css/stylesheetspecification.cpp index daa6acf04..c9748f41e 100644 --- a/src/eepp/ui/css/stylesheetspecification.cpp +++ b/src/eepp/ui/css/stylesheetspecification.cpp @@ -130,6 +130,7 @@ void StyleSheetSpecification::registerDefaultProperties() { .setType( PropertyType::ForegroundSize ) .setIndexed(); registerProperty( "visible", "true" ).setType( PropertyType::Bool ); + registerProperty( "visibility", "visible" ).setType( PropertyType::String ); registerProperty( "enabled", "true" ).setType( PropertyType::Bool ); registerProperty( "theme", "" ); registerProperty( "skin", "" ); diff --git a/src/eepp/ui/uihtmlwidget.cpp b/src/eepp/ui/uihtmlwidget.cpp index c6eea656b..8093dfda4 100644 --- a/src/eepp/ui/uihtmlwidget.cpp +++ b/src/eepp/ui/uihtmlwidget.cpp @@ -22,9 +22,8 @@ UIHTMLWidget::~UIHTMLWidget() { } UILayouter* UIHTMLWidget::getLayouter() { - if ( !mLayouter ) { + if ( nullptr == mLayouter ) mLayouter = UILayouterManager::create( mDisplay, this ); - } return mLayouter; } @@ -52,6 +51,8 @@ void UIHTMLWidget::onDisplayChange() { void UIHTMLWidget::setDisplay( CSSDisplay display ) { if ( mDisplay != display ) { mDisplay = display; + mNodeFlags |= NODE_FLAG_OVER_FIND_ALLOWED; + if ( mDisplay == CSSDisplay::InlineBlock || mDisplay == CSSDisplay::Inline ) { if ( getLayoutWidthPolicy() == SizePolicy::MatchParent ) setLayoutWidthPolicy( SizePolicy::WrapContent ); @@ -59,7 +60,10 @@ void UIHTMLWidget::setDisplay( CSSDisplay display ) { if ( getLayoutWidthPolicy() == SizePolicy::WrapContent && mPosition != CSSPosition::Absolute && mPosition != CSSPosition::Fixed ) setLayoutWidthPolicy( SizePolicy::MatchParent ); + } else if ( mDisplay == CSSDisplay::None ) { + mNodeFlags &= ~NODE_FLAG_OVER_FIND_ALLOWED; } + onDisplayChange(); } } diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index f3600a165..a53d52102 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -91,7 +91,9 @@ void UIImage::onAutoSize() { if ( nullptr == mDrawable ) return; - Sizef drawableSize = mDrawable->getPixelsSize(); + Sizef drawableSize = mFlags & UI_HTML_ELEMENT + ? mDrawable->getPixelsSize() * PixelDensity::getPixelDensity() + : mDrawable->getPixelsSize(); if ( drawableSize.getWidth() <= 0 || drawableSize.getHeight() <= 0 ) return; diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index d6fca39c0..bcbbf1f89 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -2029,6 +2029,9 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::Visible: setVisible( attribute.asBool() ); break; + case PropertyId::Visibility: + setVisible( attribute.value() == "hidden" ? false : true ); + break; case PropertyId::Enabled: setEnabled( attribute.asBool() ); break; diff --git a/src/eepp/ui/uiwidgetcreator.cpp b/src/eepp/ui/uiwidgetcreator.cpp index 7c0e54505..f6d644fff 100644 --- a/src/eepp/ui/uiwidgetcreator.cpp +++ b/src/eepp/ui/uiwidgetcreator.cpp @@ -195,6 +195,8 @@ void UIWidgetCreator::createBaseWidgetList() { registeredWidget["input"] = [] { return UIHTMLInput::New(); }; registeredWidget["header"] = [] { return UIRichText::NewWithTag( "header" ); }; registeredWidget["article"] = [] { return UIRichText::NewWithTag( "article" ); }; + registeredWidget["figure"] = [] { return UIRichText::NewWithTag( "figure" ); }; + registeredWidget["figcaption"] = [] { return UIRichText::NewWithTag( "figcaption" ); }; registeredWidget["footer"] = [] { return UIRichText::NewWithTag( "footer" ); }; registeredWidget["main"] = [] { return UIRichText::NewWithTag( "main" ); }; registeredWidget["section"] = [] { return UIRichText::NewWithTag( "section" ); };