mirror of
https://github.com/servo/servo.git
synced 2025-08-19 20:35:34 +01:00
Derive HasViewportPercentage 🍷
This commit is contained in:
parent
d1e31f7aa4
commit
90bae7f802
27 changed files with 202 additions and 452 deletions
|
|
@ -81,13 +81,6 @@
|
|||
use values::HasViewportPercentage;
|
||||
use style_traits::ToCss;
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
let &SpecifiedValue(ref vec) = self;
|
||||
vec.iter().any(|ref x| x.has_viewport_percentage())
|
||||
}
|
||||
}
|
||||
|
||||
pub mod single_value {
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
|
|
@ -168,7 +161,7 @@
|
|||
}
|
||||
|
||||
/// The specified value of ${name}.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub Vec<single_value::SpecifiedValue>);
|
||||
|
||||
|
|
|
|||
|
|
@ -236,13 +236,7 @@ ${helpers.single_keyword("background-origin",
|
|||
}
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for ExplicitSize {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
return self.width.has_viewport_percentage() || self.height.has_viewport_percentage();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub struct ExplicitSize {
|
||||
|
|
@ -266,16 +260,7 @@ ${helpers.single_keyword("background-origin",
|
|||
}
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
SpecifiedValue::Explicit(ref explicit_size) => explicit_size.has_viewport_percentage(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Explicit(ExplicitSize),
|
||||
|
|
|
|||
|
|
@ -208,17 +208,6 @@ ${helpers.predefined_type("border-image-source", "ImageLayer",
|
|||
use values::HasViewportPercentage;
|
||||
use values::specified::{LengthOrNumber, Number};
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
let mut viewport_percentage = false;
|
||||
for value in self.0.iter() {
|
||||
let vp = value.has_viewport_percentage();
|
||||
viewport_percentage = vp || viewport_percentage;
|
||||
}
|
||||
viewport_percentage
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
use values::computed::LengthOrNumber;
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
@ -227,7 +216,7 @@ ${helpers.predefined_type("border-image-source", "ImageLayer",
|
|||
pub LengthOrNumber, pub LengthOrNumber);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub Vec<LengthOrNumber>);
|
||||
|
||||
|
|
@ -402,20 +391,6 @@ ${helpers.predefined_type("border-image-source", "ImageLayer",
|
|||
use values::HasViewportPercentage;
|
||||
use values::specified::{LengthOrPercentage, Number};
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
let mut viewport_percentage = false;
|
||||
for value in self.0.clone() {
|
||||
let vp = match value {
|
||||
SingleSpecifiedValue::LengthOrPercentage(len) => len.has_viewport_percentage(),
|
||||
_ => false,
|
||||
};
|
||||
viewport_percentage = vp || viewport_percentage;
|
||||
}
|
||||
viewport_percentage
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
use values::computed::{LengthOrPercentage, Number};
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
@ -432,7 +407,7 @@ ${helpers.predefined_type("border-image-source", "ImageLayer",
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub Vec<SingleSpecifiedValue>);
|
||||
|
||||
|
|
@ -458,7 +433,7 @@ ${helpers.predefined_type("border-image-source", "ImageLayer",
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SingleSpecifiedValue {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
|
|
|
|||
|
|
@ -274,18 +274,9 @@ ${helpers.single_keyword("position", "static absolute relative fixed",
|
|||
|
||||
${helpers.gecko_keyword_conversion(vertical_align.keyword)}
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
SpecifiedValue::LengthOrPercentage(ref length) => length.has_viewport_percentage(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The `vertical-align` value.
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
% for keyword in vertical_align_keywords:
|
||||
|
|
@ -1048,15 +1039,6 @@ ${helpers.single_keyword("animation-fill-mode",
|
|||
use values::HasViewportPercentage;
|
||||
use values::specified::LengthOrPercentage;
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
SpecifiedValue::Repeat(ref length) => length.has_viewport_percentage(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
use values::computed::LengthOrPercentage;
|
||||
|
||||
|
|
@ -1065,7 +1047,7 @@ ${helpers.single_keyword("animation-fill-mode",
|
|||
pub struct T(pub Option<LengthOrPercentage>);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
None,
|
||||
|
|
@ -1253,7 +1235,7 @@ ${helpers.predefined_type("scroll-snap-coordinate",
|
|||
/// Multiple transform functions compose a transformation.
|
||||
///
|
||||
/// Some transformations can be expressed by other more general functions.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedOperation {
|
||||
/// Represents a 2D 2x3 matrix.
|
||||
|
|
@ -1328,41 +1310,6 @@ ${helpers.predefined_type("scroll-snap-coordinate",
|
|||
}
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for SpecifiedOperation {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
SpecifiedOperation::Translate(ref l1, None) |
|
||||
SpecifiedOperation::TranslateX(ref l1) |
|
||||
SpecifiedOperation::TranslateY(ref l1) => {
|
||||
l1.has_viewport_percentage()
|
||||
}
|
||||
SpecifiedOperation::TranslateZ(ref l1) => {
|
||||
l1.has_viewport_percentage()
|
||||
}
|
||||
SpecifiedOperation::Translate(ref l1, Some(ref l2)) => {
|
||||
l1.has_viewport_percentage() ||
|
||||
l2.has_viewport_percentage()
|
||||
}
|
||||
SpecifiedOperation::Translate3D(ref l1, ref l2, ref l3) => {
|
||||
l1.has_viewport_percentage() ||
|
||||
l2.has_viewport_percentage() ||
|
||||
l3.has_viewport_percentage()
|
||||
},
|
||||
SpecifiedOperation::Perspective(ref length) => length.has_viewport_percentage(),
|
||||
SpecifiedOperation::PrefixedMatrix{ ref e, ref f, .. } => {
|
||||
e.has_viewport_percentage() ||
|
||||
f.has_viewport_percentage()
|
||||
},
|
||||
SpecifiedOperation::PrefixedMatrix3D{ ref m41, ref m42, ref m43, .. } => {
|
||||
m41.has_viewport_percentage() ||
|
||||
m42.has_viewport_percentage() ||
|
||||
m43.has_viewport_percentage()
|
||||
},
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedOperation {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
use self::SpecifiedOperation::*;
|
||||
|
|
@ -1422,14 +1369,7 @@ ${helpers.predefined_type("scroll-snap-coordinate",
|
|||
}
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
let &SpecifiedValue(ref specified_ops) = self;
|
||||
specified_ops.iter().any(|ref x| x.has_viewport_percentage())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(Vec<SpecifiedOperation>);
|
||||
|
||||
|
|
@ -2223,15 +2163,7 @@ ${helpers.single_keyword("transform-style",
|
|||
}
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
self.horizontal.has_viewport_percentage() ||
|
||||
self.vertical.has_viewport_percentage() ||
|
||||
self.depth.has_viewport_percentage()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue {
|
||||
horizontal: LengthOrPercentage,
|
||||
|
|
|
|||
|
|
@ -98,13 +98,7 @@ ${helpers.predefined_type("clip",
|
|||
use values::specified::{Angle, CSSColor, Length, Shadow};
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
self.0.iter().any(|ref x| x.has_viewport_percentage())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub Vec<SpecifiedFilter>);
|
||||
|
||||
|
|
|
|||
|
|
@ -2108,7 +2108,6 @@ ${helpers.single_keyword_system("font-variant-position",
|
|||
pub use self::computed_value::T as SpecifiedValue;
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
pub mod computed_value {
|
||||
pub type T = f32;
|
||||
|
|
@ -2235,7 +2234,7 @@ ${helpers.single_keyword("-moz-math-variant",
|
|||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::specified::length::{AU_PER_PT, FontBaseSize, NoCalcLength};
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
pub struct SpecifiedValue(pub NoCalcLength);
|
||||
|
||||
pub mod computed_value {
|
||||
|
|
@ -2273,12 +2272,6 @@ ${helpers.single_keyword("-moz-math-variant",
|
|||
}
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
self.0.has_viewport_percentage()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
Au((NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT as f32 * AU_PER_PT) as i32)
|
||||
|
|
|
|||
|
|
@ -65,14 +65,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
}
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
self.horizontal.has_viewport_percentage() ||
|
||||
self.vertical.as_ref().map_or(false, |v| v.has_viewport_percentage())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue {
|
||||
pub horizontal: Length,
|
||||
|
|
|
|||
|
|
@ -12,16 +12,7 @@
|
|||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
SpecifiedValue::LengthOrPercentage(ref length) => length.has_viewport_percentage(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Normal,
|
||||
|
|
@ -415,16 +406,7 @@ ${helpers.single_keyword("text-align-last",
|
|||
use values::HasViewportPercentage;
|
||||
use values::specified::AllowQuirks;
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
SpecifiedValue::Specified(ref length) => length.has_viewport_percentage(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Normal,
|
||||
|
|
@ -501,16 +483,7 @@ ${helpers.single_keyword("text-align-last",
|
|||
use values::HasViewportPercentage;
|
||||
use values::specified::AllowQuirks;
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
SpecifiedValue::Specified(ref length) => length.has_viewport_percentage(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Normal,
|
||||
|
|
@ -722,26 +695,11 @@ ${helpers.single_keyword("text-align-last",
|
|||
use values::specified::Shadow;
|
||||
use values::HasViewportPercentage;
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
let &SpecifiedValue(ref vec) = self;
|
||||
vec.iter().any(|ref x| x.has_viewport_percentage())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(Vec<SpecifiedTextShadow>);
|
||||
|
||||
impl HasViewportPercentage for SpecifiedTextShadow {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
self.offset_x.has_viewport_percentage() ||
|
||||
self.offset_y.has_viewport_percentage() ||
|
||||
self.blur_radius.has_viewport_percentage()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedTextShadow {
|
||||
pub offset_x: specified::Length,
|
||||
|
|
|
|||
|
|
@ -81,16 +81,10 @@ ${helpers.predefined_type("outline-color", "CSSColor", "computed::CSSColor::Curr
|
|||
specified::parse_border_width(context, input).map(SpecifiedValue)
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
let &SpecifiedValue(ref length) = self;
|
||||
length.has_viewport_percentage()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub specified::Length);
|
||||
|
||||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
pub type T = Au;
|
||||
|
|
|
|||
|
|
@ -181,17 +181,11 @@ ${helpers.predefined_type("flex-basis",
|
|||
use values::HasViewportPercentage;
|
||||
use values::specified::{AllowQuirks, ${MinMax}Length};
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
self.0.has_viewport_percentage()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
pub type T = ::values::computed::${MinMax}Length;
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(${MinMax}Length);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue