mirror of
https://github.com/servo/servo.git
synced 2025-07-10 08:53:41 +01:00
This enables destructors for tagged unions in cbindgen, implemented in: * https://github.com/eqrion/cbindgen/pull/333 Which allow us to properly generate a destructor for the cbindgen-generated StyleBasicShape (which now contains an OwnedSlice). For now, we still use the glue code to go from Box<BasicShape> to UniquePtr<BasicShape>. But that will change in the future when we generate even more stuff and remove all the glue. I could add support for copy-constructor generation to cbindgen for tagged enums, but I'm not sure if it'll end up being needed, and copy-constructing unions in C++ is always very tricky. Differential Revision: https://phabricator.services.mozilla.com/D29769
75 lines
2.3 KiB
Rust
75 lines
2.3 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
//! CSS handling for the computed value of
|
|
//! [`basic-shape`][basic-shape]s
|
|
//!
|
|
//! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape
|
|
|
|
use crate::values::computed::url::ComputedUrl;
|
|
use crate::values::computed::{Image, LengthPercentage, NonNegativeLengthPercentage};
|
|
use crate::values::generics::basic_shape as generic;
|
|
use std::fmt::{self, Write};
|
|
use style_traits::{CssWriter, ToCss};
|
|
|
|
/// A computed alias for FillRule.
|
|
pub use crate::values::generics::basic_shape::FillRule;
|
|
|
|
/// A computed clipping shape.
|
|
pub type ClippingShape = generic::ClippingShape<BasicShape, ComputedUrl>;
|
|
|
|
/// A computed float area shape.
|
|
pub type FloatAreaShape = generic::FloatAreaShape<BasicShape, Image>;
|
|
|
|
/// A computed basic shape.
|
|
pub type BasicShape = generic::GenericBasicShape<
|
|
LengthPercentage,
|
|
LengthPercentage,
|
|
LengthPercentage,
|
|
NonNegativeLengthPercentage,
|
|
>;
|
|
|
|
/// The computed value of `inset()`
|
|
pub type InsetRect = generic::InsetRect<LengthPercentage, NonNegativeLengthPercentage>;
|
|
|
|
/// A computed circle.
|
|
pub type Circle = generic::Circle<LengthPercentage, LengthPercentage, NonNegativeLengthPercentage>;
|
|
|
|
/// A computed ellipse.
|
|
pub type Ellipse =
|
|
generic::Ellipse<LengthPercentage, LengthPercentage, NonNegativeLengthPercentage>;
|
|
|
|
/// The computed value of `ShapeRadius`
|
|
pub type ShapeRadius = generic::GenericShapeRadius<NonNegativeLengthPercentage>;
|
|
|
|
impl ToCss for Circle {
|
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
where
|
|
W: Write,
|
|
{
|
|
dest.write_str("circle(")?;
|
|
self.radius.to_css(dest)?;
|
|
dest.write_str(" at ")?;
|
|
self.position.to_css(dest)?;
|
|
dest.write_str(")")
|
|
}
|
|
}
|
|
|
|
impl ToCss for Ellipse {
|
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
where
|
|
W: Write,
|
|
{
|
|
dest.write_str("ellipse(")?;
|
|
if (self.semiaxis_x, self.semiaxis_y) != Default::default() {
|
|
self.semiaxis_x.to_css(dest)?;
|
|
dest.write_str(" ")?;
|
|
self.semiaxis_y.to_css(dest)?;
|
|
dest.write_str(" ")?;
|
|
}
|
|
dest.write_str("at ")?;
|
|
self.position.to_css(dest)?;
|
|
dest.write_str(")")
|
|
}
|
|
}
|