Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement ARIA string reflection on Element #32080

Merged
merged 11 commits into from Apr 27, 2024

Conversation

nolanlawson
Copy link
Contributor

@nolanlawson nolanlawson commented Apr 15, 2024

Partially addresses #32079. Implements ARIA string reflection on Element (e.g. ariaLabel), but not ARIA element reflection (ariaLabelledByElements and friends), and not on ElementInternals.

This PR won't compile until servo/html5ever#536 is merged and our dependency on html5ever is updated, but I thought I'd open the PR anyway for early feedback.

In my local testing, I was able to get all the aria-attribute-reflection.html tests to pass with this change.

Note that this involved adding reflections for ariaRelevant, which is still in the WPT tests but not in the actual spec (see web-platform-tests/wpt#43866). I guess it's up for debate whether Servo should implement this, since Chromium/Gecko/WebKit all do, so arguably it should be implemented for web compat reasons.

This PR is not ideal since the ARIAMixin getters/setters are put directly on Element rather than as a separate mixin/trait, but I figured this could be done in the future when these getters/setters are added to ElementInternals. Edit: fixed!


  • There are tests for these changes

self.remove_attribute(&ns!(), local_name);
},
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_cross_origin_attribute is really similar to this function, but I wasn't sure if it made sense to combine them, especially since the getter (reflect_cross_origin_attribute) is pretty different.

@nolanlawson nolanlawson changed the title fix: get ariaChecked working feat: implement ARIA string reflection Apr 15, 2024
@nolanlawson nolanlawson changed the title feat: implement ARIA string reflection feat: implement ARIA string reflection on Element Apr 15, 2024
Copy link
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution. Just a few small comments. We'll have to see if we need to release a new version of html5ever or not for this.

Comment on lines 1721 to 1722
// Used for string attribute reflections where absence of the attribute returns null
pub fn get_nullable_string_attribute(&self, local_name: &LocalName) -> Option<DOMString> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind turning this comment into a proper rustdoc docstring? Please see https://doc.rust-lang.org/rust-by-example/meta/doc.html for how to do this.

components/script/dom/element.rs Outdated Show resolved Hide resolved
}
}

// Used for string attribute reflections where setting null/undefined removes the attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also be a good rustdoc comment.

Comment on lines 2942 to 2951
fn GetAriaAtomic(&self) -> Option<DOMString> {
self.get_nullable_string_attribute(&local_name!("aria-atomic"))
}
fn SetAriaAtomic(&self, value: Option<DOMString>) {
self.set_nullable_string_attribute(&local_name!("aria-atomic"), value);
}
fn GetAriaAutoComplete(&self) -> Option<DOMString> {
self.get_nullable_string_attribute(&local_name!("aria-autocomplete"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think normally there are spaces between functions. Be sure to run ./mach fmt before uploading your change -- though the lint didn't fail so maybe that isn't adding the spaces for some reason.

@nolanlawson
Copy link
Contributor Author

Thanks for the review! Responded to the PR comments, let me know if I missed anything.

Copy link
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, this review was sitting as a draft for days. I'll go ahead and apply these changes and land this.

@@ -1718,6 +1718,29 @@ impl Element {
self.set_attribute(local_name, AttrValue::String(value.into()));
}

/// Used for string attribute reflections where absence of the attribute returns `null`,
/// e.g. `element.ariaLabel` returning `null` when the `aria-label` attribute is absent.
pub fn get_nullable_string_attribute(&self, local_name: &LocalName) -> Option<DOMString> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry I missed this before. These new functions do not need to be public because they are only used in this file.

Suggested change
pub fn get_nullable_string_attribute(&self, local_name: &LocalName) -> Option<DOMString> {
fn get_nullable_string_attribute(&self, local_name: &LocalName) -> Option<DOMString> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I missed that too. Fixed: f87bf34


/// Used for string attribute reflections where setting `null`/`undefined` removes the
/// attribute, e.g. `element.ariaLabel = null` removing the `aria-label` attribute.
pub fn set_nullable_string_attribute(&self, local_name: &LocalName, value: Option<DOMString>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn set_nullable_string_attribute(&self, local_name: &LocalName, value: Option<DOMString>) {
fn set_nullable_string_attribute(&self, local_name: &LocalName, value: Option<DOMString>) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: f87bf34

@mrobinson
Copy link
Member

Oh, it looks like before landing this we'll need to update stylo to the newest version of html5ever. I'll wait until that happens.

@nolanlawson
Copy link
Contributor Author

Apologies, this review was sitting as a draft for days.

No worries! I think we still need to bump the versions of html5ever/markup5ever anyway. I gave it a shot myself, but it looks like it's a bit tricky because they are also transitive dependencies via xml5ever and stylo, and the compilation fails if there are multiple competing versions installed.

@nolanlawson
Copy link
Contributor Author

nolanlawson commented Apr 24, 2024

Since I had a bit of extra time with this PR, I went ahead and implemented the proper ARIAMixin webidl.

I also reordered the properties to match the spec order (which puts role before aria-*).

@@ -127,3 +127,4 @@ Element includes ChildNode;
Element includes NonDocumentTypeChildNode;
Element includes ParentNode;
Element includes ActivatableElement;
Element includes ARIAMixin;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ARIAMixin spec has this includes statement there, but we have all our Element includes here. I wasn't sure which should take precedence.

@mrobinson mrobinson added this pull request to the merge queue Apr 26, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 26, 2024
@nolanlawson
Copy link
Contributor Author

I missed a WPT test that is newly-passing (AriaMixin-string-attributes.html). Should be fixed now.

@mrobinson mrobinson added this pull request to the merge queue Apr 27, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 27, 2024
@nolanlawson
Copy link
Contributor Author

I'm sorry, I totally forgot to update the meta-legacy-layout file as well. 🤦‍♂️

@mrobinson
Copy link
Member

I'm sorry, I totally forgot to update the meta-legacy-layout file as well. 🤦‍♂️

No problem! Hopefully someday soon we can stop running legacy layout tests on CI entirely.

@mrobinson mrobinson added this pull request to the merge queue Apr 27, 2024
Merged via the queue into servo:main with commit 02b3dd0 Apr 27, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants