mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 02:08:12 +03: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
Notes:
sideshowbarker
2024-07-18 04:16:19 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/9588a377ec3 Pull-request: https://github.com/SerenityOS/serenity/pull/9912 Reviewed-by: https://github.com/Lubrsi Reviewed-by: https://github.com/davidot Reviewed-by: https://github.com/linusg ✅
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
@ -72,6 +73,9 @@ private:
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(parent_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_GETTER(scroll_x_getter);
|
||||
JS_DECLARE_NATIVE_GETTER(scroll_y_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(alert);
|
||||
JS_DECLARE_NATIVE_FUNCTION(confirm);
|
||||
JS_DECLARE_NATIVE_FUNCTION(prompt);
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
|
||||
void set_needs_display(Gfx::IntRect const&);
|
||||
|
||||
Gfx::IntPoint const& viewport_scroll_offset() const { return m_viewport_scroll_offset; }
|
||||
void set_viewport_scroll_offset(Gfx::IntPoint const&);
|
||||
Gfx::IntRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; }
|
||||
void set_viewport_rect(Gfx::IntRect const&);
|
||||
|
Loading…
Reference in New Issue
Block a user