mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibWeb/HTML: Port Window.inner{Width,Height} to IDL
This commit is contained in:
parent
0c691087ca
commit
25f53a577d
Notes:
sideshowbarker
2024-07-17 05:23:40 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/25f53a577d Pull-request: https://github.com/SerenityOS/serenity/pull/17752 Reviewed-by: https://github.com/awesomekling
3 changed files with 27 additions and 40 deletions
|
@ -586,26 +586,6 @@ bool Window::dispatch_event(DOM::Event& event)
|
|||
return DOM::EventDispatcher::dispatch(*this, event, true);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-view-1/#dom-window-innerwidth
|
||||
int Window::inner_width() const
|
||||
{
|
||||
// The innerWidth attribute must return the viewport width including the size of a rendered scroll bar (if any),
|
||||
// or zero if there is no viewport.
|
||||
if (auto const* browsing_context = associated_document().browsing_context())
|
||||
return browsing_context->viewport_rect().width().value();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-view-1/#dom-window-innerheight
|
||||
int Window::inner_height() const
|
||||
{
|
||||
// The innerHeight attribute must return the viewport height including the size of a rendered scroll bar (if any),
|
||||
// or zero if there is no viewport.
|
||||
if (auto const* browsing_context = associated_document().browsing_context())
|
||||
return browsing_context->viewport_rect().height().value();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Page* Window::page()
|
||||
{
|
||||
return associated_document().page();
|
||||
|
@ -1030,8 +1010,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, "innerWidth", inner_width_getter, {}, JS::Attribute::Enumerable);
|
||||
define_native_accessor(realm, "innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable);
|
||||
define_native_accessor(realm, "devicePixelRatio", device_pixel_ratio_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
|
||||
define_native_function(realm, "setInterval", set_interval, 1, attr);
|
||||
|
@ -1335,6 +1313,26 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::Screen>> Window::screen()
|
|||
return JS::NonnullGCPtr { *m_screen };
|
||||
}
|
||||
|
||||
// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-innerwidth
|
||||
i32 Window::inner_width() const
|
||||
{
|
||||
// The innerWidth attribute must return the viewport width including the size of a rendered scroll bar (if any),
|
||||
// or zero if there is no viewport.
|
||||
if (auto const* browsing_context = associated_document().browsing_context())
|
||||
return browsing_context->viewport_rect().width().value();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-innerheight
|
||||
i32 Window::inner_height() const
|
||||
{
|
||||
// The innerHeight attribute must return the viewport height including the size of a rendered scroll bar (if any),
|
||||
// or zero if there is no viewport.
|
||||
if (auto const* browsing_context = associated_document().browsing_context())
|
||||
return browsing_context->viewport_rect().height().value();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> Window::performance()
|
||||
{
|
||||
|
@ -1531,18 +1529,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::location_setter)
|
|||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::inner_width_getter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
return JS::Value(impl->inner_width());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::inner_height_getter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
return JS::Value(impl->inner_height());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::device_pixel_ratio_getter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
|
|
|
@ -87,9 +87,6 @@ public:
|
|||
|
||||
void queue_microtask_impl(WebIDL::CallbackType& callback);
|
||||
|
||||
int inner_width() const;
|
||||
int inner_height() const;
|
||||
|
||||
void did_set_location_href(Badge<HTML::Location>, AK::URL const& new_href);
|
||||
void did_call_location_reload(Badge<HTML::Location>);
|
||||
void did_call_location_replace(Badge<HTML::Location>, DeprecatedString url);
|
||||
|
@ -165,6 +162,9 @@ public:
|
|||
WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::MediaQueryList>> match_media(String const& query);
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::Screen>> screen();
|
||||
|
||||
i32 inner_width() const;
|
||||
i32 inner_height() const;
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> performance();
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Crypto::Crypto>> crypto();
|
||||
|
@ -231,9 +231,6 @@ public:
|
|||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(location_setter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(scroll_x_getter);
|
||||
|
|
|
@ -48,6 +48,10 @@ interface Window : EventTarget {
|
|||
[NewObject] MediaQueryList matchMedia(CSSOMString query);
|
||||
[SameObject, Replaceable] readonly attribute Screen screen;
|
||||
|
||||
// viewport
|
||||
[Replaceable] readonly attribute long innerWidth;
|
||||
[Replaceable] readonly attribute long innerHeight;
|
||||
|
||||
// FIXME: Everything from here on should be shared through WindowOrWorkerGlobalScope
|
||||
// https://w3c.github.io/hr-time/#the-performance-attribute
|
||||
[Replaceable] readonly attribute Performance performance;
|
||||
|
|
Loading…
Reference in a new issue