mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
style: Implement accent-color in nsNativeBasicTheme
This is a new addition for CSS UI Level 4: https://drafts.csswg.org/css-ui-4/#widget-accent I want to provide feedback on some spec issues, and thought it was a kinda neat thing to prototype (it also makes testing contrast and such with random GTK themes easier). For now enable for Nightly only. Differential Revision: https://phabricator.services.mozilla.com/D112312
This commit is contained in:
parent
373d22119f
commit
ab445a02b0
5 changed files with 66 additions and 8 deletions
|
@ -73,13 +73,26 @@ ${helpers.single_keyword(
|
|||
|
||||
${helpers.predefined_type(
|
||||
"caret-color",
|
||||
"color::CaretColor",
|
||||
"generics::color::CaretColor::auto()",
|
||||
engines="gecko",
|
||||
spec="https://drafts.csswg.org/css-ui/#caret-color",
|
||||
animation_value_type="CaretColor",
|
||||
boxed=True,
|
||||
ignored_when_colors_disabled=True,
|
||||
)}
|
||||
|
||||
${helpers.predefined_type(
|
||||
"accent-color",
|
||||
"ColorOrAuto",
|
||||
"generics::color::ColorOrAuto::Auto",
|
||||
engines="gecko",
|
||||
spec="https://drafts.csswg.org/css-ui/#caret-color",
|
||||
animation_value_type="AnimatedCaretColor",
|
||||
spec="https://drafts.csswg.org/css-ui-4/#widget-accent",
|
||||
gecko_pref="layout.css.accent-color.enabled",
|
||||
animation_value_type="ColorOrAuto",
|
||||
boxed=True,
|
||||
ignored_when_colors_disabled=True,
|
||||
has_effect_on_gecko_scrollbars=False,
|
||||
)}
|
||||
|
||||
${helpers.predefined_type(
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use crate::values::animated::color::RGBA as AnimatedRGBA;
|
||||
use crate::values::animated::ToAnimatedValue;
|
||||
use crate::values::generics::color::{Color as GenericColor, ColorOrAuto as GenericColorOrAuto};
|
||||
use crate::values::generics::color::{GenericColor, GenericColorOrAuto, GenericCaretColor};
|
||||
use cssparser::{Color as CSSParserColor, RGBA};
|
||||
use std::fmt;
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
|
@ -112,3 +112,6 @@ impl ToAnimatedValue for RGBA {
|
|||
|
||||
/// auto | <color>
|
||||
pub type ColorOrAuto = GenericColorOrAuto<Color>;
|
||||
|
||||
/// caret-color
|
||||
pub type CaretColor = GenericCaretColor<Color>;
|
||||
|
|
|
@ -96,6 +96,7 @@ impl<RGBA> From<RGBA> for Color<RGBA> {
|
|||
ToAnimatedValue,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToCss,
|
||||
ToShmem,
|
||||
)]
|
||||
|
@ -108,3 +109,32 @@ pub enum GenericColorOrAuto<C> {
|
|||
}
|
||||
|
||||
pub use self::GenericColorOrAuto as ColorOrAuto;
|
||||
|
||||
/// Caret color is effectively a ColorOrAuto, but resolves `auto` to
|
||||
/// currentColor.
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
Copy,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedValue,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(transparent)]
|
||||
pub struct GenericCaretColor<C>(pub GenericColorOrAuto<C>);
|
||||
|
||||
impl<C> GenericCaretColor<C> {
|
||||
/// Returns the `auto` value.
|
||||
pub fn auto() -> Self {
|
||||
GenericCaretColor(GenericColorOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
pub use self::GenericCaretColor as CaretColor;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use super::{Context, ToResolvedValue};
|
||||
|
||||
use crate::values::computed;
|
||||
use crate::values::computed::color as computed;
|
||||
use crate::values::generics::color as generics;
|
||||
|
||||
impl ToResolvedValue for computed::Color {
|
||||
|
@ -24,14 +24,14 @@ impl ToResolvedValue for computed::Color {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToResolvedValue for computed::ColorOrAuto {
|
||||
impl ToResolvedValue for computed::CaretColor {
|
||||
// A resolved caret-color value is an rgba color, with auto resolving to
|
||||
// currentcolor.
|
||||
type ResolvedValue = cssparser::RGBA;
|
||||
|
||||
#[inline]
|
||||
fn to_resolved_value(self, context: &Context) -> Self::ResolvedValue {
|
||||
let color = match self {
|
||||
let color = match self.0 {
|
||||
generics::ColorOrAuto::Color(color) => color,
|
||||
generics::ColorOrAuto::Auto => generics::Color::currentcolor(),
|
||||
};
|
||||
|
@ -40,6 +40,6 @@ impl ToResolvedValue for computed::ColorOrAuto {
|
|||
|
||||
#[inline]
|
||||
fn from_resolved_value(resolved: Self::ResolvedValue) -> Self {
|
||||
generics::ColorOrAuto::Color(computed::Color::from_resolved_value(resolved))
|
||||
generics::CaretColor(generics::ColorOrAuto::Color(computed::Color::from_resolved_value(resolved)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use super::AllowQuirks;
|
|||
use crate::gecko_bindings::structs::nscolor;
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::computed::{Color as ComputedColor, Context, ToComputedValue};
|
||||
use crate::values::generics::color::ColorOrAuto as GenericColorOrAuto;
|
||||
use crate::values::generics::color::{GenericColorOrAuto, GenericCaretColor};
|
||||
use crate::values::specified::calc::CalcNode;
|
||||
use crate::values::specified::Percentage;
|
||||
use cssparser::{AngleOrNumber, Color as CSSParserColor, Parser, Token, RGBA};
|
||||
|
@ -808,3 +808,15 @@ impl Parse for ColorPropertyValue {
|
|||
|
||||
/// auto | <color>
|
||||
pub type ColorOrAuto = GenericColorOrAuto<Color>;
|
||||
|
||||
/// caret-color
|
||||
pub type CaretColor = GenericCaretColor<Color>;
|
||||
|
||||
impl Parse for CaretColor {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
ColorOrAuto::parse(context, input).map(GenericCaretColor)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue