2020-06-07 14:40:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-07 14:40:38 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
2021-01-21 20:55:37 +01:00
|
|
|
#include <AK/NonnullOwnPtr.h>
|
2020-09-11 18:15:47 +02:00
|
|
|
#include <AK/WeakPtr.h>
|
2020-06-07 14:40:38 +02:00
|
|
|
#include <LibGfx/Forward.h>
|
2024-01-14 10:14:36 +01:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2023-04-27 09:19:20 -04:00
|
|
|
#include <LibJS/Heap/GCPtr.h>
|
2020-06-07 14:40:38 +02:00
|
|
|
#include <LibWeb/Forward.h>
|
2022-11-02 17:35:53 +00:00
|
|
|
#include <LibWeb/PixelUnits.h>
|
2024-06-06 13:29:08 -06:00
|
|
|
#include <LibWeb/UIEvents/KeyCode.h>
|
2020-06-07 14:40:38 +02:00
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
|
|
|
class EventHandler {
|
|
|
|
public:
|
2024-04-26 16:59:04 +02:00
|
|
|
explicit EventHandler(Badge<HTML::Navigable>, HTML::Navigable&);
|
2020-06-07 14:40:38 +02:00
|
|
|
~EventHandler();
|
|
|
|
|
2023-09-08 18:48:44 +02:00
|
|
|
bool handle_mouseup(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
|
|
|
|
bool handle_mousedown(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
|
|
|
|
bool handle_mousemove(CSSPixelPoint, CSSPixelPoint screen_position, unsigned buttons, unsigned modifiers);
|
|
|
|
bool handle_mousewheel(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
|
|
|
|
bool handle_doubleclick(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
|
2020-06-07 14:40:38 +02:00
|
|
|
|
2024-06-06 13:29:08 -06:00
|
|
|
bool handle_keydown(UIEvents::KeyCode, unsigned modifiers, u32 code_point);
|
|
|
|
bool handle_keyup(UIEvents::KeyCode, unsigned modifiers, u32 code_point);
|
2020-08-02 12:10:01 +02:00
|
|
|
|
2024-01-14 10:14:36 +01:00
|
|
|
void set_mouse_event_tracking_paintable(Painting::Paintable*);
|
2020-09-11 18:15:47 +02:00
|
|
|
|
2024-03-22 11:56:49 +01:00
|
|
|
void handle_paste(String const& text);
|
|
|
|
|
2024-01-14 10:14:36 +01:00
|
|
|
void visit_edges(JS::Cell::Visitor& visitor) const;
|
|
|
|
|
2020-06-07 14:40:38 +02:00
|
|
|
private:
|
2020-08-14 19:40:37 +02:00
|
|
|
bool focus_next_element();
|
|
|
|
bool focus_previous_element();
|
|
|
|
|
2024-06-06 13:29:08 -06:00
|
|
|
bool fire_keyboard_event(FlyString const& event_name, HTML::Navigable&, UIEvents::KeyCode, unsigned modifiers, u32 code_point);
|
2022-12-31 16:04:48 +02:00
|
|
|
CSSPixelPoint compute_mouse_event_client_offset(CSSPixelPoint event_page_position) const;
|
2022-12-31 16:40:36 +02:00
|
|
|
CSSPixelPoint compute_mouse_event_page_offset(CSSPixelPoint event_client_offset) const;
|
2023-08-24 17:47:13 +02:00
|
|
|
CSSPixelPoint compute_mouse_event_movement(CSSPixelPoint event_client_offset) const;
|
2022-11-05 15:36:03 +00:00
|
|
|
|
2023-04-27 09:19:20 -04:00
|
|
|
struct Target {
|
|
|
|
JS::GCPtr<Painting::Paintable> paintable;
|
|
|
|
Optional<int> index_in_node;
|
|
|
|
};
|
|
|
|
Optional<Target> target_for_mouse_position(CSSPixelPoint position);
|
|
|
|
|
2022-03-11 00:03:28 +01:00
|
|
|
Painting::PaintableBox* paint_root();
|
|
|
|
Painting::PaintableBox const* paint_root() const;
|
|
|
|
|
2024-04-26 16:59:04 +02:00
|
|
|
JS::NonnullGCPtr<HTML::Navigable> m_navigable;
|
2020-06-07 14:40:38 +02:00
|
|
|
|
|
|
|
bool m_in_mouse_selection { false };
|
2020-09-11 18:15:47 +02:00
|
|
|
|
2024-01-14 10:14:36 +01:00
|
|
|
JS::GCPtr<Painting::Paintable> m_mouse_event_tracking_paintable;
|
2020-12-01 23:35:47 +01:00
|
|
|
|
|
|
|
NonnullOwnPtr<EditEventHandler> m_edit_event_handler;
|
2022-02-07 13:27:17 +01:00
|
|
|
|
|
|
|
WeakPtr<DOM::EventTarget> m_mousedown_target;
|
2023-08-24 17:47:13 +02:00
|
|
|
|
2023-09-08 18:48:44 +02:00
|
|
|
Optional<CSSPixelPoint> m_mousemove_previous_screen_position;
|
2020-06-07 14:40:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|