mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Create RGBAColor for colors compute to RGBA.
This commit is contained in:
parent
d0d170767d
commit
bf77f81ed6
12 changed files with 135 additions and 91 deletions
|
@ -422,8 +422,7 @@ pub trait FragmentDisplayListBuilding {
|
|||
bounds: &Rect<Au>,
|
||||
stops: &[GradientItem],
|
||||
direction: &LineDirection,
|
||||
repeating: bool,
|
||||
style: &ServoComputedValues)
|
||||
repeating: bool)
|
||||
-> display_list::Gradient;
|
||||
|
||||
fn convert_radial_gradient(&self,
|
||||
|
@ -431,8 +430,7 @@ pub trait FragmentDisplayListBuilding {
|
|||
stops: &[GradientItem],
|
||||
shape: &EndingShape,
|
||||
center: &Position,
|
||||
repeating: bool,
|
||||
style: &ServoComputedValues)
|
||||
repeating: bool)
|
||||
-> display_list::RadialGradient;
|
||||
|
||||
/// Adds the display items necessary to paint the background linear gradient of this fragment
|
||||
|
@ -634,8 +632,7 @@ fn build_border_radius_for_inner_rect(outer_rect: &Rect<Au>,
|
|||
}
|
||||
|
||||
fn convert_gradient_stops(gradient_items: &[GradientItem],
|
||||
total_length: Au,
|
||||
style: &ServoComputedValues) -> Vec<GradientStop> {
|
||||
total_length: Au) -> Vec<GradientStop> {
|
||||
// Determine the position of each stop per CSS-IMAGES § 3.4.
|
||||
|
||||
// Only keep the color stops, discard the color interpolation hints.
|
||||
|
@ -722,7 +719,7 @@ fn convert_gradient_stops(gradient_items: &[GradientItem],
|
|||
};
|
||||
stops.push(GradientStop {
|
||||
offset: offset,
|
||||
color: style.resolve_color(stop.color).to_gfx_color()
|
||||
color: stop.color.to_gfx_color()
|
||||
})
|
||||
}
|
||||
stops
|
||||
|
@ -1192,8 +1189,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
bounds: &Rect<Au>,
|
||||
stops: &[GradientItem],
|
||||
direction: &LineDirection,
|
||||
repeating: bool,
|
||||
style: &ServoComputedValues)
|
||||
repeating: bool)
|
||||
-> display_list::Gradient {
|
||||
let angle = match *direction {
|
||||
LineDirection::Angle(angle) => angle.radians(),
|
||||
|
@ -1234,7 +1230,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
let length = Au::from_f32_px(
|
||||
(delta.x.to_f32_px() * 2.0).hypot(delta.y.to_f32_px() * 2.0));
|
||||
|
||||
let mut stops = convert_gradient_stops(stops, length, style);
|
||||
let mut stops = convert_gradient_stops(stops, length);
|
||||
|
||||
// Only clamped gradients need to be fixed because in repeating gradients
|
||||
// there is no "first" or "last" stop because they repeat infinitly in
|
||||
|
@ -1258,8 +1254,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
stops: &[GradientItem],
|
||||
shape: &EndingShape,
|
||||
center: &Position,
|
||||
repeating: bool,
|
||||
style: &ServoComputedValues)
|
||||
repeating: bool)
|
||||
-> display_list::RadialGradient {
|
||||
let center = Point2D::new(center.horizontal.to_used_value(bounds.size.width),
|
||||
center.vertical.to_used_value(bounds.size.height));
|
||||
|
@ -1278,7 +1273,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
},
|
||||
};
|
||||
|
||||
let mut stops = convert_gradient_stops(stops, radius.width, style);
|
||||
let mut stops = convert_gradient_stops(stops, radius.width);
|
||||
// Repeating gradients have no last stops that can be ignored. So
|
||||
// fixup is not necessary but may actually break the gradient.
|
||||
if !repeating {
|
||||
|
@ -1322,8 +1317,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
let gradient = self.convert_linear_gradient(&bounds,
|
||||
&gradient.items[..],
|
||||
angle_or_corner,
|
||||
gradient.repeating,
|
||||
style);
|
||||
gradient.repeating);
|
||||
DisplayItem::Gradient(box GradientDisplayItem {
|
||||
base: base,
|
||||
gradient: gradient,
|
||||
|
@ -1334,8 +1328,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
&gradient.items[..],
|
||||
shape,
|
||||
center,
|
||||
gradient.repeating,
|
||||
style);
|
||||
gradient.repeating);
|
||||
DisplayItem::RadialGradient(box RadialGradientDisplayItem {
|
||||
base: base,
|
||||
gradient: gradient,
|
||||
|
@ -1459,8 +1452,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
let grad = self.convert_linear_gradient(&bounds,
|
||||
&gradient.items[..],
|
||||
&angle_or_corner,
|
||||
gradient.repeating,
|
||||
style);
|
||||
gradient.repeating);
|
||||
|
||||
state.add_display_item(DisplayItem::Border(box BorderDisplayItem {
|
||||
base: base,
|
||||
|
@ -1478,8 +1470,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
&gradient.items[..],
|
||||
shape,
|
||||
center,
|
||||
gradient.repeating,
|
||||
style);
|
||||
gradient.repeating);
|
||||
state.add_display_item(DisplayItem::Border(box BorderDisplayItem {
|
||||
base: base,
|
||||
border_widths: border.to_physical(style.writing_mode),
|
||||
|
|
|
@ -183,7 +183,6 @@ impl nsStyleImage {
|
|||
}
|
||||
|
||||
fn set_gradient(&mut self, gradient: Gradient) {
|
||||
use cssparser::Color as CSSColor;
|
||||
use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_CIRCULAR, NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL};
|
||||
use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_LINEAR, NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER};
|
||||
use gecko_bindings::structs::{NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE, NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE};
|
||||
|
@ -321,19 +320,7 @@ impl nsStyleImage {
|
|||
|
||||
match *item {
|
||||
GradientItem::ColorStop(ref stop) => {
|
||||
gecko_stop.mColor = match stop.color {
|
||||
CSSColor::CurrentColor => {
|
||||
// TODO(emilio): gecko just stores an nscolor,
|
||||
// and it doesn't seem to support currentColor
|
||||
// as value in a gradient.
|
||||
//
|
||||
// Double-check it and either remove
|
||||
// currentColor for servo or see how gecko
|
||||
// handles this.
|
||||
0
|
||||
},
|
||||
CSSColor::RGBA(ref rgba) => convert_rgba_to_nscolor(rgba),
|
||||
};
|
||||
gecko_stop.mColor = convert_rgba_to_nscolor(&stop.color);
|
||||
gecko_stop.mIsInterpolationHint = false;
|
||||
coord.set(stop.position);
|
||||
},
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||
|
||||
use app_units::Au;
|
||||
use cssparser::Color;
|
||||
use custom_properties::ComputedValuesMap;
|
||||
use gecko_bindings::bindings;
|
||||
% for style_struct in data.style_structs:
|
||||
|
@ -316,18 +315,6 @@ def set_gecko_property(ffi_name, expr):
|
|||
}
|
||||
</%def>
|
||||
|
||||
/// Convert a Servo color into an nscolor; with currentColor as 0
|
||||
///
|
||||
/// Call sites will need to be updated after https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||
fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
|
||||
match color {
|
||||
Color::RGBA(rgba) => {
|
||||
convert_rgba_to_nscolor(&rgba)
|
||||
},
|
||||
Color::CurrentColor => 0,
|
||||
}
|
||||
}
|
||||
|
||||
<%def name="impl_color_setter(ident, gecko_ffi_name, complex_color=True)">
|
||||
#[allow(unreachable_code)]
|
||||
#[allow(non_snake_case)]
|
||||
|
@ -335,7 +322,11 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
|
|||
% if complex_color:
|
||||
let result = v.into();
|
||||
% else:
|
||||
let result = color_to_nscolor_zero_currentcolor(v);
|
||||
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")}
|
||||
}
|
||||
|
@ -416,6 +407,20 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
|
|||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="impl_rgba_color(ident, gecko_ffi_name, need_clone=False)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
${set_gecko_property(gecko_ffi_name, "convert_rgba_to_nscolor(&v)")}
|
||||
}
|
||||
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
|
||||
% if need_clone:
|
||||
#[allow(non_snake_case)]
|
||||
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
||||
convert_nscolor_to_rgba(${get_gecko_property(gecko_ffi_name)})
|
||||
}
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="impl_svg_paint(ident, gecko_ffi_name, need_clone=False, complex_color=True)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_${ident}(&mut self, mut v: longhands::${ident}::computed_value::T) {
|
||||
|
@ -444,14 +449,14 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
|
|||
SVGPaintKind::Color(color) => {
|
||||
paint.mType = nsStyleSVGPaintType::eStyleSVGPaintType_Color;
|
||||
unsafe {
|
||||
*paint.mPaint.mColor.as_mut() = color_to_nscolor_zero_currentcolor(color);
|
||||
*paint.mPaint.mColor.as_mut() = convert_rgba_to_nscolor(&color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(fallback) = fallback {
|
||||
paint.mFallbackType = nsStyleSVGFallbackType::eStyleSVGFallbackType_Color;
|
||||
paint.mFallbackColor = color_to_nscolor_zero_currentcolor(fallback);
|
||||
paint.mFallbackColor = convert_rgba_to_nscolor(&fallback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -472,7 +477,7 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
|
|||
use self::structs::nsStyleSVGFallbackType;
|
||||
let ref paint = ${get_gecko_property(gecko_ffi_name)};
|
||||
let fallback = if let nsStyleSVGFallbackType::eStyleSVGFallbackType_Color = paint.mFallbackType {
|
||||
Some(Color::RGBA(convert_nscolor_to_rgba(paint.mFallbackColor)))
|
||||
Some(convert_nscolor_to_rgba(paint.mFallbackColor))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -485,7 +490,7 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
|
|||
SVGPaintKind::None
|
||||
}
|
||||
nsStyleSVGPaintType::eStyleSVGPaintType_Color => {
|
||||
unsafe { SVGPaintKind::Color(Color::RGBA(convert_nscolor_to_rgba(*paint.mPaint.mColor.as_ref()))) }
|
||||
unsafe { SVGPaintKind::Color(convert_nscolor_to_rgba(*paint.mPaint.mColor.as_ref())) }
|
||||
}
|
||||
};
|
||||
SVGPaint {
|
||||
|
@ -717,6 +722,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
|
|||
"Integer": impl_simple,
|
||||
"Opacity": impl_simple,
|
||||
"CSSColor": impl_color,
|
||||
"RGBAColor": impl_rgba_color,
|
||||
"SVGPaint": impl_svg_paint,
|
||||
"UrlOrNone": impl_css_url,
|
||||
}
|
||||
|
@ -948,7 +954,7 @@ fn static_assert() {
|
|||
structs::Side::eSide${to_camel_case(side.ident)});
|
||||
}
|
||||
for color in colors {
|
||||
let c = color_to_nscolor_zero_currentcolor(*color);
|
||||
let c = convert_rgba_to_nscolor(color);
|
||||
unsafe {
|
||||
bindings::Gecko_AppendMozBorderColors(&mut self.gecko,
|
||||
structs::Side::eSide${to_camel_case(side.ident)},
|
||||
|
|
|
@ -2823,9 +2823,9 @@ impl From<IntermediateColor> for CSSParserColor {
|
|||
}
|
||||
|
||||
/// Animatable SVGPaint
|
||||
pub type IntermediateSVGPaint = SVGPaint<IntermediateColor>;
|
||||
pub type IntermediateSVGPaint = SVGPaint<IntermediateRGBA>;
|
||||
/// Animatable SVGPaintKind
|
||||
pub type IntermediateSVGPaintKind = SVGPaintKind<IntermediateColor>;
|
||||
pub type IntermediateSVGPaintKind = SVGPaintKind<IntermediateRGBA>;
|
||||
|
||||
impl From<::values::computed::SVGPaint> for IntermediateSVGPaint {
|
||||
fn from(paint: ::values::computed::SVGPaint) -> IntermediateSVGPaint {
|
||||
|
|
|
@ -66,21 +66,21 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style',
|
|||
ignored_when_colors_disabled="True">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::specified::CSSColor;
|
||||
use values::specified::RGBAColor;
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
pub mod computed_value {
|
||||
use values::computed::CSSColor;
|
||||
use cssparser::RGBA;
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Option<Vec<CSSColor>>);
|
||||
pub struct T(pub Option<Vec<RGBA>>);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
None,
|
||||
Colors(Vec<CSSColor>),
|
||||
Colors(Vec<RGBAColor>),
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
|
@ -168,7 +168,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style',
|
|||
}
|
||||
|
||||
let mut result = Vec::new();
|
||||
while let Ok(value) = input.try(|i| CSSColor::parse(context, i)) {
|
||||
while let Ok(value) = input.try(|i| RGBAColor::parse(context, i)) {
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ ${helpers.single_keyword("vector-effect", "none non-scaling-stroke",
|
|||
// Section 13 - Gradients and Patterns
|
||||
|
||||
${helpers.predefined_type(
|
||||
"stop-color", "CSSColor",
|
||||
"CSSParserColor::RGBA(RGBA::new(0, 0, 0, 255))",
|
||||
"stop-color", "RGBAColor",
|
||||
"RGBA::new(0, 0, 0, 255)",
|
||||
products="gecko",
|
||||
animation_value_type="none",
|
||||
spec="https://www.w3.org/TR/SVGTiny12/painting.html#StopColorProperty")}
|
||||
|
@ -34,8 +34,8 @@ ${helpers.predefined_type("stop-opacity", "Opacity", "1.0",
|
|||
// Section 15 - Filter Effects
|
||||
|
||||
${helpers.predefined_type(
|
||||
"flood-color", "CSSColor",
|
||||
"CSSParserColor::RGBA(RGBA::new(0, 0, 0, 255))",
|
||||
"flood-color", "RGBAColor",
|
||||
"RGBA::new(0, 0, 0, 255)",
|
||||
products="gecko",
|
||||
animation_value_type="none",
|
||||
spec="https://www.w3.org/TR/SVG/filters.html#FloodColorProperty")}
|
||||
|
@ -45,8 +45,8 @@ ${helpers.predefined_type("flood-opacity", "Opacity",
|
|||
spec="https://www.w3.org/TR/SVG/filters.html#FloodOpacityProperty")}
|
||||
|
||||
${helpers.predefined_type(
|
||||
"lighting-color", "CSSColor",
|
||||
"CSSParserColor::RGBA(RGBA::new(255, 255, 255, 255))",
|
||||
"lighting-color", "RGBAColor",
|
||||
"RGBA::new(255, 255, 255, 255)",
|
||||
products="gecko",
|
||||
animation_value_type="none",
|
||||
spec="https://www.w3.org/TR/SVG/filters.html#LightingColorProperty")}
|
||||
|
|
10
components/style/values/computed/color.rs
Normal file
10
components/style/values/computed/color.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Computed color values.
|
||||
|
||||
use cssparser::RGBA;
|
||||
|
||||
/// Computed value type for the specified RGBAColor.
|
||||
pub type RGBAColor = RGBA;
|
|
@ -7,7 +7,7 @@
|
|||
//!
|
||||
//! [image]: https://drafts.csswg.org/css-images/#image-values
|
||||
|
||||
use cssparser::Color as CSSColor;
|
||||
use cssparser::RGBA;
|
||||
use std::f32::consts::PI;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
@ -35,7 +35,7 @@ pub type Gradient = GenericGradient<
|
|||
Length,
|
||||
LengthOrPercentage,
|
||||
Position,
|
||||
CSSColor,
|
||||
RGBA,
|
||||
>;
|
||||
|
||||
/// A computed gradient kind.
|
||||
|
@ -60,10 +60,10 @@ pub enum LineDirection {
|
|||
pub type EndingShape = GenericEndingShape<Length, LengthOrPercentage>;
|
||||
|
||||
/// A computed gradient item.
|
||||
pub type GradientItem = GenericGradientItem<CSSColor, LengthOrPercentage>;
|
||||
pub type GradientItem = GenericGradientItem<RGBA, LengthOrPercentage>;
|
||||
|
||||
/// A computed color stop.
|
||||
pub type ColorStop = GenericColorStop<CSSColor, LengthOrPercentage>;
|
||||
pub type ColorStop = GenericColorStop<RGBA, LengthOrPercentage>;
|
||||
|
||||
/// Computed values for ImageRect.
|
||||
pub type ImageRect = GenericImageRect<NumberOrPercentage>;
|
||||
|
|
|
@ -28,6 +28,7 @@ pub use properties::animated_properties::TransitionProperty;
|
|||
pub use self::background::BackgroundSize;
|
||||
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
|
||||
pub use self::border::{BorderRadius, BorderCornerRadius};
|
||||
pub use self::color::RGBAColor;
|
||||
pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect};
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::gecko::ScrollSnapPoint;
|
||||
|
@ -48,6 +49,7 @@ pub use self::transform::{TimingFunction, TransformOrigin};
|
|||
pub mod background;
|
||||
pub mod basic_shape;
|
||||
pub mod border;
|
||||
pub mod color;
|
||||
pub mod image;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub mod gecko;
|
||||
|
@ -479,9 +481,9 @@ impl IntegerOrAuto {
|
|||
}
|
||||
|
||||
/// Computed SVG Paint value
|
||||
pub type SVGPaint = ::values::generics::SVGPaint<CSSColor>;
|
||||
pub type SVGPaint = ::values::generics::SVGPaint<RGBA>;
|
||||
/// Computed SVG Paint Kind value
|
||||
pub type SVGPaintKind = ::values::generics::SVGPaintKind<CSSColor>;
|
||||
pub type SVGPaintKind = ::values::generics::SVGPaintKind<RGBA>;
|
||||
|
||||
impl Default for SVGPaint {
|
||||
fn default() -> Self {
|
||||
|
@ -497,7 +499,7 @@ impl SVGPaint {
|
|||
pub fn black() -> Self {
|
||||
let rgba = RGBA::from_floats(0., 0., 0., 1.);
|
||||
SVGPaint {
|
||||
kind: ::values::generics::SVGPaintKind::Color(CSSColor::RGBA(rgba)),
|
||||
kind: ::values::generics::SVGPaintKind::Color(rgba),
|
||||
fallback: None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -313,3 +313,56 @@ impl ToComputedValue for CSSColor {
|
|||
}).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Specified color value, but resolved to just RGBA for computed value
|
||||
/// with value from color property at the same context.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct RGBAColor(pub CSSColor);
|
||||
|
||||
no_viewport_percentage!(RGBAColor);
|
||||
|
||||
impl Parse for RGBAColor {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
CSSColor::parse(context, input).map(RGBAColor)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for RGBAColor {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for RGBAColor {
|
||||
type ComputedValue = RGBA;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> RGBA {
|
||||
match self.0.to_computed_value(context) {
|
||||
CSSParserColor::RGBA(rgba) => rgba,
|
||||
CSSParserColor::CurrentColor => context.style.get_color().clone_color(),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_computed_value(computed: &RGBA) -> Self {
|
||||
RGBAColor(CSSColor {
|
||||
parsed: Color::RGBA(*computed),
|
||||
authored: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Color> for RGBAColor {
|
||||
fn from(color: Color) -> RGBAColor {
|
||||
RGBAColor(CSSColor {
|
||||
parsed: color,
|
||||
authored: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CSSColor> for RGBAColor {
|
||||
fn from(color: CSSColor) -> RGBAColor {
|
||||
RGBAColor(color)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ use values::generics::image::{LineDirection as GenericsLineDirection, ShapeExten
|
|||
use values::generics::image::PaintWorklet;
|
||||
use values::generics::position::Position as GenericPosition;
|
||||
use values::specified::{Angle, CSSColor, Color, Length, LengthOrPercentage};
|
||||
use values::specified::{Number, NumberOrPercentage, Percentage};
|
||||
use values::specified::{Number, NumberOrPercentage, Percentage, RGBAColor};
|
||||
use values::specified::position::{Position, PositionComponent, Side, X, Y};
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
|
@ -43,7 +43,7 @@ pub type Gradient = GenericGradient<
|
|||
Length,
|
||||
LengthOrPercentage,
|
||||
Position,
|
||||
CSSColor,
|
||||
RGBAColor,
|
||||
>;
|
||||
|
||||
/// A specified gradient kind.
|
||||
|
@ -72,10 +72,10 @@ pub enum LineDirection {
|
|||
pub type EndingShape = GenericEndingShape<Length, LengthOrPercentage>;
|
||||
|
||||
/// A specified gradient item.
|
||||
pub type GradientItem = GenericGradientItem<CSSColor, LengthOrPercentage>;
|
||||
pub type GradientItem = GenericGradientItem<RGBAColor, LengthOrPercentage>;
|
||||
|
||||
/// A computed color stop.
|
||||
pub type ColorStop = GenericColorStop<CSSColor, LengthOrPercentage>;
|
||||
pub type ColorStop = GenericColorStop<RGBAColor, LengthOrPercentage>;
|
||||
|
||||
/// Specified values for `moz-image-rect`
|
||||
/// -moz-image-rect(<uri>, top, right, bottom, left);
|
||||
|
@ -390,7 +390,7 @@ impl Gradient {
|
|||
if color.parsed == Color::CurrentColor {
|
||||
return Err(());
|
||||
}
|
||||
Ok((color, p))
|
||||
Ok((color.into(), p))
|
||||
})?;
|
||||
if reverse_stops {
|
||||
p = 1. - p;
|
||||
|
@ -405,11 +405,11 @@ impl Gradient {
|
|||
if items.is_empty() {
|
||||
items = vec![
|
||||
GenericGradientItem::ColorStop(GenericColorStop {
|
||||
color: CSSColor::transparent(),
|
||||
color: CSSColor::transparent().into(),
|
||||
position: Some(Percentage(0.).into()),
|
||||
}),
|
||||
GenericGradientItem::ColorStop(GenericColorStop {
|
||||
color: CSSColor::transparent(),
|
||||
color: CSSColor::transparent().into(),
|
||||
position: Some(Percentage(1.).into()),
|
||||
}),
|
||||
];
|
||||
|
@ -674,7 +674,7 @@ impl GradientItem {
|
|||
impl Parse for ColorStop {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
Ok(ColorStop {
|
||||
color: try!(CSSColor::parse(context, input)),
|
||||
color: try!(RGBAColor::parse(context, input)),
|
||||
position: input.try(|i| LengthOrPercentage::parse(context, i)).ok(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, Justify
|
|||
pub use self::background::BackgroundSize;
|
||||
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
||||
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth};
|
||||
pub use self::color::{CSSColor, Color};
|
||||
pub use self::color::{CSSColor, Color, RGBAColor};
|
||||
pub use self::rect::LengthOrNumberRect;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::gecko::ScrollSnapPoint;
|
||||
|
@ -799,10 +799,10 @@ impl Shadow {
|
|||
no_viewport_percentage!(SVGPaint);
|
||||
|
||||
/// Specified SVG Paint value
|
||||
pub type SVGPaint = ::values::generics::SVGPaint<CSSColor>;
|
||||
pub type SVGPaint = ::values::generics::SVGPaint<RGBAColor>;
|
||||
|
||||
/// Specified SVG Paint Kind value
|
||||
pub type SVGPaintKind = ::values::generics::SVGPaintKind<CSSColor>;
|
||||
pub type SVGPaintKind = ::values::generics::SVGPaintKind<RGBAColor>;
|
||||
|
||||
impl ToComputedValue for SVGPaint {
|
||||
type ComputedValue = super::computed::SVGPaint;
|
||||
|
@ -829,12 +829,7 @@ impl ToComputedValue for SVGPaintKind {
|
|||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
self.convert(|color| {
|
||||
match color.parsed {
|
||||
Color::CurrentColor => cssparser::Color::RGBA(context.style().get_color().clone_color()),
|
||||
_ => color.to_computed_value(context),
|
||||
}
|
||||
})
|
||||
self.convert(|color| color.to_computed_value(context))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue