LibWeb: Hide audio element when controls is not set

When an audio element has no controls attribute,
it should not render at all and take up no space.
This commit is contained in:
Psychpsyo 2025-01-04 12:13:40 +01:00 committed by Sam Atkins
commit 8632ce5cdd
Notes: github-actions[bot] 2025-01-04 11:48:09 +00:00
5 changed files with 45 additions and 5 deletions

View file

@ -34,4 +34,21 @@ GC::Ptr<Painting::Paintable> AudioBox::create_paintable() const
return Painting::AudioPaintable::create(*this);
}
bool AudioBox::should_paint() const
{
auto const& audio_element = dom_node();
return audio_element.has_attribute(HTML::AttributeNames::controls) || audio_element.is_scripting_disabled();
}
void AudioBox::prepare_for_replaced_layout()
{
if (should_paint()) {
set_natural_width(300);
set_natural_height(40);
} else {
set_natural_width(0);
set_natural_height(0);
}
}
}