mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Use cbindgen for shape-outside and clip-path.
Differential Revision: https://phabricator.services.mozilla.com/D62372
This commit is contained in:
parent
558cc59288
commit
ab03688994
2 changed files with 1 additions and 234 deletions
|
@ -15,159 +15,6 @@ use crate::stylesheets::RulesMutateError;
|
|||
use crate::values::computed::transform::Matrix3D;
|
||||
use crate::values::computed::TextAlign;
|
||||
|
||||
pub mod basic_shape {
|
||||
//! Conversions from and to CSS shape representations.
|
||||
use crate::gecko_bindings::structs::{
|
||||
StyleGeometryBox, StyleShapeSource, StyleShapeSourceType,
|
||||
};
|
||||
use crate::values::computed::basic_shape::{BasicShape, ClippingShape, FloatAreaShape};
|
||||
use crate::values::computed::motion::OffsetPath;
|
||||
use crate::values::generics::basic_shape::{ShapeGeometryBox, Path, ShapeBox, ShapeSource};
|
||||
use crate::values::specified::SVGPathData;
|
||||
|
||||
impl StyleShapeSource {
|
||||
/// Convert StyleShapeSource to ShapeSource except URL and Image
|
||||
/// types.
|
||||
fn to_shape_source<ReferenceBox, ImageOrUrl>(
|
||||
&self,
|
||||
) -> Option<ShapeSource<BasicShape, ReferenceBox, ImageOrUrl>>
|
||||
where
|
||||
ReferenceBox: From<StyleGeometryBox> + Default + PartialEq,
|
||||
{
|
||||
match self.mType {
|
||||
StyleShapeSourceType::None => Some(ShapeSource::None),
|
||||
StyleShapeSourceType::Box => Some(ShapeSource::Box(self.mReferenceBox.into())),
|
||||
StyleShapeSourceType::Shape => {
|
||||
let other_shape = unsafe { &*self.__bindgen_anon_1.mBasicShape.as_ref().mPtr };
|
||||
let shape = Box::new(other_shape.clone());
|
||||
let reference_box = self.mReferenceBox.into();
|
||||
Some(ShapeSource::Shape(shape, reference_box))
|
||||
},
|
||||
StyleShapeSourceType::Image => None,
|
||||
StyleShapeSourceType::Path => {
|
||||
let path = self.to_svg_path().expect("expect an SVGPathData");
|
||||
let fill = unsafe { &*self.__bindgen_anon_1.mSVGPath.as_ref().mPtr }.mFillRule;
|
||||
Some(ShapeSource::Path(Path { fill, path }))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a SVGPathData from StyleShapeSource if possible.
|
||||
fn to_svg_path(&self) -> Option<SVGPathData> {
|
||||
match self.mType {
|
||||
StyleShapeSourceType::Path => {
|
||||
let gecko_path = unsafe { &*self.__bindgen_anon_1.mSVGPath.as_ref().mPtr };
|
||||
Some(SVGPathData(gecko_path.mPath.clone()))
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a StyleShapeSource> for ClippingShape {
|
||||
fn from(other: &'a StyleShapeSource) -> Self {
|
||||
match other.mType {
|
||||
StyleShapeSourceType::Image => unsafe {
|
||||
use crate::values::generics::image::Image as GenericImage;
|
||||
|
||||
let shape_image = &*other.__bindgen_anon_1.mShapeImage.as_ref().mPtr;
|
||||
match *shape_image {
|
||||
GenericImage::Url(ref url) => ShapeSource::ImageOrUrl(url.0.clone()),
|
||||
_ => panic!("ClippingShape doesn't support non-url images"),
|
||||
}
|
||||
},
|
||||
_ => other
|
||||
.to_shape_source()
|
||||
.expect("Couldn't convert to StyleSource!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a StyleShapeSource> for FloatAreaShape {
|
||||
fn from(other: &'a StyleShapeSource) -> Self {
|
||||
match other.mType {
|
||||
StyleShapeSourceType::Image => unsafe {
|
||||
let shape_image = &*other.__bindgen_anon_1.mShapeImage.as_ref().mPtr;
|
||||
ShapeSource::ImageOrUrl(shape_image.clone())
|
||||
},
|
||||
_ => other
|
||||
.to_shape_source()
|
||||
.expect("Couldn't convert to StyleSource!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a StyleShapeSource> for OffsetPath {
|
||||
fn from(other: &'a StyleShapeSource) -> Self {
|
||||
use crate::values::generics::motion::GenericOffsetPath;
|
||||
match other.mType {
|
||||
StyleShapeSourceType::Path => GenericOffsetPath::Path(
|
||||
other.to_svg_path().expect("Cannot convert to SVGPathData"),
|
||||
),
|
||||
StyleShapeSourceType::None => OffsetPath::none(),
|
||||
StyleShapeSourceType::Shape |
|
||||
StyleShapeSourceType::Box |
|
||||
StyleShapeSourceType::Image => unreachable!("Unsupported offset-path type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ShapeBox> for StyleGeometryBox {
|
||||
fn from(reference: ShapeBox) -> Self {
|
||||
use crate::gecko_bindings::structs::StyleGeometryBox::*;
|
||||
match reference {
|
||||
ShapeBox::ContentBox => ContentBox,
|
||||
ShapeBox::PaddingBox => PaddingBox,
|
||||
ShapeBox::BorderBox => BorderBox,
|
||||
ShapeBox::MarginBox => MarginBox,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ShapeGeometryBox> for StyleGeometryBox {
|
||||
fn from(reference: ShapeGeometryBox) -> Self {
|
||||
use crate::gecko_bindings::structs::StyleGeometryBox::*;
|
||||
match reference {
|
||||
ShapeGeometryBox::ShapeBox(shape_box) => From::from(shape_box),
|
||||
ShapeGeometryBox::FillBox => FillBox,
|
||||
ShapeGeometryBox::StrokeBox => StrokeBox,
|
||||
ShapeGeometryBox::ViewBox => ViewBox,
|
||||
ShapeGeometryBox::ElementDependent => NoBox,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StyleGeometryBox> for ShapeGeometryBox {
|
||||
fn from(reference: StyleGeometryBox) -> Self {
|
||||
use crate::gecko_bindings::structs::StyleGeometryBox::*;
|
||||
match reference {
|
||||
ContentBox => ShapeGeometryBox::ShapeBox(ShapeBox::ContentBox),
|
||||
PaddingBox => ShapeGeometryBox::ShapeBox(ShapeBox::PaddingBox),
|
||||
BorderBox => ShapeGeometryBox::ShapeBox(ShapeBox::BorderBox),
|
||||
MarginBox => ShapeGeometryBox::ShapeBox(ShapeBox::MarginBox),
|
||||
FillBox => ShapeGeometryBox::FillBox,
|
||||
StrokeBox => ShapeGeometryBox::StrokeBox,
|
||||
ViewBox => ShapeGeometryBox::ViewBox,
|
||||
NoBox => ShapeGeometryBox::ElementDependent,
|
||||
NoClip | Text | MozAlmostPadding => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StyleGeometryBox> for ShapeBox {
|
||||
fn from(reference: StyleGeometryBox) -> Self {
|
||||
use crate::gecko_bindings::structs::StyleGeometryBox::*;
|
||||
match reference {
|
||||
ContentBox => ShapeBox::ContentBox,
|
||||
PaddingBox => ShapeBox::PaddingBox,
|
||||
BorderBox => ShapeBox::BorderBox,
|
||||
MarginBox => ShapeBox::MarginBox,
|
||||
_ => panic!("Unexpected StyleGeometryBox while converting to ShapeBox"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RulesMutateError> for nsresult {
|
||||
fn from(other: RulesMutateError) -> Self {
|
||||
match other {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue