mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Resolve color:currentcolor during computing
The keyword value "currentcolor" should be preserved rather than being replaced by the CSS-wide keyword "inherit" during parsing.
This commit is contained in:
parent
eb8d0c3df8
commit
b24614f894
3 changed files with 39 additions and 28 deletions
|
@ -6,30 +6,46 @@
|
|||
|
||||
<% data.new_style_struct("Color", inherited=True) %>
|
||||
|
||||
<%helpers:raw_longhand name="color" need_clone="True" animatable="True"
|
||||
spec="https://drafts.csswg.org/css-color/#color">
|
||||
<%helpers:longhand name="color" need_clone="True" animatable="True"
|
||||
spec="https://drafts.csswg.org/css-color/#color">
|
||||
use cssparser::Color as CSSParserColor;
|
||||
use cssparser::RGBA;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
use values::specified::{CSSColor, CSSRGBA};
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
||||
self.parsed
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
match self.0.parsed {
|
||||
CSSParserColor::RGBA(rgba) => rgba,
|
||||
CSSParserColor::CurrentColor => context.inherited_style.get_color().clone_color(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||
CSSRGBA {
|
||||
parsed: *computed,
|
||||
SpecifiedValue(CSSColor {
|
||||
parsed: CSSParserColor::RGBA(*computed),
|
||||
authored: None,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub CSSColor);
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
pub type SpecifiedValue = CSSRGBA;
|
||||
pub mod computed_value {
|
||||
use cssparser;
|
||||
pub type T = cssparser::RGBA;
|
||||
|
@ -38,16 +54,7 @@
|
|||
pub fn get_initial_value() -> computed_value::T {
|
||||
RGBA::new(0, 0, 0, 255) // black
|
||||
}
|
||||
pub fn parse_specified(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<DeclaredValue<SpecifiedValue>, ()> {
|
||||
let value = try!(CSSColor::parse(context, input));
|
||||
let rgba = match value.parsed {
|
||||
CSSParserColor::RGBA(rgba) => rgba,
|
||||
CSSParserColor::CurrentColor => return Ok(DeclaredValue::Inherit)
|
||||
};
|
||||
Ok(DeclaredValue::Value(CSSRGBA {
|
||||
parsed: rgba,
|
||||
authored: value.authored,
|
||||
}))
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
CSSColor::parse(context, input).map(SpecifiedValue)
|
||||
}
|
||||
</%helpers:raw_longhand>
|
||||
</%helpers:longhand>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue