diff --git a/Tests/LibWeb/Text/expected/HTML/pre-width.txt b/Tests/LibWeb/Text/expected/HTML/pre-width.txt new file mode 100644 index 0000000000..4f893904a9 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/pre-width.txt @@ -0,0 +1,3 @@ +1. 20 +2. 0 +3. 0 diff --git a/Tests/LibWeb/Text/input/HTML/pre-width.html b/Tests/LibWeb/Text/input/HTML/pre-width.html new file mode 100644 index 0000000000..e2598da8cf --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/pre-width.html @@ -0,0 +1,29 @@ + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.cpp index c757acee3e..ee2c2e7cf8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace Web::HTML { @@ -36,4 +37,20 @@ void HTMLPreElement::apply_presentational_hints(CSS::StyleProperties& style) con }); } +// https://html.spec.whatwg.org/multipage/obsolete.html#dom-pre-width +WebIDL::Long HTMLPreElement::width() const +{ + // The width IDL attribute of the pre element must reflect the content attribute of the same name. + if (auto width_string = get_attribute(HTML::AttributeNames::width); width_string.has_value()) { + if (auto width = parse_integer(*width_string); width.has_value()) + return *width; + } + return 0; +} + +WebIDL::ExceptionOr HTMLPreElement::set_width(WebIDL::Long width) +{ + return set_attribute(HTML::AttributeNames::width, MUST(String::number(width))); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.h b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.h index 97ae40f888..8d07a56b89 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.h @@ -8,6 +8,7 @@ #include #include +#include namespace Web::HTML { @@ -21,6 +22,9 @@ public: // https://www.w3.org/TR/html-aria/#el-pre virtual Optional default_role() const override { return ARIA::Role::generic; } + WebIDL::Long width() const; + WebIDL::ExceptionOr set_width(WebIDL::Long); + private: HTMLPreElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.idl index c59ad960dc..774c6362e9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.idl @@ -7,6 +7,6 @@ interface HTMLPreElement : HTMLElement { [HTMLConstructor] constructor(); // Obsolete - // FIXME: [CEReactions, Reflect] attribute long width; + [CEReactions] attribute long width; };