EventHandler.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <andreas@ladybird.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 <LibGfx/Forward.h>
  11. #include <LibJS/Heap/Cell.h>
  12. #include <LibJS/Heap/GCPtr.h>
  13. #include <LibUnicode/Forward.h>
  14. #include <LibWeb/Forward.h>
  15. #include <LibWeb/Page/EventResult.h>
  16. #include <LibWeb/Page/InputEvent.h>
  17. #include <LibWeb/PixelUnits.h>
  18. #include <LibWeb/UIEvents/KeyCode.h>
  19. namespace Web {
  20. class EventHandler {
  21. public:
  22. explicit EventHandler(Badge<HTML::Navigable>, HTML::Navigable&);
  23. ~EventHandler();
  24. EventResult handle_mouseup(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
  25. EventResult handle_mousedown(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
  26. EventResult handle_mousemove(CSSPixelPoint, CSSPixelPoint screen_position, unsigned buttons, unsigned modifiers);
  27. EventResult handle_mousewheel(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
  28. EventResult handle_doubleclick(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
  29. EventResult handle_drag_and_drop_event(DragEvent::Type, CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Vector<HTML::SelectedFile> files);
  30. EventResult handle_keydown(UIEvents::KeyCode, unsigned modifiers, u32 code_point);
  31. EventResult handle_keyup(UIEvents::KeyCode, unsigned modifiers, u32 code_point);
  32. void set_mouse_event_tracking_paintable(Painting::Paintable*);
  33. void handle_paste(String const& text);
  34. void visit_edges(JS::Cell::Visitor& visitor) const;
  35. Unicode::Segmenter& word_segmenter();
  36. private:
  37. bool focus_next_element();
  38. bool focus_previous_element();
  39. EventResult fire_keyboard_event(FlyString const& event_name, HTML::Navigable&, UIEvents::KeyCode, unsigned modifiers, u32 code_point);
  40. [[nodiscard]] EventResult input_event(FlyString const& event_name, FlyString const& input_type, HTML::Navigable&, u32 code_point);
  41. CSSPixelPoint compute_mouse_event_client_offset(CSSPixelPoint event_page_position) const;
  42. CSSPixelPoint compute_mouse_event_page_offset(CSSPixelPoint event_client_offset) const;
  43. CSSPixelPoint compute_mouse_event_movement(CSSPixelPoint event_client_offset) const;
  44. struct Target {
  45. JS::GCPtr<Painting::Paintable> paintable;
  46. Optional<int> index_in_node;
  47. };
  48. Optional<Target> target_for_mouse_position(CSSPixelPoint position);
  49. Painting::PaintableBox* paint_root();
  50. Painting::PaintableBox const* paint_root() const;
  51. bool should_ignore_device_input_event() const;
  52. void update_selection_range_for_input_or_textarea();
  53. JS::NonnullGCPtr<HTML::Navigable> m_navigable;
  54. bool m_in_mouse_selection { false };
  55. JS::GCPtr<Painting::Paintable> m_mouse_event_tracking_paintable;
  56. NonnullOwnPtr<EditEventHandler> m_edit_event_handler;
  57. NonnullOwnPtr<DragAndDropEventHandler> m_drag_and_drop_event_handler;
  58. WeakPtr<DOM::EventTarget> m_mousedown_target;
  59. Optional<CSSPixelPoint> m_mousemove_previous_screen_position;
  60. OwnPtr<Unicode::Segmenter> m_word_segmenter;
  61. };
  62. }