Skip to content

Commit dd8d32c

Browse files
Enable min-content, max-content, fit-content and stretch (#79)
For the sizing properties. Signed-off-by: Oriol Brufau <[email protected]> Co-authored-by: Martin Robinson <[email protected]>
1 parent 1d95da7 commit dd8d32c

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

Diff for: style/values/computed/length.rs

+33-11
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,21 @@ impl MaxSize {
181181
#[inline]
182182
pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> {
183183
match *self {
184-
GenericMaxSize::None => None,
185-
GenericMaxSize::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)),
184+
Self::None | Self::MinContent | Self::MaxContent | Self::FitContent | Self::Stretch => {
185+
None
186+
},
187+
Self::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)),
188+
}
189+
}
190+
191+
/// Convert the computed value into used value if there is enough information.
192+
#[inline]
193+
pub fn maybe_to_used_value(&self, percentage_basis: Option<Au>) -> Option<Au> {
194+
match *self {
195+
Self::None | Self::MinContent | Self::MaxContent | Self::FitContent | Self::Stretch => {
196+
None
197+
},
198+
Self::LengthPercentage(ref lp) => lp.maybe_to_used_value(percentage_basis),
186199
}
187200
}
188201
}
@@ -193,8 +206,22 @@ impl Size {
193206
#[cfg(feature = "servo")]
194207
pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> {
195208
match *self {
196-
GenericSize::Auto => None,
197-
GenericSize::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)),
209+
Self::Auto | Self::MinContent | Self::MaxContent | Self::FitContent | Self::Stretch => {
210+
None
211+
},
212+
Self::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)),
213+
}
214+
}
215+
216+
/// Convert the computed value into used value if there is enough information.
217+
#[inline]
218+
#[cfg(feature = "servo")]
219+
pub fn maybe_to_used_value(&self, percentage_basis: Option<Au>) -> Option<Au> {
220+
match *self {
221+
Self::Auto | Self::MinContent | Self::MaxContent | Self::FitContent | Self::Stretch => {
222+
None
223+
},
224+
Self::LengthPercentage(ref lp) => lp.maybe_to_used_value(percentage_basis),
198225
}
199226
}
200227

@@ -204,14 +231,9 @@ impl Size {
204231
match *self {
205232
Self::Auto => false,
206233
Self::LengthPercentage(ref lp) => lp.is_definitely_zero(),
234+
Self::MinContent | Self::MaxContent | Self::FitContent | Self::Stretch => false,
207235
#[cfg(feature = "gecko")]
208-
Self::MinContent |
209-
Self::MaxContent |
210-
Self::FitContent |
211-
Self::MozAvailable |
212-
Self::WebkitFillAvailable |
213-
Self::Stretch |
214-
Self::FitContentFunction(_) => false,
236+
Self::MozAvailable | Self::WebkitFillAvailable | Self::FitContentFunction(_) => false,
215237
}
216238
}
217239
}

Diff for: style/values/generics/length.rs

-8
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,10 @@ impl<LengthPercentage: Parse> Parse for LengthPercentageOrAuto<LengthPercentage>
150150
pub enum GenericSize<LengthPercent> {
151151
LengthPercentage(LengthPercent),
152152
Auto,
153-
#[cfg(feature = "gecko")]
154153
#[animation(error)]
155154
MaxContent,
156-
#[cfg(feature = "gecko")]
157155
#[animation(error)]
158156
MinContent,
159-
#[cfg(feature = "gecko")]
160157
#[animation(error)]
161158
FitContent,
162159
#[cfg(feature = "gecko")]
@@ -165,7 +162,6 @@ pub enum GenericSize<LengthPercent> {
165162
#[cfg(feature = "gecko")]
166163
#[animation(error)]
167164
WebkitFillAvailable,
168-
#[cfg(feature = "gecko")]
169165
#[animation(error)]
170166
Stretch,
171167
#[cfg(feature = "gecko")]
@@ -212,13 +208,10 @@ impl<LengthPercentage> Size<LengthPercentage> {
212208
pub enum GenericMaxSize<LengthPercent> {
213209
LengthPercentage(LengthPercent),
214210
None,
215-
#[cfg(feature = "gecko")]
216211
#[animation(error)]
217212
MaxContent,
218-
#[cfg(feature = "gecko")]
219213
#[animation(error)]
220214
MinContent,
221-
#[cfg(feature = "gecko")]
222215
#[animation(error)]
223216
FitContent,
224217
#[cfg(feature = "gecko")]
@@ -227,7 +220,6 @@ pub enum GenericMaxSize<LengthPercent> {
227220
#[cfg(feature = "gecko")]
228221
#[animation(error)]
229222
WebkitFillAvailable,
230-
#[cfg(feature = "gecko")]
231223
#[animation(error)]
232224
Stretch,
233225
#[cfg(feature = "gecko")]

Diff for: style/values/specified/length.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1950,17 +1950,13 @@ macro_rules! parse_size_non_length {
19501950
($size:ident, $input:expr, $auto_or_none:expr => $auto_or_none_ident:ident) => {{
19511951
let size = $input.try_parse(|input| {
19521952
Ok(try_match_ident_ignore_ascii_case! { input,
1953-
#[cfg(feature = "gecko")]
19541953
"min-content" | "-moz-min-content" => $size::MinContent,
1955-
#[cfg(feature = "gecko")]
19561954
"max-content" | "-moz-max-content" => $size::MaxContent,
1957-
#[cfg(feature = "gecko")]
19581955
"fit-content" | "-moz-fit-content" => $size::FitContent,
19591956
#[cfg(feature = "gecko")]
19601957
"-moz-available" => $size::MozAvailable,
19611958
#[cfg(feature = "gecko")]
19621959
"-webkit-fill-available" if is_webkit_fill_available_keyword_enabled() => $size::WebkitFillAvailable,
1963-
#[cfg(feature = "gecko")]
19641960
"stretch" if is_stretch_enabled() => $size::Stretch,
19651961
$auto_or_none => $size::$auto_or_none_ident,
19661962
})
@@ -1975,7 +1971,6 @@ macro_rules! parse_size_non_length {
19751971
fn is_webkit_fill_available_keyword_enabled() -> bool {
19761972
static_prefs::pref!("layout.css.webkit-fill-available.enabled")
19771973
}
1978-
#[cfg(feature = "gecko")]
19791974
fn is_stretch_enabled() -> bool {
19801975
static_prefs::pref!("layout.css.stretch-size-keyword.enabled")
19811976
}

0 commit comments

Comments
 (0)