AttributeNames.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/AttributeNames.h>
  7. namespace Web::HTML {
  8. namespace AttributeNames {
  9. #define __ENUMERATE_HTML_ATTRIBUTE(name) DeprecatedFlyString name;
  10. ENUMERATE_HTML_ATTRIBUTES
  11. #undef __ENUMERATE_HTML_ATTRIBUTE
  12. void initialize_strings()
  13. {
  14. static bool s_initialized = false;
  15. VERIFY(!s_initialized);
  16. #define __ENUMERATE_HTML_ATTRIBUTE(name) \
  17. name = #name;
  18. ENUMERATE_HTML_ATTRIBUTES
  19. #undef __ENUMERATE_HTML_ATTRIBUTE
  20. // NOTE: Special cases for C++ keywords.
  21. class_ = "class";
  22. for_ = "for";
  23. default_ = "default";
  24. char_ = "char";
  25. // NOTE: Special cases for attributes with dashes in them.
  26. accept_charset = "accept-charset";
  27. http_equiv = "http-equiv";
  28. s_initialized = true;
  29. }
  30. }
  31. // https://html.spec.whatwg.org/#boolean-attribute
  32. bool is_boolean_attribute(DeprecatedFlyString const& attribute)
  33. {
  34. // NOTE: This is the list of attributes from https://html.spec.whatwg.org/#attributes-3
  35. // with a Value column value of "Boolean attribute".
  36. return attribute.is_one_of(
  37. AttributeNames::allowfullscreen,
  38. AttributeNames::async,
  39. AttributeNames::autofocus,
  40. AttributeNames::autoplay,
  41. AttributeNames::checked,
  42. AttributeNames::controls,
  43. AttributeNames::default_,
  44. AttributeNames::defer,
  45. AttributeNames::disabled,
  46. AttributeNames::formnovalidate,
  47. AttributeNames::inert,
  48. AttributeNames::ismap,
  49. AttributeNames::itemscope,
  50. AttributeNames::loop,
  51. AttributeNames::multiple,
  52. AttributeNames::muted,
  53. AttributeNames::nomodule,
  54. AttributeNames::novalidate,
  55. AttributeNames::open,
  56. AttributeNames::playsinline,
  57. AttributeNames::readonly,
  58. AttributeNames::required,
  59. AttributeNames::reversed,
  60. AttributeNames::selected);
  61. }
  62. }