mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 23:39:02 +00:00
LibWeb: Implement the HTMLInputElement.width
attribute
This allows the width of an image button input to be set and queried.
This commit is contained in:
parent
8e3adbe082
commit
45a2823e08
Notes:
github-actions[bot]
2024-11-30 10:19:31 +00:00
Author: https://github.com/tcl3
Commit: 45a2823e08
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2645
5 changed files with 79 additions and 4 deletions
|
@ -47,6 +47,7 @@
|
|||
#include <LibWeb/MimeSniff/Resource.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/Painting/PaintableBox.h>
|
||||
#include <LibWeb/Selection/Selection.h>
|
||||
#include <LibWeb/UIEvents/EventNames.h>
|
||||
#include <LibWeb/UIEvents/MouseEvent.h>
|
||||
|
@ -1881,6 +1882,41 @@ WebIDL::ExceptionOr<void> HTMLInputElement::set_size(WebIDL::UnsignedLong value)
|
|||
return set_attribute(HTML::AttributeNames::size, String::number(value));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#dom-input-width
|
||||
WebIDL::UnsignedLong HTMLInputElement::width() const
|
||||
{
|
||||
const_cast<DOM::Document&>(document()).update_layout();
|
||||
|
||||
// When the input element's type attribute is not in the Image Button state, then no image is available.
|
||||
if (type_state() != TypeAttributeState::ImageButton)
|
||||
return 0;
|
||||
|
||||
// Return the rendered width of the image, in CSS pixels, if the image is being rendered.
|
||||
if (auto* paintable_box = this->paintable_box())
|
||||
return paintable_box->content_width().to_int();
|
||||
|
||||
// On setting [the width or height IDL attribute], they must act as if they reflected the respective content attributes of the same name.
|
||||
if (auto width_string = get_attribute(HTML::AttributeNames::width); width_string.has_value()) {
|
||||
if (auto width = parse_non_negative_integer(*width_string); width.has_value() && *width <= 2147483647)
|
||||
return *width;
|
||||
}
|
||||
|
||||
// ...or else the natural width and height of the image, in CSS pixels, if an image is available but not being rendered
|
||||
if (auto bitmap = current_image_bitmap())
|
||||
return bitmap->width();
|
||||
|
||||
// ...or else 0, if the image is not available or does not have intrinsic dimensions.
|
||||
return 0;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> HTMLInputElement::set_width(WebIDL::UnsignedLong value)
|
||||
{
|
||||
if (value > 2147483647)
|
||||
value = 0;
|
||||
|
||||
return set_attribute(HTML::AttributeNames::width, String::number(value));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#concept-input-value-string-number
|
||||
Optional<double> HTMLInputElement::convert_string_to_number(StringView input) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue