Fix auto-size for HTML images.

Added visibility property support.
Fix display: none.
Added figure and figcaption HTML tags.
This commit is contained in:
Martín Lucas Golini
2026-05-10 01:55:19 -03:00
parent 24bc5edd72
commit cafdefbf4a
9 changed files with 29 additions and 12 deletions

View File

@@ -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" ),

View File

@@ -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<PropertyDefinition*>( getProperty( propertyVame ) );
PropertyDefinition* property = const_cast<PropertyDefinition*>( 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<PropertyDefinition>( propDef );

View File

@@ -123,7 +123,8 @@ bool StyleSheetParser::parse( std::string& css, std::vector<std::string>& 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 );
}
}

View File

@@ -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 );
}
}

View File

@@ -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", "" );

View File

@@ -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();
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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" ); };