mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 21:12:08 +02:00
When the middle mouse button is pressed, we can now scroll the pressed container while moving the mouse around. We paint an indicator at the pressed origin (as an overlay), as the scroll speed will depend upon the distance between the moved mouse and that origin.
40 lines
948 B
C++
40 lines
948 B
C++
/*
|
|
* Copyright (c) 2026, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGC/Ptr.h>
|
|
#include <LibJS/Heap/Cell.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/PixelUnits.h>
|
|
|
|
namespace Web {
|
|
|
|
class MiddleButtonScrollHandler {
|
|
public:
|
|
MiddleButtonScrollHandler(DOM::Element& container, CSSPixelPoint origin);
|
|
~MiddleButtonScrollHandler();
|
|
|
|
void visit_edges(JS::Cell::Visitor&) const;
|
|
|
|
static GC::Ptr<DOM::Element> find_scrollable_ancestor(DOM::Document&, Painting::Paintable&);
|
|
|
|
void update_mouse_position(CSSPixelPoint);
|
|
void perform_tick();
|
|
|
|
CSSPixelPoint origin() const { return m_origin; }
|
|
bool mouse_has_moved() const { return m_mouse_has_moved; }
|
|
|
|
private:
|
|
GC::Ref<DOM::Element> m_container_element;
|
|
CSSPixelPoint m_origin;
|
|
CSSPixelPoint m_mouse_position;
|
|
CSSPixelPoint m_fractional_delta;
|
|
bool m_mouse_has_moved { false };
|
|
};
|
|
|
|
}
|