mirror of
https://github.com/servo/servo.git
synced 2025-06-19 22:59:03 +01:00
Auto merge of #7289 - tgkokk:perspective-transform-origin-combine, r=dzbarsky
Combine transform-origin, perspective-origin code First PR, please tell me if anything is wrong/could use improvement. Fixes #7194. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7289) <!-- Reviewable:end -->
This commit is contained in:
commit
c98c1651a3
1 changed files with 99 additions and 136 deletions
|
@ -100,6 +100,9 @@ def switch_to_style_struct(name):
|
||||||
%>
|
%>
|
||||||
|
|
||||||
pub mod longhands {
|
pub mod longhands {
|
||||||
|
use cssparser::Parser;
|
||||||
|
use parser::ParserContext;
|
||||||
|
use values::specified;
|
||||||
|
|
||||||
<%def name="raw_longhand(name, derived_from=None, custom_cascade=False, experimental=False)">
|
<%def name="raw_longhand(name, derived_from=None, custom_cascade=False, experimental=False)">
|
||||||
<%
|
<%
|
||||||
|
@ -3919,6 +3922,88 @@ pub mod longhands {
|
||||||
}
|
}
|
||||||
</%self:longhand>
|
</%self:longhand>
|
||||||
|
|
||||||
|
pub struct OriginParseResult {
|
||||||
|
horizontal: Option<specified::LengthOrPercentage>,
|
||||||
|
vertical: Option<specified::LengthOrPercentage>,
|
||||||
|
depth: Option<specified::Length>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_origin(_: &ParserContext, input: &mut Parser) -> Result<OriginParseResult,()> {
|
||||||
|
let (mut horizontal, mut vertical, mut depth) = (None, None, None);
|
||||||
|
loop {
|
||||||
|
if let Err(_) = input.try(|input| {
|
||||||
|
let token = try!(input.expect_ident());
|
||||||
|
match_ignore_ascii_case! {
|
||||||
|
token,
|
||||||
|
"left" => {
|
||||||
|
if horizontal.is_none() {
|
||||||
|
horizontal = Some(specified::LengthOrPercentage::Percentage(0.0))
|
||||||
|
} else {
|
||||||
|
return Err(())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"center" => {
|
||||||
|
if horizontal.is_none() {
|
||||||
|
horizontal = Some(specified::LengthOrPercentage::Percentage(0.5))
|
||||||
|
} else if vertical.is_none() {
|
||||||
|
vertical = Some(specified::LengthOrPercentage::Percentage(0.5))
|
||||||
|
} else {
|
||||||
|
return Err(())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"right" => {
|
||||||
|
if horizontal.is_none() {
|
||||||
|
horizontal = Some(specified::LengthOrPercentage::Percentage(1.0))
|
||||||
|
} else {
|
||||||
|
return Err(())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"top" => {
|
||||||
|
if vertical.is_none() {
|
||||||
|
vertical = Some(specified::LengthOrPercentage::Percentage(0.0))
|
||||||
|
} else {
|
||||||
|
return Err(())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bottom" => {
|
||||||
|
if vertical.is_none() {
|
||||||
|
vertical = Some(specified::LengthOrPercentage::Percentage(1.0))
|
||||||
|
} else {
|
||||||
|
return Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => return Err(())
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}) {
|
||||||
|
match specified::LengthOrPercentage::parse(input) {
|
||||||
|
Ok(value) => {
|
||||||
|
if horizontal.is_none() {
|
||||||
|
horizontal = Some(value);
|
||||||
|
} else if vertical.is_none() {
|
||||||
|
vertical = Some(value);
|
||||||
|
} else if let specified::LengthOrPercentage::Length(length) = value {
|
||||||
|
depth = Some(length);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if horizontal.is_some() || vertical.is_some() {
|
||||||
|
Ok(OriginParseResult {
|
||||||
|
horizontal: horizontal,
|
||||||
|
vertical: vertical,
|
||||||
|
depth: depth,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
${single_keyword("backface-visibility", "visible hidden")}
|
${single_keyword("backface-visibility", "visible hidden")}
|
||||||
|
|
||||||
${single_keyword("transform-style", "auto flat preserve-3d")}
|
${single_keyword("transform-style", "auto flat preserve-3d")}
|
||||||
|
@ -3978,80 +4063,13 @@ pub mod longhands {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||||
let (mut horizontal, mut vertical, mut depth) = (None, None, None);
|
let result = try!(super::parse_origin(context, input));
|
||||||
loop {
|
Ok(SpecifiedValue {
|
||||||
if let Err(_) = input.try(|input| {
|
horizontal: result.horizontal.unwrap_or(LengthOrPercentage::Percentage(0.5)),
|
||||||
let token = try!(input.expect_ident());
|
vertical: result.vertical.unwrap_or(LengthOrPercentage::Percentage(0.5)),
|
||||||
match_ignore_ascii_case! {
|
depth: result.depth.unwrap_or(Length::Absolute(Au(0))),
|
||||||
token,
|
})
|
||||||
"left" => {
|
|
||||||
if horizontal.is_none() {
|
|
||||||
horizontal = Some(LengthOrPercentage::Percentage(0.0))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"center" => {
|
|
||||||
if horizontal.is_none() {
|
|
||||||
horizontal = Some(LengthOrPercentage::Percentage(0.5))
|
|
||||||
} else if vertical.is_none() {
|
|
||||||
vertical = Some(LengthOrPercentage::Percentage(0.5))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"right" => {
|
|
||||||
if horizontal.is_none() {
|
|
||||||
horizontal = Some(LengthOrPercentage::Percentage(1.0))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"top" => {
|
|
||||||
if vertical.is_none() {
|
|
||||||
vertical = Some(LengthOrPercentage::Percentage(0.0))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"bottom" => {
|
|
||||||
if vertical.is_none() {
|
|
||||||
vertical = Some(LengthOrPercentage::Percentage(1.0))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => return Err(())
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}) {
|
|
||||||
match LengthOrPercentage::parse(input) {
|
|
||||||
Ok(value) => {
|
|
||||||
if horizontal.is_none() {
|
|
||||||
horizontal = Some(value);
|
|
||||||
} else if vertical.is_none() {
|
|
||||||
vertical = Some(value);
|
|
||||||
} else if let LengthOrPercentage::Length(length) = value {
|
|
||||||
depth = Some(length);
|
|
||||||
} else {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => break,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if horizontal.is_some() || vertical.is_some() {
|
|
||||||
Ok(SpecifiedValue {
|
|
||||||
horizontal: horizontal.unwrap_or(LengthOrPercentage::Percentage(0.5)),
|
|
||||||
vertical: vertical.unwrap_or(LengthOrPercentage::Percentage(0.5)),
|
|
||||||
depth: depth.unwrap_or(Length::Absolute(Au(0))),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
|
@ -4119,69 +4137,14 @@ pub mod longhands {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||||
let (mut horizontal, mut vertical) = (None, None);
|
let result = try!(super::parse_origin(context, input));
|
||||||
loop {
|
match result.depth {
|
||||||
if let Err(_) = input.try(|input| {
|
Some(_) => Err(()),
|
||||||
let token = try!(input.expect_ident());
|
None => Ok(SpecifiedValue {
|
||||||
match_ignore_ascii_case! {
|
horizontal: result.horizontal.unwrap_or(LengthOrPercentage::Percentage(0.5)),
|
||||||
token,
|
vertical: result.vertical.unwrap_or(LengthOrPercentage::Percentage(0.5)),
|
||||||
"left" => {
|
|
||||||
if horizontal.is_none() {
|
|
||||||
horizontal = Some(LengthOrPercentage::Percentage(0.0))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"center" => {
|
|
||||||
if horizontal.is_none() {
|
|
||||||
horizontal = Some(LengthOrPercentage::Percentage(0.5))
|
|
||||||
} else if vertical.is_none() {
|
|
||||||
vertical = Some(LengthOrPercentage::Percentage(0.5))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"right" => {
|
|
||||||
if horizontal.is_none() {
|
|
||||||
horizontal = Some(LengthOrPercentage::Percentage(1.0))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"top" => {
|
|
||||||
if vertical.is_none() {
|
|
||||||
vertical = Some(LengthOrPercentage::Percentage(0.0))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"bottom" => {
|
|
||||||
if vertical.is_none() {
|
|
||||||
vertical = Some(LengthOrPercentage::Percentage(1.0))
|
|
||||||
} else {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => return Err(())
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}) {
|
|
||||||
match LengthOrPercentage::parse(input) {
|
|
||||||
Ok(value) if horizontal.is_none() => horizontal = Some(value),
|
|
||||||
Ok(value) if vertical.is_none() => vertical = Some(value),
|
|
||||||
_ => break,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if horizontal.is_some() || vertical.is_some() {
|
|
||||||
Ok(SpecifiedValue {
|
|
||||||
horizontal: horizontal.unwrap_or(LengthOrPercentage::Percentage(0.5)),
|
|
||||||
vertical: vertical.unwrap_or(LengthOrPercentage::Percentage(0.5)),
|
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue