mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:47:35 +00:00
LibWeb/HTML: Port Window.getSelection() to IDL
This commit is contained in:
parent
56550b6ec0
commit
606b9ff6f3
5 changed files with 18 additions and 22 deletions
|
@ -320,6 +320,8 @@ JS::ThrowCompletionOr<void> Document::initialize(JS::Realm& realm)
|
|||
MUST_OR_THROW_OOM(Base::initialize(realm));
|
||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::DocumentPrototype>(realm, "Document"));
|
||||
|
||||
m_selection = MUST_OR_THROW_OOM(heap().allocate<Selection::Selection>(realm, realm, *this));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -369,17 +371,12 @@ void Document::visit_edges(Cell::Visitor& visitor)
|
|||
}
|
||||
|
||||
// https://w3c.github.io/selection-api/#dom-document-getselection
|
||||
JS::GCPtr<Selection::Selection> Document::get_selection()
|
||||
JS::GCPtr<Selection::Selection> Document::get_selection() const
|
||||
{
|
||||
// The method must return the selection associated with this if this has an associated browsing context,
|
||||
// and it must return null otherwise.
|
||||
if (!browsing_context()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!m_selection) {
|
||||
m_selection = Selection::Selection::create(realm(), *this).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
if (!browsing_context())
|
||||
return {};
|
||||
return m_selection;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,8 +88,7 @@ public:
|
|||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> construct_impl(JS::Realm&);
|
||||
virtual ~Document() override;
|
||||
|
||||
// https://w3c.github.io/selection-api/#dom-document-getselection
|
||||
JS::GCPtr<Selection::Selection> get_selection();
|
||||
JS::GCPtr<Selection::Selection> get_selection() const;
|
||||
|
||||
size_t next_layout_node_serial_id(Badge<Layout::Node>) { return m_next_layout_node_serial_id++; }
|
||||
size_t layout_node_count() const { return m_next_layout_node_serial_id; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue