EventHandler.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 handle_paste(String const& text);
  33. void visit_edges(JS::Cell::Visitor& visitor) const;
  34. private:
  35. bool focus_next_element();
  36. bool focus_previous_element();
  37. bool fire_keyboard_event(FlyString const& event_name, HTML::BrowsingContext& browsing_context, KeyCode key, unsigned modifiers, u32 code_point);
  38. CSSPixelPoint compute_mouse_event_client_offset(CSSPixelPoint event_page_position) const;
  39. CSSPixelPoint compute_mouse_event_page_offset(CSSPixelPoint event_client_offset) const;
  40. CSSPixelPoint compute_mouse_event_movement(CSSPixelPoint event_client_offset) const;
  41. struct Target {
  42. JS::GCPtr<Painting::Paintable> paintable;
  43. Optional<int> index_in_node;
  44. };
  45. Optional<Target> target_for_mouse_position(CSSPixelPoint position);
  46. Painting::PaintableBox* paint_root();
  47. Painting::PaintableBox const* paint_root() const;
  48. JS::NonnullGCPtr<HTML::BrowsingContext> m_browsing_context;
  49. bool m_in_mouse_selection { false };
  50. JS::GCPtr<Painting::Paintable> m_mouse_event_tracking_paintable;
  51. NonnullOwnPtr<EditEventHandler> m_edit_event_handler;
  52. WeakPtr<DOM::EventTarget> m_mousedown_target;
  53. Optional<CSSPixelPoint> m_mousemove_previous_screen_position;
  54. };
  55. }