mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Let aspect-ratio (css-sizing-4) support 'auto | <ratio>'.
In order to test its parsing and serialization, we expose it but protect it behind a pref. Besides, I would like to drop layout.css.aspect-ratio-number.enabled in the next patch because the spec has been updated. It seems we don't have to keep this pref and we should always use Number. Differential Revision: https://phabricator.services.mozilla.com/D74955
This commit is contained in:
parent
bd23e05c47
commit
fc9321bb23
8 changed files with 185 additions and 18 deletions
|
@ -5,6 +5,10 @@
|
|||
//! Generic types for CSS handling of specified and computed values of
|
||||
//! [`position`](https://drafts.csswg.org/css-backgrounds-3/#position)
|
||||
|
||||
use crate::One;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
|
||||
/// A generic type for representing a CSS [position](https://drafts.csswg.org/css-values/#position).
|
||||
#[derive(
|
||||
Animate,
|
||||
|
@ -150,3 +154,74 @@ impl<Integer> ZIndex<Integer> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A generic value for the `<ratio>` value.
|
||||
// FIXME: Use this for aspect-ratio in both css-sizing-4 and media-queries in the following patch.
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
Copy,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct Ratio<N>(pub N, pub N);
|
||||
|
||||
impl<N> ToCss for Ratio<N>
|
||||
where
|
||||
N: ToCss + One + std::cmp::PartialEq,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
self.0.to_css(dest)?;
|
||||
// The second defaults to 1. So if it is one, we omit it in serialization.
|
||||
if !self.1.is_one() {
|
||||
dest.write_str(" / ")?;
|
||||
self.1.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// A generic value for the `aspect-ratio` property.
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
Copy,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericAspectRatio<N> {
|
||||
/// The <ratio> value.
|
||||
Ratio(#[css(field_bound)] Ratio<N>),
|
||||
/// The keyword `auto`.
|
||||
Auto,
|
||||
}
|
||||
|
||||
pub use self::GenericAspectRatio as AspectRatio;
|
||||
|
||||
impl<R> AspectRatio<R> {
|
||||
/// Returns `auto`
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
AspectRatio::Auto
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue