HTMLElement.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/DOM/Element.h>
  8. #include <LibWeb/HTML/EventNames.h>
  9. #include <LibWeb/HTML/GlobalEventHandlers.h>
  10. namespace Web::HTML {
  11. // https://html.spec.whatwg.org/multipage/dom.html#attr-dir
  12. #define ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTES \
  13. __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(ltr) \
  14. __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(rtl) \
  15. __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(auto)
  16. class HTMLElement
  17. : public DOM::Element
  18. , public HTML::GlobalEventHandlers {
  19. WEB_PLATFORM_OBJECT(HTMLElement, DOM::Element);
  20. public:
  21. virtual ~HTMLElement() override;
  22. DeprecatedString title() const { return attribute(HTML::AttributeNames::title); }
  23. DeprecatedString dir() const;
  24. void set_dir(DeprecatedString const&);
  25. virtual bool is_editable() const final;
  26. DeprecatedString content_editable() const;
  27. WebIDL::ExceptionOr<void> set_content_editable(DeprecatedString const&);
  28. DeprecatedString inner_text();
  29. void set_inner_text(StringView);
  30. int offset_top() const;
  31. int offset_left() const;
  32. int offset_width() const;
  33. int offset_height() const;
  34. bool cannot_navigate() const;
  35. DOMStringMap* dataset() { return m_dataset.ptr(); }
  36. DOMStringMap const* dataset() const { return m_dataset.ptr(); }
  37. void focus();
  38. void click();
  39. void blur();
  40. bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted);
  41. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  42. virtual bool is_labelable() const { return false; }
  43. protected:
  44. HTMLElement(DOM::Document&, DOM::QualifiedName);
  45. virtual void initialize(JS::Realm&) override;
  46. virtual void parse_attribute(FlyString const& name, DeprecatedString const& value) override;
  47. virtual void visit_edges(Cell::Visitor&) override;
  48. private:
  49. virtual bool is_html_element() const final { return true; }
  50. // ^HTML::GlobalEventHandlers
  51. virtual DOM::EventTarget& global_event_handlers_to_event_target(FlyString const&) override { return *this; }
  52. enum class ContentEditableState {
  53. True,
  54. False,
  55. Inherit,
  56. };
  57. ContentEditableState content_editable_state() const;
  58. JS::GCPtr<DOMStringMap> m_dataset;
  59. // https://html.spec.whatwg.org/multipage/interaction.html#locked-for-focus
  60. bool m_locked_for_focus { false };
  61. // https://html.spec.whatwg.org/multipage/interaction.html#click-in-progress-flag
  62. bool m_click_in_progress { false };
  63. };
  64. }
  65. namespace Web::DOM {
  66. template<>
  67. inline bool Node::fast_is<HTML::HTMLElement>() const { return is_html_element(); }
  68. }