mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +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
|
@ -103,7 +103,7 @@ use style::matching::{common_style_affecting_attributes, rare_style_affecting_at
|
||||||
use style::parser::ParserContextExtraData;
|
use style::parser::ParserContextExtraData;
|
||||||
use style::properties::{DeclaredValue, Importance};
|
use style::properties::{DeclaredValue, Importance};
|
||||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
|
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::restyle_hints::RESTYLE_SELF;
|
||||||
use style::rule_tree::CascadeLevel;
|
use style::rule_tree::CascadeLevel;
|
||||||
use style::selector_parser::{NonTSPseudoClass, RestyleDamage, SelectorImpl, SelectorParser};
|
use style::selector_parser::{NonTSPseudoClass, RestyleDamage, SelectorImpl, SelectorParser};
|
||||||
|
@ -111,7 +111,7 @@ use style::sink::Push;
|
||||||
use style::stylist::ApplicableDeclarationBlock;
|
use style::stylist::ApplicableDeclarationBlock;
|
||||||
use style::thread_state;
|
use style::thread_state;
|
||||||
use style::values::CSSFloat;
|
use style::values::CSSFloat;
|
||||||
use style::values::specified::{self, CSSColor, CSSRGBA};
|
use style::values::specified::{self, CSSColor};
|
||||||
use stylesheet_loader::StylesheetOwner;
|
use stylesheet_loader::StylesheetOwner;
|
||||||
|
|
||||||
// TODO: Update focus state when the top-level browsing context gains or loses system focus,
|
// TODO: Update focus state when the top-level browsing context gains or loses system focus,
|
||||||
|
@ -441,10 +441,13 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
|
|
||||||
if let Some(color) = color {
|
if let Some(color) = color {
|
||||||
hints.push(from_declaration(
|
hints.push(from_declaration(
|
||||||
PropertyDeclaration::Color(DeclaredValue::Value(CSSRGBA {
|
PropertyDeclaration::Color(DeclaredValue::Value(
|
||||||
parsed: color,
|
longhands::color::SpecifiedValue(CSSColor {
|
||||||
authored: None,
|
parsed: Color::RGBA(color),
|
||||||
}))));
|
authored: None,
|
||||||
|
})
|
||||||
|
))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let font_family = if let Some(this) = self.downcast::<HTMLFontElement>() {
|
let font_family = if let Some(this) = self.downcast::<HTMLFontElement>() {
|
||||||
|
|
|
@ -6,30 +6,46 @@
|
||||||
|
|
||||||
<% data.new_style_struct("Color", inherited=True) %>
|
<% data.new_style_struct("Color", inherited=True) %>
|
||||||
|
|
||||||
<%helpers:raw_longhand name="color" need_clone="True" animatable="True"
|
<%helpers:longhand name="color" need_clone="True" animatable="True"
|
||||||
spec="https://drafts.csswg.org/css-color/#color">
|
spec="https://drafts.csswg.org/css-color/#color">
|
||||||
use cssparser::Color as CSSParserColor;
|
use cssparser::Color as CSSParserColor;
|
||||||
use cssparser::RGBA;
|
use cssparser::RGBA;
|
||||||
|
use std::fmt;
|
||||||
|
use style_traits::ToCss;
|
||||||
|
use values::HasViewportPercentage;
|
||||||
use values::specified::{CSSColor, CSSRGBA};
|
use values::specified::{CSSColor, CSSRGBA};
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
type ComputedValue = computed_value::T;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||||
self.parsed
|
match self.0.parsed {
|
||||||
|
CSSParserColor::RGBA(rgba) => rgba,
|
||||||
|
CSSParserColor::CurrentColor => context.inherited_style.get_color().clone_color(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||||
CSSRGBA {
|
SpecifiedValue(CSSColor {
|
||||||
parsed: *computed,
|
parsed: CSSParserColor::RGBA(*computed),
|
||||||
authored: None,
|
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 {
|
pub mod computed_value {
|
||||||
use cssparser;
|
use cssparser;
|
||||||
pub type T = cssparser::RGBA;
|
pub type T = cssparser::RGBA;
|
||||||
|
@ -38,16 +54,7 @@
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
RGBA::new(0, 0, 0, 255) // black
|
RGBA::new(0, 0, 0, 255) // black
|
||||||
}
|
}
|
||||||
pub fn parse_specified(context: &ParserContext, input: &mut Parser)
|
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||||
-> Result<DeclaredValue<SpecifiedValue>, ()> {
|
CSSColor::parse(context, input).map(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,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
</%helpers:raw_longhand>
|
</%helpers:longhand>
|
||||||
|
|
|
@ -1102,7 +1102,8 @@ pub extern "C" fn Servo_DeclarationBlock_SetColorValue(declarations:
|
||||||
use cssparser::Color;
|
use cssparser::Color;
|
||||||
use style::gecko::values::convert_nscolor_to_rgba;
|
use style::gecko::values::convert_nscolor_to_rgba;
|
||||||
use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId};
|
use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId};
|
||||||
use style::values::specified::{CSSColor, CSSRGBA};
|
use style::properties::longhands;
|
||||||
|
use style::values::specified::CSSColor;
|
||||||
|
|
||||||
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
let long = get_longhand_from_id!(property);
|
let long = get_longhand_from_id!(property);
|
||||||
|
@ -1114,7 +1115,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetColorValue(declarations:
|
||||||
BorderRightColor => color,
|
BorderRightColor => color,
|
||||||
BorderBottomColor => color,
|
BorderBottomColor => color,
|
||||||
BorderLeftColor => color,
|
BorderLeftColor => color,
|
||||||
Color => CSSRGBA { parsed: rgba, authored: None },
|
Color => longhands::color::SpecifiedValue(color),
|
||||||
BackgroundColor => color,
|
BackgroundColor => color,
|
||||||
};
|
};
|
||||||
declarations.write().declarations.push((prop, Default::default()));
|
declarations.write().declarations.push((prop, Default::default()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue