mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 21:21:50 +03:00
LibWeb: Add HTMLPreElement width property
This commit is contained in:
parent
2e8ff1855c
commit
089a98607c
Notes:
sideshowbarker
2024-07-16 22:22:13 +09:00
Author: https://github.com/bplaat Commit: https://github.com/SerenityOS/serenity/commit/089a98607c Pull-request: https://github.com/SerenityOS/serenity/pull/23261 Reviewed-by: https://github.com/ADKaster ✅
3
Tests/LibWeb/Text/expected/HTML/pre-width.txt
Normal file
3
Tests/LibWeb/Text/expected/HTML/pre-width.txt
Normal file
@ -0,0 +1,3 @@
|
||||
1. 20
|
||||
2. 0
|
||||
3. 0
|
29
Tests/LibWeb/Text/input/HTML/pre-width.html
Normal file
29
Tests/LibWeb/Text/input/HTML/pre-width.html
Normal file
@ -0,0 +1,29 @@
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let testCounter = 1;
|
||||
function testPart(part) {
|
||||
println(`${testCounter++}. ${JSON.stringify(part())}`);
|
||||
}
|
||||
|
||||
// 1. Set the pre element width attributes
|
||||
testPart(() => {
|
||||
const pre = document.createElement('pre');
|
||||
pre.width = 20;
|
||||
return pre.width;
|
||||
});
|
||||
|
||||
// 2. Set the pre element width attributes with invalid data
|
||||
testPart(() => {
|
||||
const pre = document.createElement('pre');
|
||||
pre.width = 'dsafds';
|
||||
return pre.width;
|
||||
});
|
||||
|
||||
// 3. Get the pre element width attribute default value
|
||||
testPart(() => {
|
||||
const pre = document.createElement('pre');
|
||||
return pre.width;
|
||||
});
|
||||
});
|
||||
</script>
|
@ -8,6 +8,7 @@
|
||||
#include <LibWeb/CSS/StyleProperties.h>
|
||||
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
|
||||
#include <LibWeb/HTML/HTMLPreElement.h>
|
||||
#include <LibWeb/HTML/Numbers.h>
|
||||
|
||||
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<void> HTMLPreElement::set_width(WebIDL::Long width)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::width, MUST(String::number(width)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <LibWeb/ARIA/Roles.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/WebIDL/Types.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
@ -21,6 +22,9 @@ public:
|
||||
// https://www.w3.org/TR/html-aria/#el-pre
|
||||
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::generic; }
|
||||
|
||||
WebIDL::Long width() const;
|
||||
WebIDL::ExceptionOr<void> set_width(WebIDL::Long);
|
||||
|
||||
private:
|
||||
HTMLPreElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
|
@ -7,6 +7,6 @@ interface HTMLPreElement : HTMLElement {
|
||||
[HTMLConstructor] constructor();
|
||||
|
||||
// Obsolete
|
||||
// FIXME: [CEReactions, Reflect] attribute long width;
|
||||
[CEReactions] attribute long width;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user