2023-08-20 16:14:31 -04:00
|
|
|
/*
|
2024-07-30 14:01:05 -04:00
|
|
|
* Copyright (c) 2023-2024, Tim Flynn <trflynn89@serenityos.org>
|
2023-08-20 16:14:31 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <LibGfx/Point.h>
|
|
|
|
#include <LibGfx/Rect.h>
|
|
|
|
#include <LibGfx/Size.h>
|
2024-03-05 16:11:22 -05:00
|
|
|
#include <LibWeb/Page/InputEvent.h>
|
2023-08-20 16:14:31 -04:00
|
|
|
#include <LibWebView/ViewImplementation.h>
|
|
|
|
|
|
|
|
namespace Ladybird {
|
|
|
|
|
|
|
|
class WebViewBridge final : public WebView::ViewImplementation {
|
|
|
|
public:
|
2025-09-03 11:23:09 -04:00
|
|
|
static ErrorOr<NonnullOwnPtr<WebViewBridge>> create(Vector<Web::DevicePixelRect> screen_rects, float device_pixel_ratio, u64 maximum_frames_per_second);
|
2023-08-20 16:14:31 -04:00
|
|
|
virtual ~WebViewBridge() override;
|
|
|
|
|
2024-04-15 17:39:48 -06:00
|
|
|
virtual void initialize_client(CreateNewClient = CreateNewClient::Yes) override;
|
2025-04-15 15:54:30 -06:00
|
|
|
void initialize_client_as_child(WebViewBridge& parent, u64 page_index);
|
2024-04-15 17:39:48 -06:00
|
|
|
|
2023-08-20 16:14:31 -04:00
|
|
|
float device_pixel_ratio() const { return m_device_pixel_ratio; }
|
2023-09-20 22:10:42 +02:00
|
|
|
void set_device_pixel_ratio(float device_pixel_ratio);
|
|
|
|
float inverse_device_pixel_ratio() const { return 1.0f / m_device_pixel_ratio; }
|
2023-08-20 16:14:31 -04:00
|
|
|
|
2024-11-07 12:26:42 -05:00
|
|
|
void set_viewport_rect(Gfx::IntRect);
|
2023-08-20 16:14:31 -04:00
|
|
|
|
2025-07-25 13:23:50 +01:00
|
|
|
void set_maximum_frames_per_second(u64 maximum_frames_per_second);
|
|
|
|
|
2023-08-26 23:12:30 -04:00
|
|
|
void update_palette();
|
|
|
|
|
2024-03-05 16:11:22 -05:00
|
|
|
void enqueue_input_event(Web::MouseEvent);
|
2024-08-17 16:23:13 -04:00
|
|
|
void enqueue_input_event(Web::DragEvent);
|
2024-03-05 16:11:22 -05:00
|
|
|
void enqueue_input_event(Web::KeyEvent);
|
2025-10-08 23:59:50 +02:00
|
|
|
void enqueue_input_event(Web::PinchEvent);
|
2023-08-20 16:14:31 -04:00
|
|
|
|
|
|
|
struct Paintable {
|
2025-04-15 15:50:18 -06:00
|
|
|
Gfx::Bitmap const& bitmap;
|
2023-08-20 16:14:31 -04:00
|
|
|
Gfx::IntSize bitmap_size;
|
|
|
|
};
|
|
|
|
Optional<Paintable> paintable();
|
|
|
|
|
2023-10-07 17:21:00 -04:00
|
|
|
Function<void()> on_zoom_level_changed;
|
|
|
|
|
2025-10-08 23:59:50 +02:00
|
|
|
auto& pinch_state() { return m_pinch_state; }
|
|
|
|
|
2023-08-20 16:14:31 -04:00
|
|
|
private:
|
2025-09-03 11:23:09 -04:00
|
|
|
WebViewBridge(Vector<Web::DevicePixelRect> screen_rects, float device_pixel_ratio, u64 maximum_frames_per_second);
|
2023-08-20 16:14:31 -04:00
|
|
|
|
|
|
|
virtual void update_zoom() override;
|
2024-06-03 17:53:55 +03:00
|
|
|
virtual Web::DevicePixelSize viewport_size() const override;
|
2023-08-20 16:14:31 -04:00
|
|
|
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
|
|
|
|
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;
|
|
|
|
|
2023-12-14 07:17:00 +01:00
|
|
|
Vector<Web::DevicePixelRect> m_screen_rects;
|
2024-06-03 17:53:55 +03:00
|
|
|
Gfx::IntSize m_viewport_size;
|
2025-10-08 23:59:50 +02:00
|
|
|
|
|
|
|
struct PinchState {
|
|
|
|
double previous_scale { 1.0 };
|
|
|
|
};
|
|
|
|
Optional<PinchState> m_pinch_state;
|
2023-08-20 16:14:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|