LibWeb: Adjust buttons computed display style

This commit is contained in:
Lorenz A 2025-10-15 11:57:00 +02:00 committed by Sam Atkins
parent 4bcb34d7a0
commit f54793315c
Notes: github-actions[bot] 2025-11-01 13:03:55 +00:00
5 changed files with 41 additions and 20 deletions

View file

@ -5,6 +5,8 @@
*/
#include <LibWeb/Bindings/HTMLButtonElementPrototype.h>
#include <LibWeb/CSS/ComputedProperties.h>
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/HTML/CommandEvent.h>
@ -29,6 +31,23 @@ void HTMLButtonElement::initialize(JS::Realm& realm)
Base::initialize(realm);
}
void HTMLButtonElement::adjust_computed_style(CSS::ComputedProperties& style)
{
// https://html.spec.whatwg.org/multipage/rendering.html#button-layout
// If the computed value of 'display' is 'inline-grid', 'grid', 'inline-flex', 'flex', 'none', or 'contents', then behave as the computed value.
auto display = style.display();
if (display.is_flex_inside() || display.is_grid_inside() || display.is_none() || display.is_contents()) {
// No-op
} else if (display.is_inline_outside()) {
// Otherwise, if the computed value of 'display' is a value such that the outer display type is 'inline', then behave as 'inline-block'.
// AD-HOC https://github.com/whatwg/html/issues/11857
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
} else {
// Otherwise, behave as 'flow-root'.
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::FlowRoot)));
}
}
HTMLButtonElement::TypeAttributeState HTMLButtonElement::type_state() const
{
auto value = get_attribute_value(HTML::AttributeNames::type);