Skip to content

Commit

Permalink
Merge CSSColor into Color.
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Jun 8, 2017
1 parent bf77f81 commit 7568a19
Show file tree
Hide file tree
Showing 25 changed files with 181 additions and 264 deletions.
11 changes: 4 additions & 7 deletions components/script/dom/element.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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>() {
Expand Down Expand Up @@ -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())
)
));
}
Expand Down
21 changes: 3 additions & 18 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -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>

Expand All @@ -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>

Expand Down Expand Up @@ -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,
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhand/background.mako.rs
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhand/border.mako.rs
Expand Up @@ -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"),
Expand Down
16 changes: 10 additions & 6 deletions components/style/properties/longhand/color.mako.rs
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions components/style/properties/longhand/column.mako.rs
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions components/style/properties/longhand/inherited_text.mako.rs
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions components/style/properties/longhand/outline.mako.rs
Expand Up @@ -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")}
Expand Down
6 changes: 3 additions & 3 deletions components/style/properties/longhand/text.mako.rs
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions components/style/properties/properties.mako.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
Expand Down
6 changes: 3 additions & 3 deletions components/style/properties/shorthand/background.mako.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions components/style/properties/shorthand/border.mako.rs
Expand Up @@ -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)}

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/shorthand/outline.mako.rs
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions components/style/properties/shorthand/serialize.mako.rs
Expand Up @@ -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)?;
}
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/shorthand/text.mako.rs
Expand Up @@ -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)?;
}
Expand Down
3 changes: 1 addition & 2 deletions components/style/rule_tree/mod.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions components/style/values/computed/mod.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -584,4 +584,4 @@ impl ClipRectOrAuto {
}

/// <color> | auto
pub type ColorOrAuto = Either<CSSColor, Auto>;
pub type ColorOrAuto = Either<Color, Auto>;

0 comments on commit 7568a19

Please sign in to comment.