From 1be55fe79329c78f8ceaefe75a4159457fc4c570 Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Fri, 27 Dec 2024 17:41:18 +0900 Subject: [PATCH] LibWeb: Support the ariaActiveDescendantElement IDL attribute --- Libraries/LibWeb/ARIA/ARIAMixin.idl | 1 + Libraries/LibWeb/DOM/Element.cpp | 5 + Libraries/LibWeb/DOM/Element.h | 5 + .../html/dom/aria-element-reflection.txt | 33 + .../html/dom/aria-element-reflection.html | 846 ++++++++++++++++++ 5 files changed, 890 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/dom/aria-element-reflection.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/dom/aria-element-reflection.html diff --git a/Libraries/LibWeb/ARIA/ARIAMixin.idl b/Libraries/LibWeb/ARIA/ARIAMixin.idl index 294760cd65e2..a27828930999 100644 --- a/Libraries/LibWeb/ARIA/ARIAMixin.idl +++ b/Libraries/LibWeb/ARIA/ARIAMixin.idl @@ -1,6 +1,7 @@ // https://w3c.github.io/aria/#ARIAMixin interface mixin ARIAMixin { [CEReactions] attribute DOMString? role; + [Reflect=aria-activedescendant, CEReactions] attribute Element? ariaActiveDescendantElement; [CEReactions] attribute DOMString? ariaAtomic; [CEReactions] attribute DOMString? ariaAutoComplete; [CEReactions] attribute DOMString? ariaBrailleLabel; diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 6a4f1f666a1c..742010e19356 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -96,6 +96,7 @@ void Element::visit_edges(Cell::Visitor& visitor) SlottableMixin::visit_edges(visitor); Animatable::visit_edges(visitor); + visitor.visit(m_aria_active_descendant_element); visitor.visit(m_attributes); visitor.visit(m_inline_style); visitor.visit(m_class_list); @@ -2926,6 +2927,10 @@ void Element::attribute_changed(FlyString const& local_name, Optional co m_dir = Dir::Auto; else m_dir = {}; + } else if (local_name == ARIA::AttributeNames::aria_active_descendant) { + // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:concept-element-attributes-change-ext + // Set element's explicitly set attr-element to null. + m_aria_active_descendant_element = nullptr; } } diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index b7e8bedc0064..44b9bd44d87f 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -295,6 +295,9 @@ class Element ENUMERATE_ARIA_ATTRIBUTES #undef __ENUMERATE_ARIA_ATTRIBUTE + GC::Ptr aria_active_descendant_element() { return m_aria_active_descendant_element; } + void set_aria_active_descendant_element(GC::Ptr value) { m_aria_active_descendant_element = value; } + virtual bool exclude_from_accessibility_tree() const override; virtual bool include_in_accessibility_tree() const override; @@ -464,6 +467,8 @@ class Element bool m_in_top_layer { false }; OwnPtr m_counters_set; + + GC::Ptr m_aria_active_descendant_element; }; template<> diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/aria-element-reflection.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/aria-element-reflection.txt new file mode 100644 index 000000000000..17a448872e67 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/aria-element-reflection.txt @@ -0,0 +1,33 @@ +Harness status: OK + +Found 27 tests + +16 Pass +11 Fail +Pass aria-activedescendant element reflection +Pass aria-activedescendant If the content attribute is set directly, the IDL attribute getter always returns the first element whose ID matches the content attribute. +Pass aria-activedescendant Setting the IDL attribute to an element which is not the first element in DOM order with its ID causes the content attribute to be an empty string +Pass aria-activedescendant Setting an element reference that crosses into a shadow tree is disallowed, but setting one that is in a shadow inclusive ancestor is allowed. +Fail aria-errormessage +Pass ariaErrorMessageElement is not defined +Fail aria-details +Pass aria-activedescendant Deleting a reflected element should return null for the IDL attribute and the content attribute will be empty. +Pass aria-activedescendant Changing the ID of an element doesn't lose the reference. +Pass aria-activedescendant Reparenting an element into a descendant shadow scope hides the element reference. +Pass aria-activedescendant Reparenting referenced element cannot cause retargeting of reference. +Pass aria-activedescendant Element reference set in invalid scope remains intact throughout move to valid scope. +Fail aria-labelledby. +Fail aria-controls. +Fail aria-describedby. +Fail aria-flowto. +Fail aria-owns. +Fail shadow DOM behaviour for FrozenArray element reflection. +Fail Moving explicitly set elements across shadow DOM boundaries. +Fail Moving explicitly set elements around within the same scope, and removing from the DOM. +Pass aria-activedescendant Reparenting. +Pass aria-activedescendant Attaching element reference before it's inserted into the DOM. +Pass aria-activedescendant Cross-document references and moves. +Pass aria-activedescendant Adopting element keeps references. +Pass Caching invariant different attributes. +Pass Caching invariant different elements. +Fail Passing values of the wrong type should throw a TypeError \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/aria-element-reflection.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/aria-element-reflection.html new file mode 100644 index 000000000000..7dc5ded0670b --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/aria-element-reflection.html @@ -0,0 +1,846 @@ + + + + + Element Reflection for aria-activedescendant and aria-errormessage + + + + + + +
+ +
+
Item 1
+
Item 2
+
+ + + +
+
Item 1
+
Item 2
+
+ + + +
+
+
+
+ + + +
+

Hello world!

+ + +
+ + + + + Invalid Time + + + + + +
    +
  • First description.
  • +
  • Second description.
  • +
+ + + +
+
Item 1
+
Item 2
+
+ + + +
+
Item 1
+
Item 2
+
+ + + + +
+
Hello world!
+
+
+ + + +
+
I am an apple
+
I am a pear
+
I am a banana
+
+
+ + + +
+
+ + + +
+
Billing
+
+
+
Name
+ +
+
+
Address
+ +
+ + + + + +
+
+ + + + Fruit +
Delicious
+
Nutritious
+ + + +

Title

+
Next
+
Content2
+
Content1
+ + + +
    +
  • Parent
  • +
+
    +
  • Child 1
  • +
  • Child 2
  • +
+ + +
+

Light DOM Heading

+
+

Light DOM text

+

Light DOM text

+
+ + + +
+
Delicious
+
Nutritious
+
+
+ + + +
+
Misspelling
+
Wonderful
+
Fantastic
+ +
+
+ + + + + + + + + + + +
+ + + +
+ + + + + + +
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + + + + + +