LibWeb/HTML: Port Window.scroll{X,Y} / Window.page{X,Y}Offset to IDL
This commit is contained in:
parent
25f53a577d
commit
40b4ee88de
Notes:
sideshowbarker
2024-07-17 02:08:15 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/40b4ee88de Pull-request: https://github.com/SerenityOS/serenity/pull/17752 Reviewed-by: https://github.com/awesomekling
4 changed files with 33 additions and 44 deletions
|
@ -977,7 +977,7 @@ void Element::set_scroll_left(double x)
|
|||
if (document.document_element() == this) {
|
||||
// FIXME: Implement this in terms of invoking scroll() on window.
|
||||
if (auto* page = document.page())
|
||||
page->client().page_did_request_scroll_to({ static_cast<float>(x), window->scroll_y() });
|
||||
page->client().page_did_request_scroll_to({ static_cast<float>(x), static_cast<float>(window->scroll_y()) });
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -986,7 +986,7 @@ void Element::set_scroll_left(double x)
|
|||
if (document.body() == this && document.in_quirks_mode() && !is_potentially_scrollable()) {
|
||||
// FIXME: Implement this in terms of invoking scroll() on window.
|
||||
if (auto* page = document.page())
|
||||
page->client().page_did_request_scroll_to({ static_cast<float>(x), window->scroll_y() });
|
||||
page->client().page_did_request_scroll_to({ static_cast<float>(x), static_cast<float>(window->scroll_y()) });
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1041,7 +1041,7 @@ void Element::set_scroll_top(double y)
|
|||
if (document.document_element() == this) {
|
||||
// FIXME: Implement this in terms of invoking scroll() on window.
|
||||
if (auto* page = document.page())
|
||||
page->client().page_did_request_scroll_to({ window->scroll_x(), static_cast<float>(y) });
|
||||
page->client().page_did_request_scroll_to({ static_cast<float>(window->scroll_x()), static_cast<float>(y) });
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1050,7 +1050,7 @@ void Element::set_scroll_top(double y)
|
|||
if (document.body() == this && document.in_quirks_mode() && !is_potentially_scrollable()) {
|
||||
// FIXME: Implement this in terms of invoking scroll() on window.
|
||||
if (auto* page = document.page())
|
||||
page->client().page_did_request_scroll_to({ window->scroll_x(), static_cast<float>(y) });
|
||||
page->client().page_did_request_scroll_to({ static_cast<float>(window->scroll_x()), static_cast<float>(y) });
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -712,22 +712,6 @@ Optional<CSS::MediaFeatureValue> Window::query_media_feature(CSS::MediaFeatureID
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-view/#dom-window-scrollx
|
||||
float Window::scroll_x() const
|
||||
{
|
||||
if (auto* page = this->page())
|
||||
return page->top_level_browsing_context().viewport_scroll_offset().x().value();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-view/#dom-window-scrolly
|
||||
float Window::scroll_y() const
|
||||
{
|
||||
if (auto* page = this->page())
|
||||
return page->top_level_browsing_context().viewport_scroll_offset().y().value();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#fire-a-page-transition-event
|
||||
void Window::fire_a_page_transition_event(DeprecatedFlyString const& event_name, bool persisted)
|
||||
{
|
||||
|
@ -1033,11 +1017,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, "scrollX", scroll_x_getter, {}, attr);
|
||||
define_native_accessor(realm, "pageXOffset", scroll_x_getter, {}, attr);
|
||||
define_native_accessor(realm, "scrollY", scroll_y_getter, {}, attr);
|
||||
define_native_accessor(realm, "pageYOffset", scroll_y_getter, {}, attr);
|
||||
|
||||
define_native_function(realm, "scroll", scroll, 2, attr);
|
||||
define_native_function(realm, "scrollTo", scroll, 2, attr);
|
||||
define_native_function(realm, "scrollBy", scroll_by, 2, attr);
|
||||
|
@ -1333,6 +1312,26 @@ i32 Window::inner_height() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-scrollx
|
||||
double Window::scroll_x() const
|
||||
{
|
||||
// The scrollX attribute must return the x-coordinate, relative to the initial containing block origin,
|
||||
// of the left of the viewport, or zero if there is no viewport.
|
||||
if (auto* page = this->page())
|
||||
return page->top_level_browsing_context().viewport_scroll_offset().x().value();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-scrolly
|
||||
double Window::scroll_y() const
|
||||
{
|
||||
// The scrollY attribute must return the y-coordinate, relative to the initial containing block origin,
|
||||
// of the top of the viewport, or zero if there is no viewport.
|
||||
if (auto* page = this->page())
|
||||
return page->top_level_browsing_context().viewport_scroll_offset().y().value();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> Window::performance()
|
||||
{
|
||||
|
@ -1553,20 +1552,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::get_selection)
|
|||
return impl->associated_document().get_selection();
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-view/#dom-window-scrollx
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::scroll_x_getter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
return JS::Value(impl->scroll_x());
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-view/#dom-window-scrolly
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::scroll_y_getter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
return JS::Value(impl->scroll_y());
|
||||
}
|
||||
|
||||
enum class ScrollBehavior {
|
||||
Auto,
|
||||
Smooth
|
||||
|
|
|
@ -100,9 +100,6 @@ public:
|
|||
CSS::CSSStyleDeclaration* get_computed_style_impl(DOM::Element&) const;
|
||||
Optional<CSS::MediaFeatureValue> query_media_feature(CSS::MediaFeatureID) const;
|
||||
|
||||
float scroll_x() const;
|
||||
float scroll_y() const;
|
||||
|
||||
void fire_a_page_transition_event(DeprecatedFlyString const& event_name, bool persisted);
|
||||
|
||||
float device_pixel_ratio() const;
|
||||
|
@ -165,6 +162,9 @@ public:
|
|||
i32 inner_width() const;
|
||||
i32 inner_height() const;
|
||||
|
||||
double scroll_x() const;
|
||||
double scroll_y() const;
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> performance();
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Crypto::Crypto>> crypto();
|
||||
|
@ -233,8 +233,6 @@ private:
|
|||
|
||||
JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(scroll_x_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(scroll_y_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(scroll);
|
||||
JS_DECLARE_NATIVE_FUNCTION(scroll_by);
|
||||
|
||||
|
|
|
@ -52,6 +52,12 @@ interface Window : EventTarget {
|
|||
[Replaceable] readonly attribute long innerWidth;
|
||||
[Replaceable] readonly attribute long innerHeight;
|
||||
|
||||
// viewport scrolling
|
||||
[Replaceable] readonly attribute double scrollX;
|
||||
[Replaceable, ImplementedAs=scroll_x] readonly attribute double pageXOffset;
|
||||
[Replaceable] readonly attribute double scrollY;
|
||||
[Replaceable, ImplementedAs=scroll_y] readonly attribute double pageYOffset;
|
||||
|
||||
// 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…
Add table
Reference in a new issue