From 941bc475381d979b5e06f3ea02300f75674b438f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 10 Nov 2022 08:47:01 -0500 Subject: [PATCH] LibWeb: Define method to check if an attribute is a boolean attribute --- .../Libraries/LibWeb/HTML/AttributeNames.cpp | 33 +++++++++++++++++++ .../Libraries/LibWeb/HTML/AttributeNames.h | 3 ++ 2 files changed, 36 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/AttributeNames.cpp b/Userland/Libraries/LibWeb/HTML/AttributeNames.cpp index d4425d2679..9bc32452bf 100644 --- a/Userland/Libraries/LibWeb/HTML/AttributeNames.cpp +++ b/Userland/Libraries/LibWeb/HTML/AttributeNames.cpp @@ -39,5 +39,38 @@ ENUMERATE_HTML_ATTRIBUTES } } + +// https://html.spec.whatwg.org/#boolean-attribute +bool is_boolean_attribute(FlyString const& attribute) +{ + // NOTE: This is the list of attributes from https://html.spec.whatwg.org/#attributes-3 + // with a Value column value of "Boolean attribute". + return attribute.is_one_of( + AttributeNames::allowfullscreen, + AttributeNames::async, + AttributeNames::autofocus, + AttributeNames::autoplay, + AttributeNames::checked, + AttributeNames::controls, + AttributeNames::default_, + AttributeNames::defer, + AttributeNames::disabled, + AttributeNames::formnovalidate, + AttributeNames::inert, + AttributeNames::ismap, + AttributeNames::itemscope, + AttributeNames::loop, + AttributeNames::multiple, + AttributeNames::muted, + AttributeNames::nomodule, + AttributeNames::novalidate, + AttributeNames::open, + AttributeNames::playsinline, + AttributeNames::readonly, + AttributeNames::required, + AttributeNames::reversed, + AttributeNames::selected); +} + } } diff --git a/Userland/Libraries/LibWeb/HTML/AttributeNames.h b/Userland/Libraries/LibWeb/HTML/AttributeNames.h index 18de3a9ff8..061131938e 100644 --- a/Userland/Libraries/LibWeb/HTML/AttributeNames.h +++ b/Userland/Libraries/LibWeb/HTML/AttributeNames.h @@ -232,5 +232,8 @@ ENUMERATE_HTML_ATTRIBUTES #undef __ENUMERATE_HTML_ATTRIBUTE } + +bool is_boolean_attribute(FlyString const& attribute); + } }