HTMLElement.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. public:
  16. using WrapperType = Bindings::HTMLElementWrapper;
  17. HTMLElement(DOM::Document&, DOM::QualifiedName);
  18. virtual ~HTMLElement() override;
  19. String title() const { return attribute(HTML::AttributeNames::title); }
  20. virtual bool is_editable() const final;
  21. String content_editable() const;
  22. DOM::ExceptionOr<void> set_content_editable(String const&);
  23. String inner_text();
  24. void set_inner_text(StringView);
  25. int offset_top() const;
  26. int offset_left() const;
  27. int offset_width() const;
  28. int offset_height() const;
  29. bool cannot_navigate() const;
  30. DOMStringMap* dataset() { return m_dataset.cell(); }
  31. DOMStringMap const* dataset() const { return m_dataset.cell(); }
  32. void focus();
  33. void click();
  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. virtual void parse_attribute(FlyString const& name, String const& value) override;
  39. private:
  40. virtual bool is_html_element() const final { return true; }
  41. // ^HTML::GlobalEventHandlers
  42. virtual DOM::EventTarget& global_event_handlers_to_event_target(FlyString const&) override { return *this; }
  43. enum class ContentEditableState {
  44. True,
  45. False,
  46. Inherit,
  47. };
  48. ContentEditableState content_editable_state() const;
  49. JS::Handle<DOMStringMap> m_dataset;
  50. // https://html.spec.whatwg.org/multipage/interaction.html#locked-for-focus
  51. bool m_locked_for_focus { false };
  52. // https://html.spec.whatwg.org/multipage/interaction.html#click-in-progress-flag
  53. bool m_click_in_progress { false };
  54. };
  55. }
  56. namespace Web::DOM {
  57. template<>
  58. inline bool Node::fast_is<HTML::HTMLElement>() const { return is_html_element(); }
  59. }