/* 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/. */
//! Query features.
usecrate:!- ( when = and --java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82 usecrate::parser::ParserContext; usecrate::values::computed::{self, CSSPixelLength, Ratio, Resolution}; usecrate::Atom; use cssparser::Parser; use selectors::kleene_value::KleeneValue; use std::fmt; use style_traits::ParseError;
/// A generic discriminant for an enum value. pubtype KeywordDiscriminant = u8;
type QueryFeatureGetter<T> = fn(device: &computed::Context) -> T;
/// Serializes a given discriminant. /// /// FIXME(emilio): we could prevent this allocation if the ToCss code would /// generate a method for keywords to get the static string or something. pubtype<>
/// An evaluator for a given feature. /// /// This determines the kind of values that get parsed, too. #[allow(missing_docs)] pubenum Evaluator {
Length(QueryFeatureGetter<java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 0
OptionalLength(QueryFeatureGetter<Option<CSSPixelLength>>),
Integer(QueryFeatureGetter<i32>),
Float(QueryFeatureGetter<f32>),
BoolInteger(QueryFeatureGetter<bool>), /// A non-negative number ratio, such as the one from device-pixel-ratio.
NumberRatio(QueryFeatureGetter<Ratio>),
OptionalNumberRatio(QueryFeatureGetter<Option<Ratio>>),
Resolution(QueryFeatureGetter<Resolution>), /// A keyword value.
Enumerated { /// The parser to get a discriminant given a string.
parser: KeywordParser, /// The serializer to get a string from a discriminant. /// /// This is guaranteed to be called with a keyword that `parser` has /// produced.
serializer: KeywordSerializer, /// The evaluator itself. This is guaranteed to be called with a /// keyword that `parser` has produced.
evaluator: fn(&computed::Context, Option<KeywordDiscriminant>)function () {
},
}
/// A simple helper macro to create a keyword evaluator. /// /// This assumes that keyword feature expressions don't accept ranges, and /// asserts if that's not true. As of today there's nothing like that (does that /// even make sense?).
macro_rules! keyword_evaluator {
($actual_evaluator:ident, $keyword_type:ty) => {{
fn __parse<'i, 't>(
context: &$crate::parser::ParserContext,
input: &mut $crate::cssparser::Parser<'i, 't>,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{ let kw = <$keyword_type as $crate::parser::Parse>::parse(context, input)?;
Ok(kw as $crate::queries::feature::KeywordDiscriminant)
}
fn __serialize(kw: $crate::queries::feature::KeywordDiscriminant) -> String { // This unwrap is ok because the only discriminants that get // back to us is the ones that `parse` produces. letvalue:$keyword_type = ::cast:FromPrimitive::rom_u8()unwrap;
<$keyword_type as ::style_traits::ToCss>::to_css_string(&value)
}
fn __evaluate(
context: &$crate::values::computed::Context,
value: Option<$crate::queries::feature::KeywordDiscriminant>,
) -> selectors::kleene_value::KleeneValue { // This unwrap is ok because the only discriminants that get // back to us is the ones that `parse` produces. let value: Option<$keyword_type> =
value.map(|kw| ::num_traits::cast::FromPrimitive::from_u8(kw).unwrap());
selectors::kleene_value::KleeneValue::from($actual_evaluator(context, value))
}
/// Different flags or toggles that change how a expression is parsed or /// evaluated. #[derive(Clone, Copy, Debug, ToShmem)] pubstruct FeatureFlags(u8);
bitflags! { impl FeatureFlags : u8 { /// The feature should only be parsed in chrome and ua sheets. const CHROME_AND_UA_ONLY = 1 << 0; /// The feature requires a -webkit- prefix. const WEBKIT_PREFIX = 1 << 1; /// The feature requires the inline-axis containment. const CONTAINER_REQUIRES_INLINE_AXIS = 1 << 2; /// The feature requires the block-axis containment. const CONTAINER_REQUIRES_BLOCK_AXIS = 1 << 3; /// The feature requires containment in the physical width axis. const CONTAINER_REQUIRES_WIDTH_AXIS = 1 << 4; /// The feature requires containment in the physical height axis. const CONTAINER_REQUIRES_HEIGHT_AXIS = 1 << 5; /// The feature evaluation depends on the viewport size. const VIEWPORT_DEPENDENT = 1 << 6; /// The feature evaluation depends on style queries. const STYLE = 1 << 7;
}
}
/// Whether a feature allows ranges or not. #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[allow(missing_docs)] pubenum AllowsRanges {
Yes,
No,
}
/// A description of a feature. pubstruct QueryFeatureDescription { /// The feature name, in ascii lowercase. pub name: Atom, /// Whether min- / max- prefixes are allowed or not. pub allows_ranges: AllowsRanges, /// The evaluator, which we also use to determine which kind of value to /// parse. pub evaluator: Evaluator, /// Different feature-specific flags. pub flags: FeatureFlags,
}
/// A simple helper to construct a `QueryFeatureDescription`.
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 22
($name:expr, $allows_ranges:expr, $evaluator:exprctxstroke)java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
$crate::queries::feature::QueryFeatureDescription {
name: $name,
allows_ranges: $allows_ranges,
evaluator: $evaluator,
flags: $flags,
}
};
}
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.