From 3f122b7335193b0b8a018a1bcc695e22ead196c5 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 26 Aug 2023 13:34:59 -0400 Subject: [PATCH] LibWebView: Allow using native/user style sheets on Lagom Move the methods to set the native/user style sheets to the base ViewImplementation class. We must also generate the native style sheet explicitly for now, as LibWebView on Lagom isn't able to include the main LibWebView CMakeLists.txt file yet. --- Meta/Lagom/CMakeLists.txt | 9 +++++++++ Userland/Libraries/LibWebView/OutOfProcessWebView.cpp | 11 ----------- Userland/Libraries/LibWebView/OutOfProcessWebView.h | 5 ----- Userland/Libraries/LibWebView/ViewImplementation.cpp | 11 +++++++++++ Userland/Libraries/LibWebView/ViewImplementation.h | 5 +++++ 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 345cc56087d..d70c2e0dd8a 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -442,6 +442,15 @@ if (BUILD_LAGOM) compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebDriverClient.ipc WebContent/WebDriverClientEndpoint.h) compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebDriverServer.ipc WebContent/WebDriverServerEndpoint.h) + embed_as_string_view( + "NativeStyleSheetSource" + "${SERENITY_PROJECT_ROOT}/Userland/Libraries/LibWebView/Native.css" + "LibWebView/NativeStyleSheetSource.cpp" + "native_stylesheet_source" + NAMESPACE "WebView" + ) + + list(APPEND LIBWEBVIEW_GENERATED_SOURCES LibWebView/NativeStyleSheetSource.cpp) list(APPEND LIBWEBVIEW_GENERATED_SOURCES WebContent/WebContentClientEndpoint.h) list(APPEND LIBWEBVIEW_GENERATED_SOURCES WebContent/WebContentServerEndpoint.h) list(APPEND LIBWEBVIEW_GENERATED_SOURCES WebContent/WebDriverClientEndpoint.h) diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 4e65bd3850b..9564b4bd77b 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -431,15 +431,4 @@ void OutOfProcessWebView::set_content_scales_to_viewport(bool b) m_content_scales_to_viewport = b; } -void OutOfProcessWebView::set_user_style_sheet(String source) -{ - client().async_set_user_style(source); -} - -void OutOfProcessWebView::use_native_user_style_sheet() -{ - extern StringView native_stylesheet_source; - set_user_style_sheet(MUST(String::from_utf8(native_stylesheet_source))); -} - } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index a93d4fc2986..f19c35d40b2 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -54,11 +54,6 @@ public: // In practice, this means that OOPWV may render scaled stale versions of the content while resizing. void set_content_scales_to_viewport(bool); - void set_user_style_sheet(String source); - // Load Native.css as the User style sheet, which attempts to make WebView content look as close to - // native GUI::Widgets as possible. - void use_native_user_style_sheet(); - private: OutOfProcessWebView(); diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index 89b9b32c6b8..ca906b0986c 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -359,4 +359,15 @@ ErrorOr ViewImplementation::take_screenshot(ScreenshotType type) return {}; } +void ViewImplementation::set_user_style_sheet(String source) +{ + client().async_set_user_style(move(source)); +} + +void ViewImplementation::use_native_user_style_sheet() +{ + extern StringView native_stylesheet_source; + set_user_style_sheet(MUST(String::from_utf8(native_stylesheet_source))); +} + } diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 8a21d5c727c..dd09a5e507f 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -94,6 +94,11 @@ public: }; ErrorOr take_screenshot(ScreenshotType); + void set_user_style_sheet(String source); + // Load Native.css as the User style sheet, which attempts to make WebView content look as close to + // native GUI widgets as possible. + void use_native_user_style_sheet(); + Function on_did_layout; Function on_ready_to_paint; Function on_new_tab;