Rename LayerImage to ImageLayer and make it a type alias

This commit is contained in:
Anthony Ramine 2017-05-12 22:24:30 +02:00
parent fa5b46b6ee
commit 73f77e0a53
12 changed files with 47 additions and 101 deletions

View file

@ -865,9 +865,9 @@ impl FragmentDisplayListBuilding for Fragment {
// http://www.w3.org/TR/CSS21/colors.html#background
let background = style.get_background();
for (i, background_image) in background.background_image.0.iter().enumerate().rev() {
match background_image.0 {
None => {}
Some(Image::Gradient(ref gradient)) => {
match *background_image {
Either::First(_) => {}
Either::Second(Image::Gradient(ref gradient)) => {
self.build_display_list_for_background_gradient(state,
display_list_section,
&absolute_bounds,
@ -876,7 +876,7 @@ impl FragmentDisplayListBuilding for Fragment {
gradient,
style);
}
Some(Image::Url(ref image_url)) => {
Either::Second(Image::Url(ref image_url)) => {
if let Some(url) = image_url.url() {
self.build_display_list_for_background_image(state,
style,
@ -887,10 +887,10 @@ impl FragmentDisplayListBuilding for Fragment {
i);
}
}
Some(Image::Rect(_)) => {
Either::Second(Image::Rect(_)) => {
// TODO: Implement `-moz-image-rect`
}
Some(Image::Element(_)) => {
Either::Second(Image::Element(_)) => {
// TODO: Implement `-moz-element`
}
}
@ -1356,8 +1356,8 @@ impl FragmentDisplayListBuilding for Fragment {
style.get_cursor(Cursor::Default),
display_list_section);
match border_style_struct.border_image_source.0 {
None => {
match border_style_struct.border_image_source {
Either::First(_) => {
state.add_display_item(DisplayItem::Border(box BorderDisplayItem {
base: base,
border_widths: border.to_physical(style.writing_mode),
@ -1371,7 +1371,7 @@ impl FragmentDisplayListBuilding for Fragment {
}),
}));
}
Some(Image::Gradient(ref gradient)) => {
Either::Second(Image::Gradient(ref gradient)) => {
match gradient.kind {
GradientKind::Linear(angle_or_corner) => {
let grad = self.convert_linear_gradient(&bounds,
@ -1412,13 +1412,13 @@ impl FragmentDisplayListBuilding for Fragment {
}
}
}
Some(Image::Rect(..)) => {
Either::Second(Image::Rect(..)) => {
// TODO: Handle border-image with `-moz-image-rect`.
}
Some(Image::Element(..)) => {
Either::Second(Image::Element(..)) => {
// TODO: Handle border-image with `-moz-element`.
}
Some(Image::Url(ref image_url)) => {
Either::Second(Image::Url(ref image_url)) => {
if let Some(url) = image_url.url() {
let webrender_image = state.layout_context
.get_webrender_image_for_url(self.node,

View file

@ -109,7 +109,7 @@ use style::sink::Push;
use style::stylearc::Arc;
use style::stylist::ApplicableDeclarationBlock;
use style::thread_state;
use style::values::CSSFloat;
use style::values::{CSSFloat, Either};
use style::values::specified::{self, CSSColor};
use stylesheet_loader::StylesheetOwner;
@ -427,9 +427,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
shared_lock,
PropertyDeclaration::BackgroundImage(
background_image::SpecifiedValue(vec![
background_image::single_value::SpecifiedValue(Some(
specified::Image::for_cascade(url.into())
))
Either::Second(specified::Image::for_cascade(url.into()))
]))));
}

View file

@ -927,7 +927,7 @@ fn static_assert() {
Gecko_SetNullImageValue(&mut self.gecko.mBorderImageSource);
}
if let Some(image) = image.0 {
if let Either::Second(image) = image {
self.gecko.mBorderImageSource.set(image, &mut false)
}
}
@ -2883,7 +2883,7 @@ fn static_assert() {
for (image, geckoimage) in images.zip(self.gecko.${image_layers_field}
.mLayers.iter_mut()) {
if let Some(image) = image.0 {
if let Either::Second(image) = image {
geckoimage.mImage.set(image, cacheable)
}
}

View file

@ -12,9 +12,9 @@ ${helpers.predefined_type("background-color", "CSSColor",
spec="https://drafts.csswg.org/css-backgrounds/#background-color",
animation_value_type="IntermediateColor", complex_color=True)}
${helpers.predefined_type("background-image", "LayerImage",
initial_value="computed_value::T(None)",
initial_specified_value="SpecifiedValue(None)",
${helpers.predefined_type("background-image", "ImageLayer",
initial_value="Either::First(None_)",
initial_specified_value="Either::First(None_)",
spec="https://drafts.csswg.org/css-backgrounds/#the-background-image",
vector="True",
animation_value_type="none",

View file

@ -190,9 +190,9 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-float-edge)",
animation_value_type="none")}
${helpers.predefined_type("border-image-source", "LayerImage",
initial_value="computed_value::T(None)",
initial_specified_value="SpecifiedValue(None)",
${helpers.predefined_type("border-image-source", "ImageLayer",
initial_value="Either::First(None_)",
initial_specified_value="Either::First(None_)",
spec="https://drafts.csswg.org/css-backgrounds/#the-background-image",
vector=False,
animation_value_type="none",

View file

@ -141,9 +141,10 @@ ${helpers.single_keyword("mask-composite",
extra_prefixes="webkit",
animation_value_type="none",
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-composite")}
${helpers.predefined_type("mask-image", "LayerImage",
initial_value="computed_value::T(None)",
initial_specified_value="SpecifiedValue(None)",
${helpers.predefined_type("mask-image", "ImageLayer",
initial_value="Either::First(None_)",
initial_specified_value="Either::First(None_)",
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-image",
vector=True,
products="gecko",

View file

@ -11,6 +11,7 @@ use cssparser::Color as CSSColor;
use std::f32::consts::PI;
use std::fmt;
use style_traits::ToCss;
use values::{Either, None_};
use values::computed::{Angle, Context, Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue};
use values::computed::position::Position;
use values::generics::image::{CompatMode, ColorStop as GenericColorStop, EndingShape as GenericEndingShape};
@ -20,6 +21,9 @@ use values::generics::image::{ImageRect as GenericImageRect, LineDirection as Ge
use values::specified::image::LineDirection as SpecifiedLineDirection;
use values::specified::position::{X, Y};
/// A computed image layer.
pub type ImageLayer = Either<None_, Image>;
/// Computed values for an image according to CSS-IMAGES.
/// https://drafts.csswg.org/css-images/#image-values
pub type Image = GenericImage<Gradient, ImageRect>;
@ -126,17 +130,3 @@ impl ToComputedValue for SpecifiedLineDirection {
}
}
}
/// Computed values for none | <image> | <mask-source>.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct LayerImage(pub Option<Image>);
impl ToCss for LayerImage {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match self.0 {
None => dest.write_str("none"),
Some(ref image) => image.to_css(dest),
}
}
}

View file

@ -22,7 +22,7 @@ use super::specified::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as G
pub use app_units::Au;
pub use cssparser::Color as CSSColor;
pub use self::image::{Gradient, GradientItem, LayerImage, LineDirection, Image, ImageRect};
pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect};
pub use super::{Auto, Either, None_};
#[cfg(feature = "gecko")]
pub use super::specified::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};

View file

@ -15,6 +15,7 @@ use servo_url::ServoUrl;
use std::f32::consts::PI;
use std::fmt;
use style_traits::ToCss;
use values::{Either, None_};
use values::generics::image::{Circle, CompatMode, Ellipse, ColorStop as GenericColorStop};
use values::generics::image::{EndingShape as GenericEndingShape, Gradient as GenericGradient};
use values::generics::image::{GradientItem as GenericGradientItem, GradientKind as GenericGradientKind};
@ -24,6 +25,9 @@ use values::specified::{Angle, CSSColor, Length, LengthOrPercentage, NumberOrPer
use values::specified::position::{Position, X, Y};
use values::specified::url::SpecifiedUrl;
/// A specified image layer.
pub type ImageLayer = Either<None_, Image>;
/// Specified values for an image according to CSS-IMAGES.
/// https://drafts.csswg.org/css-images/#image-values
pub type Image = GenericImage<Gradient, ImageRect>;
@ -424,51 +428,3 @@ impl Parse for ColorStop {
})
}
}
/// Specified values for none | <image> | <mask-source>.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct LayerImage(pub Option<Image>);
no_viewport_percentage!(LayerImage);
impl ToCss for LayerImage {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
LayerImage(Some(ref image)) => image.to_css(dest),
LayerImage(None) => dest.write_str("none"),
}
}
}
use super::computed::{ToComputedValue, Context};
impl ToComputedValue for LayerImage {
type ComputedValue = super::computed::LayerImage;
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
match *self {
LayerImage(None) => super::computed::LayerImage(None),
LayerImage(Some(ref image)) =>
super::computed::LayerImage(Some(image.to_computed_value(context))),
}
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
match *computed {
super::computed::LayerImage(None) => LayerImage(None),
super::computed::LayerImage(Some(ref image)) =>
LayerImage(Some(ToComputedValue::from_computed_value(image))),
}
}
}
impl Parse for LayerImage {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
Ok(LayerImage(None))
} else {
Ok(LayerImage(Some(try!(Image::parse(context, input)))))
}
}
}

View file

@ -29,7 +29,7 @@ pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, Justify
pub use self::color::Color;
pub use self::grid::{GridLine, TrackKeyword};
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
pub use self::image::{GradientItem, GradientKind, Image, ImageRect, LayerImage};
pub use self::image::{GradientItem, GradientKind, Image, ImageRect, ImageLayer};
pub use self::length::AbsoluteLength;
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};

View file

@ -1800,7 +1800,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(declarations:
raw_extra_data: *mut URLExtraData) {
use style::properties::PropertyDeclaration;
use style::properties::longhands::background_image::SpecifiedValue as BackgroundImage;
use style::properties::longhands::background_image::single_value::SpecifiedValue as SingleBackgroundImage;
use style::values::Either;
use style::values::generics::image::Image;
use style::values::specified::url::SpecifiedUrl;
@ -1812,9 +1812,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(declarations:
QuirksMode::NoQuirks);
if let Ok(url) = SpecifiedUrl::parse_from_string(string.into(), &context) {
let decl = PropertyDeclaration::BackgroundImage(BackgroundImage(
vec![SingleBackgroundImage(
Some(Image::Url(url))
)]
vec![Either::Second(Image::Url(url))]
));
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
decls.push(decl, Importance::Normal);

View file

@ -799,6 +799,7 @@ mod shorthand_serialization {
use style::properties::longhands::mask_position_y as position_y;
use style::properties::longhands::mask_repeat as repeat;
use style::properties::longhands::mask_size as size;
use style::values::Either;
use style::values::generics::image::Image;
use super::*;
@ -828,9 +829,10 @@ mod shorthand_serialization {
fn mask_should_serialize_all_available_properties_when_specified() {
let mut properties = Vec::new();
let image = single_vec_value_typedef!(image,
image::single_value::SpecifiedValue(
Some(Image::Url(SpecifiedUrl::new_for_testing("http://servo/test.png")))));
let image = single_vec_value_typedef!(
image,
Either::Second(Image::Url(SpecifiedUrl::new_for_testing("http://servo/test.png")))
);
let mode = single_vec_keyword_value!(mode, luminance);
@ -880,9 +882,10 @@ mod shorthand_serialization {
fn mask_should_combine_origin_and_clip_properties_when_equal() {
let mut properties = Vec::new();
let image = single_vec_value_typedef!(image,
image::single_value::SpecifiedValue(
Some(Image::Url(SpecifiedUrl::new_for_testing("http://servo/test.png")))));
let image = single_vec_value_typedef!(
image,
Either::Second(Image::Url(SpecifiedUrl::new_for_testing("http://servo/test.png")))
);
let mode = single_vec_keyword_value!(mode, luminance);