Truly independent web browser
/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibCompositing/Scrolling/AsyncScrollingState.h>
#include <LibWeb/Forward.h>
#include <LibWeb/TextAffinity.h>
#include <LibWebCommon/PixelUnits.h>
namespace Web::Painting {
enum class ScrollDirection : u8 {
Horizontal,
Vertical,
};
enum class ScrollHandled {
No,
Yes,
};
// https://drafts.csswg.org/css-scroll-snap-1/#scroll-types
enum class ScrollKind : u8 {
// A scroll with an intended direction, such as a mouse wheel step or an arrow key press.
Relative,
// A scroll with only an intended end position, such as dragging a scrollbar thumb.
Absolute,
};
enum class ScrollBlockDirection {
No,
Yes,
};
CSSPixelPoint scroll_offset(Layout::Node const&);
CSSPixelPoint minimum_scroll_offset(Layout::Node const&);
CSSPixelPoint maximum_scroll_offset(Layout::Node const&);
CSSPixelPoint clamp_scroll_offset(Layout::Node const&, CSSPixelPoint);
CSSPixelRect scroll_snapport_rect(Layout::Node const&);
CSSPixelRect scroll_snapport_rect(Layout::Node const&, CSSPixelRect scrollport);
struct WheelScrollableAxes {
bool horizontal { false };
bool vertical { false };
};
WheelScrollableAxes wheel_scrollable_axes(Layout::Node const&);
bool could_be_scrolled_by_wheel_event(Layout::Node const&);
WEB_API Optional<Web::AsyncScrollNodeStableID> async_scroll_node_stable_id(Layout::Node const&);
ScrollHandled set_scroll_offset(Layout::Node&, CSSPixelPoint);
ScrollHandled set_scroll_offset_from_user_input(Layout::Node&, CSSPixelPoint, ScrollKind = ScrollKind::Relative);
ScrollHandled scroll_by(Layout::Node&, double delta_x, double delta_y, ScrollKind = ScrollKind::Relative);
WEB_API Layout::Node* first_wheel_scrollable_box_in_containing_block_chain(Layout::Node const&);
// The nearest box in the containing block chain, the given one included, that keeps a scroll step by the delta to
// itself instead of passing it on to a scroller around it. The step scrolls that box or a box inside it, or nothing.
Layout::Node* box_ending_scroll_chain(Layout::Node const&, double delta_x, double delta_y);
void scroll_text_offset_into_view(Layout::BegunRead const&, DOM::Text const&, size_t offset, TextAffinity = TextAffinity::Downstream, ScrollBlockDirection = ScrollBlockDirection::Yes);
}