EventHandler.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <AK/NonnullOwnPtr.h>
  9. #include <AK/WeakPtr.h>
  10. #include <Kernel/API/KeyCode.h>
  11. #include <LibGUI/Forward.h>
  12. #include <LibGfx/Forward.h>
  13. #include <LibJS/Heap/Cell.h>
  14. #include <LibJS/Heap/GCPtr.h>
  15. #include <LibWeb/Forward.h>
  16. #include <LibWeb/Page/EditEventHandler.h>
  17. #include <LibWeb/PixelUnits.h>
  18. namespace Web {
  19. class EventHandler {
  20. public:
  21. explicit EventHandler(Badge<HTML::BrowsingContext>, HTML::BrowsingContext&);
  22. ~EventHandler();
  23. bool handle_mouseup(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
  24. bool handle_mousedown(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
  25. bool handle_mousemove(CSSPixelPoint, CSSPixelPoint screen_position, unsigned buttons, unsigned modifiers);
  26. bool handle_mousewheel(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
  27. bool handle_doubleclick(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
  28. bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
  29. bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point);
  30. void set_mouse_event_tracking_paintable(Painting::Paintable*);
  31. void set_edit_event_handler(NonnullOwnPtr<EditEventHandler> value) { m_edit_event_handler = move(value); }
  32. void visit_edges(JS::Cell::Visitor& visitor) const;
  33. private:
  34. bool focus_next_element();
  35. bool focus_previous_element();
  36. bool fire_keyboard_event(FlyString const& event_name, HTML::BrowsingContext& browsing_context, KeyCode key, unsigned modifiers, u32 code_point);
  37. CSSPixelPoint compute_mouse_event_client_offset(CSSPixelPoint event_page_position) const;
  38. CSSPixelPoint compute_mouse_event_page_offset(CSSPixelPoint event_client_offset) const;
  39. CSSPixelPoint compute_mouse_event_movement(CSSPixelPoint event_client_offset) const;
  40. struct Target {
  41. JS::GCPtr<Painting::Paintable> paintable;
  42. Optional<int> index_in_node;
  43. };
  44. Optional<Target> target_for_mouse_position(CSSPixelPoint position);
  45. Painting::PaintableBox* paint_root();
  46. Painting::PaintableBox const* paint_root() const;
  47. JS::NonnullGCPtr<HTML::BrowsingContext> m_browsing_context;
  48. bool m_in_mouse_selection { false };
  49. JS::GCPtr<Painting::Paintable> m_mouse_event_tracking_paintable;
  50. NonnullOwnPtr<EditEventHandler> m_edit_event_handler;
  51. WeakPtr<DOM::EventTarget> m_mousedown_target;
  52. Optional<CSSPixelPoint> m_mousemove_previous_screen_position;
  53. };
  54. }