HTMLElement.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/DOMStringMap.h>
  9. #include <LibWeb/HTML/EventNames.h>
  10. #include <LibWeb/HTML/GlobalEventHandlers.h>
  11. namespace Web::HTML {
  12. class HTMLElement
  13. : public DOM::Element
  14. , public HTML::GlobalEventHandlers {
  15. WEB_PLATFORM_OBJECT(HTMLElement, DOM::Element);
  16. public:
  17. virtual ~HTMLElement() override;
  18. String title() const { return attribute(HTML::AttributeNames::title); }
  19. virtual bool is_editable() const final;
  20. String content_editable() const;
  21. WebIDL::ExceptionOr<void> set_content_editable(String const&);
  22. String inner_text();
  23. void set_inner_text(StringView);
  24. int offset_top() const;
  25. int offset_left() const;
  26. int offset_width() const;
  27. int offset_height() const;
  28. bool cannot_navigate() const;
  29. DOMStringMap* dataset() { return m_dataset.ptr(); }
  30. DOMStringMap const* dataset() const { return m_dataset.ptr(); }
  31. void focus();
  32. void click();
  33. void blur();
  34. bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted);
  35. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  36. virtual bool is_labelable() const { return false; }
  37. protected:
  38. HTMLElement(DOM::Document&, DOM::QualifiedName);
  39. virtual void initialize(JS::Realm&) override;
  40. virtual void parse_attribute(FlyString const& name, String const& value) override;
  41. virtual void visit_edges(Cell::Visitor&) override;
  42. private:
  43. virtual bool is_html_element() const final { return true; }
  44. // ^HTML::GlobalEventHandlers
  45. virtual DOM::EventTarget& global_event_handlers_to_event_target(FlyString const&) override { return *this; }
  46. enum class ContentEditableState {
  47. True,
  48. False,
  49. Inherit,
  50. };
  51. ContentEditableState content_editable_state() const;
  52. JS::GCPtr<DOMStringMap> m_dataset;
  53. // https://html.spec.whatwg.org/multipage/interaction.html#locked-for-focus
  54. bool m_locked_for_focus { false };
  55. // https://html.spec.whatwg.org/multipage/interaction.html#click-in-progress-flag
  56. bool m_click_in_progress { false };
  57. };
  58. }
  59. namespace Web::DOM {
  60. template<>
  61. inline bool Node::fast_is<HTML::HTMLElement>() const { return is_html_element(); }
  62. }