Bug 1681691 - Create a NonNegativePercentage type in values:specified. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D109285
This commit is contained in:
Jonathan Kew 2021-03-23 08:37:05 +00:00
Родитель 835997ddf8
Коммит 4545c4a746
2 изменённых файлов: 15 добавлений и 1 удалений

Просмотреть файл

@ -71,7 +71,7 @@ pub use self::list::Quotes;
pub use self::motion::{OffsetPath, OffsetRotate};
pub use self::outline::OutlineStyle;
pub use self::page::{Orientation, PageSize, PaperSize};
pub use self::percentage::Percentage;
pub use self::percentage::{Percentage, NonNegativePercentage};
pub use self::position::AspectRatio;
pub use self::position::{
GridAutoFlow, GridTemplateAreas, MasonryAutoFlow, Position, PositionOrAuto,

Просмотреть файл

@ -7,6 +7,7 @@
use crate::parser::{Parse, ParserContext};
use crate::values::computed::percentage::Percentage as ComputedPercentage;
use crate::values::computed::{Context, ToComputedValue};
use crate::values::generics::NonNegative;
use crate::values::specified::calc::CalcNode;
use crate::values::specified::Number;
use crate::values::{serialize_percentage, CSSFloat};
@ -172,3 +173,16 @@ impl ToComputedValue for Percentage {
}
impl SpecifiedValueInfo for Percentage {}
/// A wrapper of Percentage, whose value must be >= 0.
pub type NonNegativePercentage = NonNegative<Percentage>;
impl Parse for NonNegativePercentage {
#[inline]
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Ok(NonNegative(Percentage::parse_non_negative(context, input)?))
}
}