1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:48:12 +00:00

LibWeb: Make DOM::Range more suitable for JS.

This commit is contained in:
asynts 2020-12-06 19:51:55 +01:00 committed by Andreas Kling
parent 4df0eeaa3d
commit 10f9c85090
11 changed files with 186 additions and 69 deletions

View file

@ -25,6 +25,7 @@
*/
#include <LibWeb/DOM/Position.h>
#include <LibWeb/DOM/Range.h>
#include <LibWeb/Layout/LayoutPosition.h>
#include <LibWeb/Layout/Node.h>
@ -53,12 +54,14 @@ LayoutRange LayoutRange::normalized() const
return { m_end, m_start };
}
DOM::Range LayoutRange::to_dom_range() const
NonnullRefPtr<DOM::Range> LayoutRange::to_dom_range() const
{
if (!is_valid())
return {};
ASSERT(is_valid());
return { m_start.to_dom_position(), m_end.to_dom_position() };
auto start = m_start.to_dom_position();
auto end = m_end.to_dom_position();
return DOM::Range::create(*start.node(), start.offset(), *end.node(), end.offset());
}
}