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 345cc56087d7edf87a2515943ba7844ab05a7c1a..d70c2e0dd8a9309e4736a68449f2b2d508345265 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 4e65bd3850bb8a8aa5a99b427320cb9f0273fd23..9564b4bd77bc9d8d45c2632cdfefe96953b26152 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 a93d4fc2986d23a03d7fd23ce06794fa2be0b974..f19c35d40b232ac9a3813c3dbcd6e398238a2b6a 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 89b9b32c6b8dcdc97bf652b5093855f3b7107172..ca906b0986c06ee300508f6a68b45773e1fd18b2 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 8a21d5c727c654f22b77454f30495fe036045df6..dd09a5e507ff6b28df82deead283265a19436a6c 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;