LadybirdWebViewBridge.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Vector.h>
  8. #include <LibGfx/Point.h>
  9. #include <LibGfx/Rect.h>
  10. #include <LibGfx/Size.h>
  11. #include <LibGfx/StandardCursor.h>
  12. #include <LibWebView/ViewImplementation.h>
  13. // FIXME: These should not be included outside of Serenity.
  14. #include <Kernel/API/KeyCode.h>
  15. #include <LibGUI/Event.h>
  16. namespace Ladybird {
  17. class WebViewBridge final : public WebView::ViewImplementation {
  18. public:
  19. static ErrorOr<NonnullOwnPtr<WebViewBridge>> create(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path);
  20. virtual ~WebViewBridge() override;
  21. float device_pixel_ratio() const { return m_device_pixel_ratio; }
  22. float inverse_device_pixel_ratio() const { return m_inverse_device_pixel_ratio; }
  23. void set_system_visibility_state(bool is_visible);
  24. enum class ForResize {
  25. Yes,
  26. No,
  27. };
  28. void set_viewport_rect(Gfx::IntRect, ForResize = ForResize::No);
  29. void mouse_down_event(Gfx::IntPoint, GUI::MouseButton, KeyModifier);
  30. void mouse_up_event(Gfx::IntPoint, GUI::MouseButton, KeyModifier);
  31. void mouse_move_event(Gfx::IntPoint, GUI::MouseButton, KeyModifier);
  32. void mouse_double_click_event(Gfx::IntPoint, GUI::MouseButton, KeyModifier);
  33. void key_down_event(KeyCode, KeyModifier, u32);
  34. void key_up_event(KeyCode, KeyModifier, u32);
  35. struct Paintable {
  36. Gfx::Bitmap& bitmap;
  37. Gfx::IntSize bitmap_size;
  38. };
  39. Optional<Paintable> paintable();
  40. Function<void(DeprecatedString const&)> on_tooltip_entered;
  41. Function<void()> on_tooltip_left;
  42. private:
  43. WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path);
  44. virtual void notify_server_did_enter_tooltip_area(Badge<WebView::WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
  45. virtual void notify_server_did_leave_tooltip_area(Badge<WebView::WebContentClient>) override;
  46. virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
  47. virtual void update_zoom() override;
  48. virtual Gfx::IntRect viewport_rect() const override;
  49. virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
  50. virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;
  51. virtual void create_client(WebView::EnableCallgrindProfiling) override;
  52. void update_palette();
  53. Vector<Gfx::IntRect> m_screen_rects;
  54. Gfx::IntRect m_viewport_rect;
  55. float m_inverse_device_pixel_ratio { 1.0 };
  56. Optional<StringView> m_webdriver_content_ipc_path;
  57. };
  58. }