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
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue