diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txt index dd01eebec5..2187123ced 100644 --- a/Libraries/LibWebView/CMakeLists.txt +++ b/Libraries/LibWebView/CMakeLists.txt @@ -42,6 +42,12 @@ set(SOURCES CompositorClient.cpp ) +if (APPLE) + list(APPEND SOURCES + PlatformColorsMacOS.cpp + ) +endif() + set(GENERATED_SOURCES ${CURRENT_LIB_GENERATED}) compile_ipc(UIProcessServer.ipc UIProcessServerEndpoint.h) diff --git a/Libraries/LibWebView/PlatformColors.h b/Libraries/LibWebView/PlatformColors.h new file mode 100644 index 0000000000..0d51e232d3 --- /dev/null +++ b/Libraries/LibWebView/PlatformColors.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026-present, the Ladybird developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace WebView { + +WEBVIEW_API Gfx::Color macos_web_selection_color(); + +} diff --git a/Libraries/LibWebView/PlatformColorsMacOS.cpp b/Libraries/LibWebView/PlatformColorsMacOS.cpp new file mode 100644 index 0000000000..f93fcf53fb --- /dev/null +++ b/Libraries/LibWebView/PlatformColorsMacOS.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026-present, the Ladybird developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace WebView { + +Gfx::Color macos_web_selection_color() +{ + return Gfx::Color(128, 188, 254, 153); +} + +} diff --git a/UI/AppKit/Interface/Palette.mm b/UI/AppKit/Interface/Palette.mm index 6f7ead4d9e..377d7b5064 100644 --- a/UI/AppKit/Interface/Palette.mm +++ b/UI/AppKit/Interface/Palette.mm @@ -8,6 +8,7 @@ #include #include #include +#include #import #import @@ -39,7 +40,7 @@ Core::AnonymousBuffer create_system_palette() auto palette = Gfx::Palette(move(palette_impl)); palette.set_flag(Gfx::FlagRole::IsDark, is_dark); palette.set_color(Gfx::ColorRole::Accent, ns_color_to_gfx_color([NSColor controlAccentColor])); - palette.set_color(Gfx::ColorRole::Selection, Gfx::Color(128, 188, 254, 153)); + palette.set_color(Gfx::ColorRole::Selection, WebView::macos_web_selection_color()); palette.set_color(Gfx::ColorRole::InactiveSelection, ns_color_to_gfx_color([NSColor unemphasizedSelectedTextBackgroundColor])); palette.set_color(Gfx::ColorRole::InactiveSelectionText, ns_color_to_gfx_color([NSColor unemphasizedSelectedTextColor])); // FIXME: There are more system colors we currently don't use (https://developer.apple.com/documentation/appkit/nscolor/3000782-controlaccentcolor?language=objc) diff --git a/UI/Qt/MacWindow.h b/UI/Qt/MacWindow.h index 3253923d16..5105d44773 100644 --- a/UI/Qt/MacWindow.h +++ b/UI/Qt/MacWindow.h @@ -10,6 +10,11 @@ class QWidget; class QColor; +namespace Gfx { + +class Color; + +} namespace Ladybird { @@ -19,6 +24,8 @@ void install_always_active_window_control_hover_tracking(QWidget&, void (*hover_ void install_appkit_event_capture(); void make_appkit_window_first_responder(QWidget&); bool start_appkit_window_drag(QWidget&); +Gfx::Color appkit_web_inactive_selection_color(); +Gfx::Color appkit_web_inactive_selection_text_color(); #endif } diff --git a/UI/Qt/MacWindow.mm b/UI/Qt/MacWindow.mm index ee0d1c8e2d..a28e603ce2 100644 --- a/UI/Qt/MacWindow.mm +++ b/UI/Qt/MacWindow.mm @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -66,6 +67,19 @@ namespace Ladybird { static NSEvent* s_latest_window_drag_event; +static Gfx::Color ns_color_to_gfx_color(NSColor* color) +{ + auto* rgb_color = [color colorUsingColorSpace:NSColorSpace.genericRGBColorSpace]; + if (rgb_color != nil) + return { + static_cast([rgb_color redComponent] * 255), + static_cast([rgb_color greenComponent] * 255), + static_cast([rgb_color blueComponent] * 255), + static_cast([rgb_color alphaComponent] * 255) + }; + return {}; +} + static bool is_window_drag_on_gesture_enabled() { return [[NSUserDefaults standardUserDefaults] boolForKey:@"NSWindowShouldDragOnGesture"]; @@ -248,4 +262,14 @@ bool start_appkit_window_drag(QWidget& widget) return true; } +Gfx::Color appkit_web_inactive_selection_color() +{ + return ns_color_to_gfx_color([NSColor unemphasizedSelectedTextBackgroundColor]); +} + +Gfx::Color appkit_web_inactive_selection_text_color() +{ + return ns_color_to_gfx_color([NSColor unemphasizedSelectedTextColor]); +} + } diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp index e1691e45a5..2ee27f6a7f 100644 --- a/UI/Qt/WebContentView.cpp +++ b/UI/Qt/WebContentView.cpp @@ -24,9 +24,13 @@ #include #include #include +#include #include #include #include +#ifdef AK_OS_MACOS +# include +#endif #include #include @@ -857,7 +861,13 @@ static Core::AnonymousBuffer make_system_theme_from_qt_palette(QWidget& widget, translate(Gfx::ColorRole::VisitedLink, QPalette::ColorRole::LinkVisited); translate(Gfx::ColorRole::Button, QPalette::ColorRole::Button); translate(Gfx::ColorRole::ButtonText, QPalette::ColorRole::ButtonText); +#ifdef AK_OS_MACOS + palette.set_color(Gfx::ColorRole::Selection, WebView::macos_web_selection_color()); + palette.set_color(Gfx::ColorRole::InactiveSelection, appkit_web_inactive_selection_color()); + palette.set_color(Gfx::ColorRole::InactiveSelectionText, appkit_web_inactive_selection_text_color()); +#else translate(Gfx::ColorRole::Selection, QPalette::ColorRole::Highlight); +#endif palette.set_flag(Gfx::FlagRole::IsDark, is_using_dark_system_theme(widget));