LibWeb: Support setting dimensions on input image buttons

Users are allowed to specify the height and width of an image button
directly in the HTML.
This commit is contained in:
Timothy Flynn 2024-02-19 07:31:47 -05:00 committed by Andreas Kling
parent 3ea26327c7
commit 3f3db34587
Notes: sideshowbarker 2024-07-17 06:00:02 +09:00
4 changed files with 45 additions and 9 deletions

View file

@ -26,6 +26,7 @@
#include <LibWeb/HTML/HTMLFormElement.h>
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/Numbers.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/SharedImageRequest.h>
#include <LibWeb/HTML/Window.h>
@ -1311,6 +1312,24 @@ i32 HTMLInputElement::default_tab_index_value() const
return 0;
}
// https://html.spec.whatwg.org/multipage/input.html#image-button-state-(type=image):the-input-element-11
void HTMLInputElement::apply_presentational_hints(CSS::StyleProperties& style) const
{
// The input element supports dimension attributes.
if (type_state() != TypeAttributeState::ImageButton)
return;
for_each_attribute([&](auto& name, auto& value) {
if (name == HTML::AttributeNames::width) {
if (auto parsed_value = parse_dimension_value(value))
style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull());
} else if (name == HTML::AttributeNames::height) {
if (auto parsed_value = parse_dimension_value(value))
style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
}
});
}
// https://html.spec.whatwg.org/multipage/input.html#the-size-attribute
unsigned HTMLInputElement::size() const
{