/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Specified types for CSS values that are related to motion path.
usecrate::parser::{Parse, ParserContext}; usecrate::values::computed::motion::OffsetRotate as ComputedOffsetRotate; usecrate::values::computed::{Context, ToComputedValue}; usecrate::values::generics::motion as generics; usecrate::values::specified::basic_shape::BasicShape; usecrate::values::specified::position::{HorizontalPosition, VerticalPosition}; usecrate::values::specified::url::SpecifiedUrl; usecrate::values::specified::{Angle, Position}; usecrate::Zero; use cssparser::Parser; use style_traits::{ParseError, StyleParseErrorKind};
/// The specified value of ray() function. pubtype RayFunction = generics::GenericRayFunction<Angle, Position>;
/// The specified value of <offset-path>. pubtype OffsetPathFunction =
generics::GenericOffsetPathFunction<BasicShape, RayFunction, SpecifiedUrl>;
/// The specified value of `offset-path`. pubtype OffsetPath = generics::GenericOffsetPath<OffsetPathFunction>;
/// The specified value of `offset-position`. pubtype OffsetPosition = generics::GenericOffsetPosition<HorizontalPosition, VerticalPosition>;
if size.is_none() {
size = input.try_parse(generics::RaySize::parse).ok(); if size.is_some() { continue;
}
}
if !contain {
contain = input
.try_parse(|i| i.expect_ident_matching("contain"))
.is_ok(); if contain { continue;
}
}
if position.is_none() { if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() { let pos = Position::parse(context, input)?;
position = Some(PositionOrAuto::Position(pos));
}
if position.is_some() { continue;
}
} break;
}
if angle.is_none() { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(RayFunction {
angle: angle.unwrap(), // If no <ray-size> is specified it defaults to closest-side.
size: size.unwrap_or(generics::RaySize::ClosestSide),
contain,
position: position.unwrap_or(PositionOrAuto::auto()),
})
}
}
/// The direction of offset-rotate. #[derive(
Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem,
)] #[repr(u8)] pubenum OffsetRotateDirection { /// Unspecified direction keyword. #[css(skip)]
None, /// 0deg offset (face forward).
Auto, /// 180deg offset (face backward).
Reverse,
}
impl OffsetRotateDirection { /// Returns true if it is none (i.e. the keyword is not specified). #[inline] fn is_none(&self) -> bool {
*self == OffsetRotateDirection::None
}
}
/// The specified offset-rotate. /// The syntax is: "[ auto | reverse ] || <angle>" /// /// https://drafts.fxtf.org/motion-1/#offset-rotate-property #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] pubstruct OffsetRotate { /// [auto | reverse]. #[css(skip_if = "OffsetRotateDirection::is_none")]
direction: OffsetRotateDirection, /// <angle>. /// If direction is None, this is a fixed angle which indicates a /// constant clockwise rotation transformation applied to it by this /// specified rotation angle. Otherwise, the angle will be added to /// the angle of the direction in layout. #[css(contextual_skip_if = "direction_specified_and_angle_is_zero")]
angle: Angle,
}
/// Returns true if self is auto 0deg. #[inline] pubfn is_auto(&self) -> bool { self.direction == OffsetRotateDirection::Auto && self.angle.is_zero()
}
}
impl Parse for OffsetRotate { fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { let location = input.current_source_location(); letmut direction = input.try_parse(OffsetRotateDirection::parse); let angle = input.try_parse(|i| Angle::parse(context, i)); if direction.is_err() { // The direction and angle could be any order, so give it a change to parse // direction again.
direction = input.try_parse(OffsetRotateDirection::parse);
}
if direction.is_err() && angle.is_err() { return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.