mirror of
https://github.com/servo/servo.git
synced 2025-10-09 21:10:19 +01:00
Factor out Gecko-specific color keywords.
This commit is contained in:
parent
b7d8fd0ff5
commit
f3610d2724
1 changed files with 24 additions and 29 deletions
|
@ -37,6 +37,14 @@ mod gecko {
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
|
||||||
|
define_css_keyword_enum! { SpecialColorKeyword:
|
||||||
|
"-moz-default-color" => MozDefaultColor,
|
||||||
|
"-moz-default-background-color" => MozDefaultBackgroundColor,
|
||||||
|
"-moz-hyperlinktext" => MozHyperlinktext,
|
||||||
|
"-moz-activehyperlinktext" => MozActiveHyperlinktext,
|
||||||
|
"-moz-visitedhyperlinktext" => MozVisitedHyperlinktext,
|
||||||
|
}
|
||||||
|
|
||||||
/// Color value including non-standard -moz prefixed values.
|
/// Color value including non-standard -moz prefixed values.
|
||||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
|
@ -46,16 +54,8 @@ mod gecko {
|
||||||
RGBA(RGBA),
|
RGBA(RGBA),
|
||||||
/// A system color
|
/// A system color
|
||||||
System(SystemColor),
|
System(SystemColor),
|
||||||
/// -moz-default-color
|
/// A special color keyword value used in Gecko
|
||||||
MozDefaultColor,
|
Special(SpecialColorKeyword),
|
||||||
/// -moz-default-background-color
|
|
||||||
MozDefaultBackgroundColor,
|
|
||||||
/// -moz-hyperlinktext
|
|
||||||
MozHyperlinktext,
|
|
||||||
/// -moz-activehyperlinktext
|
|
||||||
MozActiveHyperlinktext,
|
|
||||||
/// -moz-visitedhyperlinktext
|
|
||||||
MozVisitedHyperlinktext,
|
|
||||||
/// Quirksmode-only rule for inheriting color from the body
|
/// Quirksmode-only rule for inheriting color from the body
|
||||||
InheritFromBodyQuirk,
|
InheritFromBodyQuirk,
|
||||||
}
|
}
|
||||||
|
@ -77,16 +77,10 @@ mod gecko {
|
||||||
Ok(value.into())
|
Ok(value.into())
|
||||||
} else if let Ok(system) = input.try(SystemColor::parse) {
|
} else if let Ok(system) = input.try(SystemColor::parse) {
|
||||||
Ok(Color::System(system))
|
Ok(Color::System(system))
|
||||||
|
} else if let Ok(special) = input.try(SpecialColorKeyword::parse) {
|
||||||
|
Ok(Color::Special(special))
|
||||||
} else {
|
} else {
|
||||||
let ident = input.expect_ident()?;
|
Err(())
|
||||||
match_ignore_ascii_case! { &ident,
|
|
||||||
"-moz-default-color" => Ok(Color::MozDefaultColor),
|
|
||||||
"-moz-default-background-color" => Ok(Color::MozDefaultBackgroundColor),
|
|
||||||
"-moz-hyperlinktext" => Ok(Color::MozHyperlinktext),
|
|
||||||
"-moz-activehyperlinktext" => Ok(Color::MozActiveHyperlinktext),
|
|
||||||
"-moz-visitedhyperlinktext" => Ok(Color::MozVisitedHyperlinktext),
|
|
||||||
_ => Err(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,11 +94,7 @@ mod gecko {
|
||||||
Color::System(system) => system.to_css(dest),
|
Color::System(system) => system.to_css(dest),
|
||||||
|
|
||||||
// Non-standard values:
|
// Non-standard values:
|
||||||
Color::MozDefaultColor => dest.write_str("-moz-default-color"),
|
Color::Special(special) => special.to_css(dest),
|
||||||
Color::MozDefaultBackgroundColor => dest.write_str("-moz-default-background-color"),
|
|
||||||
Color::MozHyperlinktext => dest.write_str("-moz-hyperlinktext"),
|
|
||||||
Color::MozActiveHyperlinktext => dest.write_str("-moz-activehyperlinktext"),
|
|
||||||
Color::MozVisitedHyperlinktext => dest.write_str("-moz-visitedhyperlinktext"),
|
|
||||||
Color::InheritFromBodyQuirk => Ok(()),
|
Color::InheritFromBodyQuirk => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -272,11 +262,16 @@ impl ToComputedValue for Color {
|
||||||
Color::RGBA(rgba) => rgba,
|
Color::RGBA(rgba) => rgba,
|
||||||
Color::System(system) => to_rgba(system.to_computed_value(context)),
|
Color::System(system) => to_rgba(system.to_computed_value(context)),
|
||||||
Color::CurrentColor => context.inherited_style.get_color().clone_color(),
|
Color::CurrentColor => context.inherited_style.get_color().clone_color(),
|
||||||
Color::MozDefaultColor => to_rgba(pres_context.mDefaultColor),
|
Color::Special(special) => {
|
||||||
Color::MozDefaultBackgroundColor => to_rgba(pres_context.mBackgroundColor),
|
use self::gecko::SpecialColorKeyword as Keyword;
|
||||||
Color::MozHyperlinktext => to_rgba(pres_context.mLinkColor),
|
to_rgba(match special {
|
||||||
Color::MozActiveHyperlinktext => to_rgba(pres_context.mActiveLinkColor),
|
Keyword::MozDefaultColor => pres_context.mDefaultColor,
|
||||||
Color::MozVisitedHyperlinktext => to_rgba(pres_context.mVisitedLinkColor),
|
Keyword::MozDefaultBackgroundColor => pres_context.mBackgroundColor,
|
||||||
|
Keyword::MozHyperlinktext => pres_context.mLinkColor,
|
||||||
|
Keyword::MozActiveHyperlinktext => pres_context.mActiveLinkColor,
|
||||||
|
Keyword::MozVisitedHyperlinktext => pres_context.mVisitedLinkColor,
|
||||||
|
})
|
||||||
|
}
|
||||||
Color::InheritFromBodyQuirk => {
|
Color::InheritFromBodyQuirk => {
|
||||||
use dom::TElement;
|
use dom::TElement;
|
||||||
use gecko::wrapper::GeckoElement;
|
use gecko::wrapper::GeckoElement;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue