mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #16859 - nox:gradients, r=emilio
Rewrite style images with a good dose of generics 💉 <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16859) <!-- Reviewable:end -->
This commit is contained in:
commit
eb7314b412
18 changed files with 1509 additions and 1476 deletions
|
@ -28,9 +28,8 @@ use values::specified::calc::CalcNode;
|
|||
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
||||
pub use self::color::Color;
|
||||
pub use self::grid::{GridLine, TrackKeyword};
|
||||
pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||
pub use self::image::{GradientItem, GradientKind, HorizontalDirection, Image, ImageRect, LayerImage};
|
||||
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword, SizeKeyword, VerticalDirection};
|
||||
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||
pub use self::image::{GradientItem, GradientKind, Image, ImageRect, ImageLayer};
|
||||
pub use self::length::AbsoluteLength;
|
||||
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
|
||||
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
|
@ -681,7 +680,7 @@ impl ToCss for Number {
|
|||
|
||||
/// <number-percentage>
|
||||
/// Accepts only non-negative numbers.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum NumberOrPercentage {
|
||||
|
@ -691,13 +690,27 @@ pub enum NumberOrPercentage {
|
|||
|
||||
no_viewport_percentage!(NumberOrPercentage);
|
||||
|
||||
impl Parse for NumberOrPercentage {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
if let Ok(per) = input.try(Percentage::parse_non_negative) {
|
||||
impl NumberOrPercentage {
|
||||
fn parse_with_clamping_mode(context: &ParserContext,
|
||||
input: &mut Parser,
|
||||
type_: AllowedNumericType)
|
||||
-> Result<Self, ()> {
|
||||
if let Ok(per) = input.try(|i| Percentage::parse_with_clamping_mode(i, type_)) {
|
||||
return Ok(NumberOrPercentage::Percentage(per));
|
||||
}
|
||||
|
||||
Number::parse_non_negative(context, input).map(NumberOrPercentage::Number)
|
||||
parse_number_with_clamping_mode(context, input, type_).map(NumberOrPercentage::Number)
|
||||
}
|
||||
|
||||
/// Parse a non-negative number or percentage.
|
||||
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
Self::parse_with_clamping_mode(context, input, AllowedNumericType::NonNegative)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for NumberOrPercentage {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
Self::parse_with_clamping_mode(context, input, AllowedNumericType::All)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue