Skip to content

Commit 25f53a5

Browse files
committed
LibWeb/HTML: Port Window.inner{Width,Height} to IDL
1 parent 0c69108 commit 25f53a5

File tree

3 files changed

+27
-40
lines changed

3 files changed

+27
-40
lines changed

Userland/Libraries/LibWeb/HTML/Window.cpp

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -586,26 +586,6 @@ bool Window::dispatch_event(DOM::Event& event)
586586
return DOM::EventDispatcher::dispatch(*this, event, true);
587587
}
588588

589-
// https://www.w3.org/TR/cssom-view-1/#dom-window-innerwidth
590-
int Window::inner_width() const
591-
{
592-
// The innerWidth attribute must return the viewport width including the size of a rendered scroll bar (if any),
593-
// or zero if there is no viewport.
594-
if (auto const* browsing_context = associated_document().browsing_context())
595-
return browsing_context->viewport_rect().width().value();
596-
return 0;
597-
}
598-
599-
// https://www.w3.org/TR/cssom-view-1/#dom-window-innerheight
600-
int Window::inner_height() const
601-
{
602-
// The innerHeight attribute must return the viewport height including the size of a rendered scroll bar (if any),
603-
// or zero if there is no viewport.
604-
if (auto const* browsing_context = associated_document().browsing_context())
605-
return browsing_context->viewport_rect().height().value();
606-
return 0;
607-
}
608-
609589
Page* Window::page()
610590
{
611591
return associated_document().page();
@@ -1030,8 +1010,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
10301010
MUST_OR_THROW_OOM(Bindings::WindowGlobalMixin::initialize(realm, *this));
10311011

10321012
// FIXME: These should be native accessors, not properties
1033-
define_native_accessor(realm, "innerWidth", inner_width_getter, {}, JS::Attribute::Enumerable);
1034-
define_native_accessor(realm, "innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable);
10351013
define_native_accessor(realm, "devicePixelRatio", device_pixel_ratio_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
10361014
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
10371015
define_native_function(realm, "setInterval", set_interval, 1, attr);
@@ -1335,6 +1313,26 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::Screen>> Window::screen()
13351313
return JS::NonnullGCPtr { *m_screen };
13361314
}
13371315

1316+
// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-innerwidth
1317+
i32 Window::inner_width() const
1318+
{
1319+
// The innerWidth attribute must return the viewport width including the size of a rendered scroll bar (if any),
1320+
// or zero if there is no viewport.
1321+
if (auto const* browsing_context = associated_document().browsing_context())
1322+
return browsing_context->viewport_rect().width().value();
1323+
return 0;
1324+
}
1325+
1326+
// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-innerheight
1327+
i32 Window::inner_height() const
1328+
{
1329+
// The innerHeight attribute must return the viewport height including the size of a rendered scroll bar (if any),
1330+
// or zero if there is no viewport.
1331+
if (auto const* browsing_context = associated_document().browsing_context())
1332+
return browsing_context->viewport_rect().height().value();
1333+
return 0;
1334+
}
1335+
13381336
// https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance
13391337
WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> Window::performance()
13401338
{
@@ -1531,18 +1529,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::location_setter)
15311529
return JS::js_undefined();
15321530
}
15331531

1534-
JS_DEFINE_NATIVE_FUNCTION(Window::inner_width_getter)
1535-
{
1536-
auto* impl = TRY(impl_from(vm));
1537-
return JS::Value(impl->inner_width());
1538-
}
1539-
1540-
JS_DEFINE_NATIVE_FUNCTION(Window::inner_height_getter)
1541-
{
1542-
auto* impl = TRY(impl_from(vm));
1543-
return JS::Value(impl->inner_height());
1544-
}
1545-
15461532
JS_DEFINE_NATIVE_FUNCTION(Window::device_pixel_ratio_getter)
15471533
{
15481534
auto* impl = TRY(impl_from(vm));

Userland/Libraries/LibWeb/HTML/Window.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ class Window final
8787

8888
void queue_microtask_impl(WebIDL::CallbackType& callback);
8989

90-
int inner_width() const;
91-
int inner_height() const;
92-
9390
void did_set_location_href(Badge<HTML::Location>, AK::URL const& new_href);
9491
void did_call_location_reload(Badge<HTML::Location>);
9592
void did_call_location_replace(Badge<HTML::Location>, DeprecatedString url);
@@ -165,6 +162,9 @@ class Window final
165162
WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::MediaQueryList>> match_media(String const& query);
166163
WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::Screen>> screen();
167164

165+
i32 inner_width() const;
166+
i32 inner_height() const;
167+
168168
WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> performance();
169169

170170
WebIDL::ExceptionOr<JS::NonnullGCPtr<Crypto::Crypto>> crypto();
@@ -231,9 +231,6 @@ class Window final
231231
private:
232232
JS_DECLARE_NATIVE_FUNCTION(location_setter);
233233

234-
JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
235-
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
236-
237234
JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter);
238235

239236
JS_DECLARE_NATIVE_FUNCTION(scroll_x_getter);

Userland/Libraries/LibWeb/HTML/Window.idl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ interface Window : EventTarget {
4848
[NewObject] MediaQueryList matchMedia(CSSOMString query);
4949
[SameObject, Replaceable] readonly attribute Screen screen;
5050

51+
// viewport
52+
[Replaceable] readonly attribute long innerWidth;
53+
[Replaceable] readonly attribute long innerHeight;
54+
5155
// FIXME: Everything from here on should be shared through WindowOrWorkerGlobalScope
5256
// https://w3c.github.io/hr-time/#the-performance-attribute
5357
[Replaceable] readonly attribute Performance performance;

0 commit comments

Comments
 (0)