Text.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/FlyString.h>
  8. #include <AK/String.h>
  9. #include <LibWeb/DOM/CharacterData.h>
  10. namespace Web::DOM {
  11. class Text : public CharacterData {
  12. public:
  13. using WrapperType = Bindings::TextWrapper;
  14. explicit Text(Document&, String const&);
  15. virtual ~Text() override = default;
  16. static NonnullRefPtr<Text> create_with_global_object(Bindings::WindowObject& window, String const& data);
  17. // ^Node
  18. virtual FlyString node_name() const override { return "#text"; }
  19. virtual bool is_editable() const override { return m_always_editable || CharacterData::is_editable(); }
  20. void set_always_editable(bool b) { m_always_editable = b; }
  21. void set_owner_input_element(Badge<HTML::HTMLInputElement>, HTML::HTMLInputElement&);
  22. HTML::HTMLInputElement* owner_input_element() { return m_owner_input_element; }
  23. ExceptionOr<NonnullRefPtr<Text>> split_text(size_t offset);
  24. protected:
  25. Text(Document&, NodeType, String const&);
  26. private:
  27. WeakPtr<HTML::HTMLInputElement> m_owner_input_element;
  28. bool m_always_editable { false };
  29. };
  30. template<>
  31. inline bool Node::fast_is<Text>() const { return is_text(); }
  32. }