mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Move ToComputedValue impl of color types into specified::color.
This commit is contained in:
parent
a7dda61158
commit
b7d8fd0ff5
2 changed files with 82 additions and 81 deletions
|
@ -360,86 +360,6 @@ impl ToCss for Time {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::Color {
|
||||
type ComputedValue = RGBA;
|
||||
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
fn to_computed_value(&self, context: &Context) -> RGBA {
|
||||
match *self {
|
||||
specified::Color::RGBA(rgba) => rgba,
|
||||
specified::Color::CurrentColor => context.inherited_style.get_color().clone_color(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
fn to_computed_value(&self, context: &Context) -> RGBA {
|
||||
use gecko::values::convert_nscolor_to_rgba as to_rgba;
|
||||
// It's safe to access the nsPresContext immutably during style computation.
|
||||
let pres_context = unsafe { &*context.device.pres_context };
|
||||
match *self {
|
||||
specified::Color::RGBA(rgba) => rgba,
|
||||
specified::Color::System(system) => to_rgba(system.to_computed_value(context)),
|
||||
specified::Color::CurrentColor => context.inherited_style.get_color().clone_color(),
|
||||
specified::Color::MozDefaultColor => to_rgba(pres_context.mDefaultColor),
|
||||
specified::Color::MozDefaultBackgroundColor => to_rgba(pres_context.mBackgroundColor),
|
||||
specified::Color::MozHyperlinktext => to_rgba(pres_context.mLinkColor),
|
||||
specified::Color::MozActiveHyperlinktext => to_rgba(pres_context.mActiveLinkColor),
|
||||
specified::Color::MozVisitedHyperlinktext => to_rgba(pres_context.mVisitedLinkColor),
|
||||
specified::Color::InheritFromBodyQuirk => {
|
||||
use dom::TElement;
|
||||
use gecko::wrapper::GeckoElement;
|
||||
use gecko_bindings::bindings::Gecko_GetBody;
|
||||
let body = unsafe {
|
||||
Gecko_GetBody(pres_context)
|
||||
};
|
||||
if let Some(body) = body {
|
||||
let wrap = GeckoElement(body);
|
||||
let borrow = wrap.borrow_data();
|
||||
borrow.as_ref().unwrap()
|
||||
.styles().primary.values()
|
||||
.get_color()
|
||||
.clone_color()
|
||||
} else {
|
||||
to_rgba(pres_context.mDefaultColor)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn from_computed_value(computed: &RGBA) -> Self {
|
||||
specified::Color::RGBA(*computed)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::CSSColor {
|
||||
type ComputedValue = CSSColor;
|
||||
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
#[inline]
|
||||
fn to_computed_value(&self, _context: &Context) -> CSSColor {
|
||||
self.parsed
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> CSSColor {
|
||||
match self.parsed {
|
||||
specified::Color::RGBA(rgba) => CSSColor::RGBA(rgba),
|
||||
specified::Color::CurrentColor => CSSColor::CurrentColor,
|
||||
// Resolve non-standard -moz keywords to RGBA:
|
||||
non_standard => CSSColor::RGBA(non_standard.to_computed_value(context)),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &CSSColor) -> Self {
|
||||
(match *computed {
|
||||
CSSColor::RGBA(rgba) => specified::Color::RGBA(rgba),
|
||||
CSSColor::CurrentColor => specified::Color::CurrentColor,
|
||||
}).into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl ToComputedValue for specified::JustifyItems {
|
||||
type ComputedValue = JustifyItems;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue