Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/aria-hidden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ fn correct_targets(parent: HtmlElement, targets: Vec<Element>) -> Vec<Element> {
return Some(target);
}

if let Some(corrected_target) = unwrap_host(NodeOrShadowRoot::Node((*target).clone())) {
if parent.contains(Some(&corrected_target)) {
return Some(corrected_target);
}
if let Some(corrected_target) = unwrap_host(NodeOrShadowRoot::Node((*target).clone()))
&& parent.contains(Some(&corrected_target))
{
return Some(corrected_target);
}

None
Expand Down
40 changes: 20 additions & 20 deletions packages/aria-query/src/element_role_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ pub static ELEMENT_ROLES: LazyLock<HashMap<AriaRoleRelationConcept, Vec<AriaRole
.chain(role.related_concepts.iter());

for relation in concepts {
if relation.module == Some("HTML".into()) {
if let Some(concept) = &relation.concept {
let element_role_relation = element_roles.get(concept);
let mut roles: Vec<AriaRoleDefinitionKey> = vec![];

if let Some(element_role_relation) = element_role_relation {
roles.extend(element_role_relation);
}
if relation.module == Some("HTML".into())
&& let Some(concept) = &relation.concept
{
let element_role_relation = element_roles.get(concept);
let mut roles: Vec<AriaRoleDefinitionKey> = vec![];

if let Some(element_role_relation) = element_role_relation {
roles.extend(element_role_relation);
}

let mut is_unique = true;
for role in &roles {
if *role == *key {
is_unique = false;
break;
}
}
if is_unique {
roles.push(*key);
let mut is_unique = true;
for role in &roles {
if *role == *key {
is_unique = false;
break;
}
}
if is_unique {
roles.push(*key);
}

if element_role_relation.is_none() {
element_roles.insert(concept.clone(), roles);
}
if element_role_relation.is_none() {
element_roles.insert(concept.clone(), roles);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/aria-query/src/role_element_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ pub static ROLE_ELEMENTS: LazyLock<HashMap<AriaRoleDefinitionKey, Vec<AriaRoleRe
.chain(role.related_concepts.iter());

for relation in concepts {
if relation.module == Some("HTML".into()) {
if let Some(concept) = &relation.concept {
relation_concepts.push(concept.clone());
}
if relation.module == Some("HTML".into())
&& let Some(concept) = &relation.concept
{
relation_concepts.push(concept.clone());
}
}

Expand Down
16 changes: 8 additions & 8 deletions packages/dom-accessibility-api/src/accessible_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ pub fn compute_accessible_description(

// https://w3c.github.io/aria/#aria-description
// Mentions that aria-description should only be calculated if aria-describedby didn't provide a description.
if description.is_empty() {
if let Some(aria_description) = root.get_attribute("aria-description") {
description = aria_description;
}
if description.is_empty()
&& let Some(aria_description) = root.get_attribute("aria-description")
{
description = aria_description;
}

// https://www.w3.org/TR/html-aam-1.0/#accessible-name-and-description-computation
// Says for so many elements to use the `title` that we assume all elements are considered.
if description.is_empty() {
if let Some(title) = root.get_attribute("title") {
description = title;
}
if description.is_empty()
&& let Some(title) = root.get_attribute("title")
{
description = title;
}

description
Expand Down
149 changes: 73 additions & 76 deletions packages/dom-accessibility-api/src/accessible_name_and_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,31 +476,29 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO
if let Some(name_from_alt) = use_attribute(consulted_nodes, element, "alt") {
return Some(name_from_alt);
}
} else if element.is_instance_of::<HtmlOptGroupElement>() {
if let Some(name_from_label) = use_attribute(consulted_nodes, element, "label") {
return Some(name_from_label);
}
} else if element.is_instance_of::<HtmlOptGroupElement>()
&& let Some(name_from_label) = use_attribute(consulted_nodes, element, "label")
{
return Some(name_from_label);
}

if let Some(input_element) = element.dyn_ref::<HtmlInputElement>() {
if input_element.type_() == "button"
if let Some(input_element) = element.dyn_ref::<HtmlInputElement>()
&& (input_element.type_() == "button"
|| input_element.type_() == "submit"
|| input_element.type_() == "reset"
{
// https://w3c.github.io/html-aam/#input-type-text-input-type-password-input-type-search-input-type-tel-input-type-email-input-type-url-and-textarea-element-accessible-description-computation
if let Some(name_from_value) = use_attribute(consulted_nodes, element, "value")
{
return Some(name_from_value);
}
|| input_element.type_() == "reset")
{
// https://w3c.github.io/html-aam/#input-type-text-input-type-password-input-type-search-input-type-tel-input-type-email-input-type-url-and-textarea-element-accessible-description-computation
if let Some(name_from_value) = use_attribute(consulted_nodes, element, "value") {
return Some(name_from_value);
}

// TODO: l10n
if input_element.type_() == "submit" {
return Some("Submit".into());
}
// TODO: l10n
if input_element.type_() == "reset" {
return Some("Reset".into());
}
// TODO: l10n
if input_element.type_() == "submit" {
return Some("Submit".into());
}
// TODO: l10n
if input_element.type_() == "reset" {
return Some("Reset".into());
}
}

Expand Down Expand Up @@ -535,21 +533,21 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO
// https://w3c.github.io/html-aam/#input-type-image-accessible-name-computation
// TODO: WPT test consider label elements but html-aam does not mention them.
// We follow existing implementations over spec.
if let Some(input_element) = node.dyn_ref::<HtmlInputElement>() {
if input_element.type_() == "image" {
let name_for_alt = use_attribute(consulted_nodes, input_element, "alt");
if let Some(name_for_alt) = name_for_alt {
return Some(name_for_alt);
}

let name_for_title = use_attribute(consulted_nodes, input_element, "title");
if let Some(name_for_alt) = name_for_title {
return Some(name_for_alt);
}
if let Some(input_element) = node.dyn_ref::<HtmlInputElement>()
&& input_element.type_() == "image"
{
let name_for_alt = use_attribute(consulted_nodes, input_element, "alt");
if let Some(name_for_alt) = name_for_alt {
return Some(name_for_alt);
}

// TODO: l10n
return Some("Submit Query".into());
let name_for_title = use_attribute(consulted_nodes, input_element, "title");
if let Some(name_for_alt) = name_for_title {
return Some(name_for_alt);
}

// TODO: l10n
return Some("Submit Query".into());
}

if has_any_concrete_roles(node, vec!["button"]) {
Expand Down Expand Up @@ -595,42 +593,41 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO
}

// 2B
if let Some(current) = current.dyn_ref::<Element>() {
if let Some(label_attribute_node) = current.get_attribute_node("aria-labelledby") {
// TODO: Do we generally need to block query IdRefs of attributes we have already consulted?
let label_elements = if !consulted_nodes.contains(&label_attribute_node) {
query_id_refs(current, "aria-labelledby")
} else {
vec![]
};

if compute == Compute::Name && !context.is_referenced && !label_elements.is_empty()
{
consulted_nodes.push(label_attribute_node.unchecked_into::<Node>());

return label_elements
.into_iter()
.map(move |element| {
// TODO: Chrome will consider repeated values i.e. use a node multiple times while we'll bail out in computeTextAlternative.
inner_compute_text_alternative(
compute,
hidden,
uncached_get_computed_style.clone(),
get_computed_style.clone(),
consulted_nodes,
&element,
ComputeTextAlternativeContext {
is_embedded_in_label: context.is_embedded_in_label,
is_referenced: true,
// This isn't recursion as specified, otherwise we would skip `aria-label` in
// <input id="myself" aria-label="foo" aria-labelledby="myself" />
recursion: false,
},
)
})
.collect::<Vec<_>>()
.join(" ");
}
if let Some(current) = current.dyn_ref::<Element>()
&& let Some(label_attribute_node) = current.get_attribute_node("aria-labelledby")
{
// TODO: Do we generally need to block query IdRefs of attributes we have already consulted?
let label_elements = if !consulted_nodes.contains(&label_attribute_node) {
query_id_refs(current, "aria-labelledby")
} else {
vec![]
};

if compute == Compute::Name && !context.is_referenced && !label_elements.is_empty() {
consulted_nodes.push(label_attribute_node.unchecked_into::<Node>());

return label_elements
.into_iter()
.map(move |element| {
// TODO: Chrome will consider repeated values i.e. use a node multiple times while we'll bail out in computeTextAlternative.
inner_compute_text_alternative(
compute,
hidden,
uncached_get_computed_style.clone(),
get_computed_style.clone(),
consulted_nodes,
&element,
ComputeTextAlternativeContext {
is_embedded_in_label: context.is_embedded_in_label,
is_referenced: true,
// This isn't recursion as specified, otherwise we would skip `aria-label` in
// <input id="myself" aria-label="foo" aria-labelledby="myself" />
recursion: false,
},
)
})
.collect::<Vec<_>>()
.join(" ");
}
}

Expand All @@ -651,18 +648,18 @@ pub fn compute_text_alternative(root: &Element, options: ComputeTextAlternativeO
}

// 2D
if !is_marked_presentational(current) {
if let Some(element_text_alternative) = compute_element_text_alternative(
if !is_marked_presentational(current)
&& let Some(element_text_alternative) = compute_element_text_alternative(
compute,
hidden,
uncached_get_computed_style.clone(),
get_computed_style.clone(),
consulted_nodes,
current,
) {
consulted_nodes.push(current.clone());
return element_text_alternative;
}
)
{
consulted_nodes.push(current.clone());
return element_text_alternative;
}
}

Expand Down
Loading