mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Derive implicit aria-level for h1–h6 from tag name
This commit is contained in:
parent
d7f830cdd1
commit
c6b289c3dc
|
|
@ -26,8 +26,11 @@ public:
|
|||
|
||||
virtual Optional<String> aria_level() const override
|
||||
{
|
||||
// TODO: aria-level = the number in the element's tag name
|
||||
return get_attribute("aria-level"_fly_string);
|
||||
if (auto const attr = get_attribute(ARIA::AttributeNames::aria_level); attr.has_value())
|
||||
return attr;
|
||||
|
||||
// Implicit defaults to the number in the element's tag name.
|
||||
return MUST(local_name().to_string().substring_from_byte_offset(1));
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include <LibJS/Runtime/Date.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibUnicode/TimeZone.h>
|
||||
#include <LibWeb/ARIA/AriaData.h>
|
||||
#include <LibWeb/ARIA/StateAndProperties.h>
|
||||
#include <LibWeb/Bindings/InternalsPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
|
@ -308,6 +310,12 @@ String Internals::get_computed_label(DOM::Element& element)
|
|||
return MUST(element.accessible_name(active_document));
|
||||
}
|
||||
|
||||
String Internals::get_computed_aria_level(DOM::Element& element)
|
||||
{
|
||||
auto aria_data = MUST(ARIA::AriaData::build_data(element));
|
||||
return MUST(ARIA::state_or_property_to_string_value(ARIA::StateAndProperties::AriaLevel, *aria_data));
|
||||
}
|
||||
|
||||
u16 Internals::get_echo_server_port()
|
||||
{
|
||||
return s_echo_server_port;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ public:
|
|||
|
||||
String get_computed_role(DOM::Element& element);
|
||||
String get_computed_label(DOM::Element& element);
|
||||
String get_computed_aria_level(DOM::Element& element);
|
||||
|
||||
static u16 get_echo_server_port();
|
||||
static void set_echo_server_port(u16 port);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ interface Internals {
|
|||
|
||||
DOMString getComputedRole(Element element);
|
||||
DOMString getComputedLabel(Element element);
|
||||
DOMString getComputedAriaLevel(Element element);
|
||||
unsigned short getEchoServerPort();
|
||||
|
||||
undefined setBrowserZoom(double factor);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
1
|
||||
3
|
||||
5
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="include.js"></script>
|
||||
<script>
|
||||
test(async () => {
|
||||
const h1 = document.createElement('h1');
|
||||
document.body.appendChild(h1);
|
||||
println(await internals.getComputedAriaLevel(h1));
|
||||
|
||||
const h3 = document.createElement('h3');
|
||||
document.body.appendChild(h3);
|
||||
println(await internals.getComputedAriaLevel(h3));
|
||||
|
||||
const h2 = document.createElement('h2');
|
||||
h2.setAttribute('aria-level', '5');
|
||||
document.body.appendChild(h2);
|
||||
println(await internals.getComputedAriaLevel(h2));
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user