Run rustfmt on selectors, servo_arc, and style.

This was generated with:

./mach cargo fmt --package selectors &&
./mach cargo fmt --package servo_arc &&
./mach cargo fmt --package style

Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
This commit is contained in:
Bobby Holley 2018-04-10 17:35:15 -07:00
parent f7ae1a37e3
commit c99bcdd4b8
181 changed files with 9981 additions and 7933 deletions

View file

@ -9,7 +9,7 @@
use values::computed::{Context, ToComputedValue};
use values::specified;
pub use super::specified::{AlignContent, JustifyContent, AlignItems, SelfAlignment};
pub use super::specified::{AlignContent, AlignItems, JustifyContent, SelfAlignment};
pub use super::specified::{AlignSelf, JustifySelf};
/// The computed value for the `justify-items` property.
@ -59,18 +59,20 @@ impl ToComputedValue for specified::JustifyItems {
fn to_computed_value(&self, _context: &Context) -> JustifyItems {
use values::specified::align;
let specified = *self;
let computed =
if self.0 != align::AlignFlags::AUTO {
*self
} else {
// If the inherited value of `justify-items` includes the
// `legacy` keyword, `auto` computes to the inherited value,
// but we assume it computes to `normal`, and handle that
// special-case in StyleAdjuster.
Self::normal()
};
let computed = if self.0 != align::AlignFlags::AUTO {
*self
} else {
// If the inherited value of `justify-items` includes the
// `legacy` keyword, `auto` computes to the inherited value,
// but we assume it computes to `normal`, and handle that
// special-case in StyleAdjuster.
Self::normal()
};
JustifyItems { specified, computed }
JustifyItems {
specified,
computed,
}
}
#[inline]

View file

@ -15,8 +15,7 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance};
/// A computed angle.
#[animate(fallback = "Self::animate_fallback")]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Animate, Clone, Copy, Debug, MallocSizeOf)]
#[derive(PartialEq, PartialOrd, ToAnimatedZero, ToCss)]
#[derive(Animate, Clone, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd, ToAnimatedZero, ToCss)]
pub enum Angle {
/// An angle with degree unit.
#[css(dimension)]
@ -103,10 +102,7 @@ impl Zero for Angle {
#[inline]
fn is_zero(&self) -> bool {
match *self {
Angle::Deg(val) |
Angle::Grad(val) |
Angle::Turn(val) |
Angle::Rad(val) => val == 0.
Angle::Deg(val) | Angle::Grad(val) | Angle::Turn(val) | Angle::Rad(val) => val == 0.,
}
}
}
@ -116,6 +112,7 @@ impl ComputeSquaredDistance for Angle {
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
// Use the formula for calculating the distance between angles defined in SVG:
// https://www.w3.org/TR/SVG/animate.html#complexDistances
self.radians64().compute_squared_distance(&other.radians64())
self.radians64()
.compute_squared_distance(&other.radians64())
}
}

View file

@ -32,7 +32,9 @@ impl RepeatableListAnimatable for BackgroundSize {}
impl ToAnimatedZero for BackgroundSize {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
fn to_animated_zero(&self) -> Result<Self, ()> {
Err(())
}
}
impl ToAnimatedValue for BackgroundSize {
@ -54,17 +56,15 @@ impl ToAnimatedValue for BackgroundSize {
LengthOrPercentageOrAuto::Percentage(percent) => {
LengthOrPercentageOrAuto::Percentage(Percentage(percent.0.max(0.)))
},
_ => value
_ => value,
}
};
match animated {
GenericBackgroundSize::Explicit { width, height } => {
GenericBackgroundSize::Explicit {
width: clamp_animated_value(width),
height: clamp_animated_value(height)
}
GenericBackgroundSize::Explicit { width, height } => GenericBackgroundSize::Explicit {
width: clamp_animated_value(width),
height: clamp_animated_value(height),
},
_ => animated
_ => animated,
}
}
}
@ -92,7 +92,10 @@ pub struct BackgroundRepeat(pub BackgroundRepeatKeyword, pub BackgroundRepeatKey
impl BackgroundRepeat {
/// Returns the `repeat repeat` value.
pub fn repeat() -> Self {
BackgroundRepeat(BackgroundRepeatKeyword::Repeat, BackgroundRepeatKeyword::Repeat)
BackgroundRepeat(
BackgroundRepeatKeyword::Repeat,
BackgroundRepeatKeyword::Repeat,
)
}
}
@ -126,15 +129,17 @@ impl ToComputedValue for SpecifiedBackgroundRepeat {
#[inline]
fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
match *self {
SpecifiedBackgroundRepeat::RepeatX => {
BackgroundRepeat(BackgroundRepeatKeyword::Repeat, BackgroundRepeatKeyword::NoRepeat)
}
SpecifiedBackgroundRepeat::RepeatY => {
BackgroundRepeat(BackgroundRepeatKeyword::NoRepeat, BackgroundRepeatKeyword::Repeat)
}
SpecifiedBackgroundRepeat::RepeatX => BackgroundRepeat(
BackgroundRepeatKeyword::Repeat,
BackgroundRepeatKeyword::NoRepeat,
),
SpecifiedBackgroundRepeat::RepeatY => BackgroundRepeat(
BackgroundRepeatKeyword::NoRepeat,
BackgroundRepeatKeyword::Repeat,
),
SpecifiedBackgroundRepeat::Keywords(horizontal, vertical) => {
BackgroundRepeat(horizontal, vertical.unwrap_or(horizontal))
}
},
}
}
@ -145,13 +150,13 @@ impl ToComputedValue for SpecifiedBackgroundRepeat {
match (computed.0, computed.1) {
(BackgroundRepeatKeyword::Repeat, BackgroundRepeatKeyword::NoRepeat) => {
SpecifiedBackgroundRepeat::RepeatX
}
},
(BackgroundRepeatKeyword::NoRepeat, BackgroundRepeatKeyword::Repeat) => {
SpecifiedBackgroundRepeat::RepeatY
}
},
(horizontal, vertical) => {
SpecifiedBackgroundRepeat::Keywords(horizontal, Some(vertical))
}
},
}
}
}

View file

@ -9,7 +9,7 @@
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
use values::computed::{LengthOrPercentage, Image};
use values::computed::{Image, LengthOrPercentage};
use values::computed::url::ComputedUrl;
use values::generics::basic_shape as generic;
@ -20,7 +20,8 @@ pub type ClippingShape = generic::ClippingShape<BasicShape, ComputedUrl>;
pub type FloatAreaShape = generic::FloatAreaShape<BasicShape, Image>;
/// A computed basic shape.
pub type BasicShape = generic::BasicShape<LengthOrPercentage, LengthOrPercentage, LengthOrPercentage>;
pub type BasicShape =
generic::BasicShape<LengthOrPercentage, LengthOrPercentage, LengthOrPercentage>;
/// The computed value of `inset()`
pub type InsetRect = generic::InsetRect<LengthOrPercentage>;

View file

@ -47,7 +47,10 @@ impl BorderImageSideWidth {
impl BorderSpacing {
/// Returns `0 0`.
pub fn zero() -> Self {
GenericBorderSpacing(Size::new(NonNegativeLength::zero(), NonNegativeLength::zero()))
GenericBorderSpacing(Size::new(
NonNegativeLength::zero(),
NonNegativeLength::zero(),
))
}
/// Returns the horizontal spacing.
@ -64,7 +67,10 @@ impl BorderSpacing {
impl BorderCornerRadius {
/// Returns `0 0`.
pub fn zero() -> Self {
GenericBorderCornerRadius(Size::new(LengthOrPercentage::zero(), LengthOrPercentage::zero()))
GenericBorderCornerRadius(Size::new(
LengthOrPercentage::zero(),
LengthOrPercentage::zero(),
))
}
}

View file

@ -10,7 +10,7 @@ use values::generics::box_::AnimationIterationCount as GenericAnimationIteration
use values::generics::box_::Perspective as GenericPerspective;
use values::generics::box_::VerticalAlign as GenericVerticalAlign;
pub use values::specified::box_::{AnimationName, Display, OverflowClipBox, Contain};
pub use values::specified::box_::{AnimationName, Contain, Display, OverflowClipBox};
pub use values::specified::box_::{OverscrollBehavior, ScrollSnapType, TouchAction, WillChange};
/// A computed value for the `vertical-align` property.

View file

@ -138,7 +138,10 @@ impl From<RGBA> for Color {
}
impl ToCss for Color {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
if self.is_numeric() {
self.color.to_css(dest)
} else if self.is_currentcolor() {
@ -185,11 +188,6 @@ impl ToAnimatedValue for RGBA {
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
// RGBA::from_floats clamps each component values.
RGBA::from_floats(
animated.red,
animated.green,
animated.blue,
animated.alpha,
)
RGBA::from_floats(animated.red, animated.green, animated.blue, animated.alpha)
}
}

View file

@ -35,24 +35,23 @@ impl Content {
}
#[cfg(feature = "servo")]
fn parse_counter_style(
input: &mut Parser
) -> ListStyleType {
input.try(|input| {
input.expect_comma()?;
ListStyleType::parse(input)
}).unwrap_or(ListStyleType::Decimal)
fn parse_counter_style(input: &mut Parser) -> ListStyleType {
input
.try(|input| {
input.expect_comma()?;
ListStyleType::parse(input)
})
.unwrap_or(ListStyleType::Decimal)
}
#[cfg(feature = "gecko")]
fn parse_counter_style(
context: &ParserContext,
input: &mut Parser
) -> CounterStyleOrNone {
input.try(|input| {
input.expect_comma()?;
CounterStyleOrNone::parse(context, input)
}).unwrap_or(CounterStyleOrNone::decimal())
fn parse_counter_style(context: &ParserContext, input: &mut Parser) -> CounterStyleOrNone {
input
.try(|input| {
input.expect_comma()?;
CounterStyleOrNone::parse(context, input)
})
.unwrap_or(CounterStyleOrNone::decimal())
}
}
@ -62,23 +61,34 @@ impl Parse for Content {
// TODO: <uri>, attr(<identifier>)
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
if input
.try(|input| input.expect_ident_matching("normal"))
.is_ok()
{
return Ok(Content::Normal);
}
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
if input
.try(|input| input.expect_ident_matching("none"))
.is_ok()
{
return Ok(Content::None);
}
#[cfg(feature = "gecko")] {
if input.try(|input| input.expect_ident_matching("-moz-alt-content")).is_ok() {
#[cfg(feature = "gecko")]
{
if input
.try(|input| input.expect_ident_matching("-moz-alt-content"))
.is_ok()
{
return Ok(Content::MozAltContent);
}
}
let mut content = vec![];
loop {
#[cfg(feature = "gecko")] {
#[cfg(feature = "gecko")]
{
if let Ok(url) = input.try(|i| SpecifiedImageUrl::parse(_context, i)) {
content.push(ContentItem::Url(url));
continue;
@ -87,8 +97,10 @@ impl Parse for Content {
// FIXME: remove clone() when lifetimes are non-lexical
match input.next().map(|t| t.clone()) {
Ok(Token::QuotedString(ref value)) => {
content.push(ContentItem::String(value.as_ref().to_owned().into_boxed_str()));
}
content.push(ContentItem::String(
value.as_ref().to_owned().into_boxed_str(),
));
},
Ok(Token::Function(ref name)) => {
let result = match_ignore_ascii_case! { &name,
"counter" => Some(input.parse_nested_block(|input| {
@ -119,25 +131,25 @@ impl Parse for Content {
};
match result {
Some(result) => content.push(result?),
None => return Err(input.new_custom_error(
StyleParseErrorKind::UnexpectedFunction(name.clone())
))
None => {
return Err(input.new_custom_error(
StyleParseErrorKind::UnexpectedFunction(name.clone()),
))
},
}
}
},
Ok(Token::Ident(ref ident)) => {
content.push(
match_ignore_ascii_case! { &ident,
"open-quote" => ContentItem::OpenQuote,
"close-quote" => ContentItem::CloseQuote,
"no-open-quote" => ContentItem::NoOpenQuote,
"no-close-quote" => ContentItem::NoCloseQuote,
_ => return Err(input.new_custom_error(
SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
}
);
}
content.push(match_ignore_ascii_case! { &ident,
"open-quote" => ContentItem::OpenQuote,
"close-quote" => ContentItem::CloseQuote,
"no-open-quote" => ContentItem::NoOpenQuote,
"no-close-quote" => ContentItem::NoCloseQuote,
_ => return Err(input.new_custom_error(
SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
});
},
Err(_) => break,
Ok(t) => return Err(input.new_unexpected_token_error(t))
Ok(t) => return Err(input.new_unexpected_token_error(t)),
}
}
if content.is_empty() {

View file

@ -7,7 +7,7 @@
use Atom;
use app_units::Au;
use byteorder::{BigEndian, ByteOrder};
use cssparser::{CssStringWriter, Parser, serialize_identifier};
use cssparser::{serialize_identifier, CssStringWriter, Parser};
#[cfg(feature = "gecko")]
use gecko_bindings::{bindings, structs};
#[cfg(feature = "gecko")]
@ -22,14 +22,14 @@ use std::slice;
use style_traits::{CssWriter, ParseError, ToCss};
use values::CSSFloat;
use values::animated::{ToAnimatedValue, ToAnimatedZero};
use values::computed::{Context, NonNegativeLength, ToComputedValue, Integer, Number};
use values::generics::font::{FontSettings, FeatureTagValue};
use values::computed::{Context, Integer, NonNegativeLength, Number, ToComputedValue};
use values::generics::font::{FeatureTagValue, FontSettings};
use values::generics::font::{KeywordInfo as GenericKeywordInfo, VariationValue};
use values::specified::font as specified;
use values::specified::length::{FontBaseSize, NoCalcLength};
pub use values::computed::Length as MozScriptMinSize;
pub use values::specified::font::{XTextZoom, XLang, MozScriptSizeMultiplier, FontSynthesis};
pub use values::specified::font::{FontSynthesis, MozScriptSizeMultiplier, XLang, XTextZoom};
/// As of CSS Fonts Module Level 3, only the following values are
/// valid: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
@ -40,8 +40,8 @@ pub use values::specified::font::{XTextZoom, XLang, MozScriptSizeMultiplier, Fon
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
pub struct FontWeight(pub u16);
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)]
#[derive(PartialEq, ToAnimatedZero, ToCss)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq,
ToAnimatedZero, ToCss)]
/// The computed value of font-size
pub struct FontSize {
/// The size.
@ -120,7 +120,7 @@ impl FontSize {
pub fn medium() -> Self {
Self {
size: Au::from_px(specified::FONT_MEDIUM_PX).into(),
keyword_info: Some(KeywordInfo::medium())
keyword_info: Some(KeywordInfo::medium()),
}
}
@ -130,15 +130,22 @@ impl FontSize {
// If inheriting, we must recompute font-size in case of language
// changes using the font_size_keyword. We also need to do this to
// handle mathml scriptlevel changes
let kw_inherited_size = context.builder.get_parent_font()
.clone_font_size()
.keyword_info.map(|info| {
specified::FontSize::Keyword(info).to_computed_value(context).size
});
let kw_inherited_size = context
.builder
.get_parent_font()
.clone_font_size()
.keyword_info
.map(|info| {
specified::FontSize::Keyword(info)
.to_computed_value(context)
.size
});
let mut font = context.builder.take_font();
font.inherit_font_size_from(context.builder.get_parent_font(),
kw_inherited_size,
context.builder.device);
font.inherit_font_size_from(
context.builder.get_parent_font(),
kw_inherited_size,
context.builder.device,
);
context.builder.put_font(font);
}
@ -153,7 +160,8 @@ impl FontSize {
// compute to the same value and depends on the font
let computed = specified::FontSize::medium().to_computed_value(context);
context.builder.mutate_font().set_font_size(computed);
#[cfg(feature = "gecko")] {
#[cfg(feature = "gecko")]
{
let device = context.builder.device;
context.builder.mutate_font().fixup_font_min_size(device);
}
@ -190,9 +198,9 @@ impl FontFamily {
#[inline]
/// Get default font family as `serif` which is a generic font-family
pub fn serif() -> Self {
FontFamily(
FontFamilyList::new(Box::new([SingleFontFamily::Generic(atom!("serif"))]))
)
FontFamily(FontFamilyList::new(Box::new([
SingleFontFamily::Generic(atom!("serif")),
])))
}
}
@ -202,16 +210,15 @@ impl MallocSizeOf for FontFamily {
// SharedFontList objects are generally shared from the pointer
// stored in the specified value. So only count this if the
// SharedFontList is unshared.
unsafe {
bindings::Gecko_SharedFontList_SizeOfIncludingThisIfUnshared(
(self.0).0.get()
)
}
unsafe { bindings::Gecko_SharedFontList_SizeOfIncludingThisIfUnshared((self.0).0.get()) }
}
}
impl ToCss for FontFamily {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
let mut iter = self.0.iter();
iter.next().unwrap().to_css(dest)?;
for family in iter {
@ -233,13 +240,16 @@ pub struct FamilyName {
}
impl ToCss for FamilyName {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
match self.syntax {
FamilyNameSyntax::Quoted => {
dest.write_char('"')?;
write!(CssStringWriter::new(dest), "{}", self.name)?;
dest.write_char('"')
}
},
FamilyNameSyntax::Identifiers => {
let mut first = true;
for ident in self.name.to_string().split(' ') {
@ -248,13 +258,16 @@ impl ToCss for FamilyName {
} else {
dest.write_char(' ')?;
}
debug_assert!(!ident.is_empty(), "Family name with leading, \
trailing, or consecutive white spaces should \
have been marked quoted by the parser");
debug_assert!(
!ident.is_empty(),
"Family name with leading, \
trailing, or consecutive white spaces should \
have been marked quoted by the parser"
);
serialize_identifier(ident, dest)?;
}
Ok(())
}
},
}
}
}
@ -308,10 +321,8 @@ impl SingleFontFamily {
atom!("sans-serif") |
atom!("cursive") |
atom!("fantasy") |
atom!("monospace") => {
return SingleFontFamily::Generic(input)
}
_ => {}
atom!("monospace") => return SingleFontFamily::Generic(input),
_ => {},
}
match_ignore_ascii_case! { &input,
"serif" => return SingleFontFamily::Generic(atom!("serif")),
@ -336,7 +347,7 @@ impl SingleFontFamily {
return Ok(SingleFontFamily::FamilyName(FamilyName {
name: Atom::from(&*value),
syntax: FamilyNameSyntax::Quoted,
}))
}));
}
let first_ident = input.expect_ident()?.clone();
@ -392,7 +403,7 @@ impl SingleFontFamily {
};
Ok(SingleFontFamily::FamilyName(FamilyName {
name: Atom::from(value),
syntax
syntax,
}))
}
@ -401,23 +412,32 @@ impl SingleFontFamily {
pub fn generic(name: &Atom) -> (structs::FontFamilyType, u8) {
use gecko_bindings::structs::FontFamilyType;
if *name == atom!("serif") {
(FontFamilyType::eFamily_serif,
structs::kGenericFont_serif)
(FontFamilyType::eFamily_serif, structs::kGenericFont_serif)
} else if *name == atom!("sans-serif") {
(FontFamilyType::eFamily_sans_serif,
structs::kGenericFont_sans_serif)
(
FontFamilyType::eFamily_sans_serif,
structs::kGenericFont_sans_serif,
)
} else if *name == atom!("cursive") {
(FontFamilyType::eFamily_cursive,
structs::kGenericFont_cursive)
(
FontFamilyType::eFamily_cursive,
structs::kGenericFont_cursive,
)
} else if *name == atom!("fantasy") {
(FontFamilyType::eFamily_fantasy,
structs::kGenericFont_fantasy)
(
FontFamilyType::eFamily_fantasy,
structs::kGenericFont_fantasy,
)
} else if *name == atom!("monospace") {
(FontFamilyType::eFamily_monospace,
structs::kGenericFont_monospace)
(
FontFamilyType::eFamily_monospace,
structs::kGenericFont_monospace,
)
} else if *name == atom!("-moz-fixed") {
(FontFamilyType::eFamily_moz_fixed,
structs::kGenericFont_moz_fixed)
(
FontFamilyType::eFamily_moz_fixed,
structs::kGenericFont_moz_fixed,
)
} else {
panic!("Unknown generic {}", name);
}
@ -434,7 +454,9 @@ impl SingleFontFamily {
FontFamilyType::eFamily_monospace => SingleFontFamily::Generic(atom!("monospace")),
FontFamilyType::eFamily_cursive => SingleFontFamily::Generic(atom!("cursive")),
FontFamilyType::eFamily_fantasy => SingleFontFamily::Generic(atom!("fantasy")),
FontFamilyType::eFamily_moz_fixed => SingleFontFamily::Generic(Atom::from("-moz-fixed")),
FontFamilyType::eFamily_moz_fixed => {
SingleFontFamily::Generic(Atom::from("-moz-fixed"))
},
FontFamilyType::eFamily_named => {
let name = Atom::from(&*family.mName);
SingleFontFamily::FamilyName(FamilyName {
@ -452,13 +474,17 @@ impl SingleFontFamily {
}
impl ToCss for SingleFontFamily {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
match *self {
SingleFontFamily::FamilyName(ref name) => name.to_css(dest),
// All generic values accepted by the parser are known to not require escaping.
SingleFontFamily::Generic(ref name) => {
#[cfg(feature = "gecko")] {
#[cfg(feature = "gecko")]
{
// We should treat -moz-fixed as monospace
if name == &atom!("-moz-fixed") {
return dest.write_str("monospace");
@ -483,7 +509,10 @@ pub struct FontFamilyList(pub RefPtr<structs::SharedFontList>);
#[cfg(feature = "gecko")]
impl Hash for FontFamilyList {
fn hash<H>(&self, state: &mut H) where H: Hasher {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
for name in self.0.mNames.iter() {
name.mType.hash(state);
name.mName.hash(state);
@ -535,19 +564,16 @@ impl FontFamilyList {
bindings::Gecko_nsTArray_FontFamilyName_AppendNamed(
names,
f.name.as_ptr(),
quoted
quoted,
);
}
}
},
SingleFontFamily::Generic(ref name) => {
let (family_type, _generic) = SingleFontFamily::generic(name);
unsafe {
bindings::Gecko_nsTArray_FontFamilyName_AppendGeneric(
names,
family_type
);
bindings::Gecko_nsTArray_FontFamilyName_AppendGeneric(names, family_type);
}
}
},
}
}
@ -651,7 +677,7 @@ impl ToAnimatedValue for FontSizeAdjust {
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
match animated {
FontSizeAdjust::Number(number) => FontSizeAdjust::Number(number.max(0.)),
_ => animated
_ => animated,
}
}
}
@ -698,11 +724,14 @@ impl FontLanguageOverride {
}
impl ToCss for FontLanguageOverride {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
use std::str;
if self.0 == 0 {
return dest.write_str("normal")
return dest.write_str("normal");
}
let mut buf = [0; 4];
BigEndian::write_u32(&mut buf, self.0);
@ -738,15 +767,11 @@ impl ToComputedValue for specified::MozScriptMinSize {
// we use the parent size
let base_size = FontBaseSize::InheritedStyle;
match self.0 {
NoCalcLength::FontRelative(value) => {
value.to_computed_value(cx, base_size)
}
NoCalcLength::FontRelative(value) => value.to_computed_value(cx, base_size),
NoCalcLength::ServoCharacterWidth(value) => {
value.to_computed_value(base_size.resolve(cx))
}
ref l => {
l.to_computed_value(cx)
}
},
ref l => l.to_computed_value(cx),
}
}
@ -775,11 +800,11 @@ impl ToComputedValue for specified::MozScriptLevel {
} else {
parent
}
}
},
specified::MozScriptLevel::Relative(rel) => {
let parent = cx.builder.get_parent_font().clone__moz_script_level();
parent as i32 + rel
}
},
specified::MozScriptLevel::MozAbsolute(abs) => abs,
};
cmp::min(int, i8::MAX as i32) as i8

View file

@ -31,23 +31,12 @@ pub type Image = generic::Image<Gradient, MozImageRect, ComputedImageUrl>;
/// Computed values for a CSS gradient.
/// <https://drafts.csswg.org/css-images/#gradients>
pub type Gradient = generic::Gradient<
LineDirection,
Length,
LengthOrPercentage,
Position,
RGBA,
Angle,
>;
pub type Gradient =
generic::Gradient<LineDirection, Length, LengthOrPercentage, Position, RGBA, Angle>;
/// A computed gradient kind.
pub type GradientKind = generic::GradientKind<
LineDirection,
Length,
LengthOrPercentage,
Position,
Angle,
>;
pub type GradientKind =
generic::GradientKind<LineDirection, Length, LengthOrPercentage, Position, Angle>;
/// A computed gradient line direction.
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
@ -81,16 +70,17 @@ impl generic::LineDirection for LineDirection {
fn points_downwards(&self, compat_mode: CompatMode) -> bool {
match *self {
LineDirection::Angle(angle) => angle.radians() == PI,
LineDirection::Vertical(Y::Bottom)
if compat_mode == CompatMode::Modern => true,
LineDirection::Vertical(Y::Top)
if compat_mode != CompatMode::Modern => true,
LineDirection::Vertical(Y::Bottom) if compat_mode == CompatMode::Modern => true,
LineDirection::Vertical(Y::Top) if compat_mode != CompatMode::Modern => true,
LineDirection::Corner(..) => false,
#[cfg(feature = "gecko")]
LineDirection::MozPosition(Some(Position {
horizontal: LengthOrPercentage::Percentage(Percentage(x)),
vertical: LengthOrPercentage::Percentage(Percentage(y)),
}), None) => {
LineDirection::MozPosition(
Some(Position {
horizontal: LengthOrPercentage::Percentage(Percentage(x)),
vertical: LengthOrPercentage::Percentage(Percentage(y)),
}),
None,
) => {
// `50% 0%` is the default value for line direction.
x == 0.5 && y == 0.0
},
@ -98,11 +88,7 @@ impl generic::LineDirection for LineDirection {
}
}
fn to_css<W>(
&self,
dest: &mut CssWriter<W>,
compat_mode: CompatMode,
) -> fmt::Result
fn to_css<W>(&self, dest: &mut CssWriter<W>, compat_mode: CompatMode) -> fmt::Result
where
W: Write,
{
@ -142,7 +128,7 @@ impl generic::LineDirection for LineDirection {
angle.to_css(dest)?;
}
Ok(())
}
},
}
}
}
@ -155,19 +141,15 @@ impl ToComputedValue for SpecifiedLineDirection {
SpecifiedLineDirection::Angle(ref angle) => {
LineDirection::Angle(angle.to_computed_value(context))
},
SpecifiedLineDirection::Horizontal(x) => {
LineDirection::Horizontal(x)
},
SpecifiedLineDirection::Vertical(y) => {
LineDirection::Vertical(y)
},
SpecifiedLineDirection::Corner(x, y) => {
LineDirection::Corner(x, y)
},
SpecifiedLineDirection::Horizontal(x) => LineDirection::Horizontal(x),
SpecifiedLineDirection::Vertical(y) => LineDirection::Vertical(y),
SpecifiedLineDirection::Corner(x, y) => LineDirection::Corner(x, y),
#[cfg(feature = "gecko")]
SpecifiedLineDirection::MozPosition(ref position, ref angle) => {
LineDirection::MozPosition(position.to_computed_value(context),
angle.to_computed_value(context))
LineDirection::MozPosition(
position.to_computed_value(context),
angle.to_computed_value(context),
)
},
}
}
@ -177,19 +159,15 @@ impl ToComputedValue for SpecifiedLineDirection {
LineDirection::Angle(ref angle) => {
SpecifiedLineDirection::Angle(ToComputedValue::from_computed_value(angle))
},
LineDirection::Horizontal(x) => {
SpecifiedLineDirection::Horizontal(x)
},
LineDirection::Vertical(y) => {
SpecifiedLineDirection::Vertical(y)
},
LineDirection::Corner(x, y) => {
SpecifiedLineDirection::Corner(x, y)
},
LineDirection::Horizontal(x) => SpecifiedLineDirection::Horizontal(x),
LineDirection::Vertical(y) => SpecifiedLineDirection::Vertical(y),
LineDirection::Corner(x, y) => SpecifiedLineDirection::Corner(x, y),
#[cfg(feature = "gecko")]
LineDirection::MozPosition(ref position, ref angle) => {
SpecifiedLineDirection::MozPosition(ToComputedValue::from_computed_value(position),
ToComputedValue::from_computed_value(angle))
SpecifiedLineDirection::MozPosition(
ToComputedValue::from_computed_value(position),
ToComputedValue::from_computed_value(angle),
)
},
}
}

View file

@ -12,8 +12,8 @@ use std::fmt::{self, Write};
use std::ops::{Add, Neg};
use style_traits::{CssWriter, ToCss};
use style_traits::values::specified::AllowedNumericType;
use super::{Number, ToComputedValue, Context, Percentage};
use values::{Auto, CSSFloat, Either, Normal, specified};
use super::{Context, Number, Percentage, ToComputedValue};
use values::{specified, Auto, CSSFloat, Either, Normal};
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
use values::distance::{ComputeSquaredDistance, SquaredDistance};
use values::generics::NonNegative;
@ -30,14 +30,16 @@ impl ToComputedValue for specified::NoCalcLength {
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
match *self {
specified::NoCalcLength::Absolute(length) =>
length.to_computed_value(context),
specified::NoCalcLength::FontRelative(length) =>
length.to_computed_value(context, FontBaseSize::CurrentStyle),
specified::NoCalcLength::ViewportPercentage(length) =>
length.to_computed_value(context.viewport_size_for_viewport_unit_resolution()),
specified::NoCalcLength::ServoCharacterWidth(length) =>
length.to_computed_value(context.style().get_font().clone_font_size().size()),
specified::NoCalcLength::Absolute(length) => length.to_computed_value(context),
specified::NoCalcLength::FontRelative(length) => {
length.to_computed_value(context, FontBaseSize::CurrentStyle)
},
specified::NoCalcLength::ViewportPercentage(length) => {
length.to_computed_value(context.viewport_size_for_viewport_unit_resolution())
},
specified::NoCalcLength::ServoCharacterWidth(length) => {
length.to_computed_value(context.style().get_font().clone_font_size().size())
},
}
}
@ -78,10 +80,10 @@ impl ComputeSquaredDistance for CalcLengthOrPercentage {
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
// FIXME(nox): This looks incorrect to me, to add a distance between lengths
// with a distance between percentages.
Ok(
self.unclamped_length().compute_squared_distance(&other.unclamped_length())? +
self.percentage().compute_squared_distance(&other.percentage())?,
)
Ok(self.unclamped_length()
.compute_squared_distance(&other.unclamped_length())? +
self.percentage()
.compute_squared_distance(&other.percentage())?)
}
}
@ -99,7 +101,11 @@ impl CalcLengthOrPercentage {
percentage: Option<Percentage>,
clamping_mode: AllowedNumericType,
) -> Self {
Self { clamping_mode, length, percentage, }
Self {
clamping_mode,
length,
percentage,
}
}
/// Returns this `calc()` as a `<length>`.
@ -155,13 +161,9 @@ impl From<LengthOrPercentage> for CalcLengthOrPercentage {
match len {
LengthOrPercentage::Percentage(this) => {
CalcLengthOrPercentage::new(Length::new(0.), Some(this))
}
LengthOrPercentage::Length(this) => {
CalcLengthOrPercentage::new(this, None)
}
LengthOrPercentage::Calc(this) => {
this
}
},
LengthOrPercentage::Length(this) => CalcLengthOrPercentage::new(this, None),
LengthOrPercentage::Calc(this) => this,
}
}
}
@ -171,16 +173,10 @@ impl From<LengthOrPercentageOrAuto> for Option<CalcLengthOrPercentage> {
match len {
LengthOrPercentageOrAuto::Percentage(this) => {
Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this)))
}
LengthOrPercentageOrAuto::Length(this) => {
Some(CalcLengthOrPercentage::new(this, None))
}
LengthOrPercentageOrAuto::Calc(this) => {
Some(this)
}
LengthOrPercentageOrAuto::Auto => {
None
}
},
LengthOrPercentageOrAuto::Length(this) => Some(CalcLengthOrPercentage::new(this, None)),
LengthOrPercentageOrAuto::Calc(this) => Some(this),
LengthOrPercentageOrAuto::Auto => None,
}
}
}
@ -190,16 +186,10 @@ impl From<LengthOrPercentageOrNone> for Option<CalcLengthOrPercentage> {
match len {
LengthOrPercentageOrNone::Percentage(this) => {
Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this)))
}
LengthOrPercentageOrNone::Length(this) => {
Some(CalcLengthOrPercentage::new(this, None))
}
LengthOrPercentageOrNone::Calc(this) => {
Some(this)
}
LengthOrPercentageOrNone::None => {
None
}
},
LengthOrPercentageOrNone::Length(this) => Some(CalcLengthOrPercentage::new(this, None)),
LengthOrPercentageOrNone::Calc(this) => Some(this),
LengthOrPercentageOrNone::None => None,
}
}
}
@ -220,7 +210,11 @@ impl ToCss for CalcLengthOrPercentage {
dest.write_str("calc(")?;
percentage.to_css(dest)?;
dest.write_str(if length.px() < Zero::zero() { " - " } else { " + " })?;
dest.write_str(if length.px() < Zero::zero() {
" - "
} else {
" + "
})?;
length.abs().to_css(dest)?;
dest.write_str(")")
@ -245,20 +239,24 @@ impl specified::CalcLengthOrPercentage {
length += zoom_fn(absolute.to_computed_value(context)).px();
}
for val in &[self.vw.map(ViewportPercentageLength::Vw),
self.vh.map(ViewportPercentageLength::Vh),
self.vmin.map(ViewportPercentageLength::Vmin),
self.vmax.map(ViewportPercentageLength::Vmax)] {
for val in &[
self.vw.map(ViewportPercentageLength::Vw),
self.vh.map(ViewportPercentageLength::Vh),
self.vmin.map(ViewportPercentageLength::Vmin),
self.vmax.map(ViewportPercentageLength::Vmax),
] {
if let Some(val) = *val {
let viewport_size = context.viewport_size_for_viewport_unit_resolution();
length += val.to_computed_value(viewport_size).px();
}
}
for val in &[self.ch.map(FontRelativeLength::Ch),
self.em.map(FontRelativeLength::Em),
self.ex.map(FontRelativeLength::Ex),
self.rem.map(FontRelativeLength::Rem)] {
for val in &[
self.ch.map(FontRelativeLength::Ch),
self.em.map(FontRelativeLength::Em),
self.ex.map(FontRelativeLength::Ex),
self.rem.map(FontRelativeLength::Rem),
] {
if let Some(val) = *val {
length += val.to_computed_value(context, base_size).px();
}
@ -277,15 +275,20 @@ impl specified::CalcLengthOrPercentage {
context: &Context,
base_size: FontBaseSize,
) -> CalcLengthOrPercentage {
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0, base_size)
self.to_computed_value_with_zoom(
context,
|abs| context.maybe_zoom_text(abs.into()).0,
base_size,
)
}
/// Compute the value into pixel length as CSSFloat without context,
/// so it returns Err(()) if there is any non-absolute unit.
pub fn to_computed_pixel_length_without_context(&self) -> Result<CSSFloat, ()> {
if self.vw.is_some() || self.vh.is_some() || self.vmin.is_some() || self.vmax.is_some() ||
self.em.is_some() || self.ex.is_some() || self.ch.is_some() || self.rem.is_some() ||
self.percentage.is_some() {
self.em.is_some() || self.ex.is_some() || self.ch.is_some() ||
self.rem.is_some() || self.percentage.is_some()
{
return Err(());
}
@ -294,7 +297,7 @@ impl specified::CalcLengthOrPercentage {
None => {
debug_assert!(false, "Someone forgot to handle an unit here: {:?}", self);
Err(())
}
},
}
}
}
@ -321,8 +324,8 @@ impl ToComputedValue for specified::CalcLengthOrPercentage {
#[allow(missing_docs)]
#[animate(fallback = "Self::animate_fallback")]
#[css(derive_debug)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq)]
#[derive(ToAnimatedZero, ToCss)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero,
ToCss)]
#[distance(fallback = "Self::compute_squared_distance_fallback")]
pub enum LengthOrPercentage {
Length(Length),
@ -332,11 +335,7 @@ pub enum LengthOrPercentage {
impl LengthOrPercentage {
/// <https://drafts.csswg.org/css-transitions/#animtype-lpcalc>
fn animate_fallback(
&self,
other: &Self,
procedure: Procedure,
) -> Result<Self, ()> {
fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
// Special handling for zero values since these should not require calc().
if self.is_definitely_zero() {
return other.to_animated_zero()?.animate(other, procedure);
@ -351,14 +350,8 @@ impl LengthOrPercentage {
}
#[inline]
fn compute_squared_distance_fallback(
&self,
other: &Self,
) -> Result<SquaredDistance, ()> {
CalcLengthOrPercentage::compute_squared_distance(
&(*self).into(),
&(*other).into(),
)
fn compute_squared_distance_fallback(&self, other: &Self) -> Result<SquaredDistance, ()> {
CalcLengthOrPercentage::compute_squared_distance(&(*self).into(), &(*other).into())
}
}
@ -391,7 +384,7 @@ impl LengthOrPercentage {
match *self {
Length(l) => l.px() == 0.0,
Percentage(p) => p.0 == 0.0,
Calc(_) => false
Calc(_) => false,
}
}
@ -403,7 +396,10 @@ impl LengthOrPercentage {
match *self {
Length(l) => (Au::from(l), NotNaN::new(0.0).unwrap()),
Percentage(p) => (Au(0), NotNaN::new(p.0).unwrap()),
Calc(c) => (Au::from(c.unclamped_length()), NotNaN::new(c.percentage()).unwrap()),
Calc(c) => (
Au::from(c.unclamped_length()),
NotNaN::new(c.percentage()).unwrap(),
),
}
}
@ -433,7 +429,7 @@ impl LengthOrPercentage {
LengthOrPercentage::Percentage(percentage) => {
LengthOrPercentage::Percentage(percentage.clamp_to_non_negative())
},
_ => self
_ => self,
}
}
}
@ -445,31 +441,27 @@ impl ToComputedValue for specified::LengthOrPercentage {
match *self {
specified::LengthOrPercentage::Length(ref value) => {
LengthOrPercentage::Length(value.to_computed_value(context))
}
},
specified::LengthOrPercentage::Percentage(value) => {
LengthOrPercentage::Percentage(value)
}
},
specified::LengthOrPercentage::Calc(ref calc) => {
LengthOrPercentage::Calc((**calc).to_computed_value(context))
}
},
}
}
fn from_computed_value(computed: &LengthOrPercentage) -> Self {
match *computed {
LengthOrPercentage::Length(value) => {
specified::LengthOrPercentage::Length(
ToComputedValue::from_computed_value(&value)
)
}
specified::LengthOrPercentage::Length(ToComputedValue::from_computed_value(&value))
},
LengthOrPercentage::Percentage(value) => {
specified::LengthOrPercentage::Percentage(value)
}
LengthOrPercentage::Calc(ref calc) => {
specified::LengthOrPercentage::Calc(
Box::new(ToComputedValue::from_computed_value(calc))
)
}
},
LengthOrPercentage::Calc(ref calc) => specified::LengthOrPercentage::Calc(Box::new(
ToComputedValue::from_computed_value(calc),
)),
}
}
}
@ -488,23 +480,18 @@ pub enum LengthOrPercentageOrAuto {
impl LengthOrPercentageOrAuto {
/// <https://drafts.csswg.org/css-transitions/#animtype-lpcalc>
fn animate_fallback(
&self,
other: &Self,
procedure: Procedure,
) -> Result<Self, ()> {
fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
let this = <Option<CalcLengthOrPercentage>>::from(*self);
let other = <Option<CalcLengthOrPercentage>>::from(*other);
Ok(LengthOrPercentageOrAuto::Calc(
this.animate(&other, procedure)?.ok_or(())?,
))
Ok(LengthOrPercentageOrAuto::Calc(this.animate(
&other,
procedure,
)?
.ok_or(())?))
}
#[inline]
fn compute_squared_distance_fallback(
&self,
other: &Self,
) -> Result<SquaredDistance, ()> {
fn compute_squared_distance_fallback(&self, other: &Self) -> Result<SquaredDistance, ()> {
<Option<CalcLengthOrPercentage>>::compute_squared_distance(
&(*self).into(),
&(*other).into(),
@ -547,7 +534,7 @@ impl LengthOrPercentageOrAuto {
match *self {
Length(l) => l.px() == 0.0,
Percentage(p) => p.0 == 0.0,
Calc(_) | Auto => false
Calc(_) | Auto => false,
}
}
@ -569,16 +556,14 @@ impl ToComputedValue for specified::LengthOrPercentageOrAuto {
match *self {
specified::LengthOrPercentageOrAuto::Length(ref value) => {
LengthOrPercentageOrAuto::Length(value.to_computed_value(context))
}
},
specified::LengthOrPercentageOrAuto::Percentage(value) => {
LengthOrPercentageOrAuto::Percentage(value)
}
specified::LengthOrPercentageOrAuto::Auto => {
LengthOrPercentageOrAuto::Auto
}
},
specified::LengthOrPercentageOrAuto::Auto => LengthOrPercentageOrAuto::Auto,
specified::LengthOrPercentageOrAuto::Calc(ref calc) => {
LengthOrPercentageOrAuto::Calc((**calc).to_computed_value(context))
}
},
}
}
@ -586,19 +571,15 @@ impl ToComputedValue for specified::LengthOrPercentageOrAuto {
fn from_computed_value(computed: &LengthOrPercentageOrAuto) -> Self {
match *computed {
LengthOrPercentageOrAuto::Auto => specified::LengthOrPercentageOrAuto::Auto,
LengthOrPercentageOrAuto::Length(value) => {
specified::LengthOrPercentageOrAuto::Length(
ToComputedValue::from_computed_value(&value)
)
}
LengthOrPercentageOrAuto::Length(value) => specified::LengthOrPercentageOrAuto::Length(
ToComputedValue::from_computed_value(&value),
),
LengthOrPercentageOrAuto::Percentage(value) => {
specified::LengthOrPercentageOrAuto::Percentage(value)
}
LengthOrPercentageOrAuto::Calc(calc) => {
specified::LengthOrPercentageOrAuto::Calc(
Box::new(ToComputedValue::from_computed_value(&calc))
)
}
},
LengthOrPercentageOrAuto::Calc(calc) => specified::LengthOrPercentageOrAuto::Calc(
Box::new(ToComputedValue::from_computed_value(&calc)),
),
}
}
}
@ -618,22 +599,17 @@ pub enum LengthOrPercentageOrNone {
impl LengthOrPercentageOrNone {
/// <https://drafts.csswg.org/css-transitions/#animtype-lpcalc>
fn animate_fallback(
&self,
other: &Self,
procedure: Procedure,
) -> Result<Self, ()> {
fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
let this = <Option<CalcLengthOrPercentage>>::from(*self);
let other = <Option<CalcLengthOrPercentage>>::from(*other);
Ok(LengthOrPercentageOrNone::Calc(
this.animate(&other, procedure)?.ok_or(())?,
))
Ok(LengthOrPercentageOrNone::Calc(this.animate(
&other,
procedure,
)?
.ok_or(())?))
}
fn compute_squared_distance_fallback(
&self,
other: &Self,
) -> Result<SquaredDistance, ()> {
fn compute_squared_distance_fallback(&self, other: &Self) -> Result<SquaredDistance, ()> {
<Option<CalcLengthOrPercentage>>::compute_squared_distance(
&(*self).into(),
&(*other).into(),
@ -647,7 +623,9 @@ impl LengthOrPercentageOrNone {
match *self {
LengthOrPercentageOrNone::None => None,
LengthOrPercentageOrNone::Length(length) => Some(Au::from(length)),
LengthOrPercentageOrNone::Percentage(percent) => Some(containing_length.scale_by(percent.0)),
LengthOrPercentageOrNone::Percentage(percent) => {
Some(containing_length.scale_by(percent.0))
},
LengthOrPercentageOrNone::Calc(ref calc) => calc.to_used_value(Some(containing_length)),
}
}
@ -661,16 +639,14 @@ impl ToComputedValue for specified::LengthOrPercentageOrNone {
match *self {
specified::LengthOrPercentageOrNone::Length(ref value) => {
LengthOrPercentageOrNone::Length(value.to_computed_value(context))
}
},
specified::LengthOrPercentageOrNone::Percentage(value) => {
LengthOrPercentageOrNone::Percentage(value)
}
},
specified::LengthOrPercentageOrNone::Calc(ref calc) => {
LengthOrPercentageOrNone::Calc((**calc).to_computed_value(context))
}
specified::LengthOrPercentageOrNone::None => {
LengthOrPercentageOrNone::None
}
},
specified::LengthOrPercentageOrNone::None => LengthOrPercentageOrNone::None,
}
}
@ -678,19 +654,15 @@ impl ToComputedValue for specified::LengthOrPercentageOrNone {
fn from_computed_value(computed: &LengthOrPercentageOrNone) -> Self {
match *computed {
LengthOrPercentageOrNone::None => specified::LengthOrPercentageOrNone::None,
LengthOrPercentageOrNone::Length(value) => {
specified::LengthOrPercentageOrNone::Length(
ToComputedValue::from_computed_value(&value)
)
}
LengthOrPercentageOrNone::Length(value) => specified::LengthOrPercentageOrNone::Length(
ToComputedValue::from_computed_value(&value),
),
LengthOrPercentageOrNone::Percentage(value) => {
specified::LengthOrPercentageOrNone::Percentage(value)
}
LengthOrPercentageOrNone::Calc(calc) => {
specified::LengthOrPercentageOrNone::Calc(
Box::new(ToComputedValue::from_computed_value(&calc))
)
}
},
LengthOrPercentageOrNone::Calc(calc) => specified::LengthOrPercentageOrNone::Calc(
Box::new(ToComputedValue::from_computed_value(&calc)),
),
}
}
}
@ -755,8 +727,8 @@ impl NonNegativeLengthOrPercentage {
/// The computed `<length>` value.
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd)]
#[derive(ToAnimatedValue, ToAnimatedZero)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq,
PartialOrd, ToAnimatedValue, ToAnimatedZero)]
pub struct CSSPixelLength(CSSFloat);
impl CSSPixelLength {
@ -968,13 +940,9 @@ impl ExtremumLength {
LonghandId::MaxWidth |
LonghandId::Width => !wm.is_vertical(),
LonghandId::MinHeight |
LonghandId::MaxHeight |
LonghandId::Height => wm.is_vertical(),
LonghandId::MinHeight | LonghandId::MaxHeight | LonghandId::Height => wm.is_vertical(),
LonghandId::MinInlineSize |
LonghandId::MaxInlineSize |
LonghandId::InlineSize => true,
LonghandId::MinInlineSize | LonghandId::MaxInlineSize | LonghandId::InlineSize => true,
// The block-* properties are rejected at parse-time, so they're
// unexpected here.
_ => {
@ -984,7 +952,7 @@ impl ExtremumLength {
longhand,
);
false
}
},
}
}
}
@ -995,8 +963,7 @@ impl ExtremumLength {
/// See values/specified/length.rs for more details.
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, PartialEq)]
#[derive(ToAnimatedZero, ToCss)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToAnimatedZero, ToCss)]
pub enum MozLength {
LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
#[animation(error)]
@ -1023,16 +990,21 @@ impl ToComputedValue for specified::MozLength {
match *self {
specified::MozLength::LengthOrPercentageOrAuto(ref lopoa) => {
MozLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context))
}
},
specified::MozLength::ExtremumLength(ext) => {
context.rule_cache_conditions.borrow_mut()
context
.rule_cache_conditions
.borrow_mut()
.set_writing_mode_dependency(context.builder.writing_mode);
if !ext.valid_for(context.builder.writing_mode, context.for_non_inherited_property.unwrap()) {
if !ext.valid_for(
context.builder.writing_mode,
context.for_non_inherited_property.unwrap(),
) {
MozLength::auto()
} else {
MozLength::ExtremumLength(ext)
}
}
},
}
}
@ -1041,12 +1013,10 @@ impl ToComputedValue for specified::MozLength {
match *computed {
MozLength::LengthOrPercentageOrAuto(ref lopoa) => {
specified::MozLength::LengthOrPercentageOrAuto(
specified::LengthOrPercentageOrAuto::from_computed_value(lopoa)
specified::LengthOrPercentageOrAuto::from_computed_value(lopoa),
)
},
MozLength::ExtremumLength(ext) => {
specified::MozLength::ExtremumLength(ext)
}
MozLength::ExtremumLength(ext) => specified::MozLength::ExtremumLength(ext),
}
}
}
@ -1082,27 +1052,33 @@ impl ToComputedValue for specified::MaxLength {
match *self {
specified::MaxLength::LengthOrPercentageOrNone(ref lopon) => {
MaxLength::LengthOrPercentageOrNone(lopon.to_computed_value(context))
}
},
specified::MaxLength::ExtremumLength(ext) => {
context.rule_cache_conditions.borrow_mut()
context
.rule_cache_conditions
.borrow_mut()
.set_writing_mode_dependency(context.builder.writing_mode);
if !ext.valid_for(context.builder.writing_mode, context.for_non_inherited_property.unwrap()) {
if !ext.valid_for(
context.builder.writing_mode,
context.for_non_inherited_property.unwrap(),
) {
MaxLength::none()
} else {
MaxLength::ExtremumLength(ext)
}
}
},
}
}
#[inline]
fn from_computed_value(computed: &MaxLength) -> Self {
match *computed {
MaxLength::LengthOrPercentageOrNone(ref lopon) =>
MaxLength::LengthOrPercentageOrNone(ref lopon) => {
specified::MaxLength::LengthOrPercentageOrNone(
specified::LengthOrPercentageOrNone::from_computed_value(&lopon)),
MaxLength::ExtremumLength(ref ext) =>
specified::MaxLength::ExtremumLength(ext.clone()),
specified::LengthOrPercentageOrNone::from_computed_value(&lopon),
)
},
MaxLength::ExtremumLength(ref ext) => specified::MaxLength::ExtremumLength(ext.clone()),
}
}
}

View file

@ -14,15 +14,17 @@ impl Quotes {
/// FIXME(emilio): This should ideally not allocate.
#[inline]
pub fn get_initial_value() -> Quotes {
Quotes(vec![
(
"\u{201c}".to_owned().into_boxed_str(),
"\u{201d}".to_owned().into_boxed_str(),
),
(
"\u{2018}".to_owned().into_boxed_str(),
"\u{2019}".to_owned().into_boxed_str(),
),
].into_boxed_slice())
Quotes(
vec![
(
"\u{201c}".to_owned().into_boxed_str(),
"\u{201d}".to_owned().into_boxed_str(),
),
(
"\u{2018}".to_owned().into_boxed_str(),
"\u{2019}".to_owned().into_boxed_str(),
),
].into_boxed_slice(),
)
}
}

View file

@ -9,7 +9,7 @@ use Atom;
use Prefix;
use context::QuirksMode;
use euclid::Size2D;
use font_metrics::{FontMetricsProvider, get_metrics_provider_for_product};
use font_metrics::{get_metrics_provider_for_product, FontMetricsProvider};
use media_queries::Device;
#[cfg(feature = "gecko")]
use properties;
@ -25,24 +25,24 @@ use super::{CSSFloat, CSSInteger};
use super::animated::ToAnimatedValue;
use super::generics::{GreaterThanOrEqualToOne, NonNegative};
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
use super::generics::grid::{TrackSize as GenericTrackSize, TrackList as GenericTrackList};
use super::generics::grid::{TrackList as GenericTrackList, TrackSize as GenericTrackSize};
use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
use super::specified;
pub use app_units::Au;
pub use properties::animated_properties::TransitionProperty;
#[cfg(feature = "gecko")]
pub use self::align::{AlignItems, AlignContent, JustifyContent, SelfAlignment, JustifyItems};
pub use self::align::{AlignContent, AlignItems, JustifyContent, JustifyItems, SelfAlignment};
#[cfg(feature = "gecko")]
pub use self::align::{AlignSelf, JustifySelf};
pub use self::angle::Angle;
pub use self::background::{BackgroundSize, BackgroundRepeat};
pub use self::border::{BorderImageRepeat, BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
pub use self::background::{BackgroundRepeat, BackgroundSize};
pub use self::border::{BorderImageRepeat, BorderImageSideWidth, BorderImageSlice, BorderImageWidth};
pub use self::border::{BorderCornerRadius, BorderRadius, BorderSpacing};
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontVariantAlternates, FontWeight};
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantEastAsian, FontVariationSettings};
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective};
pub use self::box_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange};
@ -52,7 +52,7 @@ pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
pub use self::flex::FlexBasis;
pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect};
pub use self::inherited_box::{Orientation, ImageOrientation};
pub use self::inherited_box::{ImageOrientation, Orientation};
#[cfg(feature = "gecko")]
pub use self::gecko::ScrollSnapPoint;
pub use self::rect::LengthOrNumberRect;
@ -96,10 +96,10 @@ pub mod counters;
pub mod effects;
pub mod flex;
pub mod font;
pub mod image;
pub mod inherited_box;
#[cfg(feature = "gecko")]
pub mod gecko;
pub mod image;
pub mod inherited_box;
pub mod length;
pub mod list;
pub mod outline;
@ -171,13 +171,9 @@ impl<'a> Context<'a> {
/// Creates a suitable context for media query evaluation, in which
/// font-relative units compute against the system_font, and executes `f`
/// with it.
pub fn for_media_query_evaluation<F, R>(
device: &Device,
quirks_mode: QuirksMode,
f: F,
) -> R
pub fn for_media_query_evaluation<F, R>(device: &Device, quirks_mode: QuirksMode, f: F) -> R
where
F: FnOnce(&Context) -> R
F: FnOnce(&Context) -> R,
{
let mut conditions = RuleCacheConditions::default();
let provider = get_metrics_provider_for_product();
@ -209,7 +205,9 @@ impl<'a> Context<'a> {
/// The current viewport size, used to resolve viewport units.
pub fn viewport_size_for_viewport_unit_resolution(&self) -> Size2D<Au> {
self.builder.device.au_viewport_size_for_viewport_unit_resolution()
self.builder
.device
.au_viewport_size_for_viewport_unit_resolution()
}
/// The default computed style we're getting our reset style from.
@ -259,7 +257,9 @@ impl<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> ComputedVecIter<'a, 'cx, 'cx_
}
}
impl<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> ExactSizeIterator for ComputedVecIter<'a, 'cx, 'cx_a, S> {
impl<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> ExactSizeIterator
for ComputedVecIter<'a, 'cx, 'cx_a, S>
{
fn len(&self) -> usize {
self.values.len()
}
@ -308,7 +308,9 @@ pub trait ToComputedValue {
}
impl<A, B> ToComputedValue for (A, B)
where A: ToComputedValue, B: ToComputedValue,
where
A: ToComputedValue,
B: ToComputedValue,
{
type ComputedValue = (
<A as ToComputedValue>::ComputedValue,
@ -317,17 +319,24 @@ impl<A, B> ToComputedValue for (A, B)
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
(self.0.to_computed_value(context), self.1.to_computed_value(context))
(
self.0.to_computed_value(context),
self.1.to_computed_value(context),
)
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
(A::from_computed_value(&computed.0), B::from_computed_value(&computed.1))
(
A::from_computed_value(&computed.0),
B::from_computed_value(&computed.1),
)
}
}
impl<T> ToComputedValue for Option<T>
where T: ToComputedValue
where
T: ToComputedValue,
{
type ComputedValue = Option<<T as ToComputedValue>::ComputedValue>;
@ -343,7 +352,8 @@ impl<T> ToComputedValue for Option<T>
}
impl<T> ToComputedValue for Size2D<T>
where T: ToComputedValue
where
T: ToComputedValue,
{
type ComputedValue = Size2D<<T as ToComputedValue>::ComputedValue>;
@ -365,13 +375,16 @@ impl<T> ToComputedValue for Size2D<T>
}
impl<T> ToComputedValue for Vec<T>
where T: ToComputedValue
where
T: ToComputedValue,
{
type ComputedValue = Vec<<T as ToComputedValue>::ComputedValue>;
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
self.iter().map(|item| item.to_computed_value(context)).collect()
self.iter()
.map(|item| item.to_computed_value(context))
.collect()
}
#[inline]
@ -381,7 +394,8 @@ impl<T> ToComputedValue for Vec<T>
}
impl<T> ToComputedValue for Box<T>
where T: ToComputedValue
where
T: ToComputedValue,
{
type ComputedValue = Box<<T as ToComputedValue>::ComputedValue>;
@ -397,18 +411,26 @@ impl<T> ToComputedValue for Box<T>
}
impl<T> ToComputedValue for Box<[T]>
where T: ToComputedValue
where
T: ToComputedValue,
{
type ComputedValue = Box<[<T as ToComputedValue>::ComputedValue]>;
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
self.iter().map(|item| item.to_computed_value(context)).collect::<Vec<_>>().into_boxed_slice()
self.iter()
.map(|item| item.to_computed_value(context))
.collect::<Vec<_>>()
.into_boxed_slice()
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
computed.iter().map(T::from_computed_value).collect::<Vec<_>>().into_boxed_slice()
computed
.iter()
.map(T::from_computed_value)
.collect::<Vec<_>>()
.into_boxed_slice()
}
}
@ -504,19 +526,25 @@ impl ToComputedValue for specified::NumberOrPercentage {
#[inline]
fn to_computed_value(&self, context: &Context) -> NumberOrPercentage {
match *self {
specified::NumberOrPercentage::Percentage(percentage) =>
NumberOrPercentage::Percentage(percentage.to_computed_value(context)),
specified::NumberOrPercentage::Number(number) =>
NumberOrPercentage::Number(number.to_computed_value(context)),
specified::NumberOrPercentage::Percentage(percentage) => {
NumberOrPercentage::Percentage(percentage.to_computed_value(context))
},
specified::NumberOrPercentage::Number(number) => {
NumberOrPercentage::Number(number.to_computed_value(context))
},
}
}
#[inline]
fn from_computed_value(computed: &NumberOrPercentage) -> Self {
match *computed {
NumberOrPercentage::Percentage(percentage) =>
specified::NumberOrPercentage::Percentage(ToComputedValue::from_computed_value(&percentage)),
NumberOrPercentage::Number(number) =>
specified::NumberOrPercentage::Number(ToComputedValue::from_computed_value(&number)),
NumberOrPercentage::Percentage(percentage) => {
specified::NumberOrPercentage::Percentage(ToComputedValue::from_computed_value(
&percentage,
))
},
NumberOrPercentage::Number(number) => {
specified::NumberOrPercentage::Number(ToComputedValue::from_computed_value(&number))
},
}
}
}
@ -627,7 +655,7 @@ impl ClipRectOrAuto {
pub fn is_auto(&self) -> bool {
match *self {
Either::Second(_) => true,
_ => false
_ => false,
}
}
}

View file

@ -6,12 +6,12 @@
use std::fmt;
use style_traits::{CssWriter, ToCss};
use values::{CSSFloat, serialize_percentage};
use values::{serialize_percentage, CSSFloat};
/// A computed percentage.
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, Default, MallocSizeOf)]
#[derive(PartialEq, PartialOrd, ToAnimatedZero, ToComputedValue)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, Default, MallocSizeOf, PartialEq,
PartialOrd, ToAnimatedZero, ToComputedValue)]
pub struct Percentage(pub CSSFloat);
impl Percentage {

View file

@ -41,7 +41,7 @@ impl Cursor {
pub fn auto() -> Self {
Self {
images: vec![].into_boxed_slice(),
keyword: CursorKind::Auto
keyword: CursorKind::Auto,
}
}
}
@ -51,7 +51,7 @@ impl Parse for Cursor {
#[cfg(feature = "servo")]
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Ok(Cursor(CursorKind::parse(context, input)?))
}
@ -60,7 +60,7 @@ impl Parse for Cursor {
#[cfg(feature = "gecko")]
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let mut images = vec![];
loop {
@ -94,13 +94,13 @@ impl ToCss for Cursor {
impl Parse for CursorKind {
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let location = input.current_source_location();
let ident = input.expect_ident()?;
CursorKind::from_css_keyword(&ident)
.map_err(|_| location.new_custom_error(
SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
CursorKind::from_css_keyword(&ident).map_err(|_| {
location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))
})
}
}
@ -108,7 +108,7 @@ impl Parse for CursorKind {
impl CursorImage {
fn parse_image<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Ok(Self {
url: SpecifiedImageUrl::parse(context, input)?,

View file

@ -7,7 +7,7 @@
use app_units::Au;
use values::RGBA;
use values::computed::{LengthOrPercentage, NonNegativeLength};
use values::computed::{NonNegativeNumber, NonNegativeLengthOrPercentage, Number};
use values::computed::{NonNegativeLengthOrPercentage, NonNegativeNumber, Number};
use values::computed::Opacity;
use values::computed::url::ComputedUrl;
use values::generics::svg as generic;
@ -51,8 +51,9 @@ pub type SVGLength = generic::SVGLength<SvgLengthOrPercentageOrNumber>;
impl From<Au> for SVGLength {
fn from(length: Au) -> Self {
generic::SVGLength::Length(
generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(length.into()))
generic::SVGLength::Length(generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(
length.into(),
))
}
}
@ -64,7 +65,7 @@ pub type NonNegativeSvgLengthOrPercentageOrNumber =
impl Into<NonNegativeSvgLengthOrPercentageOrNumber> for SvgLengthOrPercentageOrNumber {
fn into(self) -> NonNegativeSvgLengthOrPercentageOrNumber {
match self {
generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) =>{
generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => {
generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop.into())
},
generic::SvgLengthOrPercentageOrNumber::Number(num) => {
@ -79,8 +80,9 @@ pub type SVGWidth = generic::SVGLength<NonNegativeSvgLengthOrPercentageOrNumber>
impl From<NonNegativeLength> for SVGWidth {
fn from(length: NonNegativeLength) -> Self {
generic::SVGLength::Length(
generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(length.into()))
generic::SVGLength::Length(generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(
length.into(),
))
}
}

View file

@ -8,7 +8,7 @@
use properties::StyleBuilder;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
use values::{CSSInteger, CSSFloat};
use values::{CSSFloat, CSSInteger};
use values::computed::{NonNegativeLength, NonNegativeNumber};
use values::computed::length::{Length, LengthOrPercentage};
use values::generics::text::InitialLetter as GenericInitialLetter;
@ -95,7 +95,7 @@ impl ToCss for TextDecorationLine {
dest.write_str($css)?;
has_any = true;
}
}
};
}
write_value!(TextDecorationLine::UNDERLINE => "underline");
write_value!(TextDecorationLine::OVERLINE => "overline");
@ -136,9 +136,11 @@ impl TextDecorationsInEffect {
// otherwise, start with the declarations in effect and add in the text
// decorations that this block specifies.
let mut result = match style.get_box().clone_display() {
Display::InlineBlock |
Display::InlineTable => Self::default(),
_ => style.get_parent_inheritedtext().text_decorations_in_effect.clone(),
Display::InlineBlock | Display::InlineTable => Self::default(),
_ => style
.get_parent_inheritedtext()
.text_decorations_in_effect
.clone(),
};
let text_style = style.get_text();

View file

@ -18,9 +18,7 @@ pub struct Time {
impl Time {
/// Creates a time value from a seconds amount.
pub fn from_seconds(seconds: CSSFloat) -> Self {
Time {
seconds: seconds,
}
Time { seconds: seconds }
}
/// Returns `0s`.

View file

@ -14,13 +14,8 @@ use values::generics::transform as generic;
pub use values::generics::transform::TransformStyle;
/// A single operation in a computed CSS `transform`
pub type TransformOperation = generic::TransformOperation<
Angle,
Number,
Length,
Integer,
LengthOrPercentage,
>;
pub type TransformOperation =
generic::TransformOperation<Angle, Number, Length, Integer, LengthOrPercentage>;
/// A computed CSS `transform`
pub type Transform = generic::Transform<TransformOperation>;
@ -130,13 +125,21 @@ impl TransformOperation {
generic::TransformOperation::Translate3D(..) => self.clone(),
generic::TransformOperation::TranslateX(ref x) |
generic::TransformOperation::Translate(ref x, None) => {
generic::TransformOperation::Translate3D(x.clone(), LengthOrPercentage::zero(), Length::zero())
generic::TransformOperation::Translate3D(
x.clone(),
LengthOrPercentage::zero(),
Length::zero(),
)
},
generic::TransformOperation::Translate(ref x, Some(ref y)) => {
generic::TransformOperation::Translate3D(x.clone(), y.clone(), Length::zero())
},
generic::TransformOperation::TranslateY(ref y) => {
generic::TransformOperation::Translate3D(LengthOrPercentage::zero(), y.clone(), Length::zero())
generic::TransformOperation::Translate3D(
LengthOrPercentage::zero(),
y.clone(),
Length::zero(),
)
},
generic::TransformOperation::TranslateZ(ref z) => {
generic::TransformOperation::Translate3D(
@ -154,11 +157,21 @@ impl TransformOperation {
pub fn to_scale_3d(&self) -> Self {
match *self {
generic::TransformOperation::Scale3D(..) => self.clone(),
generic::TransformOperation::Scale(s, None) => generic::TransformOperation::Scale3D(s, s, 1.),
generic::TransformOperation::Scale(x, Some(y)) => generic::TransformOperation::Scale3D(x, y, 1.),
generic::TransformOperation::ScaleX(x) => generic::TransformOperation::Scale3D(x, 1., 1.),
generic::TransformOperation::ScaleY(y) => generic::TransformOperation::Scale3D(1., y, 1.),
generic::TransformOperation::ScaleZ(z) => generic::TransformOperation::Scale3D(1., 1., z),
generic::TransformOperation::Scale(s, None) => {
generic::TransformOperation::Scale3D(s, s, 1.)
},
generic::TransformOperation::Scale(x, Some(y)) => {
generic::TransformOperation::Scale3D(x, y, 1.)
},
generic::TransformOperation::ScaleX(x) => {
generic::TransformOperation::Scale3D(x, 1., 1.)
},
generic::TransformOperation::ScaleY(y) => {
generic::TransformOperation::Scale3D(1., y, 1.)
},
generic::TransformOperation::ScaleZ(z) => {
generic::TransformOperation::Scale3D(1., 1., z)
},
_ => unreachable!(),
}
}
@ -170,18 +183,22 @@ impl TransformOperation {
impl ToAnimatedZero for TransformOperation {
fn to_animated_zero(&self) -> Result<Self, ()> {
match *self {
generic::TransformOperation::Matrix3D(..) =>
Ok(generic::TransformOperation::Matrix3D(Matrix3D::identity())),
generic::TransformOperation::Matrix(..) =>
Ok(generic::TransformOperation::Matrix(Matrix::identity())),
generic::TransformOperation::Skew(sx, sy) => {
Ok(generic::TransformOperation::Skew(
sx.to_animated_zero()?,
sy.to_animated_zero()?,
))
generic::TransformOperation::Matrix3D(..) => {
Ok(generic::TransformOperation::Matrix3D(Matrix3D::identity()))
},
generic::TransformOperation::Matrix(..) => {
Ok(generic::TransformOperation::Matrix(Matrix::identity()))
},
generic::TransformOperation::Skew(sx, sy) => Ok(generic::TransformOperation::Skew(
sx.to_animated_zero()?,
sy.to_animated_zero()?,
)),
generic::TransformOperation::SkewX(s) => {
Ok(generic::TransformOperation::SkewX(s.to_animated_zero()?))
},
generic::TransformOperation::SkewY(s) => {
Ok(generic::TransformOperation::SkewY(s.to_animated_zero()?))
},
generic::TransformOperation::SkewX(s) => Ok(generic::TransformOperation::SkewX(s.to_animated_zero()?)),
generic::TransformOperation::SkewY(s) => Ok(generic::TransformOperation::SkewY(s.to_animated_zero()?)),
generic::TransformOperation::Translate3D(ref tx, ref ty, ref tz) => {
Ok(generic::TransformOperation::Translate3D(
tx.to_animated_zero()?,
@ -195,35 +212,48 @@ impl ToAnimatedZero for TransformOperation {
ty.to_animated_zero()?,
))
},
generic::TransformOperation::TranslateX(ref t) => {
Ok(generic::TransformOperation::TranslateX(t.to_animated_zero()?))
generic::TransformOperation::TranslateX(ref t) => Ok(
generic::TransformOperation::TranslateX(t.to_animated_zero()?),
),
generic::TransformOperation::TranslateY(ref t) => Ok(
generic::TransformOperation::TranslateY(t.to_animated_zero()?),
),
generic::TransformOperation::TranslateZ(ref t) => Ok(
generic::TransformOperation::TranslateZ(t.to_animated_zero()?),
),
generic::TransformOperation::Scale3D(..) => {
Ok(generic::TransformOperation::Scale3D(1.0, 1.0, 1.0))
},
generic::TransformOperation::TranslateY(ref t) => {
Ok(generic::TransformOperation::TranslateY(t.to_animated_zero()?))
generic::TransformOperation::Scale(_, _) => {
Ok(generic::TransformOperation::Scale(1.0, Some(1.0)))
},
generic::TransformOperation::TranslateZ(ref t) => {
Ok(generic::TransformOperation::TranslateZ(t.to_animated_zero()?))
},
generic::TransformOperation::Scale3D(..) => Ok(generic::TransformOperation::Scale3D(1.0, 1.0, 1.0)),
generic::TransformOperation::Scale(_, _) => Ok(generic::TransformOperation::Scale(1.0, Some(1.0))),
generic::TransformOperation::ScaleX(..) => Ok(generic::TransformOperation::ScaleX(1.0)),
generic::TransformOperation::ScaleY(..) => Ok(generic::TransformOperation::ScaleY(1.0)),
generic::TransformOperation::ScaleZ(..) => Ok(generic::TransformOperation::ScaleZ(1.0)),
generic::TransformOperation::Rotate3D(x, y, z, a) => {
let (x, y, z, _) = generic::get_normalized_vector_and_angle(x, y, z, a);
Ok(generic::TransformOperation::Rotate3D(x, y, z, Angle::zero()))
Ok(generic::TransformOperation::Rotate3D(
x,
y,
z,
Angle::zero(),
))
},
generic::TransformOperation::RotateX(_) => {
Ok(generic::TransformOperation::RotateX(Angle::zero()))
},
generic::TransformOperation::RotateY(_) => {
Ok(generic::TransformOperation::RotateY(Angle::zero()))
},
generic::TransformOperation::RotateZ(_) => {
Ok(generic::TransformOperation::RotateZ(Angle::zero()))
},
generic::TransformOperation::Rotate(_) => {
Ok(generic::TransformOperation::Rotate(Angle::zero()))
},
generic::TransformOperation::RotateX(_) => Ok(generic::TransformOperation::RotateX(Angle::zero())),
generic::TransformOperation::RotateY(_) => Ok(generic::TransformOperation::RotateY(Angle::zero())),
generic::TransformOperation::RotateZ(_) => Ok(generic::TransformOperation::RotateZ(Angle::zero())),
generic::TransformOperation::Rotate(_) => Ok(generic::TransformOperation::Rotate(Angle::zero())),
generic::TransformOperation::Perspective(..) |
generic::TransformOperation::AccumulateMatrix {
..
} |
generic::TransformOperation::InterpolateMatrix {
..
} => {
generic::TransformOperation::AccumulateMatrix { .. } |
generic::TransformOperation::InterpolateMatrix { .. } => {
// Perspective: We convert a perspective function into an equivalent
// ComputedMatrix, and then decompose/interpolate/recompose these matrices.
// AccumulateMatrix/InterpolateMatrix: We do interpolation on
@ -238,7 +268,6 @@ impl ToAnimatedZero for TransformOperation {
}
}
impl ToAnimatedZero for Transform {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
@ -258,8 +287,9 @@ impl Rotate {
match *self {
generic::Rotate::None => None,
generic::Rotate::Rotate(angle) => Some(generic::TransformOperation::Rotate(angle)),
generic::Rotate::Rotate3D(rx, ry, rz, angle) =>
Some(generic::TransformOperation::Rotate3D(rx, ry, rz, angle)),
generic::Rotate::Rotate3D(rx, ry, rz, angle) => {
Some(generic::TransformOperation::Rotate3D(rx, ry, rz, angle))
},
}
}
@ -267,8 +297,9 @@ impl Rotate {
pub fn from_transform_operation(operation: &TransformOperation) -> Rotate {
match *operation {
generic::TransformOperation::Rotate(angle) => generic::Rotate::Rotate(angle),
generic::TransformOperation::Rotate3D(rx, ry, rz, angle) =>
generic::Rotate::Rotate3D(rx, ry, rz, angle),
generic::TransformOperation::Rotate3D(rx, ry, rz, angle) => {
generic::Rotate::Rotate3D(rx, ry, rz, angle)
},
_ => unreachable!("Found unexpected value for rotate property"),
}
}
@ -283,8 +314,12 @@ impl Translate {
match *self {
generic::Translate::None => None,
generic::Translate::TranslateX(tx) => Some(generic::TransformOperation::TranslateX(tx)),
generic::Translate::Translate(tx, ty) => Some(generic::TransformOperation::Translate(tx, Some(ty))),
generic::Translate::Translate3D(tx, ty, tz) => Some(generic::TransformOperation::Translate3D(tx, ty, tz)),
generic::Translate::Translate(tx, ty) => {
Some(generic::TransformOperation::Translate(tx, Some(ty)))
},
generic::Translate::Translate3D(tx, ty, tz) => {
Some(generic::TransformOperation::Translate3D(tx, ty, tz))
},
}
}
@ -292,8 +327,12 @@ impl Translate {
pub fn from_transform_operation(operation: &TransformOperation) -> Translate {
match *operation {
generic::TransformOperation::TranslateX(tx) => generic::Translate::TranslateX(tx),
generic::TransformOperation::Translate(tx, Some(ty)) => generic::Translate::Translate(tx, ty),
generic::TransformOperation::Translate3D(tx, ty, tz) => generic::Translate::Translate3D(tx, ty, tz),
generic::TransformOperation::Translate(tx, Some(ty)) => {
generic::Translate::Translate(tx, ty)
},
generic::TransformOperation::Translate3D(tx, ty, tz) => {
generic::Translate::Translate3D(tx, ty, tz)
},
_ => unreachable!("Found unexpected value for translate"),
}
}
@ -309,7 +348,9 @@ impl Scale {
generic::Scale::None => None,
generic::Scale::ScaleX(sx) => Some(generic::TransformOperation::ScaleX(sx)),
generic::Scale::Scale(sx, sy) => Some(generic::TransformOperation::Scale(sx, Some(sy))),
generic::Scale::Scale3D(sx, sy, sz) => Some(generic::TransformOperation::Scale3D(sx, sy, sz)),
generic::Scale::Scale3D(sx, sy, sz) => {
Some(generic::TransformOperation::Scale3D(sx, sy, sz))
},
}
}

View file

@ -7,9 +7,9 @@
use values::generics::url::UrlOrNone as GenericUrlOrNone;
#[cfg(feature = "servo")]
pub use ::servo::url::{ComputedUrl, ComputedImageUrl};
pub use servo::url::{ComputedImageUrl, ComputedUrl};
#[cfg(feature = "gecko")]
pub use ::gecko::url::{ComputedUrl, ComputedImageUrl};
pub use gecko::url::{ComputedImageUrl, ComputedUrl};
/// Computed <url> | <none>
pub type UrlOrNone = GenericUrlOrNone<ComputedUrl>;