summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
diff options
context:
space:
mode:
authorJonah <jonahshafran@gmail.com>2022-11-28 17:58:13 -0600
committerSam Atkins <atkinssj@gmail.com>2023-01-07 10:51:53 +0000
commite63d9d4925936caf3dbd9594299ab30ab7ada706 (patch)
tree3f2a230652aa451d8893023364475f5cbde2696d /Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
parent0a244b9c1f116e1f7247fe57a28181481c09e54f (diff)
downloadserenity-e63d9d4925936caf3dbd9594299ab30ab7ada706.zip
LibWeb: Add Support for the ARIA Element Properties
Element now supports getting and setting ARIA properties from JS and HTML.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/HTMLElement.cpp')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLElement.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
index e250d35744..27c5447f87 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
@@ -6,6 +6,7 @@
#include <AK/StringBuilder.h>
#include <LibJS/Interpreter.h>
+#include <LibWeb/DOM/ARIARoleNames.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/IDLEventListener.h>
#include <LibWeb/DOM/ShadowRoot.h>
@@ -327,4 +328,88 @@ void HTMLElement::blur()
// User agents may selectively or uniformly ignore calls to this method for usability reasons.
}
+FlyString HTMLElement::default_role() const
+{
+ // https://www.w3.org/TR/html-aria/#el-article
+ if (local_name() == TagNames::article)
+ return DOM::ARIARoleNames::article;
+ // https://www.w3.org/TR/html-aria/#el-aside
+ if (local_name() == TagNames::aside)
+ return DOM::ARIARoleNames::complementary;
+ // https://www.w3.org/TR/html-aria/#el-b
+ if (local_name() == TagNames::b)
+ return DOM::ARIARoleNames::generic;
+ // https://www.w3.org/TR/html-aria/#el-bdi
+ if (local_name() == TagNames::bdi)
+ return DOM::ARIARoleNames::generic;
+ // https://www.w3.org/TR/html-aria/#el-bdo
+ if (local_name() == TagNames::bdo)
+ return DOM::ARIARoleNames::generic;
+ // https://www.w3.org/TR/html-aria/#el-code
+ if (local_name() == TagNames::code)
+ return DOM::ARIARoleNames::code;
+ // https://www.w3.org/TR/html-aria/#el-dfn
+ if (local_name() == TagNames::dfn)
+ return DOM::ARIARoleNames::term;
+ // https://www.w3.org/TR/html-aria/#el-em
+ if (local_name() == TagNames::em)
+ return DOM::ARIARoleNames::emphasis;
+ // https://www.w3.org/TR/html-aria/#el-figure
+ if (local_name() == TagNames::figure)
+ return DOM::ARIARoleNames::figure;
+ // https://www.w3.org/TR/html-aria/#el-footer
+ if (local_name() == TagNames::footer) {
+ // TODO: If not a descendant of an article, aside, main, nav or section element, or an element with role=article, complementary, main, navigation or region then role=contentinfo
+ // Otherwise, role=generic
+ return DOM::ARIARoleNames::generic;
+ }
+ // https://www.w3.org/TR/html-aria/#el-header
+ if (local_name() == TagNames::header) {
+ // TODO: If not a descendant of an article, aside, main, nav or section element, or an element with role=article, complementary, main, navigation or region then role=banner
+ // Otherwise, role=generic
+ return DOM::ARIARoleNames::generic;
+ }
+ // https://www.w3.org/TR/html-aria/#el-hgroup
+ if (local_name() == TagNames::hgroup)
+ return DOM::ARIARoleNames::generic;
+ // https://www.w3.org/TR/html-aria/#el-i
+ if (local_name() == TagNames::i)
+ return DOM::ARIARoleNames::generic;
+ // https://www.w3.org/TR/html-aria/#el-main
+ if (local_name() == TagNames::main)
+ return DOM::ARIARoleNames::main;
+ // https://www.w3.org/TR/html-aria/#el-nav
+ if (local_name() == TagNames::nav)
+ return DOM::ARIARoleNames::navigation;
+ // https://www.w3.org/TR/html-aria/#el-samp
+ if (local_name() == TagNames::samp)
+ return DOM::ARIARoleNames::generic;
+ // https://www.w3.org/TR/html-aria/#el-section
+ if (local_name() == TagNames::section) {
+ // TODO: role=region if the section element has an accessible name
+ // Otherwise, no corresponding role
+ return DOM::ARIARoleNames::region;
+ }
+ // https://www.w3.org/TR/html-aria/#el-small
+ if (local_name() == TagNames::small)
+ return DOM::ARIARoleNames::generic;
+ // https://www.w3.org/TR/html-aria/#el-strong
+ if (local_name() == TagNames::strong)
+ return DOM::ARIARoleNames::strong;
+ // https://www.w3.org/TR/html-aria/#el-sub
+ if (local_name() == TagNames::sub)
+ return DOM::ARIARoleNames::subscript;
+ // https://www.w3.org/TR/html-aria/#el-summary
+ if (local_name() == TagNames::summary)
+ return DOM::ARIARoleNames::button;
+ // https://www.w3.org/TR/html-aria/#el-sup
+ if (local_name() == TagNames::sup)
+ return DOM::ARIARoleNames::superscript;
+ // https://www.w3.org/TR/html-aria/#el-u
+ if (local_name() == TagNames::u)
+ return DOM::ARIARoleNames::generic;
+
+ return {};
+}
+
}