style: Support shape-image: <image>

MozReview-Commit-ID: GSCZIMEpCS2
This commit is contained in:
Ting-Yu Lin 2017-11-17 17:59:11 +08:00
parent b8b5c5371f
commit f3dbaad222
5 changed files with 82 additions and 27 deletions

View file

@ -9,7 +9,7 @@
use std::fmt;
use style_traits::ToCss;
use values::computed::{LengthOrPercentage, ComputedUrl};
use values::computed::{LengthOrPercentage, ComputedUrl, Image};
use values::generics::basic_shape::{BasicShape as GenericBasicShape};
use values::generics::basic_shape::{Circle as GenericCircle, ClippingShape as GenericClippingShape};
use values::generics::basic_shape::{Ellipse as GenericEllipse, FloatAreaShape as GenericFloatAreaShape};
@ -19,7 +19,7 @@ use values::generics::basic_shape::{InsetRect as GenericInsetRect, ShapeRadius a
pub type ClippingShape = GenericClippingShape<BasicShape, ComputedUrl>;
/// A computed float area shape.
pub type FloatAreaShape = GenericFloatAreaShape<BasicShape, ComputedUrl>;
pub type FloatAreaShape = GenericFloatAreaShape<BasicShape, Image>;
/// A computed basic shape.
pub type BasicShape = GenericBasicShape<LengthOrPercentage, LengthOrPercentage, LengthOrPercentage>;

View file

@ -27,7 +27,7 @@ pub enum GeometryBox {
}
/// A float area shape, for `shape-outside`.
pub type FloatAreaShape<BasicShape, Url> = ShapeSource<BasicShape, ShapeBox, Url>;
pub type FloatAreaShape<BasicShape, Image> = ShapeSource<BasicShape, ShapeBox, Image>;
// https://drafts.csswg.org/css-shapes-1/#typedef-shape-box
define_css_keyword_enum!(ShapeBox:
@ -41,9 +41,9 @@ add_impls_for_keyword_enum!(ShapeBox);
/// A shape source, for some reference box.
#[allow(missing_docs)]
#[derive(Animate, Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
pub enum ShapeSource<BasicShape, ReferenceBox, Url> {
pub enum ShapeSource<BasicShape, ReferenceBox, ImageOrUrl> {
#[animation(error)]
Url(Url),
ImageOrUrl(ImageOrUrl),
Shape(
BasicShape,
#[animation(constant)]

View file

@ -22,6 +22,7 @@ use values::generics::basic_shape::{Polygon as GenericPolygon, ShapeRadius as Ge
use values::generics::rect::Rect;
use values::specified::LengthOrPercentage;
use values::specified::border::BorderRadius;
use values::specified::image::Image;
use values::specified::position::{HorizontalPosition, Position, PositionComponent, Side, VerticalPosition};
use values::specified::url::SpecifiedUrl;
@ -29,7 +30,7 @@ use values::specified::url::SpecifiedUrl;
pub type ClippingShape = GenericClippingShape<BasicShape, SpecifiedUrl>;
/// A specified float area shape.
pub type FloatAreaShape = GenericFloatAreaShape<BasicShape, SpecifiedUrl>;
pub type FloatAreaShape = GenericFloatAreaShape<BasicShape, Image>;
/// A specified basic shape.
pub type BasicShape = GenericBasicShape<HorizontalPosition, VerticalPosition, LengthOrPercentage>;
@ -49,14 +50,18 @@ pub type ShapeRadius = GenericShapeRadius<LengthOrPercentage>;
/// The specified value of `Polygon`
pub type Polygon = GenericPolygon<LengthOrPercentage>;
impl<ReferenceBox: Parse> Parse for ShapeSource<BasicShape, ReferenceBox, SpecifiedUrl> {
impl<ReferenceBox, ImageOrUrl> Parse for ShapeSource<BasicShape, ReferenceBox, ImageOrUrl>
where
ReferenceBox: Parse,
ImageOrUrl: Parse,
{
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(ShapeSource::None)
}
if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) {
return Ok(ShapeSource::Url(url))
if let Ok(image_or_url) = input.try(|i| ImageOrUrl::parse(context, i)) {
return Ok(ShapeSource::ImageOrUrl(image_or_url))
}
fn parse_component<U: Parse>(context: &ParserContext, input: &mut Parser,