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
Conversation
self.remove_attribute(&ns!(), local_name); | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
components/script/dom/element.rs
Outdated
// Used for string attribute reflections where absence of the attribute returns null | ||
pub fn get_nullable_string_attribute(&self, local_name: &LocalName) -> Option<DOMString> { |
There was a problem hiding this comment.
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
} | ||
} | ||
|
||
// Used for string attribute reflections where setting null/undefined removes the attribute |
There was a problem hiding this comment.
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.
components/script/dom/element.rs
Outdated
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")) |
There was a problem hiding this comment.
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.
Thanks for the review! Responded to the PR comments, let me know if I missed anything. |
There was a problem hiding this 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.
components/script/dom/element.rs
Outdated
@@ -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> { |
There was a problem hiding this comment.
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.
pub fn get_nullable_string_attribute(&self, local_name: &LocalName) -> Option<DOMString> { | |
fn get_nullable_string_attribute(&self, local_name: &LocalName) -> Option<DOMString> { |
There was a problem hiding this comment.
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
components/script/dom/element.rs
Outdated
|
||
/// 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>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: f87bf34
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. |
No worries! I think we still need to bump the versions of |
Since I had a bit of extra time with this PR, I went ahead and implemented the proper I also reordered the properties to match the spec order (which puts |
@@ -127,3 +127,4 @@ Element includes ChildNode; | |||
Element includes NonDocumentTypeChildNode; | |||
Element includes ParentNode; | |||
Element includes ActivatableElement; | |||
Element includes ARIAMixin; |
There was a problem hiding this comment.
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.
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
I missed a WPT test that is newly-passing ( |
I'm sorry, I totally forgot to update the |
No problem! Hopefully someday soon we can stop running legacy layout tests on CI entirely. |
Partially addresses #32079. Implements ARIA string reflection on
Element
(e.g.ariaLabel
), but not ARIA element reflection (ariaLabelledByElements
and friends), and not onElementInternals
.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 theEdit: fixed!ARIAMixin
getters/setters are put directly onElement
rather than as a separate mixin/trait, but I figured this could be done in the future when these getters/setters are added toElementInternals
../mach build -d
does not report any errors./mach test-tidy
does not report any errorsARIAMixin
onElement
#32079