1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:57:45 +00:00

LibWeb: Move window.scroll{X,Y} from wrapper into DOM::Window

The less we do in WindowObject, the easier it will be to eventually
auto-generate the entire thing.
This commit is contained in:
Andreas Kling 2021-09-24 21:49:31 +02:00
parent 38157a6093
commit 2c0987c93b
3 changed files with 21 additions and 6 deletions

View file

@ -510,9 +510,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::scroll_x_getter)
auto* impl = impl_from(vm, global_object);
if (!impl)
return {};
if (!impl->page())
return JS::Value(0);
return JS::Value(impl->page()->top_level_browsing_context().viewport_scroll_offset().x());
return JS::Value(impl->scroll_x());
}
// https://www.w3.org/TR/cssom-view/#dom-window-scrolly
@ -521,9 +519,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::scroll_y_getter)
auto* impl = impl_from(vm, global_object);
if (!impl)
return {};
if (!impl->page())
return JS::Value(0);
return JS::Value(impl->page()->top_level_browsing_context().viewport_scroll_offset().y());
return JS::Value(impl->scroll_y());
}
enum class ScrollBehavior {

View file

@ -260,4 +260,20 @@ NonnullRefPtr<CSS::MediaQueryList> Window::match_media(String media)
return CSS::MediaQueryList::create(associated_document(), move(media));
}
// 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();
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();
return 0;
}
}

View file

@ -80,6 +80,9 @@ public:
NonnullRefPtr<CSS::CSSStyleDeclaration> get_computed_style(DOM::Element&) const;
NonnullRefPtr<CSS::MediaQueryList> match_media(String);
float scroll_x() const;
float scroll_y() const;
private:
explicit Window(Document&);