mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWeb/HTML: Port Window.screen{X,Y} / Window.screen{Left,Top} to IDL
This commit is contained in:
parent
3d075e55f5
commit
80acf03278
Notes:
sideshowbarker
2024-07-17 10:54:57 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/80acf03278 Pull-request: https://github.com/SerenityOS/serenity/pull/17752 Reviewed-by: https://github.com/awesomekling
3 changed files with 29 additions and 57 deletions
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue