From b24614f894bf5da7ee09f534e04352b27983ea95 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 28 Feb 2017 11:50:12 +1100 Subject: [PATCH] Resolve color:currentcolor during computing The keyword value "currentcolor" should be preserved rather than being replaced by the CSS-wide keyword "inherit" during parsing. --- components/script/dom/element.rs | 15 +++--- .../style/properties/longhand/color.mako.rs | 47 +++++++++++-------- ports/geckolib/glue.rs | 5 +- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 47177172895..ca4ec57773f 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -103,7 +103,7 @@ use style::matching::{common_style_affecting_attributes, rare_style_affecting_at use style::parser::ParserContextExtraData; use style::properties::{DeclaredValue, Importance}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute}; -use style::properties::longhands::{background_image, border_spacing, font_family, font_size, overflow_x}; +use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size, overflow_x}; use style::restyle_hints::RESTYLE_SELF; use style::rule_tree::CascadeLevel; use style::selector_parser::{NonTSPseudoClass, RestyleDamage, SelectorImpl, SelectorParser}; @@ -111,7 +111,7 @@ use style::sink::Push; use style::stylist::ApplicableDeclarationBlock; use style::thread_state; use style::values::CSSFloat; -use style::values::specified::{self, CSSColor, CSSRGBA}; +use style::values::specified::{self, CSSColor}; use stylesheet_loader::StylesheetOwner; // TODO: Update focus state when the top-level browsing context gains or loses system focus, @@ -441,10 +441,13 @@ impl LayoutElementHelpers for LayoutJS { if let Some(color) = color { hints.push(from_declaration( - PropertyDeclaration::Color(DeclaredValue::Value(CSSRGBA { - parsed: color, - authored: None, - })))); + PropertyDeclaration::Color(DeclaredValue::Value( + longhands::color::SpecifiedValue(CSSColor { + parsed: Color::RGBA(color), + authored: None, + }) + )) + )); } let font_family = if let Some(this) = self.downcast::() { diff --git a/components/style/properties/longhand/color.mako.rs b/components/style/properties/longhand/color.mako.rs index 6062db455be..136546e2e70 100644 --- a/components/style/properties/longhand/color.mako.rs +++ b/components/style/properties/longhand/color.mako.rs @@ -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(&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, ()> { - 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 { + CSSColor::parse(context, input).map(SpecifiedValue) } - + diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 4026696825f..915b5e1a77b 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1102,7 +1102,8 @@ pub extern "C" fn Servo_DeclarationBlock_SetColorValue(declarations: use cssparser::Color; use style::gecko::values::convert_nscolor_to_rgba; use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId}; - use style::values::specified::{CSSColor, CSSRGBA}; + use style::properties::longhands; + use style::values::specified::CSSColor; let declarations = RwLock::::as_arc(&declarations); let long = get_longhand_from_id!(property); @@ -1114,7 +1115,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetColorValue(declarations: BorderRightColor => color, BorderBottomColor => color, BorderLeftColor => color, - Color => CSSRGBA { parsed: rgba, authored: None }, + Color => longhands::color::SpecifiedValue(color), BackgroundColor => color, }; declarations.write().declarations.push((prop, Default::default()));