This commit is contained in:
Emilio Cobos Álvarez 2021-02-26 11:43:25 +01:00
parent c4ad61faa5
commit 80dae5bc59
28 changed files with 145 additions and 107 deletions

View file

@ -107,7 +107,12 @@ fn eval_aspect_ratio(
query_value: Option<Ratio>,
range_or_operator: Option<RangeOrOperator>,
) -> bool {
eval_aspect_ratio_for(device, query_value, range_or_operator, Device::au_viewport_size)
eval_aspect_ratio_for(
device,
query_value,
range_or_operator,
Device::au_viewport_size,
)
}
/// https://drafts.csswg.org/mediaqueries-4/#device-aspect-ratio
@ -244,7 +249,8 @@ fn eval_monochrome(
range_or_operator: Option<RangeOrOperator>,
) -> bool {
// For color devices we should return 0.
let depth = unsafe { bindings::Gecko_MediaFeatures_GetMonochromeBitsPerPixel(device.document()) };
let depth =
unsafe { bindings::Gecko_MediaFeatures_GetMonochromeBitsPerPixel(device.document()) };
RangeOrOperator::evaluate(range_or_operator, query_value, depth)
}

View file

@ -4,12 +4,12 @@
//! Gecko's media-query device and expression representation.
use crate::context::QuirksMode;
use crate::custom_properties::CssEnvironment;
use crate::gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
use crate::gecko_bindings::bindings;
use crate::gecko_bindings::structs;
use crate::media_queries::MediaType;
use crate::context::QuirksMode;
use crate::properties::ComputedValues;
use crate::string_cache::Atom;
use crate::values::computed::Length;
@ -20,8 +20,8 @@ use cssparser::RGBA;
use euclid::default::Size2D;
use euclid::{Scale, SideOffsets2D};
use servo_arc::Arc;
use std::{cmp, fmt};
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering};
use std::{cmp, fmt};
use style_traits::viewport::ViewportConstraints;
use style_traits::{CSSPixel, DevicePixel};
@ -275,7 +275,7 @@ impl Device {
};
if pc.mIsRootPaginatedDocument() != 0 {
return self.page_size_minus_default_margin(pc)
return self.page_size_minus_default_margin(pc);
}
let size = &pc.mSizeForViewportUnits;

View file

@ -184,12 +184,13 @@ impl NonTSPseudoClass {
/// revalidation.
pub fn needs_cache_revalidation(&self) -> bool {
self.state_flag().is_empty() &&
!matches!(*self,
// :dir() depends on state only, but doesn't use state_flag
// because its semantics don't quite match. Nevertheless, it
// doesn't need cache revalidation, because we already compare
// states for elements and candidates.
NonTSPseudoClass::Dir(_) |
!matches!(
*self,
// :dir() depends on state only, but doesn't use state_flag
// because its semantics don't quite match. Nevertheless, it
// doesn't need cache revalidation, because we already compare
// states for elements and candidates.
NonTSPseudoClass::Dir(_) |
// :-moz-is-html only depends on the state of the document and
// the namespace of the element; the former is invariant
// across all the elements involved and the latter is already

View file

@ -52,7 +52,7 @@ unsafe fn get_class_or_part_from_attr(attr: &structs::nsAttrValue) -> Class {
.mAtomArray
.as_ref();
let array = array as *const structs::nsTArray<structs::RefPtr<nsAtom>>;
return Class::More(&**array)
return Class::More(&**array);
}
debug_assert_eq!(base_type, structs::nsAttrValue_ValueBaseType_eStringBase);
Class::None

View file

@ -109,7 +109,11 @@ impl CssUrlData {
/// Returns true if this URL looks like a fragment.
/// See https://drafts.csswg.org/css-values/#local-urls
pub fn is_fragment(&self) -> bool {
self.as_str().as_bytes().iter().next().map_or(false, |b| *b == b'#')
self.as_str()
.as_bytes()
.iter()
.next()
.map_or(false, |b| *b == b'#')
}
/// Return the unresolved url as string, or the empty string if it's
@ -291,9 +295,7 @@ impl SpecifiedImageUrl {
cors_mode: CorsMode,
) -> Result<Self, ParseError<'i>> {
Ok(SpecifiedImageUrl(SpecifiedUrl::parse_with_cors_mode(
context,
input,
cors_mode,
context, input, cors_mode,
)?))
}
}

View file

@ -188,7 +188,7 @@ where
impl<T> Parse for Box<T>
where
T: Parse
T: Parse,
{
fn parse<'i, 't>(
context: &ParserContext,

View file

@ -75,7 +75,8 @@ impl<'a> SelectorParser<'a> {
/// Whether we're parsing selectors in a stylesheet that has chrome
/// privilege.
pub fn chrome_rules_enabled(&self) -> bool {
self.url_data.map_or(false, |d| d.chrome_rules_enabled()) || self.stylesheet_origin == Origin::User
self.url_data.map_or(false, |d| d.chrome_rules_enabled()) ||
self.stylesheet_origin == Origin::User
}
}

View file

@ -169,14 +169,14 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// NOTE: If this or the pointer-events tweak is removed, then
/// minimal-xul.css and the scrollbar style caching need to be tweaked.
fn adjust_for_inert(&mut self) {
use crate::values::specified::ui::CursorKind;
use crate::values::specified::ui::UserSelect;
use properties::longhands::_moz_inert::computed_value::T as Inert;
use properties::longhands::_moz_user_focus::computed_value::T as UserFocus;
use properties::longhands::_moz_user_input::computed_value::T as UserInput;
use properties::longhands::_moz_user_modify::computed_value::T as UserModify;
use properties::longhands::pointer_events::computed_value::T as PointerEvents;
use properties::longhands::cursor::computed_value::T as Cursor;
use crate::values::specified::ui::CursorKind;
use crate::values::specified::ui::UserSelect;
use properties::longhands::pointer_events::computed_value::T as PointerEvents;
let needs_update = {
let ui = self.style.get_inherited_ui();

View file

@ -139,13 +139,17 @@ fn eager_pseudo_is_definitely_not_generated(
return false;
}
if !style.flags.intersects(ComputedValueFlags::DISPLAY_DEPENDS_ON_INHERITED_STYLE) &&
if !style
.flags
.intersects(ComputedValueFlags::DISPLAY_DEPENDS_ON_INHERITED_STYLE) &&
style.get_box().clone_display() == Display::None
{
return true;
}
if !style.flags.intersects(ComputedValueFlags::CONTENT_DEPENDS_ON_INHERITED_STYLE) &&
if !style
.flags
.intersects(ComputedValueFlags::CONTENT_DEPENDS_ON_INHERITED_STYLE) &&
style.ineffective_content_property()
{
return true;

View file

@ -5,11 +5,13 @@
//! A centralized set of stylesheets for a document.
use crate::dom::TElement;
use crate::invalidation::stylesheets::{StylesheetInvalidationSet, RuleChangeKind};
use crate::invalidation::stylesheets::{RuleChangeKind, StylesheetInvalidationSet};
use crate::media_queries::Device;
use crate::selector_parser::SnapshotMap;
use crate::shared_lock::SharedRwLockReadGuard;
use crate::stylesheets::{CssRule, Origin, OriginSet, OriginSetIterator, PerOrigin, StylesheetInDocument};
use crate::stylesheets::{
CssRule, Origin, OriginSet, OriginSetIterator, PerOrigin, StylesheetInDocument,
};
use std::{mem, slice};
/// Entry for a StylesheetSet.
@ -465,9 +467,9 @@ macro_rules! sheet_set_methods {
// Insertion / Removals need to rebuild both the cascade and
// invalidation data. For generic changes this is conservative,
// could be optimized on a per-case basis.
RuleChangeKind::Generic |
RuleChangeKind::Insertion |
RuleChangeKind::Removal => DataValidity::FullyInvalid,
RuleChangeKind::Generic | RuleChangeKind::Insertion | RuleChangeKind::Removal => {
DataValidity::FullyInvalid
},
// TODO(emilio): This, in theory, doesn't need to invalidate
// style data, if the rule we're modifying is actually in the
// CascadeData already.
@ -536,9 +538,9 @@ where
/// Returns whether the given set has changed from the last flush.
pub fn has_changed(&self) -> bool {
!self.invalidations.is_empty() ||
self.collections
.iter_origins()
.any(|(collection, _)| collection.dirty)
self.collections
.iter_origins()
.any(|(collection, _)| collection.dirty)
}
/// Flush the current set, unmarking it as dirty, and returns a

View file

@ -206,8 +206,12 @@ impl DocumentMatchingFunction {
DocumentMatchingFunction::MediaDocument(_) => {
GeckoDocumentMatchingFunction::MediaDocument
},
DocumentMatchingFunction::PlainTextDocument(..) => GeckoDocumentMatchingFunction::PlainTextDocument,
DocumentMatchingFunction::UnobservableDocument(..) => GeckoDocumentMatchingFunction::UnobservableDocument,
DocumentMatchingFunction::PlainTextDocument(..) => {
GeckoDocumentMatchingFunction::PlainTextDocument
},
DocumentMatchingFunction::UnobservableDocument(..) => {
GeckoDocumentMatchingFunction::UnobservableDocument
},
};
let pattern = nsCStr::from(match *self {

View file

@ -20,7 +20,7 @@ use crate::values::serialize_atom_identifier;
use crate::Atom;
use cssparser::{AtRuleParser, AtRuleType, BasicParseErrorKind, CowRcStr};
use cssparser::{DeclarationListParser, DeclarationParser, Parser};
use cssparser::{QualifiedRuleParser, RuleListParser, SourceLocation, ParserState, Token};
use cssparser::{ParserState, QualifiedRuleParser, RuleListParser, SourceLocation, Token};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};

View file

@ -17,7 +17,9 @@ use crate::str::CssStringWriter;
use crate::stylesheets::rule_parser::VendorPrefix;
use crate::stylesheets::{CssRuleType, StylesheetContents};
use crate::values::{serialize_percentage, KeyframesName};
use cssparser::{parse_one_rule, DeclarationListParser, DeclarationParser, ParserState, SourceLocation, Token};
use cssparser::{
parse_one_rule, DeclarationListParser, DeclarationParser, ParserState, SourceLocation, Token,
};
use cssparser::{AtRuleParser, CowRcStr, Parser, ParserInput, QualifiedRuleParser, RuleListParser};
use servo_arc::Arc;
use std::fmt::{self, Write};

View file

@ -57,7 +57,9 @@ pub use self::page_rule::PageRule;
pub use self::rule_list::{CssRules, CssRulesHelpers};
pub use self::rule_parser::{InsertRuleContext, State, TopLevelRuleParser};
pub use self::rules_iterator::{AllRules, EffectiveRules};
pub use self::rules_iterator::{NestedRuleIterationCondition, EffectiveRulesIterator, RulesIterator};
pub use self::rules_iterator::{
EffectiveRulesIterator, NestedRuleIterationCondition, RulesIterator,
};
pub use self::style_rule::StyleRule;
pub use self::stylesheet::{AllowImportRules, SanitizationData, SanitizationKind};
pub use self::stylesheet::{DocumentStyleSheet, Namespaces, Stylesheet};

View file

@ -27,7 +27,7 @@ use crate::values::computed::font::FamilyName;
use crate::values::{CssUrl, CustomIdent, KeyframesName};
use crate::{Namespace, Prefix};
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
use cssparser::{BasicParseError, BasicParseErrorKind, CowRcStr, SourcePosition, ParserState};
use cssparser::{BasicParseError, BasicParseErrorKind, CowRcStr, ParserState, SourcePosition};
use selectors::SelectorList;
use servo_arc::Arc;
use style_traits::{ParseError, StyleParseErrorKind};
@ -482,7 +482,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
);
Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap(
FontFeatureValuesRule::parse(&context, input, family_names, start.source_location()),
FontFeatureValuesRule::parse(
&context,
input,
family_names,
start.source_location(),
),
))))
},
AtRuleBlockPrelude::CounterStyle(name) => {
@ -492,9 +497,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
self.namespaces,
);
Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap(
parse_counter_style_body(name, &context, input, start.source_location())?.into(),
))))
Ok(CssRule::CounterStyle(Arc::new(
self.shared_lock.wrap(
parse_counter_style_body(name, &context, input, start.source_location())?
.into(),
),
)))
},
AtRuleBlockPrelude::Media(media_queries) => {
Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {

View file

@ -130,7 +130,13 @@ where
};
let mut effective = true;
let children = children_of_rule::<C>(rule, self.device, self.quirks_mode, self.guard, &mut effective);
let children = children_of_rule::<C>(
rule,
self.device,
self.quirks_mode,
self.guard,
&mut effective,
);
if !effective {
continue;
}
@ -197,7 +203,7 @@ impl EffectiveRules {
) -> bool {
match *rule {
CssRule::Import(ref import_rule) => {
let import_rule = import_rule.read_with(guard);
let import_rule = import_rule.read_with(guard);
Self::process_import(guard, device, quirks_mode, import_rule)
},
CssRule::Document(ref doc_rule) => {

View file

@ -243,7 +243,12 @@ pub trait StylesheetInDocument: ::std::fmt::Debug {
where
C: NestedRuleIterationCondition,
{
RulesIterator::new(device, self.quirks_mode(guard), guard, self.rules(guard).iter())
RulesIterator::new(
device,
self.quirks_mode(guard),
guard,
self.rules(guard).iter(),
)
}
/// Returns whether the style-sheet applies for the current device.

View file

@ -16,8 +16,8 @@ use crate::properties::StyleBuilder;
use crate::rule_cache::RuleCacheConditions;
use crate::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard};
use crate::str::CssStringWriter;
use crate::stylesheets::{Origin, StylesheetInDocument};
use crate::stylesheets::cascading_at_rule::DescriptorDeclaration;
use crate::stylesheets::{Origin, StylesheetInDocument};
use crate::values::computed::{Context, ToComputedValue};
use crate::values::generics::length::LengthPercentageOrAuto;
use crate::values::generics::NonNegative;

View file

@ -11,9 +11,9 @@ use crate::values::generics::box_::Perspective as GenericPerspective;
use crate::values::generics::box_::VerticalAlign as GenericVerticalAlign;
use crate::values::specified::box_ as specified;
pub use crate::values::specified::box_::Clear as SpecifiedClear;
pub use crate::values::specified::box_::{AnimationName, Appearance, BreakBetween, BreakWithin};
pub use crate::values::specified::box_::{Clear as SpecifiedClear};
pub use crate::values::specified::box_::{Float as SpecifiedFloat, Contain, Display, Overflow};
pub use crate::values::specified::box_::{Contain, Display, Float as SpecifiedFloat, Overflow};
pub use crate::values::specified::box_::{OverflowAnchor, OverflowClipBox, OverscrollBehavior};
pub use crate::values::specified::box_::{
ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStrictness, ScrollSnapType,

View file

@ -35,9 +35,9 @@ use style_traits::{CssWriter, ParseError, ToCss};
use to_shmem::{self, SharedMemoryBuilder, ToShmem};
pub use crate::values::computed::Length as MozScriptMinSize;
pub use crate::values::specified::Integer as SpecifiedInteger;
pub use crate::values::specified::font::{FontSynthesis, MozScriptSizeMultiplier};
pub use crate::values::specified::font::{XLang, XTextZoom};
pub use crate::values::specified::Integer as SpecifiedInteger;
/// A value for the font-weight property per:
///

View file

@ -7,15 +7,15 @@
//!
//! [image]: https://drafts.csswg.org/css-images/#image-values
use crate::values::computed::position::Position;
use crate::values::computed::percentage::Percentage;
use crate::values::computed::position::Position;
use crate::values::computed::url::ComputedImageUrl;
#[cfg(feature = "gecko")]
use crate::values::computed::NumberOrPercentage;
use crate::values::computed::{Angle, Color, Context};
use crate::values::computed::{
AngleOrPercentage, LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage,
ToComputedValue, Resolution,
Resolution, ToComputedValue,
};
use crate::values::generics::image::{self as generic, GradientCompatMode};
use crate::values::specified::image as specified;
@ -26,7 +26,8 @@ use style_traits::{CssWriter, ToCss};
/// Computed values for an image according to CSS-IMAGES.
/// <https://drafts.csswg.org/css-images/#image-values>
pub type Image = generic::GenericImage<Gradient, MozImageRect, ComputedImageUrl, Color, Percentage, Resolution>;
pub type Image =
generic::GenericImage<Gradient, MozImageRect, ComputedImageUrl, Color, Percentage, Resolution>;
/// Computed values for a CSS gradient.
/// <https://drafts.csswg.org/css-images/#gradients>
@ -116,7 +117,6 @@ impl ToComputedValue for specified::ImageSet {
}
}
/// Computed values for `-moz-image-rect(...)`.
#[cfg(feature = "gecko")]
pub type MozImageRect = generic::GenericMozImageRect<NumberOrPercentage, ComputedImageUrl>;

View file

@ -265,9 +265,9 @@ impl LengthPercentage {
CalcLengthPercentageLeaf::Length(l) => {
Self::new_length(Length::new(clamping_mode.clamp(l.px())).normalized())
},
CalcLengthPercentageLeaf::Percentage(p) => {
Self::new_percent(Percentage(clamping_mode.clamp(crate::values::normalize(p.0))))
},
CalcLengthPercentageLeaf::Percentage(p) => Self::new_percent(Percentage(
clamping_mode.clamp(crate::values::normalize(p.0)),
)),
}
},
_ => Self::new_calc_unchecked(Box::new(CalcLengthPercentage {

View file

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

View file

@ -59,10 +59,10 @@ pub enum GenericImage<G, MozImageRect, ImageUrl, Color, Percentage, Resolution>
pub use self::GenericImage as Image;
/// <https://drafts.csswg.org/css-images-4/#cross-fade-function>
#[css(comma, function = "cross-fade")]
#[derive(
Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem, ToCss, ToComputedValue,
)]
#[css(comma, function = "cross-fade")]
#[repr(C)]
pub struct GenericCrossFade<Image, Color, Percentage> {
/// All of the image percent pairings passed as arguments to
@ -74,14 +74,7 @@ pub struct GenericCrossFade<Image, Color, Percentage> {
/// A `<percent> | none` value. Represents optional percentage values
/// assosicated with cross-fade images.
#[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
ToComputedValue,
ToResolvedValue,
ToShmem,
ToCss,
Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, ToCss,
)]
#[repr(C, u8)]
pub enum PercentOrNone<Percentage> {
@ -94,14 +87,7 @@ pub enum PercentOrNone<Percentage> {
/// An optional percent and a cross fade image.
#[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
ToComputedValue,
ToResolvedValue,
ToShmem,
ToCss,
Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, ToCss,
)]
#[repr(C)]
pub struct GenericCrossFadeElement<Image, Color, Percentage> {
@ -115,15 +101,7 @@ pub struct GenericCrossFadeElement<Image, Color, Percentage> {
/// An image or a color. `cross-fade` takes either when blending
/// images together.
#[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
ToComputedValue,
ToResolvedValue,
ToShmem,
ToCss,
Parse,
Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, ToCss,
)]
#[repr(C, u8)]
pub enum GenericCrossFadeImage<I, C> {
@ -139,10 +117,8 @@ pub use self::GenericCrossFadeElement as CrossFadeElement;
pub use self::GenericCrossFadeImage as CrossFadeImage;
/// https://drafts.csswg.org/css-images-4/#image-set-notation
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem, ToCss)]
#[css(comma, function = "image-set")]
#[derive(
Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem, ToCss,
)]
#[repr(C)]
pub struct GenericImageSet<Image, Resolution> {
/// The index of the selected candidate. Zero for specified values.

View file

@ -496,9 +496,7 @@ where
let t = t.to_pixel_length(reference_height)? as f64;
Transform3D::translation(0., t, 0.)
},
TranslateZ(ref z) => {
Transform3D::translation(0., 0., z.to_pixel_length(None)? as f64)
},
TranslateZ(ref z) => Transform3D::translation(0., 0., z.to_pixel_length(None)? as f64),
Skew(theta_x, theta_y) => Transform3D::skew(
euclid::Angle::radians(theta_x.radians64()),
euclid::Angle::radians(theta_y.radians64()),

View file

@ -2325,14 +2325,18 @@ impl Parse for MathDepth {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<MathDepth, ParseError<'i>> {
if input.try_parse(|i| i.expect_ident_matching("auto-add")).is_ok() {
if input
.try_parse(|i| i.expect_ident_matching("auto-add"))
.is_ok()
{
return Ok(MathDepth::AutoAdd);
}
if let Ok(math_depth_value) = input.try_parse(|input| Integer::parse(context, input)) {
return Ok(MathDepth::Absolute(math_depth_value));
}
input.expect_function_matching("add")?;
let math_depth_delta_value = input.parse_nested_block(|input| Integer::parse(context, input))?;
let math_depth_delta_value =
input.parse_nested_block(|input| Integer::parse(context, input))?;
Ok(MathDepth::Add(math_depth_delta_value))
}
}

View file

@ -21,7 +21,7 @@ use crate::values::specified::position::{Position, PositionComponent, Side};
use crate::values::specified::url::SpecifiedImageUrl;
use crate::values::specified::{
Angle, AngleOrPercentage, Color, Length, LengthPercentage, NonNegativeLength,
NonNegativeLengthPercentage, Resolution
NonNegativeLengthPercentage, Resolution,
};
use crate::values::specified::{Number, NumberOrPercentage, Percentage};
use crate::Atom;
@ -36,7 +36,8 @@ use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};
/// Specified values for an image according to CSS-IMAGES.
/// <https://drafts.csswg.org/css-images/#image-values>
pub type Image = generic::Image<Gradient, MozImageRect, SpecifiedImageUrl, Color, Percentage, Resolution>;
pub type Image =
generic::Image<Gradient, MozImageRect, SpecifiedImageUrl, Color, Percentage, Resolution>;
/// Specified values for a CSS gradient.
/// <https://drafts.csswg.org/css-images/#gradients>
@ -194,7 +195,9 @@ impl Image {
if allow_none && input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(generic::Image::None);
}
if let Ok(url) = input.try_parse(|input| SpecifiedImageUrl::parse_with_cors_mode(context, input, cors_mode)) {
if let Ok(url) = input
.try_parse(|input| SpecifiedImageUrl::parse_with_cors_mode(context, input, cors_mode))
{
return Ok(generic::Image::Url(url));
}
if let Ok(gradient) = input.try_parse(|i| Gradient::parse(context, i)) {
@ -218,7 +221,9 @@ impl Image {
}
#[cfg(feature = "gecko")]
{
if let Ok(image_rect) = input.try_parse(|input| MozImageRect::parse(context, input, cors_mode)) {
if let Ok(image_rect) =
input.try_parse(|input| MozImageRect::parse(context, input, cors_mode))
{
return Ok(generic::Image::Rect(Box::new(image_rect)));
}
Ok(generic::Image::Element(Image::parse_element(input)?))
@ -254,7 +259,12 @@ impl Image {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Image, ParseError<'i>> {
Self::parse_with_cors_mode(context, input, CorsMode::Anonymous, /* allow_none = */ true)
Self::parse_with_cors_mode(
context,
input,
CorsMode::Anonymous,
/* allow_none = */ true,
)
}
}
@ -299,8 +309,10 @@ impl CrossFadeImage {
input: &mut Parser<'i, 't>,
cors_mode: CorsMode,
) -> Result<Self, ParseError<'i>> {
if let Ok(image) = input.try_parse(|input| Image::parse_with_cors_mode(context, input, cors_mode, /* allow_none = */ false)) {
return Ok(Self::Image(image))
if let Ok(image) = input.try_parse(|input| {
Image::parse_with_cors_mode(context, input, cors_mode, /* allow_none = */ false)
}) {
return Ok(Self::Image(image));
}
Ok(Self::Color(Color::parse(context, input)?))
}
@ -334,7 +346,7 @@ impl ImageSet {
})?;
Ok(Self {
selected_index: 0,
items: items.into()
items: items.into(),
})
}
}
@ -346,14 +358,19 @@ impl ImageSetItem {
cors_mode: CorsMode,
) -> Result<Self, ParseError<'i>> {
let image = match input.try_parse(|i| i.expect_url_or_string()) {
Ok(url) => Image::Url(SpecifiedImageUrl::parse_from_string(url.as_ref().into(), context, cors_mode)),
Err(..) => Image::parse_with_cors_mode(context, input, cors_mode, /* allow_none = */ false)?,
Ok(url) => Image::Url(SpecifiedImageUrl::parse_from_string(
url.as_ref().into(),
context,
cors_mode,
)),
Err(..) => Image::parse_with_cors_mode(
context, input, cors_mode, /* allow_none = */ false,
)?,
};
let resolution = input.try_parse(|input| Resolution::parse(context, input)).unwrap_or(Resolution::X(1.0));
Ok(Self {
image,
resolution,
})
let resolution = input
.try_parse(|input| Resolution::parse(context, input))
.unwrap_or(Resolution::X(1.0));
Ok(Self { image, resolution })
}
}

View file

@ -70,7 +70,7 @@ pub use self::list::MozListReversed;
pub use self::list::Quotes;
pub use self::motion::{OffsetPath, OffsetRotate};
pub use self::outline::OutlineStyle;
pub use self::page::{Orientation, PaperSize, PageSize};
pub use self::page::{Orientation, PageSize, PaperSize};
pub use self::percentage::Percentage;
pub use self::position::AspectRatio;
pub use self::position::{
@ -122,8 +122,8 @@ pub mod length;
pub mod list;
pub mod motion;
pub mod outline;
pub mod percentage;
pub mod page;
pub mod percentage;
pub mod position;
pub mod ratio;
pub mod rect;