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

Merge CSSColor into Color.

  • Loading branch information
upsuper committed Jun 8, 2017
commit 7568a196885ed1f1ed2a38aa30d733e66a8e866e
@@ -111,7 +111,7 @@ use style::stylearc::Arc;
use style::stylist::ApplicableDeclarationBlock;
use style::thread_state;
use style::values::{CSSFloat, Either};
use style::values::specified::{self, CSSColor, Color};
use style::values::specified;
use stylesheet_loader::StylesheetOwner;

// TODO: Update focus state when the top-level browsing context gains or loses system focus,
@@ -420,8 +420,8 @@ impl LayoutElementHelpers for LayoutJS<Element> {
if let Some(color) = bgcolor {
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::BackgroundColor(
CSSColor { parsed: Color::RGBA(color), authored: None })));
PropertyDeclaration::BackgroundColor(color.into())
));
}

let background = if let Some(this) = self.downcast::<HTMLBodyElement>() {
@@ -455,10 +455,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::Color(
longhands::color::SpecifiedValue(CSSColor {
parsed: Color::RGBA(color),
authored: None,
})
longhands::color::SpecifiedValue(color.into())
)
));
}
@@ -319,16 +319,7 @@ def set_gecko_property(ffi_name, expr):
#[allow(unreachable_code)]
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
% if complex_color:
let result = v.into();
% else:
let result = match color {
Color::RGBA(rgba) => convert_rgba_to_nscolor(&rgba),
// FIXME handle currentcolor
Color::CurrentColor => 0,
};
% endif
${set_gecko_property(gecko_ffi_name, "result")}
${set_gecko_property(gecko_ffi_name, "v.into()")}
}
</%def>

@@ -343,11 +334,7 @@ def set_gecko_property(ffi_name, expr):
<%def name="impl_color_clone(ident, gecko_ffi_name, complex_color=True)">
#[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
% if complex_color:
${get_gecko_property(gecko_ffi_name)}.into()
% else:
Color::RGBA(convert_nscolor_to_rgba(${get_gecko_property(gecko_ffi_name)}))
% endif
${get_gecko_property(gecko_ffi_name)}.into()
}
</%def>

@@ -721,7 +708,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
"Number": impl_simple,
"Integer": impl_simple,
"Opacity": impl_simple,
"CSSColor": impl_color,
"Color": impl_color,
"RGBAColor": impl_rgba_color,
"SVGPaint": impl_svg_paint,
"UrlOrNone": impl_css_url,
@@ -742,8 +729,6 @@ impl Debug for ${style_struct.gecko_struct_name} {
args.update(cast_type=longhand.cast_type)
else:
method = predefined_types[longhand.predefined_type]
if longhand.predefined_type in ["CSSColor"]:
args.update(complex_color=longhand.complex_color)

method(**args)

@@ -6,7 +6,7 @@

<% data.new_style_struct("Background", inherited=False) %>

${helpers.predefined_type("background-color", "CSSColor",
${helpers.predefined_type("background-color", "Color",
"::cssparser::Color::RGBA(::cssparser::RGBA::transparent())",
initial_specified_value="SpecifiedValue::transparent()",
spec="https://drafts.csswg.org/css-backgrounds/#background-color",
@@ -16,7 +16,7 @@
return "https://drafts.csswg.org/css-backgrounds/#border-%s-%s" % (side[0], kind)
%>
% for side in ALL_SIDES:
${helpers.predefined_type("border-%s-color" % side[0], "CSSColor",
${helpers.predefined_type("border-%s-color" % side[0], "Color",
"::cssparser::Color::CurrentColor",
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-color"),
spec=maybe_logical_spec(side, "color"),
@@ -12,26 +12,30 @@
animation_value_type="IntermediateRGBA"
ignored_when_colors_disabled="True"
spec="https://drafts.csswg.org/css-color/#color">
use cssparser::RGBA;
use values::specified::{AllowQuirks, Color, CSSColor};
use cssparser::{Color as CSSParserColor, RGBA};
use values::specified::{AllowQuirks, Color};

impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;

#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
self.0.parsed.to_computed_value(context)
match self.0.to_computed_value(context) {
CSSParserColor::RGBA(rgba) => rgba,
CSSParserColor::CurrentColor =>
context.inherited_style.get_color().clone_color(),
}
}

#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
SpecifiedValue(Color::RGBA(*computed).into())
SpecifiedValue(Color::rgba(*computed).into())
}
}

#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)]
pub struct SpecifiedValue(pub CSSColor);
pub struct SpecifiedValue(pub Color);
no_viewport_percentage!(SpecifiedValue);

pub mod computed_value {
@@ -43,7 +47,7 @@
RGBA::new(0, 0, 0, 255) // black
}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
CSSColor::parse_quirky(context, input, AllowQuirks::Yes).map(SpecifiedValue)
Color::parse_quirky(context, input, AllowQuirks::Yes).map(SpecifiedValue)
}

// FIXME(#15973): Add servo support for system colors
@@ -51,9 +51,9 @@ ${helpers.predefined_type("column-rule-width",
extra_prefixes="moz")}

// https://drafts.csswg.org/css-multicol-1/#crc
${helpers.predefined_type("column-rule-color", "CSSColor",
${helpers.predefined_type("column-rule-color", "Color",
"::cssparser::Color::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
initial_specified_value="specified::Color::currentcolor()",
products="gecko", animation_value_type="IntermediateColor", extra_prefixes="moz",
complex_color=True, need_clone=True,
ignored_when_colors_disabled=True,
@@ -685,9 +685,9 @@ ${helpers.predefined_type("word-spacing",
% endif
</%helpers:longhand>

${helpers.predefined_type("text-emphasis-color", "CSSColor",
${helpers.predefined_type("text-emphasis-color", "Color",
"::cssparser::Color::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
initial_specified_value="specified::Color::currentcolor()",
products="gecko", animation_value_type="IntermediateColor",
complex_color=True, need_clone=True,
ignored_when_colors_disabled=True,
@@ -705,17 +705,17 @@ ${helpers.predefined_type(
// CSS Compatibility
// https://compat.spec.whatwg.org
${helpers.predefined_type(
"-webkit-text-fill-color", "CSSColor",
"-webkit-text-fill-color", "Color",
"CSSParserColor::CurrentColor",
products="gecko", animation_value_type="IntermediateColor",
complex_color=True, need_clone=True,
ignored_when_colors_disabled=True,
spec="https://compat.spec.whatwg.org/#the-webkit-text-fill-color")}

${helpers.predefined_type(
"-webkit-text-stroke-color", "CSSColor",
"-webkit-text-stroke-color", "Color",
"CSSParserColor::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
initial_specified_value="specified::Color::currentcolor()",
products="gecko", animation_value_type="IntermediateColor",
complex_color=True, need_clone=True,
ignored_when_colors_disabled=True,
@@ -10,8 +10,8 @@
additional_methods=[Method("outline_has_nonzero_width", "bool")]) %>

// TODO(pcwalton): `invert`
${helpers.predefined_type("outline-color", "CSSColor", "computed::CSSColor::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
${helpers.predefined_type("outline-color", "Color", "computed::Color::CurrentColor",
initial_specified_value="specified::Color::currentcolor()",
animation_value_type="IntermediateColor", complex_color=True, need_clone=True,
ignored_when_colors_disabled=True,
spec="https://drafts.csswg.org/css-ui/#propdef-outline-color")}
@@ -278,9 +278,9 @@ ${helpers.single_keyword("text-decoration-style",
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-style")}

${helpers.predefined_type(
"text-decoration-color", "CSSColor",
"computed::CSSColor::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
"text-decoration-color", "Color",
"computed::Color::CurrentColor",
initial_specified_value="specified::Color::currentcolor()",
complex_color=True,
products="gecko",
animation_value_type="IntermediateColor",
@@ -40,7 +40,6 @@ use stylesheets::{CssRuleType, MallocSizeOf, MallocSizeOfFn, Origin, UrlExtraDat
#[cfg(feature = "servo")] use values::Either;
use values::generics::text::LineHeight;
use values::computed;
use values::specified::Color;
use cascade_info::CascadeInfo;
use rule_tree::{CascadeLevel, StrongRuleNode};
use style_adjuster::StyleAdjuster;
@@ -2626,7 +2625,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
let ignore_colors = !device.use_document_colors();
let default_background_color_decl = if ignore_colors {
let color = device.default_background_color();
Some(PropertyDeclaration::BackgroundColor(Color::RGBA(color).into()))
Some(PropertyDeclaration::BackgroundColor(color.into()))
} else {
None
};
@@ -15,7 +15,7 @@
use properties::longhands::background_clip;
use properties::longhands::background_clip::single_value::computed_value::T as Clip;
use properties::longhands::background_origin::single_value::computed_value::T as Origin;
use values::specified::{CSSColor, Position, PositionComponent};
use values::specified::{Color, Position, PositionComponent};
use parser::Parse;

impl From<background_origin::single_value::SpecifiedValue> for background_clip::single_value::SpecifiedValue {
@@ -50,7 +50,7 @@
% endfor
loop {
if background_color.is_none() {
if let Ok(value) = input.try(|i| CSSColor::parse(context, i)) {
if let Ok(value) = input.try(|i| Color::parse(context, i)) {
background_color = Some(value);
continue
}
@@ -112,7 +112,7 @@
}));

Ok(expanded! {
background_color: background_color.unwrap_or(CSSColor::transparent()),
background_color: background_color.unwrap_or(Color::transparent()),
background_image: background_image,
background_position_x: background_position_x,
background_position_y: background_position_y,
@@ -5,7 +5,7 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import to_rust_ident, ALL_SIDES, PHYSICAL_SIDES, maybe_moz_logical_alias %>

${helpers.four_sides_shorthand("border-color", "border-%s-color", "specified::CSSColor::parse",
${helpers.four_sides_shorthand("border-color", "border-%s-color", "specified::Color::parse",
spec="https://drafts.csswg.org/css-backgrounds/#border-color",
allow_quirks=True)}

@@ -44,18 +44,18 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",


pub fn parse_border(context: &ParserContext, input: &mut Parser)
-> Result<(specified::CSSColor,
-> Result<(specified::Color,
specified::BorderStyle,
specified::BorderSideWidth), ()> {
use values::specified::{CSSColor, BorderStyle, BorderSideWidth};
use values::specified::{Color, BorderStyle, BorderSideWidth};
let _unused = context;
let mut color = None;
let mut style = None;
let mut width = None;
let mut any = false;
loop {
if color.is_none() {
if let Ok(value) = input.try(|i| CSSColor::parse(context, i)) {
if let Ok(value) = input.try(|i| Color::parse(context, i)) {
color = Some(value);
any = true;
continue
@@ -78,7 +78,7 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
break
}
if any {
Ok((color.unwrap_or_else(|| CSSColor::currentcolor()),
Ok((color.unwrap_or_else(|| Color::currentcolor()),
style.unwrap_or(BorderStyle::none),
width.unwrap_or(BorderSideWidth::Medium)))
} else {
@@ -18,7 +18,7 @@
let mut any = false;
loop {
if color.is_none() {
if let Ok(value) = input.try(|i| specified::CSSColor::parse(context, i)) {
if let Ok(value) = input.try(|i| specified::Color::parse(context, i)) {
color = Some(value);
any = true;
continue
@@ -3,18 +3,18 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use style_traits::ToCss;
use values::specified::{BorderStyle, Color, CSSColor};
use values::specified::{BorderStyle, Color};
use std::fmt;

fn serialize_directional_border<W, I,>(dest: &mut W,
width: &I,
style: &BorderStyle,
color: &CSSColor)
color: &Color)
-> fmt::Result where W: fmt::Write, I: ToCss {
width.to_css(dest)?;
dest.write_str(" ")?;
style.to_css(dest)?;
if color.parsed != Color::CurrentColor {
if *color != Color::CurrentColor {
dest.write_str(" ")?;
color.to_css(dest)?;
}
@@ -70,7 +70,7 @@
self.text_decoration_style.to_css(dest)?;
}

if self.text_decoration_color.parsed != specified::Color::CurrentColor {
if *self.text_decoration_color != specified::Color::CurrentColor {
dest.write_str(" ")?;
self.text_decoration_color.to_css(dest)?;
}
@@ -912,7 +912,6 @@ impl StrongRuleNode {
-> bool
where E: ::dom::TElement
{
use cssparser::RGBA;
use gecko_bindings::structs::{NS_AUTHOR_SPECIFIED_BACKGROUND, NS_AUTHOR_SPECIFIED_BORDER};
use gecko_bindings::structs::{NS_AUTHOR_SPECIFIED_PADDING, NS_AUTHOR_SPECIFIED_TEXT_SHADOW};
use properties::{CSSWideKeyword, LonghandId, LonghandIdSet};
@@ -1083,7 +1082,7 @@ impl StrongRuleNode {
if properties.contains(id) {
if !author_colors_allowed {
if let PropertyDeclaration::BackgroundColor(ref color) = *declaration {
return color.parsed == Color::RGBA(RGBA::transparent())
return *color == Color::transparent()
}
}
return true
@@ -23,7 +23,7 @@ use super::generics::grid::TrackList as GenericTrackList;
use super::specified;

pub use app_units::Au;
pub use cssparser::Color as CSSColor;
pub use cssparser::Color;
pub use properties::animated_properties::TransitionProperty;
pub use self::background::BackgroundSize;
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
@@ -402,7 +402,7 @@ pub struct Shadow {
pub offset_y: Au,
pub blur_radius: Au,
pub spread_radius: Au,
pub color: CSSColor,
pub color: Color,
pub inset: bool,
}

@@ -584,4 +584,4 @@ impl ClipRectOrAuto {
}

/// <color> | auto
pub type ColorOrAuto = Either<CSSColor, Auto>;
pub type ColorOrAuto = Either<Color, Auto>;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.