mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Make InsetRect generic
This commit is contained in:
parent
63965f55f5
commit
24226af794
3 changed files with 68 additions and 92 deletions
|
@ -12,7 +12,7 @@ use style_traits::ToCss;
|
||||||
use values::computed::LengthOrPercentage;
|
use values::computed::LengthOrPercentage;
|
||||||
use values::computed::position::Position;
|
use values::computed::position::Position;
|
||||||
use values::generics::basic_shape::{BorderRadius as GenericBorderRadius, ShapeRadius as GenericShapeRadius};
|
use values::generics::basic_shape::{BorderRadius as GenericBorderRadius, ShapeRadius as GenericShapeRadius};
|
||||||
use values::generics::basic_shape::Polygon as GenericPolygon;
|
use values::generics::basic_shape::{InsetRect as GenericInsetRect, Polygon as GenericPolygon};
|
||||||
use values::specified::url::SpecifiedUrl;
|
use values::specified::url::SpecifiedUrl;
|
||||||
|
|
||||||
pub use values::generics::basic_shape::FillRule;
|
pub use values::generics::basic_shape::FillRule;
|
||||||
|
@ -73,35 +73,8 @@ impl ToCss for BasicShape {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
/// The computed value of `inset()`
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
pub type InsetRect = GenericInsetRect<LengthOrPercentage>;
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub struct InsetRect {
|
|
||||||
pub top: LengthOrPercentage,
|
|
||||||
pub right: LengthOrPercentage,
|
|
||||||
pub bottom: LengthOrPercentage,
|
|
||||||
pub left: LengthOrPercentage,
|
|
||||||
pub round: Option<BorderRadius>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for InsetRect {
|
|
||||||
// XXXManishearth again, we should try to reduce the number of values printed here
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
try!(dest.write_str("inset("));
|
|
||||||
try!(self.top.to_css(dest));
|
|
||||||
try!(dest.write_str(" "));
|
|
||||||
try!(self.right.to_css(dest));
|
|
||||||
try!(dest.write_str(" "));
|
|
||||||
try!(self.bottom.to_css(dest));
|
|
||||||
try!(dest.write_str(" "));
|
|
||||||
try!(self.left.to_css(dest));
|
|
||||||
if let Some(ref radius) = self.round {
|
|
||||||
try!(dest.write_str(" round "));
|
|
||||||
try!(radius.to_css(dest));
|
|
||||||
}
|
|
||||||
dest.write_str(")")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
|
|
@ -234,3 +234,61 @@ impl<L: ToComputedValue> ToComputedValue for Polygon<L> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
/// https://drafts.csswg.org/css-shapes/#funcdef-inset
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub struct InsetRect<L> {
|
||||||
|
pub top: L,
|
||||||
|
pub right: L,
|
||||||
|
pub bottom: L,
|
||||||
|
pub left: L,
|
||||||
|
pub round: Option<BorderRadius<L>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<L: ToCss + PartialEq> ToCss for InsetRect<L> {
|
||||||
|
// XXXManishearth We should try to reduce the number of values printed here
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
dest.write_str("inset(")?;
|
||||||
|
self.top.to_css(dest)?;
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
self.right.to_css(dest)?;
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
self.bottom.to_css(dest)?;
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
self.left.to_css(dest)?;
|
||||||
|
if let Some(ref radius) = self.round {
|
||||||
|
dest.write_str(" round ")?;
|
||||||
|
radius.to_css(dest)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest.write_str(")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<L: ToComputedValue> ToComputedValue for InsetRect<L> {
|
||||||
|
type ComputedValue = InsetRect<L::ComputedValue>;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue {
|
||||||
|
InsetRect {
|
||||||
|
top: self.top.to_computed_value(cx),
|
||||||
|
right: self.right.to_computed_value(cx),
|
||||||
|
bottom: self.bottom.to_computed_value(cx),
|
||||||
|
left: self.left.to_computed_value(cx),
|
||||||
|
round: self.round.as_ref().map(|r| r.to_computed_value(cx)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||||
|
InsetRect {
|
||||||
|
top: ToComputedValue::from_computed_value(&computed.top),
|
||||||
|
right: ToComputedValue::from_computed_value(&computed.right),
|
||||||
|
bottom: ToComputedValue::from_computed_value(&computed.bottom),
|
||||||
|
left: ToComputedValue::from_computed_value(&computed.left),
|
||||||
|
round: computed.round.as_ref().map(|r| ToComputedValue::from_computed_value(r)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ use values::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
|
||||||
use values::computed::basic_shape as computed_basic_shape;
|
use values::computed::basic_shape as computed_basic_shape;
|
||||||
use values::generics::BorderRadiusSize;
|
use values::generics::BorderRadiusSize;
|
||||||
use values::generics::basic_shape::{BorderRadius as GenericBorderRadius, ShapeRadius as GenericShapeRadius};
|
use values::generics::basic_shape::{BorderRadius as GenericBorderRadius, ShapeRadius as GenericShapeRadius};
|
||||||
use values::generics::basic_shape::Polygon as GenericPolygon;
|
use values::generics::basic_shape::{InsetRect as GenericInsetRect, Polygon as GenericPolygon};
|
||||||
use values::specified::{LengthOrPercentage, Percentage};
|
use values::specified::{LengthOrPercentage, Percentage};
|
||||||
use values::specified::position::{Keyword, Position};
|
use values::specified::position::{Keyword, Position};
|
||||||
use values::specified::url::SpecifiedUrl;
|
use values::specified::url::SpecifiedUrl;
|
||||||
|
@ -202,23 +202,14 @@ impl ToComputedValue for BasicShape {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
/// The specified value of `inset()`
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
pub type InsetRect = GenericInsetRect<LengthOrPercentage>;
|
||||||
/// https://drafts.csswg.org/css-shapes/#funcdef-inset
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub struct InsetRect {
|
|
||||||
pub top: LengthOrPercentage,
|
|
||||||
pub right: LengthOrPercentage,
|
|
||||||
pub bottom: LengthOrPercentage,
|
|
||||||
pub left: LengthOrPercentage,
|
|
||||||
pub round: Option<BorderRadius>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InsetRect {
|
impl InsetRect {
|
||||||
#[allow(missing_docs)]
|
/// Parse the inner function arguments of `inset()`
|
||||||
pub fn parse_function_arguments(context: &ParserContext, input: &mut Parser) -> Result<InsetRect, ()> {
|
pub fn parse_function_arguments(context: &ParserContext, input: &mut Parser) -> Result<InsetRect, ()> {
|
||||||
let (t, r, b, l) = try!(parse_four_sides(input, |i| LengthOrPercentage::parse(context, i)));
|
let (t, r, b, l) = parse_four_sides(input, |i| LengthOrPercentage::parse(context, i))?;
|
||||||
let mut rect = InsetRect {
|
let mut rect = GenericInsetRect {
|
||||||
top: t,
|
top: t,
|
||||||
right: r,
|
right: r,
|
||||||
bottom: b,
|
bottom: b,
|
||||||
|
@ -238,58 +229,12 @@ impl Parse for InsetRect {
|
||||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||||
match input.try(|i| i.expect_function()) {
|
match input.try(|i| i.expect_function()) {
|
||||||
Ok(ref s) if s.eq_ignore_ascii_case("inset") =>
|
Ok(ref s) if s.eq_ignore_ascii_case("inset") =>
|
||||||
input.parse_nested_block(|i| InsetRect::parse_function_arguments(context, i)),
|
input.parse_nested_block(|i| GenericInsetRect::parse_function_arguments(context, i)),
|
||||||
_ => Err(())
|
_ => Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for InsetRect {
|
|
||||||
// XXXManishearth again, we should try to reduce the number of values printed here
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
try!(dest.write_str("inset("));
|
|
||||||
try!(self.top.to_css(dest));
|
|
||||||
try!(dest.write_str(" "));
|
|
||||||
try!(self.right.to_css(dest));
|
|
||||||
try!(dest.write_str(" "));
|
|
||||||
try!(self.bottom.to_css(dest));
|
|
||||||
try!(dest.write_str(" "));
|
|
||||||
try!(self.left.to_css(dest));
|
|
||||||
if let Some(ref radius) = self.round {
|
|
||||||
try!(dest.write_str(" round "));
|
|
||||||
try!(radius.to_css(dest));
|
|
||||||
}
|
|
||||||
|
|
||||||
dest.write_str(")")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for InsetRect {
|
|
||||||
type ComputedValue = computed_basic_shape::InsetRect;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue {
|
|
||||||
computed_basic_shape::InsetRect {
|
|
||||||
top: self.top.to_computed_value(cx),
|
|
||||||
right: self.right.to_computed_value(cx),
|
|
||||||
bottom: self.bottom.to_computed_value(cx),
|
|
||||||
left: self.left.to_computed_value(cx),
|
|
||||||
round: self.round.as_ref().map(|r| r.to_computed_value(cx)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
|
||||||
InsetRect {
|
|
||||||
top: ToComputedValue::from_computed_value(&computed.top),
|
|
||||||
right: ToComputedValue::from_computed_value(&computed.right),
|
|
||||||
bottom: ToComputedValue::from_computed_value(&computed.bottom),
|
|
||||||
left: ToComputedValue::from_computed_value(&computed.left),
|
|
||||||
round: computed.round.map(|ref r| ToComputedValue::from_computed_value(r)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-shapes/#basic-shape-serialization
|
/// https://drafts.csswg.org/css-shapes/#basic-shape-serialization
|
||||||
///
|
///
|
||||||
/// Positions get serialized differently with basic shapes. Keywords
|
/// Positions get serialized differently with basic shapes. Keywords
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue