/* 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/. */
//! This module contains shared types and messages for use by devtools/script. //! The traits are here instead of in script so that the devtools crate can be //! modified independently of the rest of Servo.
use cssparser::{CowRcStr, Token}; use selectors::parser::SelectorParseErrorKind; #[cfg(feature = "servo")] use servo_atoms::Atom;
/// One hardware pixel. /// /// This unit corresponds to the smallest addressable element of the display hardware. #[derive(Clone, Copy, Debug)] pubenum DevicePixel {}
/// Represents a mobile style pinch zoom factor. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize, MallocSizeOf))] pubstruct PinchZoomFactor(f32);
impl PinchZoomFactor { /// Construct a new pinch zoom factor. pubfn new(scale: f32) -> PinchZoomFactor {
PinchZoomFactor(scale)
}
/// Get the pinch zoom factor as an untyped float. pubfn get(&self) -> f32 { self.0
}
}
/// One CSS "px" in the coordinate system of the "initial viewport": /// <http://www.w3.org/TR/css-device-adapt/#initial-viewport> /// /// `CSSPixel` is equal to `DeviceIndependentPixel` times a "page zoom" factor controlled by the user. This is /// the desktop-style "full page" zoom that enlarges content but then reflows the layout viewport /// so it still exactly fits the visible area. /// /// At the default zoom level of 100%, one `CSSPixel` is equal to one `DeviceIndependentPixel`. However, if the /// document is zoomed in or out then this scale may be larger or smaller. #[derive(Clone, Copy, Debug)] pubenum CSSPixel {}
// In summary, the hierarchy of pixel units and the factors to convert from one to the next: // // DevicePixel // / hidpi_ratio => DeviceIndependentPixel // / desktop_zoom => CSSPixel
/// The error type for all CSS parsing routines. pubtype ParseError<'i> = cssparser::ParseError<'i, StyleParseErrorKind<'i>>;
/// Error in property value parsing pubtype ValueParseError<'i> = cssparser::ParseError<'i, ValueParseErrorKind<'i>>;
#[derive(Clone, Debug, PartialEq)] /// Errors that can be encountered while parsing CSS values. pubenum StyleParseErrorKind<'i> { /// A bad URL token in a DVB.
BadUrlInDeclarationValueBlock(CowRcStr<'i>), /// A bad string token in a DVB.
BadStringInDeclarationValueBlock(CowRcStr<'i>), /// Unexpected closing parenthesis in a DVB.
UnbalancedCloseParenthesisInDeclarationValueBlock, /// Unexpected closing bracket in a DVB.
UnbalancedCloseSquareBracketInDeclarationValueBlock, /// Unexpected closing curly bracket in a DVB.
UnbalancedCloseCurlyBracketInDeclarationValueBlock, /// A property declaration value had input remaining after successfully parsing.
PropertyDeclarationValueNotExhausted, /// An unexpected dimension token was encountered.
UnexpectedDimension(CowRcStr<'i>), /// Missing or invalid media feature name.
MediaQueryExpectedFeatureName(CowRcStr<'i>), /// Missing or invalid media feature value.
MediaQueryExpectedFeatureValue, /// A media feature range operator was not expected.
MediaQueryUnexpectedOperator, /// min- or max- properties must have a value.
RangedExpressionWithNoValue, /// A function was encountered that was not expected.
UnexpectedFunction(CowRcStr<'i>), /// Error encountered parsing a @property's `syntax` descriptor
PropertySyntaxField(PropertySyntaxParseError), /// Error encountered parsing a @property's `inherits` descriptor. /// /// TODO(zrhoffman, bug 1920365): Include the custom property name in error messages.
PropertyInheritsField(PropertyInheritsParseError), /// @namespace must be before any rule but @charset and @import
UnexpectedNamespaceRule, /// @import must be before any rule but @charset
UnexpectedImportRule, /// @import rules are disallowed in the parser.
DisallowedImportRule, /// Unexpected @charset rule encountered.
UnexpectedCharsetRule, /// The @property `<custom-property-name>` must start with `--`
UnexpectedIdent(CowRcStr<'i>), /// A placeholder for many sources of errors that require more specific variants.
UnspecifiedError, /// An unexpected token was found within a namespace rule.
UnexpectedTokenWithinNamespace(Token<'i>), /// An error was encountered while parsing a property value.
ValueError(ValueParseErrorKind<'i>), /// An error was encountered while parsing a selector
SelectorError(SelectorParseErrorKind<'i>), /// The property declaration was for an unknown property.
UnknownProperty(CowRcStr<'i>), /// The property declaration was for a disabled experimental property.
ExperimentalProperty, /// The property declaration contained an invalid color value.
InvalidColor(CowRcStr<'i>, Token<'i>), /// The property declaration contained an invalid filter value.
InvalidFilter(CowRcStr<'i>, Token<'i>), /// The property declaration contained an invalid value.
OtherInvalidValue(CowRcStr<'i>), /// `!important` declarations are disallowed in `@position-try` or keyframes.
UnexpectedImportantDeclaration,
}
/// Specific errors that can be encountered while parsing property values. #[derive(Clone, Debug, PartialEq)] pubenum ValueParseErrorKind<'i> { /// An invalid token was encountered while parsing a color value.
InvalidColor(Token<'i>), /// An invalid filter value was encountered.
InvalidFilter(Token<'i>),
}
impl<'i> StyleParseErrorKind<'i> { /// Create an InvalidValue parse error pubfn new_invalid<S>(name: S, value_error: ParseError<'i>) -> ParseError<'i> where
S: Into<CowRcStr<'i>>,
{ let name = name.into(); let variant = match value_error.kind {
cssparser::ParseErrorKind::Custom(StyleParseErrorKind::ValueError(e)) => match e {
ValueParseErrorKind::InvalidColor(token) => {
StyleParseErrorKind::InvalidColor(name, token)
},
ValueParseErrorKind::InvalidFilter(token) => {
StyleParseErrorKind::InvalidFilter(name, token)
},
},
_ => StyleParseErrorKind::OtherInvalidValue(name),
};
cssparser::ParseError {
kind: cssparser::ParseErrorKind::Custom(variant),
location: value_error.location,
}
}
}
/// Errors that can be encountered while parsing the @property rule's inherits descriptor. #[derive(Clone, Debug, PartialEq)] pubenum PropertyInheritsParseError { /// The inherits descriptor is required for the @property rule to be valid; if it’s missing, /// the @property rule is invalid. /// /// <https://drafts.css-houdini.org/css-properties-values-api-1/#ref-for-descdef-property-inherits②>
NoInherits,
/// The inherits descriptor must successfully parse as `true` or `false`.
InvalidInherits,
}
impl ParsingMode { /// Whether the parsing mode allows unitless lengths for non-zero values to be intpreted as px. #[inline] pubfn allows_unitless_lengths(&self) -> bool { self.intersects(ParsingMode::ALLOW_UNITLESS_LENGTH)
}
/// Whether the parsing mode allows all numeric values. #[inline] pubfn allows_all_numeric_values(&self) -> bool { self.intersects(ParsingMode::ALLOW_ALL_NUMERIC_VALUES)
}
/// Whether the parsing mode allows units or functions that are not computationally independent. #[inline] pubfn allows_computational_dependence(&self) -> bool {
!self.intersects(ParsingMode::DISALLOW_COMPUTATIONALLY_DEPENDENT)
}
}
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.