mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Clean up length handling
No behavior change, but using Self is shorter and while I'm touching this code might as well clean it up a little bit. Differential Revision: https://phabricator.services.mozilla.com/D177732
This commit is contained in:
parent
4b7260d846
commit
af13e670d9
2 changed files with 178 additions and 182 deletions
|
@ -35,7 +35,7 @@ impl ToComputedValue for specified::NoCalcLength {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||||
specified::NoCalcLength::Absolute(AbsoluteLength::Px(computed.px()))
|
Self::Absolute(AbsoluteLength::Px(computed.px()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,17 +47,17 @@ impl specified::NoCalcLength {
|
||||||
base_size: FontBaseSize,
|
base_size: FontBaseSize,
|
||||||
) -> Length {
|
) -> Length {
|
||||||
match *self {
|
match *self {
|
||||||
specified::NoCalcLength::Absolute(length) => length.to_computed_value(context),
|
Self::Absolute(length) => length.to_computed_value(context),
|
||||||
specified::NoCalcLength::FontRelative(length) => {
|
Self::FontRelative(length) => {
|
||||||
length.to_computed_value(context, base_size)
|
length.to_computed_value(context, base_size)
|
||||||
},
|
},
|
||||||
specified::NoCalcLength::ViewportPercentage(length) => {
|
Self::ViewportPercentage(length) => {
|
||||||
length.to_computed_value(context)
|
length.to_computed_value(context)
|
||||||
},
|
},
|
||||||
specified::NoCalcLength::ContainerRelative(length) => {
|
Self::ContainerRelative(length) => {
|
||||||
length.to_computed_value(context)
|
length.to_computed_value(context)
|
||||||
},
|
},
|
||||||
specified::NoCalcLength::ServoCharacterWidth(length) => {
|
Self::ServoCharacterWidth(length) => {
|
||||||
length.to_computed_value(context.style().get_font().clone_font_size().computed_size())
|
length.to_computed_value(context.style().get_font().clone_font_size().computed_size())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,8 @@ impl ToComputedValue for specified::Length {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||||
match *self {
|
match *self {
|
||||||
specified::Length::NoCalc(l) => l.to_computed_value(context),
|
Self::NoCalc(l) => l.to_computed_value(context),
|
||||||
specified::Length::Calc(ref calc) => {
|
Self::Calc(ref calc) => {
|
||||||
calc.to_computed_value(context).to_length().unwrap()
|
calc.to_computed_value(context).to_length().unwrap()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ impl ToComputedValue for specified::Length {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||||
specified::Length::NoCalc(specified::NoCalcLength::from_computed_value(computed))
|
Self::NoCalc(specified::NoCalcLength::from_computed_value(computed))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +91,8 @@ macro_rules! computed_length_percentage_or_auto {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> {
|
pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> {
|
||||||
match *self {
|
match *self {
|
||||||
generics::GenericLengthPercentageOrAuto::Auto => None,
|
Self::Auto => None,
|
||||||
generics::GenericLengthPercentageOrAuto::LengthPercentage(ref lp) => {
|
Self::LengthPercentage(ref lp) => {
|
||||||
Some(lp.to_used_value(percentage_basis))
|
Some(lp.to_used_value(percentage_basis))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -196,14 +196,14 @@ impl Size {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_definitely_zero(&self) -> bool {
|
pub fn is_definitely_zero(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
GenericSize::Auto => false,
|
Self::Auto => false,
|
||||||
GenericSize::LengthPercentage(ref lp) => lp.is_definitely_zero(),
|
Self::LengthPercentage(ref lp) => lp.is_definitely_zero(),
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
GenericSize::MinContent |
|
Self::MinContent |
|
||||||
GenericSize::MaxContent |
|
Self::MaxContent |
|
||||||
GenericSize::FitContent |
|
Self::FitContent |
|
||||||
GenericSize::MozAvailable |
|
Self::MozAvailable |
|
||||||
GenericSize::FitContentFunction(_) => false,
|
Self::FitContentFunction(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,8 @@ impl FontBaseSize {
|
||||||
/// Calculate the actual size for a given context
|
/// Calculate the actual size for a given context
|
||||||
pub fn resolve(&self, context: &Context) -> computed::FontSize {
|
pub fn resolve(&self, context: &Context) -> computed::FontSize {
|
||||||
match *self {
|
match *self {
|
||||||
FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size(),
|
Self::CurrentStyle => context.style().get_font().clone_font_size(),
|
||||||
FontBaseSize::InheritedStyle => context.style().get_parent_font().clone_font_size(),
|
Self::InheritedStyle => context.style().get_parent_font().clone_font_size(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,24 +89,24 @@ impl FontRelativeLength {
|
||||||
/// Return the unitless, raw value.
|
/// Return the unitless, raw value.
|
||||||
fn unitless_value(&self) -> CSSFloat {
|
fn unitless_value(&self) -> CSSFloat {
|
||||||
match *self {
|
match *self {
|
||||||
FontRelativeLength::Em(v) |
|
Self::Em(v) |
|
||||||
FontRelativeLength::Ex(v) |
|
Self::Ex(v) |
|
||||||
FontRelativeLength::Ch(v) |
|
Self::Ch(v) |
|
||||||
FontRelativeLength::Cap(v) |
|
Self::Cap(v) |
|
||||||
FontRelativeLength::Ic(v) |
|
Self::Ic(v) |
|
||||||
FontRelativeLength::Rem(v) => v,
|
Self::Rem(v) => v,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the unit, as a string.
|
// Return the unit, as a string.
|
||||||
fn unit(&self) -> &'static str {
|
fn unit(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
FontRelativeLength::Em(_) => "em",
|
Self::Em(_) => "em",
|
||||||
FontRelativeLength::Ex(_) => "ex",
|
Self::Ex(_) => "ex",
|
||||||
FontRelativeLength::Ch(_) => "ch",
|
Self::Ch(_) => "ch",
|
||||||
FontRelativeLength::Cap(_) => "cap",
|
Self::Cap(_) => "cap",
|
||||||
FontRelativeLength::Ic(_) => "ic",
|
Self::Ic(_) => "ic",
|
||||||
FontRelativeLength::Rem(_) => "rem",
|
Self::Rem(_) => "rem",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ impl FontRelativeLength {
|
||||||
|
|
||||||
let reference_font_size = base_size.resolve(context);
|
let reference_font_size = base_size.resolve(context);
|
||||||
match *self {
|
match *self {
|
||||||
FontRelativeLength::Em(length) => {
|
Self::Em(length) => {
|
||||||
if context.for_non_inherited_property.is_some() {
|
if context.for_non_inherited_property.is_some() {
|
||||||
if base_size == FontBaseSize::CurrentStyle {
|
if base_size == FontBaseSize::CurrentStyle {
|
||||||
context
|
context
|
||||||
|
@ -194,7 +194,7 @@ impl FontRelativeLength {
|
||||||
|
|
||||||
(reference_font_size.computed_size(), length)
|
(reference_font_size.computed_size(), length)
|
||||||
},
|
},
|
||||||
FontRelativeLength::Ex(length) => {
|
Self::Ex(length) => {
|
||||||
// The x-height is an intrinsically horizontal metric.
|
// The x-height is an intrinsically horizontal metric.
|
||||||
let metrics =
|
let metrics =
|
||||||
query_font_metrics(context, base_size, FontMetricsOrientation::Horizontal);
|
query_font_metrics(context, base_size, FontMetricsOrientation::Horizontal);
|
||||||
|
@ -211,7 +211,7 @@ impl FontRelativeLength {
|
||||||
});
|
});
|
||||||
(reference_size, length)
|
(reference_size, length)
|
||||||
},
|
},
|
||||||
FontRelativeLength::Ch(length) => {
|
Self::Ch(length) => {
|
||||||
// https://drafts.csswg.org/css-values/#ch:
|
// https://drafts.csswg.org/css-values/#ch:
|
||||||
//
|
//
|
||||||
// Equal to the used advance measure of the “0” (ZERO,
|
// Equal to the used advance measure of the “0” (ZERO,
|
||||||
|
@ -246,7 +246,7 @@ impl FontRelativeLength {
|
||||||
});
|
});
|
||||||
(reference_size, length)
|
(reference_size, length)
|
||||||
},
|
},
|
||||||
FontRelativeLength::Cap(length) => {
|
Self::Cap(length) => {
|
||||||
let metrics =
|
let metrics =
|
||||||
query_font_metrics(context, base_size, FontMetricsOrientation::Horizontal);
|
query_font_metrics(context, base_size, FontMetricsOrientation::Horizontal);
|
||||||
let reference_size = metrics.cap_height.unwrap_or_else(|| {
|
let reference_size = metrics.cap_height.unwrap_or_else(|| {
|
||||||
|
@ -260,7 +260,7 @@ impl FontRelativeLength {
|
||||||
});
|
});
|
||||||
(reference_size, length)
|
(reference_size, length)
|
||||||
},
|
},
|
||||||
FontRelativeLength::Ic(length) => {
|
Self::Ic(length) => {
|
||||||
let metrics = query_font_metrics(
|
let metrics = query_font_metrics(
|
||||||
context,
|
context,
|
||||||
base_size,
|
base_size,
|
||||||
|
@ -279,7 +279,7 @@ impl FontRelativeLength {
|
||||||
});
|
});
|
||||||
(reference_size, length)
|
(reference_size, length)
|
||||||
},
|
},
|
||||||
FontRelativeLength::Rem(length) => {
|
Self::Rem(length) => {
|
||||||
// https://drafts.csswg.org/css-values/#rem:
|
// https://drafts.csswg.org/css-values/#rem:
|
||||||
//
|
//
|
||||||
// When specified on the font-size property of the root
|
// When specified on the font-size property of the root
|
||||||
|
@ -414,63 +414,59 @@ impl ViewportPercentageLength {
|
||||||
// Return the unit, as a string.
|
// Return the unit, as a string.
|
||||||
fn unit(&self) -> &'static str {
|
fn unit(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
ViewportPercentageLength::Vw(_) => "vw",
|
Self::Vw(_) => "vw",
|
||||||
ViewportPercentageLength::Lvw(_) => "lvw",
|
Self::Lvw(_) => "lvw",
|
||||||
ViewportPercentageLength::Svw(_) => "svw",
|
Self::Svw(_) => "svw",
|
||||||
ViewportPercentageLength::Dvw(_) => "dvw",
|
Self::Dvw(_) => "dvw",
|
||||||
ViewportPercentageLength::Vh(_) => "vh",
|
Self::Vh(_) => "vh",
|
||||||
ViewportPercentageLength::Svh(_) => "svh",
|
Self::Svh(_) => "svh",
|
||||||
ViewportPercentageLength::Lvh(_) => "lvh",
|
Self::Lvh(_) => "lvh",
|
||||||
ViewportPercentageLength::Dvh(_) => "dvh",
|
Self::Dvh(_) => "dvh",
|
||||||
ViewportPercentageLength::Vmin(_) => "vmin",
|
Self::Vmin(_) => "vmin",
|
||||||
ViewportPercentageLength::Svmin(_) => "svmin",
|
Self::Svmin(_) => "svmin",
|
||||||
ViewportPercentageLength::Lvmin(_) => "lvmin",
|
Self::Lvmin(_) => "lvmin",
|
||||||
ViewportPercentageLength::Dvmin(_) => "dvmin",
|
Self::Dvmin(_) => "dvmin",
|
||||||
ViewportPercentageLength::Vmax(_) => "vmax",
|
Self::Vmax(_) => "vmax",
|
||||||
ViewportPercentageLength::Svmax(_) => "svmax",
|
Self::Svmax(_) => "svmax",
|
||||||
ViewportPercentageLength::Lvmax(_) => "lvmax",
|
Self::Lvmax(_) => "lvmax",
|
||||||
ViewportPercentageLength::Dvmax(_) => "dvmax",
|
Self::Dvmax(_) => "dvmax",
|
||||||
ViewportPercentageLength::Vb(_) => "vb",
|
Self::Vb(_) => "vb",
|
||||||
ViewportPercentageLength::Svb(_) => "svb",
|
Self::Svb(_) => "svb",
|
||||||
ViewportPercentageLength::Lvb(_) => "lvb",
|
Self::Lvb(_) => "lvb",
|
||||||
ViewportPercentageLength::Dvb(_) => "dvb",
|
Self::Dvb(_) => "dvb",
|
||||||
ViewportPercentageLength::Vi(_) => "vi",
|
Self::Vi(_) => "vi",
|
||||||
ViewportPercentageLength::Svi(_) => "svi",
|
Self::Svi(_) => "svi",
|
||||||
ViewportPercentageLength::Lvi(_) => "lvi",
|
Self::Lvi(_) => "lvi",
|
||||||
ViewportPercentageLength::Dvi(_) => "dvi",
|
Self::Dvi(_) => "dvi",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unpack(&self) -> (ViewportVariant, ViewportUnit, CSSFloat) {
|
fn unpack(&self) -> (ViewportVariant, ViewportUnit, CSSFloat) {
|
||||||
match *self {
|
match *self {
|
||||||
ViewportPercentageLength::Vw(v) => (ViewportVariant::UADefault, ViewportUnit::Vw, v),
|
Self::Vw(v) => (ViewportVariant::UADefault, ViewportUnit::Vw, v),
|
||||||
ViewportPercentageLength::Svw(v) => (ViewportVariant::Small, ViewportUnit::Vw, v),
|
Self::Svw(v) => (ViewportVariant::Small, ViewportUnit::Vw, v),
|
||||||
ViewportPercentageLength::Lvw(v) => (ViewportVariant::Large, ViewportUnit::Vw, v),
|
Self::Lvw(v) => (ViewportVariant::Large, ViewportUnit::Vw, v),
|
||||||
ViewportPercentageLength::Dvw(v) => (ViewportVariant::Dynamic, ViewportUnit::Vw, v),
|
Self::Dvw(v) => (ViewportVariant::Dynamic, ViewportUnit::Vw, v),
|
||||||
ViewportPercentageLength::Vh(v) => (ViewportVariant::UADefault, ViewportUnit::Vh, v),
|
Self::Vh(v) => (ViewportVariant::UADefault, ViewportUnit::Vh, v),
|
||||||
ViewportPercentageLength::Svh(v) => (ViewportVariant::Small, ViewportUnit::Vh, v),
|
Self::Svh(v) => (ViewportVariant::Small, ViewportUnit::Vh, v),
|
||||||
ViewportPercentageLength::Lvh(v) => (ViewportVariant::Large, ViewportUnit::Vh, v),
|
Self::Lvh(v) => (ViewportVariant::Large, ViewportUnit::Vh, v),
|
||||||
ViewportPercentageLength::Dvh(v) => (ViewportVariant::Dynamic, ViewportUnit::Vh, v),
|
Self::Dvh(v) => (ViewportVariant::Dynamic, ViewportUnit::Vh, v),
|
||||||
ViewportPercentageLength::Vmin(v) => {
|
Self::Vmin(v) => (ViewportVariant::UADefault, ViewportUnit::Vmin, v),
|
||||||
(ViewportVariant::UADefault, ViewportUnit::Vmin, v)
|
Self::Svmin(v) => (ViewportVariant::Small, ViewportUnit::Vmin, v),
|
||||||
},
|
Self::Lvmin(v) => (ViewportVariant::Large, ViewportUnit::Vmin, v),
|
||||||
ViewportPercentageLength::Svmin(v) => (ViewportVariant::Small, ViewportUnit::Vmin, v),
|
Self::Dvmin(v) => (ViewportVariant::Dynamic, ViewportUnit::Vmin, v),
|
||||||
ViewportPercentageLength::Lvmin(v) => (ViewportVariant::Large, ViewportUnit::Vmin, v),
|
Self::Vmax(v) => (ViewportVariant::UADefault, ViewportUnit::Vmax, v),
|
||||||
ViewportPercentageLength::Dvmin(v) => (ViewportVariant::Dynamic, ViewportUnit::Vmin, v),
|
Self::Svmax(v) => (ViewportVariant::Small, ViewportUnit::Vmax, v),
|
||||||
ViewportPercentageLength::Vmax(v) => {
|
Self::Lvmax(v) => (ViewportVariant::Large, ViewportUnit::Vmax, v),
|
||||||
(ViewportVariant::UADefault, ViewportUnit::Vmax, v)
|
Self::Dvmax(v) => (ViewportVariant::Dynamic, ViewportUnit::Vmax, v),
|
||||||
},
|
Self::Vb(v) => (ViewportVariant::UADefault, ViewportUnit::Vb, v),
|
||||||
ViewportPercentageLength::Svmax(v) => (ViewportVariant::Small, ViewportUnit::Vmax, v),
|
Self::Svb(v) => (ViewportVariant::Small, ViewportUnit::Vb, v),
|
||||||
ViewportPercentageLength::Lvmax(v) => (ViewportVariant::Large, ViewportUnit::Vmax, v),
|
Self::Lvb(v) => (ViewportVariant::Large, ViewportUnit::Vb, v),
|
||||||
ViewportPercentageLength::Dvmax(v) => (ViewportVariant::Dynamic, ViewportUnit::Vmax, v),
|
Self::Dvb(v) => (ViewportVariant::Dynamic, ViewportUnit::Vb, v),
|
||||||
ViewportPercentageLength::Vb(v) => (ViewportVariant::UADefault, ViewportUnit::Vb, v),
|
Self::Vi(v) => (ViewportVariant::UADefault, ViewportUnit::Vi, v),
|
||||||
ViewportPercentageLength::Svb(v) => (ViewportVariant::Small, ViewportUnit::Vb, v),
|
Self::Svi(v) => (ViewportVariant::Small, ViewportUnit::Vi, v),
|
||||||
ViewportPercentageLength::Lvb(v) => (ViewportVariant::Large, ViewportUnit::Vb, v),
|
Self::Lvi(v) => (ViewportVariant::Large, ViewportUnit::Vi, v),
|
||||||
ViewportPercentageLength::Dvb(v) => (ViewportVariant::Dynamic, ViewportUnit::Vb, v),
|
Self::Dvi(v) => (ViewportVariant::Dynamic, ViewportUnit::Vi, v),
|
||||||
ViewportPercentageLength::Vi(v) => (ViewportVariant::UADefault, ViewportUnit::Vi, v),
|
|
||||||
ViewportPercentageLength::Svi(v) => (ViewportVariant::Small, ViewportUnit::Vi, v),
|
|
||||||
ViewportPercentageLength::Lvi(v) => (ViewportVariant::Large, ViewportUnit::Vi, v),
|
|
||||||
ViewportPercentageLength::Dvi(v) => (ViewportVariant::Dynamic, ViewportUnit::Vi, v),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -629,26 +625,26 @@ impl AbsoluteLength {
|
||||||
/// Return the unitless, raw value.
|
/// Return the unitless, raw value.
|
||||||
fn unitless_value(&self) -> CSSFloat {
|
fn unitless_value(&self) -> CSSFloat {
|
||||||
match *self {
|
match *self {
|
||||||
AbsoluteLength::Px(v) |
|
Self::Px(v) |
|
||||||
AbsoluteLength::In(v) |
|
Self::In(v) |
|
||||||
AbsoluteLength::Cm(v) |
|
Self::Cm(v) |
|
||||||
AbsoluteLength::Mm(v) |
|
Self::Mm(v) |
|
||||||
AbsoluteLength::Q(v) |
|
Self::Q(v) |
|
||||||
AbsoluteLength::Pt(v) |
|
Self::Pt(v) |
|
||||||
AbsoluteLength::Pc(v) => v,
|
Self::Pc(v) => v,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the unit, as a string.
|
// Return the unit, as a string.
|
||||||
fn unit(&self) -> &'static str {
|
fn unit(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
AbsoluteLength::Px(_) => "px",
|
Self::Px(_) => "px",
|
||||||
AbsoluteLength::In(_) => "in",
|
Self::In(_) => "in",
|
||||||
AbsoluteLength::Cm(_) => "cm",
|
Self::Cm(_) => "cm",
|
||||||
AbsoluteLength::Mm(_) => "mm",
|
Self::Mm(_) => "mm",
|
||||||
AbsoluteLength::Q(_) => "q",
|
Self::Q(_) => "q",
|
||||||
AbsoluteLength::Pt(_) => "pt",
|
Self::Pt(_) => "pt",
|
||||||
AbsoluteLength::Pc(_) => "pc",
|
Self::Pc(_) => "pc",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,13 +652,13 @@ impl AbsoluteLength {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_px(&self) -> CSSFloat {
|
pub fn to_px(&self) -> CSSFloat {
|
||||||
match *self {
|
match *self {
|
||||||
AbsoluteLength::Px(value) => value,
|
Self::Px(value) => value,
|
||||||
AbsoluteLength::In(value) => value * PX_PER_IN,
|
Self::In(value) => value * PX_PER_IN,
|
||||||
AbsoluteLength::Cm(value) => value * PX_PER_CM,
|
Self::Cm(value) => value * PX_PER_CM,
|
||||||
AbsoluteLength::Mm(value) => value * PX_PER_MM,
|
Self::Mm(value) => value * PX_PER_MM,
|
||||||
AbsoluteLength::Q(value) => value * PX_PER_Q,
|
Self::Q(value) => value * PX_PER_Q,
|
||||||
AbsoluteLength::Pt(value) => value * PX_PER_PT,
|
Self::Pt(value) => value * PX_PER_PT,
|
||||||
AbsoluteLength::Pc(value) => value * PX_PER_PC,
|
Self::Pc(value) => value * PX_PER_PC,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -724,24 +720,24 @@ pub enum ContainerRelativeLength {
|
||||||
impl ContainerRelativeLength {
|
impl ContainerRelativeLength {
|
||||||
fn unitless_value(&self) -> CSSFloat {
|
fn unitless_value(&self) -> CSSFloat {
|
||||||
match *self {
|
match *self {
|
||||||
ContainerRelativeLength::Cqw(v) |
|
Self::Cqw(v) |
|
||||||
ContainerRelativeLength::Cqh(v) |
|
Self::Cqh(v) |
|
||||||
ContainerRelativeLength::Cqi(v) |
|
Self::Cqi(v) |
|
||||||
ContainerRelativeLength::Cqb(v) |
|
Self::Cqb(v) |
|
||||||
ContainerRelativeLength::Cqmin(v) |
|
Self::Cqmin(v) |
|
||||||
ContainerRelativeLength::Cqmax(v) => v,
|
Self::Cqmax(v) => v,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the unit, as a string.
|
// Return the unit, as a string.
|
||||||
fn unit(&self) -> &'static str {
|
fn unit(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
ContainerRelativeLength::Cqw(_) => "cqw",
|
Self::Cqw(_) => "cqw",
|
||||||
ContainerRelativeLength::Cqh(_) => "cqh",
|
Self::Cqh(_) => "cqh",
|
||||||
ContainerRelativeLength::Cqi(_) => "cqi",
|
Self::Cqi(_) => "cqi",
|
||||||
ContainerRelativeLength::Cqb(_) => "cqb",
|
Self::Cqb(_) => "cqb",
|
||||||
ContainerRelativeLength::Cqmin(_) => "cqmin",
|
Self::Cqmin(_) => "cqmin",
|
||||||
ContainerRelativeLength::Cqmax(_) => "cqmax",
|
Self::Cqmax(_) => "cqmax",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -790,18 +786,18 @@ impl ContainerRelativeLength {
|
||||||
pub fn to_computed_value(&self, context: &Context) -> CSSPixelLength {
|
pub fn to_computed_value(&self, context: &Context) -> CSSPixelLength {
|
||||||
let size = context.get_container_size_query();
|
let size = context.get_container_size_query();
|
||||||
let (factor, container_length) = match *self {
|
let (factor, container_length) = match *self {
|
||||||
ContainerRelativeLength::Cqw(v) => (v, size.get_container_width(context)),
|
Self::Cqw(v) => (v, size.get_container_width(context)),
|
||||||
ContainerRelativeLength::Cqh(v) => (v, size.get_container_height(context)),
|
Self::Cqh(v) => (v, size.get_container_height(context)),
|
||||||
ContainerRelativeLength::Cqi(v) => (v, size.get_container_inline_size(context)),
|
Self::Cqi(v) => (v, size.get_container_inline_size(context)),
|
||||||
ContainerRelativeLength::Cqb(v) => (v, size.get_container_block_size(context)),
|
Self::Cqb(v) => (v, size.get_container_block_size(context)),
|
||||||
ContainerRelativeLength::Cqmin(v) => (
|
Self::Cqmin(v) => (
|
||||||
v,
|
v,
|
||||||
cmp::min(
|
cmp::min(
|
||||||
size.get_container_inline_size(context),
|
size.get_container_inline_size(context),
|
||||||
size.get_container_block_size(context),
|
size.get_container_block_size(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ContainerRelativeLength::Cqmax(v) => (
|
Self::Cqmax(v) => (
|
||||||
v,
|
v,
|
||||||
cmp::max(
|
cmp::max(
|
||||||
size.get_container_inline_size(context),
|
size.get_container_inline_size(context),
|
||||||
|
@ -857,22 +853,22 @@ impl NoCalcLength {
|
||||||
/// Return the unitless, raw value.
|
/// Return the unitless, raw value.
|
||||||
pub fn unitless_value(&self) -> CSSFloat {
|
pub fn unitless_value(&self) -> CSSFloat {
|
||||||
match *self {
|
match *self {
|
||||||
NoCalcLength::Absolute(v) => v.unitless_value(),
|
Self::Absolute(v) => v.unitless_value(),
|
||||||
NoCalcLength::FontRelative(v) => v.unitless_value(),
|
Self::FontRelative(v) => v.unitless_value(),
|
||||||
NoCalcLength::ViewportPercentage(v) => v.unitless_value(),
|
Self::ViewportPercentage(v) => v.unitless_value(),
|
||||||
NoCalcLength::ContainerRelative(v) => v.unitless_value(),
|
Self::ContainerRelative(v) => v.unitless_value(),
|
||||||
NoCalcLength::ServoCharacterWidth(c) => c.0 as f32,
|
Self::ServoCharacterWidth(c) => c.0 as f32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the unit, as a string.
|
// Return the unit, as a string.
|
||||||
fn unit(&self) -> &'static str {
|
fn unit(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
NoCalcLength::Absolute(v) => v.unit(),
|
Self::Absolute(v) => v.unit(),
|
||||||
NoCalcLength::FontRelative(v) => v.unit(),
|
Self::FontRelative(v) => v.unit(),
|
||||||
NoCalcLength::ViewportPercentage(v) => v.unit(),
|
Self::ViewportPercentage(v) => v.unit(),
|
||||||
NoCalcLength::ContainerRelative(v) => v.unit(),
|
Self::ContainerRelative(v) => v.unit(),
|
||||||
NoCalcLength::ServoCharacterWidth(_) => "",
|
Self::ServoCharacterWidth(_) => "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,112 +913,112 @@ impl NoCalcLength {
|
||||||
unit: &str,
|
unit: &str,
|
||||||
) -> Result<Self, ()> {
|
) -> Result<Self, ()> {
|
||||||
Ok(match_ignore_ascii_case! { unit,
|
Ok(match_ignore_ascii_case! { unit,
|
||||||
"px" => NoCalcLength::Absolute(AbsoluteLength::Px(value)),
|
"px" => Self::Absolute(AbsoluteLength::Px(value)),
|
||||||
"in" => NoCalcLength::Absolute(AbsoluteLength::In(value)),
|
"in" => Self::Absolute(AbsoluteLength::In(value)),
|
||||||
"cm" => NoCalcLength::Absolute(AbsoluteLength::Cm(value)),
|
"cm" => Self::Absolute(AbsoluteLength::Cm(value)),
|
||||||
"mm" => NoCalcLength::Absolute(AbsoluteLength::Mm(value)),
|
"mm" => Self::Absolute(AbsoluteLength::Mm(value)),
|
||||||
"q" => NoCalcLength::Absolute(AbsoluteLength::Q(value)),
|
"q" => Self::Absolute(AbsoluteLength::Q(value)),
|
||||||
"pt" => NoCalcLength::Absolute(AbsoluteLength::Pt(value)),
|
"pt" => Self::Absolute(AbsoluteLength::Pt(value)),
|
||||||
"pc" => NoCalcLength::Absolute(AbsoluteLength::Pc(value)),
|
"pc" => Self::Absolute(AbsoluteLength::Pc(value)),
|
||||||
// font-relative
|
// font-relative
|
||||||
"em" => NoCalcLength::FontRelative(FontRelativeLength::Em(value)),
|
"em" => Self::FontRelative(FontRelativeLength::Em(value)),
|
||||||
"ex" => NoCalcLength::FontRelative(FontRelativeLength::Ex(value)),
|
"ex" => Self::FontRelative(FontRelativeLength::Ex(value)),
|
||||||
"ch" => NoCalcLength::FontRelative(FontRelativeLength::Ch(value)),
|
"ch" => Self::FontRelative(FontRelativeLength::Ch(value)),
|
||||||
"cap" => NoCalcLength::FontRelative(FontRelativeLength::Cap(value)),
|
"cap" => Self::FontRelative(FontRelativeLength::Cap(value)),
|
||||||
"ic" => NoCalcLength::FontRelative(FontRelativeLength::Ic(value)),
|
"ic" => Self::FontRelative(FontRelativeLength::Ic(value)),
|
||||||
"rem" => NoCalcLength::FontRelative(FontRelativeLength::Rem(value)),
|
"rem" => Self::FontRelative(FontRelativeLength::Rem(value)),
|
||||||
// viewport percentages
|
// viewport percentages
|
||||||
"vw" if !context.in_page_rule() => {
|
"vw" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Vw(value))
|
||||||
},
|
},
|
||||||
"svw" if !context.in_page_rule() => {
|
"svw" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Svw(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Svw(value))
|
||||||
},
|
},
|
||||||
"lvw" if !context.in_page_rule() => {
|
"lvw" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Lvw(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Lvw(value))
|
||||||
},
|
},
|
||||||
"dvw" if !context.in_page_rule() => {
|
"dvw" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Dvw(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Dvw(value))
|
||||||
},
|
},
|
||||||
"vh" if !context.in_page_rule() => {
|
"vh" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Vh(value))
|
||||||
},
|
},
|
||||||
"svh" if !context.in_page_rule() => {
|
"svh" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Svh(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Svh(value))
|
||||||
},
|
},
|
||||||
"lvh" if !context.in_page_rule() => {
|
"lvh" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Lvh(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Lvh(value))
|
||||||
},
|
},
|
||||||
"dvh" if !context.in_page_rule() => {
|
"dvh" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Dvh(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Dvh(value))
|
||||||
},
|
},
|
||||||
"vmin" if !context.in_page_rule() => {
|
"vmin" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmin(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Vmin(value))
|
||||||
},
|
},
|
||||||
"svmin" if !context.in_page_rule() => {
|
"svmin" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Svmin(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Svmin(value))
|
||||||
},
|
},
|
||||||
"lvmin" if !context.in_page_rule() => {
|
"lvmin" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Lvmin(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Lvmin(value))
|
||||||
},
|
},
|
||||||
"dvmin" if !context.in_page_rule() => {
|
"dvmin" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Dvmin(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Dvmin(value))
|
||||||
},
|
},
|
||||||
"vmax" if !context.in_page_rule() => {
|
"vmax" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Vmax(value))
|
||||||
},
|
},
|
||||||
"svmax" if !context.in_page_rule() => {
|
"svmax" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Svmax(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Svmax(value))
|
||||||
},
|
},
|
||||||
"lvmax" if !context.in_page_rule() => {
|
"lvmax" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Lvmax(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Lvmax(value))
|
||||||
},
|
},
|
||||||
"dvmax" if !context.in_page_rule() => {
|
"dvmax" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Dvmax(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Dvmax(value))
|
||||||
},
|
},
|
||||||
"vb" if !context.in_page_rule() => {
|
"vb" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vb(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Vb(value))
|
||||||
},
|
},
|
||||||
"svb" if !context.in_page_rule() => {
|
"svb" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Svb(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Svb(value))
|
||||||
},
|
},
|
||||||
"lvb" if !context.in_page_rule() => {
|
"lvb" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Lvb(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Lvb(value))
|
||||||
},
|
},
|
||||||
"dvb" if !context.in_page_rule() => {
|
"dvb" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Dvb(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Dvb(value))
|
||||||
},
|
},
|
||||||
"vi" if !context.in_page_rule() => {
|
"vi" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vi(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Vi(value))
|
||||||
},
|
},
|
||||||
"svi" if !context.in_page_rule() => {
|
"svi" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Svi(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Svi(value))
|
||||||
},
|
},
|
||||||
"lvi" if !context.in_page_rule() => {
|
"lvi" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Lvi(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Lvi(value))
|
||||||
},
|
},
|
||||||
"dvi" if !context.in_page_rule() => {
|
"dvi" if !context.in_page_rule() => {
|
||||||
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Dvi(value))
|
Self::ViewportPercentage(ViewportPercentageLength::Dvi(value))
|
||||||
},
|
},
|
||||||
// Container query lengths. Inherit the limitation from viewport units since
|
// Container query lengths. Inherit the limitation from viewport units since
|
||||||
// we may fall back to them.
|
// we may fall back to them.
|
||||||
"cqw" if !context.in_page_rule() && are_container_queries_enabled() => {
|
"cqw" if !context.in_page_rule() && are_container_queries_enabled() => {
|
||||||
NoCalcLength::ContainerRelative(ContainerRelativeLength::Cqw(value))
|
Self::ContainerRelative(ContainerRelativeLength::Cqw(value))
|
||||||
},
|
},
|
||||||
"cqh" if !context.in_page_rule() && are_container_queries_enabled() => {
|
"cqh" if !context.in_page_rule() && are_container_queries_enabled() => {
|
||||||
NoCalcLength::ContainerRelative(ContainerRelativeLength::Cqh(value))
|
Self::ContainerRelative(ContainerRelativeLength::Cqh(value))
|
||||||
},
|
},
|
||||||
"cqi" if !context.in_page_rule() && are_container_queries_enabled() => {
|
"cqi" if !context.in_page_rule() && are_container_queries_enabled() => {
|
||||||
NoCalcLength::ContainerRelative(ContainerRelativeLength::Cqi(value))
|
Self::ContainerRelative(ContainerRelativeLength::Cqi(value))
|
||||||
},
|
},
|
||||||
"cqb" if !context.in_page_rule() && are_container_queries_enabled() => {
|
"cqb" if !context.in_page_rule() && are_container_queries_enabled() => {
|
||||||
NoCalcLength::ContainerRelative(ContainerRelativeLength::Cqb(value))
|
Self::ContainerRelative(ContainerRelativeLength::Cqb(value))
|
||||||
},
|
},
|
||||||
"cqmin" if !context.in_page_rule() && are_container_queries_enabled() => {
|
"cqmin" if !context.in_page_rule() && are_container_queries_enabled() => {
|
||||||
NoCalcLength::ContainerRelative(ContainerRelativeLength::Cqmin(value))
|
Self::ContainerRelative(ContainerRelativeLength::Cqmin(value))
|
||||||
},
|
},
|
||||||
"cqmax" if !context.in_page_rule() && are_container_queries_enabled() => {
|
"cqmax" if !context.in_page_rule() && are_container_queries_enabled() => {
|
||||||
NoCalcLength::ContainerRelative(ContainerRelativeLength::Cqmax(value))
|
Self::ContainerRelative(ContainerRelativeLength::Cqmax(value))
|
||||||
},
|
},
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue