mirror of
https://github.com/servo/servo.git
synced 2025-08-21 05:15:33 +01:00
style: Move system colors to values::specified::color.
This should be an idempotent patch. The way to come up with this patch has been: * Run the first script attached to the bug and pipe it to xclip, then paste it in color.rs * Add the relevant #[derive] annotations and remove the color.mako.rs definition. * Reorder the values to match the ColorID definition, on which some widget prefs and caching stuff relies on. * Manually port some documentation from nsLookAndFeel.h * Run `rg 'eColorID_' | cut -d : -f 1 | sort | uniq >files` * Run the second script attached to the bug. * Manually fix usage of `LAST_COLOR` (adding the `End` variant), and adding casts to integer as needed. * Add an static assert so that people remember to update the prefs, rather than a comment on the definition :) Differential Revision: https://phabricator.services.mozilla.com/D32610
This commit is contained in:
parent
3a2705f587
commit
729bf19437
2 changed files with 223 additions and 131 deletions
|
@ -17,114 +17,3 @@ ${helpers.predefined_type(
|
|||
ignored_when_colors_disabled="True",
|
||||
spec="https://drafts.csswg.org/css-color/#color",
|
||||
)}
|
||||
|
||||
// FIXME(#15973): Add servo support for system colors
|
||||
//
|
||||
// FIXME(emilio): Move outside of mako.
|
||||
% if product == "gecko":
|
||||
pub mod system_colors {
|
||||
<%
|
||||
# These are actually parsed. See nsCSSProps::kColorKTable
|
||||
system_colors = """activeborder activecaption appworkspace background buttonface
|
||||
buttonhighlight buttonshadow buttontext captiontext graytext highlight
|
||||
highlighttext inactiveborder inactivecaption inactivecaptiontext
|
||||
infobackground infotext menu menutext scrollbar threeddarkshadow
|
||||
threedface threedhighlight threedlightshadow threedshadow window
|
||||
windowframe windowtext -moz-buttondefault -moz-buttonhoverface
|
||||
-moz-buttonhovertext -moz-cellhighlight -moz-cellhighlighttext
|
||||
-moz-eventreerow -moz-field -moz-fieldtext -moz-dialog -moz-dialogtext
|
||||
-moz-dragtargetzone -moz-gtk-info-bar-text -moz-html-cellhighlight
|
||||
-moz-html-cellhighlighttext -moz-mac-buttonactivetext
|
||||
-moz-gtk-buttonactivetext
|
||||
-moz-mac-chrome-active -moz-mac-chrome-inactive
|
||||
-moz-mac-defaultbuttontext -moz-mac-focusring -moz-mac-menuselect
|
||||
-moz-mac-menushadow -moz-mac-menutextdisable -moz-mac-menutextselect
|
||||
-moz-mac-disabledtoolbartext -moz-mac-secondaryhighlight
|
||||
-moz-mac-vibrancy-light -moz-mac-vibrancy-dark
|
||||
-moz-mac-vibrant-titlebar-light -moz-mac-vibrant-titlebar-dark
|
||||
-moz-mac-menupopup
|
||||
-moz-mac-menuitem -moz-mac-active-menuitem -moz-mac-source-list
|
||||
-moz-mac-source-list-selection -moz-mac-active-source-list-selection
|
||||
-moz-mac-tooltip
|
||||
-moz-menuhover -moz-menuhovertext -moz-menubartext -moz-menubarhovertext
|
||||
-moz-oddtreerow -moz-win-mediatext -moz-win-communicationstext
|
||||
-moz-win-accentcolor -moz-win-accentcolortext
|
||||
-moz-nativehyperlinktext -moz-comboboxtext -moz-combobox""".split()
|
||||
|
||||
# These are not parsed but must be serialized
|
||||
# They are only ever set directly by Gecko
|
||||
extra_colors = """WindowBackground WindowForeground WidgetBackground WidgetForeground
|
||||
WidgetSelectBackground WidgetSelectForeground Widget3DHighlight Widget3DShadow
|
||||
TextBackground TextForeground TextSelectBackground TextSelectForeground
|
||||
TextSelectForegroundCustom TextSelectBackgroundDisabled TextSelectBackgroundAttention
|
||||
TextHighlightBackground TextHighlightForeground IMERawInputBackground
|
||||
IMERawInputForeground IMERawInputUnderline IMESelectedRawTextBackground
|
||||
IMESelectedRawTextForeground IMESelectedRawTextUnderline
|
||||
IMEConvertedTextBackground IMEConvertedTextForeground IMEConvertedTextUnderline
|
||||
IMESelectedConvertedTextBackground IMESelectedConvertedTextForeground
|
||||
IMESelectedConvertedTextUnderline SpellCheckerUnderline""".split()
|
||||
%>
|
||||
use crate::gecko_bindings::bindings::Gecko_GetLookAndFeelSystemColor;
|
||||
use crate::gecko_bindings::structs::root::mozilla::LookAndFeel_ColorID;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use to_shmem::impl_trivial_to_shmem;
|
||||
use crate::values::computed::{Context, ToComputedValue};
|
||||
|
||||
pub type SystemColor = LookAndFeel_ColorID;
|
||||
|
||||
// It's hard to implement MallocSizeOf for LookAndFeel_ColorID because it
|
||||
// is a bindgen type. So we implement it on the typedef instead.
|
||||
malloc_size_of_is_0!(SystemColor);
|
||||
|
||||
impl_trivial_to_shmem!(SystemColor);
|
||||
|
||||
impl ToCss for SystemColor {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
let s = match *self {
|
||||
% for color in system_colors + extra_colors:
|
||||
LookAndFeel_ColorID::eColorID_${to_rust_ident(color)} => "${color}",
|
||||
% endfor
|
||||
LookAndFeel_ColorID::eColorID_LAST_COLOR => unreachable!(),
|
||||
};
|
||||
dest.write_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SystemColor {
|
||||
type ComputedValue = u32; // nscolor
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue {
|
||||
unsafe {
|
||||
Gecko_GetLookAndFeelSystemColor(
|
||||
*self as i32,
|
||||
cx.device().document(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(_: &Self::ComputedValue) -> Self {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl SystemColor {
|
||||
pub fn from_ident<'i, 't>(ident: &str) -> Result<Self, ()> {
|
||||
ascii_case_insensitive_phf_map! {
|
||||
color_name -> SystemColor = {
|
||||
% for color in system_colors:
|
||||
"${color}" => LookAndFeel_ColorID::eColorID_${to_rust_ident(color)},
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
|
||||
color_name(ident).cloned().ok_or(())
|
||||
}
|
||||
}
|
||||
}
|
||||
% endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue