Quellcode durchsuchen

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.
Timothy Flynn vor 1 Jahr
Ursprung
Commit
3f122b7335

+ 9 - 0
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/WebDriverClient.ipc WebContent/WebDriverClientEndpoint.h)
         compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebDriverServer.ipc WebContent/WebDriverServerEndpoint.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/WebContentClientEndpoint.h)
         list(APPEND LIBWEBVIEW_GENERATED_SOURCES WebContent/WebContentServerEndpoint.h)
         list(APPEND LIBWEBVIEW_GENERATED_SOURCES WebContent/WebContentServerEndpoint.h)
         list(APPEND LIBWEBVIEW_GENERATED_SOURCES WebContent/WebDriverClientEndpoint.h)
         list(APPEND LIBWEBVIEW_GENERATED_SOURCES WebContent/WebDriverClientEndpoint.h)

+ 0 - 11
Userland/Libraries/LibWebView/OutOfProcessWebView.cpp

@@ -431,15 +431,4 @@ void OutOfProcessWebView::set_content_scales_to_viewport(bool b)
     m_content_scales_to_viewport = 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)));
-}
-
 }
 }

+ 0 - 5
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.
     // 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_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:
 private:
     OutOfProcessWebView();
     OutOfProcessWebView();
 
 

+ 11 - 0
Userland/Libraries/LibWebView/ViewImplementation.cpp

@@ -359,4 +359,15 @@ ErrorOr<void> ViewImplementation::take_screenshot(ScreenshotType type)
     return {};
     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)));
+}
+
 }
 }

+ 5 - 0
Userland/Libraries/LibWebView/ViewImplementation.h

@@ -94,6 +94,11 @@ public:
     };
     };
     ErrorOr<void> take_screenshot(ScreenshotType);
     ErrorOr<void> 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<void(Gfx::IntSize)> on_did_layout;
     Function<void(Gfx::IntSize)> on_did_layout;
     Function<void()> on_ready_to_paint;
     Function<void()> on_ready_to_paint;
     Function<String(Web::HTML::ActivateTab)> on_new_tab;
     Function<String(Web::HTML::ActivateTab)> on_new_tab;