mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Fix related to #14101
Add Parse trait implementation for some structures
This commit is contained in:
parent
4b9693cf81
commit
9564673b5a
14 changed files with 149 additions and 114 deletions
|
@ -169,7 +169,18 @@ impl Position {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn parse(input: &mut Parser) -> Result<Position, ()> {
|
||||
pub fn center() -> Position {
|
||||
Position {
|
||||
horiz_keyword: Some(Keyword::Center),
|
||||
horiz_position: None,
|
||||
vert_keyword: Some(Keyword::Center),
|
||||
vert_position: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for Position {
|
||||
fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
let first = try!(PositionComponent::parse(input));
|
||||
let second = input.try(PositionComponent::parse)
|
||||
.unwrap_or(PositionComponent::Keyword(Keyword::Center));
|
||||
|
@ -216,15 +227,6 @@ impl Position {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn center() -> Position {
|
||||
Position {
|
||||
horiz_keyword: Some(Keyword::Center),
|
||||
horiz_position: None,
|
||||
vert_keyword: Some(Keyword::Center),
|
||||
vert_position: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Keyword {
|
||||
|
@ -362,25 +364,6 @@ impl HasViewportPercentage for PositionComponent {
|
|||
}
|
||||
|
||||
impl PositionComponent {
|
||||
pub fn parse(input: &mut Parser) -> Result<PositionComponent, ()> {
|
||||
input.try(LengthOrPercentage::parse)
|
||||
.map(PositionComponent::Length)
|
||||
.or_else(|()| {
|
||||
match try!(input.next()) {
|
||||
Token::Ident(value) => {
|
||||
match_ignore_ascii_case! { value,
|
||||
"center" => Ok(PositionComponent::Keyword(Keyword::Center)),
|
||||
"left" => Ok(PositionComponent::Keyword(Keyword::Left)),
|
||||
"right" => Ok(PositionComponent::Keyword(Keyword::Right)),
|
||||
"top" => Ok(PositionComponent::Keyword(Keyword::Top)),
|
||||
"bottom" => Ok(PositionComponent::Keyword(Keyword::Bottom)),
|
||||
_ => Err(())
|
||||
}
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
pub fn to_length_or_percentage(self) -> LengthOrPercentage {
|
||||
match self {
|
||||
|
@ -389,3 +372,25 @@ impl PositionComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for PositionComponent {
|
||||
fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
input.try(LengthOrPercentage::parse)
|
||||
.map(PositionComponent::Length)
|
||||
.or_else(|()| {
|
||||
match try!(input.next()) {
|
||||
Token::Ident(value) => {
|
||||
match_ignore_ascii_case! { value,
|
||||
"center" => Ok(PositionComponent::Keyword(Keyword::Center)),
|
||||
"left" => Ok(PositionComponent::Keyword(Keyword::Left)),
|
||||
"right" => Ok(PositionComponent::Keyword(Keyword::Right)),
|
||||
"top" => Ok(PositionComponent::Keyword(Keyword::Top)),
|
||||
"bottom" => Ok(PositionComponent::Keyword(Keyword::Bottom)),
|
||||
_ => Err(())
|
||||
}
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue