mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
LibWeb: Implement Window.scroll{X,Y} JS properties
...and pageXOffset/pageYOffset too, since those are just aliases for the same thing.
This commit is contained in:
parent
83414af9f3
commit
9588a377ec
3 changed files with 35 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -29,6 +30,7 @@
|
|||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/Origin.h>
|
||||
#include <LibWeb/Page/BrowsingContext.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/WebAssembly/WebAssemblyObject.h>
|
||||
|
||||
#include <LibWeb/Bindings/WindowObjectHelper.h>
|
||||
|
@ -74,6 +76,12 @@ void WindowObject::initialize_global_object()
|
|||
|
||||
define_native_function("getComputedStyle", get_computed_style, 1, attr);
|
||||
|
||||
// FIXME: These properties should be [Replaceable] according to the spec, but [Writable+Configurable] is the closest we have.
|
||||
define_native_accessor("scrollX", scroll_x_getter, {}, attr);
|
||||
define_native_accessor("pageXOffset", scroll_x_getter, {}, attr);
|
||||
define_native_accessor("scrollY", scroll_y_getter, {}, attr);
|
||||
define_native_accessor("pageYOffset", scroll_y_getter, {}, attr);
|
||||
|
||||
// Legacy
|
||||
define_native_accessor("event", event_getter, {}, JS::Attribute::Enumerable);
|
||||
|
||||
|
@ -458,4 +466,26 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style)
|
|||
return wrap(global_object, impl->get_computed_style(static_cast<ElementWrapper*>(object)->impl()));
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-view/#dom-window-scrollx
|
||||
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());
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-view/#dom-window-scrolly
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue