1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibWeb: Add Document.createRange()

Also tidy up DOM::Range a little bit while we're here, and unify the
way we create them to use a delegating constructors.
This commit is contained in:
Andreas Kling 2021-02-21 23:41:54 +01:00
parent ff018607a1
commit 9194a97cbe
6 changed files with 42 additions and 21 deletions

View file

@ -31,11 +31,27 @@
namespace Web::DOM {
Range::Range(Window& window)
: m_start_container(window.document())
, m_start_offset(0)
, m_end_container(window.document())
, m_end_offset(0)
NonnullRefPtr<Range> Range::create(Window& window)
{
return Range::create(window.document());
}
NonnullRefPtr<Range> Range::create(Document& document)
{
return adopt(*new Range(document));
}
NonnullRefPtr<Range> Range::create(Node& start_container, size_t start_offset, Node& end_container, size_t end_offset)
{
return adopt(*new Range(start_container, start_offset, end_container, end_offset));
}
NonnullRefPtr<Range> Range::create_with_global_object(Bindings::WindowObject& window)
{
return Range::create(window.impl());
}
Range::Range(Document& document)
: Range(document, 0, document, 0)
{
}