Skip to content

Commit

Permalink
LibWebView+Ladybird: Begin de-duplicate WebView implementations
Browse files Browse the repository at this point in the history
This starts moving code equally shared between the OOPWV and Ladybird
WebContentView implementations to WebView::ViewImplementation, beginning
with the client state.
  • Loading branch information
linusg authored and awesomekling committed Jan 12, 2023
1 parent 121181e commit 5411adc
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 48 deletions.
6 changes: 0 additions & 6 deletions Ladybird/WebContentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
21 changes: 3 additions & 18 deletions Ladybird/WebContentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ class WebContentView final
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();
Expand All @@ -216,28 +219,10 @@ class WebContentView final

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;
Expand Down
1 change: 1 addition & 0 deletions Meta/Lagom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWebView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(SOURCES
OutOfProcessWebView.cpp
RequestServerAdapter.cpp
StylePropertiesModel.cpp
ViewImplementation.cpp
WebContentClient.cpp
WebSocketClientAdapter.cpp
)
Expand Down
6 changes: 0 additions & 6 deletions Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 1 addition & 18 deletions Userland/Libraries/LibWebView/OutOfProcessWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class OutOfProcessWebView final
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;
Expand Down Expand Up @@ -207,9 +208,6 @@ class OutOfProcessWebView final
void handle_resize();
void update_zoom();

void create_client();
WebContentClient& client();

void handle_web_content_process_crash();

using InputEvent = Variant<GUI::KeyEvent, GUI::MouseEvent>;
Expand All @@ -218,21 +216,6 @@ class OutOfProcessWebView final

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;

Expand Down
23 changes: 23 additions & 0 deletions Userland/Libraries/LibWebView/ViewImplementation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023, Linus Groh <[email protected]>
*
* 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;
}

}
21 changes: 21 additions & 0 deletions Userland/Libraries/LibWebView/ViewImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <LibGfx/StandardCursor.h>
#include <LibWeb/Forward.h>
#include <LibWebView/Forward.h>
#include <LibWebView/WebContentClient.h>

namespace WebView {

Expand Down Expand Up @@ -68,6 +69,26 @@ class ViewImplementation {
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;
};

}

0 comments on commit 5411adc

Please sign in to comment.