Auto merge of #16541 - sbwtw:fix_calc_behavior, r=stshine

Add calc method for CalcLengthOrPercentage

* Add calc method to calculate formula value with parent size
* Add unit test case

<!-- Please describe your changes on the following line: -->
Please see this issue: https://github.com/servo/servo/issues/15986

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15986 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16541)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-24 04:16:18 -05:00 committed by GitHub
commit 418c3e8cc7
8 changed files with 47 additions and 32 deletions

View file

@ -4,6 +4,19 @@
use app_units::Au;
use style::attr::{AttrValue, LengthOrPercentageOrAuto, parse_length};
use style::values::computed::CalcLengthOrPercentage;
#[test]
fn test_length_calc() {
let calc = CalcLengthOrPercentage { length: Au(10), percentage: Some(0.2) };
assert_eq!(calc.to_computed(Some(Au(10))), Some(Au(12)));
assert_eq!(calc.to_computed(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_computed(None), None);
let calc = CalcLengthOrPercentage { length: Au(10), percentage: None };
assert_eq!(calc.to_computed(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_computed(None), Some(Au(10)));
}
#[test]
fn test_parse_double() {

View file

@ -1,3 +0,0 @@
[calc-height-block-1.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[calc-max-height-block-1.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[calc-min-height-block-1.htm]
type: reftest
expected: FAIL