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
This commit is contained in:
Emilio Cobos Álvarez 2023-05-30 20:36:40 +02:00 committed by Oriol Brufau
parent 6c16c019fc
commit c3322938f2

View file

@ -471,28 +471,17 @@ impl SystemColor {
fn compute(&self, cx: &Context) -> ComputedColor { fn compute(&self, cx: &Context) -> ComputedColor {
use crate::gecko_bindings::bindings; use crate::gecko_bindings::bindings;
let colors = &cx.device().pref_sheet_prefs().mColors; // TODO: We should avoid cloning here most likely, though it's
let style_color_scheme = cx.style().get_inherited_ui().clone_color_scheme(); // cheap-ish.
let style_color_scheme =
// TODO: At least Canvas / CanvasText should be color-scheme aware cx.style().get_inherited_ui().clone_color_scheme();
// (probably the link colors too). let color = unsafe {
convert_nscolor_to_computedcolor(match *self { bindings::Gecko_ComputeSystemColor(*self, cx.device().document(), &style_color_scheme)
SystemColor::Canvastext => colors.mDefault, };
SystemColor::Canvas => colors.mDefaultBackground, if color == bindings::NS_SAME_AS_FOREGROUND_COLOR {
SystemColor::Linktext => colors.mLink, return ComputedColor::currentcolor();
SystemColor::Activetext => colors.mActiveLink, }
SystemColor::Visitedtext => colors.mVisitedLink, convert_nscolor_to_computedcolor(color)
_ => {
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
},
})
} }
} }