mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 14:45:08 +00:00
LibWeb/HTML: Port Window.top to IDL
This commit is contained in:
parent
baaf891c64
commit
dba8dbe07d
3 changed files with 14 additions and 17 deletions
|
@ -1073,7 +1073,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
|
||||||
MUST_OR_THROW_OOM(Bindings::WindowGlobalMixin::initialize(realm, *this));
|
MUST_OR_THROW_OOM(Bindings::WindowGlobalMixin::initialize(realm, *this));
|
||||||
|
|
||||||
// FIXME: These should be native accessors, not properties
|
// FIXME: These should be native accessors, not properties
|
||||||
define_native_accessor(realm, "top", top_getter, nullptr, JS::Attribute::Enumerable);
|
|
||||||
define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable);
|
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, "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, "performance", performance_getter, performance_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||||
|
@ -1251,6 +1250,18 @@ u32 Window::length() const
|
||||||
return static_cast<u32>(document_tree_child_browsing_context_count());
|
return static_cast<u32>(document_tree_child_browsing_context_count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-top
|
||||||
|
JS::GCPtr<WindowProxy const> Window::top() const
|
||||||
|
{
|
||||||
|
// 1. If this's navigable is null, then return null.
|
||||||
|
auto const* browsing_context = this->browsing_context();
|
||||||
|
if (!browsing_context)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 2. Return this's navigable's top-level traversable's active WindowProxy.
|
||||||
|
return browsing_context->top_level_browsing_context().window_proxy();
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator
|
||||||
JS::NonnullGCPtr<Navigator> Window::navigator() const
|
JS::NonnullGCPtr<Navigator> Window::navigator() const
|
||||||
{
|
{
|
||||||
|
@ -1548,20 +1559,6 @@ size_t Window::document_tree_child_browsing_context_count() const
|
||||||
return this_browsing_context->document_tree_child_browsing_context_count();
|
return this_browsing_context->document_tree_child_browsing_context_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/browsers.html#dom-top
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(Window::top_getter)
|
|
||||||
{
|
|
||||||
auto* impl = TRY(impl_from(vm));
|
|
||||||
|
|
||||||
// 1. If this Window object's browsing context is null, then return null.
|
|
||||||
auto* browsing_context = impl->browsing_context();
|
|
||||||
if (!browsing_context)
|
|
||||||
return JS::js_null();
|
|
||||||
|
|
||||||
// 2. Return this Window object's browsing context's top-level browsing context's WindowProxy object.
|
|
||||||
return browsing_context->top_level_browsing_context().window_proxy();
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter)
|
JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter)
|
||||||
{
|
{
|
||||||
auto* impl = TRY(impl_from(vm));
|
auto* impl = TRY(impl_from(vm));
|
||||||
|
|
|
@ -147,6 +147,7 @@ public:
|
||||||
|
|
||||||
JS::NonnullGCPtr<WindowProxy> frames() const;
|
JS::NonnullGCPtr<WindowProxy> frames() const;
|
||||||
u32 length() const;
|
u32 length() const;
|
||||||
|
JS::GCPtr<WindowProxy const> top() const;
|
||||||
|
|
||||||
JS::NonnullGCPtr<Navigator> navigator() const;
|
JS::NonnullGCPtr<Navigator> navigator() const;
|
||||||
|
|
||||||
|
@ -218,8 +219,6 @@ public:
|
||||||
CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; }
|
CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(top_getter);
|
|
||||||
|
|
||||||
JS_DECLARE_NATIVE_FUNCTION(frame_element_getter);
|
JS_DECLARE_NATIVE_FUNCTION(frame_element_getter);
|
||||||
|
|
||||||
JS_DECLARE_NATIVE_FUNCTION(location_setter);
|
JS_DECLARE_NATIVE_FUNCTION(location_setter);
|
||||||
|
|
|
@ -17,6 +17,7 @@ interface Window : EventTarget {
|
||||||
// other browsing contexts
|
// other browsing contexts
|
||||||
[Replaceable] readonly attribute WindowProxy frames;
|
[Replaceable] readonly attribute WindowProxy frames;
|
||||||
[Replaceable] readonly attribute unsigned long length;
|
[Replaceable] readonly attribute unsigned long length;
|
||||||
|
[LegacyUnforgeable] readonly attribute WindowProxy? top;
|
||||||
|
|
||||||
// the user agent
|
// the user agent
|
||||||
readonly attribute Navigator navigator;
|
readonly attribute Navigator navigator;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue