HTMLButtonElement.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/HTMLButtonElement.h>
  7. namespace Web::HTML {
  8. HTMLButtonElement::HTMLButtonElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  9. : FormAssociatedElement(document, move(qualified_name))
  10. {
  11. }
  12. HTMLButtonElement::~HTMLButtonElement()
  13. {
  14. }
  15. String HTMLButtonElement::type() const
  16. {
  17. auto value = attribute(HTML::AttributeNames::type);
  18. #define __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(keyword, _) \
  19. if (value.equals_ignoring_case(#keyword)) \
  20. return #keyword;
  21. ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTES
  22. #undef __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE
  23. // The missing value default and invalid value default are the Submit Button state.
  24. return "submit";
  25. }
  26. HTMLButtonElement::TypeAttributeState HTMLButtonElement::type_state() const
  27. {
  28. auto value = attribute(HTML::AttributeNames::type);
  29. #define __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(keyword, state) \
  30. if (value.equals_ignoring_case(#keyword)) \
  31. return HTMLButtonElement::TypeAttributeState::state;
  32. ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTES
  33. #undef __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE
  34. // The missing value default and invalid value default are the Submit Button state.
  35. return HTMLButtonElement::TypeAttributeState::Submit;
  36. }
  37. void HTMLButtonElement::set_type(String const& type)
  38. {
  39. set_attribute(HTML::AttributeNames::type, type);
  40. }
  41. }