From 5411adca223a51edde731903828ae4cb39462880 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 12 Jan 2023 19:27:17 +0000 Subject: [PATCH] LibWebView+Ladybird: Begin de-duplicate WebView implementations This starts moving code equally shared between the OOPWV and Ladybird WebContentView implementations to WebView::ViewImplementation, beginning with the client state. --- Ladybird/WebContentView.cpp | 6 ----- Ladybird/WebContentView.h | 21 +++-------------- Meta/Lagom/CMakeLists.txt | 1 + Userland/Libraries/LibWebView/CMakeLists.txt | 1 + .../LibWebView/OutOfProcessWebView.cpp | 6 ----- .../LibWebView/OutOfProcessWebView.h | 19 +-------------- .../LibWebView/ViewImplementation.cpp | 23 +++++++++++++++++++ .../Libraries/LibWebView/ViewImplementation.h | 21 +++++++++++++++++ 8 files changed, 50 insertions(+), 48 deletions(-) create mode 100644 Userland/Libraries/LibWebView/ViewImplementation.cpp diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index e9a99b07ad0..0c5f9964d3d 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -607,12 +607,6 @@ void WebContentView::hideEvent(QHideEvent* event) client().async_set_system_visibility_state(false); } -WebContentClient& WebContentView::client() -{ - VERIFY(m_client_state.client); - return *m_client_state.client; -} - void WebContentView::create_client() { m_client_state = {}; diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index d09d9ffa4fa..058c31ed778 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -190,6 +190,9 @@ private: static constexpr auto ZOOM_MAX_LEVEL = 5.0f; static constexpr auto ZOOM_STEP = 0.1f; + // ^WebView::ViewImplementation + virtual void create_client() override; + void request_repaint(); void update_viewport_rect(); void handle_resize(); @@ -216,28 +219,10 @@ private: Gfx::IntRect m_viewport_rect; - void create_client(); - WebContentClient& client(); - void handle_web_content_process_crash(); AK::URL m_url; - struct SharedBitmap { - i32 id { -1 }; - i32 pending_paints { 0 }; - RefPtr bitmap; - }; - - struct ClientState { - RefPtr client; - SharedBitmap front_bitmap; - SharedBitmap back_bitmap; - i32 next_bitmap_id { 0 }; - bool has_usable_bitmap { false }; - bool got_repaint_requests_while_painting { false }; - } m_client_state; - RefPtr m_backup_bitmap; StringView m_webdriver_content_ipc_path; diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 938bf7c47c3..50b3ee35fb2 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -394,6 +394,7 @@ if (BUILD_LAGOM) # WebView list(APPEND LIBWEBVIEW_SOURCES "../../Userland/Libraries/LibWebView/DOMTreeModel.cpp") list(APPEND LIBWEBVIEW_SOURCES "../../Userland/Libraries/LibWebView/StylePropertiesModel.cpp") + list(APPEND LIBWEBVIEW_SOURCES "../../Userland/Libraries/LibWebView/ViewImplementation.cpp") list(APPEND LIBWEBVIEW_SOURCES "../../Userland/Libraries/LibWebView/WebContentClient.cpp") compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebContentServer.ipc WebContent/WebContentServerEndpoint.h) diff --git a/Userland/Libraries/LibWebView/CMakeLists.txt b/Userland/Libraries/LibWebView/CMakeLists.txt index 707bb835ee0..1147a4c0ef9 100644 --- a/Userland/Libraries/LibWebView/CMakeLists.txt +++ b/Userland/Libraries/LibWebView/CMakeLists.txt @@ -4,6 +4,7 @@ set(SOURCES OutOfProcessWebView.cpp RequestServerAdapter.cpp StylePropertiesModel.cpp + ViewImplementation.cpp WebContentClient.cpp WebSocketClientAdapter.cpp ) diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index f8560e0368d..52d9c613ad1 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -582,12 +582,6 @@ void OutOfProcessWebView::request_repaint() client().async_paint(m_client_state.back_bitmap.bitmap->rect().translated(horizontal_scrollbar().value(), vertical_scrollbar().value()), m_client_state.back_bitmap.id); } -WebContentClient& OutOfProcessWebView::client() -{ - VERIFY(m_client_state.client); - return *m_client_state.client; -} - void OutOfProcessWebView::debug_request(DeprecatedString const& request, DeprecatedString const& argument) { client().async_debug_request(request, argument); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 73bc7a66ec5..d80fc482dd0 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -152,6 +152,7 @@ private: virtual void did_scroll() override; // ^WebView::ViewImplementation + virtual void create_client() override; virtual void notify_server_did_layout(Badge, Gfx::IntSize content_size) override; virtual void notify_server_did_paint(Badge, i32 bitmap_id) override; virtual void notify_server_did_invalidate_content_rect(Badge, Gfx::IntRect const&) override; @@ -207,9 +208,6 @@ private: void handle_resize(); void update_zoom(); - void create_client(); - WebContentClient& client(); - void handle_web_content_process_crash(); using InputEvent = Variant; @@ -218,21 +216,6 @@ private: AK::URL m_url; - struct SharedBitmap { - i32 id { -1 }; - i32 pending_paints { 0 }; - RefPtr bitmap; - }; - - struct ClientState { - RefPtr client; - SharedBitmap front_bitmap; - SharedBitmap back_bitmap; - i32 next_bitmap_id { 0 }; - bool has_usable_bitmap { false }; - bool got_repaint_requests_while_painting { false }; - } m_client_state; - RefPtr m_backup_bitmap; RefPtr m_dialog; diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp new file mode 100644 index 00000000000..30278456b2a --- /dev/null +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace WebView { + +WebContentClient& ViewImplementation::client() +{ + VERIFY(m_client_state.client); + return *m_client_state.client; +} + +WebContentClient const& ViewImplementation::client() const +{ + VERIFY(m_client_state.client); + return *m_client_state.client; +} + +} diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 7689b933802..48c9e4ce89e 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace WebView { @@ -68,6 +69,26 @@ public: virtual Gfx::IntRect notify_server_did_request_fullscreen_window() = 0; virtual void notify_server_did_request_file(Badge, DeprecatedString const& path, i32) = 0; virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) = 0; + +protected: + WebContentClient& client(); + WebContentClient const& client() const; + virtual void create_client() = 0; + + struct SharedBitmap { + i32 id { -1 }; + i32 pending_paints { 0 }; + RefPtr bitmap; + }; + + struct ClientState { + RefPtr client; + SharedBitmap front_bitmap; + SharedBitmap back_bitmap; + i32 next_bitmap_id { 0 }; + bool has_usable_bitmap { false }; + bool got_repaint_requests_while_painting { false }; + } m_client_state; }; }