mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-20 08:18:55 +00:00
LibWeb: Add select element size property
This commit is contained in:
parent
abb4b6d117
commit
4e5ce7b63e
Notes:
sideshowbarker
2024-07-17 02:05:41 +09:00
Author: https://github.com/bplaat
Commit: 4e5ce7b63e
Pull-request: https://github.com/SerenityOS/serenity/pull/23895
Reviewed-by: https://github.com/shannonbooth
5 changed files with 46 additions and 1 deletions
|
@ -4,3 +4,6 @@
|
||||||
4. 3
|
4. 3
|
||||||
5. "three"
|
5. "three"
|
||||||
6. "Three"
|
6. "Three"
|
||||||
|
7. 45
|
||||||
|
8. 0
|
||||||
|
9. 0
|
||||||
|
|
|
@ -74,5 +74,26 @@
|
||||||
`;
|
`;
|
||||||
return select.value;
|
return select.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 7. Set select size property
|
||||||
|
testPart(() => {
|
||||||
|
const select = document.createElement('select');
|
||||||
|
select.size = '45';
|
||||||
|
return select.size;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 8. Set select size property invalid
|
||||||
|
testPart(() => {
|
||||||
|
const select = document.createElement('select');
|
||||||
|
select.size = '12';
|
||||||
|
select.size = 'fadsfsd';
|
||||||
|
return select.size;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 9. Get select size default
|
||||||
|
testPart(() => {
|
||||||
|
const select = document.createElement('select');
|
||||||
|
return select.size;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <LibWeb/HTML/HTMLOptGroupElement.h>
|
#include <LibWeb/HTML/HTMLOptGroupElement.h>
|
||||||
#include <LibWeb/HTML/HTMLOptionElement.h>
|
#include <LibWeb/HTML/HTMLOptionElement.h>
|
||||||
#include <LibWeb/HTML/HTMLSelectElement.h>
|
#include <LibWeb/HTML/HTMLSelectElement.h>
|
||||||
|
#include <LibWeb/HTML/Numbers.h>
|
||||||
#include <LibWeb/Infra/Strings.h>
|
#include <LibWeb/Infra/Strings.h>
|
||||||
#include <LibWeb/Layout/Node.h>
|
#include <LibWeb/Layout/Node.h>
|
||||||
#include <LibWeb/Namespace.h>
|
#include <LibWeb/Namespace.h>
|
||||||
|
@ -67,6 +68,22 @@ void HTMLSelectElement::adjust_computed_style(CSS::StyleProperties& style)
|
||||||
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
|
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-size
|
||||||
|
WebIDL::UnsignedLong HTMLSelectElement::size() const
|
||||||
|
{
|
||||||
|
// The size IDL attribute must reflect the respective content attributes of the same name. The size IDL attribute has a default value of 0.
|
||||||
|
if (auto size_string = get_attribute(HTML::AttributeNames::size); size_string.has_value()) {
|
||||||
|
if (auto size = parse_non_negative_integer(*size_string); size.has_value())
|
||||||
|
return *size;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<void> HTMLSelectElement::set_size(WebIDL::UnsignedLong size)
|
||||||
|
{
|
||||||
|
return set_attribute(HTML::AttributeNames::size, MUST(String::number(size)));
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
|
||||||
JS::GCPtr<HTMLOptionsCollection> const& HTMLSelectElement::options()
|
JS::GCPtr<HTMLOptionsCollection> const& HTMLSelectElement::options()
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <LibWeb/HTML/HTMLElement.h>
|
#include <LibWeb/HTML/HTMLElement.h>
|
||||||
#include <LibWeb/HTML/HTMLOptionsCollection.h>
|
#include <LibWeb/HTML/HTMLOptionsCollection.h>
|
||||||
#include <LibWeb/HTML/SelectItem.h>
|
#include <LibWeb/HTML/SelectItem.h>
|
||||||
|
#include <LibWeb/WebIDL/Types.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
@ -28,6 +29,9 @@ public:
|
||||||
|
|
||||||
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
||||||
|
|
||||||
|
WebIDL::UnsignedLong size() const;
|
||||||
|
WebIDL::ExceptionOr<void> set_size(WebIDL::UnsignedLong);
|
||||||
|
|
||||||
JS::GCPtr<HTMLOptionsCollection> const& options();
|
JS::GCPtr<HTMLOptionsCollection> const& options();
|
||||||
|
|
||||||
size_t length();
|
size_t length();
|
||||||
|
|
|
@ -13,7 +13,7 @@ interface HTMLSelectElement : HTMLElement {
|
||||||
[CEReactions, Reflect] attribute boolean multiple;
|
[CEReactions, Reflect] attribute boolean multiple;
|
||||||
[CEReactions, Reflect] attribute DOMString name;
|
[CEReactions, Reflect] attribute DOMString name;
|
||||||
[CEReactions, Reflect] attribute boolean required;
|
[CEReactions, Reflect] attribute boolean required;
|
||||||
// FIXME: [CEReactions] attribute unsigned long size;
|
[CEReactions] attribute unsigned long size;
|
||||||
|
|
||||||
readonly attribute DOMString type;
|
readonly attribute DOMString type;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue