AttributeNames.cpp 2.0 KB

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