Range.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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(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. // https://dom.spec.whatwg.org/#dom-range-start_to_start
  26. enum HowToCompareBoundaryPoints : u16 {
  27. START_TO_START = 0,
  28. START_TO_END = 1,
  29. END_TO_END = 2,
  30. END_TO_START = 3,
  31. };
  32. ExceptionOr<i16> compare_boundary_points(u16 how, Range const& source_range) const;
  33. NonnullRefPtr<Range> inverted() const;
  34. NonnullRefPtr<Range> normalized() const;
  35. NonnullRefPtr<Range> clone_range() const;
  36. NonnullRefPtr<Node> common_ancestor_container() const;
  37. private:
  38. explicit Range(Document&);
  39. Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
  40. Node& root();
  41. Node const& root() const;
  42. enum class StartOrEnd {
  43. Start,
  44. End,
  45. };
  46. ExceptionOr<void> set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end);
  47. };
  48. }