Truly independent web browser
/*
* Copyright (c) 2026, Jelle Raaijmakers <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/OwnPtr.h>
#include <LibGC/Ptr.h>
#include <LibJS/Heap/Cell.h>
#include <LibWeb/Forward.h>
#include <LibWebCommon/PixelUnits.h>
namespace Web {
class AutoScrollHandler {
public:
AK_ALLOC_WITH_KMALLOC;
AutoScrollHandler(HTML::LocalNavigable&, DOM::Element& container);
~AutoScrollHandler();
void visit_edges(JS::Cell::Visitor&) const;
CSSPixelPoint process(CSSPixelPoint mouse_position);
void perform_tick();
bool is_active() const { return m_active; }
// The scrollport that keeps the pointer of the selection the handler scrolls for, in the coordinates of the viewport.
Optional<CSSPixelRect> scrollport_in_viewport(Layout::BegunRead const&) const;
static GC::Ptr<DOM::Element> find_scrollable_ancestor(Layout::Node const&);
static Layout::Node* auto_scroll_layout_node(Layout::BegunRead const& read, DOM::Element&);
private:
void activate();
void deactivate();
GC::Ref<HTML::LocalNavigable> m_navigable;
GC::Ref<DOM::Element> m_container_element;
CSSPixelPoint m_mouse_position;
CSSPixelPoint m_fractional_delta;
OwnPtr<HTML::UserScrollGestureHold> m_scroll_gesture_hold;
bool m_active { false };
};
}