mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb/HTML: Port Window.parent to IDL
This commit is contained in:
parent
dba8dbe07d
commit
c6353ac8cd
Notes:
sideshowbarker
2024-07-17 02:56:25 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/c6353ac8cd Pull-request: https://github.com/SerenityOS/serenity/pull/17752 Reviewed-by: https://github.com/awesomekling
3 changed files with 20 additions and 38 deletions
|
@ -867,29 +867,6 @@ JS::NonnullGCPtr<HTML::Storage> Window::session_storage()
|
|||
return *storage;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsers.html#dom-parent
|
||||
WindowProxy* Window::parent()
|
||||
{
|
||||
// 1. Let current be this Window object's browsing context.
|
||||
auto* current = browsing_context();
|
||||
|
||||
// 2. If current is null, then return null.
|
||||
if (!current)
|
||||
return nullptr;
|
||||
|
||||
// 3. If current is a child browsing context of another browsing context parent,
|
||||
// then return parent's WindowProxy object.
|
||||
if (current->parent()) {
|
||||
return current->parent()->window_proxy();
|
||||
}
|
||||
|
||||
// 4. Assert: current is a top-level browsing context.
|
||||
VERIFY(current->is_top_level());
|
||||
|
||||
// 5. Return current's WindowProxy object.
|
||||
return current->window_proxy();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone
|
||||
WebIDL::ExceptionOr<JS::Value> Window::structured_clone_impl(JS::VM& vm, JS::Value message)
|
||||
{
|
||||
|
@ -1073,7 +1050,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
|
|||
MUST_OR_THROW_OOM(Bindings::WindowGlobalMixin::initialize(realm, *this));
|
||||
|
||||
// FIXME: These should be native accessors, not properties
|
||||
define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable);
|
||||
define_native_accessor(realm, "frameElement", frame_element_getter, {}, JS::Attribute::Enumerable);
|
||||
define_native_accessor(realm, "performance", performance_getter, performance_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
define_native_accessor(realm, "crypto", crypto_getter, {}, JS::Attribute::Enumerable);
|
||||
|
@ -1262,6 +1238,24 @@ JS::GCPtr<WindowProxy const> Window::top() const
|
|||
return browsing_context->top_level_browsing_context().window_proxy();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-parent
|
||||
JS::GCPtr<WindowProxy const> Window::parent() const
|
||||
{
|
||||
// 1. Let navigable be this's navigable.
|
||||
auto* navigable = browsing_context();
|
||||
|
||||
// 2. If navigable is null, then return null.
|
||||
if (!navigable)
|
||||
return {};
|
||||
|
||||
// 3. If navigable's parent is not null, then set navigable to navigable's parent.
|
||||
if (auto parent = navigable->parent())
|
||||
navigable = parent;
|
||||
|
||||
// 4. Return navigable's active WindowProxy.
|
||||
return navigable->window_proxy();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator
|
||||
JS::NonnullGCPtr<Navigator> Window::navigator() const
|
||||
{
|
||||
|
@ -1559,15 +1553,6 @@ size_t Window::document_tree_child_browsing_context_count() const
|
|||
return this_browsing_context->document_tree_child_browsing_context_count();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
auto* parent = impl->parent();
|
||||
if (!parent)
|
||||
return JS::js_null();
|
||||
return parent;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsers.html#dom-frameelement
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::frame_element_getter)
|
||||
{
|
||||
|
|
|
@ -116,9 +116,6 @@ public:
|
|||
JS::NonnullGCPtr<HTML::Storage> local_storage();
|
||||
JS::NonnullGCPtr<HTML::Storage> session_storage();
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsers.html#dom-parent
|
||||
WindowProxy* parent();
|
||||
|
||||
WebIDL::ExceptionOr<JS::Value> structured_clone_impl(JS::VM& vm, JS::Value);
|
||||
|
||||
void start_an_idle_period();
|
||||
|
@ -148,6 +145,7 @@ public:
|
|||
JS::NonnullGCPtr<WindowProxy> frames() const;
|
||||
u32 length() const;
|
||||
JS::GCPtr<WindowProxy const> top() const;
|
||||
JS::GCPtr<WindowProxy const> parent() const;
|
||||
|
||||
JS::NonnullGCPtr<Navigator> navigator() const;
|
||||
|
||||
|
@ -235,8 +233,6 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(parent_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(scroll_x_getter);
|
||||
|
|
|
@ -18,6 +18,7 @@ interface Window : EventTarget {
|
|||
[Replaceable] readonly attribute WindowProxy frames;
|
||||
[Replaceable] readonly attribute unsigned long length;
|
||||
[LegacyUnforgeable] readonly attribute WindowProxy? top;
|
||||
[Replaceable] readonly attribute WindowProxy? parent;
|
||||
|
||||
// the user agent
|
||||
readonly attribute Navigator navigator;
|
||||
|
|
Loading…
Reference in a new issue