Range.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibWeb/DOM/AbstractRange.h>
  9. namespace Web::DOM {
  10. class Range final : public AbstractRange {
  11. public:
  12. using WrapperType = Bindings::RangeWrapper;
  13. virtual ~Range() override;
  14. static NonnullRefPtr<Range> create(Document&);
  15. static NonnullRefPtr<Range> create(HTML::Window&);
  16. static NonnullRefPtr<Range> create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
  17. static NonnullRefPtr<Range> create_with_global_object(Bindings::WindowObject&);
  18. // FIXME: There are a ton of methods missing here.
  19. ExceptionOr<void> set_start(Node& node, u32 offset);
  20. ExceptionOr<void> set_end(Node& node, u32 offset);
  21. ExceptionOr<void> set_start_before(Node& node);
  22. ExceptionOr<void> set_start_after(Node& node);
  23. ExceptionOr<void> set_end_before(Node& node);
  24. ExceptionOr<void> set_end_after(Node& node);
  25. ExceptionOr<void> select_node(Node& node);
  26. void collapse(bool to_start);
  27. ExceptionOr<void> select_node_contents(Node const&);
  28. // https://dom.spec.whatwg.org/#dom-range-start_to_start
  29. enum HowToCompareBoundaryPoints : u16 {
  30. START_TO_START = 0,
  31. START_TO_END = 1,
  32. END_TO_END = 2,
  33. END_TO_START = 3,
  34. };
  35. ExceptionOr<i16> compare_boundary_points(u16 how, Range const& source_range) const;
  36. NonnullRefPtr<Range> inverted() const;
  37. NonnullRefPtr<Range> normalized() const;
  38. NonnullRefPtr<Range> clone_range() const;
  39. NonnullRefPtr<Node> common_ancestor_container() const;
  40. // https://dom.spec.whatwg.org/#dom-range-detach
  41. void detach() const
  42. {
  43. // The detach() method steps are to do nothing.
  44. // Note: Its functionality (disabling a Range object) was removed, but the method itself is preserved for compatibility.
  45. }
  46. bool intersects_node(Node const&) const;
  47. ExceptionOr<bool> is_point_in_range(Node const&, u32 offset) const;
  48. ExceptionOr<i16> compare_point(Node const&, u32 offset) const;
  49. private:
  50. explicit Range(Document&);
  51. Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
  52. Node& root();
  53. Node const& root() const;
  54. enum class StartOrEnd {
  55. Start,
  56. End,
  57. };
  58. ExceptionOr<void> set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end);
  59. ExceptionOr<void> select(Node& node);
  60. };
  61. }