diff options
author | Linus Groh <mail@linusgroh.de> | 2023-03-06 21:38:09 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-07 23:33:34 +0000 |
commit | 80acf03278e216843cc977800132b5319a5abca7 (patch) | |
tree | 4597122e9a704b919e36a100b23806e71287224b /Userland/Libraries | |
parent | 3d075e55f59f02a518bef68b9a7218f0dfb8b7b4 (diff) | |
download | serenity-80acf03278e216843cc977800132b5319a5abca7.zip |
LibWeb/HTML: Port Window.screen{X,Y} / Window.screen{Left,Top} to IDL
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Window.cpp | 69 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Window.h | 11 | ||||
-rw-r--r-- | 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 6d6ae49cdd..f00e6bbf8f 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<void> Window::initialize_web_interfaces(Badge<WindowEnvironm define_native_function(realm, "fetch", Bindings::fetch, 1, attr); // FIXME: These properties should be [Replaceable] according to the spec, but [Writable+Configurable] is the closest we have. - define_native_accessor(realm, "screenX", screen_x_getter, {}, attr); - define_native_accessor(realm, "screenY", screen_y_getter, {}, attr); - define_native_accessor(realm, "screenLeft", screen_left_getter, {}, attr); - define_native_accessor(realm, "screenTop", screen_top_getter, {}, attr); - define_native_accessor(realm, "outerWidth", outer_width_getter, {}, attr); define_native_accessor(realm, "outerHeight", outer_height_getter, {}, attr); @@ -1460,6 +1435,26 @@ void Window::scroll_by(double x, double y) scroll_by(options); } +// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-screenx +i32 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://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<JS::NonnullGCPtr<HighResolutionTime::Performance>> 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 96fcabad91..390d3facc6 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<JS::NonnullGCPtr<HighResolutionTime::Performance>> performance(); WebIDL::ExceptionOr<JS::NonnullGCPtr<Crypto::Crypto>> 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 be6e2b4cef..2a9d648f6a 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; |