mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
style: Use rust lengths for row-gap / column-gap.
Differential Revision: https://phabricator.services.mozilla.com/D26915
This commit is contained in:
parent
0f57b7b833
commit
0a84073767
8 changed files with 48 additions and 72 deletions
|
@ -18,7 +18,7 @@ use crate::values::generics::gecko::ScrollSnapPoint;
|
|||
use crate::values::generics::grid::{TrackBreadth, TrackKeyword};
|
||||
use crate::values::generics::length::LengthPercentageOrAuto;
|
||||
use crate::values::generics::{CounterStyleOrNone, NonNegative};
|
||||
use crate::values::{Auto, Either, None_, Normal};
|
||||
use crate::values::Either;
|
||||
use crate::{Atom, Zero};
|
||||
use app_units::Au;
|
||||
use cssparser::RGBA;
|
||||
|
@ -44,23 +44,6 @@ impl nsStyleCoord {
|
|||
}
|
||||
}
|
||||
|
||||
impl<A: GeckoStyleCoordConvertible, B: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible
|
||||
for Either<A, B>
|
||||
{
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
Either::First(ref v) => v.to_gecko_style_coord(coord),
|
||||
Either::Second(ref v) => v.to_gecko_style_coord(coord),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
A::from_gecko_style_coord(coord)
|
||||
.map(Either::First)
|
||||
.or_else(|| B::from_gecko_style_coord(coord).map(Either::Second))
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner> GeckoStyleCoordConvertible for NonNegative<Inner>
|
||||
where
|
||||
Inner: GeckoStyleCoordConvertible,
|
||||
|
@ -265,48 +248,6 @@ impl GeckoStyleCoordConvertible for Angle {
|
|||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for Auto {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::Auto)
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
if let CoordDataValue::Auto = coord.as_value() {
|
||||
Some(Auto)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for None_ {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::None)
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
if let CoordDataValue::None = coord.as_value() {
|
||||
Some(None_)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for Normal {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::Normal)
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
if let CoordDataValue::Normal = coord.as_value() {
|
||||
Some(Normal)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for ScrollSnapPoint<LengthPercentage> {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match self.repeated() {
|
||||
|
|
|
@ -1190,7 +1190,6 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
|||
|
||||
# Types used with predefined_type()-defined properties that we can auto-generate.
|
||||
predefined_types = {
|
||||
"length::NonNegativeLengthPercentageOrNormal": impl_style_coord,
|
||||
"MozScriptMinSize": impl_absolute_length,
|
||||
"SVGLength": impl_svg_length,
|
||||
"SVGOpacity": impl_svg_opacity,
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
#[allow(unused_imports)]
|
||||
use crate::values::{computed, specified};
|
||||
#[allow(unused_imports)]
|
||||
use crate::values::{Auto, Either, None_, Normal};
|
||||
use crate::values::{Auto, Either, None_};
|
||||
${caller.body()}
|
||||
}
|
||||
|
||||
|
@ -292,7 +292,7 @@
|
|||
#[allow(unused_imports)]
|
||||
use crate::properties::{UnparsedValue, ShorthandId};
|
||||
#[allow(unused_imports)]
|
||||
use crate::values::{Auto, Either, None_, Normal};
|
||||
use crate::values::{Auto, Either, None_};
|
||||
#[allow(unused_imports)]
|
||||
use crate::error_reporting::ParseErrorReporter;
|
||||
#[allow(unused_imports)]
|
||||
|
|
|
@ -372,7 +372,7 @@ ${helpers.predefined_type(
|
|||
${helpers.predefined_type(
|
||||
"column-gap",
|
||||
"length::NonNegativeLengthPercentageOrNormal",
|
||||
"Either::Second(Normal)",
|
||||
"computed::length::NonNegativeLengthPercentageOrNormal::normal()",
|
||||
alias="grid-column-gap" if product == "gecko" else "",
|
||||
extra_prefixes="moz",
|
||||
servo_pref="layout.columns.enabled",
|
||||
|
@ -385,7 +385,7 @@ ${helpers.predefined_type(
|
|||
${helpers.predefined_type(
|
||||
"row-gap",
|
||||
"length::NonNegativeLengthPercentageOrNormal",
|
||||
"Either::Second(Normal)",
|
||||
"computed::length::NonNegativeLengthPercentageOrNormal::normal()",
|
||||
alias="grid-row-gap",
|
||||
products="gecko",
|
||||
spec="https://drafts.csswg.org/css-align-3/#propdef-row-gap",
|
||||
|
|
|
@ -10,12 +10,13 @@ use crate::values::computed::NonNegativeNumber;
|
|||
use crate::values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
use crate::values::generics::length as generics;
|
||||
use crate::values::generics::length::{
|
||||
GenericLengthOrNumber, MaxSize as GenericMaxSize, Size as GenericSize,
|
||||
GenericLengthPercentageOrNormal, GenericLengthOrNumber,
|
||||
GenericMaxSize, GenericSize,
|
||||
};
|
||||
use crate::values::generics::NonNegative;
|
||||
use crate::values::specified::length::ViewportPercentageLength;
|
||||
use crate::values::specified::length::{AbsoluteLength, FontBaseSize, FontRelativeLength};
|
||||
use crate::values::{specified, CSSFloat, Either, Normal};
|
||||
use crate::values::{specified, CSSFloat};
|
||||
use crate::Zero;
|
||||
use app_units::Au;
|
||||
use ordered_float::NotNan;
|
||||
|
@ -782,7 +783,7 @@ impl From<NonNegativeLength> for Au {
|
|||
}
|
||||
|
||||
/// Either a computed NonNegativeLengthPercentage or the `normal` keyword.
|
||||
pub type NonNegativeLengthPercentageOrNormal = Either<NonNegativeLengthPercentage, Normal>;
|
||||
pub type NonNegativeLengthPercentageOrNormal = GenericLengthPercentageOrNormal<NonNegativeLengthPercentage>;
|
||||
|
||||
/// Either a non-negative `<length>` or a `<number>`.
|
||||
pub type NonNegativeLengthOrNumber = GenericLengthOrNumber<NonNegativeLength, NonNegativeNumber>;
|
||||
|
|
|
@ -219,3 +219,38 @@ impl<L, N: Zero> Zero for LengthOrNumber<L, N> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A generic `<length-percentage>` | normal` value.
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
Copy,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedValue,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum GenericLengthPercentageOrNormal<LengthPercent> {
|
||||
LengthPercentage(LengthPercent),
|
||||
Normal,
|
||||
}
|
||||
|
||||
pub use self::GenericLengthPercentageOrNormal as LengthPercentageOrNormal;
|
||||
|
||||
impl<LengthPercent> LengthPercentageOrNormal<LengthPercent> {
|
||||
/// Returns the normal value.
|
||||
#[inline]
|
||||
pub fn normal() -> Self {
|
||||
LengthPercentageOrNormal::Normal
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ pub type CSSInteger = i32;
|
|||
|
||||
define_keyword_type!(None_, "none");
|
||||
define_keyword_type!(Auto, "auto");
|
||||
define_keyword_type!(Normal, "normal");
|
||||
|
||||
/// Serialize an identifier which is represented as an atom.
|
||||
#[cfg(feature = "gecko")]
|
||||
|
|
|
@ -13,12 +13,13 @@ use crate::properties::computed_value_flags::ComputedValueFlags;
|
|||
use crate::values::computed::{self, CSSPixelLength, Context};
|
||||
use crate::values::generics::length as generics;
|
||||
use crate::values::generics::length::{
|
||||
GenericLengthOrNumber, MaxSize as GenericMaxSize, Size as GenericSize,
|
||||
GenericLengthPercentageOrNormal, GenericLengthOrNumber,
|
||||
GenericMaxSize, GenericSize,
|
||||
};
|
||||
use crate::values::generics::NonNegative;
|
||||
use crate::values::specified::calc::CalcNode;
|
||||
use crate::values::specified::NonNegativeNumber;
|
||||
use crate::values::{CSSFloat, Either, Normal};
|
||||
use crate::values::CSSFloat;
|
||||
use crate::Zero;
|
||||
use app_units::Au;
|
||||
use cssparser::{Parser, Token};
|
||||
|
@ -957,7 +958,7 @@ impl NonNegativeLengthPercentageOrAuto {
|
|||
pub type NonNegativeLengthPercentage = NonNegative<LengthPercentage>;
|
||||
|
||||
/// Either a NonNegativeLengthPercentage or the `normal` keyword.
|
||||
pub type NonNegativeLengthPercentageOrNormal = Either<NonNegativeLengthPercentage, Normal>;
|
||||
pub type NonNegativeLengthPercentageOrNormal = GenericLengthPercentageOrNormal<NonNegativeLengthPercentage>;
|
||||
|
||||
impl From<NoCalcLength> for NonNegativeLengthPercentage {
|
||||
#[inline]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue