Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CSS3 Calc #7496

Merged
merged 23 commits into from Sep 2, 2015
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9556141
Implement Calc for LengthOrPercentage
dzbarsky Aug 11, 2015
cb4d878
Implement Calc for LengthOrPercentageOrAuto
dzbarsky Aug 12, 2015
2bb6b45
Implement proper calc parsing
dzbarsky Aug 12, 2015
5df4b82
Implement font relative and viewport relative units for calc
dzbarsky Aug 12, 2015
af4d2e9
Clean up serialization and other hacks
dzbarsky Aug 13, 2015
64dc954
Clean up serialization code a little
dzbarsky Aug 13, 2015
cfa1e46
Clean up AST simplification code
dzbarsky Aug 13, 2015
6573e80
Properly serialize % values in calc expressions
dzbarsky Aug 13, 2015
663e0f6
Simplify like terms in all sum expressions, not just toplevel calc
dzbarsky Aug 13, 2015
63d0429
Simplify the calc AST simplification code
dzbarsky Aug 13, 2015
67db4fb
Remove stray changes
dzbarsky Aug 13, 2015
f8bd7c4
Fix some calc parsing panics
dzbarsky Aug 14, 2015
164af05
Expand out nested products
dzbarsky Aug 15, 2015
dcac654
Use the type system to enforce that product nodes are simplified away
dzbarsky Aug 15, 2015
53e8f7d
Get rid of some cloning
dzbarsky Aug 15, 2015
5ac205b
Clean up some stray lines
dzbarsky Aug 15, 2015
cdae523
Address review comments
dzbarsky Aug 23, 2015
25829bb
Add calc reftest
dzbarsky Aug 26, 2015
2591a89
Add calc parsing tests for the other properties
dzbarsky Aug 26, 2015
80d471d
Merge branch 'master' into calc
SimonSapin Sep 1, 2015
b30c4f7
Add support for the ch unit in calc()
SimonSapin Sep 1, 2015
9f48dcd
Fix font-size keywords parsing.
SimonSapin Sep 2, 2015
b51b7dd
Fix ch/em confusion.
SimonSapin Sep 2, 2015
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Clean up some stray lines

  • Loading branch information
dzbarsky committed Aug 26, 2015
commit 5ac205b3e5c555b2311ce3bb1e130a1ab9c9704f
@@ -428,8 +428,7 @@ pub mod specified {
products.push(try!(Calc::parse_product(input)));

loop {
let next = input.next();
match next {
match input.next() {
Ok(Token::Delim('+')) => {
products.push(try!(Calc::parse_product(input)));
}
@@ -452,8 +451,7 @@ pub mod specified {

loop {
let position = input.position();
let next = input.next();
match next {
match input.next() {
Ok(Token::Delim('*')) => {
values.push(try!(Calc::parse_value(input)));
}
@@ -478,8 +476,7 @@ pub mod specified {
}

fn parse_value(input: &mut Parser) -> Result<CalcValueNode, ()> {
let next = input.next();
match next {
match input.next() {
Ok(Token::Number(ref value)) => Ok(CalcValueNode::Number(value.value)),
Ok(Token::Dimension(ref value, ref unit)) =>
Length::parse_dimension(value.value, unit).map(CalcValueNode::Length),
@@ -503,7 +500,7 @@ pub mod specified {

fn simplify_sum_to_number(node: &CalcSumNode) -> Option<CSSFloat> {
let mut sum = 0.;
for product in &node.products {
for ref product in &node.products {
match Calc::simplify_product_to_number(product) {
Some(number) => sum += number,
_ => return None
@@ -514,7 +511,7 @@ pub mod specified {

fn simplify_product_to_number(node: &CalcProductNode) -> Option<CSSFloat> {
let mut product = 1.;
for value in &node.values {
for ref value in &node.values {
match Calc::simplify_value_to_number(value) {
Some(number) => product *= number,
_ => return None
@@ -539,22 +536,21 @@ pub mod specified {
}
}

fn simplify_product(node: CalcProductNode) -> Result<SimplifiedValueNode, ()> {
fn simplify_product(node: &CalcProductNode) -> Result<SimplifiedValueNode, ()> {
let mut multiplier = 1.;
let mut node_with_unit = None;
for node in node.values {
for node in &node.values {
match Calc::simplify_value_to_number(&node) {
Some(number) => multiplier *= number,
_ if node_with_unit.is_none() => {
node_with_unit = Some(match node {
CalcValueNode::Sum(box ref sum) =>
&CalcValueNode::Sum(box ref sum) =>
try!(Calc::simplify_products_in_sum(sum)),
CalcValueNode::Length(l) => SimplifiedValueNode::Length(l),
CalcValueNode::Percentage(p) => SimplifiedValueNode::Percentage(p),
&CalcValueNode::Length(l) => SimplifiedValueNode::Length(l),
&CalcValueNode::Percentage(p) => SimplifiedValueNode::Percentage(p),
_ => unreachable!("Numbers should have been handled by simplify_value_to_nubmer")
})
},
//_ if node_with_unit.is_none() => node_with_unit = Some(node),
_ => return Err(()),
}
}
@@ -569,7 +565,7 @@ pub mod specified {
let ast = try!(Calc::parse_sum(input));

let mut simplified = Vec::new();
for node in ast.products {
for ref node in ast.products {
match try!(Calc::simplify_product(node)) {
SimplifiedValueNode::Sum(sum) => simplified.push_all(&sum.values),
value => simplified.push(value),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.