mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Use Rust sizes for flex-basis, width, height, and their min/max properties.
Really sorry for the size of the patch :( Only intentional behavior change is in the uses of HasLengthAndPercentage(), where it's easier to do the right thing. The checks that used to check for (IsCalcUnit() && CalcHasPercentage()) are wrong since bug 957915. Differential Revision: https://phabricator.services.mozilla.com/D19553
This commit is contained in:
parent
e12c76982d
commit
f7a59bf0ee
9 changed files with 70 additions and 106 deletions
|
@ -79,6 +79,9 @@ include = [
|
|||
"LengthPercentageOrAuto",
|
||||
"Rect",
|
||||
"IntersectionObserverRootMargin",
|
||||
"Size",
|
||||
"MaxSize",
|
||||
"FlexBasis",
|
||||
]
|
||||
item_types = ["enums", "structs", "typedefs"]
|
||||
|
||||
|
@ -86,10 +89,12 @@ item_types = ["enums", "structs", "typedefs"]
|
|||
"LengthPercentage" = """
|
||||
// Defined in nsStyleCoord.h
|
||||
static constexpr inline StyleLengthPercentage Zero();
|
||||
static inline StyleLengthPercentage FromAppUnits(nscoord);
|
||||
inline bool HasPercent() const;
|
||||
inline bool ConvertsToLength() const;
|
||||
inline nscoord ToLength() const;
|
||||
inline bool ConvertsToPercentage() const;
|
||||
inline bool HasLengthAndPercentage() const;
|
||||
inline float ToPercentage() const;
|
||||
inline CSSCoord LengthInCSSPixels() const;
|
||||
inline float Percentage() const;
|
||||
|
@ -101,8 +106,41 @@ item_types = ["enums", "structs", "typedefs"]
|
|||
|
||||
"GenericLengthPercentageOrAuto" = """
|
||||
inline const StyleLengthPercentage& AsLengthPercentage() const;
|
||||
inline bool HasPercent() const;
|
||||
inline bool ConvertsToLength() const;
|
||||
inline nscoord ToLength() const;
|
||||
inline bool ConvertsToPercentage() const;
|
||||
inline float ToPercentage() const;
|
||||
inline bool HasPercent() const;
|
||||
inline bool HasLengthAndPercentage() const;
|
||||
"""
|
||||
|
||||
"GenericSize" = """
|
||||
inline const StyleLengthPercentage& AsLengthPercentage() const;
|
||||
inline StyleExtremumLength AsExtremumLength() const;
|
||||
inline bool ConvertsToLength() const;
|
||||
inline nscoord ToLength() const;
|
||||
inline bool ConvertsToPercentage() const;
|
||||
inline float ToPercentage() const;
|
||||
inline bool HasPercent() const;
|
||||
inline bool HasLengthAndPercentage() const;
|
||||
inline bool BehavesLikeInitialValueOnBlockAxis() const;
|
||||
"""
|
||||
|
||||
"GenericFlexBasis" = """
|
||||
inline bool IsAuto() const;
|
||||
inline const StyleSize& AsSize() const;
|
||||
"""
|
||||
|
||||
"GenericMaxSize" = """
|
||||
inline const StyleLengthPercentage& AsLengthPercentage() const;
|
||||
inline StyleExtremumLength AsExtremumLength() const;
|
||||
inline bool ConvertsToLength() const;
|
||||
inline nscoord ToLength() const;
|
||||
inline bool ConvertsToPercentage() const;
|
||||
inline float ToPercentage() const;
|
||||
inline bool HasPercent() const;
|
||||
inline bool HasLengthAndPercentage() const;
|
||||
inline bool BehavesLikeInitialValueOnBlockAxis() const;
|
||||
"""
|
||||
|
||||
"Rect" = """
|
||||
|
|
|
@ -7,22 +7,18 @@
|
|||
//! Different kind of helpers to interact with Gecko values.
|
||||
|
||||
use crate::counter_style::{Symbol, Symbols};
|
||||
use crate::gecko_bindings::structs::{self, nsStyleCoord, CounterStylePtr};
|
||||
use crate::gecko_bindings::structs::{nsStyleCoord, CounterStylePtr};
|
||||
use crate::gecko_bindings::structs::{StyleGridTrackBreadth, StyleShapeRadius};
|
||||
use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||
use crate::media_queries::Device;
|
||||
use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
|
||||
use crate::values::computed::FlexBasis as ComputedFlexBasis;
|
||||
use crate::values::computed::{Angle, ExtremumLength, Length, LengthPercentage};
|
||||
use crate::values::computed::{MaxSize as ComputedMaxSize, Size as ComputedSize};
|
||||
use crate::values::computed::{NonNegativeLengthPercentage, Percentage};
|
||||
use crate::values::computed::{Number, NumberOrPercentage};
|
||||
use crate::values::computed::{Angle, Length, LengthPercentage};
|
||||
use crate::values::computed::{Number, NumberOrPercentage, Percentage};
|
||||
use crate::values::generics::basic_shape::ShapeRadius;
|
||||
use crate::values::generics::box_::Perspective;
|
||||
use crate::values::generics::flex::FlexBasis;
|
||||
use crate::values::generics::gecko::ScrollSnapPoint;
|
||||
use crate::values::generics::grid::{TrackBreadth, TrackKeyword};
|
||||
use crate::values::generics::length::{LengthPercentageOrAuto, MaxSize, Size};
|
||||
use crate::values::generics::length::LengthPercentageOrAuto;
|
||||
use crate::values::generics::{CounterStyleOrNone, NonNegative};
|
||||
use crate::values::{Auto, Either, None_, Normal};
|
||||
use crate::Atom;
|
||||
|
@ -80,29 +76,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for ComputedFlexBasis {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
FlexBasis::Content => coord.set_value(CoordDataValue::Enumerated(
|
||||
structs::NS_STYLE_FLEX_BASIS_CONTENT,
|
||||
)),
|
||||
FlexBasis::Width(ref w) => w.to_gecko_style_coord(coord),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
if let Some(width) = ComputedSize::from_gecko_style_coord(coord) {
|
||||
return Some(FlexBasis::Width(width));
|
||||
}
|
||||
|
||||
if let CoordDataValue::Enumerated(structs::NS_STYLE_FLEX_BASIS_CONTENT) = coord.as_value() {
|
||||
return Some(FlexBasis::Content);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for Number {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::Factor(*self));
|
||||
|
@ -336,60 +309,6 @@ impl GeckoStyleCoordConvertible for Normal {
|
|||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for ExtremumLength {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::Enumerated(*self as u32));
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
use num_traits::FromPrimitive;
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Enumerated(v) => ExtremumLength::from_u32(v),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for ComputedSize {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
Size::LengthPercentage(ref lpoa) => lpoa.to_gecko_style_coord(coord),
|
||||
Size::Auto => coord.set_value(CoordDataValue::Auto),
|
||||
Size::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
if let CoordDataValue::Auto = coord.as_value() {
|
||||
return Some(Size::Auto);
|
||||
}
|
||||
if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) {
|
||||
return Some(Size::LengthPercentage(lp));
|
||||
}
|
||||
ExtremumLength::from_gecko_style_coord(coord).map(Size::ExtremumLength)
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for ComputedMaxSize {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
MaxSize::LengthPercentage(ref lpon) => lpon.to_gecko_style_coord(coord),
|
||||
MaxSize::None => coord.set_value(CoordDataValue::None),
|
||||
MaxSize::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
if let CoordDataValue::None = coord.as_value() {
|
||||
return Some(MaxSize::None);
|
||||
}
|
||||
if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) {
|
||||
return Some(MaxSize::LengthPercentage(lp));
|
||||
}
|
||||
ExtremumLength::from_gecko_style_coord(coord).map(MaxSize::ExtremumLength)
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for ScrollSnapPoint<LengthPercentage> {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match self.repeated() {
|
||||
|
|
|
@ -1385,13 +1385,13 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
|||
"length::NonNegativeLengthOrAuto": impl_style_coord,
|
||||
"length::NonNegativeLengthPercentageOrNormal": impl_style_coord,
|
||||
"FillRule": impl_simple,
|
||||
"FlexBasis": impl_style_coord,
|
||||
"FlexBasis": impl_simple,
|
||||
"Length": impl_absolute_length,
|
||||
"LengthOrNormal": impl_style_coord,
|
||||
"LengthPercentage": impl_simple,
|
||||
"LengthPercentageOrAuto": impl_style_coord,
|
||||
"MaxSize": impl_style_coord,
|
||||
"Size": impl_style_coord,
|
||||
"MaxSize": impl_simple,
|
||||
"Size": impl_simple,
|
||||
"MozScriptMinSize": impl_absolute_length,
|
||||
"MozScriptSizeMultiplier": impl_simple,
|
||||
"NonNegativeLengthPercentage": impl_simple,
|
||||
|
|
|
@ -236,6 +236,7 @@ ${helpers.predefined_type(
|
|||
extra_prefixes="webkit",
|
||||
animation_value_type="FlexBasis",
|
||||
servo_restyle_damage="reflow",
|
||||
boxed=True,
|
||||
)}
|
||||
|
||||
% for (size, logical) in ALL_SIZES:
|
||||
|
|
|
@ -14,6 +14,6 @@ impl FlexBasis {
|
|||
/// `auto`
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
GenericFlexBasis::Width(Size::auto())
|
||||
GenericFlexBasis::Size(Size::auto())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,12 @@
|
|||
ToComputedValue,
|
||||
ToCss,
|
||||
)]
|
||||
pub enum FlexBasis<Width> {
|
||||
#[repr(C)]
|
||||
pub enum GenericFlexBasis<S> {
|
||||
/// `content`
|
||||
Content,
|
||||
/// `<width>`
|
||||
Width(Width),
|
||||
Size(S),
|
||||
}
|
||||
|
||||
pub use self::GenericFlexBasis as FlexBasis;
|
||||
|
|
|
@ -192,10 +192,7 @@ impl<L> TrackBreadth<L> {
|
|||
/// <https://drafts.csswg.org/css-grid/#typedef-fixed-breadth>
|
||||
#[inline]
|
||||
pub fn is_fixed(&self) -> bool {
|
||||
match *self {
|
||||
TrackBreadth::Breadth(ref _lp) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, TrackBreadth::Breadth(..))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,14 +96,17 @@ impl<LengthPercentage: Parse> Parse for LengthPercentageOrAuto<LengthPercentage>
|
|||
ToComputedValue,
|
||||
ToCss,
|
||||
)]
|
||||
pub enum Size<LengthPercentage> {
|
||||
LengthPercentage(LengthPercentage),
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericSize<LengthPercent> {
|
||||
LengthPercentage(LengthPercent),
|
||||
Auto,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[animation(error)]
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
pub use self::GenericSize as Size;
|
||||
|
||||
impl<LengthPercentage> Size<LengthPercentage> {
|
||||
/// `auto` value.
|
||||
#[inline]
|
||||
|
@ -134,14 +137,17 @@ impl<LengthPercentage> Size<LengthPercentage> {
|
|||
ToComputedValue,
|
||||
ToCss,
|
||||
)]
|
||||
pub enum MaxSize<LengthPercentage> {
|
||||
LengthPercentage(LengthPercentage),
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericMaxSize<LengthPercent> {
|
||||
LengthPercentage(LengthPercent),
|
||||
None,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[animation(error)]
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
pub use self::GenericMaxSize as MaxSize;
|
||||
|
||||
impl<LengthPercentage> MaxSize<LengthPercentage> {
|
||||
/// `none` value.
|
||||
#[inline]
|
||||
|
|
|
@ -18,8 +18,8 @@ impl Parse for FlexBasis {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(width) = input.try(|i| Size::parse(context, i)) {
|
||||
return Ok(GenericFlexBasis::Width(width));
|
||||
if let Ok(size) = input.try(|i| Size::parse(context, i)) {
|
||||
return Ok(GenericFlexBasis::Size(size));
|
||||
}
|
||||
try_match_ident_ignore_ascii_case! { input,
|
||||
"content" => Ok(GenericFlexBasis::Content),
|
||||
|
@ -31,12 +31,12 @@ impl FlexBasis {
|
|||
/// `auto`
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
GenericFlexBasis::Width(Size::auto())
|
||||
GenericFlexBasis::Size(Size::auto())
|
||||
}
|
||||
|
||||
/// `0%`
|
||||
#[inline]
|
||||
pub fn zero_percent() -> Self {
|
||||
GenericFlexBasis::Width(Size::zero_percent())
|
||||
GenericFlexBasis::Size(Size::zero_percent())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue