From 46e547d774f18c471e7a81c95cef1a573b13b6a2 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 6 Mar 2023 22:02:09 +0000 Subject: [PATCH] LibWeb/HTML: Port Window.outer{Width,Height} to IDL --- Userland/Libraries/LibWeb/HTML/Window.cpp | 54 +++++++++-------------- Userland/Libraries/LibWeb/HTML/Window.h | 8 +--- Userland/Libraries/LibWeb/HTML/Window.idl | 2 + 3 files changed, 24 insertions(+), 40 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index f00e6bbf8f..6110804e6d 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -750,24 +750,6 @@ float Window::device_pixel_ratio() const return 1.0f; } -// https://drafts.csswg.org/cssom-view/#dom-window-outerwidth -int Window::outer_width() const -{ - // The outerWidth attribute must return the width of the client window. If there is no client window this attribute must return zero. - if (auto* page = this->page()) - return page->window_size().width().value(); - return 0; -} - -// https://drafts.csswg.org/cssom-view/#dom-window-screeny -int Window::outer_height() const -{ - // The outerHeight attribute must return the height of the client window. If there is no client window this attribute must return zero. - if (auto* page = this->page()) - return page->window_size().height().value(); - return 0; -} - // https://html.spec.whatwg.org/multipage/webstorage.html#dom-localstorage JS::NonnullGCPtr Window::local_storage() { @@ -996,10 +978,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge(realm, realm)), 0); define_native_accessor(realm, "localStorage", local_storage_getter, {}, attr); @@ -1455,6 +1433,26 @@ i32 Window::screen_y() const return 0; } +// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-outerwidth +i32 Window::outer_width() const +{ + // The outerWidth attribute must return the width of the client window. If there is no client window this + // attribute must return zero. + if (auto* page = this->page()) + return page->window_size().width().value(); + return 0; +} + +// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-outerheight +i32 Window::outer_height() const +{ + // The outerHeight attribute must return the height of the client window. If there is no client window this + // attribute must return zero. + if (auto* page = this->page()) + return page->window_size().height().value(); + return 0; +} + // https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance WebIDL::ExceptionOr> Window::performance() { @@ -1675,18 +1673,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::get_selection) return impl->associated_document().get_selection(); } -JS_DEFINE_NATIVE_FUNCTION(Window::outer_width_getter) -{ - auto* impl = TRY(impl_from(vm)); - return JS::Value(impl->outer_width()); -} - -JS_DEFINE_NATIVE_FUNCTION(Window::outer_height_getter) -{ - auto* impl = TRY(impl_from(vm)); - return JS::Value(impl->outer_height()); -} - JS_DEFINE_NATIVE_FUNCTION(Window::structured_clone) { auto* impl = TRY(impl_from(vm)); diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 390d3facc6..9dac88f53b 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -115,9 +115,6 @@ public: float device_pixel_ratio() const; - int outer_width() const; - int outer_height() const; - JS::NonnullGCPtr local_storage(); JS::NonnullGCPtr session_storage(); @@ -179,6 +176,8 @@ public: i32 screen_x() const; i32 screen_y() const; + i32 outer_width() const; + i32 outer_height() const; WebIDL::ExceptionOr> performance(); @@ -248,9 +247,6 @@ private: JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter); - JS_DECLARE_NATIVE_FUNCTION(outer_width_getter); - JS_DECLARE_NATIVE_FUNCTION(outer_height_getter); - JS_DECLARE_NATIVE_FUNCTION(structured_clone); JS_DECLARE_NATIVE_FUNCTION(local_storage_getter); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 2a9d648f6a..a882f3fc05 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -69,6 +69,8 @@ interface Window : EventTarget { [Replaceable, ImplementedAs=screen_x] readonly attribute long screenLeft; [Replaceable] readonly attribute long screenY; [Replaceable, ImplementedAs=screen_y] readonly attribute long screenTop; + [Replaceable] readonly attribute long outerWidth; + [Replaceable] readonly attribute long outerHeight; // FIXME: Everything from here on should be shared through WindowOrWorkerGlobalScope // https://w3c.github.io/hr-time/#the-performance-attribute