mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:08:13 +00:00
LibWeb: Add textarea cols and rows attribute
This commit is contained in:
parent
f3db0003c2
commit
7e6fc9c26e
3 changed files with 45 additions and 2 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <LibWeb/DOM/ShadowRoot.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/HTML/HTMLTextAreaElement.h>
|
||||
#include <LibWeb/HTML/Numbers.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -95,6 +96,42 @@ void HTMLTextAreaElement::form_associated_element_was_removed(DOM::Node*)
|
|||
set_shadow_root(nullptr);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-cols
|
||||
unsigned HTMLTextAreaElement::cols() const
|
||||
{
|
||||
// The cols and rows attributes are limited to only positive numbers with fallback. The cols IDL attribute's default value is 20.
|
||||
auto maybe_cols_string = get_attribute(HTML::AttributeNames::cols);
|
||||
if (maybe_cols_string.has_value()) {
|
||||
auto maybe_cols = parse_non_negative_integer(maybe_cols_string.value());
|
||||
if (maybe_cols.has_value())
|
||||
return maybe_cols.value();
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> HTMLTextAreaElement::set_cols(unsigned value)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::cols, MUST(String::number(value)));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-rows
|
||||
unsigned HTMLTextAreaElement::rows() const
|
||||
{
|
||||
// The cols and rows attributes are limited to only positive numbers with fallback. The rows IDL attribute's default value is 2.
|
||||
auto maybe_rows_string = get_attribute(HTML::AttributeNames::rows);
|
||||
if (maybe_rows_string.has_value()) {
|
||||
auto maybe_rows = parse_non_negative_integer(maybe_rows_string.value());
|
||||
if (maybe_rows.has_value())
|
||||
return maybe_rows.value();
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> HTMLTextAreaElement::set_rows(unsigned value)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::rows, MUST(String::number(value)));
|
||||
}
|
||||
|
||||
void HTMLTextAreaElement::create_shadow_tree_if_needed()
|
||||
{
|
||||
if (shadow_root_internal())
|
||||
|
|
|
@ -69,6 +69,12 @@ public:
|
|||
// https://www.w3.org/TR/html-aria/#el-textarea
|
||||
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::textbox; }
|
||||
|
||||
unsigned cols() const;
|
||||
WebIDL::ExceptionOr<void> set_cols(unsigned value);
|
||||
|
||||
unsigned rows() const;
|
||||
WebIDL::ExceptionOr<void> set_rows(unsigned value);
|
||||
|
||||
private:
|
||||
HTMLTextAreaElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ interface HTMLTextAreaElement : HTMLElement {
|
|||
[HTMLConstructor] constructor();
|
||||
|
||||
[CEReactions, Reflect] attribute DOMString autocomplete;
|
||||
// FIXME: [CEReactions] attribute unsigned long cols;
|
||||
[CEReactions] attribute unsigned long cols;
|
||||
[CEReactions, Reflect=dirname] attribute DOMString dirName;
|
||||
[CEReactions, Reflect] attribute boolean disabled;
|
||||
readonly attribute HTMLFormElement? form;
|
||||
|
@ -17,7 +17,7 @@ interface HTMLTextAreaElement : HTMLElement {
|
|||
[CEReactions, Reflect] attribute DOMString placeholder;
|
||||
[CEReactions, Reflect=readonly] attribute boolean readOnly;
|
||||
[CEReactions, Reflect] attribute boolean required;
|
||||
// FIXME: [CEReactions] attribute unsigned long rows;
|
||||
[CEReactions] attribute unsigned long rows;
|
||||
[CEReactions, Reflect] attribute DOMString wrap;
|
||||
|
||||
readonly attribute DOMString type;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue