From c3322938f2b3d6f48dfc0b2049b8016a91d16ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 30 May 2023 20:36:40 +0200 Subject: [PATCH] style: Move Canvas/Link color computation to C++-land This doesn't change behavior but will allow us to deduplicate some logic given we compute the effective color-scheme in C++. Differential Revision: https://phabricator.services.mozilla.com/D129744 --- components/style/values/specified/color.rs | 33 ++++++++-------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index 2fd586864ae..d0f3ef80dcf 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -471,28 +471,17 @@ impl SystemColor { fn compute(&self, cx: &Context) -> ComputedColor { use crate::gecko_bindings::bindings; - let colors = &cx.device().pref_sheet_prefs().mColors; - let style_color_scheme = cx.style().get_inherited_ui().clone_color_scheme(); - - // TODO: At least Canvas / CanvasText should be color-scheme aware - // (probably the link colors too). - convert_nscolor_to_computedcolor(match *self { - SystemColor::Canvastext => colors.mDefault, - SystemColor::Canvas => colors.mDefaultBackground, - SystemColor::Linktext => colors.mLink, - SystemColor::Activetext => colors.mActiveLink, - SystemColor::Visitedtext => colors.mVisitedLink, - - _ => { - let color = unsafe { - bindings::Gecko_GetLookAndFeelSystemColor(*self as i32, cx.device().document(), &style_color_scheme) - }; - if color == bindings::NS_SAME_AS_FOREGROUND_COLOR { - return ComputedColor::currentcolor(); - } - color - }, - }) + // TODO: We should avoid cloning here most likely, though it's + // cheap-ish. + let style_color_scheme = + cx.style().get_inherited_ui().clone_color_scheme(); + let color = unsafe { + bindings::Gecko_ComputeSystemColor(*self, cx.device().document(), &style_color_scheme) + }; + if color == bindings::NS_SAME_AS_FOREGROUND_COLOR { + return ComputedColor::currentcolor(); + } + convert_nscolor_to_computedcolor(color) } }