Title: [293860] trunk
Revision
293860
Author
[email protected]
Date
2022-05-05 14:40:17 -0700 (Thu, 05 May 2022)

Log Message

ARIA reflection for Element attributes
https://bugs.webkit.org/show_bug.cgi?id=239852

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

Small fix on the test and update test results with the new PASS.
Add new test case to cover elements moved to a different document.

* web-platform-tests/dom/nodes/aria-element-reflection.tentative-expected.txt:
* web-platform-tests/dom/nodes/aria-element-reflection.tentative.html:

Source/WebCore:

Implement ARIA reflection for attributes that refer to a single Element:
aria-activedescendant & aria-errormessage.
For the properties names this patch uses "Element" suffix:
ariaActiveDescendantElement & ariaErrorMessageElement;
this matches Chromium implementation and AOM explainer, but not AOM spec:
https://github.com/w3c/aria/issues/1732

This implementation is done following the proposed spec text defined at:
https://github.com/whatwg/html/pull/3917

* accessibility/AriaAttributes.idl: Add ariaActiveDescendantElement &
ariaErrorMessageElement.
* bindings/scripts/CodeGenerator.pm:
(GetterExpression): Add function for Element attributes.
(SetterExpression): Ditto.
* bindings/scripts/test/JS/JSTestObj.cpp: Add tests for element
attribute reflection.
(WebCore::JSTestObjDOMConstructor::construct):
(WebCore::jsTestObj_reflectedElementAttrGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
(WebCore::setJSTestObj_reflectedElementAttrSetter):
(WebCore::JSC_DEFINE_CUSTOM_SETTER):
* bindings/scripts/test/TestObj.idl: Add reflectedElementAttr
attribute.
* dom/Element.cpp:
(WebCore::isElementReflectionAttribute): Utility function to identify
Element reflection attributes.
(WebCore::Element::attributeChanged): If an element reflection
attribute has changed we need to synchronize the map entry by removing
it as it'll be properly updated in setElementAttribute() when needed.
(WebCore::Element::explicitlySetAttrElementsMap): Kind of getter
for the ExplicitlySetAttrElementsMap but that creates the map if it
doesn't exist yet.
(WebCore::Element::explicitlySetAttrElementsMapIfExists const):
Getter for the map.
(WebCore::Element::getElementAttribute const): Implement getter for
element attribute.
(WebCore::Element::setElementAttribute): Implement setter for
element attribute.
* dom/Element.h: Add new method headers and defines the
ExplicitlySetAttrElementsMap, which so far only stores one Element in
the Vector, but uses a Vector in preparation for supporting
FrozenArray<Element> reflection in the future.
* dom/ElementRareData.cpp: Update size of SameSizeAsElementRareData to
include the new pointer.
* dom/ElementRareData.h: Add m_explicitlySetAttrElementsMap attribute.
(WebCore::ElementRareData::explicitlySetAttrElementsMap): Getter.
(WebCore::ElementRareData::useTypes const):Include
ExplicitlySetAttrElementsMap.
* dom/Node.cpp:
(WebCore::stringForRareDataUseType): Add ExplicitlySetAttrElementsMap.
* dom/NodeRareData.h: Ditto.

Source/WTF:

Add new runtime flag AriaReflectionForElementReferencesEnabled.

* Scripts/Preferences/WebPreferencesExperimental.yaml:

LayoutTests:

Update test to include the new reflected attributes.

* accessibility/ARIA-reflection-expected.txt:
* accessibility/ARIA-reflection.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (293859 => 293860)


--- trunk/LayoutTests/ChangeLog	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/LayoutTests/ChangeLog	2022-05-05 21:40:17 UTC (rev 293860)
@@ -1,3 +1,15 @@
+2022-05-05  Manuel Rego Casasnovas  <[email protected]>
+
+        ARIA reflection for Element attributes
+        https://bugs.webkit.org/show_bug.cgi?id=239852
+
+        Reviewed by Chris Dumez.
+
+        Update test to include the new reflected attributes.
+
+        * accessibility/ARIA-reflection-expected.txt:
+        * accessibility/ARIA-reflection.html:
+
 2022-05-05  Karl Rackler  <[email protected]>
 
         [ iOS ][ Monterey Release wk2 ] imported/w3c/web-platform-tests/content-security-policy/inheritance/blob-url-in-main-window-self-navigate-inherits.sub.html is a flaky failure

Modified: trunk/LayoutTests/accessibility/ARIA-reflection-expected.txt (293859 => 293860)


--- trunk/LayoutTests/accessibility/ARIA-reflection-expected.txt	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/LayoutTests/accessibility/ARIA-reflection-expected.txt	2022-05-05 21:40:17 UTC (rev 293860)
@@ -7,317 +7,292 @@
 Test role < - > role
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["role"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("role", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
+Test ariaActiveDescendantElement < - > aria-activedescendant
+PASS element[currentProperty] is null
+PASS element.getAttribute(currentAttribute) is null
+PASS element.getAttribute(currentAttribute) is dataAttribute
+element.setAttribute("aria-activedescendant", otherData);
+PASS element[currentProperty] is otherDataProperty
+
 Test ariaAtomic < - > aria-atomic
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaAtomic"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-atomic", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaAutoComplete < - > aria-autocomplete
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaAutoComplete"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-autocomplete", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaBusy < - > aria-busy
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaBusy"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-busy", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaChecked < - > aria-checked
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaChecked"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-checked", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaColCount < - > aria-colcount
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaColCount"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-colcount", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaColIndex < - > aria-colindex
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaColIndex"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-colindex", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaColSpan < - > aria-colspan
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaColSpan"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-colspan", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaCurrent < - > aria-current
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaCurrent"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-current", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaDisabled < - > aria-disabled
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaDisabled"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-disabled", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
+Test ariaErrorMessageElement < - > aria-errormessage
+PASS element[currentProperty] is null
+PASS element.getAttribute(currentAttribute) is null
+PASS element.getAttribute(currentAttribute) is dataAttribute
+element.setAttribute("aria-errormessage", otherData);
+PASS element[currentProperty] is otherDataProperty
+
 Test ariaExpanded < - > aria-expanded
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaExpanded"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-expanded", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaHasPopup < - > aria-haspopup
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaHasPopup"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-haspopup", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaHidden < - > aria-hidden
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaHidden"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-hidden", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaInvalid < - > aria-invalid
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaInvalid"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-invalid", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaKeyShortcuts < - > aria-keyshortcuts
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaKeyShortcuts"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-keyshortcuts", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaLabel < - > aria-label
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaLabel"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-label", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaLevel < - > aria-level
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaLevel"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-level", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaLive < - > aria-live
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaLive"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-live", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaModal < - > aria-modal
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaModal"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-modal", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaMultiLine < - > aria-multiline
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaMultiLine"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-multiline", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaMultiSelectable < - > aria-multiselectable
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaMultiSelectable"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-multiselectable", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaOrientation < - > aria-orientation
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaOrientation"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-orientation", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaPlaceholder < - > aria-placeholder
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaPlaceholder"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-placeholder", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaPosInSet < - > aria-posinset
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaPosInSet"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-posinset", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaPressed < - > aria-pressed
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaPressed"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-pressed", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaReadOnly < - > aria-readonly
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaReadOnly"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-readonly", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaRelevant < - > aria-relevant
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaRelevant"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-relevant", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaRequired < - > aria-required
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaRequired"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-required", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaRoleDescription < - > aria-roledescription
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaRoleDescription"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-roledescription", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaRowCount < - > aria-rowcount
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaRowCount"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-rowcount", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaRowIndex < - > aria-rowindex
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaRowIndex"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-rowindex", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaRowSpan < - > aria-rowspan
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaRowSpan"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-rowspan", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaSelected < - > aria-selected
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaSelected"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-selected", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaSetSize < - > aria-setsize
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaSetSize"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-setsize", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaSort < - > aria-sort
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaSort"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-sort", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaValueMax < - > aria-valuemax
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaValueMax"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-valuemax", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaValueMin < - > aria-valuemin
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaValueMin"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-valuemin", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaValueNow < - > aria-valuenow
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaValueNow"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-valuenow", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 Test ariaValueText < - > aria-valuetext
 PASS element[currentProperty] is null
 PASS element.getAttribute(currentAttribute) is null
-element["ariaValueText"] = data;
-PASS element.getAttribute(currentAttribute) is data
+PASS element.getAttribute(currentAttribute) is dataAttribute
 element.setAttribute("aria-valuetext", otherData);
-PASS element[currentProperty] is otherData
+PASS element[currentProperty] is otherDataProperty
 
 
-PASS count is 38
+PASS count is 40
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/accessibility/ARIA-reflection.html (293859 => 293860)


--- trunk/LayoutTests/accessibility/ARIA-reflection.html	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/LayoutTests/accessibility/ARIA-reflection.html	2022-05-05 21:40:17 UTC (rev 293860)
@@ -5,7 +5,8 @@
 <div id="content">
 
 <div id="test" data="" data">
-
+  <div id="firstChild"></div>
+  <div id="secondChild"></div>
 </div>
 
 <p id="description"></p>
@@ -21,22 +22,40 @@
     var currentProperty;
     var currentAttribute;
 
+    function isElementReflectionProperty(property) {
+        switch (property) {
+            case "ariaActiveDescendantElement":
+            case "ariaErrorMessageElement":
+                return true;
+        }
+        return false;
+    }
+
+    function convertPropertyToAttribute(property) {
+        if (isElementReflectionProperty(property))
+          property = property.replace("Element", "");
+        return property.replace("aria", "aria-").toLowerCase();
+    }
+
     function testElement() {
-        currentAttribute = currentProperty.replace("aria", "aria-").toLowerCase();
-        
+        currentAttribute = convertPropertyToAttribute(currentProperty);
+
         debug("\nTest " + currentProperty + " < - > " + currentAttribute);
         shouldBeNull("element[currentProperty]");
         shouldBeNull("element.getAttribute(currentAttribute)");
-        
+
         // Set the property value
-        debug("element[\"" + currentProperty + "\"] = data;");
-        element[currentProperty] = data;
-        shouldBe("element.getAttribute(currentAttribute)", "data");
+        dataProperty = isElementReflectionProperty(currentProperty) ? firstChild : data;
+        dataAttribute = isElementReflectionProperty(currentProperty) ? firstChild.id : data;
+        element[currentProperty] = dataProperty;
+        shouldBe("element.getAttribute(currentAttribute)", "dataAttribute");
 
         // Set the attribute value
+        otherDataProperty = isElementReflectionProperty(currentProperty) ? secondChild : otherData;
+        otherDataAttribute = isElementReflectionProperty(currentProperty) ? secondChild.id : otherData;
         debug("element.setAttribute(\"" + currentAttribute + "\", otherData);");
-        element.setAttribute(currentAttribute, otherData);
-        shouldBe("element[currentProperty]", "otherData");
+        element.setAttribute(currentAttribute, otherDataAttribute);
+        shouldBe("element[currentProperty]", "otherDataProperty");
     }
 
     function testRole() {
@@ -59,7 +78,7 @@
         }
 
         debug("\n");
-        shouldBe("count", "38");
+        shouldBe("count", "40");
 
     } else {
         testFailed("Could not load accessibility controller");

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (293859 => 293860)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-05-05 21:40:17 UTC (rev 293860)
@@ -1,3 +1,16 @@
+2022-05-05  Manuel Rego Casasnovas  <[email protected]>
+
+        ARIA reflection for Element attributes
+        https://bugs.webkit.org/show_bug.cgi?id=239852
+
+        Reviewed by Chris Dumez.
+
+        Small fix on the test and update test results with the new PASS.
+        Add new test case to cover elements moved to a different document.
+
+        * web-platform-tests/dom/nodes/aria-element-reflection.tentative-expected.txt:
+        * web-platform-tests/dom/nodes/aria-element-reflection.tentative.html:
+
 2022-05-05  Ziran Sun  <[email protected]>
 
         <input type=color> should have box-sizing: border-box in UA stylesheet

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/aria-element-reflection.tentative-expected.txt (293859 => 293860)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/aria-element-reflection.tentative-expected.txt	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/aria-element-reflection.tentative-expected.txt	2022-05-05 21:40:17 UTC (rev 293860)
@@ -9,10 +9,7 @@
 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
@@ -47,17 +44,17 @@
 Fantastic
 
 
-FAIL aria-activedescendant element reflection assert_equals: invalid ID for relationship returns null expected (object) null but got (undefined) undefined
-FAIL If the content attribute is set directly, the IDL attribute getter always returns the first element whose ID matches the content attribute. assert_equals: expected (object) Element node <div role="option" id="option1">Item 1</div> but got (undefined) undefined
-FAIL 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 assert_true: expected true got false
-FAIL Setting an element reference that crosses into a shadow tree is disallowed, but setting one that is in a shadow inclusive ancestor is allowed. assert_equals: expected (object) null but got (undefined) undefined
-FAIL aria-errormessage assert_equals: expected (string) "errorMessage" but got (object) null
+PASS aria-activedescendant element reflection
+PASS If the content attribute is set directly, the IDL attribute getter always returns the first element whose ID matches the content attribute.
+PASS 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 Setting an element reference that crosses into a shadow tree is disallowed, but setting one that is in a shadow inclusive ancestor is allowed.
+PASS aria-errormessage
 FAIL aria-details assert_array_equals: value is undefined, expected array
-FAIL Deleting a reflected element should return null for the IDL attribute and cause the content attribute to become stale. assert_equals: expected (object) Element node <div role="option" id="contentAttrElement">Item 1</div> but got (undefined) undefined
-FAIL Changing the ID of an element causes the content attribute to become out of sync. assert_equals: expected (object) Element node <div role="option" id="changingIdElement">Item 1</div> but got (undefined) undefined
-FAIL Reparenting an element into a descendant shadow scope hides the element reference. assert_equals: null before expected (object) null but got (undefined) undefined
-FAIL Reparenting referenced element cannot cause retargeting of reference. assert_equals: expected (string) "apple" but got (object) null
-FAIL Element reference set in invalid scope remains intact throughout move to valid scope. assert_equals: expected null but got Element node <div id="toast"></div>
+PASS Deleting a reflected element should return null for the IDL attribute and cause the content attribute to become stale.
+PASS Changing the ID of an element causes the content attribute to become out of sync.
+PASS Reparenting an element into a descendant shadow scope hides the element reference.
+PASS Reparenting referenced element cannot cause retargeting of reference.
+PASS Element reference set in invalid scope remains intact throughout move to valid scope.
 FAIL aria-labelledby. assert_array_equals: parsed content attribute sets element references. value is undefined, expected array
 FAIL aria-controls. assert_array_equals: value is undefined, expected array
 FAIL aria-describedby. assert_array_equals: value is undefined, expected array
@@ -67,6 +64,7 @@
 FAIL Moving explicitly set elements across shadow DOM boundaries. assert_equals: expected (string) "buttonDescription1 buttonDescription2" but got (object) null
 FAIL Moving explicitly set elements around within the same scope, and removing from the DOM. assert_array_equals: aria-labeled by is supported by IDL getter. value is undefined, expected array
 PASS Reparenting.
-FAIL Attaching element reference before it's inserted into the DOM. assert_equals: Referenced element not inserted into document, so is in an invalid scope. expected null but got Element node <span id="toSpan"></span>
-FAIL Cross-document references and moves. assert_equals: Cross-document is an invalid scope, so reference will not be visible. expected null but got Element node <span></span>
+PASS Attaching element reference before it's inserted into the DOM.
+PASS Cross-document references and moves.
+PASS Adopting element keeps references.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/aria-element-reflection.tentative.html (293859 => 293860)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/aria-element-reflection.tentative.html	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/aria-element-reflection.tentative.html	2022-05-05 21:40:17 UTC (rev 293860)
@@ -164,6 +164,7 @@
   <script>
 
   test(function(t) {
+    const contentAttrElement = document.getElementById("contentAttrElement");
     const idlAttrElement = document.getElementById("idlAttrElement");
 
     assert_equals(deletionParent.getAttribute("aria-activedescendant"), "contentAttrElement");
@@ -707,6 +708,24 @@
     }, "Cross-document references and moves.");
   </script>
 
+
+  <script>
+    test(function(t) {
+      const otherDoc = document.implementation.createHTMLDocument('otherDoc');
+      const otherDocDiv = otherDoc.createElement('div');
+      const otherDocSpan = otherDoc.createElement('span');
+      otherDocDiv.appendChild(otherDocSpan);
+      otherDoc.body.appendChild(otherDocDiv);
+
+      otherDocDiv.ariaActiveDescendantElement = otherDocSpan;
+      assert_equals(otherDocDiv.ariaActiveDescendantElement, otherDocSpan, "Setting reference on a different document.");
+
+      // Adopt element from other oducment.
+      document.body.appendChild(document.adoptNode(otherDocDiv));
+      assert_equals(otherDocDiv.ariaActiveDescendantElement, otherDocSpan, "Reference should be kept on the new document too.");
+    }, "Adopting element keeps references.");
+  </script>
+
   <!-- TODO(chrishall): add additional GC test covering:
        if an element is in an invalid scope but attached to the document, it's
        not GC'd;

Modified: trunk/Source/WTF/ChangeLog (293859 => 293860)


--- trunk/Source/WTF/ChangeLog	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WTF/ChangeLog	2022-05-05 21:40:17 UTC (rev 293860)
@@ -1,3 +1,14 @@
+2022-05-05  Manuel Rego Casasnovas  <[email protected]>
+
+        ARIA reflection for Element attributes
+        https://bugs.webkit.org/show_bug.cgi?id=239852
+
+        Reviewed by Chris Dumez.
+
+        Add new runtime flag AriaReflectionForElementReferencesEnabled.
+
+        * Scripts/Preferences/WebPreferencesExperimental.yaml:
+
 2022-05-05  Sihui Liu  <[email protected]>
 
         SuspendableWorkQueue::suspend should invoke callback immediately when queue is suspended

Modified: trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml (293859 => 293860)


--- trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml	2022-05-05 21:40:17 UTC (rev 293860)
@@ -66,6 +66,18 @@
     WebKit:
       default: false
 
+AriaReflectionForElementReferencesEnabled:
+  type: bool
+  humanReadableName: "ARIA Reflection for Element References"
+  humanReadableDescription: "Enable ARIA reflection for attributes that refer to elements"
+  defaultValue:
+    WebKitLegacy:
+      default: false
+    WebKit:
+      default: false
+    WebCore:
+      default: false
+
 AspectRatioEnabled:
   type: bool
   humanReadableName: "CSS Aspect Ratio"

Modified: trunk/Source/WebCore/ChangeLog (293859 => 293860)


--- trunk/Source/WebCore/ChangeLog	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/ChangeLog	2022-05-05 21:40:17 UTC (rev 293860)
@@ -1,3 +1,63 @@
+2022-05-05  Manuel Rego Casasnovas  <[email protected]>
+
+        ARIA reflection for Element attributes
+        https://bugs.webkit.org/show_bug.cgi?id=239852
+
+        Reviewed by Chris Dumez.
+
+        Implement ARIA reflection for attributes that refer to a single Element:
+        aria-activedescendant & aria-errormessage.
+        For the properties names this patch uses "Element" suffix:
+        ariaActiveDescendantElement & ariaErrorMessageElement;
+        this matches Chromium implementation and AOM explainer, but not AOM spec:
+        https://github.com/w3c/aria/issues/1732
+
+        This implementation is done following the proposed spec text defined at:
+        https://github.com/whatwg/html/pull/3917
+
+        * accessibility/AriaAttributes.idl: Add ariaActiveDescendantElement &
+        ariaErrorMessageElement.
+        * bindings/scripts/CodeGenerator.pm:
+        (GetterExpression): Add function for Element attributes.
+        (SetterExpression): Ditto.
+        * bindings/scripts/test/JS/JSTestObj.cpp: Add tests for element
+        attribute reflection.
+        (WebCore::JSTestObjDOMConstructor::construct):
+        (WebCore::jsTestObj_reflectedElementAttrGetter):
+        (WebCore::JSC_DEFINE_CUSTOM_GETTER):
+        (WebCore::setJSTestObj_reflectedElementAttrSetter):
+        (WebCore::JSC_DEFINE_CUSTOM_SETTER):
+        * bindings/scripts/test/TestObj.idl: Add reflectedElementAttr
+        attribute.
+        * dom/Element.cpp:
+        (WebCore::isElementReflectionAttribute): Utility function to identify
+        Element reflection attributes.
+        (WebCore::Element::attributeChanged): If an element reflection
+        attribute has changed we need to synchronize the map entry by removing
+        it as it'll be properly updated in setElementAttribute() when needed.
+        (WebCore::Element::explicitlySetAttrElementsMap): Kind of getter
+        for the ExplicitlySetAttrElementsMap but that creates the map if it
+        doesn't exist yet.
+        (WebCore::Element::explicitlySetAttrElementsMapIfExists const):
+        Getter for the map.
+        (WebCore::Element::getElementAttribute const): Implement getter for
+        element attribute.
+        (WebCore::Element::setElementAttribute): Implement setter for
+        element attribute.
+        * dom/Element.h: Add new method headers and defines the
+        ExplicitlySetAttrElementsMap, which so far only stores one Element in
+        the Vector, but uses a Vector in preparation for supporting
+        FrozenArray<Element> reflection in the future.
+        * dom/ElementRareData.cpp: Update size of SameSizeAsElementRareData to
+        include the new pointer.
+        * dom/ElementRareData.h: Add m_explicitlySetAttrElementsMap attribute.
+        (WebCore::ElementRareData::explicitlySetAttrElementsMap): Getter.
+        (WebCore::ElementRareData::useTypes const):Include
+        ExplicitlySetAttrElementsMap.
+        * dom/Node.cpp:
+        (WebCore::stringForRareDataUseType): Add ExplicitlySetAttrElementsMap.
+        * dom/NodeRareData.h: Ditto.
+
 2022-05-05  Alex Christensen  <[email protected]>
 
         Remove unnecessary calls to CachedResource::updateBuffer and CachedResource::updateData

Modified: trunk/Source/WebCore/accessibility/AriaAttributes.idl (293859 => 293860)


--- trunk/Source/WebCore/accessibility/AriaAttributes.idl	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/accessibility/AriaAttributes.idl	2022-05-05 21:40:17 UTC (rev 293860)
@@ -25,6 +25,7 @@
 
 // https://wicg.github.io/aom/spec/aria-reflection.html#AriaAttributes
 interface mixin AriaAttributes {
+    [Reflect=aria_activedescendant, EnabledBySetting=AriaReflectionForElementReferencesEnabled] attribute Element? ariaActiveDescendantElement;
     [Reflect=aria_atomic]           attribute [AtomString] DOMString? ariaAtomic;
     [Reflect=aria_autocomplete]     attribute [AtomString] DOMString? ariaAutoComplete;
     [Reflect=aria_busy]             attribute [AtomString] DOMString? ariaBusy;
@@ -34,6 +35,7 @@
     [Reflect=aria_colspan]          attribute [AtomString] DOMString? ariaColSpan;
     [Reflect=aria_current]          attribute [AtomString] DOMString? ariaCurrent;
     [Reflect=aria_disabled]         attribute [AtomString] DOMString? ariaDisabled;
+    [Reflect=aria_errormessage, EnabledBySetting=AriaReflectionForElementReferencesEnabled] attribute Element? ariaErrorMessageElement;
     [Reflect=aria_expanded]         attribute [AtomString] DOMString? ariaExpanded;
     [Reflect=aria_haspopup]         attribute [AtomString] DOMString? ariaHasPopup;
     [Reflect=aria_hidden]           attribute [AtomString] DOMString? ariaHidden;

Modified: trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm (293859 => 293860)


--- trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm	2022-05-05 21:40:17 UTC (rev 293860)
@@ -1108,6 +1108,8 @@
         $functionName = "getIntegralAttribute";
     } elsif ($attributeType->name eq "unsigned long") {
         $functionName = "getUnsignedIntegralAttribute";
+    } elsif ($attributeType->name eq "Element") {
+        $functionName = "getElementAttribute";
     } else {
         if ($contentAttributeName eq "WebCore::HTMLNames::idAttr") {
             $functionName = "getIdAttribute";
@@ -1145,6 +1147,8 @@
         $functionName = "setIntegralAttribute";
     } elsif ($attributeType->name eq "unsigned long") {
         $functionName = "setUnsignedIntegralAttribute";
+    } elsif ($attributeType->name eq "Element") {
+        $functionName = "setElementAttribute";
     } elsif ($generator->IsSVGAnimatedType($attributeType)) {
         $functionName = "setAttribute";
     } else {

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (293859 => 293860)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2022-05-05 21:40:17 UTC (rev 293860)
@@ -1803,6 +1803,8 @@
 static JSC_DECLARE_CUSTOM_SETTER(setJSTestObj_reflectedUnsignedIntegralAttr);
 static JSC_DECLARE_CUSTOM_GETTER(jsTestObj_reflectedBooleanAttr);
 static JSC_DECLARE_CUSTOM_SETTER(setJSTestObj_reflectedBooleanAttr);
+static JSC_DECLARE_CUSTOM_GETTER(jsTestObj_reflectedElementAttr);
+static JSC_DECLARE_CUSTOM_SETTER(setJSTestObj_reflectedElementAttr);
 static JSC_DECLARE_CUSTOM_GETTER(jsTestObj_reflectedURLAttr);
 static JSC_DECLARE_CUSTOM_SETTER(setJSTestObj_reflectedURLAttr);
 static JSC_DECLARE_CUSTOM_GETTER(jsTestObj_reflectedUSVURLAttr);
@@ -2175,6 +2177,7 @@
     { "reflectedIntegralAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObj_reflectedIntegralAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObj_reflectedIntegralAttr) } },
     { "reflectedUnsignedIntegralAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObj_reflectedUnsignedIntegralAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObj_reflectedUnsignedIntegralAttr) } },
     { "reflectedBooleanAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObj_reflectedBooleanAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObj_reflectedBooleanAttr) } },
+    { "reflectedElementAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObj_reflectedElementAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObj_reflectedElementAttr) } },
     { "reflectedURLAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObj_reflectedURLAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObj_reflectedURLAttr) } },
     { "reflectedUSVURLAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObj_reflectedUSVURLAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObj_reflectedUSVURLAttr) } },
     { "reflectedStringAttr", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObj_reflectedStringAttr), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObj_reflectedStringAttr) } },
@@ -3918,6 +3921,37 @@
     return IDLAttribute<JSTestObj>::set<setJSTestObj_reflectedBooleanAttrSetter>(*lexicalGlobalObject, thisValue, encodedValue, attributeName);
 }
 
+static inline JSValue jsTestObj_reflectedElementAttrGetter(JSGlobalObject& lexicalGlobalObject, JSTestObj& thisObject)
+{
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    auto& impl = thisObject.wrapped();
+    RELEASE_AND_RETURN(throwScope, (toJS<IDLInterface<Element>>(lexicalGlobalObject, *thisObject.globalObject(), throwScope, impl.getElementAttribute(WebCore::HTMLNames::reflectedelementattrAttr))));
+}
+
+JSC_DEFINE_CUSTOM_GETTER(jsTestObj_reflectedElementAttr, (JSGlobalObject* lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+    return IDLAttribute<JSTestObj>::get<jsTestObj_reflectedElementAttrGetter, CastedThisErrorBehavior::Assert>(*lexicalGlobalObject, thisValue, attributeName);
+}
+
+static inline bool setJSTestObj_reflectedElementAttrSetter(JSGlobalObject& lexicalGlobalObject, JSTestObj& thisObject, JSValue value)
+{
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    auto& impl = thisObject.wrapped();
+    auto nativeValue = convert<IDLInterface<Element>>(lexicalGlobalObject, value, [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwAttributeTypeError(lexicalGlobalObject, scope, "TestObject", "reflectedElementAttr", "Element"); });
+    RETURN_IF_EXCEPTION(throwScope, false);
+    invokeFunctorPropagatingExceptionIfNecessary(lexicalGlobalObject, throwScope, [&] {
+        return impl.setElementAttribute(WebCore::HTMLNames::reflectedelementattrAttr, *nativeValue);
+    });
+    return true;
+}
+
+JSC_DEFINE_CUSTOM_SETTER(setJSTestObj_reflectedElementAttr, (JSGlobalObject* lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName))
+{
+    return IDLAttribute<JSTestObj>::set<setJSTestObj_reflectedElementAttrSetter>(*lexicalGlobalObject, thisValue, encodedValue, attributeName);
+}
+
 static inline JSValue jsTestObj_reflectedURLAttrGetter(JSGlobalObject& lexicalGlobalObject, JSTestObj& thisObject)
 {
     auto& vm = JSC::getVM(&lexicalGlobalObject);

Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (293859 => 293860)


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2022-05-05 21:40:17 UTC (rev 293860)
@@ -104,6 +104,7 @@
     [Reflect] attribute long reflectedIntegralAttr;
     [Reflect] attribute unsigned long reflectedUnsignedIntegralAttr;
     [Reflect] attribute boolean reflectedBooleanAttr;
+    [Reflect] attribute Element reflectedElementAttr;
     [Reflect, URL] attribute DOMString reflectedURLAttr;
     [Reflect, URL] attribute USVString reflectedUSVURLAttr;
     [Reflect=customContentStringAttr] attribute DOMString reflectedStringAttr;

Modified: trunk/Source/WebCore/dom/Element.cpp (293859 => 293860)


--- trunk/Source/WebCore/dom/Element.cpp	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/dom/Element.cpp	2022-05-05 21:40:17 UTC (rev 293860)
@@ -1901,6 +1901,11 @@
     return value;
 }
 
+static inline bool isElementReflectionAttribute(const QualifiedName& name)
+{
+    return name == HTMLNames::aria_activedescendantAttr || name == HTMLNames::aria_errormessageAttr;
+}
+
 void Element::attributeChanged(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason)
 {
     bool valueIsSameAsBefore = oldValue == newValue;
@@ -1937,7 +1942,11 @@
             }
         } else if (name == HTMLNames::partAttr)
             partAttributeChanged(newValue);
-        else if (name == HTMLNames::exportpartsAttr) {
+        else if (isElementReflectionAttribute(name)) {
+            ASSERT(document().settings().ariaReflectionForElementReferencesEnabled());
+            if (auto* map = explicitlySetAttrElementsMapIfExists())
+                map->remove(name);
+        } else if (name == HTMLNames::exportpartsAttr) {
             if (auto* shadowRoot = this->shadowRoot()) {
                 shadowRoot->invalidatePartMappings();
                 Style::Invalidator::invalidateShadowParts(*shadowRoot);
@@ -1961,6 +1970,60 @@
         cache->deferAttributeChangeIfNeeded(name, this);
 }
 
+ExplicitlySetAttrElementsMap& Element::explicitlySetAttrElementsMap()
+{
+    return ensureElementRareData().explicitlySetAttrElementsMap();
+}
+
+ExplicitlySetAttrElementsMap* Element::explicitlySetAttrElementsMapIfExists() const
+{
+    return hasRareData() ? &elementRareData()->explicitlySetAttrElementsMap() : nullptr;
+}
+
+Element* Element::getElementAttribute(const QualifiedName& attributeName) const
+{
+    ASSERT(document().settings().ariaReflectionForElementReferencesEnabled());
+    ASSERT(isElementReflectionAttribute(attributeName));
+
+    if (auto* map = explicitlySetAttrElementsMapIfExists()) {
+        auto it = map->find(attributeName);
+        if (it != map->end()) {
+            ASSERT(it->value.size() == 1);
+            auto* element = it->value[0].get();
+            if (element && isDescendantOrShadowDescendantOf(element->rootNode()))
+                return element;
+            return nullptr;
+        }
+    }
+
+    auto id = getAttribute(attributeName);
+    if (id.isNull())
+        return nullptr;
+
+    return treeScope().getElementById(id);
+}
+
+void Element::setElementAttribute(const QualifiedName& attributeName, Element* element)
+{
+    ASSERT(document().settings().ariaReflectionForElementReferencesEnabled());
+    ASSERT(isElementReflectionAttribute(attributeName));
+
+    if (!element) {
+        if (auto* map = explicitlySetAttrElementsMapIfExists())
+            map->remove(attributeName);
+        removeAttribute(attributeName);
+        return;
+    }
+
+    auto id = element->getIdAttribute();
+    if (!id.isNull() && &rootNode() == &element->rootNode() && treeScope().getElementById(id) == element)
+        setAttribute(attributeName, id);
+    else
+        setAttribute(attributeName, emptyAtom());
+
+    explicitlySetAttrElementsMap().set(attributeName, Vector<WeakPtr<Element>> { element });
+}
+
 template <typename CharacterType>
 static inline bool isNonEmptyTokenList(const CharacterType* characters, unsigned length)
 {

Modified: trunk/Source/WebCore/dom/Element.h (293859 => 293860)


--- trunk/Source/WebCore/dom/Element.h	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/dom/Element.h	2022-05-05 21:40:17 UTC (rev 293860)
@@ -93,6 +93,10 @@
 struct SecurityPolicyViolationEventInit;
 struct ShadowRootInit;
 
+// FIXME: This only stores one Element in the Vector right now, though this will change
+// once reflection for FrozenArray<Element> is implemented in https://webkit.org/b/239853.
+using ExplicitlySetAttrElementsMap = HashMap<QualifiedName, Vector<WeakPtr<Element>>>;
+
 namespace Style {
 class Resolver;
 enum class Change : uint8_t;
@@ -121,6 +125,8 @@
     WEBCORE_EXPORT void setIntegralAttribute(const QualifiedName& attributeName, int value);
     WEBCORE_EXPORT unsigned getUnsignedIntegralAttribute(const QualifiedName& attributeName) const;
     WEBCORE_EXPORT void setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value);
+    WEBCORE_EXPORT Element* getElementAttribute(const QualifiedName& attributeName) const;
+    WEBCORE_EXPORT void setElementAttribute(const QualifiedName& attributeName, Element* value);
 
     // Call this to get the value of an attribute that is known not to be the style
     // attribute or one of the SVG animatable attributes.
@@ -668,6 +674,9 @@
     StylePropertyMapReadOnly* computedStyleMap();
 #endif
 
+    ExplicitlySetAttrElementsMap& explicitlySetAttrElementsMap();
+    ExplicitlySetAttrElementsMap* explicitlySetAttrElementsMapIfExists() const;
+
 protected:
     Element(const QualifiedName&, Document&, ConstructionType);
 

Modified: trunk/Source/WebCore/dom/ElementRareData.cpp (293859 => 293860)


--- trunk/Source/WebCore/dom/ElementRareData.cpp	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/dom/ElementRareData.cpp	2022-05-05 21:40:17 UTC (rev 293860)
@@ -42,6 +42,7 @@
     void* typedOMData[2];
 #endif
     void* resizeObserverData;
+    ExplicitlySetAttrElementsMap explicitlySetAttrElementsMap;
 };
 
 static_assert(sizeof(ElementRareData) == sizeof(SameSizeAsElementRareData), "ElementRareData should stay small");

Modified: trunk/Source/WebCore/dom/ElementRareData.h (293859 => 293860)


--- trunk/Source/WebCore/dom/ElementRareData.h	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/dom/ElementRareData.h	2022-05-05 21:40:17 UTC (rev 293860)
@@ -107,6 +107,8 @@
     void setComputedStyleMap(Ref<StylePropertyMapReadOnly>&& map) { m_computedStyleMap = WTFMove(map); }
 #endif
 
+    ExplicitlySetAttrElementsMap& explicitlySetAttrElementsMap() { return m_explicitlySetAttrElementsMap; }
+
 #if DUMP_NODE_STATISTICS
     OptionSet<UseType> useTypes() const
     {
@@ -147,6 +149,8 @@
             result.add(UseType::PartNames);
         if (m_nonce)
             result.add(UseType::Nonce);
+        if (!m_explicitlySetAttrElementsMap.isEmpty())
+            result.add(UseType::ExplicitlySetAttrElementsMap);
         return result;
     }
 #endif
@@ -180,6 +184,8 @@
 
     AtomString m_nonce;
 
+    ExplicitlySetAttrElementsMap m_explicitlySetAttrElementsMap;
+
     void releasePseudoElement(PseudoElement*);
 };
 

Modified: trunk/Source/WebCore/dom/Node.cpp (293859 => 293860)


--- trunk/Source/WebCore/dom/Node.cpp	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/dom/Node.cpp	2022-05-05 21:40:17 UTC (rev 293860)
@@ -144,6 +144,8 @@
         return "PartList";
     case NodeRareData::UseType::PartNames:
         return "PartNames";
+    case NodeRareData::UseType::ExplicitlySetAttrElementsMap:
+        return "ExplicitlySetAttrElementsMap";
     }
     return nullptr;
 }

Modified: trunk/Source/WebCore/dom/NodeRareData.h (293859 => 293860)


--- trunk/Source/WebCore/dom/NodeRareData.h	2022-05-05 21:10:01 UTC (rev 293859)
+++ trunk/Source/WebCore/dom/NodeRareData.h	2022-05-05 21:40:17 UTC (rev 293860)
@@ -265,6 +265,7 @@
         PartNames = 1 << 16,
         Nonce = 1 << 17,
         ComputedStyleMap = 1 << 18,
+        ExplicitlySetAttrElementsMap = 1 << 19,
     };
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to