diff options
author | Linus Groh <mail@linusgroh.de> | 2023-01-12 19:27:17 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-01-12 23:39:36 +0100 |
commit | 5411adca223a51edde731903828ae4cb39462880 (patch) | |
tree | c95b0f27311618a70ad27c0a8b86875263035385 | |
parent | 121181e392ddfe54194b4dd5493665f13a2ffe2b (diff) | |
download | serenity-5411adca223a51edde731903828ae4cb39462880.zip |
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.
-rw-r--r-- | Ladybird/WebContentView.cpp | 6 | ||||
-rw-r--r-- | Ladybird/WebContentView.h | 21 | ||||
-rw-r--r-- | Meta/Lagom/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/OutOfProcessWebView.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/OutOfProcessWebView.h | 19 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/ViewImplementation.cpp | 23 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/ViewImplementation.h | 21 |
8 files changed, 50 insertions, 48 deletions
diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index e9a99b07ad..0c5f9964d3 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 d09d9ffa4f..058c31ed77 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<Gfx::Bitmap> bitmap; - }; - - struct ClientState { - RefPtr<WebContentClient> 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<Gfx::Bitmap> m_backup_bitmap; StringView m_webdriver_content_ipc_path; diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 938bf7c47c..50b3ee35fb 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 707bb835ee..1147a4c0ef 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 f8560e0368..52d9c613ad 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 73bc7a66ec..d80fc482dd 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<WebContentClient>, Gfx::IntSize content_size) override; virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) override; virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, 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<GUI::KeyEvent, GUI::MouseEvent>; @@ -218,21 +216,6 @@ private: AK::URL m_url; - struct SharedBitmap { - i32 id { -1 }; - i32 pending_paints { 0 }; - RefPtr<Gfx::Bitmap> bitmap; - }; - - struct ClientState { - RefPtr<WebContentClient> 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<Gfx::Bitmap> m_backup_bitmap; RefPtr<GUI::Dialog> m_dialog; diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp new file mode 100644 index 0000000000..30278456b2 --- /dev/null +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023, Linus Groh <linusg@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibWebView/ViewImplementation.h> + +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 7689b93380..48c9e4ce89 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -11,6 +11,7 @@ #include <LibGfx/StandardCursor.h> #include <LibWeb/Forward.h> #include <LibWebView/Forward.h> +#include <LibWebView/WebContentClient.h> 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<WebContentClient>, 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<Gfx::Bitmap> bitmap; + }; + + struct ClientState { + RefPtr<WebContentClient> 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; }; } |