Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename LengthOrPercentageOrAutoOrContent to FlexBasis
- Loading branch information
Showing
11 changed files
with
111 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
//! Computed types for CSS values related to flexbox. | ||
|
||
use values::computed::length::LengthOrPercentage; | ||
use values::generics::flex::FlexBasis as GenericFlexBasis; | ||
|
||
/// A computed value for the `flex-basis` property. | ||
pub type FlexBasis = GenericFlexBasis<LengthOrPercentage>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
//! Generic types for CSS values related to flexbox. | ||
|
||
use values::specified::Percentage; | ||
|
||
/// A generic value for the `flex-basis` property. | ||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] | ||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)] | ||
pub enum FlexBasis<LengthOrPercentage> { | ||
/// `auto` | ||
Auto, | ||
/// `content` | ||
Content, | ||
/// `<length-percentage>` | ||
Length(LengthOrPercentage), | ||
} | ||
|
||
impl<L> FlexBasis<L> { | ||
/// Returns `auto`. | ||
#[inline] | ||
pub fn auto() -> Self { | ||
FlexBasis::Auto | ||
} | ||
} | ||
|
||
impl<L> FlexBasis<L> | ||
where Percentage: Into<L>, | ||
{ | ||
/// Returns `0%`. | ||
#[inline] | ||
pub fn zero_percent() -> Self { | ||
FlexBasis::Length(Percentage(0.).into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
//! Specified types for CSS values related to flexbox. | ||
|
||
use cssparser::Parser; | ||
use parser::{Parse, ParserContext}; | ||
use style_traits::ParseError; | ||
use values::generics::flex::FlexBasis as GenericFlexBasis; | ||
use values::specified::length::LengthOrPercentage; | ||
|
||
/// A specified value for the `flex-basis` property. | ||
pub type FlexBasis = GenericFlexBasis<LengthOrPercentage>; | ||
|
||
impl Parse for FlexBasis { | ||
fn parse<'i, 't>( | ||
context: &ParserContext, | ||
input: &mut Parser<'i, 't>) | ||
-> Result<Self, ParseError<'i>> { | ||
if let Ok(length) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) { | ||
return Ok(GenericFlexBasis::Length(length)); | ||
} | ||
try_match_ident_ignore_ascii_case! { input.expect_ident()?, | ||
"auto" => Ok(GenericFlexBasis::Auto), | ||
"content" => Ok(GenericFlexBasis::Content), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters