From 80acf03278e216843cc977800132b5319a5abca7 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 6 Mar 2023 21:38:09 +0000 Subject: [PATCH] LibWeb/HTML: Port Window.screen{X,Y} / Window.screen{Left,Top} to IDL --- Userland/Libraries/LibWeb/HTML/Window.cpp | 69 +++++++---------------- Userland/Libraries/LibWeb/HTML/Window.h | 11 +--- Userland/Libraries/LibWeb/HTML/Window.idl | 6 ++ 3 files changed, 29 insertions(+), 57 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 6d6ae49cdd6..f00e6bbf8f9 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -750,26 +750,6 @@ float Window::device_pixel_ratio() const return 1.0f; } -// https://drafts.csswg.org/cssom-view/#dom-window-screenx -int Window::screen_x() const -{ - // The screenX and screenLeft attributes must return the x-coordinate, relative to the origin of the Web-exposed screen area, - // of the left of the client window as number of CSS pixels, or zero if there is no such thing. - if (auto* page = this->page()) - return page->window_position().x().value(); - return 0; -} - -// https://drafts.csswg.org/cssom-view/#dom-window-screeny -int Window::screen_y() const -{ - // The screenY and screenTop attributes must return the y-coordinate, relative to the origin of the screen of the Web-exposed screen area, - // of the top of the client window as number of CSS pixels, or zero if there is no such thing. - if (auto* page = this->page()) - return page->window_position().y().value(); - return 0; -} - // https://drafts.csswg.org/cssom-view/#dom-window-outerwidth int Window::outer_width() const { @@ -1017,11 +997,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badgepage()) + return page->window_position().x().value(); + return 0; +} + +// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-screeny +i32 Window::screen_y() const +{ + // The screenY and screenTop attributes must return the y-coordinate, relative to the origin of the screen of the + // Web-exposed screen area, of the top of the client window as number of CSS pixels, or zero if there is no such thing. + if (auto* page = this->page()) + return page->window_position().y().value(); + return 0; +} + // https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance WebIDL::ExceptionOr> Window::performance() { @@ -1680,30 +1675,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::get_selection) return impl->associated_document().get_selection(); } -JS_DEFINE_NATIVE_FUNCTION(Window::screen_left_getter) -{ - auto* impl = TRY(impl_from(vm)); - return JS::Value(impl->screen_x()); -} - -JS_DEFINE_NATIVE_FUNCTION(Window::screen_top_getter) -{ - auto* impl = TRY(impl_from(vm)); - return JS::Value(impl->screen_y()); -} - -JS_DEFINE_NATIVE_FUNCTION(Window::screen_x_getter) -{ - auto* impl = TRY(impl_from(vm)); - return JS::Value(impl->screen_x()); -} - -JS_DEFINE_NATIVE_FUNCTION(Window::screen_y_getter) -{ - auto* impl = TRY(impl_from(vm)); - return JS::Value(impl->screen_y()); -} - JS_DEFINE_NATIVE_FUNCTION(Window::outer_width_getter) { auto* impl = TRY(impl_from(vm)); diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 96fcabad917..390d3facc60 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 screen_x() const; - int screen_y() const; - int outer_width() const; int outer_height() const; @@ -180,6 +177,9 @@ public: void scroll_by(ScrollToOptions); void scroll_by(double x, double y); + i32 screen_x() const; + i32 screen_y() const; + WebIDL::ExceptionOr> performance(); WebIDL::ExceptionOr> crypto(); @@ -248,11 +248,6 @@ private: JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter); - JS_DECLARE_NATIVE_FUNCTION(screen_x_getter); - JS_DECLARE_NATIVE_FUNCTION(screen_y_getter); - JS_DECLARE_NATIVE_FUNCTION(screen_left_getter); - JS_DECLARE_NATIVE_FUNCTION(screen_top_getter); - JS_DECLARE_NATIVE_FUNCTION(outer_width_getter); JS_DECLARE_NATIVE_FUNCTION(outer_height_getter); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index be6e2b4cef1..2a9d648f6a0 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -64,6 +64,12 @@ interface Window : EventTarget { undefined scrollBy(optional ScrollToOptions options = {}); undefined scrollBy(unrestricted double x, unrestricted double y); + // client + [Replaceable] readonly attribute long screenX; + [Replaceable, ImplementedAs=screen_x] readonly attribute long screenLeft; + [Replaceable] readonly attribute long screenY; + [Replaceable, ImplementedAs=screen_y] readonly attribute long screenTop; + // FIXME: Everything from here on should be shared through WindowOrWorkerGlobalScope // https://w3c.github.io/hr-time/#the-performance-attribute [Replaceable] readonly attribute Performance performance;