Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support interpolation between currentcolor and numeric color #17219

Merged
merged 10 commits into from Jun 8, 2017

Move ToComputedValue impl of color types into specified::color.

  • Loading branch information
upsuper committed Jun 8, 2017
commit b7d8fd0ff5334ae92fd5de0dead7862fd6418b4b
@@ -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;
@@ -4,13 +4,14 @@

//! Specified color values.

use cssparser::{self, Parser, Token};
use cssparser::{self, Color as CSSParserColor, Parser, RGBA, Token};
use itoa;
use parser::{ParserContext, Parse};
use std::fmt;
use std::io::Write;
use style_traits::ToCss;
use super::AllowQuirks;
use values::computed::{Context, ToComputedValue};

#[cfg(not(feature = "gecko"))] pub use self::servo::Color;
#[cfg(feature = "gecko")] pub use self::gecko::Color;
@@ -250,3 +251,83 @@ impl CSSColor {
Color::RGBA(cssparser::RGBA::transparent()).into()
}
}

impl ToComputedValue for Color {
type ComputedValue = RGBA;

#[cfg(not(feature = "gecko"))]
fn to_computed_value(&self, context: &Context) -> RGBA {
match *self {
Color::RGBA(rgba) => rgba,
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 {
Color::RGBA(rgba) => rgba,
Color::System(system) => to_rgba(system.to_computed_value(context)),
Color::CurrentColor => context.inherited_style.get_color().clone_color(),
Color::MozDefaultColor => to_rgba(pres_context.mDefaultColor),
Color::MozDefaultBackgroundColor => to_rgba(pres_context.mBackgroundColor),
Color::MozHyperlinktext => to_rgba(pres_context.mLinkColor),
Color::MozActiveHyperlinktext => to_rgba(pres_context.mActiveLinkColor),
Color::MozVisitedHyperlinktext => to_rgba(pres_context.mVisitedLinkColor),
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 {
Color::RGBA(*computed)
}
}

impl ToComputedValue for CSSColor {
type ComputedValue = CSSParserColor;

#[cfg(not(feature = "gecko"))]
#[inline]
fn to_computed_value(&self, _context: &Context) -> CSSParserColor {
self.parsed
}

#[cfg(feature = "gecko")]
#[inline]
fn to_computed_value(&self, context: &Context) -> CSSParserColor {
match self.parsed {
Color::RGBA(rgba) => CSSParserColor::RGBA(rgba),
Color::CurrentColor => CSSParserColor::CurrentColor,
// Resolve non-standard -moz keywords to RGBA:
non_standard => CSSParserColor::RGBA(non_standard.to_computed_value(context)),
}
}

#[inline]
fn from_computed_value(computed: &CSSParserColor) -> Self {
(match *computed {
CSSParserColor::RGBA(rgba) => Color::RGBA(rgba),
CSSParserColor::CurrentColor => Color::CurrentColor,
}).into()
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.