1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:27:46 +00:00

LibWeb: Implement a simple version of Element.scrollIntoView()

We parse the arguments that come in, but since we don't yet track
scrollable overflow, we can't do the full "scroll an element into view"
algorithm. For now, we just call out to the PageClient and ask it to
bring the nearest principal box into the visible viewport.
This commit is contained in:
Andreas Kling 2022-10-04 19:52:25 +02:00
parent 3ca44e2258
commit 162e4179fc
3 changed files with 103 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#include <AK/FlyString.h>
#include <AK/String.h>
#include <LibWeb/Bindings/ElementPrototype.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Attr.h>
@ -25,6 +26,17 @@
namespace Web::DOM {
// https://w3c.github.io/csswg-drafts/cssom-view-1/#dictdef-scrolloptions
struct ScrollOptions {
Bindings::ScrollBehavior behavior { Bindings::ScrollBehavior::Auto };
};
// https://w3c.github.io/csswg-drafts/cssom-view-1/#dictdef-scrollintoviewoptions
struct ScrollIntoViewOptions : public ScrollOptions {
Bindings::ScrollLogicalPosition block { Bindings::ScrollLogicalPosition::Start };
Bindings::ScrollLogicalPosition inline_ { Bindings::ScrollLogicalPosition::Nearest };
};
class Element
: public ParentNode
, public ChildNode<Element>
@ -147,6 +159,9 @@ public:
WebIDL::ExceptionOr<JS::GCPtr<Element>> insert_adjacent_element(String const& where, JS::NonnullGCPtr<Element> element);
WebIDL::ExceptionOr<void> insert_adjacent_text(String const& where, String const& data);
// https://w3c.github.io/csswg-drafts/cssom-view-1/#dom-element-scrollintoview
void scroll_into_view(Optional<Variant<bool, ScrollIntoViewOptions>>);
protected:
Element(Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;