style: Define offset-path and implement it in style system.

Define OffsetPath & SVGPathData on the servo-side, and StyleMotion &
StyleSVGPath on the gecko-side. We parse the SVG Path string into a
vector of PathCommand. To build the gfx::Path, we will convert it into
gfx::Path later in a different patch.

The basic flow is:
  - Parse SVG Path String into SVGPathData (in Rust).
  - Use cbindgen to make sure the layout of PathCommand and StylePathCommand, and then set the Box[PathCommand] into nsTArray<StylePathCommand>.
  - Try to convert nsTArray<StylePathCommand> into gfx::Path. (This part will be implemented in a different patch.)

Finally, we use the gfx::Path to create a motion path transform.
The layout implementation is in the later patch.

Depends on D2962

Differential Revision: https://phabricator.services.mozilla.com/D2963
This commit is contained in:
Boris Chiou 2018-08-22 01:24:13 +00:00 committed by Emilio Cobos Álvarez
parent 249b865eb8
commit dce2e2927f
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
8 changed files with 742 additions and 3 deletions

View file

@ -638,6 +638,7 @@ pub mod basic_shape {
use values::computed::basic_shape::{BasicShape, ClippingShape, FloatAreaShape, ShapeRadius};
use values::computed::border::{BorderCornerRadius, BorderRadius};
use values::computed::length::LengthOrPercentage;
use values::computed::motion::OffsetPath;
use values::computed::position;
use values::computed::url::ComputedUrl;
use values::generics::basic_shape::{BasicShape as GenericBasicShape, InsetRect, Polygon};
@ -669,6 +670,7 @@ pub mod basic_shape {
Some(ShapeSource::Shape(shape, reference_box))
},
StyleShapeSourceType::URL | StyleShapeSourceType::Image => None,
StyleShapeSourceType::Path => None,
}
}
}
@ -710,6 +712,29 @@ pub mod basic_shape {
}
}
impl<'a> From<&'a StyleShapeSource> for OffsetPath {
fn from(other: &'a StyleShapeSource) -> Self {
use gecko_bindings::structs::StylePathCommand;
use values::specified::motion::{SVGPathData, PathCommand};
match other.mType {
StyleShapeSourceType::Path => {
let gecko_path = unsafe { &*other.__bindgen_anon_1.mSVGPath.as_ref().mPtr };
let result: Vec<PathCommand> =
gecko_path.mPath.iter().map(|gecko: &StylePathCommand| {
// unsafe: cbindgen ensures the representation is the same.
unsafe{ ::std::mem::transmute(*gecko) }
}).collect();
OffsetPath::Path(SVGPathData::new(result.into_boxed_slice()))
},
StyleShapeSourceType::None => OffsetPath::none(),
StyleShapeSourceType::Shape |
StyleShapeSourceType::Box |
StyleShapeSourceType::URL |
StyleShapeSourceType::Image => unreachable!("Unsupported offset-path type"),
}
}
}
impl<'a> From<&'a StyleBasicShape> for BasicShape {
fn from(other: &'a StyleBasicShape) -> Self {
match other.mType {